Skip to content

Commit fe3bafe

Browse files
committed
Improved DistanceProtocol decoder output and minor changes
1 parent 0c4d269 commit fe3bafe

File tree

18 files changed

+153
-159
lines changed

18 files changed

+153
-159
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ Modify them by enabling / disabling them, or change the values if applicable.
386386
| `USE_NO_SEND_PWM` | disabled | Use no carrier PWM, just simulate an **active low** receiver signal. Overrides `SEND_PWM_BY_TIMER` definition. |
387387
| `USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN` | disabled | Use or simulate open drain output mode at send pin. **Attention, active state of open drain is LOW**, so connect the send LED between positive supply and send pin! |
388388
| `EXCLUDE_EXOTIC_PROTOCOLS` | disabled | If activated, BOSEWAVE, WHYNTER and LEGO_PF are excluded in `decode()` and in sending with `IrSender.write()`. Saves up to 650 bytes program memory. |
389-
| `EXCLUDE_UNIVERSAL_PROTOCOLS` | disabled | If activated, the universal decoder for pulse width or pulse distance protocols and decodeHash (special decoder for all protocols) are excluded in `decode()`. Saves up to 1000 bytes program memory. |
389+
| `EXCLUDE_UNIVERSAL_PROTOCOLS` | disabled | If activated, the universal decoder for pulse distance protocols and decodeHash (special decoder for all protocols) are excluded in `decode()`. Saves up to 1000 bytes program memory. |
390390
| `DECODE_<Protocol name>` | all | Selection of individual protocol(s) to be decoded. You can specify multiple protocols. See [here](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/IRremote.hpp#L98-L121) |
391391
| `MARK_EXCESS_MICROS` | 20 | MARK_EXCESS_MICROS is subtracted from all marks and added to all spaces before decoding, to compensate for the signal forming of different IR receiver modules. |
392392
| `RECORD_GAP_MICROS` | 5000 | Minimum gap between IR transmissions, to detect the end of a protocol.<br/>Must be greater than any space of a protocol e.g. the NEC header space of 4500 µs.<br/>Must be smaller than any gap between a command and a repeat; e.g. the retransmission gap for Sony is around 24 ms.<br/>Keep in mind, that this is the delay between the end of the received command and the start of decoding. |

changelog.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ See also the commit log at github: https://github.com/Arduino-IRremote/Arduino-I
44

55
## 3.7.1
66
- SendRaw now supports bufferlenght > 255.
7+
- Improved DistanceProtocol decoder output.
78

89
## 3.7.0
910
- Changed TOLERANCE to TOLERANCE_FOR_DECODERS_MARK_OR_SPACE_MATCHING and documented it.
@@ -56,15 +57,15 @@ See also the commit log at github: https://github.com/Arduino-IRremote/Arduino-I
5657
- Moved blink13() back to IRrecv class.
5758
- Added Kaseikyo convenience functions like sendKaseikyo_Denon().
5859
- Improved / adjusted LG protocol and added class Aircondition_LG based on real hardware supplied by makerspace 201 (https://wiki.hackerspaces.org/ZwoNullEins) from Cologne.
59-
- Improved universal decoder for pulse width or pulse distance protocols to support more than 32 bits.
60+
- Improved universal decoder for pulse distance protocols to support more than 32 bits.
6061
- Added mbed support.
6162

6263
## 3.3.0
6364
- Fix errors if LED_BUILTIN is not defined.
6465
- Fixed error for AVR timer1. Thanks to alexbarcelo.
6566
- New example IRremoteExtensionTest.
6667
- Enabled megaAVR 0-series devices.
67-
- Added universal decoder for pulse width or pulse distance protocols.
68+
- Added universal decoder for pulse distance protocols.
6869

6970
## 3.2.0
7071
- Fix for ESP32 send Error, removed `USE_SOFT_SEND_PWM` macro.

examples/IRDispatcherDemo/IRCommandDispatcher.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#ifndef _IR_COMMAND_DISPATCHER_H
3030
#define _IR_COMMAND_DISPATCHER_H
3131

32+
#include <stdint.h>
33+
3234
/*
3335
* For command mapping file
3436
*/

examples/ReceiveAndSend/ReceiveAndSend.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ void sendCode(storedIRDataStruct *aIRDataToSend) {
192192
IrSender.write(&aIRDataToSend->receivedIRData, DEFAULT_NUMBER_OF_REPEATS_TO_SEND);
193193

194194
Serial.print(F("Sent: "));
195-
printIRResultShort(&Serial, &aIRDataToSend->receivedIRData);
195+
printIRResultShort(&Serial, &aIRDataToSend->receivedIRData, false);
196196
}
197197
}
198198

examples/ReceiveDemo/ReceiveDemo.ino

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
//#define RECORD_GAP_MICROS 12000 // Activate it for some LG air conditioner protocols
6464

6565
//#define DEBUG // Activate this for lots of lovely debug output from the decoders.
66-
#define INFO // To see valuable informations from universal decoder for pulse width or pulse distance protocols
6766

6867
#include "PinDefinitionsAndMore.h" //Define macros for input and output pin etc.
6968
#include <IRremote.hpp>
@@ -80,9 +79,6 @@
8079
#endif
8180

8281
void setup() {
83-
#if defined(_IR_MEASURE_TIMING) && defined(_IR_TIMING_TEST_PIN)
84-
pinMode(_IR_TIMING_TEST_PIN, OUTPUT);
85-
#endif
8682
#if FLASHEND >= 0x3FFF // For 16k flash or more, like ATtiny1604. Code does not fit in program memory of ATtiny85 etc.
8783
pinMode(DEBUG_BUTTON_PIN, INPUT_PULLUP);
8884
#endif

examples/ReceiveDump/ReceiveDump.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444

4545
//#define RECORD_GAP_MICROS 12000 // Activate it for some LG air conditioner protocols
4646
//#define DEBUG // Activate this for lots of lovely debug output from the decoders.
47-
#define INFO // To see valuable informations from universal decoder for pulse width or pulse distance protocols
4847

4948
#include "PinDefinitionsAndMore.h" //Define macros for input and output pin etc.
5049
#include <IRremote.hpp>

examples/SendAndReceive/SendAndReceive.ino

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
#include <Arduino.h>
3434

35-
// select only NEC and the universal decoder for pulse width or pulse distance protocols
35+
// select only NEC and the universal decoder for pulse distance protocols
3636
#define DECODE_NEC // Includes Apple and Onkyo
3737
#define DECODE_DISTANCE // in case NEC is not received correctly
3838

@@ -42,7 +42,6 @@
4242
//#define USE_NO_SEND_PWM
4343
//#define NO_LED_FEEDBACK_CODE // saves 500 bytes program memory
4444
//#define DEBUG // Activate this for lots of lovely debug output from the decoders.
45-
#define INFO // To see valuable informations from universal decoder for pulse width or pulse distance protocols
4645

4746
#include "PinDefinitionsAndMore.h" //Define macros for input and output pin etc.
4847
#include <IRremote.hpp>
@@ -51,10 +50,6 @@
5150
#define DELAY_AFTER_LOOP 5000
5251

5352
void setup() {
54-
#if defined(_IR_MEASURE_TIMING) && defined(_IR_TIMING_TEST_PIN)
55-
pinMode(_IR_TIMING_TEST_PIN, OUTPUT);
56-
#endif
57-
5853
Serial.begin(115200);
5954
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217)
6055
delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor!

examples/SimpleReceiver/SimpleReceiver.ino

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,10 @@
5050
//#define DECODE_MAGIQUEST
5151
//#define DECODE_WHYNTER
5252

53-
//#define DECODE_DISTANCE // universal decoder for pulse width or pulse distance protocols
53+
//#define DECODE_DISTANCE // universal decoder for pulse distance protocols
5454
//#define DECODE_HASH // special decoder for all protocols
5555

56-
//#define DEBUG // Activate this for lots of lovely debug output from the decoders.
57-
//#define INFO // To see valuable informations from universal decoder for pulse width or pulse distance protocols
56+
//#define DEBUG // Activate this for lots of lovely debug output from the decoders.
5857

5958
#include <Arduino.h>
6059

examples/UnitTest/UnitTest.ino

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@
3939
//#define EXCLUDE_EXOTIC_PROTOCOLS
4040
//#define SEND_PWM_BY_TIMER
4141
//#define USE_NO_SEND_PWM
42-
//#define NO_LED_FEEDBACK_CODE // saves 500 bytes program memory
42+
#define NO_LED_FEEDBACK_CODE // saves 500 bytes program memory
43+
#define MARK_EXCESS_MICROS 10 // Adapt it to your IR receiver module. See also IRremote.h.
44+
4345
//#define TRACE // For internal usage
4446
//#define DEBUG // Activate this for lots of lovely debug output from the decoders.
45-
#define INFO // To see valuable informations from universal decoder for pulse width or pulse distance protocols
4647

4748
#if FLASHEND >= 0x1FFF // For 8k flash or more, like ATtiny85
4849
#define DECODE_DENON // Includes Sharp
@@ -57,7 +58,7 @@
5758
#define DECODE_SONY
5859
#define DECODE_PANASONIC // the same as DECODE_KASEIKYO
5960

60-
#define DECODE_DISTANCE // universal decoder for pulse width or pulse distance protocols
61+
#define DECODE_DISTANCE // universal decoder for pulse distance protocols
6162
#define DECODE_HASH // special decoder for all protocols
6263
#endif
6364

@@ -71,14 +72,6 @@
7172
#define DECODE_WHYNTER
7273
#endif
7374

74-
//#define SEND_PWM_BY_TIMER
75-
//#define USE_NO_SEND_PWM
76-
//#define _IR_MEASURE_TIMING
77-
#define MARK_EXCESS_MICROS 10 // Adapt it to your IR receiver module. See also IRremote.h.
78-
#define NO_LED_FEEDBACK_CODE // halves ISR duration
79-
//#define DEBUG // Activate this for lots of lovely debug output from the decoders.
80-
#define INFO // To see valuable informations from universal decoder for pulse width or pulse distance protocols
81-
8275
#include "PinDefinitionsAndMore.h" //Define macros for input and output pin etc.
8376
#include <IRremote.hpp>
8477

@@ -97,9 +90,6 @@
9790

9891
void setup() {
9992
pinMode(DEBUG_BUTTON_PIN, INPUT_PULLUP);
100-
#if defined(_IR_MEASURE_TIMING) && defined(_IR_TIMING_TEST_PIN)
101-
pinMode(_IR_TIMING_TEST_PIN, OUTPUT);
102-
#endif
10393

10494
Serial.begin(115200);
10595
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217)

src/IRReceive.hpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ void IRrecv::begin(uint_fast8_t aReceivePin, bool aEnableLEDFeedback, uint_fast8
105105
// Set pin mode once
106106
pinMode(irparams.IRReceivePin, INPUT);
107107

108+
#if defined(_IR_MEASURE_TIMING) && defined(_IR_TIMING_TEST_PIN)
109+
pinMode(_IR_TIMING_TEST_PIN, OUTPUT);
110+
#endif
108111
start();
109112
}
110113

@@ -356,7 +359,7 @@ bool IRrecv::decode() {
356359
#endif
357360

358361
/*
359-
* Try the universal decoder for pulse width or pulse distance protocols
362+
* Try the universal decoder for pulse distance protocols
360363
*/
361364
#if defined(DECODE_DISTANCE)
362365
IR_TRACE_PRINTLN(F("Attempting universal Distance decode"));
@@ -854,13 +857,14 @@ void CheckForRecordGapsMicros(Print *aSerial, IRData *aIRDataPtr) {
854857
* Check if protocol is not detected and detected space between two transmissions
855858
* is smaller than known value for protocols (Sony with around 24 ms)
856859
*/
857-
if (aIRDataPtr->protocol <= PULSE_WIDTH && aIRDataPtr->rawDataPtr->rawbuf[0] < RECORD_GAP_MICROS_WARNING_THRESHOLD) {
860+
if (aIRDataPtr->protocol <= PULSE_WIDTH
861+
&& aIRDataPtr->rawDataPtr->rawbuf[0] < (RECORD_GAP_MICROS_WARNING_THRESHOLD / MICROS_PER_TICK)) {
858862
aSerial->println();
859-
aSerial->print(F("Space between two detected transmission is greater than "));
860-
aSerial->print(RECORD_GAP_MICROS);
861-
aSerial->print(F(" but smaller than the minimal gap of "));
863+
aSerial->print(F("Space of "));
864+
aSerial->print(aIRDataPtr->rawDataPtr->rawbuf[0] * MICROS_PER_TICK);
865+
aSerial->print(F(" us between two detected transmission is smaller than the minimal gap of "));
862866
aSerial->print(RECORD_GAP_MICROS_WARNING_THRESHOLD);
863-
aSerial->println(F(" known for a protocol."));
867+
aSerial->println(F(" us known for a protocol."));
864868
aSerial->println(F("If you get unexpected results, try to increase the RECORD_GAP_MICROS in IRremote.h."));
865869
aSerial->println();
866870
}
@@ -930,7 +934,7 @@ void printActiveIRProtocols(Print *aSerial) {
930934
*
931935
* @param aSerial The Print object on which to write, for Arduino you can use &Serial.
932936
*/
933-
void printIRResultShort(Print *aSerial, IRData *aIRDataPtr, unsigned int aLeadingSpaceTicks) {
937+
void printIRResultShort(Print *aSerial, IRData *aIRDataPtr, bool aPrintGap) {
934938
aSerial->print(F("Protocol="));
935939
aSerial->print(getProtocolString(aIRDataPtr->protocol));
936940
if (aIRDataPtr->protocol == UNKNOWN) {
@@ -970,9 +974,9 @@ void printIRResultShort(Print *aSerial, IRData *aIRDataPtr, unsigned int aLeadin
970974
aSerial->print(F("Auto-"));
971975
}
972976
aSerial->print(F("Repeat"));
973-
if (aLeadingSpaceTicks != 0) {
977+
if (aPrintGap) {
974978
aSerial->print(F(" gap="));
975-
aSerial->print((uint32_t) aLeadingSpaceTicks * MICROS_PER_TICK);
979+
aSerial->print((uint32_t) aIRDataPtr->rawDataPtr->rawbuf[0] * MICROS_PER_TICK);
976980
aSerial->print(F("us"));
977981
}
978982
}
@@ -1012,7 +1016,7 @@ void printIRResultShort(Print *aSerial, IRData *aIRDataPtr, unsigned int aLeadin
10121016
* @param aSerial The Print object on which to write, for Arduino you can use &Serial.
10131017
*/
10141018
void IRrecv::printIRResultShort(Print *aSerial) {
1015-
::printIRResultShort(aSerial, &decodedIRData, decodedIRData.rawDataPtr->rawbuf[0]);
1019+
::printIRResultShort(aSerial, &decodedIRData, true);
10161020
}
10171021

10181022
/**

0 commit comments

Comments
 (0)