Serial Wombat Arduino Library
Loading...
Searching...
No Matches
SerialWombatPulseOnChange.h
Go to the documentation of this file.
1#pragma once
2/*
3Copyright 2022-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
28#include <stdint.h>
29#include "SerialWombat.h"
30
31class SerialWombat;
32
35
81
83{
84public:
93
94
107 int16_t begin(uint8_t pin, SerialWombatPinState_t activeMode = SW_HIGH, SerialWombatPinState_t inactiveMode = SW_LOW, uint16_t pulseOnTime = 50, uint16_t pulseOffTime = 50, uint8_t orNotAnd = 1, uint16_t PWMperiod = 0, uint16_t PWMdutyCycle = 0x8000)
108{
109 int16_t result;
110 _pin = pin;
111
112 result = initPacketNoResponse(0,(uint8_t)activeMode,(uint8_t)inactiveMode, orNotAnd); if (result < 0) { return result; }
113 result = initPacketNoResponse(1,pulseOnTime,pulseOffTime); if (result < 0) { return result; }
114 return initPacketNoResponse(2,PWMperiod,PWMdutyCycle);
115}
116
125 int16_t setEntryOnChange(uint8_t entryID, uint8_t sourcePin)
126{
127 return setEntryMode(entryID, sourcePin, 0);
128}
129
137 int16_t setEntryOnIncrease(uint8_t entryID, uint8_t sourcePin)
138{
139 return setEntryMode(entryID, sourcePin, 1);
140}
141
149 int16_t setEntryOnDecrease(uint8_t entryID, uint8_t sourcePin)
150{
151 return setEntryMode(entryID, sourcePin, 2);
152}
153
162 int16_t setEntryOnEqualValue(uint8_t entryID, uint8_t sourcePin, uint16_t value)
163{
164 int16_t result = setEntryParams(entryID, value, 0); if (result < 0) return result;
165 return setEntryMode(entryID, sourcePin, 3);
166}
167
176 int16_t setEntryOnLessThanValue(uint8_t entryID, uint8_t sourcePin, uint16_t value)
177 {
178 int16_t result = setEntryParams(entryID, value, 0); if (result < 0) return result;
179 return setEntryMode(entryID, sourcePin, 4);
180 }
181
190 int16_t setEntryOnGreaterThanValue(uint8_t entryID, uint8_t sourcePin, uint16_t value)
191 {
192 int16_t result = setEntryParams(entryID, value, 0); if (result < 0) return result;
193 return setEntryMode(entryID, sourcePin, 5);
194 }
195
196
206 int16_t setEntryOnNotEqualValue(uint8_t entryID, uint8_t sourcePin, uint16_t value)
207 {
208 int16_t result = setEntryParams(entryID, value, 0); if (result < 0) return result;
209 return setEntryMode(entryID, sourcePin, 6);
210 }
211
220 int16_t setEntryOnPinsEqual(uint8_t entryID, uint8_t sourcePin, uint8_t secondPin )
221 {
222 int16_t result = setEntryParams(entryID, secondPin, 0); if (result < 0) return result;
223 return setEntryMode(entryID, sourcePin, 7);
224 }
225
235 int16_t setEntryOnPinsNotEqual(uint8_t entryID, uint8_t sourcePin, uint8_t secondPin )
236 {
237 int16_t result = setEntryParams(entryID, secondPin, 0); if (result < 0) return result;
238 return setEntryMode(entryID, sourcePin, 10);
239 }
240
250 int16_t setEntryOnPinGTPin(uint8_t entryID, uint8_t sourcePin, uint8_t secondPin );
251
261 int16_t setEntryOnPinLTPin(uint8_t entryID, uint8_t sourcePin, uint8_t secondPin );
271 int16_t setEntryOnPinCrossValue(uint8_t entryID, uint8_t sourcePin, uint16_t value);
272
282 int16_t setEntryOnPinCrossAscending(uint8_t entryID, uint8_t sourcePin, uint16_t value);
283
293 int16_t setEntryOnPinCrossDescending(uint8_t entryID, uint8_t sourcePin, uint16_t value);
294
305 int16_t setEntryOnPinWithinRange(uint8_t entryID, uint8_t sourcePin, uint16_t lowValue, uint16_t highValue);
306
317 int16_t setEntryOnPinOutsideRange(uint8_t entryID, uint8_t sourcePin, uint16_t lowValue, uint16_t highValue);
318private:
319 int16_t setEntryParams(uint8_t entryID, uint16_t firstParam, uint16_t secondParam)
320 {
321 return initPacketNoResponse(3, entryID, SW_LE16(firstParam), SW_LE16(secondParam));
322 }
323 int16_t setEntryMode(uint8_t entryID, uint8_t pin, uint8_t mode)
324 {
325 return initPacketNoResponse(4, entryID, mode,pin);
326 }
327};
328
#define SW_LE16(_a)
Convert a uint16_t to two bytes in little endian format for array initialization.
@ PIN_MODE_PULSE_ON_CHANGE
(25)
SerialWombatPinState_t
@ SW_HIGH
@ SW_LOW
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
This class name is depricated. Do not use for new development. Use SerialWombatChip instead.
SerialWombatPin(SerialWombatChip &serialWombatChip)
Instantiates a Serial Wombat Pin.
int16_t initPacketNoResponse(uint8_t packetNumber, uint8_t param0=0x55, uint8_t param1=0x55, uint8_t param2=0x55, uint8_t param3=0x55, uint8_t param4=0x55)
uint8_t pin()
Returns the current SW pin number. Used primarily for virtual calls by derived classes.
int16_t setEntryOnPinsEqual(uint8_t entryID, uint8_t sourcePin, uint8_t secondPin)
Configure a change entry to pulse when a pin or public data equals a second pin or public data's valu...
int16_t setEntryOnGreaterThanValue(uint8_t entryID, uint8_t sourcePin, uint16_t value)
Configure a change entry to pulse when a pin or public data is above a specified value.
int16_t setEntryOnPinOutsideRange(uint8_t entryID, uint8_t sourcePin, uint16_t lowValue, uint16_t highValue)
Configure a change entry to pulse when a pin or public data is within a specified range.
int16_t setEntryOnPinCrossDescending(uint8_t entryID, uint8_t sourcePin, uint16_t value)
Configure a change entry to pulse when a pin or public data falls below a specified value.
int16_t setEntryOnIncrease(uint8_t entryID, uint8_t sourcePin)
Configure a change entry to pulse when a pin or public data increases.
int16_t setEntryOnEqualValue(uint8_t entryID, uint8_t sourcePin, uint16_t value)
Configure a change entry to pulse when a pin or public data equals a specified value.
int16_t setEntryOnNotEqualValue(uint8_t entryID, uint8_t sourcePin, uint16_t value)
Configure a change entry to pulse when a pin or public data is not equal to a specified value.
int16_t begin(uint8_t pin, SerialWombatPinState_t activeMode=SW_HIGH, SerialWombatPinState_t inactiveMode=SW_LOW, uint16_t pulseOnTime=50, uint16_t pulseOffTime=50, uint8_t orNotAnd=1, uint16_t PWMperiod=0, uint16_t PWMdutyCycle=0x8000)
Initialization routine for SerialWombatPulseOnChange.
int16_t setEntryOnPinGTPin(uint8_t entryID, uint8_t sourcePin, uint8_t secondPin)
Configure a change entry to pulse when a pin or public data is greater than a second pin or public da...
int16_t setEntryOnPinLTPin(uint8_t entryID, uint8_t sourcePin, uint8_t secondPin)
Configure a change entry to pulse when a pin or public data is less than a second pin or public data'...
int16_t setEntryOnPinsNotEqual(uint8_t entryID, uint8_t sourcePin, uint8_t secondPin)
Configure a change entry to pulse when a pin or public data is not equal to a second pin or public da...
int16_t setEntryOnPinCrossAscending(uint8_t entryID, uint8_t sourcePin, uint16_t value)
Configure a change entry to pulse when a pin or public data rises above a specified value.
int16_t setEntryOnDecrease(uint8_t entryID, uint8_t sourcePin)
Configure a change entry to pulse when a pin or public data Decreases.
int16_t setEntryOnPinWithinRange(uint8_t entryID, uint8_t sourcePin, uint16_t lowValue, uint16_t highValue)
Configure a change entry to pulse when a pin or public data is within a specified range.
SerialWombatPulseOnChange(SerialWombatChip &serialWombat)
Class constructor for SerialWombatPulseOnChange.
int16_t setEntryOnLessThanValue(uint8_t entryID, uint8_t sourcePin, uint16_t value)
Configure a change entry to pulse when a pin or public data is below a specified value.
int16_t setEntryOnChange(uint8_t entryID, uint8_t sourcePin)
Configure a change entry to pulse when a pin or public data changes.
int16_t setEntryOnPinCrossValue(uint8_t entryID, uint8_t sourcePin, uint16_t value)
Configure a change entry to pulse when a pin or public data crosses a specified value.