Skip to content

Commit 39eec4c

Browse files
committed
LG2 protocol
1 parent 0b16ba4 commit 39eec4c

File tree

15 files changed

+136
-70
lines changed

15 files changed

+136
-70
lines changed

README.md

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# IRremote Arduino Library
22
Available as Arduino library "IRremote"
33

4-
### [Version 3.3.1](https://github.com/Arduino-IRremote/Arduino-IRremote/archive/master.zip) - work in progress
4+
### [Version 3.4.0](https://github.com/Arduino-IRremote/Arduino-IRremote/archive/master.zip) - work in progress
55

66
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
77
[![Commits since latest](https://img.shields.io/github/commits-since/Arduino-IRremote/Arduino-IRremote/latest)](https://github.com/Arduino-IRremote/Arduino-IRremote/commits/master)
@@ -43,13 +43,11 @@ This is a quite old but maybe useful wiki for this library.
4343
- Ability to generate a non PWM signal to just simulate an active low receiver signal for direct connect to existent receiving devices without using IR.
4444
- Easy configuration of protocols required, directly in your [source code[(https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/SimpleReceiver/SimpleReceiver.ino#L18-L34). This reduces the memory footprint and increases decoding time.
4545

46-
# Converting your program to the 3.1 version
47-
This must be done also for all versions > 3.0.1 if `USE_NO_SEND_PWM` is defined.<br/>
48-
Starting with this version, **the generation of PWM is done by software**, thus saving the hardware timer and **enabling arbitrary output pins**.<br/>
49-
Therefore you must change all `IrSender.begin(true);` by `IrSender.begin(IR_SEND_PIN, ENABLE_LED_FEEDBACK);`.
50-
If you use a core that does not use the `-flto` flag for compile, you can activate the line `#define SUPPRESS_ERROR_MESSAGE_FOR_BEGIN` in IRRemote.h, if you get false error messages regarding begin() during compilation.
5146

5247
# Converting your 2.x program to the 3.x version
48+
Starting with the 3.1 version, **the generation of PWM is done by software**, thus saving the hardware timer and **enabling arbitrary output pins**.<br/>
49+
If you use an (old) Arduino core that does not use the `-flto` flag for compile, you can activate the line `#define SUPPRESS_ERROR_MESSAGE_FOR_BEGIN` in IRRemote.h, if you get false error messages regarding begin() during compilation.
50+
5351
- Now there is an **IRreceiver** and **IRsender** object like the well known Arduino **Serial** object.
5452
- Just remove the line `IRrecv IrReceiver(IR_RECEIVE_PIN);` and/or `IRsend IrSender;` in your program, and replace all occurrences of `IRrecv.` or `irrecv.` with `IrReceiver`.
5553
- Since the decoded values are now in `IrReceiver.decodedIRData` and not in `results` any more, remove the line `decode_results results` or similar.
@@ -59,8 +57,9 @@ If you use a core that does not use the `-flto` flag for compile, you can activa
5957
- Overflow, Repeat and other flags are now in [`IrReceiver.receivedIRData.flags`](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/IRremote.h#L126).
6058
- Seldom used: `results.rawbuf` and `results.rawlen` must be replaced by `IrReceiver.decodedIRData.rawDataPtr->rawbuf` and `IrReceiver.decodedIRData.rawDataPtr->rawlen`.
6159

62-
# Running your 2.x program with the 3.x library version
63-
If you program is like:
60+
# Do not convert your 2.x program and use the 3.x library version
61+
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, so in this cases you must revisit your code and adapt it to the 3.x library.<br/>
62+
If you program look like:
6463
```
6564
IRrecv irrecv(RECV_PIN);
6665
decode_results results;
@@ -80,17 +79,19 @@ void loop() {
8079
...
8180
}
8281
```
83-
it should run on the 3.1.1 version as before. The following decoders are available: Denon, JVC, LG, NEC, Panasonic, RC5, RC6, Samsung, Sony.
84-
The `results.value` is set by the decoders for **NEC, Panasonic, Sony, Samsung and JVC** as MSB first like in 2.x.<br/>
82+
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.
83+
The `results.value` is set by the decoders for **NEC, Panasonic, Sony, Samsung and JVC** as MSB first like in 2.x!<br/>
8584
- 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, which is not the standard for NEC and JVC. Use them to send your **old MSB-first 32 bit IR data codes**.
86-
In the new version you will send NEC commands not by 32 bit codes but by a (constant) 8 bit address and an 8 bit command.
87-
88-
# Convert old MSB first 32 bit IR data codes to new LSB first 32 bit IR data codes
89-
The new decoders for **NEC, Panasonic, Sony, Samsung and JVC** `IrReceiver.decodedIRData.decodedRawData` is now LSB-first, as the definition of these protocols suggests!
90-
To convert one into the other, you must reverse the byte positions and then reverse all bit positions of each byte or write it as one binary string and reverse/mirror it.<br/>
91-
Example:<br/>
92-
0xCB340102 byte reverse -> 02 01 34 CB bit reverse-> 40 80 2C D3.<br/>
93-
0xCB340102 is binary 11001011001101000000000100000010.<br/>
85+
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.
86+
87+
# How to convert old MSB first 32 bit IR data codes to new LSB first 32 bit IR data codes
88+
For the new decoders for **NEC, Panasonic, Sony, Samsung and JVC**, the result `IrReceiver.decodedIRData.decodedRawData` is now **LSB-first**, as the definition of these protocols suggests!<br/>
89+
To convert one into the other, you must reverse the byte/nibble positions and then reverse all bit positions of each byte/nibble or write it as one binary string and reverse/mirror it.<br/><br/>
90+
Example:
91+
- 0xCB340102 byte reverse -> 02 01 34 CB. Bit reverse of byte -> 40 80 2C D3.
92+
- 0xCB340102 nibble reverse -> 201043BC. Bit reverse of nibble -> 40802CD3.<br/>
93+
Nibble reverse map: | 1->8 | 2->4 | 3->C | 4->2 | 5->A | 6->6 | 7->E | 8->1 | 9->9 | A->5 | B->D | C->3 | D->B | E->7 | F->F |
94+
- 0xCB340102 is binary 11001011001101000000000100000010.<br/>
9495
0x40802CD3 is binary 01000000100000000010110011010011.<br/>
9596
If you read the first binary sequence backwards (right to left), you get the second sequence.
9697

@@ -165,7 +166,7 @@ MinimalReceiver can be tested online with [WOKWI](https://wokwi.com/arduino/proj
165166
Click on the receiver while simulation is running to specify individual IR codes.
166167

167168
### IRDispatcherDemo
168-
Framework for calling different functions for different IR codes.
169+
Framework for calling different functions of **your program** for different IR codes.
169170

170171
### IRrelay
171172
Control a relay (connected to an output pin) with your remote.
@@ -178,7 +179,7 @@ This example analyzes the signal delivered by your IR receiver module.
178179
Values can be used to determine the stability of the received signal as well as a hint for determining the protocol.<br/>
179180
It also computes the MARK_EXCESS_MICROS value, which is the extension of the mark (pulse) duration introduced by the IR receiver module.<br/>
180181
It can be tested online with [WOKWI](https://wokwi.com/arduino/projects/299033930562011656).
181-
Click on the receiver while simulation is running to specify individual IR codes.
182+
Click on the receiver while simulation is running to specify individual NEC IR codes.
182183

183184
# Compile options / macros for this library
184185
To customize the library to different requirements, there are some compile options / macros available.<br/>

changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22
The latest version may not be released!
3-
## 3.3.1
3+
## 3.4.0
4+
- Added LG2 protocol.
45

56
## 3.3.0
67
- Fix errors if LED_BUILTIN is not defined.

examples/ReceiveDemo/ReceiveDemo.ino

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
// to compensate for the signal forming of different IR receiver modules.
5858
#define MARK_EXCESS_MICROS 20 // 20 is recommended for the cheap VS1838 modules
5959

60-
//#define RECORD_GAP_MICROS 12000 // Activate it for some LG air conditioner protocols
60+
#define RECORD_GAP_MICROS 12000 // Activate it for some LG air conditioner protocols
6161

6262
/*
6363
* First define macros for input and output pin etc.
@@ -111,13 +111,14 @@ void setup() {
111111
#if FLASHEND >= 0x3FFF // For 16k flash or more, like ATtiny1604. Code does not fit in program space of ATtiny85 etc.
112112
Serial.print(F("Debug button pin is "));
113113
Serial.println(DEBUG_BUTTON_PIN);
114-
#endif
115114

116115
// infos for receive
117116
Serial.print(RECORD_GAP_MICROS);
118117
Serial.println(F(" us is the (minimum) gap, after which the start of a new IR packet is assumed"));
119118
Serial.print(MARK_EXCESS_MICROS);
120119
Serial.println(F(" us are subtracted from all marks and added to all spaces for decoding"));
120+
#endif
121+
121122
}
122123

123124
void loop() {

examples/SendLGAirConditionerDemo/SendLGAirConditionerDemo.ino

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
*/
3333
#include <Arduino.h>
3434

35+
#define USE_LG2_PROTOCOL // Try it if you do not have success with the default LG protocol
36+
3537
/*
3638
* Define macros for input and output pin etc.
3739
*/
@@ -59,13 +61,32 @@ uint8_t ACRequestedTemperature = 25; // temperature : 18 ~ 30
5961
const int AC_FAN_TOWER[3] = { 0, 4, 6 };
6062
const int AC_FAN_WALL[4] = { 0, 2, 4, 5 }; // 5 -> cycle
6163

64+
// from https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_LG.h
65+
union LGProtocol{
66+
uint32_t raw; ///< The state of the IR remote in IR code form.
67+
struct {
68+
uint32_t Sum :4;
69+
uint32_t Fan :3;
70+
uint32_t FanExt :1;
71+
uint32_t Temp :4;
72+
uint32_t Mode :3;
73+
uint32_t :3;
74+
uint32_t Power :2;
75+
uint32_t Signature :8; /*=0x88*/
76+
};
77+
};
78+
6279
void ACSendCode(uint16_t aCommand) {
6380
Serial.print(F("Send code="));
6481
Serial.print(aCommand, HEX);
6582
Serial.print(F(" | "));
6683
Serial.println(aCommand, BIN);
6784
Serial.flush();
68-
IrSender.sendLG((uint8_t) 0x88, aCommand, 0);
85+
#if defined(USE_LG2_PROTOCOL)
86+
IrSender.sendLG((uint8_t) 0x88, aCommand, 0, true);
87+
#else
88+
IrSender.sendLG((uint8_t) 0x88, aCommand, 0, false);
89+
#endif
6990
}
7091

7192
void sendCommand(uint8_t aTemperature, uint8_t aFanIntensity) {
@@ -81,7 +102,7 @@ void sendCommand(uint8_t aTemperature, uint8_t aFanIntensity) {
81102
// heating
82103
tCommand.UByte.HighByte = 0x4; // maybe cooling is 0x08????
83104
}
84-
tCommand.UByte.LowByte = ((aTemperature - 15) << 4); // 18 -> 3, 30 -> F
105+
tCommand.UByte.LowByte = ((aTemperature - 15) << 4); // 16 -> 0, 18 -> 3, 30 -> F
85106

86107
if (ACIsWallType) {
87108
tCommand.UByte.LowByte |= AC_FAN_WALL[aFanIntensity];
@@ -115,7 +136,7 @@ void sendAirSwing(bool aSwing) {
115136

116137
void SendPowerDown() {
117138
Serial.println(F("Send power down"));
118-
IrSender.sendLGRaw(0x88C0051);
139+
ACSendCode(0xC005);
119140
ACPowerIsOn = false;
120141
}
121142

examples/UnitTest/UnitTest.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@
5252
#define DECODE_RC5
5353
#define DECODE_RC6
5454
#define DECODE_PANASONIC // the same as DECODE_KASEIKYO
55-
#define DECODE_LG
5655

5756
#define DECODE_DISTANCE // universal decoder for pulse width or pulse distance protocols
5857
#define DECODE_HASH // special decoder for all protocols
5958
#endif
6059

6160
#if FLASHEND >= 0x7FFF // For 32k flash or more, like ATmega328
6261
#define DECODE_SAMSUNG
62+
#define DECODE_LG
6363

6464
#define DECODE_BOSEWAVE
6565
#define DECODE_LEGO_PF

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"type": "git",
88
"url": "https://github.com/z3t0/Arduino-IRremote.git"
99
},
10-
"version": "3.3.0",
10+
"version": "3.4.0",
1111
"frameworks": "arduino",
1212
"platforms": ["atmelavr", "atmelmegaavr", "atmelsam", "espressif8266", "espressif32", "ststm32"],
1313
"authors" :

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name=IRremote
2-
version=3.3.0
2+
version=3.4.0
33
author=shirriff, z3t0 <zetoslab@gmail.com>, ArminJo
44
maintainer=Armin Joachimsmeyer <armin.arduino@gmail.com>
55
sentence=Send and receive infrared signals with multiple protocols
6-
paragraph=Currently included protocols: Denon / Sharp, JVC, LG, NEC / Onkyo / Apple, Panasonic / Kaseikyo, RC5, RC6, Samsung, Sony, (Pronto), BoseWave, Lego, Whynter, MagiQuest.<br/><br/><b>New: </b><a href="https://github.com/Arduino-IRremote/Arduino-IRremote#converting-your-program-to-the-31-version">3.x upgrade instructions</a><br/>Added universal decoder for pulse width or pulse distance protocols.<br/>For all 3.x: Generation of PWM is now done by software by default, thus saving the hardware timer and enabling abitrary output pins. Removed decode_results results. Renamed most irparams_struct values. The macros FEEDBACK_LED, SYSCLOCK, SENDPIN_ON and SENDPIN_OFF are not longer used / evaluated. Major refactoring of CPU dependent and feedback LED code. Support for more CPU's.<br/>
6+
paragraph=Currently included protocols: Denon / Sharp, JVC, LG, NEC / Onkyo / Apple, Panasonic / Kaseikyo, RC5, RC6, Samsung, Sony, (Pronto), BoseWave, Lego, Whynter, MagiQuest.<br/><br/><b>New: </b><a href="https://github.com/Arduino-IRremote/Arduino-IRremote#converting-your-program-to-the-31-version">3.x upgrade instructions</a><br/>Added LG2 protocol.<br/>For all 3.x: Generation of PWM is now done by software by default, thus saving the hardware timer and enabling abitrary output pins. Removed decode_results results. Renamed most irparams_struct values. The macros FEEDBACK_LED, SYSCLOCK, SENDPIN_ON and SENDPIN_OFF are not longer used / evaluated. Major refactoring of CPU dependent and feedback LED code. Support for more CPU's.<br/>
77
category=Communication
88
url=https://github.com/Arduino-IRremote/Arduino-IRremote
99
architectures=avr,megaavr,samd,esp8266,esp32,stm32,STM32F1,mbed,mbed_nano

pictures/LGRemote.jpg

336 KB
Loading

pictures/LGRemote1.jpg

12 KB
Loading

src/IRProtocol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ typedef enum {
4444
DISH,
4545
JVC,
4646
LG,
47+
LG2,
4748
NEC,
4849
PANASONIC,
4950
KASEIKYO,

0 commit comments

Comments
 (0)