8000 adding SEND_LG by chaeplin · Pull Request #203 · Arduino-IRremote/Arduino-IRremote · GitHub
[go: up one dir, main page]

Skip to content

adding SEND_LG #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions IRremote.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#define SEND_AIWA_RC_T501 1

#define DECODE_LG 1
#define SEND_LG 0 // NOT WRITTEN
#define SEND_LG 1

#define DECODE_SANYO 1
#define SEND_SANYO 0 // NOT WRITTEN
Expand Down Expand Up @@ -300,7 +300,7 @@ class IRsend
# endif
//......................................................................
# if SEND_LG
void sendLG ( ) ; // NOT WRITTEN
void sendLG (unsigned long data, int nbits) ;
# endif
//......................................................................
# if SEND_SANYO
Expand Down
249 changes: 249 additions & 0 deletions examples/LGACSendDemo/LGACSendDemo.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
#include <IRremote.h>
#include <Wire.h>


IRsend irsend;
// not used
int RECV_PIN = 11;
IRrecv irrecv (RECV_PIN);

const int AC_TYPE = 0;
// 0 : TOWER
// 1 : WALL

int AC_POWER_ON = 0;
// 0 : off
// 1 : on

int AC_AIR_ACLEAN = 0;
// 0 : off
// 1 : on --> power on

int AC_TEMPERATURE = 27;
// temperature : 18 ~ 30

int AC_FLOW = 1;
// 0 : low
// 1 : mid
// 2 : high
// if AC_TYPE =1, 3 : change

const int AC_FLOW_TOWER[3] = {0, 4, 6};
const int AC_FLOW_WALL[4] = {0, 2, 4, 5};

unsigned long AC_CODE_TO_SEND;

int r = LOW;
int o_r = LOW;

byte a, b;

void ac_send_code(unsigned long code)
{
Serial.print("code to send : ");
Serial.print(code, BIN);
Serial.print(" : ");
Serial.println(code, HEX);

irsend.sendLG(code, 28);
}

void ac_activate(int temperature, int air_flow)
{

int AC_MSBITS1 = 8;
int AC_MSBITS2 = 8;
int AC_MSBITS3 = 0;
int AC_MSBITS4 = 0;
int AC_MSBITS5 = temperature - 15;
int AC_MSBITS6 ;

if ( AC_TYPE == 0) {
AC_MSBITS6 = AC_FLOW_TOWER[air_flow];
} else {
AC_MSBITS6 = AC_FLOW_WALL[air_flow];
}

int AC_MSBITS7 = (AC_MSBITS3 + AC_MSBITS4 + AC_MSBITS5 + AC_MSBITS6) & B00001111;

AC_CODE_TO_SEND = AC_MSBITS1 << 4 ;
AC_CODE_TO_SEND = (AC_CODE_TO_SEND + AC_MSBITS2) << 4;
AC_CODE_TO_SEND = (AC_CODE_TO_SEND + AC_MSBITS3) << 4;
AC_CODE_TO_SEND = (AC_CODE_TO_SEND + AC_MSBITS4) << 4;
AC_CODE_TO_SEND = (AC_CODE_TO_SEND + AC_MSBITS5) << 4;
AC_CODE_TO_SEND = (AC_CODE_TO_SEND + AC_MSBITS6) << 4;
AC_CODE_TO_SEND = (AC_CODE_TO_SEND + AC_MSBITS7);

ac_send_code(AC_CODE_TO_SEND);

AC_POWER_ON = 1;
AC_TEMPERATURE = temperature;
AC_FLOW = air_flow;
}

void ac_change_air_swing(int air_swing)
{
if ( AC_TYPE == 0) {
if ( air_swing == 1) {
AC_CODE_TO_SEND = 0x881316B;
} else {
AC_CODE_TO_SEND = 0x881317C;
}
} else {
if ( air_swing == 1) {
AC_CODE_TO_SEND = 0x8813149;
} else {
AC_CODE_TO_SEND = 0x881315A;
}
}

ac_send_code(AC_CODE_TO_SEND);
}

void ac_power_down()
{
AC_CODE_TO_SEND = 0x88C0051;

ac_send_code(AC_CODE_TO_SEND);

AC_POWER_ON = 0;
}

void ac_air_clean(int air_clean)
{
if ( air_clean == 1) {
AC_CODE_TO_SEND = 0x88C000C;
} else {
AC_CODE_TO_SEND = 0x88C0084;
}

ac_send_code(AC_CODE_TO_SEND);

AC_AIR_ACLEAN = air_clean;
}

void setup()
{
Serial.begin(38400);
delay(1000);
Wire.begin(7);
Wire.onReceive(receiveEvent);

Serial.println(" - - - T E S T - - - ");

/* test
ac_activate(25, 1);
delay(5000);
ac_activate(27, 2);
delay(5000);

*/
}

void loop()
{


ac_activate(25, 1);
delay(5000);
ac_activate(27, 0);
delay(5000);


if ( r != o_r) {

/*
# a : mode or temp b : air_flow, temp, swing, clean
# 18 ~ 30 : temp 0 ~ 2 : flow // on
# 0 : off 0
# 1 : on 0
# 2 : air_swing 0 or 1
# 3 : air_clean 0 or 1
# 4 : air_flow 0 ~ 2 : flow
# 5 : temp 18 ~ 30
# + : temp + 1
# - : temp - 1
# m : change cooling to air clean, air clean to cooling
*/
Serial.print("a : ");
Serial.print(a);
Serial.print(" b : ");
Serial.println(b);

switch (a) {
case 0: // off
ac_power_down();
break;
case 1: // on
ac_activate(AC_TEMPERATURE, AC_FLOW);
break;
case 2:
if ( b == 0 | b == 1 ) {
ac_change_air_swing(b);
}
break;
case 3: // 1 : clean on, power on
if ( b == 0 | b == 1 ) {
ac_air_clean(b);
}
break;
case 4:
if ( 0 <= b && b <= 2 ) {
ac_activate(AC_TEMPERATURE, b);
}
break;
case 5:
if (18 <= b && b <= 30 ) {
ac_activate(b, AC_FLOW);
}
break;
case '+':
if ( 18 <= AC_TEMPERATURE && AC_TEMPERATURE <= 29 ) {
ac_activate((AC_TEMPERATURE + 1), AC_FLOW);
}
break;
case '-':
if ( 19 <= AC_TEMPERATURE && AC_TEMPERATURE <= 30 ) {
ac_activate((AC_TEMPERATURE - 1), AC_FLOW);
}
break;
case 'm':
/*
if ac is on, 1) turn off, 2) turn on ac_air_clean(1)
if ac is off, 1) turn on, 2) turn off ac_air_clean(0)
*/
if ( AC_POWER_ON == 1 ) {
ac_power_down();
delay(100);
ac_air_clean(1);
} else {
if ( AC_AIR_ACLEAN == 1) {
ac_air_clean(0);
delay(100);
}
ac_activate(AC_TEMPERATURE, AC_FLOW);
}
break;
default:
if ( 18 <= a && a <= 30 ) {
if ( 0 <= b && b <= 2 ) {
ac_activate(a, b);
}
}
}

o_r = r ;
}
delay(100);
}



void receiveEvent(int howMany)
{
a = Wire.read();
b = Wire.read();
r = !r ;
}


35 changes: 35 additions & 0 deletions examples/LGACSendDemo/LGACSendDemo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
1) Sample raw code : https://gist.github.com/chaeplin/ab2a7ad1533c41260f0d
2) send raw code : https://gist.github.com/chaeplin/7c800d3166463bb51be4


=== *** ===
- (1) : fixed
- (2) : fixed
- (3) : special(power, swing, air clean)
- (4) : change air flow, temperature
- (5) : temperature ( 15 + (5) = )
- (6) : air flow
- (7) : crc ( 3 + 4 + 5 + 6 ) & B00001111

=== *** ===

| status | (1)| (2)| (3)| (4)| (5)| (6)| (7)
|----------------|----|----|----|----|----|----|----
| on / 25 / mid |1000|1000|0000|0000|1010|0010|1100
| on / 26 / mid |1000|1000|0000|0000|1011|0010|1101
| on / 27 / mid |1000|1000|0000|0000|1100|0010|1110
| on / 28 / mid |1000|1000|0000|0000|1101|0010|1111
| on / 25 / high |1000|1000|0000|0000|1010|0100|1110
| on / 26 / high |1000|1000|0000|0000|1011|0100|1111
| on / 27 / high |1000|1000|0000|0000|1100|0100|0000
| on / 28 / high |1000|1000|0000|0000|1101|0100|0001
| 1 up |1000|1000|0000|1000|1101|0100|1001
| Cool power |1000|1000|0001|0000|0000|1100|1101
| energy saving |1000|1000|0001|0000|0000|0100|0101
| power |1000|1000|0001|0000|0000|1000|1001
| flow/up/down |1000|1000|0001|0011|0001|0100|1001
| up/down off |1000|1000|0001|0011|0001|0101|1010
| flow/left/right|1000|1000|0001|0011|0001|0110|1011
| left/right off |1000|1000|0001|0011|0001|0111|1100
| Air clean |1000|1000|1100|0000|0000|0000|1100
| off |1000|1000|1100|0000|0000|0101|0001
26 changes: 26 additions & 0 deletions ir_LG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,29 @@ bool IRrecv::decodeLG (decode_results *results)
}
#endif

//+=============================================================================
#if SEND_LG
void IRsend::sendLG (unsigned long data, int nbits)
{
// Set IR carrier frequency
enableIROut(38);

// Header
mark(LG_HDR_MARK);
space(LG_HDR_SPACE);
mark(LG_BIT_MARK);

// Data
for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) {
if (data & mask) {
space(LG_ONE_SPACE);
mark(LG_BIT_MARK);
} else {
space(LG_ZERO_SPACE);
mark(LG_BIT_MARK);
}
}
space(0); // Always end with the LED off
}
#endif

0