Serial Wombat Arduino Library

Loading...
Searching...
No Matches
SerialWombatPulseOnChange.h
Go to the documentation of this file.
1#pragma once
2/*
3 Copyright 2022-2024 Broadwell Consulting Inc.
4
5"Serial Wombat" is a registered trademark of Broadwell Consulting Inc. in
6 the United States. See SerialWombat.com for usage guidance.
7
8 Permission 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
15 The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17
18 THE 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
31 class SerialWombat;
32
35
81
82 class SerialWombatPulseOnChange : public SerialWombatPin
83{
84 public:
89 SerialWombatPulseOnChange(SerialWombatChip& serialWombat):SerialWombatPin(serialWombat)
90 {
91 _pinMode = PIN_MODE_PULSE_ON_CHANGE;
92 }
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);
318 private:
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
SerialWombat.h
SW_LE16
#define SW_LE16(_a)
Convert a uint16_t to two bytes in little endian format for array initialization.
Definition SerialWombat.h:46
PIN_MODE_PULSE_ON_CHANGE
@ PIN_MODE_PULSE_ON_CHANGE
(25)
Definition SerialWombat.h:283
SerialWombatPinState_t
SerialWombatPinState_t
Definition SerialWombat.h:57
SW_HIGH
@ SW_HIGH
Definition SerialWombat.h:59
SW_LOW
@ SW_LOW
Definition SerialWombat.h:58
SerialWombatChip
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
Definition SerialWombat.h:315
SerialWombat
This class name is depricated. Do not use for new development. Use SerialWombatChip instead.
Definition SerialWombat.h:1745
SerialWombatPin::SerialWombatPin
SerialWombatPin(SerialWombatChip &serialWombatChip)
Instantiates a Serial Wombat Pin.
Definition SerialWombatPin.h:45
SerialWombatPin::initPacketNoResponse
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)
Definition SerialWombatPin.h:130
SerialWombatPin::_pin
uint8_t _pin
Definition SerialWombatPin.h:213
SerialWombatPin::pin
uint8_t pin()
Returns the current SW pin number. Used primarily for virtual calls by derived classes.
Definition SerialWombatPin.h:120
SerialWombatPin::_pinMode
uint8_t _pinMode
Definition SerialWombatPin.h:215
SerialWombatPulseOnChange::setEntryOnPinsEqual
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...
Definition SerialWombatPulseOnChange.h:220
SerialWombatPulseOnChange::setEntryOnGreaterThanValue
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.
Definition SerialWombatPulseOnChange.h:190
SerialWombatPulseOnChange::setEntryOnPinOutsideRange
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.
SerialWombatPulseOnChange::setEntryOnPinCrossDescending
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.
SerialWombatPulseOnChange::setEntryOnIncrease
int16_t setEntryOnIncrease(uint8_t entryID, uint8_t sourcePin)
Configure a change entry to pulse when a pin or public data increases.
Definition SerialWombatPulseOnChange.h:137
SerialWombatPulseOnChange::setEntryOnEqualValue
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.
Definition SerialWombatPulseOnChange.h:162
SerialWombatPulseOnChange::setEntryOnNotEqualValue
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.
Definition SerialWombatPulseOnChange.h:206
SerialWombatPulseOnChange::begin
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.
Definition SerialWombatPulseOnChange.h:107
SerialWombatPulseOnChange::setEntryOnPinGTPin
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...
SerialWombatPulseOnChange::setEntryOnPinLTPin
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'...
SerialWombatPulseOnChange::setEntryOnPinsNotEqual
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...
Definition SerialWombatPulseOnChange.h:235
SerialWombatPulseOnChange::setEntryOnPinCrossAscending
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.
SerialWombatPulseOnChange::setEntryOnDecrease
int16_t setEntryOnDecrease(uint8_t entryID, uint8_t sourcePin)
Configure a change entry to pulse when a pin or public data Decreases.
Definition SerialWombatPulseOnChange.h:149
SerialWombatPulseOnChange::setEntryOnPinWithinRange
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::SerialWombatPulseOnChange
SerialWombatPulseOnChange(SerialWombatChip &serialWombat)
Class constructor for SerialWombatPulseOnChange.
Definition SerialWombatPulseOnChange.h:89
SerialWombatPulseOnChange::setEntryOnLessThanValue
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.
Definition SerialWombatPulseOnChange.h:176
SerialWombatPulseOnChange::setEntryOnChange
int16_t setEntryOnChange(uint8_t entryID, uint8_t sourcePin)
Configure a change entry to pulse when a pin or public data changes.
Definition SerialWombatPulseOnChange.h:125
SerialWombatPulseOnChange::setEntryOnPinCrossValue
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.