Skip to content

Commit 7398373

Browse files
author
Nathan Seidle
committed
Adding write functions for global print usage
1 parent ee9f2a3 commit 7398373

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

libraries/SoftwareSerial/src/SoftwareSerial.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ void SoftwareSerial::begin(uint32_t baudRate, HardwareSerial_Config_e SSconfig)
138138

139139
txSysTicksPerStopBit = txSysTicksPerBit * _stopBits;
140140

141-
Serial.printf("sysTicksPerBit: %d\n", txSysTicksPerBit);
142-
143141
//Clear pin change interrupt
144142
am_hal_gpio_interrupt_clear(AM_HAL_GPIO_BIT(_rxPad));
145143

@@ -194,7 +192,8 @@ bool SoftwareSerial::overflow()
194192
return (false);
195193
}
196194

197-
void SoftwareSerial::write(uint8_t toSend)
195+
//Required for print
196+
size_t SoftwareSerial::write(uint8_t toSend)
198197
{
199198
//See if we are going to overflow buffer
200199
uint8_t nextSpot = (txBufferHead + 1) % AP3_SS_BUFFER_SIZE;
@@ -225,6 +224,22 @@ void SoftwareSerial::write(uint8_t toSend)
225224
}
226225
}
227226

227+
size_t SoftwareSerial::write(const uint8_t *buffer, size_t size)
228+
{
229+
for (uint16_t x = 0; x < size; x++)
230+
{
231+
write(buffer[x]);
232+
}
233+
return (size);
234+
}
235+
236+
size_t SoftwareSerial::write(const char *str)
237+
{
238+
if (str == NULL)
239+
return 0;
240+
return write((const uint8_t *)str, strlen(str));
241+
}
242+
228243
//Starts the transmission of the next available byte from the buffer
229244
void SoftwareSerial::beginTX()
230245
{

libraries/SoftwareSerial/src/SoftwareSerial.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
#define TIMER_FREQ 3000000L
4242

43-
class SoftwareSerial
43+
class SoftwareSerial : public Print
4444
{
4545
public:
4646
SoftwareSerial(uint8_t rxPin, uint8_t txPin, bool invertLogic = false);
@@ -63,7 +63,11 @@ class SoftwareSerial
6363
void rxBit(void);
6464
void rxEndOfByte(void);
6565

66-
void write(uint8_t toSend);
66+
virtual size_t write(uint8_t toSend);
67+
68+
virtual size_t write(const uint8_t *buffer, size_t size);
69+
virtual size_t write(const char *str);
70+
6771
void beginTX();
6872
void calcParityBit();
6973
void txHandler(void);

0 commit comments

Comments
 (0)