Serial Wombat Arduino Library
Loading...
Searching...
No Matches
SerialWombat18CapTouch.h
Go to the documentation of this file.
1#pragma once
2/*
3Copyright 2021-2024 Broadwell Consulting Inc.
4
5"Serial Wombat" is a registered trademark of Broadwell Consulting Inc. in
6the United States. See SerialWombat.com for usage guidance.
7
8Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14
15The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
25*/
26
27#include <stdint.h>
28#include "SerialWombat.h"
29#include "limits.h"
30
86{
87public:
88
91
92
104 int16_t begin(uint8_t pin, uint16_t chargeTime, uint16_t delay = 10)
105 {
106 _pin = pin;
108
109 uint8_t tx[8] = { 200,_pin, 22, SW_LE16(chargeTime), SW_LE16(delay),0x55 };
110
111 return _sw.sendPacket(tx);
112 }
113
124 int16_t makeDigital(uint16_t touchLimit, uint16_t noTouchLimit)
125 {
126 return makeDigital(touchLimit, noTouchLimit, 1, 0, 0, 0);
127 }
128
143 int16_t makeDigital(uint16_t touchLimit, uint16_t noTouchLimit, uint16_t touchValue, uint16_t noTouchValue, bool invert,uint16_t debounceCount)
144 {
145 uint8_t tx1[8] = { 201,_pin,22,SW_LE16(touchLimit), SW_LE16(noTouchLimit),0x55 };
146 int16_t result = _sw.sendPacket(tx1);
147 if (result < 0)
148 {
149 return (result);
150 }
151
152 _trueOutput = touchValue;
153 _falseOutput = noTouchValue;
154 uint8_t tx2[8] = { 202,_pin,22,SW_LE16(touchValue), SW_LE16(noTouchValue),0x55 };
155 result = _sw.sendPacket(tx2);
156 if (result < 0)
157 {
158 return (result);
159 }
160 uint8_t tx3[8] = { 203,_pin,22,1, invert? (uint8_t)1: (uint8_t)0,SW_LE16(debounceCount),0x55 };
161 result = _sw.sendPacket(tx3);
162 if (result < 0)
163 {
164 return (result);
165 }
166 return(0);
167 }
168
169 int16_t makeAnalog()
170 {
171 uint8_t tx3[8] = { 203,_pin,22,0, 0x55,0x55,0x55,0x55 };
172 return _sw.sendPacket(tx3);
173 }
174
184 {
185 uint8_t tx[8] = { 204,_pin,22,0,0x55,0x55,0x55,0x55 };
186 uint8_t rx[8];
187 if (_sw.sendPacket(tx, rx) >= 0)
188 {
189 return(rx[3] > 0);
190 }
191 return(false);
192 }
193
202 {
203 uint8_t tx[8] = { 204,_pin,22,1,0x55,0x55,0x55,0x55 };
204 uint8_t rx[8];
205 _sw.sendPacket(tx, rx);
206
207 transitions += (256 * rx[5] + rx[4]);
208 if (rx[3] == 0)
209 {
210 return (0);
211 }
212 else
213 {
214 return(256 * rx[7] + rx[6]);
215 }
216 }
217
226 {
227 uint8_t tx[8] = { 204,_pin,22,1,0x55,0x55,0x55,0x55 };
228 uint8_t rx[8];
229 _sw.sendPacket(tx, rx);
230
231 transitions += (256 * rx[5] + rx[4]);
232
233 if (rx[3] == 1)
234 {
235 return (0);
236 }
237 else
238 {
239 return(256 * rx[7] + rx[6]);
240 }
241 }
242
243
245 uint16_t transitions = 0;
246
256 bool readTransitionsState(bool resetTransitionCounts = true)
257 {
258 uint8_t tx[8] = { 204,_pin,22,1,(uint8_t)resetTransitionCounts,0x55,0x55,0x55 };
259 uint8_t rx[8];
260 _sw.sendPacket(tx, rx);
261 transitions = (256 * rx[5] + rx[4]);
262 return (rx[3] > 0);
263 }
264
265 uint8_t pin() { return _pin; }
266 uint8_t swPinModeNumber() { return _pinMode; }
267
268private:
269
270 uint16_t _trueOutput = 1;
271 uint16_t _falseOutput = 1;
272};
#define SW_LE16(_a)
Convert a uint16_t to two bytes in little endian format for array initialization.
@ PIN_MODE_SW18AB_CAPTOUCH
(22)
uint8_t pin()
Used for inheritance.
uint8_t swPinModeNumber()
Used for ineheritance.
bool digitalRead()
Returns the debounced state of the input.
uint16_t readDurationInTrueState_mS()
return the number of mS that the debounced input has been in true state
int16_t makeDigital(uint16_t touchLimit, uint16_t noTouchLimit, uint16_t touchValue, uint16_t noTouchValue, bool invert, uint16_t debounceCount)
Make a cap touch behave like a digital button.
int16_t makeDigital(uint16_t touchLimit, uint16_t noTouchLimit)
Make a cap touch behave like a digital button.
uint16_t readDurationInFalseState_mS()
return the number of mS that the debounced input has been in false state
SerialWombat18CapTouch(SerialWombatChip &serialWombat)
Instantiate a SerialWombat18CapTouch class on a specified Serial Wombat Chip.
bool readTransitionsState(bool resetTransitionCounts=true)
Queries the number of transistions that have occured on the debounced input.
int16_t begin(uint8_t pin, uint16_t chargeTime, uint16_t delay=10)
Initialize the SerialWombat18CapTouch instance with a given charge Time in uS.
uint16_t transitions
Number of transitions returned by last call to readTransitionsState()
SerialWombatAbstractProcessedInput(SerialWombatChip &sw)
Constructor for the SerialWombatAbstractScaledOutput Class.
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
SerialWombatChip & _sw
SerialWombatPin(SerialWombatChip &serialWombatChip)
Instantiates a Serial Wombat Pin.