Serial Wombat Arduino Library

Loading...
Searching...
No Matches
SerialWombatQueuedPulseOutput.h
Go to the documentation of this file.
1#pragma once
2/*
3 Copyright 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
34
57
58 class SerialWombatQueuedPulseOutput : public SerialWombatPin
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;
79 _pinMode = PIN_MODE_QUEUED_PULSE_OUTPUT;
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 {
94 (uint8_t)SerialWombatCommands::CONFIGURE_PIN_MODE1,
95 _pin,
96 _pinMode,
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
127 int16_t queueEntriesFilled()
128 {
129 uint8_t tx[] =
130 {
131 (uint8_t)SerialWombatCommands::CONFIGURE_PIN_MODE1,
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
150 int16_t queueEntriesFree()
151 {
152 uint8_t tx[] =
153 {
154 (uint8_t)SerialWombatCommands::CONFIGURE_PIN_MODE1,
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};
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
SerialWombatCommands::CONFIGURE_PIN_MODE1
@ CONFIGURE_PIN_MODE1
(201)
Definition SerialWombat.h:238
PIN_MODE_QUEUED_PULSE_OUTPUT
@ PIN_MODE_QUEUED_PULSE_OUTPUT
(34)
Definition SerialWombat.h:292
SerialWombatChip
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
Definition SerialWombat.h:315
SerialWombatPin::_sw
SerialWombatChip & _sw
Definition SerialWombatPin.h:214
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
SerialWombatQueuedPulseOutput::queueEntriesFree
int16_t queueEntriesFree()
Definition SerialWombatQueuedPulseOutput.h:150
SerialWombatQueuedPulseOutput::queuePulses
int16_t queuePulses(uint16_t firstPulse, uint16_t secondPulse=0, bool emptyQueueFirst=false)
Add a pulse or two pulses to the queue /.
Definition SerialWombatQueuedPulseOutput.h:90
SerialWombatQueuedPulseOutput::SerialWombatQueuedPulseOutput
SerialWombatQueuedPulseOutput(SerialWombatChip &serialWombatChip)
Class constructor for SerialWombatQueuedPulseOutput pin mode.
Definition SerialWombatQueuedPulseOutput.h:65
SerialWombatQueuedPulseOutput::pause
int16_t pause(bool paused)
Pause or unpause the generation of new pulses /.
Definition SerialWombatQueuedPulseOutput.h:122
SerialWombatQueuedPulseOutput::begin
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 /.
Definition SerialWombatQueuedPulseOutput.h:76
SerialWombatQueuedPulseOutput::queueEntriesFilled
int16_t queueEntriesFilled()
Definition SerialWombatQueuedPulseOutput.h:127