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