Skip to content

Commit 7d30f44

Browse files
committed
Printout of LSB or MSB first
1 parent d002441 commit 7d30f44

File tree

16 files changed

+92
-67
lines changed

16 files changed

+92
-67
lines changed

.github/workflows/LibraryBuild.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353
- arduino:megaavr:nona4809:mode=off
5454
- digistump:avr:digispark-tiny:clock=clock1
5555
- ATTinyCore:avr:attinyx5:chip=85,clock=1internal
56+
- TinyCore:avr:tiny32
5657
- arduino:samd:arduino_zero_native
5758
- MegaCore:avr:128:bootloader=no_bootloader,eeprom=keep,BOD=2v7,LTO=Os,clock=8MHz_internal # ATmega128
5859
- esp32:esp32:featheresp32:FlashFreq=80
@@ -91,6 +92,10 @@ jobs:
9192
platform-url: http://drazzy.com/package_drazzy.com_index.json
9293
sketches-exclude: IR2Keyboard,IRUnitTest,IRrelay,IRrecord,IRreceiveDumpV2,IRsendProntoDemo,MicroGirs,IRreceiveDemo,BoseWaveSendDemo,IRDispatcherDemo # Does not fit in FLASH or RAM
9394

95+
- arduino-boards-fqbn: TinyCore:avr:tiny32
96+
platform-url: https://raw.githubusercontent.com/xukangmin/TinyCore/master/avr/package/package_tinycore_index.json
97+
sketches-exclude: IR2Keyboard
98+
9499
- arduino-boards-fqbn: MegaCore:avr:128:bootloader=no_bootloader,eeprom=keep,BOD=2v7,LTO=Os,clock=8MHz_internal
95100
platform-url: https://mcudude.github.io/MegaCore/package_MCUdude_MegaCore_index.json
96101
arduino-platform: arduino:avr,MegaCore:avr # gcc is taken from arduino:avr

src/IRremote.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ typedef enum {
130130
#define IRDATA_TOGGLE_BIT_MASK 0x08
131131
#define IRDATA_FLAGS_EXTRA_INFO 0x10 // there is unexpected extra info not contained in address and data (e.g. Kaseikyo unknown vendor ID)
132132
#define IRDATA_FLAGS_WAS_OVERFLOW 0x40 // irparams.rawlen is 0 in this case to avoid endless overflow
133+
#define IRDATA_FLAGS_IS_LSB_FIRST 0x00
134+
#define IRDATA_FLAGS_IS_MSB_FIRST 0x80 // Just for info. Value is simply determined by the protocol
133135

134136
struct IRData {
135137
decode_type_t protocol; ///< UNKNOWN, NEC, SONY, RC5, ...
@@ -283,10 +285,10 @@ class IRrecv {
283285
* The main decoding functions used by the individual decoders
284286
*/
285287
bool decodePulseDistanceData(uint8_t aNumberOfBits, uint8_t aStartOffset, unsigned int aBitMarkMicros,
286-
unsigned int aOneSpaceMicros, unsigned int aZeroSpaceMicros, bool aMSBfirst = true);
288+
unsigned int aOneSpaceMicros, unsigned int aZeroSpaceMicros, bool aMSBfirst);
287289

288290
bool decodePulseWidthData(uint8_t aNumberOfBits, uint8_t aStartOffset, unsigned int aOneMarkMicros,
289-
unsigned int aZeroMarkMicros, unsigned int aBitSpaceMicros, bool aMSBfirst = true);
291+
unsigned int aZeroMarkMicros, unsigned int aBitSpaceMicros, bool aMSBfirst);
290292

291293
bool decodeBiPhaseData(uint8_t aNumberOfBits, uint8_t aStartOffset, uint8_t aValueOfSpaceToMarkTransition,
292294
unsigned int aBiphaseTimeUnit);
@@ -317,7 +319,7 @@ class IRrecv {
317319
/*
318320
* Old functions
319321
*/
320-
bool decode(decode_results *aResults) __attribute__ ((deprecated ("You should use decode() without a parameter."))); // deprecated
322+
bool decode(decode_results *aResults) __attribute__ ((deprecated ("Please use decode() without a parameter."))); // deprecated
321323
bool decodeWhynter();
322324

323325
bool decodeSAMSUNG() __attribute__ ((deprecated ("Renamed to decodeSamsung()"))); // deprecated
@@ -395,7 +397,7 @@ class IRsend {
395397
void enableIROut(int khz);
396398

397399
void sendPulseDistanceWidthData(unsigned int aOneMarkMicros, unsigned int aOneSpaceMicros, unsigned int aZeroMarkMicros,
398-
unsigned int aZeroSpaceMicros, uint32_t aData, uint8_t aNumberOfBits, bool aMSBfirst = true, bool aSendStopBit = false);
400+
unsigned int aZeroSpaceMicros, uint32_t aData, uint8_t aNumberOfBits, bool aMSBfirst, bool aSendStopBit = false);
399401
void sendBiphaseData(unsigned int aBiphaseTimeUnit, uint32_t aData, uint8_t aNumberOfBits);
400402

401403
void mark(uint16_t timeMicros);
@@ -472,18 +474,18 @@ class IRsend {
472474
*/
473475
void sendDenon(unsigned long data, int nbits);
474476
void sendDISH(unsigned long data, int nbits);
475-
void sendJVC(unsigned long data, int nbits, bool repeat = false);
477+
void sendJVC(unsigned long data, int nbits, bool repeat = false) __attribute__ ((deprecated ("This old function sends MSB first! Please use sendJVC((uint8_t) aAddress, aCommand, aNumberOfRepeats).")));
476478
void sendLG(unsigned long data, int nbits);
477-
void sendNEC(uint32_t data, uint8_t nbits, bool repeat = false);
478-
void sendPanasonic(uint16_t aAddress, uint32_t aData);
479+
void sendNEC(uint32_t data, uint8_t nbits, bool repeat = false) __attribute__ ((deprecated ("This old function sends MSB first! Please use sendNECRaw().")));
480+
void sendPanasonic(uint16_t aAddress, uint32_t aData) __attribute__ ((deprecated ("This old function sends MSB first! Please use sendPanasonic(aAddress, aCommand, aNumberOfRepeats).")));
479481
void sendRC5(uint32_t data, uint8_t nbits);
480482
void sendRC5ext(uint8_t addr, uint8_t cmd, boolean toggle);
481483
void sendRC6(uint32_t data, uint8_t nbits);
482484
void sendRC6(uint64_t data, uint8_t nbits);
483485
void sendSharpRaw(unsigned long data, int nbits);
484486
void sendSharp(unsigned int address, unsigned int command);
485-
void sendSAMSUNG(unsigned long data, int nbits);
486-
void sendSony(unsigned long data, int nbits);
487+
void sendSAMSUNG(unsigned long data, int nbits); __attribute__ ((deprecated ("This old function sends MSB first! Please use sendSamsung().")));
488+
void sendSony(unsigned long data, int nbits) __attribute__ ((deprecated ("This old function sends MSB first! Please use sendSony(aAddress, aCommand, aNumberOfRepeats).")));;
487489
void sendWhynter(unsigned long data, int nbits);
488490

489491
#if defined(USE_SOFT_SEND_PWM) || defined(USE_NO_SEND_PWM)

src/irReceive.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -910,15 +910,26 @@ void IRrecv::printIRResultShort(Print *aSerial, IRData *aIRDataPtr, uint16_t aLe
910910
/*
911911
* Print raw data
912912
*/
913-
aSerial->print(F(" Raw-Data=0x"));
914-
aSerial->print(aIRDataPtr->decodedRawData, HEX);
913+
if (!(aIRDataPtr->flags & IRDATA_FLAGS_IS_REPEAT) || aIRDataPtr->decodedRawData != 0) {
914+
aSerial->print(F(" Raw-Data=0x"));
915+
aSerial->print(aIRDataPtr->decodedRawData, HEX);
915916

916-
/*
917-
* Print number of bits processed
918-
*/
919-
aSerial->print(F(" ("));
920-
aSerial->print(aIRDataPtr->numberOfBits, DEC);
921-
aSerial->println(F(" bits)"));
917+
/*
918+
* Print number of bits processed
919+
*/
920+
aSerial->print(F(" ("));
921+
aSerial->print(aIRDataPtr->numberOfBits, DEC);
922+
aSerial->print(F(" bits)"));
923+
924+
if (aIRDataPtr->flags & IRDATA_FLAGS_IS_MSB_FIRST) {
925+
aSerial->println(F(" MSB first"));
926+
} else {
927+
aSerial->println(F(" LSB first"));
928+
929+
}
930+
} else {
931+
aSerial->println();
932+
}
922933
}
923934

924935
}

src/ir_BoseWave.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ bool IRrecv::decodeBoseWave() {
104104
}
105105

106106
// Success
107+
// decodedIRData.flags = IRDATA_FLAGS_IS_LSB_FIRST; // Not required, since this is the start value
107108
uint16_t tDecodedValue = decodedIRData.decodedRawData;
108109
uint8_t tCommandNotInverted = tDecodedValue & 0xFF;
109110
uint8_t tCommandInverted = tDecodedValue >> 8;
@@ -116,7 +117,7 @@ bool IRrecv::decodeBoseWave() {
116117

117118
// check for repeat
118119
if (decodedIRData.rawDataPtr->rawbuf[0] < ((BOSEWAVE_REPEAT_SPACE + (BOSEWAVE_REPEAT_SPACE / 4)) / MICROS_PER_TICK)) {
119-
decodedIRData.flags = IRDATA_FLAGS_IS_REPEAT;
120+
decodedIRData.flags = IRDATA_FLAGS_IS_REPEAT | IRDATA_FLAGS_IS_LSB_FIRST;
120121
}
121122

122123
decodedIRData.command = tCommandNotInverted;

src/ir_Denon.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ bool IRrecv::decodeDenon() {
136136
}
137137

138138
// Read the bits in
139-
if (!decodePulseDistanceData(DENON_BITS, 1, DENON_BIT_MARK, DENON_ONE_SPACE, DENON_ZERO_SPACE)) {
139+
if (!decodePulseDistanceData(DENON_BITS, 1, DENON_BIT_MARK, DENON_ONE_SPACE, DENON_ZERO_SPACE, MSB_FIRST)) {
140140
DBG_PRINT("Denon: ");
141141
DBG_PRINTLN("Decode failed");
142142
return false;
@@ -150,6 +150,7 @@ bool IRrecv::decodeDenon() {
150150
}
151151

152152
// Success
153+
decodedIRData.flags = IRDATA_FLAGS_IS_MSB_FIRST;
153154
uint8_t tFrameBits = decodedIRData.decodedRawData & 0x03;
154155
decodedIRData.command = decodedIRData.decodedRawData >> DENON_FRAME_BITS;
155156
decodedIRData.address = decodedIRData.command >> DENON_COMMAND_BITS;
@@ -161,7 +162,7 @@ bool IRrecv::decodeDenon() {
161162
repeatCount++;
162163
if (tFrameBits == 0x3 || tFrameBits == 0x1) {
163164
// We are in the auto repeated frame with the inverted command
164-
decodedIRData.flags = IRDATA_FLAGS_IS_AUTO_REPEAT;
165+
decodedIRData.flags = IRDATA_FLAGS_IS_AUTO_REPEAT | IRDATA_FLAGS_IS_MSB_FIRST;
165166
// Check parity of consecutive received commands. There is no parity in one data set.
166167
uint8_t tLastCommand = lastDecodedCommand;
167168
if (tLastCommand != (uint8_t) (~tCommand)) {

src/ir_Dish.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void IRsend::sendDISH(unsigned long data, int nbits) {
3838
mark(DISH_HEADER_MARK);
3939
space(DISH_HEADER_SPACE);
4040

41-
sendPulseDistanceWidthData(DISH_BIT_MARK, DISH_ONE_SPACE, DISH_BIT_MARK, DISH_ZERO_SPACE, data, nbits);
41+
sendPulseDistanceWidthData(DISH_BIT_MARK, DISH_ONE_SPACE, DISH_BIT_MARK, DISH_ZERO_SPACE, data, nbits, MSB_FIRST);
4242
mark(DISH_HEADER_MARK); //added 26th March 2016, by AnalysIR ( https://www.AnalysIR.com )
4343
space(0); // Always end with the LED off
4444
interrupts();

src/ir_JVC.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void IRsend::sendJVC(uint8_t aAddress, uint8_t aCommand, uint8_t aNumberOfRepeat
7979

8080
// Address + command
8181
sendPulseDistanceWidthData(JVC_BIT_MARK, JVC_ONE_SPACE, JVC_BIT_MARK, JVC_ZERO_SPACE,
82-
aAddress | aCommand << JVC_ADDRESS_BITS, JVC_BITS, LSB_FIRST, SEND_STOP_BIT);
82+
aAddress | (aCommand << JVC_ADDRESS_BITS), JVC_BITS, LSB_FIRST, SEND_STOP_BIT);
8383

8484
interrupts();
8585

@@ -116,7 +116,7 @@ bool IRrecv::decodeJVC() {
116116
/*
117117
* We have a repeat here, so do not check for start bit
118118
*/
119-
decodedIRData.flags = IRDATA_FLAGS_IS_REPEAT;
119+
decodedIRData.flags = IRDATA_FLAGS_IS_REPEAT | IRDATA_FLAGS_IS_LSB_FIRST;
120120
}
121121
} else {
122122

@@ -137,6 +137,7 @@ bool IRrecv::decodeJVC() {
137137
}
138138

139139
// Success
140+
// decodedIRData.flags = IRDATA_FLAGS_IS_LSB_FIRST; // Not required, since this is the start value
140141
uint8_t tCommand = decodedIRData.decodedRawData >> JVC_ADDRESS_BITS; // upper 8 bits of LSB first value
141142
uint8_t tAddress = decodedIRData.decodedRawData & 0xFF; // lowest 8 bit of LSB first value
142143

@@ -209,7 +210,7 @@ bool IRrecv::decodeJVC() {
209210
//+=============================================================================
210211
// JVC does NOT repeat by sending a separate code (like NEC does).
211212
// The JVC protocol repeats by skipping the header.
212-
//
213+
// Old version with MSB first Data
213214
void IRsend::sendJVC(unsigned long data, int nbits, bool repeat) {
214215
// Set IR carrier frequency
215216
enableIROut(38);
@@ -220,7 +221,7 @@ void IRsend::sendJVC(unsigned long data, int nbits, bool repeat) {
220221
space(JVC_HEADER_SPACE);
221222
}
222223

223-
// Data + stop bit
224+
// Old version with MSB first Data
224225
sendPulseDistanceWidthData(JVC_BIT_MARK, JVC_ONE_SPACE, JVC_BIT_MARK, JVC_ZERO_SPACE, data, nbits, MSB_FIRST, SEND_STOP_BIT);
225226

226227
}

src/ir_Kaseikyo.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ bool IRrecv::decodeKaseikyo() {
184184
DBG_PRINTLN("Address, command + parity decode failed");
185185
return false;
186186
}
187+
188+
// Success
189+
// decodedIRData.flags = IRDATA_FLAGS_IS_LSB_FIRST; // Not required, since this is the start value
187190
LongUnion tValue;
188191
tValue.ULong = decodedIRData.decodedRawData;
189192
decodedIRData.address = (tValue.UWord.LowWord >> KASEIKYO_VENDOR_ID_PARITY_BITS); // remove vendor parity
@@ -198,7 +201,7 @@ bool IRrecv::decodeKaseikyo() {
198201
DBG_PRINT(decodedIRData.decodedRawData, HEX);
199202
DBG_PRINT(" VendorID=0x");
200203
DBG_PRINTLN(tVendorId, HEX);
201-
decodedIRData.flags = IRDATA_FLAGS_PARITY_FAILED;
204+
decodedIRData.flags = IRDATA_FLAGS_PARITY_FAILED | IRDATA_FLAGS_IS_LSB_FIRST;
202205
}
203206

204207
if (tProtocol == KASEIKYO) {
@@ -219,7 +222,7 @@ bool IRrecv::decodeKaseikyo() {
219222
DBG_PRINT(decodedIRData.address, HEX);
220223
DBG_PRINT(" command=0x");
221224
DBG_PRINTLN(decodedIRData.command, HEX);
222-
decodedIRData.flags = IRDATA_FLAGS_PARITY_FAILED;
225+
decodedIRData.flags |= IRDATA_FLAGS_PARITY_FAILED;
223226
}
224227

225228
// check for repeat
@@ -267,6 +270,7 @@ bool IRrecv::decodePanasonic() {
267270

268271
#endif
269272

273+
// Old version with MSB first Data
270274
void IRsend::sendPanasonic(uint16_t aAddress, uint32_t aData) {
271275
// Set IR carrier frequency
272276
enableIROut(37); // 36.7kHz is the correct frequency
@@ -275,13 +279,13 @@ void IRsend::sendPanasonic(uint16_t aAddress, uint32_t aData) {
275279
mark(KASEIKYO_HEADER_MARK);
276280
space(KASEIKYO_HEADER_SPACE);
277281

278-
// Address
282+
// Old version with MSB first Data Address
279283
sendPulseDistanceWidthData(KASEIKYO_BIT_MARK, KASEIKYO_ONE_SPACE, KASEIKYO_BIT_MARK, KASEIKYO_ZERO_SPACE, aAddress,
280-
KASEIKYO_ADDRESS_BITS);
284+
KASEIKYO_ADDRESS_BITS, MSB_FIRST);
281285

282-
// Data + stop bit
286+
// Old version with MSB first Data Data + stop bit
283287
sendPulseDistanceWidthData(KASEIKYO_BIT_MARK, KASEIKYO_ONE_SPACE, KASEIKYO_BIT_MARK, KASEIKYO_ZERO_SPACE, aData,
284-
KASEIKYO_DATA_BITS);
288+
KASEIKYO_DATA_BITS, MSB_FIRST);
285289

286290
}
287291

src/ir_LG.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void IRsend::sendLG(uint8_t aAddress, uint16_t aCommand, uint8_t aNumberOfRepeat
9292
tTempForChecksum >>= 4; // shift by a nibble
9393
}
9494
tRawData |= tChecksum;
95-
sendLG(tRawData, aNumberOfRepeats, aIsRepeat);
95+
sendLGRaw(tRawData, aNumberOfRepeats, aIsRepeat);
9696
}
9797

9898
/*
@@ -155,7 +155,7 @@ bool IRrecv::decodeLG() {
155155
if (decodedIRData.rawDataPtr->rawlen == 4) {
156156
if (MATCH_SPACE(decodedIRData.rawDataPtr->rawbuf[2], LG_REPEAT_HEADER_SPACE)
157157
&& MATCH_MARK(decodedIRData.rawDataPtr->rawbuf[3], LG_BIT_MARK)) {
158-
decodedIRData.flags = IRDATA_FLAGS_IS_REPEAT;
158+
decodedIRData.flags = IRDATA_FLAGS_IS_REPEAT | IRDATA_FLAGS_IS_MSB_FIRST;
159159
decodedIRData.address = lastDecodedAddress;
160160
decodedIRData.command = lastDecodedCommand;
161161
return true;
@@ -184,6 +184,7 @@ bool IRrecv::decodeLG() {
184184
}
185185

186186
// Success
187+
decodedIRData.flags = IRDATA_FLAGS_IS_MSB_FIRST;
187188
decodedIRData.command = (decodedIRData.decodedRawData >> LG_CHECKSUM_BITS) & 0xFFFF;
188189
decodedIRData.address = decodedIRData.decodedRawData >> (LG_COMMAND_BITS + LG_CHECKSUM_BITS); // first 8 bit
189190

src/ir_Lego.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ bool IRrecv::decodeLegoPowerFunctions() {
184184
}
185185

186186
// Success
187+
decodedIRData.flags = IRDATA_FLAGS_IS_MSB_FIRST;
187188
uint16_t tDecodedValue = decodedIRData.decodedRawData;
188189
uint8_t tToggleEscapeChannel = tDecodedValue >> (LEGO_MODE_BITS + LEGO_COMMAND_BITS + LEGO_PARITY_BITS);
189190
uint8_t tMode = (tDecodedValue >> (LEGO_COMMAND_BITS + LEGO_PARITY_BITS)) & 0xF;
@@ -210,7 +211,7 @@ bool IRrecv::decodeLegoPowerFunctions() {
210211
DBG_PRINT(", 0x");
211212
DBG_PRINTLN(tData, HEX);
212213
// might not be an error, so just continue
213-
decodedIRData.flags = IRDATA_FLAGS_PARITY_FAILED;
214+
decodedIRData.flags = IRDATA_FLAGS_PARITY_FAILED | IRDATA_FLAGS_IS_MSB_FIRST;
214215
}
215216

216217
/*

0 commit comments

Comments
 (0)