Serial Wombat Arduino Library
Loading...
Searching...
No Matches
SerialWombatQueuedPulseOutput.h
Go to the documentation of this file.
1#pragma once
2/*
3Copyright 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
31
34
57
59{
60 public:
65 SerialWombatQueuedPulseOutput(SerialWombatChip &serialWombatChip):SerialWombatPin(serialWombatChip){}
66
75 */
76 int16_t begin(uint8_t pin, bool initialState = 0, bool idleState = 0, bool unitsMs = 0, uint16_t QueueIndex = 0xFFFF)
77 {
78 _pin = pin;
80 return (initPacketNoResponse(0,(uint8_t) initialState, idleState,unitsMs,SW_LE16(QueueIndex)));
81 }
82
89 */
90 int16_t queuePulses(uint16_t firstPulse, uint16_t secondPulse = 0, bool emptyQueueFirst = false)
91 {
92 uint8_t tx[] =
93 {
95 _pin,
97 SW_LE16(firstPulse),
98 SW_LE16(secondPulse),
99 0x55
100 };
101 if (emptyQueueFirst)
102 {
103 tx[7] = 0x01;
104 }
105 uint8_t rx[8];
106 int16_t result = _sw.sendPacket(tx, rx);
107 if (result < 0)
108 {
109 return (result);
110 }
111 else
112 {
113 return (rx[3]);
114 }
115 }
116
121 */
122 int16_t pause(bool paused)
123 {
124 return (initPacketNoResponse(2,(uint8_t) paused));
125 }
126
128 {
129 uint8_t tx[] =
130 {
132 _pin,
133 _pinMode,
134 SW_LE16(0),
135 SW_LE16(0),
136 0x55
137 };
138 uint8_t rx[8];
139 int16_t result = _sw.sendPacket(tx, rx);
140 if (result < 0)
141 {
142 return (result);
143 }
144 else
145 {
146 return (rx[4]);
147 }
148 }
149
151 {
152 uint8_t tx[] =
153 {
155 _pin,
156 _pinMode,
157 SW_LE16(0),
158 SW_LE16(0),
159 0x55
160 };
161 uint8_t rx[8];
162 int16_t result = _sw.sendPacket(tx, rx);
163 if (result < 0)
164 {
165 return (result);
166 }
167 else
168 {
169 return (rx[5]);
170 }
171 }
172
173};
#define SW_LE16(_a)
Convert a uint16_t to two bytes in little endian format for array initialization.
@ PIN_MODE_QUEUED_PULSE_OUTPUT
(34)
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.
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 queuePulses(uint16_t firstPulse, uint16_t secondPulse=0, bool emptyQueueFirst=false)
Add a pulse or two pulses to the queue /.
SerialWombatQueuedPulseOutput(SerialWombatChip &serialWombatChip)
Class constructor for SerialWombatQueuedPulseOutput pin mode.
int16_t pause(bool paused)
Pause or unpause the generation of new pulses /.
int16_t begin(uint8_t pin, bool initialState=0, bool idleState=0, bool unitsMs=0, uint16_t QueueIndex=0xFFFF)
Initialize a queued pulse output mode /.