forked from ToniA/Raw-IR-decoder-for-Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Samsung.cpp
119 lines (105 loc) · 2.61 KB
/
Samsung.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
#include <Arduino.h>
// Samsung with remote ARH-465
bool decodeSamsung(byte *bytes, int byteCount)
{
// If this looks like a Samsung code...
if (bytes[0] == 0x02
&& ((byteCount == 21 && bytes[1] == 0xB2) || (byteCount == 14 && bytes[1] == 0x92))
&& bytes[2] == 0x0F) {
Serial.println(F("Looks like a Samsung protocol"));
// Power mode
if (byteCount == 21)
{
Serial.println(F("POWER OFF"));
return true;
}
Serial.println(F("POWER ON"));
// Operating mode
switch (bytes[12] & 0xF0) {
case 0x00:
Serial.println(F("MODE AUTO"));
break;
case 0x10:
Serial.println(F("MODE COOL"));
break;
case 0x20:
Serial.println(F("MODE DRY"));
break;
case 0x30:
Serial.println(F("MODE FAN"));
break;
case 0x40:
Serial.println(F("MODE HEAT"));
break;
}
// Temperature
Serial.print(F("Temperature: "));
Serial.println((bytes[11] >> 4) + 16);
// Fan speed
switch (bytes[12] & 0x0F) {
case 0x01:
Serial.println(F("FAN: AUTO"));
break;
case 0x05:
Serial.println(F("FAN: 1"));
break;
case 0x09:
Serial.println(F("FAN: 2"));
break;
case 0x0B:
Serial.println(F("FAN: 3"));
break;
case 0x0F:
Serial.println(F("FAN: 4"));
break;
}
// Airflow mode
Serial.print(F("Airflow: "));
switch (bytes[9] & 0xF0) {
case 0xA0:
Serial.println(F("ON"));
break;
case 0xF0:
Serial.println(F("OFF"));
break;
}
// Turbo mode
Serial.print(F("Turbo mode: "));
switch (bytes[10] & 0x0F) {
case 0x07:
Serial.println(F("ON"));
break;
case 0x01:
Serial.println(F("OFF"));
break;
}
// Check if the checksum matches
byte originalChecksum = bytes[8];
byte checksum = 0x00;
// Calculate the byte 8 checksum
// Count the number of ONE bits
bytes[9] &= 0b11111110;
for (uint8_t j=9; j<13; j++) {
uint8_t samsungByte = bytes[j];
for (uint8_t i=0; i<8; i++) {
if ( (samsungByte & 0x01) == 0x01 ) {
checksum++;
}
samsungByte >>= 1;
}
}
checksum = 28 - checksum;
checksum <<= 4;
checksum |= 0x02;
Serial.print(F("Checksum '0x"));
Serial.print(checksum, HEX);
if ( originalChecksum == checksum ) {
Serial.println(F("' matches"));
} else {
Serial.print(F("' does not match 0x"));
Serial.println(originalChecksum, HEX);
}
return true;
}
return false;
}