Skip to content

Commit 82a3b7d

Browse files
committed
Documentation
1 parent a44f93e commit 82a3b7d

File tree

4 files changed

+93
-41
lines changed

4 files changed

+93
-41
lines changed

README.md

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Click on the LibraryManager badge above to see the [instructions](https://www.ar
2020
Denon / Sharp, JVC, LG, NEC / Onkyo / Apple, Panasonic / Kaseikyo, RC5, RC6, Samsung, Sony, (Pronto), BoseWave, Lego, Whynter and optional MagiQuest.<br/>
2121
Protocols can be switched off and on by defining macros before the line `#include <IRremote.hpp>` like [here](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/SimpleReceiver/SimpleReceiver.ino#L14):
2222

23-
```
23+
```c++
2424
#define DECODE_NEC
2525
//#define DECODE_DENON
2626
#include <IRremote.hpp>
@@ -58,11 +58,12 @@ If you use an (old) Arduino core that does not use the `-flto` flag for compile,
5858
- Overflow, Repeat and other flags are now in [`IrReceiver.receivedIRData.flags`](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/IRremote.h#L126).
5959
- Seldom used: `results.rawbuf` and `results.rawlen` must be replaced by `IrReceiver.decodedIRData.rawDataPtr->rawbuf` and `IrReceiver.decodedIRData.rawDataPtr->rawlen`.
6060

61-
# Do not want to convert your 2.x program and use the 3.x library version?
62-
The 3.x versions try to be backwards compatible, so you can easily run your old examples. But some functions like e.g. `sendNEC()` -see below- could not made backwards compatible,
63-
so in this cases you must revisit your code and adapt it to the 3.x library.<br/>
64-
If you program look like:
65-
```
61+
## Example
62+
### 2.x program:
63+
64+
```c++
65+
#include <IRremote.h>
66+
6667
IRrecv irrecv(RECV_PIN);
6768
decode_results results;
6869

@@ -81,9 +82,38 @@ void loop() {
8182
...
8283
}
8384
```
85+
86+
### 3.x program:
87+
88+
```c++
89+
#include <IRremote.hpp>
90+
91+
void setup()
92+
{
93+
...
94+
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); // Start the receiver
95+
}
96+
97+
void loop() {
98+
if (IrReceiver.decode()) {
99+
Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX);
100+
IrReceiver.printIRResultShort(&Serial); // optional use new print version
101+
...
102+
IrReceiver.resume(); // Enable receiving of the next value
103+
}
104+
...
105+
}
106+
```
107+
108+
# Do not want to convert your 2.x program and use the 3.x library version?
109+
The 3.x versions try to be backwards compatible, so you can easily run your old examples. But some functions like e.g. `sendNEC()` -see below- could not made backwards compatible,
110+
so in this cases you must revisit your code and adapt it to the 3.x library.<br/>
111+
If you program look like:
112+
84113
it runs on the 3.x version as before. But only the following decoders are available then: Denon, JVC, LG, NEC, Panasonic, RC5, RC6, Samsung, Sony.
85114
The `results.value` is set by the decoders for **NEC, Panasonic, Sony, Samsung and JVC** as MSB first like in 2.x!<br/>
86-
- The old functions `sendNEC()` and `sendJVC()` are deprecated and renamed to `sendNECMSB()` and `sendJVCMSB()` to make it clearer that they send data with MSB first,
115+
116+
The old functions `sendNEC()` and `sendJVC()` are deprecated and renamed to `sendNECMSB()` and `sendJVCMSB()` to make it clearer that they send data with MSB first,
87117
which is not the standard for NEC and JVC. Use them to send your **old MSB-first 32 bit IR data codes**.
88118
In the new version you will send NEC (and other) commands not by 32 bit codes but by a (constant) 8 bit address and an 8 bit command.
89119

@@ -98,6 +128,27 @@ Example:
98128
0x40802CD3 is binary 01000000100000000010110011010011.<br/>
99129
If you read the first binary sequence backwards (right to left), you get the second sequence.
100130

131+
# Receiving IR codes
132+
Check for **available data** can be done by `if (IrReceiver.decode()) {`. This also decodes the received data.
133+
After successful decoding, the IR data is contained in the IRData structure, available as `IrReceiver.decodedIRData`.
134+
135+
```c++
136+
struct IRData {
137+
decode_type_t protocol; // UNKNOWN, NEC, SONY, RC5, ...
138+
uint16_t address; // Decoded address
139+
uint16_t command; // Decoded command
140+
uint16_t extra; // Used by MagiQuest and for Kaseikyo unknown vendor ID. Ticks used for decoding Distance protocol.
141+
uint16_t numberOfBits; // Number of bits received for data (address + command + parity) - to determine protocol length if different length are possible.
142+
uint8_t flags; // See IRDATA_FLAGS_* definitions above
143+
uint32_t decodedRawData; // Up to 32 bit decoded raw data, used for sendRaw functions.
144+
irparams_struct *rawDataPtr; // Pointer of the raw timing data to be decoded. Mainly the data buffer filled by receiving ISR.
145+
};
146+
```
147+
To access e.g. the **RAW data**, use `uint32_t myRawdata= IrReceiver.decodedIRData.decodedRawData;`.<br/>
148+
The content of the `IrReceiver.decodedIRData.flags` is described [here](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/IRremoteInt.h#L204-L212).<br/>
149+
To **print all fields**, use `IrReceiver.printIRResultShort(&Serial);`.<br/>
150+
To print the **raw timing data** received, use `IrReceiver.printIRResultRawFormatted(&Serial, true);`.
151+
101152
# Sending IR codes
102153
Please do not use the old send*Raw() functions for sending like e.g. `IrSender.sendNECRaw(0xE61957A8,2)`,
103154
even if this functions are used in a lot of **(old)** tutorials. They are only kept for backward compatibility and unsupported and error prone.<br/>
@@ -257,6 +308,8 @@ If you are using Sloeber as your IDE, you can easily define global symbols with
257308
![Sloeber settings](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/pictures/SloeberDefineSymbols.png)
258309
259310
# Supported Boards
311+
**Issues and discussions with the content "Is it possible to use this library with the ATTinyXYZ? / board XYZ" without any reasonable explanations will be immediately closed without further notice.**<br/>
312+
<br/>
260313
ATtiny and Digispark boards are only tested with the recommended [ATTinyCore](https://github.com/SpenceKonde/ATTinyCore) using `New Style` pin mapping for the pro board.
261314
- Arduino Uno / Mega / Leonardo / Duemilanove / Diecimila / LilyPad / Mini / Fio / Nano etc.
262315
- Teensy 1.0 / 1.0++ / 2.0 / 2++ / 3.0 / 3.1 / Teensy-LC - but [limited support](https://forum.pjrc.com/threads/65912-Enable-Continuous-Integration-with-arduino-cli-for-3-party-libraries); Credits: PaulStoffregen (Teensy Team)
@@ -293,7 +346,7 @@ The **send PWM signal** is by default generated by software. **Therefore every p
293346
If you use a library which requires the same timer as IRremote, you have a problem, since **the timer resource cannot be shared simultaneously** by both libraries. The best approach is to change the timer used for IRremote, which can be accomplished by modifying the timer selection in [private/IRTimer.hpp](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/private/IRTimer.hpp).<br/>
294347
For the AVR platform the code to modify looks like:
295348
296-
```
349+
```c++
297350
// Arduino Mega
298351
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
299352
# if !defined(IR_USE_AVR_TIMER1) && !defined(IR_USE_AVR_TIMER2) && !defined(IR_USE_AVR_TIMER3) && !defined(IR_USE_AVR_TIMER4) && !defined(IR_USE_AVR_TIMER5)

src/IRremoteInt.h

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -175,29 +175,6 @@ struct irparams_struct {
175175
/****************************************************
176176
* RECEIVING
177177
****************************************************/
178-
/*
179-
* Activating this saves 60 bytes program space and 14 bytes RAM
180-
*/
181-
//#define NO_LEGACY_COMPATIBILITY
182-
#if !defined(NO_LEGACY_COMPATIBILITY)
183-
/**
184-
* Results returned from old decoders !!!deprecated!!!
185-
*/
186-
struct decode_results {
187-
decode_type_t decode_type; // deprecated, moved to decodedIRData.protocol ///< UNKNOWN, NEC, SONY, RC5, ...
188-
uint16_t address; ///< Used by Panasonic & Sharp [16-bits]
189-
uint32_t value; // deprecated, moved to decodedIRData.decodedRawData ///< Decoded value / command [max 32-bits]
190-
uint8_t bits; // deprecated, moved to decodedIRData.numberOfBits ///< Number of bits in decoded value
191-
uint16_t magnitude; // deprecated, moved to decodedIRData.extra ///< Used by MagiQuest [16-bits]
192-
bool isRepeat; // deprecated, moved to decodedIRData.flags ///< True if repeat of value is detected
193-
194-
// next 3 values are copies of irparams values - see IRremoteint.h
195-
uint16_t *rawbuf; // deprecated, moved to decodedIRData.rawDataPtr->rawbuf ///< Raw intervals in 50uS ticks
196-
uint16_t rawlen; // deprecated, moved to decodedIRData.rawDataPtr->rawlen ///< Number of records in rawbuf
197-
bool overflow; // deprecated, moved to decodedIRData.flags ///< true if IR raw code too long
198-
};
199-
#endif
200-
201178
/*
202179
* Definitions for member IRData.flags
203180
*/
@@ -216,13 +193,13 @@ struct decode_results {
216193
* Filled by decoders and read by print functions or user application.
217194
*/
218195
struct IRData {
219-
decode_type_t protocol; ///< UNKNOWN, NEC, SONY, RC5, ...
220-
uint16_t address; ///< Decoded address
221-
uint16_t command; ///< Decoded command
222-
uint16_t extra; ///< Used by MagiQuest and for Kaseikyo unknown vendor ID. Ticks used for decoding Distance protocol.
196+
decode_type_t protocol; ///< UNKNOWN, NEC, SONY, RC5, ...
197+
uint16_t address; ///< Decoded address
198+
uint16_t command; ///< Decoded command
199+
uint16_t extra; ///< Used by MagiQuest and for Kaseikyo unknown vendor ID. Ticks used for decoding Distance protocol.
223200
uint16_t numberOfBits; ///< Number of bits received for data (address + command + parity) - to determine protocol length if different length are possible.
224-
uint8_t flags; ///< See IRDATA_FLAGS_* definitions above
225-
uint32_t decodedRawData; ///< Up to 32 bit decoded raw data, used for sendRaw functions.
201+
uint8_t flags; ///< See IRDATA_FLAGS_* definitions above
202+
uint32_t decodedRawData; ///< Up to 32 bit decoded raw data, used for sendRaw functions.
226203
irparams_struct *rawDataPtr; ///< Pointer of the raw timing data to be decoded. Mainly the data buffer filled by receiving ISR.
227204
};
228205

@@ -231,6 +208,29 @@ struct IRData {
231208
*/
232209
#define USE_DEFAULT_FEEDBACK_LED_PIN 0
233210

211+
/*
212+
* Activating this saves 60 bytes program space and 14 bytes RAM
213+
*/
214+
//#define NO_LEGACY_COMPATIBILITY
215+
#if !defined(NO_LEGACY_COMPATIBILITY)
216+
/**
217+
* Results returned from old decoders !!!deprecated!!!
218+
*/
219+
struct decode_results {
220+
decode_type_t decode_type; // deprecated, moved to decodedIRData.protocol ///< UNKNOWN, NEC, SONY, RC5, ...
221+
uint16_t address; ///< Used by Panasonic & Sharp [16-bits]
222+
uint32_t value; // deprecated, moved to decodedIRData.decodedRawData ///< Decoded value / command [max 32-bits]
223+
uint8_t bits; // deprecated, moved to decodedIRData.numberOfBits ///< Number of bits in decoded value
224+
uint16_t magnitude; // deprecated, moved to decodedIRData.extra ///< Used by MagiQuest [16-bits]
225+
bool isRepeat; // deprecated, moved to decodedIRData.flags ///< True if repeat of value is detected
226+
227+
// next 3 values are copies of irparams values - see IRremoteint.h
228+
uint16_t *rawbuf; // deprecated, moved to decodedIRData.rawDataPtr->rawbuf ///< Raw intervals in 50uS ticks
229+
uint16_t rawlen; // deprecated, moved to decodedIRData.rawDataPtr->rawlen ///< Number of records in rawbuf
230+
bool overflow; // deprecated, moved to decodedIRData.flags ///< true if IR raw code too long
231+
};
232+
#endif
233+
234234
/**
235235
* Main class for receiving IR signals
236236
*/
@@ -466,7 +466,6 @@ class IRsend {
466466
// Not guarded for backward compatibility
467467
void begin(uint8_t aSendPin, bool aEnableLEDFeedback = true, uint8_t aFeedbackLEDPin = USE_DEFAULT_FEEDBACK_LED_PIN);
468468

469-
470469
size_t write(IRData *aIRSendData, uint_fast8_t aNumberOfRepeats = NO_REPEATS);
471470

472471
void enableIROut(uint8_t aFrequencyKHz);

src/LongUnion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ union WordUnion {
4444
int8_t Bytes[2];
4545
uint16_t UWord;
4646
int16_t Word;
47-
uint8_t * BytePointer;
47+
uint8_t *BytePointer;
4848
};
4949

5050
/**

src/ir_DistanceProtocol.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ bool IRrecv::decodeDistance() {
209209
// tNumberOfBits++;
210210
// }
211211
// decode without leading start bit. Currently only seen for sony protocol
212-
for (uint8_t i = 0; i <= tNumberOfAdditionalLong; ++i) {
212+
for (uint_fast8_t i = 0; i <= tNumberOfAdditionalLong; ++i) {
213213
uint8_t tNumberOfBitsForOneDecode = tNumberOfBits;
214214
if (tNumberOfBitsForOneDecode > 32) {
215215
tNumberOfBitsForOneDecode = 32;
@@ -260,7 +260,7 @@ bool IRrecv::decodeDistance() {
260260
/*
261261
* Decode in 32 bit chunks
262262
*/
263-
for (uint8_t i = 0; i <= tNumberOfAdditionalLong; ++i) {
263+
for (uint_fast8_t i = 0; i <= tNumberOfAdditionalLong; ++i) {
264264
uint8_t tNumberOfBitsForOneDecode = tNumberOfBits;
265265
if (tNumberOfBitsForOneDecode > 32) {
266266
tNumberOfBitsForOneDecode = 32;

0 commit comments

Comments
 (0)