Skip to content

Commit 5389c9d

Browse files
committed
PulseDistanceWidthProtocolConstants now in PROGMEM
1 parent f570ed2 commit 5389c9d

21 files changed

+391
-130
lines changed

examples/ReceiveAndSendDistanceWidth/ReceiveAndSendDistanceWidth.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080

8181
// Storage for the recorded code, pre-filled with NEC data
8282
IRRawDataType sDecodedRawDataArray[DECODED_RAW_DATA_ARRAY_SIZE] = { 0x7B34ED12 }; // Initialize with NEC address 0x12 and command 0x34
83-
DistanceWidthTimingInfoStruct sDistanceWidthTimingInfo = { 9000, 4500, 560, 1690, 560, 560 }; // Initialize with NEC timing
83+
DistanceWidthTimingInfoStruct sDistanceWidthTimingInfo = { 9000, 4500, 560, 1690, 560, 560 }; // Initialize with NEC timing
8484
uint8_t sNumberOfBits = 32;
8585

8686
bool sSendButtonWasActive;

examples/SendDemo/SendDemo.ino

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
#define DELAY_AFTER_SEND 2000
5151
#define DELAY_AFTER_LOOP 5000
5252

53+
#if __INT_WIDTH__ < 32
54+
IRRawDataType const tRawDataPGM[] PROGMEM = { 0xB02002, 0xA010 }; // LSB of tRawData[0] is sent first
55+
#endif
56+
5357
void setup() {
5458
Serial.begin(115200);
5559

@@ -145,7 +149,7 @@ void loop() {
145149
delay(DELAY_AFTER_SEND);
146150

147151
if (sRepeats == 0) {
148-
#if FLASHEND >= 0x3FFF && ((defined(RAMEND) && RAMEND > 0x6FF) || (defined(RAMSIZE) && RAMSIZE > 0x6FF)) // For 16k flash or more, like ATtiny1604. Code does not fit in program memory of ATtiny85 etc.
152+
#if FLASHEND >= 0x3FFF && ( (!defined(RAMEND) && !defined(RAMSIZE)) || (defined(RAMEND) && RAMEND > 0x6FF) || (defined(RAMSIZE) && RAMSIZE > 0x6FF)) // For 16k flash or more, like ATtiny1604. Code does not fit in program memory of ATtiny85 etc.
149153
/*
150154
* Send constant values only once in this demo
151155
*/
@@ -197,10 +201,9 @@ void loop() {
197201
Serial.println(F("Send Panasonic 0xB, 0x10 as 48 bit PulseDistance using ProtocolConstants"));
198202
Serial.flush();
199203
#if __INT_WIDTH__ < 32
200-
IRRawDataType tRawData[] = { 0xB02002, 0xA010 }; // LSB of tRawData[0] is sent first
201-
IrSender.sendPulseDistanceWidthFromArray(&KaseikyoProtocolConstants, &tRawData[0], 48, NO_REPEATS); // Panasonic is a Kaseikyo variant
204+
IrSender.sendPulseDistanceWidthFromPGMArray_P(&KaseikyoProtocolConstants, &tRawDataPGM[0], 48, NO_REPEATS); // Panasonic is a Kaseikyo variant
202205
#else
203-
IrSender.sendPulseDistanceWidth(&KaseikyoProtocolConstants, 0xA010B02002, 48, NO_REPEATS); // Panasonic is a Kaseikyo variant
206+
IrSender.sendPulseDistanceWidth_P(&KaseikyoProtocolConstants, 0xA010B02002, 48, NO_REPEATS); // Panasonic is a Kaseikyo variant
204207
#endif
205208

206209
delay(DELAY_AFTER_SEND);
@@ -212,24 +215,25 @@ void loop() {
212215
Serial.println(F(" LSB first"));
213216
Serial.flush();
214217
#if __INT_WIDTH__ < 32
215-
IrSender.sendPulseDistanceWidthFromArray(38, 3450, 1700, 450, 1250, 450, 400, &tRawData[0], 48,
218+
IrSender.sendPulseDistanceWidthFromPGMArray(38, 3450, 1700, 450, 1250, 450, 400, &tRawDataPGM[0], 48,
216219
PROTOCOL_IS_LSB_FIRST, 0, NO_REPEATS);
217220
#else
218-
IrSender.sendPulseDistanceWidth(38, 3450, 1700, 450, 1250, 450, 400, 0xA010B02002, 48, PROTOCOL_IS_LSB_FIRST,
219-
0, NO_REPEATS);
221+
IrSender.sendPulseDistanceWidth(38, 3450, 1700, 450, 1250, 450, 400, 0xA010B02002, 48, PROTOCOL_IS_LSB_FIRST, 0,
222+
NO_REPEATS);
220223
#endif
221224
delay(DELAY_AFTER_SEND);
222225

223226
// The same with MSB first. Use bit reversed raw data of LSB first part
224227
Serial.println(F(" MSB first"));
228+
IRRawDataType tRawData[4];
225229
#if __INT_WIDTH__ < 32
226230
tRawData[0] = 0x40040D00; // MSB of tRawData[0] is sent first
227231
tRawData[1] = 0x805;
228232
IrSender.sendPulseDistanceWidthFromArray(38, 3450, 1700, 450, 1250, 450, 400, &tRawData[0], 48,
229233
PROTOCOL_IS_MSB_FIRST, 0, NO_REPEATS);
230234
#else
231-
IrSender.sendPulseDistanceWidth(38, 3450, 1700, 450, 1250, 450, 400, 0x40040D000805, 48, PROTOCOL_IS_MSB_FIRST,
232-
0, NO_REPEATS);
235+
IrSender.sendPulseDistanceWidth(38, 3450, 1700, 450, 1250, 450, 400, 0x40040D000805, 48, PROTOCOL_IS_MSB_FIRST, 0,
236+
NO_REPEATS);
233237
#endif
234238
delay(DELAY_AFTER_SEND);
235239

@@ -242,8 +246,10 @@ void loop() {
242246
IrSender.sendPulseDistanceWidthFromArray(38, 8900, 4450, 550, 1700, 550, 600, &tRawData[0], 72, PROTOCOL_IS_LSB_FIRST, 0,
243247
NO_REPEATS);
244248
# else
245-
IRRawDataType tRawData[] = { 0xAFEDCBA987654321, 0x5A }; // LSB of tRawData[0] is sent first
246-
IrSender.sendPulseDistanceWidthFromArray(38, 8900, 4450, 550, 1700, 550, 600, &tRawData[0], 72, PROTOCOL_IS_LSB_FIRST, 0, NO_REPEATS);
249+
tRawData[0] = 0xAFEDCBA987654321;
250+
tRawData[1] = 0x5A; // LSB of tRawData[0] is sent first
251+
IrSender.sendPulseDistanceWidthFromArray(38, 8900, 4450, 550, 1700, 550, 600, &tRawData[0], 72, PROTOCOL_IS_LSB_FIRST, 0,
252+
NO_REPEATS);
247253
# endif
248254
delay(DELAY_AFTER_SEND);
249255

@@ -254,8 +260,7 @@ void loop() {
254260
IrSender.sendPulseDistanceWidthFromArray(38, 300, 600, 600, 300, 300, 600, &tRawData[0], 52,
255261
PROTOCOL_IS_LSB_FIRST, 0, 0);
256262
#else
257-
IrSender.sendPulseDistanceWidth(38, 300, 600, 600, 300, 300, 600, 0xDCBA987654321, 52, PROTOCOL_IS_LSB_FIRST,
258-
0, 0);
263+
IrSender.sendPulseDistanceWidth(38, 300, 600, 600, 300, 300, 600, 0xDCBA987654321, 52, PROTOCOL_IS_LSB_FIRST, 0, 0);
259264
#endif
260265
delay(DELAY_AFTER_SEND);
261266
#endif
@@ -364,7 +369,7 @@ void loop() {
364369
IrSender.sendRC6A(sAddress & 0xFF, sCommand, sRepeats, 0x2711, true);
365370
delay(DELAY_AFTER_SEND);
366371

367-
#if FLASHEND >= 0x3FFF && ((defined(RAMEND) && RAMEND > 0x4FF) || (defined(RAMSIZE) && RAMSIZE > 0x4FF)) // For 16k flash or more, like ATtiny1604. Code does not fit in program memory of ATtiny85 etc.
372+
#if FLASHEND >= 0x3FFF && ((!defined(RAMEND) && !defined(RAMSIZE)) || (defined(RAMEND) && RAMEND > 0x4FF) || (defined(RAMSIZE) && RAMSIZE > 0x4FF)) // For 16k flash or more, like ATtiny1604. Code does not fit in program memory of ATtiny85 etc.
368373

369374
Serial.println(F("Send MagiQuest"));
370375
Serial.flush();
@@ -389,14 +394,14 @@ void loop() {
389394
Serial.println(F("Send next protocols with IrSender.write"));
390395
Serial.flush();
391396

392-
IRSendData.protocol = JVC; // switch protocol
397+
IRSendData.protocol = JVC;// switch protocol
393398
Serial.print(F("Send "));
394399
Serial.println(getProtocolString(IRSendData.protocol));
395400
Serial.flush();
396401
IrSender.write(&IRSendData, sRepeats);
397402
delay(DELAY_AFTER_SEND);
398403

399-
IRSendData.command = s16BitCommand; // LG support more than 8 bit command
404+
IRSendData.command = s16BitCommand;// LG support more than 8 bit command
400405

401406
IRSendData.protocol = SAMSUNG;
402407
Serial.print(F("Send "));

examples/UnitTest/UnitTest.ino

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@
119119
volatile bool sDataJustReceived = false;
120120
void ReceiveCompleteCallbackHandler();
121121

122+
#if __INT_WIDTH__ < 32
123+
IRRawDataType const tRawDataPGM[4] PROGMEM = { 0xB02002, 0xA010, 0x0, 0x0 }; // LSB of tRawData[0] is sent first
124+
#endif
125+
122126
void setup() {
123127
pinMode(DEBUG_BUTTON_PIN, INPUT_PULLUP);
124128

@@ -130,7 +134,7 @@ void setup() {
130134
// Required for boards using USB code for Serial like Leonardo.
131135
// Is void for USB Serial implementations using external chips e.g. a CH340.
132136
while (!Serial)
133-
;
137+
;
134138
// !!! Program will not proceed if no Serial Monitor is attached !!!
135139
#endif
136140
// Just to know which program is running on my Arduino
@@ -169,7 +173,7 @@ void setup() {
169173
#else
170174
// Here the macro IR_SEND_PIN is not defined or undefined above with #undef IR_SEND_PIN
171175
uint8_t tSendPin = 3;
172-
IrSender.begin(tSendPin, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN); // Specify send pin and enable feedback LED at default feedback LED pin
176+
IrSender.begin(tSendPin, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN);// Specify send pin and enable feedback LED at default feedback LED pin
173177
// You can change send pin later with IrSender.setSendPin();
174178

175179
Serial.print(F("Send IR signals at pin "));
@@ -485,17 +489,14 @@ void loop() {
485489
delay(DELAY_AFTER_SEND);
486490
# endif
487491

488-
# if __INT_WIDTH__ < 32
489-
IRRawDataType tRawData[4] = { 0xB02002, 0xA010, 0x0, 0x0 }; // LSB of tRawData[0] is sent first
490-
# endif
491492
# if defined(DECODE_PANASONIC) || defined(DECODE_KASEIKYO)
492493
Serial.println(F("Send Panasonic 0xB, 0x10 as 48 bit PulseDistance using ProtocolConstants"));
493494
Serial.flush();
494495
# if __INT_WIDTH__ < 32
495-
IrSender.sendPulseDistanceWidthFromArray(&KaseikyoProtocolConstants, &tRawData[0], 48, NO_REPEATS); // Panasonic is a Kaseikyo variant
496+
IrSender.sendPulseDistanceWidthFromPGMArray_P(&KaseikyoProtocolConstants, &tRawDataPGM[0], 48, NO_REPEATS); // Panasonic is a Kaseikyo variant
496497
checkReceive(0x0B, 0x10);
497498
# else
498-
IrSender.sendPulseDistanceWidth(&KaseikyoProtocolConstants, 0xA010B02002, 48, NO_REPEATS); // Panasonic is a Kaseikyo variant
499+
IrSender.sendPulseDistanceWidth_P(&KaseikyoProtocolConstants, 0xA010B02002, 48, NO_REPEATS); // Panasonic is a Kaseikyo variant
499500
checkReceivedRawData(0xA010B02002);
500501
# endif
501502
delay(DELAY_AFTER_SEND);
@@ -507,18 +508,19 @@ void loop() {
507508
Serial.println(F("-LSB first"));
508509
Serial.flush();
509510
# if __INT_WIDTH__ < 32
510-
IrSender.sendPulseDistanceWidthFromArray(38, 3450, 1700, 450, 1250, 450, 400, &tRawData[0], 48, PROTOCOL_IS_LSB_FIRST, 0,
511-
NO_REPEATS);
511+
IrSender.sendPulseDistanceWidthFromPGMArray(38, 3450, 1700, 450, 1250, 450, 400, &tRawDataPGM[0], 48, PROTOCOL_IS_LSB_FIRST,
512+
0, NO_REPEATS);
512513
checkReceive(0x0B, 0x10);
513514
# else
514515
IrSender.sendPulseDistanceWidth(38, 3450, 1700, 450, 1250, 450, 400, 0xA010B02002, 48, PROTOCOL_IS_LSB_FIRST, 0,
515-
NO_REPEATS);
516+
NO_REPEATS);
516517
checkReceivedRawData(0xA010B02002);
517518
# endif
518519
delay(DELAY_AFTER_SEND);
519520

520521
// The same with MSB first. Use bit reversed raw data of LSB first part
521522
Serial.println(F("-MSB first"));
523+
IRRawDataType tRawData[4];
522524
# if __INT_WIDTH__ < 32
523525
tRawData[0] = 0x40040D00; // MSB of tRawData[0] is sent first
524526
tRawData[1] = 0x805;
@@ -527,7 +529,7 @@ void loop() {
527529
checkReceive(0x0B, 0x10);
528530
# else
529531
IrSender.sendPulseDistanceWidth(38, 3450, 1700, 450, 1250, 450, 400, 0x40040D000805, 48, PROTOCOL_IS_MSB_FIRST, 0,
530-
NO_REPEATS);
532+
NO_REPEATS);
531533
checkReceivedRawData(0x40040D000805);
532534
# endif
533535

@@ -579,9 +581,10 @@ void loop() {
579581
NO_REPEATS);
580582
checkReceivedArray(tRawData, 3);
581583
# else
582-
IRRawDataType tRawData[] = { 0xAFEDCBA987654321, 0x5A }; // LSB of tRawData[0] is sent first
584+
tRawData[0] = 0xAFEDCBA987654321;
585+
tRawData[1] = 0x5A; // LSB of tRawData[0] is sent first
583586
IrSender.sendPulseDistanceWidthFromArray(38, 8900, 4450, 550, 1700, 550, 600, &tRawData[0], 72, PROTOCOL_IS_LSB_FIRST, 0,
584-
NO_REPEATS);
587+
NO_REPEATS);
585588
checkReceivedArray(tRawData, 2);
586589
# endif
587590
delay(DELAY_AFTER_SEND);

src/IRReceive.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,15 @@ bool IRrecv::decodePulseDistanceWidthData(PulseDistanceWidthProtocolConstants *a
988988
aProtocolConstants->Flags);
989989
}
990990

991+
bool IRrecv::decodePulseDistanceWidthData_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM,
992+
uint_fast8_t aNumberOfBits, IRRawlenType aStartOffset) {
993+
PulseDistanceWidthProtocolConstants tTemporaryPulseDistanceWidthProtocolConstants;
994+
memcpy_P(&tTemporaryPulseDistanceWidthProtocolConstants, aProtocolConstantsPGM,
995+
sizeof(tTemporaryPulseDistanceWidthProtocolConstants));
996+
997+
return decodePulseDistanceWidthData(&tTemporaryPulseDistanceWidthProtocolConstants, aNumberOfBits, aStartOffset);
998+
}
999+
9911000
/*
9921001
* Static variables for the getBiphaselevel function
9931002
*/
@@ -1171,6 +1180,25 @@ bool IRrecv::checkHeader(PulseDistanceWidthProtocolConstants *aProtocolConstants
11711180
return true;
11721181
}
11731182

1183+
bool IRrecv::checkHeader_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM) {
1184+
// Check header "mark" and "space"
1185+
if (!matchMark(decodedIRData.rawDataPtr->rawbuf[1], pgm_read_word(&aProtocolConstantsPGM->DistanceWidthTimingInfo.HeaderMarkMicros))) {
1186+
#if defined(LOCAL_TRACE)
1187+
Serial.print(::getProtocolString(aProtocolConstants->ProtocolIndex));
1188+
Serial.println(F(": Header mark length is wrong"));
1189+
#endif
1190+
return false;
1191+
}
1192+
if (!matchSpace(decodedIRData.rawDataPtr->rawbuf[2], pgm_read_word(&aProtocolConstantsPGM->DistanceWidthTimingInfo.HeaderSpaceMicros))) {
1193+
#if defined(LOCAL_TRACE)
1194+
Serial.print(::getProtocolString(aProtocolConstants->ProtocolIndex));
1195+
Serial.println(F(": Header space length is wrong"));
1196+
#endif
1197+
return false;
1198+
}
1199+
return true;
1200+
}
1201+
11741202
/*
11751203
* Does not check for same address and command, because it is almost not possible to press 2 different buttons on the remote within around 100 ms.
11761204
* And if really required, it can be enabled here, or done manually in user program.

0 commit comments

Comments
 (0)