forked from ToniA/arduino-heatpumpir
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MitsubishiHeatpumpIR.cpp
296 lines (253 loc) · 8.18 KB
/
MitsubishiHeatpumpIR.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#include <MitsubishiHeatpumpIR.h>
// These are protected methods, i.e. generic Mitsubishi instances cannot be created directly
MitsubishiHeatpumpIR::MitsubishiHeatpumpIR() : HeatpumpIR()
{
}
// The different models just set the model accordingly
MitsubishiFDHeatpumpIR::MitsubishiFDHeatpumpIR() : MitsubishiHeatpumpIR()
{
static const char PROGMEM model[] PROGMEM = "mitsubishi_fd";
static const char PROGMEM info[] PROGMEM = "{\"mdl\":\"mitsubishi_fd\",\"dn\":\"Mitsubishi FD\",\"mT\":16,\"xT\":31,\"fs\":5}";
_model = model;
_info = info;
_mitsubishiModel = MITSUBISHI_FD;
}
MitsubishiFEHeatpumpIR::MitsubishiFEHeatpumpIR() : MitsubishiHeatpumpIR()
{
static const char PROGMEM model[] PROGMEM = "mitsubishi_fe";
static const char PROGMEM info[] PROGMEM = "{\"mdl\":\"mitsubishi_fe\",\"dn\":\"Mitsubishi FE\",\"mT\":16,\"xT\":31,\"fs\":5,\"maint\":[10]}";
_model = model;
_info = info;
_mitsubishiModel = MITSUBISHI_FE;
}
MitsubishiMSYHeatpumpIR::MitsubishiMSYHeatpumpIR() : MitsubishiHeatpumpIR()
{
static const char PROGMEM model[] PROGMEM = "mitsubishi_msy";
static const char PROGMEM info[] PROGMEM = "{\"mdl\":\"mitsubishi_msy\",\"dn\":\"Mitsubishi MSY\",\"mT\":16,\"xT\":31,\"fs\":5,\"maint\":[10]}";
_model = model;
_info = info;
_mitsubishiModel = MITSUBISHI_MSY;
}
MitsubishiFAHeatpumpIR::MitsubishiFAHeatpumpIR() : MitsubishiHeatpumpIR()
{
static const char PROGMEM model[] PROGMEM = "mitsubishi_fa";
static const char PROGMEM info[] PROGMEM = "{\"mdl\":\"mitsubishi_fa\",\"dn\":\"Mitsubishi FA\",\"mT\":16,\"xT\":31,\"fs\":5}"; //TODO: What should be here?
_model = model;
_info = info;
_mitsubishiModel = MITSUBISHI_FA;
}
void MitsubishiHeatpumpIR::send(IRSender& IR, uint8_t powerModeCmd, uint8_t operatingModeCmd, uint8_t fanSpeedCmd, uint8_t temperatureCmd, uint8_t swingVCmd, uint8_t swingHCmd)
{
// Sensible defaults for the heat pump mode
uint8_t powerMode = MITSUBISHI_AIRCON1_MODE_ON;
uint8_t operatingMode = MITSUBISHI_AIRCON1_MODE_HEAT;
uint8_t fanSpeed = MITSUBISHI_AIRCON1_FAN_AUTO;
uint8_t temperature = 23;
uint8_t swingV = MITSUBISHI_AIRCON1_VS_AUTO;
uint8_t swingH = MITSUBISHI_AIRCON1_HS_SWING;
if (powerModeCmd == 0)
{
powerMode = MITSUBISHI_AIRCON1_MODE_OFF;
}
if (_mitsubishiModel != MITSUBISHI_MSY)
{
switch (operatingModeCmd)
{
case MODE_AUTO:
operatingMode = MITSUBISHI_AIRCON1_MODE_AUTO;
break;
case MODE_HEAT:
operatingMode = MITSUBISHI_AIRCON1_MODE_HEAT;
break;
case MODE_COOL:
operatingMode = MITSUBISHI_AIRCON1_MODE_COOL;
break;
case MODE_DRY:
operatingMode = MITSUBISHI_AIRCON1_MODE_DRY;
break;
case MODE_FAN:
if (_mitsubishiModel == MITSUBISHI_FE) {
operatingMode = MITSUBISHI_AIRCON1_MODE_FAN;
temperatureCmd = 24;
} else {
operatingMode = MITSUBISHI_AIRCON1_MODE_COOL;
// Temperature needs to be set to 31 degrees for 'simulated' FAN mode
temperatureCmd = 31;
}
break;
case MODE_MAINT: // Maintenance mode is just the heat mode at +10, FAN5
if (_mitsubishiModel == MITSUBISHI_FE) {
operatingMode |= MITSUBISHI_AIRCON1_MODE_HEAT;
temperature = 10; // Default to +10 degrees
fanSpeedCmd = FAN_AUTO;
}
break;
}
}
else if (_mitsubishiModel == MITSUBISHI_FA) // set operating model for FA
{
switch (operatingModeCmd)
{
case MODE_AUTO:
operatingMode = MITSUBISHI_AIRCON3_MODE_AUTO;
break;
case MODE_HEAT:
operatingMode = MITSUBISHI_AIRCON3_MODE_HEAT;
break;
case MODE_COOL:
operatingMode = MITSUBISHI_AIRCON3_MODE_COOL;
break;
case MODE_DRY:
operatingMode = MITSUBISHI_AIRCON3_MODE_DRY;
break;
}
}
else
{
operatingMode = MITSUBISHI_AIRCON2_MODE_COOL;
switch (operatingModeCmd)
{
case MODE_AUTO:
operatingMode = MITSUBISHI_AIRCON2_MODE_IFEEL;
break;
case MODE_COOL:
operatingMode = MITSUBISHI_AIRCON2_MODE_COOL;
break;
case MODE_DRY:
operatingMode = MITSUBISHI_AIRCON2_MODE_DRY;
break;
case MODE_FAN:
operatingMode = MITSUBISHI_AIRCON2_MODE_FAN;
break;
}
}
switch (fanSpeedCmd)
{
case FAN_AUTO:
fanSpeed = MITSUBISHI_AIRCON1_FAN_AUTO;
break;
case FAN_1:
fanSpeed = MITSUBISHI_AIRCON1_FAN1;
break;
case FAN_2:
fanSpeed = MITSUBISHI_AIRCON1_FAN2;
break;
case FAN_3:
fanSpeed = MITSUBISHI_AIRCON1_FAN3;
break;
case FAN_4:
fanSpeed = MITSUBISHI_AIRCON1_FAN4;
break;
}
if ( temperatureCmd > 16 && temperatureCmd < 32)
{
temperature = temperatureCmd;
}
switch (swingVCmd)
{
case VDIR_AUTO:
swingV = MITSUBISHI_AIRCON1_VS_AUTO;
break;
case VDIR_SWING:
swingV = MITSUBISHI_AIRCON1_VS_SWING;
break;
case VDIR_UP:
swingV = MITSUBISHI_AIRCON1_VS_UP;
break;
case VDIR_MUP:
swingV = MITSUBISHI_AIRCON1_VS_MUP;
break;
case VDIR_MIDDLE:
swingV = MITSUBISHI_AIRCON1_VS_MIDDLE;
break;
case VDIR_MDOWN:
swingV = MITSUBISHI_AIRCON1_VS_MDOWN;
break;
case VDIR_DOWN:
swingV = MITSUBISHI_AIRCON1_VS_DOWN;
break;
}
switch (swingHCmd)
{
case HDIR_AUTO:
case HDIR_SWING:
swingH = MITSUBISHI_AIRCON1_HS_SWING;
break;
case HDIR_MIDDLE:
swingH = MITSUBISHI_AIRCON1_HS_MIDDLE;
break;
case HDIR_LEFT:
swingH = MITSUBISHI_AIRCON1_HS_LEFT;
break;
case HDIR_MLEFT:
swingH = MITSUBISHI_AIRCON1_HS_MLEFT;
break;
case HDIR_RIGHT:
swingH = MITSUBISHI_AIRCON1_HS_RIGHT;
break;
case HDIR_MRIGHT:
swingH = MITSUBISHI_AIRCON1_HS_MRIGHT;
break;
}
sendMitsubishi(IR, powerMode, operatingMode, fanSpeed, temperature, swingV, swingH);
}
void MitsubishiHeatpumpIR::sendMitsubishi(IRSender& IR, uint8_t powerMode, uint8_t operatingMode, uint8_t fanSpeed, uint8_t temperature, uint8_t swingV, uint8_t swingH)
{
uint8_t MitsubishiTemplate[] = { 0x23, 0xCB, 0x26, 0x01, 0x00, 0x20, 0x48, 0x00, 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0x10, 0x40, 0x00, 0x00 };
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
uint8_t checksum = 0x00;
// Set the operatingmode on the template message
MitsubishiTemplate[5] = powerMode;
MitsubishiTemplate[6] = operatingMode;
// Set the temperature on the template message
if (temperature == 10) {
MitsubishiTemplate[7] = 0x00; // Maintenance mode
MitsubishiTemplate[15] = 0x20; // This seems to be set to 0x20 on maintenance mode
} else {
MitsubishiTemplate[7] = temperature - 16;
}
// Set the horizontal air direction on the template message
MitsubishiTemplate[8] = swingH;
// Set the fan speed and vertical air direction on the template message
MitsubishiTemplate[9] = fanSpeed | swingV;
// MSY has a bit different template
if (_mitsubishiModel == MITSUBISHI_MSY) {
MitsubishiTemplate[14] = 0x00;
MitsubishiTemplate[15] = 0x00;
}
// FA also has a bit different template
if (_mitsubishiModel == MITSUBISHI_FA)
{
MitsubishiTemplate[10] = 0x00;
MitsubishiTemplate[15] = 0x00;
}
// Calculate the checksum
for (int i=0; i<17; i++) {
checksum += MitsubishiTemplate[i];
}
MitsubishiTemplate[17] = checksum;
// 40 kHz PWM frequency
IR.setFrequency(38);
// The Mitsubishi data is repeated twice
for (int j=0; j<2; j++) {
// Header
IR.mark(MITSUBISHI_AIRCON1_HDR_MARK);
IR.space(MITSUBISHI_AIRCON1_HDR_SPACE);
// Data
for (unsigned int i=0; i<sizeof(MitsubishiTemplate); i++) {
IR.sendIRbyte(MitsubishiTemplate[i], MITSUBISHI_AIRCON1_BIT_MARK, MITSUBISHI_AIRCON1_ZERO_SPACE, MITSUBISHI_AIRCON1_ONE_SPACE);
}
// Pause between the first and the second data burst
// Also modify one byte for the second burst on MSY model. This does not affect the checksum of the second burst
if (j == 0) {
IR.mark(MITSUBISHI_AIRCON1_BIT_MARK);
IR.space(MITSUBISHI_AIRCON1_MSG_SPACE);
if (_mitsubishiModel == MITSUBISHI_MSY) {
MitsubishiTemplate[14] = 0x24;
}
}
}
// End mark
IR.mark(MITSUBISHI_AIRCON1_BIT_MARK);
IR.space(0);
}