-
Notifications
You must be signed in to change notification settings - Fork 838
/
Copy pathir_Argo.cpp
1822 lines (1642 loc) · 66.9 KB
/
ir_Argo.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
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2017 Schmolders
// Copyright 2019 crankyoldgit
// Copyright 2022 Mateusz Bronk (mbronk)
/// @file
/// @brief Argo A/C protocol.
/// @see https://github.com/crankyoldgit/IRremoteESP8266/issues/1859
/// @see https://github.com/crankyoldgit/IRremoteESP8266/issues/1912
#include "ir_Argo.h"
#include <algorithm>
#include <cmath>
#include <cstring>
#ifndef UNIT_TEST
#include <Arduino.h>
#endif // UNIT_TEST
#include "IRremoteESP8266.h"
#include "IRtext.h"
#include "IRutils.h"
// Constants
// using SPACE modulation. MARK is always const 400u
const uint16_t kArgoHdrMark = 6400;
const uint16_t kArgoHdrSpace = 3300;
const uint16_t kArgoBitMark = 400;
const uint16_t kArgoOneSpace = 2200;
const uint16_t kArgoZeroSpace = 900;
const uint32_t kArgoGap = kDefaultMessageGap; // Made up value. Complete guess.
const uint8_t kArgoSensorCheck = 52; // Part of the sensor message check calc.
const uint8_t kArgoSensorFixed = 0b011;
const uint8_t kArgoWrem3Preamble = 0b1011;
const uint8_t kArgoWrem3Postfix_Timer = 0b1;
const uint8_t kArgoWrem3Postfix_ACControl = 0b110000;
using irutils::addBoolToString;
using irutils::addIntToString;
using irutils::addLabeledString;
using irutils::addModeToString;
using irutils::addTempToString;
using irutils::addFanToString;
using irutils::addSwingVToString;
using irutils::minsToString;
using irutils::addDayToString;
using irutils::addModelToString;
using irutils::daysBitmaskToString;
using irutils::addTimerModeToString;
#if SEND_ARGO
/// Send a Argo A/C formatted message.
/// Status: [WREM-2] BETA / Probably works.
/// [WREM-3] Confirmed working w/ Argo 13 ECO (WREM-3)
/// @note The "no footer" part needs re-checking for validity but retained for
/// backwards compatibility.
/// Consider using @c sendFooter=true code for WREM-2 as well
/// @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.
/// @param[in] sendFooter Whether to send footer and add a final gap.
/// *REQUIRED* for WREM-3, UNKNOWN for WREM-2 (used to be
/// disabled in previous impl., hence retained)
/// @note Consider removing this param (default to true) if WREM-2 works w/ it
void IRsend::sendArgo(const unsigned char data[], const uint16_t nbytes,
const uint16_t repeat, bool sendFooter /*= false*/) {
if (nbytes < std::min({kArgo3AcControlStateLength,
kArgo3ConfigStateLength,
kArgo3iFeelReportStateLength,
kArgo3TimerStateLength,
kArgoStateLength,
kArgoShortStateLength})) {
return; // Not enough bytes to send a proper message.
}
const uint16_t _footermark = (sendFooter)? kArgoBitMark : 0;
const uint32_t _gap = (sendFooter)? kArgoGap : 0;
sendGeneric(kArgoHdrMark, kArgoHdrSpace, kArgoBitMark, kArgoOneSpace,
kArgoBitMark, kArgoZeroSpace,
_footermark, _gap,
data, nbytes, kArgoFrequency, false, repeat, kDutyDefault);
}
/// Send a Argo A/C formatted message.
/// Status: Confirmed working w/ Argo 13 ECO (WREM-3)
/// @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::sendArgoWREM3(const unsigned char data[], const uint16_t nbytes,
const uint16_t repeat) {
sendArgo(data, nbytes, repeat, true);
}
#endif // SEND_ARGO
/// 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?
template <typename T>
IRArgoACBase<T>::IRArgoACBase(const uint16_t pin, const bool inverted,
const bool use_modulation)
: _irsend(pin, inverted, use_modulation) { stateReset(); }
/// 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?
IRArgoAC::IRArgoAC(const uint16_t pin, const bool inverted,
const bool use_modulation)
: IRArgoACBase<ArgoProtocol>(pin, inverted, use_modulation) { }
/// 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?
IRArgoAC_WREM3::IRArgoAC_WREM3(const uint16_t pin, const bool inverted,
const bool use_modulation)
: IRArgoACBase<ArgoProtocolWREM3>(pin, inverted, use_modulation) {}
/// Set up hardware to be able to send a message.
template<typename T>
void IRArgoACBase<T>::begin(void) { _irsend.begin(); }
/// @cond
/// @brief Get byte length of raw WREM-2 message based on IR cmd type
/// @note This is a full specialization for @c ArgoProtocol type and while
/// it semantically belongs to @c IrArgoAC class impl., it has *not*
/// been pushed there, to avoid having to use a virtual function
/// @param type The type of IR command
/// @note Not all types are supported. AC_CONTROL and TIMER are the same cmd
/// @return Byte length of state command
/// @relates IRArgoACBase\<ARGO_PROTOCOL_T\>
template<>
uint16_t IRArgoACBase<ArgoProtocol>::getStateLengthForIrMsgType(
argoIrMessageType_t type) {
switch (type) {
case argoIrMessageType_t::AC_CONTROL:
case argoIrMessageType_t::TIMER_COMMAND:
return kArgoStateLength;
case argoIrMessageType_t::IFEEL_TEMP_REPORT:
return kArgoShortStateLength;
case argoIrMessageType_t::CONFIG_PARAM_SET:
default:
return 0; // Not supported by WREM-2
}
}
/// @endcond
/// @brief Get byte length of raw WREM-3 message based on IR cmd type
/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while
/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not*
/// been pushed there, to avoid having to use a virtual function
/// @param type The type of IR command
/// @return Byte length of state command
/// @relates IRArgoACBase\<ARGO_PROTOCOL_T\>
template<>
uint16_t IRArgoACBase<ArgoProtocolWREM3>::getStateLengthForIrMsgType(
argoIrMessageType_t type) {
switch (type) {
case argoIrMessageType_t::AC_CONTROL:
return kArgo3AcControlStateLength;
case argoIrMessageType_t::IFEEL_TEMP_REPORT:
return kArgo3iFeelReportStateLength;
case argoIrMessageType_t::TIMER_COMMAND:
return kArgo3TimerStateLength;
case argoIrMessageType_t::CONFIG_PARAM_SET:
return kArgo3ConfigStateLength;
default:
return 0;
}
}
/// @cond
/// @brief Get message type from raw WREM-2 data
/// 1st param ignored: WREM-2 does not carry type in payload, allegedly
/// @param length Message length: used for *heuristic* detection of message type
/// @return IR message type
/// @note This is a full specialization for @c ArgoProtocol type and while
/// it semantically belongs to @c IrArgoAC class impl., it has *not*
/// been pushed there, to avoid having to use a virtual function
/// @relates IRArgoACBase\<ARGO_PROTOCOL_T\>
template<>
argoIrMessageType_t IRArgoACBase<ArgoProtocol>::getMessageType(
const uint8_t[], const uint16_t length) {
if (length == kArgoShortStateLength) {
return argoIrMessageType_t::IFEEL_TEMP_REPORT;
}
return argoIrMessageType_t::AC_CONTROL;
}
/// @endcond
/// @brief Get message type from raw WREM-3 data
/// @param state The raw IR data
/// @param length Length of @c state (in byte)
/// @return IR message type
/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while
/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not*
/// been pushed there, to avoid having to use a virtual function
/// @relates IRArgoACBase\<ARGO_PROTOCOL_T\>
template<>
argoIrMessageType_t IRArgoACBase<ArgoProtocolWREM3>::getMessageType(
const uint8_t state[], const uint16_t length) {
if (length < 1) {
return static_cast<argoIrMessageType_t>(-1);
}
return static_cast<argoIrMessageType_t>(state[0] >> 6);
}
/// @brief Get message type from raw WREM-3 data
/// @param raw Raw data
/// @return IR message type
argoIrMessageType_t IRArgoAC_WREM3::getMessageType(
const ArgoProtocolWREM3& raw) {
return static_cast<argoIrMessageType_t>(raw.IrCommandType);
}
/// @brief Get actual raw state byte length for the current state
/// _param 1st param ignored: WREM-2 does not caryy type in payload, allegedly
/// @param messageType Type of message the state is carrying
/// @return Actual length of state (in bytes)
/// @note This is a full specialization for @c ArgoProtocol type and while
/// it semantically belongs to @c IrArgoAC class impl., it has *not*
/// been pushed there, to avoid having to use a virtual function
/// @relates IRArgoACBase\<ARGO_PROTOCOL_T\>
template<>
uint16_t IRArgoACBase<ArgoProtocol>::getRawByteLength(const ArgoProtocol&,
argoIrMessageType_t messageType) {
if (messageType == argoIrMessageType_t::IFEEL_TEMP_REPORT) {
return kArgoShortStateLength;
}
return kArgoStateLength;
}
/// @brief Get actual raw state byte length for the current state
/// @param raw The raw state
/// _param 2nd param ignored (1st byte of @c raw is sufficient to get len)
/// @return Actual length of state (in bytes)
/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while
/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not*
/// been pushed there, to avoid having to use a virtual function
/// @relates IRArgoACBase\<ARGO_PROTOCOL_T\>
template<>
uint16_t IRArgoACBase<ArgoProtocolWREM3>::getRawByteLength(
const ArgoProtocolWREM3& raw, argoIrMessageType_t) {
return IRArgoAC_WREM3::getStateLengthForIrMsgType(
IRArgoAC_WREM3::getMessageType(raw));
}
/// @brief Get actual raw state byte length for the current state
/// @return Actual length of state (in bytes)
template<typename T>
uint16_t IRArgoACBase<T>::getRawByteLength() const {
return getRawByteLength(_, _messageType);
}
/// @cond
/// Calculate the checksum for a given state (WREM-2).
/// @note This is a full specialization for @c ArgoProtocol type and while
/// it semantically belongs to @c IrArgoAC class impl., it has *not*
/// been pushed there, to avoid having to use a virtual function
/// @warning This does NOT calculate 'short' (iFeel) message checksums
/// @param[in] state The array to calculate the checksum for.
/// @param[in] length The size of the state.
/// @return The 8-bit calculated result.
/// @relates IRArgoACBase\<ARGO_PROTOCOL_T\>
template<>
uint8_t IRArgoACBase<ArgoProtocol>::calcChecksum(const uint8_t state[],
const uint16_t length) {
// Corresponds to byte 11 being constant 0b01
// Only add up bytes to 9. byte 10 is 0b01 constant anyway.
// Assume that argo array is MSB first (left)
return sumBytes(state, length - 2, 2);
}
/// @endcond
/// Calculate the checksum for a given state (WREM-3).
/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while
/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not*
/// been pushed there, to avoid having to use a virtual function
/// @param[in] state The array to calculate the checksum for.
/// @param[in] length The size of the state.
/// @return The 8-bit calculated result.
/// @relates IRArgoACBase\<ARGO_PROTOCOL_T\>
template<>
uint8_t IRArgoACBase<ArgoProtocolWREM3>::calcChecksum(const uint8_t state[],
const uint16_t length) {
if (length < 1) {
return -1; // Nothing to compute on
}
uint16_t payloadSizeBits = (length - 1) * 8; // Last byte carries checksum
argoIrMessageType_t msgType = getMessageType(state, length);
if (msgType == argoIrMessageType_t::IFEEL_TEMP_REPORT) {
payloadSizeBits += 5; // For WREM3::iFeel the checksum is 3-bit
} else if (msgType == argoIrMessageType_t::TIMER_COMMAND) {
payloadSizeBits += 3; // For WREM3::Timer the checksum is 5-bit
} // Otherwise: full 8-bit checksum
uint8_t checksum = sumBytes(state, payloadSizeBits / 8, 0);
// Add stray bits from last byte to the checksum (if any)
const uint8_t maskPayload = 0xFF >> (8 - (payloadSizeBits % 8));
checksum += (state[length-1] & maskPayload);
const uint8_t maskChecksum = 0xFF >> (payloadSizeBits % 8);
return checksum & maskChecksum;
}
/// Update the checksum for a given state (WREM2).
/// @note This is a full specialization for @c ArgoProtocol type and while
/// it semantically belongs to @c IrArgoAC class impl., it has *not*
/// been pushed there, to avoid having to use a virtual function
/// @warning This impl does not support short message format (iFeel)
/// @param[in,out] state Pointer to a binary representation of the A/C state.
/// @relates IRArgoACBase\<ARGO_PROTOCOL_T\>
template<>
void IRArgoACBase<ArgoProtocol>::_checksum(ArgoProtocol *state) {
uint8_t sum = calcChecksum(state->raw, kArgoStateLength);
// Append sum to end of array
// Set const part of checksum bit 10
state->Post = kArgoPost;
state->Sum = sum;
}
/// @brief Update the checksum for a given state (WREM3).
/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while
/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not*
/// been pushed there, to avoid having to use a virtual function
/// @param[in,out] state Pointer to a binary representation of the A/C state.
/// @relates IRArgoACBase\<ARGO_PROTOCOL_T\>
template<>
void IRArgoACBase<ArgoProtocolWREM3>::_checksum(ArgoProtocolWREM3 *state) {
argoIrMessageType_t msgType = IRArgoAC_WREM3::getMessageType(*state);
uint8_t sum = calcChecksum(state->raw, getRawByteLength(*state));
switch (msgType) {
case argoIrMessageType_t::IFEEL_TEMP_REPORT:
state->CheckHi = sum;
break;
case argoIrMessageType_t::TIMER_COMMAND:
state->timer.Checksum = sum;
break;
case argoIrMessageType_t::CONFIG_PARAM_SET:
state->config.Checksum = sum;
break;
case argoIrMessageType_t::AC_CONTROL:
default:
state->Sum = sum;
break;
}
}
/// Update the checksum for the internal state.
template<typename T>
void IRArgoACBase<T>::checksum(void) { _checksum(&_); }
/// Reset the given state to a known good state.
/// @note This is a full specialization for @c ArgoProtocol type and while
/// it semantically belongs to @c IrArgoAC class impl., it has *not*
/// been pushed there, to avoid having to use a virtual function
/// @param[in,out] state Pointer to a binary representation of the A/C state.
/// _param 2nd param unused (always resets to AC_CONTROL state)
/// @relates IRArgoACBase\<ARGO_PROTOCOL_T\>
template<>
void IRArgoACBase<ArgoProtocol>::_stateReset(ArgoProtocol *state,
argoIrMessageType_t) {
for (uint8_t i = 2; i < kArgoStateLength; i++) state->raw[i] = 0x0;
state->Pre1 = kArgoPreamble1; // LSB first (as sent) 0b00110101;
state->Pre2 = kArgoPreamble2; // LSB first: 0b10101111;
state->Post = kArgoPost;
}
/// Reset the given state to a known good state
/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while
/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not*
/// been pushed there, to avoid having to use a virtual function
/// @param[in,out] state Pointer to a binary representation of the A/C state.
/// @param messageType Type of message to reset the state for
/// @relates IRArgoACBase\<ARGO_PROTOCOL_T\>
template<>
void IRArgoACBase<ArgoProtocolWREM3>::_stateReset(ArgoProtocolWREM3 *state,
argoIrMessageType_t messageType) {
for (uint8_t i = 1; i < sizeof(state->raw) / sizeof(state->raw[0]); i++) {
state->raw[i] = 0x0;
}
state->Pre1 = kArgoWrem3Preamble; // LSB first (as sent) 0b00110101;
state->IrChannel = 0;
state->IrCommandType = static_cast<uint8_t>(messageType);
if (messageType == argoIrMessageType_t::TIMER_COMMAND) {
state->timer.Post1 = kArgoWrem3Postfix_Timer; // 0b1
} else if (messageType == argoIrMessageType_t::AC_CONTROL) {
state->Post1 = kArgoWrem3Postfix_ACControl; // 0b110000
}
}
/// @brief Reset the internals of the object to a known good state.
/// @param messageType Type of message to reset the state for
template<typename T>
void IRArgoACBase<T>::stateReset(argoIrMessageType_t messageType) {
_stateReset(&_, messageType);
if (messageType == argoIrMessageType_t::AC_CONTROL) {
off();
setTemp(20);
setSensorTemp(25);
setMode(argoMode_t::AUTO);
setFan(argoFan_t::FAN_AUTO);
}
_messageType = messageType;
_length = getStateLengthForIrMsgType(_messageType);
}
/// @brief Retrieve the checksum value from transmitted state
/// @note This is a full specialization for @c ArgoProtocol type and while
/// it semantically belongs to @c IrArgoAC class impl., it has *not*
/// been pushed there, to avoid having to use a virtual function
/// @param[in] state Raw state
/// @param length Length of @c state in bytes
/// @return Checksum value (8-bit)
/// @relates IRArgoACBase\<ARGO_PROTOCOL_T\>
template<>
uint8_t IRArgoACBase<ArgoProtocol>::getChecksum(const uint8_t state[],
const uint16_t length) {
if (length < 1) {
return -1;
}
return (state[length - 2] >> 2) + (state[length - 1] << 6);
}
/// @cond
/// @brief Retrieve the checksum value from transmitted state
/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while
/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not*
/// been pushed there, to avoid having to use a virtual function
/// @param[in] state Raw state
/// @param length Length of @c state in bytes
/// @return Checksum value (up to 8-bit)
template<>
uint8_t IRArgoACBase<ArgoProtocolWREM3>::getChecksum(const uint8_t state[],
const uint16_t length) {
if (length < 1) {
return -1;
}
argoIrMessageType_t msgType = getMessageType(state, length);
if (msgType == argoIrMessageType_t::IFEEL_TEMP_REPORT) {
return (state[length - 1] & 0b11100000) >> 5;
}
if (msgType == argoIrMessageType_t::TIMER_COMMAND) {
return state[length - 1] >> 3;
}
return (state[length - 1]);
}
/// @endcond
/// Verify the checksum is valid for a given state.
/// @param[in] state The array to verify the checksum of.
/// @param[in] length The size of the state.
/// @return A boolean indicating if it's checksum is valid.
template<typename T>
bool IRArgoACBase<T>::validChecksum(const uint8_t state[],
const uint16_t length) {
return (getChecksum(state, length) == calcChecksum(state, length));
}
#if SEND_ARGO
/// Send the current internal state as an IR message.
/// @param[in] repeat Nr. of times the message will be repeated.
template<typename T>
void IRArgoACBase<T>::send(const uint16_t repeat) {
_irsend.sendArgo(getRaw(), getRawByteLength(), repeat);
}
/// @cond
/// Send the current internal state as an IR message.
/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while
/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not*
/// been pushed there, to avoid having to use a virtual function
/// @param[in] repeat Nr. of times the message will be repeated.
/// @relates IRArgoACBase\<ARGO_PROTOCOL_T\>
template<>
void IRArgoACBase<ArgoProtocolWREM3>::send(const uint16_t repeat) {
_irsend.sendArgoWREM3(getRaw(), getRawByteLength(), repeat);
}
/// @endcond
/// Send current room temperature for the iFeel feature as a silent IR
/// message (no acknowledgement from the device) (WREM2)
/// @param[in] degrees The temperature in degrees celsius.
/// @param[in] repeat Nr. of times the message will be repeated.
void IRArgoAC::sendSensorTemp(const uint8_t degrees, const uint16_t repeat) {
const uint8_t temp = std::max(std::min(degrees, kArgoMaxRoomTemp),
kArgoTempDelta) - kArgoTempDelta;
const uint8_t check = kArgoSensorCheck + temp;
ArgoProtocol data;
_stateReset(&data, argoIrMessageType_t::IFEEL_TEMP_REPORT);
data.SensorT = temp;
data.CheckHi = check >> 5;
data.CheckLo = check;
data.Fixed = kArgoSensorFixed;
_checksum(&data);
uint16_t msgLen = getRawByteLength(data,
argoIrMessageType_t::IFEEL_TEMP_REPORT);
_irsend.sendArgo(data.raw, msgLen, repeat);
}
/// Send current room temperature for the iFeel feature as a silent IR
/// message (no acknowledgement from the device) (WREM3)
/// @param[in] degrees The temperature in degrees celsius.
/// @param[in] repeat Nr. of times the message will be repeated.
void IRArgoAC_WREM3::sendSensorTemp(const uint8_t degrees,
const uint16_t repeat) {
const uint8_t temp = std::max(std::min(degrees, kArgoMaxRoomTemp),
kArgoTempDelta) - kArgoTempDelta;
ArgoProtocolWREM3 data = {};
_stateReset(&data, argoIrMessageType_t::IFEEL_TEMP_REPORT);
data.SensorT = temp;
_checksum(&data);
uint16_t msgLen = getRawByteLength(data,
argoIrMessageType_t::IFEEL_TEMP_REPORT);
_irsend.sendArgoWREM3(data.raw, msgLen, repeat);
}
#endif
/// Get the raw state of the object, suitable to be sent with the appropriate
/// IRsend object method.
/// @return A PTR to the internal state.
template<typename T>
uint8_t* IRArgoACBase<T>::getRaw(void) {
checksum(); // Ensure correct bit array before returning
return _.raw;
}
/// Set the raw state of the object.
/// @param[in] state The raw state from the native IR message.
/// @param[in] length The length of raw state in bytes.
template<typename T>
void IRArgoACBase<T>::setRaw(const uint8_t state[], const uint16_t length) {
std::memcpy(_.raw, state, length);
_messageType = getMessageType(state, length);
_length = length;
}
/// Set the internal state to have the power on.
template<typename T>
void IRArgoACBase<T>::on(void) { setPower(true); }
/// Set the internal state to have the power off.
template<typename T>
void IRArgoACBase<T>::off(void) { setPower(false); }
/// @cond
/// Set the internal state to have the desired power.
/// @param[in] on The desired power state.
/// @note This is a full specialization for @c ArgoProtocol type and while
/// it semantically belongs to @c IrArgoAC class impl., it has *not*
/// been pushed there, to avoid having to use a virtual function
/// @relates IRArgoACBase\<ARGO_PROTOCOL_T\>
template<>
void IRArgoACBase<ArgoProtocol>::setPower(const bool on) {
_.Power = on;
}
/// @endcond
/// @brief Set the internal state to have the desired power.
/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while
/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not*
/// been pushed there, to avoid having to use a virtual function
/// @param[in] on The desired power state.
/// @relates IRArgoACBase\<ARGO_PROTOCOL_T\>
template<>
void IRArgoACBase<ArgoProtocolWREM3>::setPower(const bool on) {
if (_messageType == argoIrMessageType_t::TIMER_COMMAND) {
_.timer.IsOn = on;
} else {
_.Power = on;
}
}
/// Get the power setting from the internal state.
/// @note This is a full specialization for @c ArgoProtocol type and while
/// it semantically belongs to @c IrArgoAC class impl., it has *not*
/// been pushed there, to avoid having to use a virtual function
/// @return A boolean indicating the power setting.
/// @relates IRArgoACBase\<ARGO_PROTOCOL_T\>
template<>
bool IRArgoACBase<ArgoProtocol>::getPower(void) const { return _.Power; }
/// Get the power setting from the internal state.
/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while
/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not*
/// been pushed there, to avoid having to use a virtual function
/// @return A boolean indicating the power setting.
/// @relates IRArgoACBase\<ARGO_PROTOCOL_T\>
template<>
bool IRArgoACBase<ArgoProtocolWREM3>::getPower(void) const {
if (_messageType == argoIrMessageType_t::TIMER_COMMAND) {
return _.timer.IsOn;
}
return _.Power;
}
/// Control the current Max setting. (i.e. Turbo)
/// @param[in] on The desired setting.
template<typename T>
void IRArgoACBase<T>::setMax(const bool on) {
_.Max = on;
}
/// Is the Max (i.e. Turbo) setting on?
/// @return The current value.
template<typename T>
bool IRArgoACBase<T>::getMax(void) const { return _.Max; }
/// Set the temperature.
/// @param[in] degrees The temperature in degrees celsius.
/// @note Sending 0 equals +4
template<typename T>
void IRArgoACBase<T>::setTemp(const uint8_t degrees) {
uint8_t temp = std::max(kArgoMinTemp, degrees);
// delta 4 degrees. "If I want 12 degrees, I need to send 8"
temp = std::min(kArgoMaxTemp, temp) - kArgoTempDelta;
// mask out bits
_.Temp = temp;
}
/// Get the current temperature setting.
/// @return The current setting for temp. in degrees celsius.
template<typename T>
uint8_t IRArgoACBase<T>::getTemp(void) const {
return _.Temp + kArgoTempDelta;
}
/// @brief Get the current fan mode setting as a strongly typed value (WREM2).
/// @note This is a full specialization for @c ArgoProtocol type and while
/// it semantically belongs to @c IrArgoAC class impl., it has *not*
/// been pushed there, to avoid having to use a virtual function
/// @return The current fan mode.
/// @relates IRArgoACBase\<ARGO_PROTOCOL_T\>
template<>
argoFan_t IRArgoACBase<ArgoProtocol>::getFanEx(void) const {
switch (_.Fan) {
case kArgoFan3:
return argoFan_t::FAN_HIGHEST;
case kArgoFan2:
return argoFan_t::FAN_MEDIUM;
case kArgoFan1:
return argoFan_t::FAN_LOWEST;
case kArgoFanAuto:
return argoFan_t::FAN_AUTO;
default:
return static_cast<argoFan_t>(_.Fan);
}
}
/// @brief Get the current fan mode setting as a strongly typed value (WREM3).
/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while
/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not*
/// been pushed there, to avoid having to use a virtual function
/// @return The current fan mode.
/// @relates IRArgoACBase\<ARGO_PROTOCOL_T\>
template<>
argoFan_t IRArgoACBase<ArgoProtocolWREM3>::getFanEx(void) const {
return static_cast<argoFan_t>(_.Fan);
}
/// @cond
/// Set the desired fan mode (WREM2).
/// @note This is a full specialization for @c ArgoProtocol type and while
/// it semantically belongs to @c IrArgoAC class impl., it has *not*
/// been pushed there, to avoid having to use a virtual function
/// @param[in] fan The desired fan speed.
/// @note Only a subset of fan speeds are supported (1|2|3|Auto)
/// @relates IRArgoACBase\<ARGO_PROTOCOL_T\>
template<>
void IRArgoACBase<ArgoProtocol>::setFan(argoFan_t fan) {
switch (fan) {
case argoFan_t::FAN_AUTO:
_.Fan = kArgoFanAuto;
break;
case argoFan_t::FAN_HIGHEST:
case argoFan_t::FAN_HIGH:
_.Fan = kArgoFan3;
break;
case argoFan_t::FAN_MEDIUM:
case argoFan_t::FAN_LOW:
_.Fan = kArgoFan2;
break;
case argoFan_t::FAN_LOWER:
case argoFan_t::FAN_LOWEST:
_.Fan = kArgoFan1;
break;
default:
uint8_t raw_value = static_cast<uint8_t>(fan); // 2-bit value, per def.
if ((raw_value & 0b11) == raw_value) {
// Outside of known value range, but matches field length
// Let's assume the caller knows what they're doing and pass it through
_.Fan = raw_value;
} else {
_.Fan = kArgoFanAuto;
}
break;
}
}
/// @endcond
/// Set the desired fan mode (WREM3).
/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while
/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not*
/// been pushed there, to avoid having to use a virtual function
/// @param[in] fan The desired fan speed.
/// @relates IRArgoACBase\<ARGO_PROTOCOL_T\>
template<>
void IRArgoACBase<ArgoProtocolWREM3>::setFan(argoFan_t fan) {
switch (fan) {
case argoFan_t::FAN_AUTO:
case argoFan_t::FAN_HIGHEST:
case argoFan_t::FAN_HIGH:
case argoFan_t::FAN_MEDIUM:
case argoFan_t::FAN_LOW:
case argoFan_t::FAN_LOWER:
case argoFan_t::FAN_LOWEST:
_.Fan = static_cast<uint8_t>(fan);
break;
default:
_.Fan = static_cast<uint8_t>(argoFan_t::FAN_AUTO);
break;
}
}
/// Set the speed of the fan.
/// @deprecated
/// @param[in] fan The desired setting.
void IRArgoAC::setFan(const uint8_t fan) {
_.Fan = std::min(fan, kArgoFan3);
}
/// Get the current fan speed setting.
/// @deprecated
/// @return The current fan speed.
uint8_t IRArgoAC::getFan(void) const {
return _.Fan;
}
/// @brief Get Flap (VSwing) value as a strongly-typed value
/// @note This @c getFlapEx() method has been introduced to be able to retain
/// old implementation of @c getFlap() for @c IRArgoAc which used uint8_t
/// @return Flap setting
template<typename T>
argoFlap_t IRArgoACBase<T>::getFlapEx(void) const {
return static_cast<argoFlap_t>(_.Flap);
}
/// Set the desired flap mode
/// @param[in] flap The desired flap mode.
template<typename T>
void IRArgoACBase<T>::setFlap(argoFlap_t flap) {
uint8_t raw_value = static_cast<uint8_t>(flap);
if ((raw_value & 0b111) == raw_value) {
// Outside of known value range, but matches field length
// Let's assume the caller knows what they're doing and pass it through
_.Flap = raw_value;
} else {
_.Flap = static_cast<uint8_t>(argoFlap_t::FLAP_AUTO);
}
}
/// Set the flap position. i.e. Swing. (WREM2)
/// @warning Not yet working!
/// @deprecated
/// @param[in] flap The desired setting.
void IRArgoAC::setFlap(const uint8_t flap) {
setFlap(static_cast<argoFlap_t>(flap));
// TODO(kaschmo): set correct bits for flap mode
}
/// Get the flap position. i.e. Swing. (WREM2)
/// @warning Not yet working!
/// @deprecated
/// @return The current flap setting.
uint8_t IRArgoAC::getFlap(void) const {
return _.Flap;
}
/// Get the current operation mode setting.
/// @note This is a full specialization for @c ArgoProtocol type and while
/// it semantically belongs to @c IrArgoAC class impl., it has *not*
/// been pushed there, to avoid having to use a virtual function
/// @return The current operation mode.
/// @note This @c getModeEx() method has been introduced to be able to retain
/// old implementation of @c getMode() for @c IRArgoAc which used uint8_t
/// @relates IRArgoACBase\<ARGO_PROTOCOL_T\>
template<>
argoMode_t IRArgoACBase<ArgoProtocol>::getModeEx(void) const {
switch (_.Mode) {
case kArgoCool:
return argoMode_t::COOL;
case kArgoDry:
return argoMode_t::DRY;
case kArgoAuto:
return argoMode_t::AUTO;
case kArgoHeat:
return argoMode_t::HEAT;
case kArgoOff: // Modelling "FAN" as "OFF", for the lack of better constant
return argoMode_t::FAN;
case kArgoHeatAuto:
default:
return static_cast<argoMode_t>(_.Mode);
}
}
/// Get the current operation mode setting.
/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while
/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not*
/// been pushed there, to avoid having to use a virtual function.
/// @return The current operation mode.
/// @note This @c getModeEx() method has been introduced to be able to retain
/// old implementation of @c getMode() for @c IRArgoAc which used uint8_t
/// @relates IRArgoACBase\<ARGO_PROTOCOL_T\>
template<>
argoMode_t IRArgoACBase<ArgoProtocolWREM3>::getModeEx(void) const {
return static_cast<argoMode_t>(_.Mode);
}
/// @cond
/// Set the desired operation mode.
/// @param[in] mode The desired operation mode.
/// @note This is a full specialization for @c ArgoProtocol type and while
/// it semantically belongs to @c IrArgoAC class impl., it has *not*
/// been pushed there, to avoid having to use a virtual function
/// @relates IRArgoACBase\<ARGO_PROTOCOL_T\>
template<>
void IRArgoACBase<ArgoProtocol>::setMode(argoMode_t mode) {
switch (mode) {
case argoMode_t::COOL:
_.Mode = static_cast<uint8_t>(kArgoCool);
break;
case argoMode_t::DRY:
_.Mode = static_cast<uint8_t>(kArgoDry);
break;
case argoMode_t::HEAT:
_.Mode = static_cast<uint8_t>(kArgoHeat);
break;
case argoMode_t::FAN:
_.Mode = static_cast<uint8_t>(kArgoOff);
break;
case argoMode_t::AUTO:
_.Mode = static_cast<uint8_t>(kArgoAuto);
break;
default:
uint8_t raw_value = static_cast<uint8_t>(mode);
if ((raw_value & 0b111) == raw_value) {
// Outside of known value range, but matches field length
// Let's assume the caller knows what they're doing and pass it through
_.Mode = raw_value;
} else {
_.Mode = static_cast<uint8_t>(kArgoAuto);
}
break;
}
}
/// @endcond
/// @brief Set the desired operation mode.
/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while
/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not*
/// been pushed there, to avoid having to use a virtual function
/// @param[in] mode The desired operation mode.
/// @relates IRArgoACBase\<ARGO_PROTOCOL_T\>
template<>
void IRArgoACBase<ArgoProtocolWREM3>::setMode(argoMode_t mode) {
switch (mode) {
case argoMode_t::COOL:
case argoMode_t::DRY:
case argoMode_t::HEAT:
case argoMode_t::FAN:
case argoMode_t::AUTO:
_.Mode = static_cast<uint8_t>(mode);
break;
default:
_.Mode = static_cast<uint8_t>(argoMode_t::AUTO);
break;
}
}
/// @brief Set the desired operation mode.
/// @deprecated
/// @param mode The desired operation mode.
void IRArgoAC::setMode(uint8_t mode) {
switch (mode) {
case kArgoCool:
case kArgoDry:
case kArgoAuto:
case kArgoOff:
case kArgoHeat:
case kArgoHeatAuto:
_.Mode = mode;
break;
default:
_.Mode = kArgoAuto;
break;
}
}
/// @brief Get the current operation mode
/// @deprecated
/// @return The current operation mode
uint8_t IRArgoAC::getMode() const { return _.Mode;}
argoFan_t IRArgoAC_WREM3::getFan(void) const { return getFanEx(); }
argoFlap_t IRArgoAC_WREM3::getFlap(void) const { return getFlapEx(); }
argoMode_t IRArgoAC_WREM3::getMode(void) const { return getModeEx(); }
/// Turn on/off the Night mode. i.e. Sleep.
/// @param[in] on The desired setting.
template<typename T>
void IRArgoACBase<T>::setNight(const bool on) { _.Night = on; }
/// Get the status of Night mode. i.e. Sleep.
/// @return true if on, false if off.
template<typename T>
bool IRArgoACBase<T>::getNight(void) const { return _.Night; }
/// @brief Turn on/off the Economy mode (lowered power mode)
/// @param[in] on The desired setting.
void IRArgoAC_WREM3::setEco(const bool on) { _.Eco = on; }
/// @brief Get the status of Economy function
/// @return true if on, false if off.
bool IRArgoAC_WREM3::getEco(void) const { return _.Eco; }
/// @brief Turn on/off the Filter mode (not supported by Argo Ulisse)
/// @param[in] on The desired setting.
void IRArgoAC_WREM3::setFilter(const bool on) { _.Filter = on; }
/// @brief Get status of the filter function
/// @return true if on, false if off.
bool IRArgoAC_WREM3::getFilter(void) const { return _.Filter; }
/// @brief Turn on/off the device Lights (LED)
/// @param[in] on The desired setting.
void IRArgoAC_WREM3::setLight(const bool on) { _.Light = on; }
/// @brief Get status of device lights
/// @return true if on, false if off.
bool IRArgoAC_WREM3::getLight(void) const { return _.Light; }
/// @brief Set the IR channel on which to communicate
/// @param[in] channel The desired IR channel.
void IRArgoAC_WREM3::setChannel(const uint8_t channel) {
_.IrChannel = std::min(channel, kArgoMaxChannel);
}
/// @brief Get the currently set transmission channel
/// @return Channel number
uint8_t IRArgoAC_WREM3::getChannel(void) const { return _.IrChannel;}
/// @brief Set the config data to send
/// Valid only for @c argoIrMessageType_t::CONFIG_PARAM_SET message
/// @param paramId The param ID
/// @param value The value of the parameter
void IRArgoAC_WREM3::setConfigEntry(const uint8_t paramId,
const uint8_t value) {
_.config.Key = paramId;
_.config.Value = value;
}
/// @brief Get the config entry previously set
/// @return Key->value pair (paramID: value)
std::pair<uint8_t, uint8_t> IRArgoAC_WREM3::getConfigEntry(void) const {
return std::make_pair(_.config.Key, _.config.Value);
}
/// Turn on/off the iFeel mode.
/// @param[in] on The desired setting.
template<typename T>