Skip to content

Commit af17724

Browse files
committed
Workaround for LG parity problem #755.
1 parent 23ed2f8 commit af17724

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

src/IRremote.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ class IRsend {
428428

429429
void sendLGRepeat();
430430
void sendLG(uint8_t aAddress, uint16_t aCommand, uint8_t aNumberOfRepeats, bool aIsRepeat = false);
431+
void sendLGRaw(uint32_t aRawData, uint8_t aNumberOfRepeats, bool aIsRepeat = false);
431432
void sendNECRepeat();
432433
void sendNEC(uint16_t aAddress, uint8_t aCommand, uint8_t aNumberOfRepeats, bool aIsRepeat = false);
433434

src/ir_LG.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
//==============================================================================
4141
// MSB first, timing and repeat is like NEC but 28 data bits
4242
// MSB! first, 1 start bit + 8 bit address + 16 bit command + 4 bit parity + 1 stop bit.
43+
// In https://github.com/Arduino-IRremote/Arduino-IRremote/discussions/755 we saw no key repetition
44+
// and a intended parity error, or something I do not understand.
4345
#define LG_ADDRESS_BITS 8
4446
#define LG_COMMAND_BITS 16
4547
#define LG_CHECKSUM_BITS 4
@@ -79,6 +81,24 @@ void IRsend::sendLGRepeat() {
7981
* There is NO delay after the last sent repeat!
8082
*/
8183
void IRsend::sendLG(uint8_t aAddress, uint16_t aCommand, uint8_t aNumberOfRepeats, bool aIsRepeat) {
84+
uint32_t tRawData = ((uint32_t) aAddress << (LG_COMMAND_BITS + LG_CHECKSUM_BITS)) | (aCommand << LG_CHECKSUM_BITS);
85+
/*
86+
* My guess of the checksum
87+
*/
88+
uint8_t tChecksum = 0;
89+
uint16_t tTempForChecksum = aCommand;
90+
for (int i = 0; i < 4; ++i) {
91+
tChecksum += tTempForChecksum & 0xF; // add low nibble
92+
tTempForChecksum >>= 4; // shift by a nibble
93+
}
94+
tRawData |= tChecksum;
95+
sendLG(tRawData, aNumberOfRepeats, aIsRepeat);
96+
}
97+
98+
/*
99+
* Here you can put your raw data, even one with "wrong" parity
100+
*/
101+
void IRsend::sendLGRaw(uint32_t aRawData, uint8_t aNumberOfRepeats, bool aIsRepeat) {
82102
if (aIsRepeat) {
83103
sendLGRepeat();
84104
return;
@@ -91,21 +111,8 @@ void IRsend::sendLG(uint8_t aAddress, uint16_t aCommand, uint8_t aNumberOfRepeat
91111
mark(LG_HEADER_MARK);
92112
space(LG_HEADER_SPACE);
93113

94-
uint32_t tData = ((uint32_t) aAddress << (LG_COMMAND_BITS + LG_CHECKSUM_BITS)) | (aCommand << LG_CHECKSUM_BITS);
95-
96-
/*
97-
* My guess of the checksum
98-
*/
99-
uint8_t tChecksum = 0;
100-
uint16_t tTempForChecksum = aCommand;
101-
for (int i = 0; i < 4; ++i) {
102-
tChecksum += tTempForChecksum & 0xF; // add low nibble
103-
tTempForChecksum >>= 4; // shift by a nibble
104-
}
105-
tData |= tChecksum;
106-
107114
// MSB first
108-
sendPulseDistanceWidthData(LG_BIT_MARK, LG_ONE_SPACE, LG_BIT_MARK, LG_ZERO_SPACE, tData, LG_BITS, true, true);
115+
sendPulseDistanceWidthData(LG_BIT_MARK, LG_ONE_SPACE, LG_BIT_MARK, LG_ZERO_SPACE, aRawData, LG_BITS, true, true);
109116

110117
interrupts();
111118

@@ -146,7 +153,8 @@ bool IRrecv::decodeLG() {
146153

147154
// Check for repeat - here we have another header space length
148155
if (decodedIRData.rawDataPtr->rawlen == 4) {
149-
if (MATCH_SPACE(decodedIRData.rawDataPtr->rawbuf[2], LG_REPEAT_HEADER_SPACE) && MATCH_MARK(decodedIRData.rawDataPtr->rawbuf[3], LG_BIT_MARK)) {
156+
if (MATCH_SPACE(decodedIRData.rawDataPtr->rawbuf[2], LG_REPEAT_HEADER_SPACE)
157+
&& MATCH_MARK(decodedIRData.rawDataPtr->rawbuf[3], LG_BIT_MARK)) {
150158
decodedIRData.flags = IRDATA_FLAGS_IS_REPEAT;
151159
decodedIRData.address = lastDecodedAddress;
152160
decodedIRData.command = lastDecodedCommand;

0 commit comments

Comments
 (0)