-
Notifications
You must be signed in to change notification settings - Fork 0
/
IotLgAC.cpp
138 lines (120 loc) · 2.52 KB
/
IotLgAC.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <IoTLgAC.h>
IoTLgAC::IoTLgAC(int acType) :
irsend(4)
{
this->acType = acType;
}
void IoTLgAC::setup() {
irsend.begin();
}
void IoTLgAC::loop() {
}
void IoTLgAC::sendCode(unsigned long code)
{
Serial.print("send code "); Serial.println(code,HEX);
irsend.sendLG(code, 28);
}
void IoTLgAC::activate()
{
this->acPower=1;
int acMsBits1 = 8;
int acMsBits2 = 8;
int acMsBits3 = 0;
int acMsBits4 = 0;
if ( this->acMode == LG_AC_MODE_HEADING )
acMsBits4 = 4;
int acMsBits5 = this->acTemperature - 15;
int acMsBits6;
if ( this->acType == LG_AC_TYPE_TOWER) {
acMsBits6 = AC_FLOW_TOWER[this->acFlow];
} else {
acMsBits6 = AC_FLOW_WALL[this->acFlow];
}
int acMsBits7 = (acMsBits3 + acMsBits4 + acMsBits5 + acMsBits6) & B00001111;
int code2Send = acMsBits1 << 4 ;
code2Send = (code2Send + acMsBits2) << 4;
code2Send = (code2Send + acMsBits3) << 4;
code2Send = (code2Send + acMsBits4) << 4;
code2Send = (code2Send + acMsBits5) << 4;
code2Send = (code2Send + acMsBits6) << 4;
code2Send = (code2Send + acMsBits7);
sendCode(code2Send);
}
void IoTLgAC::powerOn()
{
activate();
}
void IoTLgAC::powerOff()
{
int code2send = 0x88C0051;
sendCode(code2send);
this->acPower = 0;
}
void IoTLgAC::setAirSwing(int airSwing)
{
int code2send = 0;
if ( this->acType == LG_AC_TYPE_TOWER) {
if ( airSwing == LG_AC_FAN_SWING_ON) {
code2send = 0x881316B;
} else {
code2send = 0x881317C;
}
} else {
if ( airSwing == LG_AC_FAN_SWING_ON) {
code2send = 0x8813149;
} else {
code2send = 0x881315A;
}
}
sendCode(code2send);
}
void IoTLgAC::setAirClean(int airClean)
{
int code2send = 0;
if ( airClean == LG_AC_AIR_CLEAN_ON) {
code2send = 0x88C000C;
} else {
code2send = 0x88C0084;
}
sendCode(code2send);
}
void IoTLgAC::setTemperature(int temperature)
{
this->acTemperature = temperature;
activate();
}
void IoTLgAC::setAirFlow(int airFlow)
{
this->acFlow = airFlow;
activate();
}
void IoTLgAC::setParameter(const char* parameter, const char* value)
{
if (strcmp("temp",parameter) == 0)
{
int _value = atoi(value);
setTemperature(_value);
}
if (strcmp("airClean",parameter) == 0)
{
int _value = atoi(value);
setAirClean(_value);
}
if (strcmp("airSwing",parameter) == 0)
{
int _value = atoi(value);
setAirSwing(_value);
}
if (strcmp("airFlow",parameter) == 0)
{
int _value = atoi(value);
setAirFlow(_value);
}
if (strcmp("power",parameter) == 0)
{
if (strcmp(value,"ON") == 0)
powerOn();
if (strcmp(value,"OFF") == 0)
powerOff();
}
}