forked from crankyoldgit/IRremoteESP8266
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ir_Neoclima.cpp
585 lines (526 loc) · 21.3 KB
/
ir_Neoclima.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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
// Copyright 2019 David Conran
/// @file
/// @brief Support for Neoclima protocols.
/// Analysis by crankyoldgit & AndreyShpilevoy
/// Code by crankyoldgit
/// @see https://github.com/crankyoldgit/IRremoteESP8266/issues/764
/// @see https://drive.google.com/file/d/1kjYk4zS9NQcMQhFkak-L4mp4UuaAIesW/view
#include "ir_Neoclima.h"
#include <algorithm>
#include <cstring>
#include "IRrecv.h"
#include "IRsend.h"
#include "IRtext.h"
#include "IRutils.h"
// Constants
const uint16_t kNeoclimaHdrMark = 6112;
const uint16_t kNeoclimaHdrSpace = 7391;
const uint16_t kNeoclimaBitMark = 537;
const uint16_t kNeoclimaOneSpace = 1651;
const uint16_t kNeoclimaZeroSpace = 571;
const uint32_t kNeoclimaMinGap = kDefaultMessageGap;
using irutils::addBoolToString;
using irutils::addFanToString;
using irutils::addIntToString;
using irutils::addLabeledString;
using irutils::addModeToString;
using irutils::addTempToString;
using irutils::setBit;
using irutils::setBits;
#if SEND_NEOCLIMA
/// Send a Neoclima message.
/// Status: STABLE / Known to be working.
/// @param[in] data The message to be sent.
/// @param[in] nbytes The number of bytes of message to be sent.
/// @param[in] repeat The number of times the command is to be repeated.
void IRsend::sendNeoclima(const unsigned char data[], const uint16_t nbytes,
const uint16_t repeat) {
// Set IR carrier frequency
enableIROut(38);
for (uint16_t i = 0; i <= repeat; i++) {
sendGeneric(kNeoclimaHdrMark, kNeoclimaHdrSpace,
kNeoclimaBitMark, kNeoclimaOneSpace,
kNeoclimaBitMark, kNeoclimaZeroSpace,
kNeoclimaBitMark, kNeoclimaHdrSpace,
data, nbytes, 38000, false, 0, // Repeats are already handled.
50);
// Extra footer.
mark(kNeoclimaBitMark);
space(kNeoclimaMinGap);
}
}
#endif // SEND_NEOCLIMA
/// Class constructor
/// @param[in] pin GPIO to be used when sending.
/// @param[in] inverted Is the output signal to be inverted?
/// @param[in] use_modulation Is frequency modulation to be used?
IRNeoclimaAc::IRNeoclimaAc(const uint16_t pin, const bool inverted,
const bool use_modulation)
: _irsend(pin, inverted, use_modulation) {
this->stateReset();
}
/// Reset the state of the remote to a known good state/sequence.
void IRNeoclimaAc::stateReset(void) {
static const uint8_t kReset[kNeoclimaStateLength] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6A, 0x00, 0x2A, 0xA5};
setRaw(kReset);
}
/// Set up hardware to be able to send a message.
void IRNeoclimaAc::begin(void) { _irsend.begin(); }
/// Calculate the checksum for a given state.
/// @param[in] state The array to calc the checksum of.
/// @param[in] length The length/size of the array.
/// @return The calculated checksum value.
uint8_t IRNeoclimaAc::calcChecksum(const uint8_t state[],
const uint16_t length) {
if (length == 0) return state[0];
return sumBytes(state, length - 1);
}
/// Verify the checksum is valid for a given state.
/// @param[in] state The array to verify the checksum of.
/// @param[in] length The length/size of the array.
/// @return true, if the state has a valid checksum. Otherwise, false.
bool IRNeoclimaAc::validChecksum(const uint8_t state[], const uint16_t length) {
if (length < 2)
return true; // No checksum to compare with. Assume okay.
return (state[length - 1] == calcChecksum(state, length));
}
/// Calculate & update the checksum for the internal state.
/// @param[in] length The length/size of the internal state.
void IRNeoclimaAc::checksum(uint16_t length) {
if (length < 2) return;
remote_state[length - 1] = calcChecksum(remote_state, length);
}
#if SEND_NEOCLIMA
/// Send the current internal state as an IR message.
/// @param[in] repeat Nr. of times the message will be repeated.
void IRNeoclimaAc::send(const uint16_t repeat) {
_irsend.sendNeoclima(getRaw(), kNeoclimaStateLength, repeat);
}
#endif // SEND_NEOCLIMA
/// Get a PTR to the internal state/code for this protocol.
/// @return PTR to a code for this protocol based on the current internal state.
uint8_t *IRNeoclimaAc::getRaw(void) {
this->checksum();
return remote_state;
}
/// Set the internal state from a valid code for this protocol.
/// @param[in] new_code A valid code for this protocol.
/// @param[in] length The length/size of the new_code array.
void IRNeoclimaAc::setRaw(const uint8_t new_code[], const uint16_t length) {
memcpy(remote_state, new_code, std::min(length, kNeoclimaStateLength));
}
/// Set the Button/Command pressed setting of the A/C.
/// @param[in] button The value of the button/command that was pressed.
void IRNeoclimaAc::setButton(const uint8_t button) {
switch (button) {
case kNeoclimaButtonPower:
case kNeoclimaButtonMode:
case kNeoclimaButtonTempUp:
case kNeoclimaButtonTempDown:
case kNeoclimaButtonSwing:
case kNeoclimaButtonFanSpeed:
case kNeoclimaButtonAirFlow:
case kNeoclimaButtonHold:
case kNeoclimaButtonSleep:
case kNeoclimaButtonLight:
case kNeoclimaButtonEye:
case kNeoclimaButtonFollow:
case kNeoclimaButtonIon:
case kNeoclimaButtonFresh:
case kNeoclimaButton8CHeat:
case kNeoclimaButtonTurbo:
setBits(&remote_state[5], kNeoclimaButtonOffset, kNeoclimaButtonSize,
button);
break;
default:
this->setButton(kNeoclimaButtonPower);
}
}
/// Get the Button/Command setting of the A/C.
/// @return The value of the button/command that was pressed.
uint8_t IRNeoclimaAc::getButton(void) {
return GETBITS8(remote_state[5], kNeoclimaButtonOffset, kNeoclimaButtonSize);
}
/// Set the requested power state of the A/C to on.
void IRNeoclimaAc::on(void) { this->setPower(true); }
/// Set the requested power state of the A/C to off.
void IRNeoclimaAc::off(void) { this->setPower(false); }
/// Change the power setting.
/// @param[in] on true, the setting is on. false, the setting is off.
void IRNeoclimaAc::setPower(const bool on) {
this->setButton(kNeoclimaButtonPower);
setBit(&remote_state[7], kNeoclimaPowerOffset, on);
}
/// Get the value of the current power setting.
/// @return true, the setting is on. false, the setting is off.
bool IRNeoclimaAc::getPower(void) {
return GETBIT8(remote_state[7], kNeoclimaPowerOffset);
}
/// Set the operating mode of the A/C.
/// @param[in] mode The desired operating mode.
void IRNeoclimaAc::setMode(const uint8_t mode) {
switch (mode) {
case kNeoclimaDry:
// In this mode fan speed always LOW
this->setFan(kNeoclimaFanLow);
// FALL THRU
case kNeoclimaAuto:
case kNeoclimaCool:
case kNeoclimaFan:
case kNeoclimaHeat:
setBits(&remote_state[9], kNeoclimaModeOffset, kModeBitsSize, mode);
this->setButton(kNeoclimaButtonMode);
break;
default:
// If we get an unexpected mode, default to AUTO.
this->setMode(kNeoclimaAuto);
}
}
/// Get the operating mode setting of the A/C.
/// @return The current operating mode setting.
uint8_t IRNeoclimaAc::getMode(void) {
return GETBITS8(remote_state[9], kNeoclimaModeOffset, kModeBitsSize);
}
/// Convert a stdAc::opmode_t enum into its native mode.
/// @param[in] mode The enum to be converted.
/// @return The native equivilant of the enum.
uint8_t IRNeoclimaAc::convertMode(const stdAc::opmode_t mode) {
switch (mode) {
case stdAc::opmode_t::kCool: return kNeoclimaCool;
case stdAc::opmode_t::kHeat: return kNeoclimaHeat;
case stdAc::opmode_t::kDry: return kNeoclimaDry;
case stdAc::opmode_t::kFan: return kNeoclimaFan;
default: return kNeoclimaAuto;
}
}
/// Convert a native mode into its stdAc equivilant.
/// @param[in] mode The native setting to be converted.
/// @return The stdAc equivilant of the native setting.
stdAc::opmode_t IRNeoclimaAc::toCommonMode(const uint8_t mode) {
switch (mode) {
case kNeoclimaCool: return stdAc::opmode_t::kCool;
case kNeoclimaHeat: return stdAc::opmode_t::kHeat;
case kNeoclimaDry: return stdAc::opmode_t::kDry;
case kNeoclimaFan: return stdAc::opmode_t::kFan;
default: return stdAc::opmode_t::kAuto;
}
}
/// Set the temperature.
/// @param[in] temp The temperature in degrees celsius.
void IRNeoclimaAc::setTemp(const uint8_t temp) {
uint8_t oldtemp = this->getTemp();
uint8_t newtemp = std::max(kNeoclimaMinTemp, temp);
newtemp = std::min(kNeoclimaMaxTemp, newtemp);
if (oldtemp > newtemp)
this->setButton(kNeoclimaButtonTempDown);
else if (newtemp > oldtemp)
this->setButton(kNeoclimaButtonTempUp);
setBits(&remote_state[9], kNeoclimaTempOffset, kNeoclimaTempSize,
newtemp - kNeoclimaMinTemp);
}
/// Get the current temperature setting.
/// @return The current setting for temp. in degrees celsius.
uint8_t IRNeoclimaAc::getTemp(void) {
return GETBITS8(remote_state[9], kNeoclimaTempOffset, kNeoclimaTempSize) +
kNeoclimaMinTemp;
}
/// Set the speed of the fan.
/// @param[in] speed The desired setting. 0-3, 0 is auto, 1-3 is the speed
void IRNeoclimaAc::setFan(const uint8_t speed) {
switch (speed) {
case kNeoclimaFanAuto:
case kNeoclimaFanHigh:
case kNeoclimaFanMed:
if (this->getMode() == kNeoclimaDry) { // Dry mode only allows low speed.
this->setFan(kNeoclimaFanLow);
return;
}
// FALL-THRU
case kNeoclimaFanLow:
setBits(&remote_state[7], kNeoclimaFanOffest, kNeoclimaFanSize, speed);
this->setButton(kNeoclimaButtonFanSpeed);
break;
default:
// If we get an unexpected speed, default to Auto.
this->setFan(kNeoclimaFanAuto);
}
}
/// Get the current fan speed setting.
/// @return The current fan speed/mode.
uint8_t IRNeoclimaAc::getFan(void) {
return GETBITS8(remote_state[7], kNeoclimaFanOffest, kNeoclimaFanSize);
}
/// Convert a stdAc::fanspeed_t enum into it's native speed.
/// @param[in] speed The enum to be converted.
/// @return The native equivilant of the enum.
uint8_t IRNeoclimaAc::convertFan(const stdAc::fanspeed_t speed) {
switch (speed) {
case stdAc::fanspeed_t::kMin:
case stdAc::fanspeed_t::kLow: return kNeoclimaFanLow;
case stdAc::fanspeed_t::kMedium: return kNeoclimaFanMed;
case stdAc::fanspeed_t::kHigh:
case stdAc::fanspeed_t::kMax: return kNeoclimaFanHigh;
default: return kNeoclimaFanAuto;
}
}
/// Convert a native fan speed into its stdAc equivilant.
/// @param[in] speed The native setting to be converted.
/// @return The stdAc equivilant of the native setting.
stdAc::fanspeed_t IRNeoclimaAc::toCommonFanSpeed(const uint8_t speed) {
switch (speed) {
case kNeoclimaFanHigh: return stdAc::fanspeed_t::kMax;
case kNeoclimaFanMed: return stdAc::fanspeed_t::kMedium;
case kNeoclimaFanLow: return stdAc::fanspeed_t::kMin;
default: return stdAc::fanspeed_t::kAuto;
}
}
/// Set the Sleep setting of the A/C.
/// @param[in] on true, the setting is on. false, the setting is off.
void IRNeoclimaAc::setSleep(const bool on) {
this->setButton(kNeoclimaButtonSleep);
setBit(&remote_state[7], kNeoclimaSleepOffset, on);
}
/// Get the Sleep setting of the A/C.
/// @return true, the setting is on. false, the setting is off.
bool IRNeoclimaAc::getSleep(void) {
return GETBIT8(remote_state[7], kNeoclimaSleepOffset);
}
/// Set the vertical swing setting of the A/C.
/// @param[in] on true, the setting is on. false, the setting is off.
void IRNeoclimaAc::setSwingV(const bool on) {
this->setButton(kNeoclimaButtonSwing);
setBits(&remote_state[7], kNeoclimaSwingVOffset, kNeoclimaSwingVSize,
on ? kNeoclimaSwingVOn : kNeoclimaSwingVOff);
}
/// Get the vertical swing setting of the A/C.
/// @return true, the setting is on. false, the setting is off.
bool IRNeoclimaAc::getSwingV(void) {
return GETBITS8(remote_state[7], kNeoclimaSwingVOffset,
kNeoclimaSwingVSize) == kNeoclimaSwingVOn;
}
/// Set the horizontal swing setting of the A/C.
/// @param[in] on true, the setting is on. false, the setting is off.
void IRNeoclimaAc::setSwingH(const bool on) {
this->setButton(kNeoclimaButtonAirFlow);
setBit(&remote_state[7], kNeoclimaSwingHOffset, !on); // Cleared when `on`
}
/// Get the horizontal swing (Air Flow) setting of the A/C.
/// @return true, the setting is on. false, the setting is off.
bool IRNeoclimaAc::getSwingH(void) {
return !GETBIT8(remote_state[7], kNeoclimaSwingHOffset);
}
/// Set the Turbo setting of the A/C.
/// @param[in] on true, the setting is on. false, the setting is off.
void IRNeoclimaAc::setTurbo(const bool on) {
this->setButton(kNeoclimaButtonTurbo);
setBit(&remote_state[3], kNeoclimaTurboOffset, on);
}
/// Get the Turbo setting of the A/C.
/// @return true, the setting is on. false, the setting is off.
bool IRNeoclimaAc::getTurbo(void) {
return GETBIT8(remote_state[3], kNeoclimaTurboOffset);
}
/// Set the Fresh (air) setting of the A/C.
/// @param[in] on true, the setting is on. false, the setting is off.
void IRNeoclimaAc::setFresh(const bool on) {
this->setButton(kNeoclimaButtonFresh);
setBit(&remote_state[5], kNeoclimaFreshOffset, on);
}
/// Get the Frsh (air) setting of the A/C.
/// @return true, the setting is on. false, the setting is off.
bool IRNeoclimaAc::getFresh(void) {
return GETBIT8(remote_state[5], kNeoclimaFreshOffset);
}
/// Set the Hold setting of the A/C.
/// @param[in] on true, the setting is on. false, the setting is off.
void IRNeoclimaAc::setHold(const bool on) {
this->setButton(kNeoclimaButtonHold);
setBit(&remote_state[3], kNeoclimaHoldOffset, on);
}
/// Get the Hold setting of the A/C.
/// @return true, the setting is on. false, the setting is off.
bool IRNeoclimaAc::getHold(void) {
return GETBIT8(remote_state[3], kNeoclimaHoldOffset);
}
/// Set the Ion (filter) setting of the A/C.
/// @param[in] on true, the setting is on. false, the setting is off.
void IRNeoclimaAc::setIon(const bool on) {
this->setButton(kNeoclimaButtonIon);
setBit(&remote_state[1], kNeoclimaIonOffset, on);
}
/// Get the Ion (filter) setting of the A/C.
/// @return true, the setting is on. false, the setting is off.
bool IRNeoclimaAc::getIon(void) {
return GETBIT8(remote_state[1], kNeoclimaIonOffset);
}
/// Set the Light(LED display) setting of the A/C.
/// @param[in] on true, the setting is on. false, the setting is off.
void IRNeoclimaAc::setLight(const bool on) {
this->setButton(kNeoclimaButtonLight);
setBit(&remote_state[3], kNeoclimaLightOffset, on);
}
/// Get the Light (LED display) setting of the A/C.
/// @return true, the setting is on. false, the setting is off.
bool IRNeoclimaAc::getLight(void) {
return GETBIT8(remote_state[3], kNeoclimaLightOffset);
}
/// Set the 8°C Heat setting of the A/C.
/// @param[in] on true, the setting is on. false, the setting is off.
/// @note This feature maintains the room temperature steadily at 8°C and
/// prevents the room from freezing by activating the heating operation
/// automatically when nobody is at home over a longer period during severe
/// winter.
void IRNeoclimaAc::set8CHeat(const bool on) {
this->setButton(kNeoclimaButton8CHeat);
setBit(&remote_state[1], kNeoclima8CHeatOffset, on);
}
/// Get the 8°C Heat setting of the A/C.
/// @return true, the setting is on. false, the setting is off.
bool IRNeoclimaAc::get8CHeat(void) {
return GETBIT8(remote_state[1], kNeoclima8CHeatOffset);
}
/// Set the Eye (Sensor) setting of the A/C.
/// @param[in] on true, the setting is on. false, the setting is off.
void IRNeoclimaAc::setEye(const bool on) {
this->setButton(kNeoclimaButtonEye);
setBit(&remote_state[3], kNeoclimaEyeOffset, on);
}
/// Get the Eye (Sensor) setting of the A/C.
/// @return true, the setting is on. false, the setting is off.
bool IRNeoclimaAc::getEye(void) {
return GETBIT8(remote_state[3], kNeoclimaEyeOffset);
}
/* DISABLED
TODO(someone): Work out why "on" is either 0x5D or 0x5F
void IRNeoclimaAc::setFollow(const bool on) {
this->setButton(kNeoclimaButtonFollow);
if (on)
remote_state[8] = kNeoclimaFollowMe;
else
remote_state[8] = 0;
}
*/
/// Get the Follow Me setting of the A/C.
/// @return true, the setting is on. false, the setting is off.
bool IRNeoclimaAc::getFollow(void) {
return (remote_state[8] & kNeoclimaFollowMe) == kNeoclimaFollowMe;
}
/// Convert the current internal state into its stdAc::state_t equivilant.
/// @return The stdAc equivilant of the native settings.
stdAc::state_t IRNeoclimaAc::toCommon(void) {
stdAc::state_t result;
result.protocol = decode_type_t::NEOCLIMA;
result.model = -1; // No models used.
result.power = this->getPower();
result.mode = this->toCommonMode(this->getMode());
result.celsius = true;
result.degrees = this->getTemp();
result.fanspeed = this->toCommonFanSpeed(this->getFan());
result.swingv = this->getSwingV() ? stdAc::swingv_t::kAuto
: stdAc::swingv_t::kOff;
result.swingh = this->getSwingH() ? stdAc::swingh_t::kAuto
: stdAc::swingh_t::kOff;
result.turbo = this->getTurbo();
result.light = this->getLight();
result.filter = this->getIon();
result.sleep = this->getSleep() ? 0 : -1;
// Not supported.
result.quiet = false;
result.econo = false;
result.clean = false;
result.beep = false;
result.clock = -1;
return result;
}
/// Convert the current internal state into a human readable string.
/// @return A human readable string.
String IRNeoclimaAc::toString(void) {
String result = "";
result.reserve(100); // Reserve some heap for the string to reduce fragging.
result += addBoolToString(getPower(), kPowerStr, false);
result += addModeToString(getMode(), kNeoclimaAuto, kNeoclimaCool,
kNeoclimaHeat, kNeoclimaDry, kNeoclimaFan);
result += addTempToString(getTemp());
result += addFanToString(getFan(), kNeoclimaFanHigh, kNeoclimaFanLow,
kNeoclimaFanAuto, kNeoclimaFanAuto, kNeoclimaFanMed);
result += addBoolToString(getSwingV(), kSwingVStr);
result += addBoolToString(getSwingH(), kSwingHStr);
result += addBoolToString(getSleep(), kSleepStr);
result += addBoolToString(getTurbo(), kTurboStr);
result += addBoolToString(getHold(), kHoldStr);
result += addBoolToString(getIon(), kIonStr);
result += addBoolToString(getEye(), kEyeStr);
result += addBoolToString(getLight(), kLightStr);
result += addBoolToString(getFollow(), kFollowStr);
result += addBoolToString(get8CHeat(), k8CHeatStr);
result += addBoolToString(getFresh(), kFreshStr);
result += addIntToString(getButton(), kButtonStr);
result += kSpaceLBraceStr;
switch (this->getButton()) {
case kNeoclimaButtonPower: result += kPowerStr; break;
case kNeoclimaButtonMode: result += kModeStr; break;
case kNeoclimaButtonTempUp: result += kTempUpStr; break;
case kNeoclimaButtonTempDown: result += kTempDownStr; break;
case kNeoclimaButtonSwing: result += kSwingStr; break;
case kNeoclimaButtonFanSpeed: result += kFanStr; break;
case kNeoclimaButtonAirFlow: result += kAirFlowStr; break;
case kNeoclimaButtonHold: result += kHoldStr; break;
case kNeoclimaButtonSleep: result += kSleepStr; break;
case kNeoclimaButtonLight: result += kLightStr; break;
case kNeoclimaButtonEye: result += kEyeStr; break;
case kNeoclimaButtonFollow: result += kFollowStr; break;
case kNeoclimaButtonIon: result += kIonStr; break;
case kNeoclimaButtonFresh: result += kFreshStr; break;
case kNeoclimaButton8CHeat: result += k8CHeatStr; break;
case kNeoclimaButtonTurbo: result += kTurboStr; break;
default:
result += kUnknownStr;
}
result += ')';
return result;
}
#if DECODE_NEOCLIMA
/// Decode the supplied Neoclima message.
/// Status: STABLE / Known working
/// @param[in,out] results Ptr to the data to decode & where to store the result
/// @param[in] offset The starting index to use when attempting to decode the
/// raw data. Typically/Defaults to kStartOffset.
/// @param[in] nbits The number of data bits to expect.
/// @param[in] strict Flag indicating if we should perform strict matching.
/// @return True if it can decode it, false if it can't.
bool IRrecv::decodeNeoclima(decode_results *results, uint16_t offset,
const uint16_t nbits, const bool strict) {
// Compliance
if (strict && nbits != kNeoclimaBits)
return false; // Incorrect nr. of bits per spec.
// Match Main Header + Data + Footer
uint16_t used;
used = matchGeneric(results->rawbuf + offset, results->state,
results->rawlen - offset, nbits,
kNeoclimaHdrMark, kNeoclimaHdrSpace,
kNeoclimaBitMark, kNeoclimaOneSpace,
kNeoclimaBitMark, kNeoclimaZeroSpace,
kNeoclimaBitMark, kNeoclimaHdrSpace, false,
_tolerance, 0, false);
if (!used) return false;
offset += used;
// Extra footer.
uint64_t unused;
if (!matchGeneric(results->rawbuf + offset, &unused,
results->rawlen - offset, 0, 0, 0, 0, 0, 0, 0,
kNeoclimaBitMark, kNeoclimaHdrSpace, true)) return false;
// Compliance
if (strict) {
// Check we got a valid checksum.
if (!IRNeoclimaAc::validChecksum(results->state, nbits / 8)) return false;
}
// Success
results->decode_type = decode_type_t::NEOCLIMA;
results->bits = nbits;
// No need to record the state as we stored it as we decoded it.
// As we use result->state, we don't record value, address, or command as it
// is a union data type.
return true;
}
#endif // DECODE_NEOCLIMA