Skip to content

Commit 85bf1c7

Browse files
committed
Moved dump/print functions from example to irReceiver
1 parent e6c8b1c commit 85bf1c7

File tree

8 files changed

+194
-180
lines changed

8 files changed

+194
-180
lines changed

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
- Added Lego_PF decode.
88
- Added new example IR2Keyboard.
99
- Changed internal usage of custom_delay_usec.
10+
- Moved dump/print functions from example to irReceiver.
11+
- irPronto.cpp: Using Print instead of Stream saves 1020 bytes program memory. Changed from & to * parameter type to be more transparent and consistent with other code of IRremote.
1012

1113
## 2.7.0 2020/09
1214
- Added ATmega328PB support.

examples/IRreceiveDump/IRreceiveDump.ino

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,35 +42,10 @@ void setup() {
4242
Serial.println(IR_RECEIVE_PIN);
4343
}
4444

45-
void dump() {
46-
// Dumps out the decode_results structure.
47-
// Call this after IRrecv::decode()
48-
int count = IrReceiver.results.rawlen;
49-
IrReceiver.printResultShort(&Serial);
50-
51-
Serial.print(" (");
52-
Serial.print(IrReceiver.results.bits, DEC);
53-
Serial.println(" bits)");
54-
Serial.print("Raw [");
55-
Serial.print(count, DEC);
56-
Serial.print("]: ");
57-
58-
for (int i = 0; i < count; i++) {
59-
if (i & 1) {
60-
Serial.print(IrReceiver.results.rawbuf[i] * MICROS_PER_TICK, DEC);
61-
} else {
62-
Serial.write('-');
63-
Serial.print((unsigned long) IrReceiver.results.rawbuf[i] * MICROS_PER_TICK, DEC);
64-
}
65-
Serial.print(" ");
66-
}
67-
Serial.println();
68-
}
69-
7045
void loop() {
7146
if (IrReceiver.decode()) {
7247
Serial.println();
73-
dump();
48+
IrReceiver.printIRResultRaw(&Serial);
7449
IrReceiver.resume(); // Receive the next value
7550
}
7651
}

examples/IRreceiveDumpV2/IRreceiveDumpV2.ino

Lines changed: 8 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -50,114 +50,19 @@ void dumpInfo() {
5050
Serial.println(" bits)");
5151
}
5252

53-
//+=============================================================================
54-
// Dump out the decode_results structure.
55-
//
56-
void dumpRaw() {
57-
// Print Raw data
58-
Serial.print("Timing[");
59-
Serial.print(IrReceiver.results.rawlen - 1, DEC);
60-
Serial.println("]: ");
61-
62-
for (unsigned int i = 1; i < IrReceiver.results.rawlen; i++) {
63-
unsigned long x = IrReceiver.results.rawbuf[i] * MICROS_PER_TICK;
64-
if (!(i & 1)) { // even
65-
Serial.print("-");
66-
if (x < 1000) {
67-
Serial.print(" ");
68-
}
69-
if (x < 100) {
70-
Serial.print(" ");
71-
}
72-
Serial.print(x, DEC);
73-
} else { // odd
74-
Serial.print(" ");
75-
Serial.print("+");
76-
if (x < 1000) {
77-
Serial.print(" ");
78-
}
79-
if (x < 100) {
80-
Serial.print(" ");
81-
}
82-
Serial.print(x, DEC);
83-
if (i < IrReceiver.results.rawlen - 1) {
84-
Serial.print(", "); //',' not needed for last one
85-
}
86-
}
87-
if (!(i % 8)) {
88-
Serial.println("");
89-
}
90-
}
91-
Serial.println(""); // Newline
92-
}
93-
94-
//+=============================================================================
95-
// Dump out the decode_results structure.
96-
//
97-
void dumpCode() {
98-
// Start declaration
99-
Serial.print("unsigned int "); // variable type
100-
Serial.print("rawData["); // array name
101-
Serial.print(IrReceiver.results.rawlen - 1, DEC); // array size
102-
Serial.print("] = {"); // Start declaration
103-
104-
// Dump data
105-
for (unsigned int i = 1; i < IrReceiver.results.rawlen; i++) {
106-
Serial.print(IrReceiver.results.rawbuf[i] * MICROS_PER_TICK, DEC);
107-
if (i < IrReceiver.results.rawlen - 1)
108-
Serial.print(","); // ',' not needed on last one
109-
if (!(i & 1))
110-
Serial.print(" ");
111-
}
112-
113-
// End declaration
114-
Serial.print("};"); //
115-
116-
// Comment
117-
Serial.print(" // ");
118-
IrReceiver.printResultShort(&Serial);
119-
120-
// Newline
121-
Serial.println("");
122-
123-
// Now dump "known" codes
124-
if (IrReceiver.results.decode_type != UNKNOWN) {
125-
126-
// Some protocols have an address
127-
if(IrReceiver.results.address != 0){
128-
Serial.print("unsigned int addr = 0x");
129-
Serial.print(IrReceiver.results.address, HEX);
130-
Serial.println(";");
131-
}
132-
133-
// All protocols have data
134-
Serial.print("unsigned int data = 0x");
135-
Serial.print(IrReceiver.results.value, HEX);
136-
Serial.println(";");
137-
Serial.println();
138-
}
139-
}
140-
141-
//+=============================================================================
142-
// Dump out the raw data as Pronto Hex.
143-
//
144-
void dumpPronto() {
145-
Serial.print("Pronto Hex: ");
146-
IrReceiver.dumpPronto(Serial);
147-
Serial.println();
148-
}
149-
15053
//+=============================================================================
15154
// The repeating section of the code
15255
//
15356
void loop() {
15457
if (IrReceiver.decode()) { // Grab an IR code
155-
dumpInfo(); // Output the results
156-
dumpRaw(); // Output the results in RAW format
157-
dumpCode(); // Output the results as source code
158-
dumpPronto();
159-
Serial.println(); // 2 blank lines between entries
58+
dumpInfo(); // Output the results
59+
IrReceiver.printIRResultRawFormatted(&Serial); // Output the results in RAW format
60+
Serial.println(); // blank line between entries
61+
IrReceiver.printIRResultAsCArray(&Serial); // Output the results as source code array
62+
IrReceiver.printIRResultAsCVariables(&Serial); // Output address and data as source code variables
63+
IrReceiver.printIRResultAsPronto(&Serial);
64+
Serial.println(); // 2 blank lines between entries
16065
Serial.println();
161-
IrReceiver.resume(); // Prepare for the next value
66+
IrReceiver.resume(); // Prepare for the next value
16267
}
16368
}

examples/IRsendDemo/ATtinySerialOut.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void useCliSeiForStrings(bool aUseCliSeiForWrite) {
100100
/*
101101
* Write String residing in RAM
102102
*/
103-
void writeString(const char * aStringPtr) {
103+
void writeString(const char *aStringPtr) {
104104
#ifndef USE_ALWAYS_CLI_SEI_GUARD_FOR_OUTPUT
105105
if (sUseCliSeiForWrite) {
106106
#endif
@@ -119,7 +119,7 @@ void writeString(const char * aStringPtr) {
119119
/*
120120
* Write string residing in program space (FLASH)
121121
*/
122-
void writeString_P(const char * aStringPtr) {
122+
void writeString_P(const char *aStringPtr) {
123123
uint8_t tChar = pgm_read_byte((const uint8_t * ) aStringPtr);
124124
// Comparing with 0xFF is safety net for wrong string pointer
125125
while (tChar != 0 && tChar != 0xFF) {
@@ -139,7 +139,7 @@ void writeString_P(const char * aStringPtr) {
139139
/*
140140
* Write string residing in program space (FLASH)
141141
*/
142-
void writeString(const __FlashStringHelper * aStringPtr) {
142+
void writeString(const __FlashStringHelper *aStringPtr) {
143143
PGM_P tPGMStringPtr = reinterpret_cast<PGM_P>(aStringPtr);
144144
uint8_t tChar = pgm_read_byte((const uint8_t * ) aStringPtr);
145145
// Comparing with 0xFF is safety net for wrong string pointer
@@ -160,7 +160,7 @@ void writeString(const __FlashStringHelper * aStringPtr) {
160160
/*
161161
* Write string residing in EEPROM space
162162
*/
163-
void writeString_E(const char * aStringPtr) {
163+
void writeString_E(const char *aStringPtr) {
164164
uint8_t tChar = eeprom_read_byte((const uint8_t *) aStringPtr);
165165
// Comparing with 0xFF is safety net for wrong string pointer
166166
while (tChar != 0 && tChar != 0xFF) {
@@ -177,19 +177,19 @@ void writeString_E(const char * aStringPtr) {
177177
}
178178
}
179179

180-
void writeStringWithoutCliSei(const char * aStringPtr) {
180+
void writeStringWithoutCliSei(const char *aStringPtr) {
181181
while (*aStringPtr != 0) {
182182
write1Start8Data1StopNoParity(*aStringPtr++);
183183
}
184184
}
185185

186-
void writeStringWithCliSei(const char * aStringPtr) {
186+
void writeStringWithCliSei(const char *aStringPtr) {
187187
while (*aStringPtr != 0) {
188188
write1Start8Data1StopNoParityWithCliSei(*aStringPtr++);
189189
}
190190
}
191191

192-
void writeStringSkipLeadingSpaces(const char * aStringPtr) {
192+
void writeStringSkipLeadingSpaces(const char *aStringPtr) {
193193
// skip leading spaces
194194
while (*aStringPtr == ' ' && *aStringPtr != 0) {
195195
aStringPtr++;
@@ -379,7 +379,7 @@ void TinySerialOut::print(const char* aStringPtr) {
379379
writeString(aStringPtr);
380380
}
381381

382-
void TinySerialOut::print(const __FlashStringHelper * aStringPtr) {
382+
void TinySerialOut::print(const __FlashStringHelper *aStringPtr) {
383383
writeString(aStringPtr);
384384
}
385385

@@ -440,7 +440,7 @@ void TinySerialOut::println(const char* aStringPtr) {
440440
println();
441441
}
442442

443-
void TinySerialOut::println(const __FlashStringHelper * aStringPtr) {
443+
void TinySerialOut::println(const __FlashStringHelper *aStringPtr) {
444444
print(aStringPtr);
445445
println();
446446
}

examples/IRsendDemo/ATtinySerialOut.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,13 @@ void write1Start8Data1StopNoParity(uint8_t aValue);
104104
void write1Start8Data1StopNoParityWithCliSei(uint8_t aValue);
105105
void writeValue(uint8_t aValue);
106106

107-
void writeString(const char * aStringPtr);
108-
void writeString(const __FlashStringHelper * aStringPtr);
109-
void writeString_P(const char * aStringPtr);
110-
void writeString_E(const char * aStringPtr);
111-
void writeStringWithCliSei(const char * aStringPtr);
112-
void writeStringWithoutCliSei(const char * aStringPtr);
113-
void writeStringSkipLeadingSpaces(const char * aStringPtr);
107+
void writeString(const char *aStringPtr);
108+
void writeString(const __FlashStringHelper *aStringPtr);
109+
void writeString_P(const char *aStringPtr);
110+
void writeString_E(const char *aStringPtr);
111+
void writeStringWithCliSei(const char *aStringPtr);
112+
void writeStringWithoutCliSei(const char *aStringPtr);
113+
void writeStringSkipLeadingSpaces(const char *aStringPtr);
114114

115115
void writeBinary(uint8_t aByte); // write direct without decoding
116116
void writeChar(uint8_t aChar); // Synonym for writeBinary
@@ -145,7 +145,7 @@ class TinySerialOut
145145
size_t write(uint8_t aByte);
146146
operator bool(); // To support "while (!Serial); // wait for serial port to connect. Needed for Leonardo only
147147

148-
void print(const __FlashStringHelper * aStringPtr);
148+
void print(const __FlashStringHelper *aStringPtr);
149149
void print(const char* aStringPtr);
150150
void print(char aChar);
151151
void print(uint8_t aByte, uint8_t aBase = 10);
@@ -156,7 +156,7 @@ class TinySerialOut
156156
void print(double aFloat, uint8_t aDigits = 2);
157157

158158
void println(const char* aStringPtr);
159-
void println(const __FlashStringHelper * aStringPtr);
159+
void println(const __FlashStringHelper *aStringPtr);
160160
void println(char aChar);
161161
void println(uint8_t aByte, uint8_t aBase = 10);
162162
void println(int16_t aInteger, uint8_t aBase = 10);

src/IRremote.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,19 @@ class IRrecv {
253253
void resume();
254254

255255
const char* getProtocolString();
256-
void printResultShort(Print * aSerial);
257-
256+
void printResultShort(Print *aSerial);
257+
void printIRResultRaw(Print *aSerial);
258+
void printIRResultRawFormatted(Print *aSerial);
259+
void printIRResultAsCArray(Print *aSerial);
260+
void printIRResultAsCVariables(Print *aSerial);
258261
/**
259262
* Print the result (second argument) as Pronto Hex on the Stream supplied as argument.
260263
* @param stream The Stream on which to write, often Serial
261264
* @param results the decode_results as delivered from irrecv.decode.
262265
* @param frequency Modulation frequency in Hz. Often 38000Hz.
263266
*/
264-
void dumpPronto(Stream& stream, unsigned int frequency = 38000U);
267+
void dumpPronto(Print *aSerial, unsigned int frequency = 38000U);
268+
void printIRResultAsPronto(Print *aSerial, unsigned int frequency = 38000U);
265269

266270
bool decodePulseDistanceData(uint8_t aNumberOfBits, uint8_t aStartOffset, unsigned int aBitMarkMicros,
267271
unsigned int aOneSpaceMicros, unsigned int aZeroSpaceMicros, bool aMSBfirst = true);

0 commit comments

Comments
 (0)