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
8 // Brand: TCL, Model: TAC-09CHSD/XA31I A/C
9 
10 #ifndef IR_TCL_H_
11 #define IR_TCL_H_
12 
13 #ifndef UNIT_TEST
14 #include <Arduino.h>
15 #endif
16 #include "IRremoteESP8266.h"
17 #include "IRsend.h"
18 #include "IRrecv.h"
19 #ifdef UNIT_TEST
20 #include "IRsend_test.h"
21 #endif
22 
26  struct {
27  // Byte 0~2
28  uint8_t pad0[3];
29  // Byte 3
30  uint8_t MsgType :2;
31  uint8_t :6;
32  // Byte 4
33  uint8_t :8;
34  // Byte 5
35  uint8_t :2;
36  uint8_t Power :1;
37  uint8_t :2;
38  uint8_t Quiet :1;
39  uint8_t Light :1;
40  uint8_t Econo :1;
41  // Byte 6
42  uint8_t Mode :4;
43  uint8_t Health :1;
44  uint8_t Turbo :1;
45  uint8_t :2;
46  // Byte 7
47  uint8_t Temp :4;
48  uint8_t :4;
49  // Byte 8
50  uint8_t Fan :3;
51  uint8_t SwingV :3;
52  uint8_t :2;
53  // Byte 9~11
54  uint8_t pad1[3];
55  // Byte 12
56  uint8_t :3;
57  uint8_t SwingH :1;
58  uint8_t :1;
59  uint8_t HalfDegree :1;
60  uint8_t :2;
61  // Byte 13
62  uint8_t Sum :8;
63  };
64 };
65 
66 // Constants
67 const uint16_t kTcl112AcHdrMark = 3000;
68 const uint16_t kTcl112AcHdrSpace = 1650;
69 const uint16_t kTcl112AcBitMark = 500;
70 const uint16_t kTcl112AcOneSpace = 1050;
71 const uint16_t kTcl112AcZeroSpace = 325;
72 const uint32_t kTcl112AcGap = kDefaultMessageGap; // Just a guess.
73 // Total tolerance percentage to use for matching the header mark.
74 const uint8_t kTcl112AcHdrMarkTolerance = 6;
75 const uint8_t kTcl112AcTolerance = 5; // Extra Percentage for the rest.
76 
77 const uint8_t kTcl112AcHeat = 1;
78 const uint8_t kTcl112AcDry = 2;
79 const uint8_t kTcl112AcCool = 3;
80 const uint8_t kTcl112AcFan = 7;
81 const uint8_t kTcl112AcAuto = 8;
82 
83 const uint8_t kTcl112AcFanAuto = 0b000;
84 const uint8_t kTcl112AcFanLow = 0b010;
85 const uint8_t kTcl112AcFanMed = 0b011;
86 const uint8_t kTcl112AcFanHigh = 0b101;
87 
88 const float kTcl112AcTempMax = 31.0;
89 const float kTcl112AcTempMin = 16.0;
90 
91 const uint8_t kTcl112AcSwingVOn = 0b111;
92 const uint8_t kTcl112AcSwingVOff = 0b000;
93 // MsgType
94 const uint8_t kTcl112AcNormal = 0b01;
95 const uint8_t kTcl112AcSpecial = 0b10;
96 
97 // Classes
99 class IRTcl112Ac {
100  public:
101  explicit IRTcl112Ac(const uint16_t pin, const bool inverted = false,
102  const bool use_modulation = true);
103 #if SEND_TCL112AC
104  void send(const uint16_t repeat = kTcl112AcDefaultRepeat);
109  int8_t calibrate(void) { return _irsend.calibrate(); }
110 #endif // SEND_TCL
111  void begin(void);
112  void stateReset(void);
113  uint8_t* getRaw(void);
114  void setRaw(const uint8_t new_code[],
115  const uint16_t length = kTcl112AcStateLength);
116  void on(void);
117  void off(void);
118  void setPower(const bool on);
119  bool getPower(void) const;
120  void setTemp(const float celsius); // Celsius in 0.5 increments
121  float getTemp(void) const;
122  void setMode(const uint8_t mode);
123  uint8_t getMode(void) const;
124  static uint8_t calcChecksum(uint8_t state[],
125  const uint16_t length = kTcl112AcStateLength);
126  static bool validChecksum(uint8_t state[],
127  const uint16_t length = kTcl112AcStateLength);
128  void setFan(const uint8_t speed);
129  uint8_t getFan(void) const;
130  void setEcono(const bool on);
131  bool getEcono(void) const;
132  void setHealth(const bool on);
133  bool getHealth(void) const;
134  void setLight(const bool on);
135  bool getLight(void) const;
136  void setSwingHorizontal(const bool on);
137  bool getSwingHorizontal(void) const;
138  void setSwingVertical(const bool on);
139  bool getSwingVertical(void) const;
140  void setTurbo(const bool on);
141  bool getTurbo(void) const;
142  void setQuiet(const bool on);
143  bool getQuiet(const bool def = false) const;
144  static uint8_t convertMode(const stdAc::opmode_t mode);
145  static uint8_t convertFan(const stdAc::fanspeed_t speed);
146  static stdAc::opmode_t toCommonMode(const uint8_t mode);
147  static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
148  stdAc::state_t toCommon(const stdAc::state_t *prev = NULL) const;
149  String toString(void) const;
150 #ifndef UNIT_TEST
151 
152  private:
154 #else // UNIT_TEST
155  IRsendTest _irsend;
157 #endif // UNIT_TEST
161  bool _quiet;
163  void checksum(const uint16_t length = kTcl112AcStateLength);
164 };
165 
166 #endif // IR_TCL_H_
IRTcl112Ac::_
Tcl112Protocol _
Definition: ir_Tcl.h:159
IRTcl112Ac::setSwingHorizontal
void setSwingHorizontal(const bool on)
Set the horizontal swing setting of the A/C.
Definition: ir_Tcl.cpp:246
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:310
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:84
IRTcl112Ac::getMode
uint8_t getMode(void) const
Get the operating mode setting of the A/C.
Definition: ir_Tcl.cpp:154
kTcl112AcTempMin
const float kTcl112AcTempMin
Definition: ir_Tcl.h:89
IRTcl112Ac::setSwingVertical
void setSwingVertical(const bool on)
Set the vertical swing setting of the A/C.
Definition: ir_Tcl.cpp:254
kTcl112AcHdrSpace
const uint16_t kTcl112AcHdrSpace
Definition: ir_Tcl.h:68
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:297
Tcl112Protocol::SwingH
uint8_t SwingH
Definition: ir_Tcl.h:57
stdAc::fanspeed_t
fanspeed_t
Common A/C settings for Fan Speeds.
Definition: IRsend.h:58
kDefaultMessageGap
const uint32_t kDefaultMessageGap
Definition: IRsend.h:41
kTcl112AcFanLow
const uint8_t kTcl112AcFanLow
Definition: ir_Tcl.h:84
IRTcl112Ac::send
void send(const uint16_t repeat=kTcl112AcDefaultRepeat)
Send the current internal state as an IR message.
Definition: ir_Tcl.cpp:55
Tcl112Protocol::Quiet
uint8_t Quiet
Definition: ir_Tcl.h:38
kTcl112AcBitMark
const uint16_t kTcl112AcBitMark
Definition: ir_Tcl.h:69
IRTcl112Ac::getEcono
bool getEcono(void) const
Get the economy setting of the A/C.
Definition: ir_Tcl.cpp:226
kTcl112AcSpecial
const uint8_t kTcl112AcSpecial
Definition: ir_Tcl.h:95
IRTcl112Ac::_quiet_prev
bool _quiet_prev
Definition: ir_Tcl.h:160
kTcl112AcFanMed
const uint8_t kTcl112AcFanMed
Definition: ir_Tcl.h:85
Tcl112Protocol::pad0
uint8_t pad0[3]
Definition: ir_Tcl.h:28
Tcl112Protocol::Temp
uint8_t Temp
Definition: ir_Tcl.h:47
IRsend.h
IRTcl112Ac::getSwingHorizontal
bool getSwingHorizontal(void) const
Get the horizontal swing setting of the A/C.
Definition: ir_Tcl.cpp:250
IRTcl112Ac::getQuiet
bool getQuiet(const bool def=false) const
Get the Quiet setting of the A/C.
Definition: ir_Tcl.cpp:287
IRTcl112Ac::getTemp
float getTemp(void) const
Get the current temperature setting.
Definition: ir_Tcl.cpp:194
IRsend
Class for sending all basic IR protocols.
Definition: IRsend.h:190
IRTcl112Ac::setEcono
void setEcono(const bool on)
Set the economy setting of the A/C.
Definition: ir_Tcl.cpp:222
kTcl112AcNormal
const uint8_t kTcl112AcNormal
Definition: ir_Tcl.h:94
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:234
kTcl112AcOneSpace
const uint16_t kTcl112AcOneSpace
Definition: ir_Tcl.h:70
String
std::string String
Definition: IRremoteESP8266.h:1279
IRTcl112Ac::stateReset
void stateReset(void)
Reset the internal state of the emulation. (On, Cool, 24C)
Definition: ir_Tcl.cpp:113
IRTcl112Ac::_quiet_explictly_set
bool _quiet_explictly_set
Definition: ir_Tcl.h:162
IRTcl112Ac
Class for handling detailed TCL A/C messages.
Definition: ir_Tcl.h:99
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:98
Tcl112Protocol::Turbo
uint8_t Turbo
Definition: ir_Tcl.h:44
IRremoteESP8266.h
Tcl112Protocol
Native representation of a TCL 112 A/C message.
Definition: ir_Tcl.h:24
Tcl112Protocol::HalfDegree
uint8_t HalfDegree
Definition: ir_Tcl.h:59
IRTcl112Ac::_irsend
IRsend _irsend
Instance of the IR send class.
Definition: ir_Tcl.h:153
IRTcl112Ac::setTemp
void setTemp(const float celsius)
Set the temperature.
Definition: ir_Tcl.cpp:180
IRTcl112Ac::getRaw
uint8_t * getRaw(void)
Get a PTR to the internal state/code for this protocol.
Definition: ir_Tcl.cpp:126
IRTcl112Ac::setLight
void setLight(const bool on)
Set the Light (LED/Display) setting of the A/C.
Definition: ir_Tcl.cpp:238
IRTcl112Ac::setPower
void setPower(const bool on)
Change the power setting.
Definition: ir_Tcl.cpp:146
IRTcl112Ac::calibrate
int8_t calibrate(void)
Run the calibration to calculate uSec timing offsets for this platform.
Definition: ir_Tcl.h:109
Tcl112Protocol::Light
uint8_t Light
Definition: ir_Tcl.h:39
kTcl112AcGap
const uint32_t kTcl112AcGap
Definition: ir_Tcl.h:72
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:108
IRTcl112Ac::_quiet
bool _quiet
Definition: ir_Tcl.h:161
Tcl112Protocol::Fan
uint8_t Fan
Definition: ir_Tcl.h:50
IRTcl112Ac::begin
void begin(void)
Set up hardware to be able to send a message.
Definition: ir_Tcl.cpp:50
Tcl112Protocol::Mode
uint8_t Mode
Definition: ir_Tcl.h:42
Tcl112Protocol::pad1
uint8_t pad1[3]
Definition: ir_Tcl.h:54
kTcl112AcSwingVOn
const uint8_t kTcl112AcSwingVOn
Definition: ir_Tcl.h:91
kTcl112AcAuto
const uint8_t kTcl112AcAuto
Definition: ir_Tcl.h:81
kTcl112AcDefaultRepeat
const uint16_t kTcl112AcDefaultRepeat
Definition: IRremoteESP8266.h:1166
IRTcl112Ac::toCommonFanSpeed
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed)
Convert a native fan speed into its stdAc equivalent.
Definition: ir_Tcl.cpp:337
kTcl112AcTempMax
const float kTcl112AcTempMax
Definition: ir_Tcl.h:88
kTcl112AcHdrMark
const uint16_t kTcl112AcHdrMark
Definition: ir_Tcl.h:67
IRTcl112Ac::getLight
bool getLight(void) const
Get the Light (LED/Display) setting of the A/C.
Definition: ir_Tcl.cpp:242
IRTcl112Ac::setMode
void setMode(const uint8_t mode)
Set the operating mode of the A/C.
Definition: ir_Tcl.cpp:160
kTcl112AcFanAuto
const uint8_t kTcl112AcFanAuto
Definition: ir_Tcl.h:83
IRTcl112Ac::setQuiet
void setQuiet(const bool on)
Set the Quiet setting of the A/C.
Definition: ir_Tcl.cpp:278
kTcl112AcCool
const uint8_t kTcl112AcCool
Definition: ir_Tcl.h:79
IRTcl112Ac::on
void on(void)
Set the requested power state of the A/C to on.
Definition: ir_Tcl.cpp:139
IRrecv.h
Tcl112Protocol::SwingV
uint8_t SwingV
Definition: ir_Tcl.h:51
Tcl112Protocol::Health
uint8_t Health
Definition: ir_Tcl.h:43
Tcl112Protocol::raw
uint8_t raw[kTcl112AcStateLength]
The State in IR code form.
Definition: ir_Tcl.h:25
IRTcl112Ac::setHealth
void setHealth(const bool on)
Set the Health (Filter) setting of the A/C.
Definition: ir_Tcl.cpp:230
IRTcl112Ac::off
void off(void)
Set the requested power state of the A/C to off.
Definition: ir_Tcl.cpp:142
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:134
kTcl112AcSwingVOff
const uint8_t kTcl112AcSwingVOff
Definition: ir_Tcl.h:92
Tcl112Protocol::Sum
uint8_t Sum
Definition: ir_Tcl.h:62
IRTcl112Ac::setFan
void setFan(const uint8_t speed)
Set the speed of the fan.
Definition: ir_Tcl.cpp:203
kTcl112AcHdrMarkTolerance
const uint8_t kTcl112AcHdrMarkTolerance
Definition: ir_Tcl.h:74
kTcl112AcDry
const uint8_t kTcl112AcDry
Definition: ir_Tcl.h:78
Tcl112Protocol::MsgType
uint8_t MsgType
Definition: ir_Tcl.h:30
IRTcl112Ac::getTurbo
bool getTurbo(void) const
Get the Turbo setting of the A/C.
Definition: ir_Tcl.cpp:274
kTcl112AcFanHigh
const uint8_t kTcl112AcFanHigh
Definition: ir_Tcl.h:86
IRTcl112Ac::getSwingVertical
bool getSwingVertical(void) const
Get the vertical swing setting of the A/C.
Definition: ir_Tcl.cpp:260
kTcl112AcStateLength
const uint16_t kTcl112AcStateLength
Definition: IRremoteESP8266.h:1164
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:349
kTcl112AcFan
const uint8_t kTcl112AcFan
Definition: ir_Tcl.h:80
IRTcl112Ac::toString
String toString(void) const
Convert the current internal state into a human readable string.
Definition: ir_Tcl.cpp:380
kTcl112AcZeroSpace
const uint16_t kTcl112AcZeroSpace
Definition: ir_Tcl.h:71
IRTcl112Ac::getPower
bool getPower(void) const
Get the value of the current power setting.
Definition: ir_Tcl.cpp:150
IRTcl112Ac::toCommonMode
static stdAc::opmode_t toCommonMode(const uint8_t mode)
Convert a native mode into its stdAc equivalent.
Definition: ir_Tcl.cpp:324
IRTcl112Ac::setTurbo
void setTurbo(const bool on)
Set the Turbo setting of the A/C.
Definition: ir_Tcl.cpp:264
IRTcl112Ac::IRTcl112Ac
IRTcl112Ac(const uint16_t pin, const bool inverted=false, const bool use_modulation=true)
Class constructor.
Definition: ir_Tcl.cpp:45
kTcl112AcTolerance
const uint8_t kTcl112AcTolerance
Definition: ir_Tcl.h:75
kTcl112AcHeat
const uint8_t kTcl112AcHeat
Definition: ir_Tcl.h:77
IRTcl112Ac::getFan
uint8_t getFan(void) const
Get the current fan speed setting.
Definition: ir_Tcl.cpp:218
stdAc::state_t
Structure to hold a common A/C state.
Definition: IRsend.h:97
Tcl112Protocol::Econo
uint8_t Econo
Definition: ir_Tcl.h:40
Tcl112Protocol::Power
uint8_t Power
Definition: ir_Tcl.h:36
stdAc::opmode_t
opmode_t
Common A/C settings for A/C operating modes.
Definition: IRsend.h:46