forked from ToniA/arduino-heatpumpir
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MitsubishiHeavyHeatpumpIR.cpp
389 lines (328 loc) · 11.8 KB
/
MitsubishiHeavyHeatpumpIR.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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
#include <MitsubishiHeavyHeatpumpIR.h>
// These are protected methods, i.e. generic MitsubishiHeavy instances cannot be created directly
MitsubishiHeavyHeatpumpIR::MitsubishiHeavyHeatpumpIR() : HeatpumpIR()
{
}
// The different models just set the model accordingly
MitsubishiHeavyZJHeatpumpIR::MitsubishiHeavyZJHeatpumpIR() : MitsubishiHeavyHeatpumpIR()
{
static const char PROGMEM model[] PROGMEM = "mitsubishi_heavy_zj";
static const char PROGMEM info[] PROGMEM = "{\"mdl\":\"mitsubishi_heavy_zj\",\"dn\":\"Mitsubishi Heavy ZJ\",\"mT\":18,\"xT\":30,\"fs\":3}";
_model = model;
_info = info;
_mitsubishiModel = MITSUBISHIHEAVY_ZJ;
}
MitsubishiHeavyZMHeatpumpIR::MitsubishiHeavyZMHeatpumpIR() : MitsubishiHeavyHeatpumpIR()
{
static const char PROGMEM model[] PROGMEM = "mitsubishi_heavy_zm";
static const char PROGMEM info[] PROGMEM = "{\"mdl\":\"mitsubishi_heavy_zm\",\"dn\":\"Mitsubishi Heavy ZM\",\"mT\":18,\"xT\":30,\"fs\":4}";
_model = model;
_info = info;
_mitsubishiModel = MITSUBISHIHEAVY_ZM;
}
void MitsubishiHeavyHeatpumpIR::send(IRSender& IR, uint8_t powerModeCmd, uint8_t operatingModeCmd, uint8_t fanSpeedCmd, uint8_t temperatureCmd, uint8_t swingVCmd, uint8_t swingHCmd)
{
send(IR, powerModeCmd, operatingModeCmd, fanSpeedCmd, temperatureCmd, swingVCmd, swingHCmd, true, false, false);
}
// This is a virtual dummy method, i.e. MitsubishiHeavyZJHeatpumpIR::send or MitsubishiHeavyZMHeatpumpIR::send is called instead
void MitsubishiHeavyHeatpumpIR::send(IRSender&, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, bool, bool, bool)
{
}
void MitsubishiHeavyZJHeatpumpIR::send(IRSender& IR, uint8_t powerModeCmd, uint8_t operatingModeCmd, uint8_t fanSpeedCmd, uint8_t temperatureCmd, uint8_t swingVCmd, uint8_t swingHCmd, bool cleanModeCmd, bool silentModeCmd, bool _3DAutoCmd)
{
// Sensible defaults for the heat pump mode
uint8_t powerMode = MITSUBISHI_HEAVY_MODE_ON;
uint8_t operatingMode = MITSUBISHI_HEAVY_MODE_HEAT;
uint8_t fanSpeed = MITSUBISHI_HEAVY_ZJ_FAN_AUTO;
uint8_t temperature = 23;
uint8_t swingV = MITSUBISHI_HEAVY_ZJ_VS_STOP;
uint8_t swingH = MITSUBISHI_HEAVY_ZJ_HS_STOP;
uint8_t cleanMode = MITSUBISHI_HEAVY_ZJ_CLEAN_OFF;
if (powerModeCmd == POWER_OFF)
{
powerMode = MITSUBISHI_HEAVY_MODE_OFF;
}
if (cleanModeCmd && powerModeCmd == POWER_OFF && (operatingModeCmd == MODE_AUTO || operatingModeCmd == MODE_COOL || operatingModeCmd == MODE_DRY))
{
powerMode = MITSUBISHI_HEAVY_MODE_ON;
cleanMode = MITSUBISHI_HEAVY_CLEAN_ON;
}
switch (operatingModeCmd)
{
case MODE_AUTO:
operatingMode = MITSUBISHI_HEAVY_MODE_AUTO;
break;
case MODE_HEAT:
operatingMode = MITSUBISHI_HEAVY_MODE_HEAT;
break;
case MODE_COOL:
operatingMode = MITSUBISHI_HEAVY_MODE_COOL;
break;
case MODE_DRY:
operatingMode = MITSUBISHI_HEAVY_MODE_DRY;
break;
case MODE_FAN:
operatingMode = MITSUBISHI_HEAVY_MODE_FAN;
break;
}
switch (fanSpeedCmd)
{
case FAN_AUTO:
fanSpeed = MITSUBISHI_HEAVY_ZJ_FAN_AUTO;
break;
case FAN_1:
fanSpeed = MITSUBISHI_HEAVY_ZJ_FAN1;
break;
case FAN_2:
fanSpeed = MITSUBISHI_HEAVY_ZJ_FAN2;
break;
case FAN_3:
fanSpeed = MITSUBISHI_HEAVY_ZJ_FAN3;
break;
}
if (silentModeCmd)
{
// Silent mode doesn't exist on ZJ model, use ECONO mode instead
fanSpeed = MITSUBISHI_HEAVY_ZJ_SILENT_ON;
}
if ( temperatureCmd > 17 && temperatureCmd < 31)
{
temperature = (~((temperatureCmd - 17) << 4)) & 0xF0;
}
switch (swingVCmd)
{
case VDIR_MANUAL:
swingV = MITSUBISHI_HEAVY_ZJ_VS_STOP;
break;
case VDIR_SWING:
swingV = MITSUBISHI_HEAVY_ZJ_VS_SWING;
break;
case VDIR_UP:
swingV = MITSUBISHI_HEAVY_ZJ_VS_UP;
break;
case VDIR_MUP:
swingV = MITSUBISHI_HEAVY_ZJ_VS_MUP;
break;
case VDIR_MIDDLE:
swingV = MITSUBISHI_HEAVY_ZJ_VS_MIDDLE;
break;
case VDIR_MDOWN:
swingV = MITSUBISHI_HEAVY_ZJ_VS_MDOWN;
break;
case VDIR_DOWN:
swingV = MITSUBISHI_HEAVY_ZJ_VS_DOWN;
break;
}
switch (swingHCmd)
{
case HDIR_MANUAL:
swingH = MITSUBISHI_HEAVY_ZJ_HS_STOP;
break;
case HDIR_SWING:
swingH = MITSUBISHI_HEAVY_ZJ_HS_SWING;
break;
case HDIR_MIDDLE:
swingH = MITSUBISHI_HEAVY_ZJ_HS_MIDDLE;
break;
case HDIR_LEFT:
swingH = MITSUBISHI_HEAVY_ZJ_HS_LEFT;
break;
case HDIR_MLEFT:
swingH = MITSUBISHI_HEAVY_ZJ_HS_MLEFT;
break;
case HDIR_RIGHT:
swingH = MITSUBISHI_HEAVY_ZJ_HS_RIGHT;
break;
case HDIR_MRIGHT:
swingH = MITSUBISHI_HEAVY_ZJ_HS_MRIGHT;
break;
}
if (_3DAutoCmd == true && (operatingModeCmd == MODE_AUTO || operatingModeCmd == MODE_COOL || operatingModeCmd == MODE_HEAT))
{
swingH = MITSUBISHI_HEAVY_ZJ_HS_3DAUTO;
}
sendMitsubishiHeavy(IR, powerMode, operatingMode, fanSpeed, temperature, swingV, swingH, cleanMode);
}
void MitsubishiHeavyZMHeatpumpIR::send(IRSender& IR, uint8_t powerModeCmd, uint8_t operatingModeCmd, uint8_t fanSpeedCmd, uint8_t temperatureCmd, uint8_t swingVCmd, uint8_t swingHCmd, bool cleanModeCmd, bool silentModeCmd, bool _3DAutoCmd)
{
// Sensible defaults for the heat pump mode
uint8_t powerMode = MITSUBISHI_HEAVY_MODE_ON;
uint8_t operatingMode = MITSUBISHI_HEAVY_MODE_HEAT;
uint8_t fanSpeed = MITSUBISHI_HEAVY_ZM_FAN_AUTO;
uint8_t temperature = 23;
uint8_t swingV = MITSUBISHI_HEAVY_ZM_VS_STOP;
uint8_t swingH = MITSUBISHI_HEAVY_ZM_HS_STOP;
uint8_t cleanMode = MITSUBISHI_HEAVY_ZM_CLEAN_OFF;
uint8_t _3DAuto = MITSUBISHI_HEAVY_ZM_3DAUTO_OFF;
uint8_t silentMode = MITSUBISHI_HEAVY_ZM_SILENT_OFF;
if (powerModeCmd == POWER_OFF)
{
powerMode = MITSUBISHI_HEAVY_MODE_OFF;
}
if (cleanModeCmd && powerModeCmd == POWER_OFF && (operatingModeCmd == MODE_AUTO || operatingModeCmd == MODE_COOL || operatingModeCmd == MODE_DRY))
{
powerMode = MITSUBISHI_HEAVY_MODE_ON;
cleanMode = MITSUBISHI_HEAVY_CLEAN_ON;
}
if (silentModeCmd && !(operatingModeCmd == MODE_DRY || operatingModeCmd == MODE_FAN))
{
silentMode = MITSUBISHI_HEAVY_ZM_SILENT_ON;
}
if (_3DAutoCmd && !(operatingModeCmd == MODE_DRY || operatingModeCmd == MODE_FAN))
{
_3DAuto = MITSUBISHI_HEAVY_ZM_3DAUTO_ON;
}
switch (operatingModeCmd)
{
case MODE_AUTO:
operatingMode = MITSUBISHI_HEAVY_MODE_AUTO;
break;
case MODE_HEAT:
operatingMode = MITSUBISHI_HEAVY_MODE_HEAT;
break;
case MODE_COOL:
operatingMode = MITSUBISHI_HEAVY_MODE_COOL;
break;
case MODE_DRY:
operatingMode = MITSUBISHI_HEAVY_MODE_DRY;
break;
case MODE_FAN:
operatingMode = MITSUBISHI_HEAVY_MODE_FAN;
break;
}
switch (fanSpeedCmd)
{
case FAN_AUTO:
fanSpeed = MITSUBISHI_HEAVY_ZM_FAN_AUTO;
break;
case FAN_1:
fanSpeed = MITSUBISHI_HEAVY_ZM_FAN1;
break;
case FAN_2:
fanSpeed = MITSUBISHI_HEAVY_ZM_FAN2;
break;
case FAN_3:
fanSpeed = MITSUBISHI_HEAVY_ZM_FAN3;
break;
case FAN_4:
fanSpeed = MITSUBISHI_HEAVY_ZM_FAN4;
break;
}
if ( temperatureCmd > 17 && temperatureCmd < 31)
{
temperature = (~(temperatureCmd - 17) & 0x0F);
}
switch (swingVCmd)
{
case VDIR_MANUAL:
swingV = MITSUBISHI_HEAVY_ZM_VS_STOP;
break;
case VDIR_SWING:
swingV = MITSUBISHI_HEAVY_ZM_VS_SWING;
break;
case VDIR_UP:
swingV = MITSUBISHI_HEAVY_ZM_VS_UP;
break;
case VDIR_MUP:
swingV = MITSUBISHI_HEAVY_ZM_VS_MUP;
break;
case VDIR_MIDDLE:
swingV = MITSUBISHI_HEAVY_ZM_VS_MIDDLE;
break;
case VDIR_MDOWN:
swingV = MITSUBISHI_HEAVY_ZM_VS_MDOWN;
break;
case VDIR_DOWN:
swingV = MITSUBISHI_HEAVY_ZM_VS_DOWN;
break;
}
switch (swingHCmd)
{
case HDIR_MANUAL:
swingH = MITSUBISHI_HEAVY_ZM_HS_STOP;
break;
case HDIR_SWING:
swingH = MITSUBISHI_HEAVY_ZM_HS_SWING;
break;
case HDIR_MIDDLE:
swingH = MITSUBISHI_HEAVY_ZM_HS_MIDDLE;
break;
case HDIR_LEFT:
swingH = MITSUBISHI_HEAVY_ZM_HS_LEFT;
break;
case HDIR_MLEFT:
swingH = MITSUBISHI_HEAVY_ZM_HS_MLEFT;
break;
case HDIR_RIGHT:
swingH = MITSUBISHI_HEAVY_ZM_HS_RIGHT;
break;
case HDIR_MRIGHT:
swingH = MITSUBISHI_HEAVY_ZM_HS_MRIGHT;
break;
}
sendMitsubishiHeavy(IR, powerMode, operatingMode, fanSpeed, temperature, swingV, swingH, cleanMode, silentMode, _3DAuto);
}
void MitsubishiHeavyZJHeatpumpIR::sendMitsubishiHeavy(IRSender& IR, uint8_t powerMode, uint8_t operatingMode, uint8_t fanSpeed, uint8_t temperature, uint8_t swingV, uint8_t swingH, uint8_t cleanMode)
{
uint8_t MitsubishiHeavyZJTemplate[] = { 0x52, 0xAE, 0xC3, 0x26, 0xD9, 0x11, 0x00, 0x07, 0x00, 0x00, 0x00 };
// 0 1 2 3 4 5 6 7 8 9 10
// Horizontal & vertical air flow + allergen + clean + 3D
MitsubishiHeavyZJTemplate[5] |= swingH | (swingV & 0b00000010) | cleanMode;
// Vertical air flow + fan speed
MitsubishiHeavyZJTemplate[7] |= fanSpeed | (swingV & 0b00011000);
// Power state + operating mode + temperature
MitsubishiHeavyZJTemplate[9] |= operatingMode | powerMode | temperature;
// There is no checksum, but some bytes are inverted
MitsubishiHeavyZJTemplate[6] = ~MitsubishiHeavyZJTemplate[5];
MitsubishiHeavyZJTemplate[8] = ~MitsubishiHeavyZJTemplate[7];
MitsubishiHeavyZJTemplate[10] = ~MitsubishiHeavyZJTemplate[9];
// 38 kHz PWM frequency
IR.setFrequency(38);
// Header
IR.mark(MITSUBISHI_HEAVY_HDR_MARK);
IR.space(MITSUBISHI_HEAVY_HDR_SPACE);
// Data
for (uint8_t i=0; i<sizeof(MitsubishiHeavyZJTemplate); i++) {
IR.sendIRbyte(MitsubishiHeavyZJTemplate[i], MITSUBISHI_HEAVY_BIT_MARK, MITSUBISHI_HEAVY_ZERO_SPACE, MITSUBISHI_HEAVY_ONE_SPACE);
}
// End mark
IR.mark(MITSUBISHI_HEAVY_BIT_MARK);
IR.space(0);
}
void MitsubishiHeavyZMHeatpumpIR::sendMitsubishiHeavy(IRSender& IR, uint8_t powerMode, uint8_t operatingMode, uint8_t fanSpeed, uint8_t temperature, uint8_t swingV, uint8_t swingH, uint8_t cleanMode, uint8_t silentMode, uint8_t _3DAuto)
{
uint8_t MitsubishiHeavyZMTemplate[] = { 0x52, 0xAE, 0xC3, 0x1A, 0xE5, 0x90, 0x00, 0xF0, 0x00, 0xF0, 0x00, 0x0D, 0x00, 0x10, 0x00, 0xFF, 0x00, 0x7B, 0x00 };
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// Power state + operating mode
MitsubishiHeavyZMTemplate[5] |= operatingMode | powerMode | cleanMode;
// Temperature
MitsubishiHeavyZMTemplate[7] |= temperature;
// Fan speed
MitsubishiHeavyZMTemplate[9] |= fanSpeed;
// Vertical air flow + 3D auto
MitsubishiHeavyZMTemplate[11] |= swingV | _3DAuto;
// Horizontal air flow
MitsubishiHeavyZMTemplate[13] |= swingH | swingV;
// Silent
MitsubishiHeavyZMTemplate[15] |= silentMode;
// There is no checksum, but some bytes are inverted
MitsubishiHeavyZMTemplate[6] = ~MitsubishiHeavyZMTemplate[5];
MitsubishiHeavyZMTemplate[8] = ~MitsubishiHeavyZMTemplate[7];
MitsubishiHeavyZMTemplate[10] = ~MitsubishiHeavyZMTemplate[9];
MitsubishiHeavyZMTemplate[12] = ~MitsubishiHeavyZMTemplate[11];
MitsubishiHeavyZMTemplate[14] = ~MitsubishiHeavyZMTemplate[13];
MitsubishiHeavyZMTemplate[16] = ~MitsubishiHeavyZMTemplate[15];
MitsubishiHeavyZMTemplate[18] = ~MitsubishiHeavyZMTemplate[17];
// 38 kHz PWM frequency
IR.setFrequency(38);
// Header
IR.mark(MITSUBISHI_HEAVY_HDR_MARK);
IR.space(MITSUBISHI_HEAVY_HDR_SPACE);
// Data
for (uint8_t i=0; i<sizeof(MitsubishiHeavyZMTemplate); i++) {
IR.sendIRbyte(MitsubishiHeavyZMTemplate[i], MITSUBISHI_HEAVY_BIT_MARK, MITSUBISHI_HEAVY_ZERO_SPACE, MITSUBISHI_HEAVY_ONE_SPACE);
}
// End mark
IR.mark(MITSUBISHI_HEAVY_BIT_MARK);
IR.space(0);
}