forked from adafruit/Raw-IR-decoder-for-Arduino
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathKY26Remote.cpp
158 lines (147 loc) · 4.96 KB
/
KY26Remote.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
153
154
155
156
157
158
#include <Arduino.h>
// KY-26 Remote protocol
//
// The KY-26 remote control is used in locally branded air conditioners.
// I used a ZAICON air conditioner, which also seems to be rebranded as
// SACOM, SENCYS, and possibly others.
//
// The remote sends a 4-byte message which contains all possible settings every
// time.
//
// Byte 0 contains the a power signal, operating mode, and fan speed.
// Byte 1 contains the timer setting.
// Byte 2 contains the temperature setting.
// Byte 3 contains a checksum.
bool decodeKY26Remote(byte *bytes, int byteCount) {
// If this looks like a KY-26 code...
if (byteCount != 4 //
|| (bytes[0] & 0xC4) != 0x00 // Bits 3, 7, and 8 must be 0
|| (bytes[1] & 0xC0) != 0x80 // Bits 7 must be 0, bit 8 must be 1
|| (bytes[2] & 0xE0) != 0x00 // Bits 6, 7, and 8 must be 0
|| (bytes[3] & 0x80) != 0x80 // Bit 8 must be 1
) {
return false;
}
Serial.println(F("Looks like a KY-26 remote control protocol"));
// Power mode
// It sends the same signal for on/off, it depends on the unit status.
if (bytes[0] & 0x08) {
Serial.println(F("On/Off action"));
}
// Operating mode
Serial.print(F("MODE: "));
switch (bytes[0] & 0x03) {
case 0x00:
Serial.println(F("AUTO"));
break;
case 0x01:
Serial.println(F("COOL"));
break;
case 0x03:
Serial.println(F("FAN"));
break;
case 0x02:
Serial.println(F("DRY"));
break;
}
// Fan speed
switch (bytes[0] & 0x30) {
case 0x10:
Serial.println(F("FAN: 1"));
break;
case 0x20:
Serial.println(F("FAN: 2"));
break;
case 0x30:
Serial.println(F("FAN: 3"));
break;
}
// Timer
// First 4 bits are hours, last 4 bits are half hours.
Serial.print(F("Timer: "));
if (!(bytes[1] & 0x20)) {
Serial.println(F("OFF"));
} else {
Serial.print(bytes[1] & 0x0F);
if (bytes[1] & 0x10) {
Serial.print(F(".5"));
}
Serial.println(F("h"));
}
// Temperature
Serial.print(F("Temperature: "));
int temp = bytes[2] & 0x1F;
Serial.println(temp == 0 ? 15 : temp); // 0 is 15 degrees
// CheckSum8 Modulo 256
byte checksum = 0;
for (int i = 0; i < 3; i++) {
checksum += bytes[i];
}
checksum = checksum % 256;
if (checksum != bytes[3]) {
Serial.print(F("Checksum error: "));
Serial.print(checksum, HEX);
Serial.print(F(" != "));
Serial.println(bytes[3], HEX);
} else {
Serial.println(F("Checksum matches"));
}
return true;
}
/*
x
Hh 00011000 00000001 00000001 11110101 h POWER
xx
Hh 00001000 00000001 11101000 11100101 h SPEED 1
Hh 00000100 00000001 11101000 11101101 h SPEED 2
Hh 00001100 00000001 11101000 11100011 h SPEED 3
xx
Hh 00001000 00000001 11101000 11100101 h MODE 1
Hh 10001000 00000001 11011000 00110101 h MODE 2
Hh 11001000 00000001 11011000 01110101 h MODE 3
Hh 01001000 00000001 10011000 11010101 h MODE 4
xxxxxx
Hh 00001000 00000001 00000000 00001001 h TEMP 15
Hh 00001000 00000001 00001000 00000101 h TEMP 16
Hh 00001000 00000001 10001000 10000101 h TEMP 17
Hh 00001000 00000001 01001000 01000101 h TEMP 18
Hh 00001000 00000001 11001000 11000101 h TEMP 19
Hh 00001000 00000001 00101000 00100101 h TEMP 20
Hh 00001000 00000001 10101000 10100101 h TEMP 21
Hh 00001000 00000001 01101000 01100101 h TEMP 22
Hh 00001000 00000001 11101000 11100101 h TEMP 23
Hh 00001000 00000001 00011000 00010101 h TEMP 24
Hh 00001000 00000001 10011000 10010101 h TEMP 25
Hh 00001000 00000001 01011000 01010101 h TEMP 26
Hh 00001000 00000001 11011000 11010101 h TEMP 27
Hh 00001000 00000001 00111000 00110101 h TEMP 28
Hh 00001000 00000001 10111000 10110101 h TEMP 29
Hh 00001000 00000001 01111000 01110101 h TEMP 30
Hh 00001000 00000001 11111000 11110101 h TEMP 31
xxxxxx
Hh 00001100 00000001 00000000 00001101 h Timer OFF
Hh 00001100 00001101 00000000 00000111 h Timer 0.5h
Hh 00001100 10000101 00000000 10001011 h Timer 1h
Hh 00001100 10001101 00000000 10000111 h Timer 1.5h
Hh 00001100 01000101 00000000 01001011 h Timer 2h
Hh 00001100 01001101 00000000 01000111 h Timer 2.5h
Hh 00001100 11000101 00000000 11001011 h Timer 3h
Hh 00001100 11001101 00000000 11000111 h Timer 3.5h
Hh 00001100 00100101 00000000 00101011 h Timer 4h
Hh 00001100 00101101 00000000 00100111 h Timer 4.5h
Hh 00001100 10100101 00000000 10101011 h Timer 5h
Hh 00001100 10101101 00000000 10100111 h Timer 5.5h
Hh 00001100 01100101 00000000 01101011 h Timer 6h
Hh 00001100 01101101 00000000 01100111 h Timer 6.5h
Hh 00001100 11100101 00000000 11101011 h Timer 7h
Hh 00001100 11101101 00000000 11100111 h Timer 7.5h
Hh 00001100 00010101 00000000 00011011 h Timer 8h
Hh 00001100 00011101 00000000 00010111 h Timer 8.5h
Hh 00001100 10010101 00000000 10011011 h Timer 9h
Hh 00001100 10011101 00000000 10010111 h Timer 9.5h
Hh 00001100 01010101 00000000 01011011 h Timer 10h
Hh 00001100 01011101 00000000 01010111 h Timer 10.5h
Hh 00001100 11010101 00000000 11011011 h Timer 11h
Hh 00001100 11011101 00000000 11010111 h Timer 11.5h
Hh 00001100 00110101 00000000 00111011 h Timer 12h
*/