Skip to content

Commit 8007e65

Browse files
committed
Reverted RC5 and RC6 to old decode method.
1 parent 3283ef7 commit 8007e65

20 files changed

+371
-419
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Available as Arduino library "IRremote"
1212
This library enables you to send and receive using infra-red signals on an Arduino.
1313

1414
# API
15-
A Doxygen documentation of the sources is available on [project homepage](https://arduino-irremote.github.io/Arduino-IRremote/).
15+
A Doxygen documentation of the sources is available on the [project homepage](https://arduino-irremote.github.io/Arduino-IRremote/).
1616

1717
# Installation
1818
Click on the LibraryManager badge above to see the [instructions](https://www.ardu-badge.com/IRremote/zip).
@@ -82,7 +82,7 @@ If you do not know which protocol your IR transmitter uses, you have several cho
8282
the old [IRLib](https://github.com/cyborg5/IRLib) and [Infrared4Arduino](https://github.com/bengtmartensson/Infrared4Arduino).
8383
- To **increase strength of sent output signal** you can increase the current through the send diode, and/or use 2 diodes in series,
8484
since one IR diode requires only 1.5 volt.
85-
- The line #include "ATtinySerialOut.h" in PinDefinitionsAndMore.h (requires the library to be installed) saves 370 bytes program space and 38 bytes RAM for **Digispark boards** as well as enables serial output at 8MHz.
85+
- The line \#include "ATtinySerialOut.h" in PinDefinitionsAndMore.h (requires the library to be installed) saves 370 bytes program space and 38 bytes RAM for **Digispark boards** as well as enables serial output at 8MHz.
8686
- The default software generated PWM has **problems on ATtinies running with 8 MHz**. The PWM frequency is around 30 instead of 38 kHz and RC6 is not reliable. You can switch to timer PWM generation by `#define SEND_PWM_BY_TIMER`.
8787

8888
# Examples

examples/UnitTest/UnitTest.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ void checkReceive(uint16_t aSentAddress, uint16_t aSentCommand) {
105105
// Print a short summary of received data
106106
IrReceiver.printIRResultShort(&Serial);
107107

108-
if (IrReceiver.decodedIRData.protocol == UNKNOWN || digitalRead(DEBUG_BUTTON_PIN) == LOW) {
108+
if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_WAS_OVERFLOW) {
109+
IrReceiver.decodedIRData.flags = false; // yes we have recognized the flag :-)
110+
Serial.println(F("Overflow detected"));
111+
} else if (IrReceiver.decodedIRData.protocol == UNKNOWN || digitalRead(DEBUG_BUTTON_PIN) == LOW) {
109112
// We have an unknown protocol, print more info
110113
IrReceiver.printIRResultRawFormatted(&Serial, true);
111114
} else {
@@ -325,7 +328,6 @@ void loop() {
325328
// IrSender.sendLegoPowerFunctions(sAddress, sCommand, LEGO_MODE_COMBO, true);
326329
// checkReceive(sAddress, sCommand); // never has success for Lego protocol :-(
327330
// delay(DELAY_AFTER_SEND);
328-
329331
/*
330332
* Force buffer overflow
331333
*/

src/IRReceive.cpp.h

Lines changed: 67 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
************************************************************************************
3232
*/
3333

34-
//#define DEBUG
35-
3634
/** \addtogroup Receiving Receiving IR data for multiple protocols
3735
* @{
3836
*/
@@ -586,112 +584,76 @@ bool IRrecv::decodePulseDistanceData(uint8_t aNumberOfBits, uint8_t aStartOffset
586584
return true;
587585
}
588586

589-
//# define DBG_PRINT(...) Serial.print(__VA_ARGS__)
590-
//# define DBG_PRINTLN(...) Serial.println(__VA_ARGS__)
591-
//# define TRACE_PRINT(...) Serial.print(__VA_ARGS__)
592-
//# define TRACE_PRINTLN(...) Serial.println(__VA_ARGS__)
587+
/*
588+
* Static variables for the getBiphaselevel function
589+
*/
590+
uint8_t sBiphaseDecodeRawbuffOffset;// Index into raw timing array
591+
uint16_t sCurrentTimingIntervals; // Number of aBiphaseTimeUnit intervals of the current rawbuf[sBiphaseDecodeRawbuffOffset] timing.
592+
uint8_t sUsedTimingIntervals; // Number of already used intervals of sCurrentTimingIntervals.
593+
uint16_t sBiphaseTimeUnit;
594+
595+
void IRrecv::initBiphaselevel(uint8_t aRCDecodeRawbuffOffset, uint16_t aBiphaseTimeUnit) {
596+
sBiphaseDecodeRawbuffOffset = aRCDecodeRawbuffOffset;
597+
sBiphaseTimeUnit = aBiphaseTimeUnit;
598+
sUsedTimingIntervals = 0;
599+
}
600+
593601
/**
594-
* Decode Biphase protocols
595-
* We "regenerate" the clock and check changes on the significant clock transition
596-
* We assume that the transition from (aStartOffset -1) to aStartOffset is a significant clock transition
597-
*
598-
* The first bit is assumed as start bit and excluded for result
602+
* Gets the level of one time interval (aBiphaseTimeUnit) at a time from the raw buffer.
603+
* The RC5/6 decoding is easier if the data is broken into time intervals.
604+
* E.g. if the buffer has mark for 2 time intervals and space for 1,
605+
* successive calls to getBiphaselevel will return 1, 1, 0.
599606
*
600-
* Input is IrReceiver.decodedIRData.rawDataPtr->rawbuf[]
601-
* Output is IrReceiver.decodedIRData.decodedRawData
602-
*
603-
* @param aStartOffset must point to a mark
604-
* @return true if decoding was successful
607+
* _ _ _ _ _ _ _ _ _ _ _ _ _
608+
* _____| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |
609+
* ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ Significant clock edge
610+
* _ _ _ ___ _ ___ ___ _ - Mark
611+
* Data _____| |___| |_| |_| |_| |___| |___| |_| | - Data starts with a mark->space bit
612+
* 1 0 0 0 1 1 0 1 0 1 1 - Space
613+
* A mark to space at a significant clock edge results in a 1
614+
* A space to mark at a significant clock edge results in a 0 (for RC6)
615+
* Returns current level [MARK or SPACE] or -1 for error (measured time interval is not a multiple of sBiphaseTimeUnit).
605616
*/
606-
bool IRrecv::decodeBiPhaseData(uint8_t aNumberOfBits, uint8_t aStartOffset, uint8_t aValueOfSpaceToMarkTransition,
607-
uint16_t aBiphaseTimeUnit) {
617+
uint8_t IRrecv::getBiphaselevel() {
618+
uint8_t tLevelOfCurrentInterval; // 0 (SPACE) or 1 (MARK)
608619

609-
uint16_t *tRawBufPointer = &decodedIRData.rawDataPtr->rawbuf[aStartOffset];
610-
bool tCheckMark = aStartOffset & 1;
611-
uint_fast8_t tClockCount = 0; // assume that first transition is significant
612-
aValueOfSpaceToMarkTransition &= 1; // only 0 or 1 are valid
613-
uint32_t tDecodedData = 0;
614-
615-
for (uint_fast8_t tBitIndex = 0; tBitIndex < aNumberOfBits;) {
616-
if (tCheckMark) {
617-
/*
618-
* Check mark and determine current (and next) bit value
619-
*/
620-
if (matchMark(*tRawBufPointer, aBiphaseTimeUnit)) {
621-
// we have a transition here from space to mark
622-
tClockCount++;
623-
// for BiPhaseCode, we have a transition at every odd clock count.
624-
if (tClockCount & 1) {
625-
// valid clock edge
626-
tDecodedData = (tDecodedData << 1) | aValueOfSpaceToMarkTransition;
627-
TRACE_PRINT(aValueOfSpaceToMarkTransition);
628-
tBitIndex++;
629-
}
630-
} else if (matchMark(*tRawBufPointer, 2 * aBiphaseTimeUnit)) {
631-
tClockCount = 0; // can reset clock count here
632-
// We have a double length mark this includes two valid clock edges
633-
tDecodedData = (tDecodedData << 1) | aValueOfSpaceToMarkTransition;
634-
TRACE_PRINT(aValueOfSpaceToMarkTransition);
635-
636-
tBitIndex++;
620+
if (sBiphaseDecodeRawbuffOffset >= decodedIRData.rawDataPtr->rawlen) {
621+
return SPACE; // After end of recorded buffer, assume space.
622+
}
637623

638-
} else {
639-
/*
640-
* Use TRACE_PRINT here, since this normally checks the length of the start bit and therefore will happen very often
641-
*/
642-
TRACE_PRINT(F("Mark="));
643-
TRACE_PRINT(*tRawBufPointer * MICROS_PER_TICK);
644-
TRACE_PRINT(F(" is not "));
645-
TRACE_PRINT(aBiphaseTimeUnit);
646-
TRACE_PRINT(F(" or "));
647-
TRACE_PRINT(2 * aBiphaseTimeUnit);
648-
TRACE_PRINT(' ');
649-
return false;
650-
}
624+
tLevelOfCurrentInterval = (sBiphaseDecodeRawbuffOffset) & 1; // on odd rawbuf offsets we have mark timings
651625

626+
/*
627+
* Setup data if sUsedTimingIntervals is 0
628+
*/
629+
if (sUsedTimingIntervals == 0) {
630+
uint16_t tCurrentTimingWith = decodedIRData.rawDataPtr->rawbuf[sBiphaseDecodeRawbuffOffset];
631+
uint16_t tMarkExcessCorrection = (tLevelOfCurrentInterval == MARK) ? MARK_EXCESS_MICROS : -MARK_EXCESS_MICROS;
632+
633+
if (matchTicks(tCurrentTimingWith, (sBiphaseTimeUnit) + tMarkExcessCorrection)) {
634+
sCurrentTimingIntervals = 1;
635+
} else if (matchTicks(tCurrentTimingWith, (2 * sBiphaseTimeUnit) + tMarkExcessCorrection)) {
636+
sCurrentTimingIntervals = 2;
637+
} else if (matchTicks(tCurrentTimingWith, (3 * sBiphaseTimeUnit) + tMarkExcessCorrection)) {
638+
sCurrentTimingIntervals = 3;
652639
} else {
653-
/*
654-
* Check space - simulate last not recorded space
655-
*/
656-
if (tRawBufPointer == &decodedIRData.rawDataPtr->rawbuf[decodedIRData.rawDataPtr->rawlen]
657-
|| matchSpace(*tRawBufPointer, aBiphaseTimeUnit)) {
658-
// we have a transition here from mark to space
659-
tClockCount++;
660-
if (tClockCount & 1) {
661-
// valid clock edge
662-
tDecodedData = (tDecodedData << 1) | (aValueOfSpaceToMarkTransition ^ 1);
663-
TRACE_PRINT((aValueOfSpaceToMarkTransition ^ 1));
664-
tBitIndex++;
665-
}
666-
} else if (matchSpace(*tRawBufPointer, 2 * aBiphaseTimeUnit)) {
667-
// We have a double length space -> current bit value is 0 and changes to 1
668-
tClockCount = 0; // can reset clock count here
669-
// We have a double length mark this includes two valid clock edges
670-
if (tBitIndex == 0) {
671-
TRACE_PRINT('S'); // do not put start bit into data
672-
} else {
673-
tDecodedData = (tDecodedData << 1) | (aValueOfSpaceToMarkTransition ^ 1);
674-
TRACE_PRINT((aValueOfSpaceToMarkTransition ^ 1));
675-
}
676-
tBitIndex++;
677-
} else {
678-
DBG_PRINT(F("Space="));
679-
DBG_PRINT(*tRawBufPointer * MICROS_PER_TICK);
680-
DBG_PRINT(F(" is not "));
681-
DBG_PRINT(aBiphaseTimeUnit);
682-
DBG_PRINT(F(" or "));
683-
DBG_PRINT(2 * aBiphaseTimeUnit);
684-
DBG_PRINT(' ');
685-
return false;
686-
}
640+
return -1;
687641
}
688-
tRawBufPointer++;
689-
tCheckMark = !tCheckMark;
642+
}
690643

644+
// We use another interval from tCurrentTimingIntervals
645+
sUsedTimingIntervals++;
646+
647+
// keep track of current timing offset
648+
if (sUsedTimingIntervals >= sCurrentTimingIntervals) {
649+
// we have used all intervals of current timing, switch to next timing value
650+
sUsedTimingIntervals = 0;
651+
sBiphaseDecodeRawbuffOffset++;
691652
}
692-
TRACE_PRINTLN("");
693-
decodedIRData.decodedRawData = tDecodedData;
694-
return true;
653+
654+
TRACE_PRINTLN(tLevelOfCurrentInterval);
655+
656+
return tLevelOfCurrentInterval;
695657
}
696658

697659
#if defined(DECODE_HASH)
@@ -979,12 +941,12 @@ void IRrecv::printIRResultShort(Print *aSerial) {
979941
}
980942

981943
/**
982-
* Function to print protocol, address, command,raw data and repeat flag of IrReceiver.decodedIRData in one short line.
944+
* Function to print protocol number, address, command, raw data and repeat flag of IrReceiver.decodedIRData in one short line.
983945
* @param aSerial The Print object on which to write, for Arduino you can use &Serial.
984946
*/
985947
void IRrecv::printIRResultMinimal(Print *aSerial) {
986948
aSerial->print(F("P="));
987-
aSerial->print(getProtocolString(decodedIRData.protocol));
949+
aSerial->print(decodedIRData.protocol);
988950
if (decodedIRData.protocol == UNKNOWN) {
989951
#if defined(DECODE_HASH)
990952
aSerial->print(F(" #=0x"));
@@ -1311,7 +1273,7 @@ ISR () // for functions definitions which are called by separate (board specific
13111273
// switch (irparams.StateForISR) {
13121274
//......................................................................
13131275
if (irparams.StateForISR == IR_REC_STATE_IDLE) { // In the middle of a gap
1314-
if (irdata == MARK) {
1276+
if (irdata == INPUT_MARK) {
13151277
// check if we did not start in the middle of an command by checking the minimum length of leading space
13161278
if (irparams.TickCounterForISR > RECORD_GAP_TICKS) {
13171279
// Gap just ended; Record gap duration + start recording transmission
@@ -1328,7 +1290,7 @@ ISR () // for functions definitions which are called by separate (board specific
13281290
}
13291291

13301292
} else if (irparams.StateForISR == IR_REC_STATE_MARK) { // Timing Mark
1331-
if (irdata != MARK) { // Mark ended; Record time
1293+
if (irdata != INPUT_MARK) { // Mark ended; Record time
13321294
#if defined(IR_MEASURE_TIMING) && defined(IR_TIMING_TEST_PIN)
13331295
// digitalWriteFast(IR_TIMING_TEST_PIN, HIGH); // 2 clock cycles
13341296
#endif
@@ -1338,7 +1300,7 @@ ISR () // for functions definitions which are called by separate (board specific
13381300
}
13391301

13401302
} else if (irparams.StateForISR == IR_REC_STATE_SPACE) { // Timing Space
1341-
if (irdata == MARK) { // Space just ended; Record time
1303+
if (irdata == INPUT_MARK) { // Space just ended; Record time
13421304
if (irparams.rawlen >= RAW_BUFFER_LENGTH) {
13431305
// Flag up a read OverflowFlag; Stop the State Machine
13441306
irparams.OverflowFlag = true;
@@ -1369,14 +1331,14 @@ ISR () // for functions definitions which are called by separate (board specific
13691331
#if defined(IR_MEASURE_TIMING) && defined(IR_TIMING_TEST_PIN)
13701332
// digitalWriteFast(IR_TIMING_TEST_PIN, HIGH); // 2 clock cycles
13711333
#endif
1372-
if (irdata == MARK) {
1334+
if (irdata == INPUT_MARK) {
13731335
irparams.TickCounterForISR = 0; // Reset gap TickCounterForISR, to prepare for call of resume()
13741336
}
13751337
}
13761338

13771339
#if !defined(DISABLE_LED_FEEDBACK_FOR_RECEIVE)
13781340
if (FeedbackLEDControl.LedFeedbackEnabled) {
1379-
setFeedbackLED(irdata == MARK);
1341+
setFeedbackLED(irdata == INPUT_MARK);
13801342
}
13811343
#endif
13821344

src/IRSend.cpp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*
3030
************************************************************************************
3131
*/
32-
//#define DEBUG
32+
3333
#include "IRremoteInt.h"
3434

3535
__attribute((error("Version > 3.0.1"))) void UsageError(const char *details);

src/IRremote.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
*
44
* @brief Public API to the library.
55
*
6-
*
6+
* @code
77
* !!! All the macro values defined here can be overwritten with values, !!!
88
* !!! the user defines in its source code BEFORE the #include <IRremote.h> !!!
9+
* @endcode
910
*
1011
* This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
1112
*
@@ -89,6 +90,8 @@
8990
#warning "The macros DECODE_XXX no longer require a value. Decoding is now switched by defining / non defining the macro."
9091
#endif
9192

93+
//#define DEBUG // Activate this for lots of lovely debug output from the IRremote core.
94+
9295
/**
9396
* For better readability of code
9497
*/
@@ -136,12 +139,10 @@
136139
//#define IR_INPUT_IS_ACTIVE_HIGH
137140
#ifdef IR_INPUT_IS_ACTIVE_HIGH
138141
// IR detector output is active high
139-
#define MARK 1 ///< Sensor output for a mark ("flash")
140-
#define SPACE 0 ///< Sensor output for a space ("gap")
142+
#define INPUT_MARK 1 ///< Sensor output for a mark ("flash")
141143
#else
142144
// IR detector output is active low
143-
#define MARK 0 ///< Sensor output for a mark ("flash")
144-
#define SPACE 1 ///< Sensor output for a space ("gap")
145+
#define INPUT_MARK 0 ///< Sensor output for a mark ("flash")
145146
#endif
146147
/****************************************************
147148
* SENDING

src/IRremoteInt.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
#error RAW_BUFFER_LENGTH must be even, since the array consists of space / mark pairs.
4242
#endif
4343

44+
#define MARK 1
45+
#define SPACE 0
46+
4447
/*
4548
* Try to activate it, if you have legacy code to compile with version >= 3
4649
*/
@@ -78,7 +81,7 @@ struct irparams_struct {
7881
uint16_t rawbuf[RAW_BUFFER_LENGTH]; ///< raw data / tick counts per mark/space, first entry is the length of the gap between previous and current command
7982
};
8083

81-
//#define DEBUG // Activate this for lots of lovely debug output.
84+
//#define DEBUG // Activate this for lots of lovely debug output from the IRremote core and all protocol decoders.
8285
/*
8386
* Debug directives
8487
*/
@@ -147,7 +150,7 @@ struct IRData {
147150
uint16_t address; ///< Decoded address
148151
uint16_t command; ///< Decoded command
149152
uint16_t extra; ///< Used by MagiQuest and for Kaseikyo unknown vendor ID
150-
uint8_t numberOfBits; ///< Number of bits received for data (address + command + parity) - to determine protocol length if different length are possible (currently only Sony).
153+
uint8_t numberOfBits; ///< Number of bits received for data (address + command + parity) - to determine protocol length if different length are possible.
151154
uint8_t flags; ///< See IRDATA_FLAGS_* definitions above
152155
uint32_t decodedRawData; ///< Up to 32 bit decoded raw data, used for sendRaw functions.
153156
irparams_struct *rawDataPtr; ///< Pointer of the raw timing data to be decoded. Mainly the data buffer filled by receiving ISR.
@@ -219,9 +222,12 @@ class IRrecv {
219222
bool decodePulseWidthData(uint8_t aNumberOfBits, uint8_t aStartOffset, uint16_t aOneMarkMicros, uint16_t aZeroMarkMicros,
220223
uint16_t aBitSpaceMicros, bool aMSBfirst);
221224

222-
bool decodeBiPhaseData(uint8_t aNumberOfBits, uint8_t aStartOffset, uint8_t aValueOfSpaceToMarkTransition,
225+
bool decodeBiPhaseData(uint_fast8_t aNumberOfBits, uint_fast8_t aStartOffset, uint_fast8_t aStartClockCount, uint_fast8_t aValueOfSpaceToMarkTransition,
223226
uint16_t aBiphaseTimeUnit);
224227

228+
void initBiphaselevel(uint8_t aRCDecodeRawbuffOffset, uint16_t aBiphaseTimeUnit);
229+
uint8_t getBiphaselevel();
230+
225231
/*
226232
* All standard (decode address + command) protocol decoders
227233
*/
@@ -271,6 +277,8 @@ class IRrecv {
271277
uint8_t repeatCount; // Used e.g. for Denon decode for autorepeat decoding.
272278
};
273279

280+
extern uint8_t sBiphaseDecodeRawbuffOffset; //
281+
274282
/*
275283
* Mark & Space matching functions
276284
*/

src/ir_BoseWave.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
* This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
77
*
88
*/
9+
#include <Arduino.h>
910

10-
//#define DEBUG // Activate this for lots of lovely debug output.
11-
#include "IRremoteInt.h"
11+
//#define DEBUG // Activate this for lots of lovely debug output from this decoder.
12+
#include "IRremoteInt.h" // evaluates the DEBUG for DBG_PRINT
1213

14+
/** \addtogroup Decoder Decoders and encoders for different protocols
15+
* @{
16+
*/
1317
//==============================================================================
1418
// BBBB OOO SSSS EEEEE
1519
// B B O O S E
@@ -123,3 +127,5 @@ bool IRrecv::decodeBoseWave() {
123127

124128
return true;
125129
}
130+
131+
/** @}*/

0 commit comments

Comments
 (0)