Serial Wombat Arduino Library
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 
59 {
60  public:
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 
81  uint8_t tx[] =
82  {
84  _pin,
85  _pinMode,
86  initialState,
87  idleState,
88  unitsMs,
89  SW_LE16(QueueIndex)
90  };
91  uint8_t rx[8];
92  int16_t result = _sw.sendPacket(tx, rx);
93  return (result);
94  }
95 
101 
102  int16_t queuePulses(uint16_t firstPulse, uint16_t secondPulse = 0)
103  {
104  uint8_t tx[] =
105  {
107  _pin,
108  _pinMode,
109  SW_LE16(firstPulse),
110  SW_LE16(secondPulse),
111  0x55
112  };
113  uint8_t rx[8];
114  int16_t result = _sw.sendPacket(tx, rx);
115  if (result < 0)
116  {
117  return (result);
118  }
119  else
120  {
121  return (rx[3]);
122  }
123  }
124 
129 
130  int16_t pause(bool paused)
131  {
132  uint8_t tx[] =
133  {
135  _pin,
136  _pinMode,
137  paused,
138  0x55,0x55,0x55, 0x55
139  };
140  int16_t result = _sw.sendPacket(tx);
141  return (result);
142  }
143 };
SerialWombatChip
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
Definition: SerialWombat.h:286
SerialWombatQueuedPulseOutput::queuePulses
int16_t queuePulses(uint16_t firstPulse, uint16_t secondPulse=0)
Add a pulse or two pulses to the queue /.
Definition: SerialWombatQueuedPulseOutput.h:102
SerialWombatCommands::CONFIGURE_PIN_MODE0
@ CONFIGURE_PIN_MODE0
(200)
SerialWombatPin::_sw
SerialWombatChip & _sw
Definition: SerialWombatPin.h:134
SerialWombat.h
PIN_MODE_QUEUED_PULSE_OUTPUT
@ PIN_MODE_QUEUED_PULSE_OUTPUT
(34)
Definition: SerialWombat.h:273
SerialWombatPin
Describes a Serial Wombat Pin. Is base class for other pin modes.
Definition: SerialWombatPin.h:38
SerialWombatQueuedPulseOutput::pause
int16_t pause(bool paused)
Pause or unpause the generation of new pulses /.
Definition: SerialWombatQueuedPulseOutput.h:130
SerialWombatPin::_pinMode
uint8_t _pinMode
Definition: SerialWombatPin.h:135
SerialWombatChip::sendPacket
int sendPacket(uint8_t tx[], uint8_t rx[])
Send an 8 byte packet to the Serial Wombat chip and wait for 8 bytes back.
Definition: SerialWombat.cpp:115
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
SerialWombatPin::pin
uint8_t pin()
Returns the current SW pin number. Used primarily for virtual calls by derived classes.
Definition: SerialWombatPin.h:121
SerialWombatPin::_pin
uint8_t _pin
Definition: SerialWombatPin.h:133
SerialWombatQueuedPulseOutput::SerialWombatQueuedPulseOutput
SerialWombatQueuedPulseOutput(SerialWombatChip &sw)
Class constructor for SerialWombatQueuedPulseOutput pin mode.
Definition: SerialWombatQueuedPulseOutput.h:65
SerialWombatCommands::CONFIGURE_PIN_MODE2
@ CONFIGURE_PIN_MODE2
(202)
SW_LE16
#define SW_LE16(_a)
Convert a uint16_t to two bytes in little endian format for array initialization.
Definition: SerialWombat.h:41
SerialWombatCommands::CONFIGURE_PIN_MODE1
@ CONFIGURE_PIN_MODE1
(201)
SerialWombatQueuedPulseOutput
A Class which outputs pulses of a duration stored in a queue.
Definition: SerialWombatQueuedPulseOutput.h:58