Skip to content

Commit 21ae195

Browse files
committed
Improved distance protocol decoder
1 parent f0546dd commit 21ae195

File tree

9 files changed

+160
-109
lines changed

9 files changed

+160
-109
lines changed

.github/workflows/PlatformIoPublish.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,8 @@ jobs:
3131
env:
3232
PLATFORMIO_AUTH_TOKEN: ${{ secrets.PLATFORMIO_TOKEN }}
3333
run: |
34-
pio package pack
3534
pio package publish --owner arminjo --non-interactive
35+
# run: |
36+
# pio package pack
37+
# pio package publish --owner arminjo --non-interactive
38+

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ See also the commit log at github: https://github.com/Arduino-IRremote/Arduino-I
99
- Improved prints and documentation.
1010
- Added IrReceiver.restartAfterSend() and inserted it in every send(). Closes #989
1111
- Use IRAM_ATTR instead of deprecated ICACHE_RAM_ATTR for ESP8266.
12+
- Removed pulse width decoding from ir_DistanceProtocol.
1213

1314
## 3.6.1
1415
- Switched Bose internal protocol timing for 0 and 1 -> old 1 timing is now 0 and vice versa.

examples/IRDispatcherDemo/IRCommandDispatcher.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@
4242
* Enable this to see information on each call.
4343
* Since there should be no library which uses Serial, it should only be enabled for development purposes.
4444
*/
45-
#if defined(INFO)
45+
#if defined(INFO) && !defined(LOCAL_INFO)
4646
#define LOCAL_INFO
4747
#else
4848
//#define LOCAL_INFO // This enables info output only for this file
4949
#endif
50-
#if defined(DEBUG)
50+
#if defined(DEBUG) && !defined(LOCAL_DEBUG)
5151
#define LOCAL_DEBUG
5252
// Propagate debug level
5353
#define LOCAL_INFO

src/IRReceive.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ bool IRrecv::decode() {
388388
* Common decode functions
389389
**********************************************************************************************************************/
390390
/**
391-
* Decode pulse width protocols. Currently only used for sony protocol.
391+
* Decode pulse width protocols. Currently only used for sony protocol, which is LSB first.
392392
* The space (pause) has constant length, the length of the mark determines the bit value.
393393
* Each bit looks like: MARK_1 + SPACE -> 1 or : MARK_0 + SPACE -> 0
394394
*
@@ -405,6 +405,9 @@ bool IRrecv::decodePulseWidthData(uint_fast8_t aNumberOfBits, uint_fast8_t aStar
405405
uint32_t tDecodedData = 0;
406406

407407
if (aMSBfirst) {
408+
/*
409+
* MSB first is currently optimized out by the compiler, since it is never used.
410+
*/
408411
for (uint_fast8_t i = 0; i < aNumberOfBits; i++) {
409412
// Check for variable length mark indicating a 0 or 1
410413
if (matchMark(*tRawBufPointer, aOneMarkMicros)) {
@@ -441,6 +444,7 @@ bool IRrecv::decodePulseWidthData(uint_fast8_t aNumberOfBits, uint_fast8_t aStar
441444
}
442445
IR_TRACE_PRINTLN(F(""));
443446
} else {
447+
// LSB first
444448
for (uint32_t tMask = 1UL; aNumberOfBits > 0; tMask <<= 1, aNumberOfBits--) {
445449

446450
// Check for variable length mark indicating a 0 or 1

src/digitalWriteFast.h

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
((((P) >= 10 && (P) <= 13) || ((P) >= 50 && (P) <= 53)) ? &PORTB : \
163163
(((P) >= 30 && (P) <= 37) ? &PORTC : \
164164
((((P) >= 18 && (P) <= 21) || (P) == 38) ? &PORTD : \
165-
((((P) >= 0 && (P) <= 3) || (P) == 5) ? &PORTE : \
165+
((((P) <= 3) || (P) == 5) ? &PORTE : \
166166
(((P) >= 54 && (P) <= 61) ? &PORTF : \
167167
((((P) >= 39 && (P) <= 41) || (P) == 4) ? &PORTG : \
168168
((((P) >= 6 && (P) <= 9) || (P) == 16 || (P) == 17) ? &PORTH : \
@@ -174,7 +174,7 @@
174174
((((P) >= 10 && (P) <= 13) || ((P) >= 50 && (P) <= 53)) ? &DDRB : \
175175
(((P) >= 30 && (P) <= 37) ? &DDRC : \
176176
((((P) >= 18 && (P) <= 21) || (P) == 38) ? &DDRD : \
177-
((((P) >= 0 && (P) <= 3) || (P) == 5) ? &DDRE : \
177+
((((P) <= 3) || (P) == 5) ? &DDRE : \
178178
(((P) >= 54 && (P) <= 61) ? &DDRF : \
179179
((((P) >= 39 && (P) <= 41) || (P) == 4) ? &DDRG : \
180180
((((P) >= 6 && (P) <= 9) || (P) == 16 || (P) == 17) ? &DDRH : \
@@ -186,7 +186,7 @@
186186
((((P) >= 10 && (P) <= 13) || ((P) >= 50 && (P) <= 53)) ? &PINB : \
187187
(((P) >= 30 && (P) <= 37) ? &PINC : \
188188
((((P) >= 18 && (P) <= 21) || (P) == 38) ? &PIND : \
189-
((((P) >= 0 && (P) <= 3) || (P) == 5) ? &PINE : \
189+
((((P) <= 3) || (P) == 5) ? &PINE : \
190190
(((P) >= 54 && (P) <= 61) ? &PINF : \
191191
((((P) >= 39 && (P) <= 41) || (P) == 4) ? &PING : \
192192
((((P) >= 6 && (P) <= 9) || (P) == 16 || (P) == 17) ? &PINH : \
@@ -241,31 +241,31 @@
241241

242242
#if defined(__AVR_ATmega324PB__)
243243
#define __digitalPinToPortReg(P) \
244-
(((P) >= 0 && (P) <= 7) ? &PORTB : (((P) >= 8 && (P) <= 15) ? &PORTD : (((P) >= 16 && (P) <= 23) ? &PORTC : (((P) >= 24 && (P) <= 31) ? &PORTA : &PORTE))))
244+
(((P) <= 7) ? &PORTB : (((P) >= 8 && (P) <= 15) ? &PORTD : (((P) >= 16 && (P) <= 23) ? &PORTC : (((P) >= 24 && (P) <= 31) ? &PORTA : &PORTE))))
245245
#define __digitalPinToDDRReg(P) \
246-
(((P) >= 0 && (P) <= 7) ? &DDRB : (((P) >= 8 && (P) <= 15) ? &DDRD : (((P) >= 16 && (P) <= 23) ? &DDRC : (((P) >= 24 && (P) <= 31) ? &DDRA : &DDRE))))
246+
(((P) <= 7) ? &DDRB : (((P) >= 8 && (P) <= 15) ? &DDRD : (((P) >= 16 && (P) <= 23) ? &DDRC : (((P) >= 24 && (P) <= 31) ? &DDRA : &DDRE))))
247247
#define __digitalPinToPINReg(P) \
248-
(((P) >= 0 && (P) <= 7) ? &PINB : (((P) >= 8 && (P) <= 15) ? &PIND : (((P) >= 16 && (P) <= 23) ? &PINC : (((P) >= 24 && (P) <= 31) ? &PINA : &PINE))))
248+
(((P) <= 7) ? &PINB : (((P) >= 8 && (P) <= 15) ? &PIND : (((P) >= 16 && (P) <= 23) ? &PINC : (((P) >= 24 && (P) <= 31) ? &PINA : &PINE))))
249249
# if defined(SANGUINO_PINOUT)
250250
#define __digitalPinToBit(P) \
251-
(((P) >= 0 && (P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (((P) >= 16 && (P) <= 23) ? (7 - ((P) - 24)) : (P) - 32))))
251+
(((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (((P) >= 16 && (P) <= 23) ? (7 - ((P) - 24)) : (P) - 32))))
252252
# else //MightyCore Pinout
253253
#define __digitalPinToBit(P) \
254-
(((P) >= 0 && (P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (((P) >= 16 && (P) <= 23) ? (P) - 24 : (P) - 32))))
254+
(((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (((P) >= 16 && (P) <= 23) ? (P) - 24 : (P) - 32))))
255255
# endif
256256
#else
257257
#define __digitalPinToPortReg(P) \
258-
(((P) >= 0 && (P) <= 7) ? &PORTB : (((P) >= 8 && (P) <= 15) ? &PORTD : (((P) >= 16 && (P) <= 23) ? &PORTC : &PORTA)))
258+
(((P) <= 7) ? &PORTB : (((P) >= 8 && (P) <= 15) ? &PORTD : (((P) >= 16 && (P) <= 23) ? &PORTC : &PORTA)))
259259
#define __digitalPinToDDRReg(P) \
260-
(((P) >= 0 && (P) <= 7) ? &DDRB : (((P) >= 8 && (P) <= 15) ? &DDRD : (((P) >= 16 && (P) <= 23) ? &DDRC : &DDRA)))
260+
(((P) <= 7) ? &DDRB : (((P) >= 8 && (P) <= 15) ? &DDRD : (((P) >= 16 && (P) <= 23) ? &DDRC : &DDRA)))
261261
#define __digitalPinToPINReg(P) \
262-
(((P) >= 0 && (P) <= 7) ? &PINB : (((P) >= 8 && (P) <= 15) ? &PIND : (((P) >= 16 && (P) <= 23) ? &PINC : &PINA)))
262+
(((P) <= 7) ? &PINB : (((P) >= 8 && (P) <= 15) ? &PIND : (((P) >= 16 && (P) <= 23) ? &PINC : &PINA)))
263263
# if defined(SANGUINO_PINOUT)
264264
#define __digitalPinToBit(P) \
265-
(((P) >= 0 && (P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (7 - ((P) - 24)))))
265+
(((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (7 - ((P) - 24)))))
266266
# else //MightyCore Pinout
267267
#define __digitalPinToBit(P) \
268-
(((P) >= 0 && (P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (P) - 24)))
268+
(((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (P) - 24)))
269269
# endif
270270
#endif
271271

@@ -287,11 +287,11 @@
287287
#define SPI_HW_SCK_PIN (15) //PB1
288288

289289
#define __digitalPinToPortReg(P) \
290-
((((P) >= 0 && (P) <= 4) || (P) == 6 || (P) == 12 || (P) == 24 || (P) == 25 || (P) == 29) ? &PORTD : (((P) == 5 || (P) == 13) ? &PORTC : (((P) >= 18 && (P) <= 23)) ? &PORTF : (((P) == 7) ? &PORTE : &PORTB)))
290+
((((P) <= 4) || (P) == 6 || (P) == 12 || (P) == 24 || (P) == 25 || (P) == 29) ? &PORTD : (((P) == 5 || (P) == 13) ? &PORTC : (((P) >= 18 && (P) <= 23)) ? &PORTF : (((P) == 7) ? &PORTE : &PORTB)))
291291
#define __digitalPinToDDRReg(P) \
292-
((((P) >= 0 && (P) <= 4) || (P) == 6 || (P) == 12 || (P) == 24 || (P) == 25 || (P) == 29) ? &DDRD : (((P) == 5 || (P) == 13) ? &DDRC : (((P) >= 18 && (P) <= 23)) ? &DDRF : (((P) == 7) ? &DDRE : &DDRB)))
292+
((((P) <= 4) || (P) == 6 || (P) == 12 || (P) == 24 || (P) == 25 || (P) == 29) ? &DDRD : (((P) == 5 || (P) == 13) ? &DDRC : (((P) >= 18 && (P) <= 23)) ? &DDRF : (((P) == 7) ? &DDRE : &DDRB)))
293293
#define __digitalPinToPINReg(P) \
294-
((((P) >= 0 && (P) <= 4) || (P) == 6 || (P) == 12 || (P) == 24 || (P) == 25 || (P) == 29) ? &PIND : (((P) == 5 || (P) == 13) ? &PINC : (((P) >= 18 && (P) <= 23)) ? &PINF : (((P) == 7) ? &PINE : &PINB)))
294+
((((P) <= 4) || (P) == 6 || (P) == 12 || (P) == 24 || (P) == 25 || (P) == 29) ? &PIND : (((P) == 5 || (P) == 13) ? &PINC : (((P) >= 18 && (P) <= 23)) ? &PINF : (((P) == 7) ? &PINE : &PINB)))
295295
#define __digitalPinToBit(P) \
296296
(((P) >= 8 && (P) <= 11) ? (P) - 4 : (((P) >= 18 && (P) <= 21) ? 25 - (P) : (((P) == 0) ? 2 : (((P) == 1) ? 3 : (((P) == 2) ? 1 : (((P) == 3) ? 0 : (((P) == 4) ? 4 : (((P) == 6) ? 7 : (((P) == 13) ? 7 : (((P) == 14) ? 3 : (((P) == 15) ? 1 : (((P) == 16) ? 2 : (((P) == 17) ? 0 : (((P) == 22) ? 1 : (((P) == 23) ? 0 : (((P) == 24) ? 4 : (((P) == 25) ? 7 : (((P) == 26) ? 4 : (((P) == 27) ? 5 : 6 )))))))))))))))))))
297297

@@ -325,22 +325,22 @@
325325

326326
#if defined(__AVR_ATmega48PB__) || defined(__AVR_ATmega88PB__) || defined(__AVR_ATmega168PB__) || defined(__AVR_ATmega328PB__)
327327
#define __digitalPinToPortReg(P) \
328-
(((P) >= 0 && (P) <= 7) ? &PORTD : (((P) >= 8 && (P) <= 13) ? &PORTB : (((P) >= 14 && (P) <= 19) ? &PORTC : &PORTE)))
328+
(((P) <= 7) ? &PORTD : (((P) >= 8 && (P) <= 13) ? &PORTB : (((P) >= 14 && (P) <= 19) ? &PORTC : &PORTE)))
329329
#define __digitalPinToDDRReg(P) \
330-
(((P) >= 0 && (P) <= 7) ? &DDRD : (((P) >= 8 && (P) <= 13) ? &DDRB : (((P) >= 14 && (P) <= 19) ? &DDRC : &DDRE)))
330+
(((P) <= 7) ? &DDRD : (((P) >= 8 && (P) <= 13) ? &DDRB : (((P) >= 14 && (P) <= 19) ? &DDRC : &DDRE)))
331331
#define __digitalPinToPINReg(P) \
332-
(((P) >= 0 && (P) <= 7) ? &PIND : (((P) >= 8 && (P) <= 13) ? &PINB : (((P) >= 14 && (P) <= 19) ? &PINC : &PINE)))
332+
(((P) <= 7) ? &PIND : (((P) >= 8 && (P) <= 13) ? &PINB : (((P) >= 14 && (P) <= 19) ? &PINC : &PINE)))
333333
#define __digitalPinToBit(P) \
334-
(((P) >= 0 && (P) <= 7) ? (P) : (((P) >= 8 && (P) <= 13) ? (P) - 8 : (((P) >= 14 && (P) <= 19) ? (P) - 14 : (((P) >= 20 && (P) <= 21) ? (P) - 18 : (P) - 22))))
334+
(((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 13) ? (P) - 8 : (((P) >= 14 && (P) <= 19) ? (P) - 14 : (((P) >= 20 && (P) <= 21) ? (P) - 18 : (P) - 22))))
335335
#else
336336
#define __digitalPinToPortReg(P) \
337-
(((P) >= 0 && (P) <= 7) ? &PORTD : (((P) >= 8 && (P) <= 13) ? &PORTB : &PORTC))
337+
(((P) <= 7) ? &PORTD : (((P) >= 8 && (P) <= 13) ? &PORTB : &PORTC))
338338
#define __digitalPinToDDRReg(P) \
339-
(((P) >= 0 && (P) <= 7) ? &DDRD : (((P) >= 8 && (P) <= 13) ? &DDRB : &DDRC))
339+
(((P) <= 7) ? &DDRD : (((P) >= 8 && (P) <= 13) ? &DDRB : &DDRC))
340340
#define __digitalPinToPINReg(P) \
341-
(((P) >= 0 && (P) <= 7) ? &PIND : (((P) >= 8 && (P) <= 13) ? &PINB : &PINC))
341+
(((P) <= 7) ? &PIND : (((P) >= 8 && (P) <= 13) ? &PINB : &PINC))
342342
#define __digitalPinToBit(P) \
343-
(((P) >= 0 && (P) <= 7) ? (P) : (((P) >= 8 && (P) <= 13) ? (P) - 8 : (P) - 14))
343+
(((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 13) ? (P) - 8 : (P) - 14))
344344
#endif
345345

346346
// --- Arduino Uno WiFi Rev 2, Nano Every ---
@@ -462,7 +462,7 @@ if (__builtin_constant_p(P) && __builtin_constant_p(V)) { \
462462
#else
463463
#define pinModeFast pinMode
464464
#endif
465-
#endif
465+
#endif // !defined(pinModeFast)
466466

467467
#if !defined(digitalReadFast)
468468
#if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR))
@@ -474,7 +474,7 @@ if (__builtin_constant_p(P) && __builtin_constant_p(V)) { \
474474
#else
475475
#define digitalReadFast digitalRead
476476
#endif
477-
#endif
477+
#endif // !defined(digitalReadFast)
478478

479479
#if !defined(digitalToggleFast)
480480
#if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR))
@@ -487,6 +487,6 @@ if (__builtin_constant_p(P)) { \
487487
#else
488488
#define digitalToggleFast(P) digitalWrite(P, ! digitalRead(P))
489489
#endif
490-
#endif
490+
#endif // !defined(digitalToggleFast)
491491

492492
#endif //__digitalWriteFast_h_

0 commit comments

Comments
 (0)