-
Notifications
You must be signed in to change notification settings - Fork 0
/
PanavoxAC.cpp
184 lines (152 loc) · 3.83 KB
/
PanavoxAC.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include "PanavoxAC.h"
#define PANAVOX_AC_SIGN 0x0B
#define PANAVOX_AC_CMD_MODE 2
#define PANAVOX_AC_CMD_EXTRA 5
#define FAN_SPEED_0 5
#define FAN_SPEED_1 4
#define FAN_SPEED_2 2
#define FAN_SPEED_3 1
#define SETMODE(cmd,value) cmd->param2.mode = (uint8_t)value
#define SETFANSPEED(cmd, value) cmd->param1.fan_speed = (uint8_t)value
#define SETTEMP(cmd, value) cmd->param2.temp = (uint8_t)value
enum class PanavoxACMode : uint8_t {
Cool = 0,
DryFan = 1,
Auto = 2,
Heat = 3
};
typedef uint8_t ac_mode_t;
typedef struct panavox_ac_cmd_t {
uint8_t type : 4;
uint8_t sign : 4;
uint8_t param1;
uint8_t param2;
} panavox_ac_cmd_t;
typedef struct panavox_ac_cmd_mode_param1_t {
uint8_t ext : 5; // Fill with ones
uint8_t fan_speed : 3;
} panavox_ac_cmd_mode_param1_t;
typedef struct panavox_ac_cmd_mode_param2_t {
uint8_t ext : 2;
uint8_t mode : 2;
uint8_t temp : 4;
} panavox_ac_cmd_mode_param2_t;
typedef struct panavox_ac_cmd_mode_t {
uint8_t type : 4;
uint8_t sign : 4;
panavox_ac_cmd_mode_param1_t param1;
panavox_ac_cmd_mode_param2_t param2;
} panavox_ac_cmd_mode_t;
static uint8_t FAN_SPEEDS[] = { FAN_SPEED_0, FAN_SPEED_1, FAN_SPEED_2, FAN_SPEED_3 };
uint8_t encodeTemp(uint8_t temp) {
uint8_t value = temp - 17;
if (value == 10 || value == 11)
value += 4;
return value ^ (value >> 1);
}
PanavoxAC::PanavoxAC()
{
}
PanavoxAC::~PanavoxAC()
{
}
void PanavoxAC::sendState(void)
{
panavox_ac_cmd_t cmd;
panavox_ac_cmd_mode_t* cmd_mode = (panavox_ac_cmd_mode_t*)&cmd;
cmd.sign = PANAVOX_AC_SIGN;
cmd.type = PANAVOX_AC_CMD_MODE;
cmd_mode->param1.ext = 0x1F;
cmd_mode->param2.ext = 0;
SETFANSPEED(cmd_mode, FAN_SPEEDS[this->_fanSpeed]);
SETTEMP(cmd_mode, encodeTemp(this->_temperature));
if (this->_mode == ACMode::Off) {
cmd.param1 = 0x7B;
cmd.param2 = 0xE0;
}
else if (this->_mode == ACMode::Auto) {
SETMODE(cmd_mode, PanavoxACMode::Auto);
SETFANSPEED(cmd_mode, 0);
}
else if (this->_mode == ACMode::Dry) {
SETMODE(cmd_mode, PanavoxACMode::DryFan);
SETFANSPEED(cmd_mode, 0);
}
else if (this->_mode == ACMode::Fan) {
SETMODE(cmd_mode, PanavoxACMode::DryFan);
SETTEMP(cmd_mode, 0x0E);
}
else if (this->_mode == ACMode::Cool) {
SETMODE(cmd_mode, PanavoxACMode::Cool);
}
else if (this->_mode == ACMode::Heat) {
SETMODE(cmd_mode, PanavoxACMode::Heat);
}
uint32_t value = *((uint32_t*)&cmd) & 0x00FFFFFF;
Serial.println(value, HEX);
this->_irSender.send(value);
}
void PanavoxAC::setMode(ACMode mode)
{
this->_mode = mode;
}
ACMode PanavoxAC::getMode(void)
{
return this->_mode;
}
void PanavoxAC::setTemperature(uint8_t temp)
{
this->_temperature = max(min(temp, PANAVOX_AC_TEMP_MAX), PANAVOX_AC_TEMP_MIN);
}
uint8_t PanavoxAC::getTemperature(void)
{
return this->_temperature;
}
void PanavoxAC::setFanSpeed(uint8_t level)
{
this->_fanSpeed = min(level, 3);
}
uint8_t PanavoxAC::getFanSpeed(void)
{
return this->_fanSpeed;
}
void PanavoxAC::sendMoveFlap(void) {
panavox_ac_cmd_t cmd;
cmd.sign = PANAVOX_AC_SIGN;
cmd.type = PANAVOX_AC_CMD_MODE;
cmd.param1 = 0xE0;
cmd.param2 = 0x0F;
this->_irSender.send(&cmd);
}
void PanavoxAC::sendSwapLight(void) {
panavox_ac_cmd_t cmd;
cmd.sign = PANAVOX_AC_SIGN;
cmd.type = PANAVOX_AC_CMD_EXTRA;
cmd.param1 = 0xA5;
cmd.param2 = 0xF5;
this->_irSender.send(&cmd);
}
void PanavoxAC::sendSuperMode(void) {
panavox_ac_cmd_t cmd;
cmd.sign = PANAVOX_AC_SIGN;
cmd.type = PANAVOX_AC_CMD_EXTRA;
cmd.param1 = 0xA2;
cmd.param2 = 0xF5;
this->_irSender.send(&cmd);
}
void PanavoxAC::sendAutoClean(void) {
panavox_ac_cmd_t cmd;
cmd.sign = PANAVOX_AC_SIGN;
cmd.type = PANAVOX_AC_CMD_EXTRA;
cmd.param1 = 0xAA;
cmd.param2 = 0xF5;
this->_irSender.send(&cmd);
}
void PanavoxAC::sendFlapOscillation(void) {
panavox_ac_cmd_t cmd;
cmd.sign = PANAVOX_AC_SIGN;
cmd.type = PANAVOX_AC_CMD_MODE;
cmd.param1 = 0xE0;
cmd.param2 = 0x6B;
this->_irSender.send(&cmd);
}