forked from crankyoldgit/IRremoteESP8266
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IRDaikinESP.cpp
153 lines (129 loc) · 2.49 KB
/
IRDaikinESP.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
An Arduino sketch to emulate IR Daikin ARC433** remote control unit
Read more on http://harizanov.com/2012/02/control-daikin-air-conditioner-over-the-internet/
*/
#include <IRDaikinESP.h>
IRDaikinESP::IRDaikinESP(int pin) : _irsend(pin)
{
}
void IRDaikinESP::begin()
{
_irsend.begin();
}
void IRDaikinESP::send()
{
_irsend.sendDaikin(daikin);
}
uint8_t IRDaikinESP::checksum()
{
uint8_t sum = 0;
uint8_t i;
for(i = 0; i <= 6; i++){
sum += daikin[i];
}
daikin[7] = sum &0xFF;
sum=0;
for(i = 8; i <= 25; i++){
sum += daikin[i];
}
daikin[26] = sum &0xFF;
}
void IRDaikinESP::on()
{
//state = ON;
daikin[13] |= 0x01;
checksum();
}
void IRDaikinESP::off()
{
//state = OFF;
daikin[13] &= 0xFE;
checksum();
}
uint8_t IRDaikinESP::getPower()
{
return (daikin[13])&0x01;
}
// DAIKIN_SILENT or DAIKIN_POWERFUL
void IRDaikinESP::setAux(uint8_t aux)
{
daikin[21] = aux;
checksum();
}
uint8_t IRDaikinESP::getAux(){
return daikin[21];
}
// Set the temp in deg C
void IRDaikinESP::setTemp(uint8_t temp)
{
if (temp < 18)
temp = 18;
else if (temp > 32)
temp = 32;
daikin[14] = (temp)*2;
checksum();
}
uint8_t IRDaikinESP::getTemp()
{
return (daikin[14])/2;
}
// Set the speed of the fan, 0-5, 0 is auto, 1-5 is the speed
void IRDaikinESP::setFan(uint8_t fan)
{
// Set the fan speed bits, leave low 4 bits alone
uint8_t fanset;
daikin[16] = daikin[16] & 0x0F;
if (fan >= 1 && fan <= 5)
fanset = 0x20 + (0x10 * fan);
else
fanset = 0xA0;
daikin[16] = daikin[16] | fanset;
checksum();
}
uint8_t IRDaikinESP::getFan()
{
uint8_t fan = daikin[16] >> 4;
fan = fan - 2;
if (fan > 5)
fan = 0;
return fan;
}
uint8_t IRDaikinESP::getMode()
{/*
DAIKIN_COOL
DAIKIN_HEAT
DAIKIN_FAN
DAIKIN_AUTO
DAIKIN_DRY
*/
return (daikin[13])>>4;
}
void IRDaikinESP::setMode(uint8_t mode)
{
daikin[13]=mode<<4 | getPower();
checksum();
}
void IRDaikinESP::setSwingVertical(uint8_t swing)
{
if (swing)
daikin[16] = daikin[16] | 0x0F;
else
daikin[16] = daikin[16] & 0xF0;
checksum();
}
uint8_t IRDaikinESP::getSwingVertical()
{
return (daikin[16])&0x01;
}
void IRDaikinESP::setSwingHorizontal(uint8_t swing)
{
if (swing)
daikin[17] = daikin[17] | 0x0F;
else
daikin[17] = daikin[17] & 0xF0;
checksum();
}
uint8_t IRDaikinESP::getSwingHorizontal()
{
return (daikin[17])&0x01;
}