forked from ToniA/arduino-heatpumpir
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PanasonicCKPHeatpumpIR.cpp
262 lines (216 loc) · 8.25 KB
/
PanasonicCKPHeatpumpIR.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
#include <PanasonicCKPHeatpumpIR.h>
PanasonicCKPHeatpumpIR::PanasonicCKPHeatpumpIR()
{
static const char PROGMEM model[] PROGMEM = "panasonic_ckp";
static const char PROGMEM info[] PROGMEM = "{\"mdl\":\"panasonic_ckp\",\"dn\":\"Panasonic CKP\",\"mT\":16,\"xT\":30,\"fs\":6}";
_model = model;
_info = info;
}
// Panasonic CKP numeric values to command uint8_ts
void PanasonicCKPHeatpumpIR::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 = false;
uint8_t operatingMode = PANASONIC_AIRCON1_MODE_KEEP;
uint8_t fanSpeed = PANASONIC_AIRCON1_FAN_AUTO;
uint8_t temperature = 23;
uint8_t swingV = PANASONIC_AIRCON1_VS_UP;
uint8_t swingH = PANASONIC_AIRCON1_HS_SWING;
switch (powerModeCmd)
{
case POWER_ON:
powerMode = true;
break;
}
switch (operatingModeCmd)
{
case MODE_AUTO:
operatingMode |= PANASONIC_AIRCON1_MODE_AUTO;
break;
case MODE_HEAT:
operatingMode |= PANASONIC_AIRCON1_MODE_HEAT;
break;
case MODE_COOL:
operatingMode |= PANASONIC_AIRCON1_MODE_COOL;
break;
case MODE_DRY:
operatingMode |= PANASONIC_AIRCON1_MODE_DRY;
break;
case MODE_FAN:
operatingMode |= PANASONIC_AIRCON1_MODE_FAN;
temperatureCmd = 27; // Temperature is always 27 in FAN mode
break;
default:
operatingMode |= PANASONIC_AIRCON1_MODE_HEAT;
break;
}
switch (fanSpeedCmd)
{
case FAN_AUTO:
fanSpeed = PANASONIC_AIRCON1_FAN_AUTO;
break;
case FAN_1:
fanSpeed = PANASONIC_AIRCON1_FAN1;
break;
case FAN_2:
fanSpeed = PANASONIC_AIRCON1_FAN2;
break;
case FAN_3:
fanSpeed = PANASONIC_AIRCON1_FAN3;
break;
case FAN_4:
fanSpeed = PANASONIC_AIRCON1_FAN4;
break;
case FAN_5:
fanSpeed = PANASONIC_AIRCON1_FAN5;
break;
}
if ( temperatureCmd > 15 && temperatureCmd < 31)
{
temperature = temperatureCmd;
}
switch (swingVCmd)
{
case VDIR_SWING:
swingV = PANASONIC_AIRCON1_VS_SWING;
break;
case VDIR_UP:
swingV = PANASONIC_AIRCON1_VS_UP;
break;
case VDIR_MUP:
swingV = PANASONIC_AIRCON1_VS_MUP;
break;
case VDIR_MIDDLE:
swingV = PANASONIC_AIRCON1_VS_MIDDLE;
break;
case VDIR_MDOWN:
swingV = PANASONIC_AIRCON1_VS_MDOWN;
break;
case VDIR_DOWN:
swingV = PANASONIC_AIRCON1_VS_DOWN;
break;
}
switch (swingHCmd)
{
case HDIR_SWING:
swingH = PANASONIC_AIRCON1_HS_SWING;
break;
case HDIR_AUTO: // Well, just set it to manual
swingH = PANASONIC_AIRCON1_HS_MANUAL;
break;
}
sendPanasonicCKP(IR, operatingMode, fanSpeed, temperature, swingV, swingH);
delay(1000); // Sleep 1 second between the messages
// This will change the power state in one minute from now
sendPanasonicCKPOnOffTimerCancel(IR, powerMode, false);
/*
// Send the 'timer cancel' signal 2 minutes later
if (panasonicCancelTimer != 0)
{
timer.stop(panasonicCancelTimer);
panasonicCancelTimer = 0;
}
// Note that the argument to 'timer.after' has to be explicitly cast into 'long'
panasonicCancelTimer = timer.after(2L*60L*1000L, sendPanasonicCKPCancelTimer);
Serial.print(F("'Timer cancel' timer ID: "));
Serial.println(panasonicCancelTimer);
*/
}
// Send the Panasonic CKP code
void PanasonicCKPHeatpumpIR::sendPanasonicCKP(IRSender& IR, uint8_t operatingMode, uint8_t fanSpeed, uint8_t temperature, uint8_t swingV, uint8_t swingH)
{
uint8_t sendBuffer[4];
// Fan speed & temperature, temperature needs to be 27 in FAN mode
if (operatingMode == PANASONIC_AIRCON1_MODE_FAN || operatingMode == (PANASONIC_AIRCON1_MODE_FAN | PANASONIC_AIRCON1_MODE_KEEP ))
{
temperature = 27;
}
sendBuffer[0] = fanSpeed | (temperature - 15);
// Power toggle & operation mode
sendBuffer[1] = operatingMode;
// Swings
sendBuffer[2] = swingV | swingH;
// Always 0x36
sendBuffer[3] = 0x36;
// Send the code
sendPanasonicCKPraw(IR, sendBuffer);
}
// Send the Panasonic CKP raw code
void PanasonicCKPHeatpumpIR::sendPanasonicCKPraw(IRSender& IR, uint8_t sendBuffer[])
{
// 40 kHz PWM frequency
IR.setFrequency(38);
// Header, two first uint8_ts repeated
IR.mark(PANASONIC_AIRCON1_HDR_MARK);
IR.space(PANASONIC_AIRCON1_HDR_SPACE);
for (int i=0; i<2; i++) {
IR.sendIRbyte(sendBuffer[0], PANASONIC_AIRCON1_BIT_MARK, PANASONIC_AIRCON1_ZERO_SPACE, PANASONIC_AIRCON1_ONE_SPACE);
IR.sendIRbyte(sendBuffer[0], PANASONIC_AIRCON1_BIT_MARK, PANASONIC_AIRCON1_ZERO_SPACE, PANASONIC_AIRCON1_ONE_SPACE);
IR.sendIRbyte(sendBuffer[1], PANASONIC_AIRCON1_BIT_MARK, PANASONIC_AIRCON1_ZERO_SPACE, PANASONIC_AIRCON1_ONE_SPACE);
IR.sendIRbyte(sendBuffer[1], PANASONIC_AIRCON1_BIT_MARK, PANASONIC_AIRCON1_ZERO_SPACE, PANASONIC_AIRCON1_ONE_SPACE);
IR.mark(PANASONIC_AIRCON1_HDR_MARK);
IR.space(PANASONIC_AIRCON1_HDR_SPACE);
}
// Pause
IR.mark(PANASONIC_AIRCON1_BIT_MARK);
IR.space(PANASONIC_AIRCON1_MSG_SPACE);
// Header, two last uint8_ts repeated
IR.mark(PANASONIC_AIRCON1_HDR_MARK);
IR.space(PANASONIC_AIRCON1_HDR_SPACE);
for (int i=0; i<2; i++) {
IR.sendIRbyte(sendBuffer[2], PANASONIC_AIRCON1_BIT_MARK, PANASONIC_AIRCON1_ZERO_SPACE, PANASONIC_AIRCON1_ONE_SPACE);
IR.sendIRbyte(sendBuffer[2], PANASONIC_AIRCON1_BIT_MARK, PANASONIC_AIRCON1_ZERO_SPACE, PANASONIC_AIRCON1_ONE_SPACE);
IR.sendIRbyte(sendBuffer[3], PANASONIC_AIRCON1_BIT_MARK, PANASONIC_AIRCON1_ZERO_SPACE, PANASONIC_AIRCON1_ONE_SPACE);
IR.sendIRbyte(sendBuffer[3], PANASONIC_AIRCON1_BIT_MARK, PANASONIC_AIRCON1_ZERO_SPACE, PANASONIC_AIRCON1_ONE_SPACE);
IR.mark(PANASONIC_AIRCON1_HDR_MARK);
IR.space(PANASONIC_AIRCON1_HDR_SPACE);
}
IR.mark(PANASONIC_AIRCON1_BIT_MARK);
IR.space(0);
}
// Send the Panasonic CKP On/Off code
//
// CKP does not have discrete ON/OFF commands, but this can be emulated by using the timer
// The side-effects of using the timer are:
// * ONE minute delay before the power state changes
// * the 'TIMER' led (orange) is lit
// * a timer event is scheduled to cancel the timer after TWO minutes (the 'TIMER' led turns off
void PanasonicCKPHeatpumpIR::sendPanasonicCKPOnOffTimerCancel(IRSender& IR, boolean powerState, boolean cancelTimer)
{
static const uint8_t ON_msg[] PROGMEM = { 0x7F, 0x38, 0xBF, 0x38, 0x10, 0x3D, 0x80, 0x3D, 0x09, 0x34, 0x80, 0x34 }; // ON at 00:10, time now 00:09, no OFF timing
static const uint8_t OFF_msg[] PROGMEM = { 0x10, 0x38, 0x80, 0x38, 0x7F, 0x3D, 0xBF, 0x3D, 0x09, 0x34, 0x80, 0x34 }; // OFF at 00:10, time now 00:09, no ON timing
static const uint8_t CANCEL_msg[] PROGMEM = { 0x7F, 0x38, 0xBF, 0x38, 0x7F, 0x3D, 0xBF, 0x3D, 0x17, 0x34, 0x80, 0x34 }; // Timer CANCEL
// Save some SRAM by only having one copy of the template on the SRAM
uint8_t sendBuffer[sizeof(ON_msg)];
if ( cancelTimer == true ) {
memcpy_P(sendBuffer, CANCEL_msg, sizeof(ON_msg));
} else if ( powerState == true ) {
memcpy_P(sendBuffer, ON_msg, sizeof(ON_msg));
} else {
memcpy_P(sendBuffer, OFF_msg, sizeof(ON_msg));
}
// 40 kHz PWM frequency
IR.setFrequency(38);
for (int i=0; i<6; i++) {
IR.mark(PANASONIC_AIRCON1_HDR_MARK);
IR.space(PANASONIC_AIRCON1_HDR_SPACE);
IR.sendIRbyte(sendBuffer[i*2 + 0], PANASONIC_AIRCON1_BIT_MARK, PANASONIC_AIRCON1_ZERO_SPACE, PANASONIC_AIRCON1_ONE_SPACE);
IR.sendIRbyte(sendBuffer[i*2 + 0], PANASONIC_AIRCON1_BIT_MARK, PANASONIC_AIRCON1_ZERO_SPACE, PANASONIC_AIRCON1_ONE_SPACE);
IR.sendIRbyte(sendBuffer[i*2 + 1], PANASONIC_AIRCON1_BIT_MARK, PANASONIC_AIRCON1_ZERO_SPACE, PANASONIC_AIRCON1_ONE_SPACE);
IR.sendIRbyte(sendBuffer[i*2 + 1], PANASONIC_AIRCON1_BIT_MARK, PANASONIC_AIRCON1_ZERO_SPACE, PANASONIC_AIRCON1_ONE_SPACE);
IR.mark(PANASONIC_AIRCON1_HDR_MARK);
IR.space(PANASONIC_AIRCON1_HDR_SPACE);
if ( i < 5 ) {
IR.mark(PANASONIC_AIRCON1_BIT_MARK);
IR.space(PANASONIC_AIRCON1_MSG_SPACE);
}
}
IR.mark(PANASONIC_AIRCON1_BIT_MARK);
IR.space(0);
}
// Send the Panasonic CKP timer cancel
void PanasonicCKPHeatpumpIR::sendPanasonicCKPCancelTimer(IRSender& IR)
{
Serial.println(F("Sending Panasonic CKP timer cancel"));
sendPanasonicCKPOnOffTimerCancel(IR, false, true);
}