Skip to content

Commit 45437b0

Browse files
authored
Fix outdated README, source comments for readParity. Fix dropped 0xff octets. (#205)
* Fixes #203 * Check for hidden stop bit at the end of each rxBits. Fixes first-octet in session dropped issue, and intermittently dropped octets, in particular the delay(2000), issue. * Fixes #204 * Use precise enum value identifier in sample code.
1 parent 7fdef9b commit 45437b0

File tree

5 files changed

+12
-13
lines changed

5 files changed

+12
-13
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ argument to ``begin()``. Word lengths can be set to between 5 and 8 bits, parity
7979
can be N(one), O(dd) or E(ven) and 1 or 2 stop bits can be used. The default is
8080
``SWSERIAL_8N1`` using 8 bits, no parity and 1 stop bit but any combination can
8181
be used, e.g. ``SWSERIAL_7E2``. If using EVEN or ODD parity, any parity errors
82-
can be detected with the ``peekParityError()`` function. Note that parity
83-
checking must be done before ``read()``, as the parity information is removed
84-
from the buffer when reading the corresponding byte.
82+
can be detected with the ``readParity()`` and ``parityEven()`` or ``parityOdd()``
83+
functions respectively. Note that the result of ``readParity()`` always applies
84+
to the preceding ``read()`` or ``peek()`` call, and is undefined if they report
85+
no data or an error.
8586

8687
To allow flexible 9-bit and data/addressing protocols, the additional parity
8788
modes MARK and SPACE are also available. Furthermore, the parity mode can be
@@ -93,8 +94,8 @@ up SoftwareSerial with parity mode SPACE, e.g. ``SWSERIAL_8S1``. This will add a
9394
parity bit to every byte sent, setting it to logical zero (SPACE parity).
9495

9596
To detect incoming bytes with the parity bit set (MARK parity), use the
96-
``peekParityError()`` function. To send a byte with the parity bit set, just add
97-
``MARK`` as the second argument when writing, e.g. ``write(ch, MARK)``.
97+
``readParity()`` function. To send a byte with the parity bit set, just add
98+
``MARK`` as the second argument when writing, e.g. ``write(ch, SWSERIAL_PARITY_MARK)``.
9899

99100
## Using and updating EspSoftwareSerial in the esp8266com/esp8266 Arduino build environment
100101

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "EspSoftwareSerial",
3-
"version": "6.12.0",
3+
"version": "6.12.1",
44
"keywords": [
55
"serial", "io", "softwareserial"
66
],

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=EspSoftwareSerial
2-
version=6.12.0
2+
version=6.12.1
33
author=Dirk Kaar, Peter Lerup
44
maintainer=Dirk Kaar <dok@dok-net.net>
55
sentence=Implementation of the Arduino software serial for ESP8266/ESP32.

src/SoftwareSerial.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,6 @@ int SoftwareSerial::peek() {
421421
}
422422

423423
void SoftwareSerial::rxBits() {
424-
int isrAvail = m_isrBuffer->available();
425424
#ifdef ESP8266
426425
if (m_isrOverflow.load()) {
427426
m_overflow = true;
@@ -433,19 +432,18 @@ void SoftwareSerial::rxBits() {
433432
}
434433
#endif
435434

435+
m_isrBuffer->for_each([this](const uint32_t& isrCycle) { rxBits(isrCycle); });
436+
436437
// stop bit can go undetected if leading data bits are at same level
437438
// and there was also no next start bit yet, so one byte may be pending.
438-
// low-cost check first
439-
if (!isrAvail && m_rxCurBit >= -1 && m_rxCurBit < m_pduBits - m_stopBits) {
439+
if (m_rxCurBit >= -1 && m_rxCurBit < m_pduBits - m_stopBits) {
440440
uint32_t detectionCycles = (m_pduBits - m_stopBits - m_rxCurBit) * m_bitCycles;
441441
if (ESP.getCycleCount() - m_isrLastCycle > detectionCycles) {
442442
// Produce faux stop bit level, prevents start bit maldetection
443443
// cycle's LSB is repurposed for the level bit
444444
rxBits(((m_isrLastCycle + detectionCycles) | 1) ^ m_invert);
445445
}
446446
}
447-
448-
m_isrBuffer->for_each([this](const uint32_t& isrCycle) { rxBits(isrCycle); });
449447
}
450448

451449
void SoftwareSerial::rxBits(const uint32_t& isrCycle) {

src/SoftwareSerial.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class SoftwareSerial : public Stream {
138138
}
139139
int peek() override;
140140
int read() override;
141-
/// @returns The verbatim parity bit associated with the last read() or peek() call
141+
/// @returns The verbatim parity bit associated with the last successful read() or peek() call
142142
bool readParity()
143143
{
144144
return m_lastReadParity;

0 commit comments

Comments
 (0)