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
105 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)
106{
107 int16_t result;
108 _pin = pin;
109
110 result = initPacketNoResponse(0,(uint8_t)activeMode,(uint8_t)inactiveMode, orNotAnd); if (result < 0) { return result; }
111 result = initPacketNoResponse(1,pulseOnTime,pulseOffTime); if (result < 0) { return result; }
112 return initPacketNoResponse(2,PWMperiod,PWMdutyCycle);
113}
114
123 int16_t setEntryOnChange(uint8_t entryID, uint8_t sourcePin)
124{
125 return setEntryMode(entryID, sourcePin, 0);
126}
127
135 int16_t setEntryOnIncrease(uint8_t entryID, uint8_t sourcePin)
136{
137 return setEntryMode(entryID, sourcePin, 1);
138}
139
147 int16_t setEntryOnDecrease(uint8_t entryID, uint8_t sourcePin)
148{
149 return setEntryMode(entryID, sourcePin, 2);
150}
151
160 int16_t setEntryOnEqualValue(uint8_t entryID, uint8_t sourcePin, uint16_t value)
161{
162 int16_t result = setEntryParams(entryID, value, 0); if (result < 0) return result;
163 return setEntryMode(entryID, sourcePin, 3);
164}
165
174 int16_t setEntryOnLessThanValue(uint8_t entryID, uint8_t sourcePin, uint16_t value)
175 {
176 int16_t result = setEntryParams(entryID, value, 0); if (result < 0) return result;
177 return setEntryMode(entryID, sourcePin, 4);
178 }
179
188 int16_t setEntryOnGreaterThanValue(uint8_t entryID, uint8_t sourcePin, uint16_t value)
189 {
190 int16_t result = setEntryParams(entryID, value, 0); if (result < 0) return result;
191 return setEntryMode(entryID, sourcePin, 5);
192 }
193
194
204 int16_t setEntryOnNotEqualValue(uint8_t entryID, uint8_t sourcePin, uint16_t value)
205 {
206 int16_t result = setEntryParams(entryID, value, 0); if (result < 0) return result;
207 return setEntryMode(entryID, sourcePin, 6);
208 }
209
218 int16_t setEntryOnPinsEqual(uint8_t entryID, uint8_t sourcePin, uint8_t secondPin )
219 {
220 int16_t result = setEntryParams(entryID, secondPin, 0); if (result < 0) return result;
221 return setEntryMode(entryID, sourcePin, 7);
222 }
223
233 int16_t setEntryOnPinsNotEqual(uint8_t entryID, uint8_t sourcePin, uint8_t secondPin )
234 {
235 int16_t result = setEntryParams(entryID, secondPin, 0); if (result < 0) return result;
236 return setEntryMode(entryID, sourcePin, 10);
237 }
238
248 int16_t setEntryOnPinGTPin(uint8_t entryID, uint8_t sourcePin, uint8_t secondPin );
249
259 int16_t setEntryOnPinLTPin(uint8_t entryID, uint8_t sourcePin, uint8_t secondPin );
269 int16_t setEntryOnPinCrossValue(uint8_t entryID, uint8_t sourcePin, uint16_t value);
270
280 int16_t setEntryOnPinCrossAscending(uint8_t entryID, uint8_t sourcePin, uint16_t value);
281
291 int16_t setEntryOnPinCrossDescending(uint8_t entryID, uint8_t sourcePin, uint16_t value);
292
303 int16_t setEntryOnPinWithinRange(uint8_t entryID, uint8_t sourcePin, uint16_t lowValue, uint16_t highValue);
304
315 int16_t setEntryOnPinOutsideRange(uint8_t entryID, uint8_t sourcePin, uint16_t lowValue, uint16_t highValue);
316 private:
317 int16_t setEntryParams(uint8_t entryID, uint16_t firstParam, uint16_t secondParam)
318 {
319 return initPacketNoResponse(3, entryID, SW_LE16(firstParam), SW_LE16(secondParam));
320 }
321 int16_t setEntryMode(uint8_t entryID, uint8_t pin, uint8_t mode)
322 {
323 return initPacketNoResponse(4, entryID, mode,pin);
324 }
325};
326
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:41
PIN_MODE_PULSE_ON_CHANGE
@ PIN_MODE_PULSE_ON_CHANGE
(25)
Definition SerialWombat.h:273
SerialWombatPinState_t
SerialWombatPinState_t
Definition SerialWombat.h:52
SW_HIGH
@ SW_HIGH
Definition SerialWombat.h:54
SW_LOW
@ SW_LOW
Definition SerialWombat.h:53
SerialWombatChip
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
Definition SerialWombat.h:297
SerialWombat
This class name is depricated. Do not use for new development. Use SerialWombatChip instead.
Definition SerialWombat.h:1581
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:131
SerialWombatPin::_pin
uint8_t _pin
Definition SerialWombatPin.h:193
SerialWombatPin::pin
uint8_t pin()
Returns the current SW pin number. Used primarily for virtual calls by derived classes.
Definition SerialWombatPin.h:121
SerialWombatPin::_pinMode
uint8_t _pinMode
Definition SerialWombatPin.h:195
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:218
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:188
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:135
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:160
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:204
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:105
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:233
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:147
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:174
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:123
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.