Serial Wombat Arduino Library

Loading...
Searching...
No Matches
SerialWombatIRTx.h
Go to the documentation of this file.
1#pragma once
2#include "Stream.h"
3#include "SerialWombat.h"
6
7/*
8 Copyright 2026 Broadwell Consulting Inc.
9
10"Serial Wombat" is a registered trademark of Broadwell Consulting Inc. in
11 the United States. See SerialWombat.com for usage guidance.
12
13 Permission is hereby granted, free of charge, to any person obtaining a
14 * copy of this software and associated documentation files (the "Software"),
15 * to deal in the Software without restriction, including without limitation
16 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 * and/or sell copies of the Software, and to permit persons to whom the
18 * Software is furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in
21 * all copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
27 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
28 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 * OTHER DEALINGS IN THE SOFTWARE.
30*/
31
61
62 class SerialWombatIRTx :
63 public Stream, public SerialWombatPin
64{
65 public:
70 SerialWombatIRTx(SerialWombatChip& serialWombat):SerialWombatPin(serialWombat){}
71
72
79 int16_t begin( uint8_t pin, uint16_t address , uint8_t irMode = 0)
80 {
81 (void) irMode;
82 _pin = pin;
83 _pinMode = PIN_MODE_IRTX;
84 _address = address;
85 uint8_t tx[8] = { 200, _pin,_pinMode, 0,0x55,0x55,0x55, 0x55 };
86 uint8_t rx[8];
87 return _sw.sendPacket(tx, rx);
88
89 }
90
96 int16_t enableSW8b38KHzWP6()
97{
98 uint8_t tx[8] = { 220, _pin,_pinMode,0x55,0x55,0x55, 0x55,0x55 };
99 uint8_t rx[8];
100 return _sw.sendPacket(tx, rx);
101
102}
103
108 int sendMessage(uint8_t command, int32_t address = -1, uint8_t repeat = 0)
109{
110 uint8_t peektx[8] = { 203, _pin,_pinMode,0x55,0x55,0x55,0x55,0x55 };
111 uint8_t peekrx[8];
112 _sw.sendPacket(peektx, peekrx);
113 if (address >= 0)
114 {
115 _address = (uint16_t)address;
116 }
117
118 if (peekrx[3] >= 4)
119 {
120
121 uint8_t tx[8] = { 201, _pin,_pinMode,4,(uint8_t)(_address &0xFF),(uint8_t)(_address >>8),command,repeat };
122 uint8_t rx[8];
123 _sw.sendPacket(tx,rx);
124 return (1);
125 }
126 else
127 {
128 return -1;
129 }
130}
131
135 virtual int available()
136{
137 return(0);
138}
139
143 virtual int read()
144{
145 return -1;
146}
147
150 virtual void flush()
151{
152}
153
157 virtual int peek()
158{
159 return (-1);
160}
161
166 virtual size_t write(uint8_t data)
167{
168 if (sendMessage(data) > 0)
169 {
170 return (1);
171 }
172 else
173 {
174 return 0;
175 }
176}
177
190 virtual size_t write(const uint8_t* buffer, size_t size)
191{
192 size_t bytesSent;
193
194 for (bytesSent = 0; bytesSent < size ;)
195 {
196 size_t result = write(buffer[bytesSent]);
197 if (result < 1)
198 {
199 return (bytesSent);
200 }
201
202 }
203 return (bytesSent);
204}
205
209 virtual int availableForWrite()
210{
211 uint8_t peektx[8] = { 203, _pin,_pinMode,0x55,0x55,0x55,0x55,0x55 };
212 uint8_t peekrx[8];
213 _sw.sendPacket(peektx, peekrx);
214 return peekrx[3];
215}
216
220 virtual size_t readBytes(char* buffer, size_t length)
221{
222 (void) buffer;
223 (void) length;
224 return (0);
225}
226
227
231 virtual void setTimeout(long timeout_mS)
232{
233 (void) timeout_mS;
234}
235 protected:
236 uint16_t _address;
237};
238
239
SerialWombat.h
PIN_MODE_IRTX
@ PIN_MODE_IRTX
(38)
Definition SerialWombat.h:295
SerialWombatChip
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
Definition SerialWombat.h:315
SerialWombatIRTx::readBytes
virtual size_t readBytes(char *buffer, size_t length)
This function exists to satisfy stream requirements, and always returns 0.
Definition SerialWombatIRTx.h:220
SerialWombatIRTx::begin
int16_t begin(uint8_t pin, uint16_t address, uint8_t irMode=0)
Definition SerialWombatIRTx.h:79
SerialWombatIRTx::availableForWrite
virtual int availableForWrite()
Queries the SerialWombatUART for the amount of free TX queue space.
Definition SerialWombatIRTx.h:209
SerialWombatIRTx::setTimeout
virtual void setTimeout(long timeout_mS)
This function exists to satisfy stream requirements.
Definition SerialWombatIRTx.h:231
SerialWombatIRTx::sendMessage
int sendMessage(uint8_t command, int32_t address=-1, uint8_t repeat=0)
Write a byte to the SerialWombatIRTx for Transmit as a command using the prior specified address.
Definition SerialWombatIRTx.h:108
SerialWombatIRTx::write
virtual size_t write(uint8_t data)
Write a byte to the SerialWombatIRTx for Transmit as a command using the prior specified address.
Definition SerialWombatIRTx.h:166
SerialWombatIRTx::peek
virtual int peek()
This function exists to satisfy stream requirements, and always returns -1.
Definition SerialWombatIRTx.h:157
SerialWombatIRTx::write
virtual size_t write(const uint8_t *buffer, size_t size)
Write bytes to the SerialWombatUART for Transmit.
Definition SerialWombatIRTx.h:190
SerialWombatIRTx::_address
uint16_t _address
Definition SerialWombatIRTx.h:236
SerialWombatIRTx::flush
virtual void flush()
Discard all received bytes. Does nothing, exists to satisfy stream requirements.
Definition SerialWombatIRTx.h:150
SerialWombatIRTx::read
virtual int read()
This function exists to satisfy stream requirements, and always returns -1.
Definition SerialWombatIRTx.h:143
SerialWombatIRTx::available
virtual int available()
This function exists to satisfy stream requirements, and always returns 0.
Definition SerialWombatIRTx.h:135
SerialWombatIRTx::enableSW8b38KHzWP6
int16_t enableSW8b38KHzWP6()
Causes pin WP6 on the Serial Wombat 8B to generate a 38kHz carrier wave.
Definition SerialWombatIRTx.h:96
SerialWombatIRTx::SerialWombatIRTx
SerialWombatIRTx(SerialWombatChip &serialWombat)
Constructor for the SerialWombatIRTx class.
Definition SerialWombatIRTx.h:70
SerialWombatPin::_sw
SerialWombatChip & _sw
Definition SerialWombatPin.h:214
SerialWombatPin::SerialWombatPin
SerialWombatPin(SerialWombatChip &serialWombatChip)
Instantiates a Serial Wombat Pin.
Definition SerialWombatPin.h:45
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