forked from ToniA/Raw-IR-decoder-for-Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gree.cpp
99 lines (88 loc) · 2.07 KB
/
Gree.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
#include <Arduino.h>
bool decodeGree(byte *bytes, int pulseCount)
{
// If this looks like a Gree code...
if ( pulseCount == 71 ) {
Serial.println(F("Looks like a Gree protocol"));
// Check if the checksum matches
uint8_t checksum = (
(bytes[0] & 0x0F) +
(bytes[1] & 0x0F) +
(bytes[2] & 0x0F) +
(bytes[3] & 0x0F) +
(bytes[5] & 0xF0) >> 4 +
(bytes[6] & 0xF0) >> 4 +
(bytes[7] & 0xF0) >> 4 +
0x0A) & 0xF0;
if (checksum == bytes[8]) {
Serial.println(F("Checksum matches"));
} else {
Serial.println(F("Checksum does not match"));
}
// Power mode
switch (bytes[0] & 0x08) {
case 0x00:
Serial.println(F("POWER OFF"));
break;
case 0x08:
Serial.println(F("POWER ON"));
break;
}
// Operating mode
switch (bytes[0] & 0x07) {
case 0x00:
Serial.println(F("MODE AUTO"));
break;
case 0x04:
Serial.println(F("MODE HEAT"));
break;
case 0x01:
Serial.println(F("MODE COOL"));
break;
case 0x02:
Serial.println(F("MODE DRY"));
break;
case 0x03:
Serial.println(F("MODE FAN"));
break;
}
// Temperature
Serial.print(F("Temperature: "));
Serial.println((bytes[1] & 0x0F) + 16);
// Fan speed
switch (bytes[0] & 0x30) {
case 0x00:
Serial.println(F("FAN: AUTO"));
break;
case 0x10:
Serial.println(F("FAN: 1"));
break;
case 0x20:
Serial.println(F("FAN: 2"));
break;
case 0x30:
Serial.println(F("FAN: 3"));
break;
}
// Sleep mode
switch (bytes[0] & 0x80) {
case 0x80:
Serial.println(F("SLEEP: ON"));
break;
case 0x00:
Serial.println(F("SLEEP: OFF"));
break;
}
// Air direction
switch (bytes[0] & 0x40) {
case 0x40:
Serial.println(F("SWING: ON"));
break;
case 0x00:
Serial.println(F("SWING: OFF"));
break;
}
return true;
}
return false;
}