IRremoteESP8266
ir_Tcl.h
Go to the documentation of this file.
1 // Copyright 2019, 2021 David Conran
2 
5 
6 // Supports:
7 // Brand: Leberg, Model: LBS-TOR07 A/C (TAC09CHSD)
8 // Brand: TCL, Model: TAC-09CHSD/XA31I A/C (TAC09CHSD)
9 // Brand: Teknopoint, Model: Allegro SSA-09H A/C (GZ055BE1)
10 // Brand: Teknopoint, Model: GZ-055B-E1 remote (GZ055BE1)
11 // Brand: Daewoo, Model: DSB-F0934ELH-V A/C
12 // Brand: Daewoo, Model: GYKQ-52E remote
13 // Brand: TCL, Model: GYKQ-58(XM) remote (TCL96AC)
14 
15 #ifndef IR_TCL_H_
16 #define IR_TCL_H_
17 
18 #ifndef UNIT_TEST
19 #include <Arduino.h>
20 #endif
21 #include "IRremoteESP8266.h"
22 #include "IRsend.h"
23 #include "IRrecv.h"
24 #ifdef UNIT_TEST
25 #include "IRsend_test.h"
26 #endif
27 
31  struct {
32  // Byte 0~2
33  uint8_t :8;
34  uint8_t :8;
35  uint8_t :8;
36  // Byte 3
37  uint8_t MsgType :2;
38  uint8_t :6;
39  // Byte 4
40  uint8_t :8;
41  // Byte 5
42  uint8_t :2;
43  uint8_t Power :1;
44  uint8_t OffTimerEnabled :1;
45  uint8_t OnTimerEnabled :1;
46  uint8_t Quiet :1;
47  uint8_t Light :1;
48  uint8_t Econo :1;
49  // Byte 6
50  uint8_t Mode :4;
51  uint8_t Health :1;
52  uint8_t Turbo :1;
53  uint8_t :2;
54  // Byte 7
55  uint8_t Temp :4;
56  uint8_t :4;
57  // Byte 8
58  uint8_t Fan :3;
59  uint8_t SwingV :3;
60  uint8_t TimerIndicator :1;
61  uint8_t :1;
62  // Byte 9
63  uint8_t :1; // 0
64  uint8_t OffTimer :6;
65  uint8_t :1; // 0
66  // Byte 10
67  uint8_t :1; // 0
68  uint8_t OnTimer :6;
69  uint8_t :1; // 0
70  // Byte 11
71  uint8_t :8; // 00000000
72  // Byte 12
73  uint8_t :3;
74  uint8_t SwingH :1;
75  uint8_t :1;
76  uint8_t HalfDegree :1;
77  uint8_t :1;
78  uint8_t isTcl :1;
79  // Byte 13
80  uint8_t Sum :8;
81  };
82 };
83 
84 // Constants
85 const uint16_t kTcl112AcHdrMark = 3000;
86 const uint16_t kTcl112AcHdrSpace = 1650;
87 const uint16_t kTcl112AcBitMark = 500;
88 const uint16_t kTcl112AcOneSpace = 1050;
89 const uint16_t kTcl112AcZeroSpace = 325;
90 const uint32_t kTcl112AcGap = kDefaultMessageGap; // Just a guess.
91 // Total tolerance percentage to use for matching the header mark.
92 const uint8_t kTcl112AcHdrMarkTolerance = 6;
93 const uint8_t kTcl112AcTolerance = 5; // Extra Percentage for the rest.
94 
95 const uint8_t kTcl112AcHeat = 1;
96 const uint8_t kTcl112AcDry = 2;
97 const uint8_t kTcl112AcCool = 3;
98 const uint8_t kTcl112AcFan = 7;
99 const uint8_t kTcl112AcAuto = 8;
100 
101 const uint8_t kTcl112AcFanAuto = 0b000;
102 const uint8_t kTcl112AcFanMin = 0b001; // Aka. "Night"
103 const uint8_t kTcl112AcFanLow = 0b010;
104 const uint8_t kTcl112AcFanMed = 0b011;
105 const uint8_t kTcl112AcFanHigh = 0b101;
108 
109 const float kTcl112AcTempMax = 31.0;
110 const float kTcl112AcTempMin = 16.0;
111 
112 const uint8_t kTcl112AcSwingVOff = 0b000;
113 const uint8_t kTcl112AcSwingVHighest = 0b001;
114 const uint8_t kTcl112AcSwingVHigh = 0b010;
115 const uint8_t kTcl112AcSwingVMiddle = 0b011;
116 const uint8_t kTcl112AcSwingVLow = 0b100;
117 const uint8_t kTcl112AcSwingVLowest = 0b101;
118 const uint8_t kTcl112AcSwingVOn = 0b111;
119 // MsgType
120 const uint8_t kTcl112AcNormal = 0b01;
121 const uint8_t kTcl112AcSpecial = 0b10;
122 
123 // Classes
125 class IRTcl112Ac {
126  public:
127  explicit IRTcl112Ac(const uint16_t pin, const bool inverted = false,
128  const bool use_modulation = true);
129 #if SEND_TCL112AC
130  void send(const uint16_t repeat = kTcl112AcDefaultRepeat);
135  int8_t calibrate(void) { return _irsend.calibrate(); }
136 #endif // SEND_TCL
137  void begin(void);
138  void stateReset(void);
139  uint8_t* getRaw(void);
140  void setRaw(const uint8_t new_code[],
141  const uint16_t length = kTcl112AcStateLength);
142  tcl_ac_remote_model_t getModel(void) const;
143  void setModel(const tcl_ac_remote_model_t model);
144  void on(void);
145  void off(void);
146  void setPower(const bool on);
147  bool getPower(void) const;
148  void setTemp(const float celsius); // Celsius in 0.5 increments
149  float getTemp(void) const;
150  void setMode(const uint8_t mode);
151  uint8_t getMode(void) const;
152  static uint8_t calcChecksum(uint8_t state[],
153  const uint16_t length = kTcl112AcStateLength);
154  static bool validChecksum(uint8_t state[],
155  const uint16_t length = kTcl112AcStateLength);
156  void setFan(const uint8_t speed);
157  uint8_t getFan(void) const;
158  void setEcono(const bool on);
159  bool getEcono(void) const;
160  void setHealth(const bool on);
161  bool getHealth(void) const;
162  void setLight(const bool on);
163  bool getLight(void) const;
164  void setSwingHorizontal(const bool on);
165  bool getSwingHorizontal(void) const;
166  void setSwingVertical(const uint8_t setting);
167  uint8_t getSwingVertical(void) const;
168  void setTurbo(const bool on);
169  bool getTurbo(void) const;
170  void setQuiet(const bool on);
171  bool getQuiet(const bool def = false) const;
172  uint16_t getOnTimer(void) const;
173  void setOnTimer(const uint16_t mins);
174  uint16_t getOffTimer(void) const;
175  void setOffTimer(const uint16_t mins);
176  static bool isTcl(const uint8_t state[]);
177  static uint8_t convertMode(const stdAc::opmode_t mode);
178  static uint8_t convertFan(const stdAc::fanspeed_t speed);
179  static uint8_t convertSwingV(const stdAc::swingv_t position);
180  static stdAc::opmode_t toCommonMode(const uint8_t mode);
181  static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
182  static stdAc::swingv_t toCommonSwingV(const uint8_t setting);
183  stdAc::state_t toCommon(const stdAc::state_t *prev = NULL) const;
184  String toString(void) const;
185 #ifndef UNIT_TEST
186 
187  private:
189 #else // UNIT_TEST
190  IRsendTest _irsend;
192 #endif // UNIT_TEST
196  bool _quiet;
198  void checksum(const uint16_t length = kTcl112AcStateLength);
199 };
200 
201 #endif // IR_TCL_H_
IRTcl112Ac::_
Tcl112Protocol _
Definition: ir_Tcl.h:194
IRTcl112Ac::setSwingHorizontal
void setSwingHorizontal(const bool on)
Set the horizontal swing setting of the A/C.
Definition: ir_Tcl.cpp:288
IRTcl112Ac::convertFan
static uint8_t convertFan(const stdAc::fanspeed_t speed)
Convert a stdAc::fanspeed_t enum into it's native speed.
Definition: ir_Tcl.cpp:391
IRTcl112Ac::calcChecksum
static uint8_t calcChecksum(uint8_t state[], const uint16_t length=kTcl112AcStateLength)
Calculate the checksum for a given state.
Definition: ir_Tcl.cpp:101
IRTcl112Ac::getMode
uint8_t getMode(void) const
Get the operating mode setting of the A/C.
Definition: ir_Tcl.cpp:195
kTcl112AcTempMin
const float kTcl112AcTempMin
Definition: ir_Tcl.h:110
stdAc::swingv_t
swingv_t
Common A/C settings for Vertical Swing.
Definition: IRsend.h:74
IRTcl112Ac::convertSwingV
static uint8_t convertSwingV(const stdAc::swingv_t position)
Convert a stdAc::swingv_t enum into it's native setting.
Definition: ir_Tcl.cpp:418
kTcl112AcHdrSpace
const uint16_t kTcl112AcHdrSpace
Definition: ir_Tcl.h:86
IRTcl112Ac::convertMode
static uint8_t convertMode(const stdAc::opmode_t mode)
Convert a stdAc::opmode_t enum into its native mode.
Definition: ir_Tcl.cpp:378
Tcl112Protocol::SwingH
uint8_t SwingH
Definition: ir_Tcl.h:74
stdAc::fanspeed_t
fanspeed_t
Common A/C settings for Fan Speeds.
Definition: IRsend.h:61
IRTcl112Ac::getOffTimer
uint16_t getOffTimer(void) const
Get how long the Off Timer is set for, in minutes.
Definition: ir_Tcl.cpp:362
IRTcl112Ac::setOffTimer
void setOffTimer(const uint16_t mins)
Set or cancel the Off Timer function.
Definition: ir_Tcl.cpp:369
kDefaultMessageGap
const uint32_t kDefaultMessageGap
Definition: IRsend.h:41
IRTcl112Ac::isTcl
static bool isTcl(const uint8_t state[])
Check the supplied state looks like a TCL112AC message.
Definition: ir_Tcl.cpp:134
kTcl112AcFanQuiet
const uint8_t kTcl112AcFanQuiet
Definition: ir_Tcl.h:107
tcl_ac_remote_model_t
tcl_ac_remote_model_t
TCL (& Teknopoint) A/C model numbers.
Definition: IRsend.h:199
kTcl112AcFanLow
const uint8_t kTcl112AcFanLow
Definition: ir_Tcl.h:103
IRTcl112Ac::send
void send(const uint16_t repeat=kTcl112AcDefaultRepeat)
Send the current internal state as an IR message.
Definition: ir_Tcl.cpp:70
Tcl112Protocol::Quiet
uint8_t Quiet
Definition: ir_Tcl.h:46
kTcl112AcBitMark
const uint16_t kTcl112AcBitMark
Definition: ir_Tcl.h:87
IRTcl112Ac::getEcono
bool getEcono(void) const
Get the economy setting of the A/C.
Definition: ir_Tcl.cpp:268
kTcl112AcSpecial
const uint8_t kTcl112AcSpecial
Definition: ir_Tcl.h:121
IRTcl112Ac::_quiet_prev
bool _quiet_prev
Definition: ir_Tcl.h:195
kTcl112AcSwingVMiddle
const uint8_t kTcl112AcSwingVMiddle
Definition: ir_Tcl.h:115
kTcl112AcFanMed
const uint8_t kTcl112AcFanMed
Definition: ir_Tcl.h:104
Tcl112Protocol::isTcl
uint8_t isTcl
Definition: ir_Tcl.h:78
Tcl112Protocol::Temp
uint8_t Temp
Definition: ir_Tcl.h:55
IRsend.h
IRTcl112Ac::getSwingHorizontal
bool getSwingHorizontal(void) const
Get the horizontal swing setting of the A/C.
Definition: ir_Tcl.cpp:292
IRTcl112Ac::getQuiet
bool getQuiet(const bool def=false) const
Get the Quiet setting of the A/C.
Definition: ir_Tcl.cpp:338
kTcl112AcSwingVLowest
const uint8_t kTcl112AcSwingVLowest
Definition: ir_Tcl.h:117
IRTcl112Ac::getTemp
float getTemp(void) const
Get the current temperature setting.
Definition: ir_Tcl.cpp:235
IRsend
Class for sending all basic IR protocols.
Definition: IRsend.h:237
IRTcl112Ac::setEcono
void setEcono(const bool on)
Set the economy setting of the A/C.
Definition: ir_Tcl.cpp:264
kTcl112AcNormal
const uint8_t kTcl112AcNormal
Definition: ir_Tcl.h:120
IRsend::calibrate
int8_t calibrate(uint16_t hz=38000U)
Calculate & set any offsets to account for execution times during sending.
Definition: IRsend.cpp:207
IRTcl112Ac::getHealth
bool getHealth(void) const
Get the Health (Filter) setting of the A/C.
Definition: ir_Tcl.cpp:276
kTcl112AcOneSpace
const uint16_t kTcl112AcOneSpace
Definition: ir_Tcl.h:88
String
std::string String
Definition: IRremoteESP8266.h:1521
IRTcl112Ac::stateReset
void stateReset(void)
Reset the internal state of the emulation. (On, Cool, 24C)
Definition: ir_Tcl.cpp:141
IRTcl112Ac::_quiet_explictly_set
bool _quiet_explictly_set
Definition: ir_Tcl.h:197
kTcl112AcSwingVHighest
const uint8_t kTcl112AcSwingVHighest
Definition: ir_Tcl.h:113
IRTcl112Ac
Class for handling detailed TCL A/C messages.
Definition: ir_Tcl.h:125
IRTcl112Ac::checksum
void checksum(const uint16_t length=kTcl112AcStateLength)
Calculate & set the checksum for the current internal state of the remote.
Definition: ir_Tcl.cpp:115
Tcl112Protocol::Turbo
uint8_t Turbo
Definition: ir_Tcl.h:52
Tcl112Protocol::OnTimer
uint8_t OnTimer
Definition: ir_Tcl.h:68
IRremoteESP8266.h
Tcl112Protocol
Native representation of a TCL 112 A/C message.
Definition: ir_Tcl.h:29
Tcl112Protocol::HalfDegree
uint8_t HalfDegree
Definition: ir_Tcl.h:76
IRTcl112Ac::_irsend
IRsend _irsend
Instance of the IR send class.
Definition: ir_Tcl.h:188
IRTcl112Ac::setTemp
void setTemp(const float celsius)
Set the temperature.
Definition: ir_Tcl.cpp:221
IRTcl112Ac::getRaw
uint8_t * getRaw(void)
Get a PTR to the internal state/code for this protocol.
Definition: ir_Tcl.cpp:167
IRTcl112Ac::setLight
void setLight(const bool on)
Set the Light (LED/Display) setting of the A/C.
Definition: ir_Tcl.cpp:280
IRTcl112Ac::setPower
void setPower(const bool on)
Change the power setting.
Definition: ir_Tcl.cpp:187
IRTcl112Ac::calibrate
int8_t calibrate(void)
Run the calibration to calculate uSec timing offsets for this platform.
Definition: ir_Tcl.h:135
Tcl112Protocol::Light
uint8_t Light
Definition: ir_Tcl.h:47
kTcl112AcGap
const uint32_t kTcl112AcGap
Definition: ir_Tcl.h:90
IRTcl112Ac::validChecksum
static bool validChecksum(uint8_t state[], const uint16_t length=kTcl112AcStateLength)
Verify the checksum is valid for a given state.
Definition: ir_Tcl.cpp:125
IRTcl112Ac::_quiet
bool _quiet
Definition: ir_Tcl.h:196
Tcl112Protocol::Fan
uint8_t Fan
Definition: ir_Tcl.h:58
IRTcl112Ac::begin
void begin(void)
Set up hardware to be able to send a message.
Definition: ir_Tcl.cpp:65
Tcl112Protocol::Mode
uint8_t Mode
Definition: ir_Tcl.h:50
IRTcl112Ac::setOnTimer
void setOnTimer(const uint16_t mins)
Set or cancel the On Timer function.
Definition: ir_Tcl.cpp:354
kTcl112AcSwingVOn
const uint8_t kTcl112AcSwingVOn
Definition: ir_Tcl.h:118
kTcl112AcAuto
const uint8_t kTcl112AcAuto
Definition: ir_Tcl.h:99
kTcl112AcDefaultRepeat
const uint16_t kTcl112AcDefaultRepeat
Definition: IRremoteESP8266.h:1394
Tcl112Protocol::OnTimerEnabled
uint8_t OnTimerEnabled
Definition: ir_Tcl.h:45
IRTcl112Ac::toCommonFanSpeed
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed)
Convert a native fan speed into its stdAc equivalent.
Definition: ir_Tcl.cpp:433
kTcl112AcTempMax
const float kTcl112AcTempMax
Definition: ir_Tcl.h:109
kTcl112AcHdrMark
const uint16_t kTcl112AcHdrMark
Definition: ir_Tcl.h:85
IRTcl112Ac::getLight
bool getLight(void) const
Get the Light (LED/Display) setting of the A/C.
Definition: ir_Tcl.cpp:284
kTcl112AcFanNight
const uint8_t kTcl112AcFanNight
Definition: ir_Tcl.h:106
IRTcl112Ac::setMode
void setMode(const uint8_t mode)
Set the operating mode of the A/C.
Definition: ir_Tcl.cpp:201
Tcl112Protocol::OffTimerEnabled
uint8_t OffTimerEnabled
Definition: ir_Tcl.h:44
kTcl112AcSwingVHigh
const uint8_t kTcl112AcSwingVHigh
Definition: ir_Tcl.h:114
kTcl112AcFanAuto
const uint8_t kTcl112AcFanAuto
Definition: ir_Tcl.h:101
IRTcl112Ac::setQuiet
void setQuiet(const bool on)
Set the Quiet setting of the A/C.
Definition: ir_Tcl.cpp:329
kTcl112AcCool
const uint8_t kTcl112AcCool
Definition: ir_Tcl.h:97
IRTcl112Ac::on
void on(void)
Set the requested power state of the A/C to on.
Definition: ir_Tcl.cpp:180
IRrecv.h
IRTcl112Ac::getOnTimer
uint16_t getOnTimer(void) const
Get how long the On Timer is set for, in minutes.
Definition: ir_Tcl.cpp:347
Tcl112Protocol::SwingV
uint8_t SwingV
Definition: ir_Tcl.h:59
kTcl112AcSwingVLow
const uint8_t kTcl112AcSwingVLow
Definition: ir_Tcl.h:116
Tcl112Protocol::Health
uint8_t Health
Definition: ir_Tcl.h:51
IRTcl112Ac::getModel
tcl_ac_remote_model_t getModel(void) const
Get/Detect the model of the A/C.
Definition: ir_Tcl.cpp:154
Tcl112Protocol::raw
uint8_t raw[kTcl112AcStateLength]
The State in IR code form.
Definition: ir_Tcl.h:30
IRTcl112Ac::setHealth
void setHealth(const bool on)
Set the Health (Filter) setting of the A/C.
Definition: ir_Tcl.cpp:272
IRTcl112Ac::off
void off(void)
Set the requested power state of the A/C to off.
Definition: ir_Tcl.cpp:183
IRTcl112Ac::setRaw
void setRaw(const uint8_t new_code[], const uint16_t length=kTcl112AcStateLength)
Set the internal state from a valid code for this protocol.
Definition: ir_Tcl.cpp:175
kTcl112AcSwingVOff
const uint8_t kTcl112AcSwingVOff
Definition: ir_Tcl.h:112
Tcl112Protocol::Sum
uint8_t Sum
Definition: ir_Tcl.h:80
IRTcl112Ac::setFan
void setFan(const uint8_t speed)
Set the speed of the fan.
Definition: ir_Tcl.cpp:244
Tcl112Protocol::TimerIndicator
uint8_t TimerIndicator
Definition: ir_Tcl.h:60
kTcl112AcHdrMarkTolerance
const uint8_t kTcl112AcHdrMarkTolerance
Definition: ir_Tcl.h:92
kTcl112AcDry
const uint8_t kTcl112AcDry
Definition: ir_Tcl.h:96
Tcl112Protocol::MsgType
uint8_t MsgType
Definition: ir_Tcl.h:37
IRTcl112Ac::getTurbo
bool getTurbo(void) const
Get the Turbo setting of the A/C.
Definition: ir_Tcl.cpp:325
kTcl112AcFanHigh
const uint8_t kTcl112AcFanHigh
Definition: ir_Tcl.h:105
kTcl112AcStateLength
const uint16_t kTcl112AcStateLength
Definition: IRremoteESP8266.h:1392
IRTcl112Ac::toCommon
stdAc::state_t toCommon(const stdAc::state_t *prev=NULL) const
Convert the current internal state into its stdAc::state_t equivalent.
Definition: ir_Tcl.cpp:455
IRTcl112Ac::getSwingVertical
uint8_t getSwingVertical(void) const
Get the vertical swing setting of the A/C.
Definition: ir_Tcl.cpp:311
IRTcl112Ac::toCommonSwingV
static stdAc::swingv_t toCommonSwingV(const uint8_t setting)
Convert a native vertical swing postion to it's common equivalent.
Definition: ir_Tcl.cpp:446
kTcl112AcFan
const uint8_t kTcl112AcFan
Definition: ir_Tcl.h:98
IRTcl112Ac::toString
String toString(void) const
Convert the current internal state into a human readable string.
Definition: ir_Tcl.cpp:486
kTcl112AcZeroSpace
const uint16_t kTcl112AcZeroSpace
Definition: ir_Tcl.h:89
IRTcl112Ac::getPower
bool getPower(void) const
Get the value of the current power setting.
Definition: ir_Tcl.cpp:191
IRTcl112Ac::toCommonMode
static stdAc::opmode_t toCommonMode(const uint8_t mode)
Convert a native mode into its stdAc equivalent.
Definition: ir_Tcl.cpp:405
IRTcl112Ac::setTurbo
void setTurbo(const bool on)
Set the Turbo setting of the A/C.
Definition: ir_Tcl.cpp:315
IRTcl112Ac::setModel
void setModel(const tcl_ac_remote_model_t model)
Set the model of the A/C to emulate.
Definition: ir_Tcl.cpp:161
IRTcl112Ac::IRTcl112Ac
IRTcl112Ac(const uint16_t pin, const bool inverted=false, const bool use_modulation=true)
Class constructor.
Definition: ir_Tcl.cpp:60
IRTcl112Ac::setSwingVertical
void setSwingVertical(const uint8_t setting)
Set the vertical swing setting of the A/C.
Definition: ir_Tcl.cpp:296
kTcl112AcTolerance
const uint8_t kTcl112AcTolerance
Definition: ir_Tcl.h:93
kTcl112AcHeat
const uint8_t kTcl112AcHeat
Definition: ir_Tcl.h:95
IRTcl112Ac::getFan
uint8_t getFan(void) const
Get the current fan speed setting.
Definition: ir_Tcl.cpp:260
stdAc::state_t
Structure to hold a common A/C state.
Definition: IRsend.h:114
Tcl112Protocol::OffTimer
uint8_t OffTimer
Definition: ir_Tcl.h:64
Tcl112Protocol::Econo
uint8_t Econo
Definition: ir_Tcl.h:48
kTcl112AcFanMin
const uint8_t kTcl112AcFanMin
Definition: ir_Tcl.h:102
Tcl112Protocol::Power
uint8_t Power
Definition: ir_Tcl.h:43
stdAc::opmode_t
opmode_t
Common A/C settings for A/C operating modes.
Definition: IRsend.h:49