IRremoteESP8266: src/ir_Tcl.h Source File

IRremoteESP8266

ir_Tcl.h
Go to the documentation of this file.
1 // Copyright 2019 David Conran
2
5
6 // Supports:
7 // Brand: Leberg, Model: LBS-TOR07 A/C
8
9 #ifndef IR_TCL_H_
10 #define IR_TCL_H_
11
12 #ifndef UNIT_TEST
13 #include <Arduino.h>
14 #endif
15 #include "IRremoteESP8266.h"
16 #include "IRsend.h"
17 #include "IRrecv.h"
18 #ifdef UNIT_TEST
19 #include "IRsend_test.h"
20 #endif
21
23 union Tcl112Protocol{
24 uint8_t raw[kTcl112AcStateLength];
25 struct {
26 // Byte 0~4
27 uint8_t pad0[5];
28 // Byte 5
29 uint8_t :2;
30 uint8_t Power :1;
31 uint8_t :3;
32 uint8_t Light :1;
33 uint8_t Econo :1;
34 // Byte 6
35 uint8_t Mode :4;
36 uint8_t Health :1;
37 uint8_t Turbo :1;
38 uint8_t :2;
39 // Byte 7
40 uint8_t Temp :4;
41 uint8_t :4;
42 // Byte 8
43 uint8_t Fan :3;
44 uint8_t SwingV :3;
45 uint8_t :2;
46 // Byte 9~11
47 uint8_t pad1[3];
48 // Byte 12
49 uint8_t :3;
50 uint8_t SwingH :1;
51 uint8_t :1;
52 uint8_t HalfDegree :1;
53 uint8_t :2;
54 // Byte 13
55 uint8_t Sum :8;
56 };
57 };
58
59 // Constants
60 const uint16_t kTcl112AcHdrMark = 3000;
61 const uint16_t kTcl112AcHdrSpace = 1650;
62 const uint16_t kTcl112AcBitMark = 500;
63 const uint16_t kTcl112AcOneSpace = 1050;
64 const uint16_t kTcl112AcZeroSpace = 325;
65 const uint32_t kTcl112AcGap = kDefaultMessageGap; // Just a guess.
66 // Total tolerance percentage to use for matching the header mark.
67 const uint8_t kTcl112AcHdrMarkTolerance = 6;
68 const uint8_t kTcl112AcTolerance = 5; // Extra Percentage for the rest.
69
70 const uint8_t kTcl112AcHeat = 1;
71 const uint8_t kTcl112AcDry = 2;
72 const uint8_t kTcl112AcCool = 3;
73 const uint8_t kTcl112AcFan = 7;
74 const uint8_t kTcl112AcAuto = 8;
75
76 const uint8_t kTcl112AcFanAuto = 0b000;
77 const uint8_t kTcl112AcFanLow = 0b010;
78 const uint8_t kTcl112AcFanMed = 0b011;
79 const uint8_t kTcl112AcFanHigh = 0b101;
80
81 const float kTcl112AcTempMax = 31.0;
82 const float kTcl112AcTempMin = 16.0;
83
84 const uint8_t kTcl112AcSwingVOn = 0b111;
85 const uint8_t kTcl112AcSwingVOff = 0b000;
86
87 // Classes
89 class IRTcl112Ac {
90 public:
91 explicit IRTcl112Ac(const uint16_t pin, const bool inverted = false,
92 const bool use_modulation = true);
93 #if SEND_TCL112AC
94 void send(const uint16_t repeat = kTcl112AcDefaultRepeat);
99 int8_t calibrate(void) { return _irsend.calibrate(); }
100 #endif // SEND_TCL
101 void begin(void);
102 void stateReset(void);
103 uint8_t* getRaw(void);
104 void setRaw(const uint8_t new_code[],
105 const uint16_t length = kTcl112AcStateLength);
106 void on(void);
107 void off(void);
108 void setPower(const bool on);
109 bool getPower(void) const;
110 void setTemp(const float celsius); // Celsius in 0.5 increments
111 float getTemp(void) const;
112 void setMode(const uint8_t mode);
113 uint8_t getMode(void) const;
114 static uint8_t calcChecksum(uint8_t state[],
115 const uint16_t length = kTcl112AcStateLength);
116 static bool validChecksum(uint8_t state[],
117 const uint16_t length = kTcl112AcStateLength);
118 void setFan(const uint8_t speed);
119 uint8_t getFan(void) const;
120 void setEcono(const bool on);
121 bool getEcono(void) const;
122 void setHealth(const bool on);
123 bool getHealth(void) const;
124 void setLight(const bool on);
125 bool getLight(void) const;
126 void setSwingHorizontal(const bool on);
127 bool getSwingHorizontal(void) const;
128 void setSwingVertical(const bool on);
129 bool getSwingVertical(void) const;
130 void setTurbo(const bool on);
131 bool getTurbo(void) const;
132 static uint8_t convertMode(const stdAc::opmode_t mode);
133 static uint8_t convertFan(const stdAc::fanspeed_t speed);
134 static stdAc::opmode_t toCommonMode(const uint8_t mode);
135 static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
136 stdAc::state_t toCommon(void) const;
137 String toString(void) const;
138 #ifndef UNIT_TEST
139
140 private:
141 IRsend _irsend;
142 #else // UNIT_TEST
143 IRsendTest _irsend;
145 #endif // UNIT_TEST
147 Tcl112Protocol _;
148 void checksum(const uint16_t length = kTcl112AcStateLength);
149 };
150
151 #endif // IR_TCL_H_
IRTcl112Ac::_
Tcl112Protocol _
Definition: ir_Tcl.h:147
IRTcl112Ac::setSwingHorizontal
void setSwingHorizontal(const bool on)
Set the horizontal swing setting of the A/C.
Definition: ir_Tcl.cpp:238
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:292
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:64
IRTcl112Ac::getMode
uint8_t getMode(void) const
Get the operating mode setting of the A/C.
Definition: ir_Tcl.cpp:130
kTcl112AcTempMin
const float kTcl112AcTempMin
Definition: ir_Tcl.h:82
IRTcl112Ac::setSwingVertical
void setSwingVertical(const bool on)
Set the vertical swing setting of the A/C.
Definition: ir_Tcl.cpp:250
kTcl112AcHdrSpace
const uint16_t kTcl112AcHdrSpace
Definition: ir_Tcl.h:61
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:279
Tcl112Protocol::SwingH
uint8_t SwingH
Definition: ir_Tcl.h:50
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:77
IRTcl112Ac::send
void send(const uint16_t repeat=kTcl112AcDefaultRepeat)
Send the current internal state as an IR message.
Definition: ir_Tcl.cpp:55
kTcl112AcBitMark
const uint16_t kTcl112AcBitMark
Definition: ir_Tcl.h:62
IRTcl112Ac::getEcono
bool getEcono(void) const
Get the economy setting of the A/C.
Definition: ir_Tcl.cpp:208
kTcl112AcFanMed
const uint8_t kTcl112AcFanMed
Definition: ir_Tcl.h:78
Tcl112Protocol::Temp
uint8_t Temp
Definition: ir_Tcl.h:40
IRsend.h
IRTcl112Ac::getSwingHorizontal
bool getSwingHorizontal(void) const
Get the horizontal swing setting of the A/C.
Definition: ir_Tcl.cpp:244
IRTcl112Ac::getTemp
float getTemp(void) const
Get the current temperature setting.
Definition: ir_Tcl.cpp:172
IRsend
Class for sending all basic IR protocols.
Definition: IRsend.h:187
IRTcl112Ac::setEcono
void setEcono(const bool on)
Set the economy setting of the A/C.
Definition: ir_Tcl.cpp:202
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::toCommon
stdAc::state_t toCommon(void) const
Convert the current internal state into its stdAc::state_t equivalent.
Definition: ir_Tcl.cpp:330
IRTcl112Ac::getHealth
bool getHealth(void) const
Get the Health (Filter) setting of the A/C.
Definition: ir_Tcl.cpp:220
kTcl112AcOneSpace
const uint16_t kTcl112AcOneSpace
Definition: ir_Tcl.h:63
String
std::string String
Definition: IRremoteESP8266.h:1199
IRTcl112Ac::stateReset
void stateReset(void)
Reset the internal state of the emulation. (On, Cool, 24C)
Definition: ir_Tcl.cpp:88
IRTcl112Ac
Class for handling detailed TCL A/C messages.
Definition: ir_Tcl.h:89
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:73
Tcl112Protocol::Turbo
uint8_t Turbo
Definition: ir_Tcl.h:37
IRremoteESP8266.h
Tcl112Protocol
Native representation of a TCL 112 A/C message.
Definition: ir_Tcl.h:23
Tcl112Protocol::HalfDegree
uint8_t HalfDegree
Definition: ir_Tcl.h:52
IRTcl112Ac::_irsend
IRsend _irsend
Instance of the IR send class.
Definition: ir_Tcl.h:141
IRTcl112Ac::setTemp
void setTemp(const float celsius)
Set the temperature.
Definition: ir_Tcl.cpp:158
IRTcl112Ac::getRaw
uint8_t * getRaw(void)
Get a PTR to the internal state/code for this protocol.
Definition: ir_Tcl.cpp:98
IRTcl112Ac::setLight
void setLight(const bool on)
Set the Light (LED/Display) setting of the A/C.
Definition: ir_Tcl.cpp:226
IRTcl112Ac::setPower
void setPower(const bool on)
Change the power setting.
Definition: ir_Tcl.cpp:118
IRTcl112Ac::calibrate
int8_t calibrate(void)
Run the calibration to calculate uSec timing offsets for this platform.
Definition: ir_Tcl.h:99
Tcl112Protocol::Light
uint8_t Light
Definition: ir_Tcl.h:32
kTcl112AcGap
const uint32_t kTcl112AcGap
Definition: ir_Tcl.h:65
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:83
Tcl112Protocol::Fan
uint8_t Fan
Definition: ir_Tcl.h:43
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:35
Tcl112Protocol::pad1
uint8_t pad1[3]
Definition: ir_Tcl.h:47
kTcl112AcSwingVOn
const uint8_t kTcl112AcSwingVOn
Definition: ir_Tcl.h:84
kTcl112AcAuto
const uint8_t kTcl112AcAuto
Definition: ir_Tcl.h:74
kTcl112AcDefaultRepeat
const uint16_t kTcl112AcDefaultRepeat
Definition: IRremoteESP8266.h:1091
IRTcl112Ac::toCommonFanSpeed
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed)
Convert a native fan speed into its stdAc equivalent.
Definition: ir_Tcl.cpp:319
kTcl112AcTempMax
const float kTcl112AcTempMax
Definition: ir_Tcl.h:81
kTcl112AcHdrMark
const uint16_t kTcl112AcHdrMark
Definition: ir_Tcl.h:60
IRTcl112Ac::getLight
bool getLight(void) const
Get the Light (LED/Display) setting of the A/C.
Definition: ir_Tcl.cpp:232
IRTcl112Ac::setMode
void setMode(const uint8_t mode)
Set the operating mode of the A/C.
Definition: ir_Tcl.cpp:138
kTcl112AcFanAuto
const uint8_t kTcl112AcFanAuto
Definition: ir_Tcl.h:76
kTcl112AcCool
const uint8_t kTcl112AcCool
Definition: ir_Tcl.h:72
IRTcl112Ac::on
void on(void)
Set the requested power state of the A/C to on.
Definition: ir_Tcl.cpp:111
IRrecv.h
Tcl112Protocol::SwingV
uint8_t SwingV
Definition: ir_Tcl.h:44
Tcl112Protocol::Health
uint8_t Health
Definition: ir_Tcl.h:36
Tcl112Protocol::pad0
uint8_t pad0[5]
Definition: ir_Tcl.h:27
Tcl112Protocol::raw
uint8_t raw[kTcl112AcStateLength]
The State in IR code form.
Definition: ir_Tcl.h:24
IRTcl112Ac::setHealth
void setHealth(const bool on)
Set the Health (Filter) setting of the A/C.
Definition: ir_Tcl.cpp:214
IRTcl112Ac::off
void off(void)
Set the requested power state of the A/C to off.
Definition: ir_Tcl.cpp:114
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:106
kTcl112AcSwingVOff
const uint8_t kTcl112AcSwingVOff
Definition: ir_Tcl.h:85
Tcl112Protocol::Sum
uint8_t Sum
Definition: ir_Tcl.h:55
IRTcl112Ac::setFan
void setFan(const uint8_t speed)
Set the speed of the fan.
Definition: ir_Tcl.cpp:181
kTcl112AcHdrMarkTolerance
const uint8_t kTcl112AcHdrMarkTolerance
Definition: ir_Tcl.h:67
kTcl112AcDry
const uint8_t kTcl112AcDry
Definition: ir_Tcl.h:71
IRTcl112Ac::getTurbo
bool getTurbo(void) const
Get the Turbo setting of the A/C.
Definition: ir_Tcl.cpp:272
kTcl112AcFanHigh
const uint8_t kTcl112AcFanHigh
Definition: ir_Tcl.h:79
IRTcl112Ac::getSwingVertical
bool getSwingVertical(void) const
Get the vertical swing setting of the A/C.
Definition: ir_Tcl.cpp:256
kTcl112AcStateLength
const uint16_t kTcl112AcStateLength
Definition: IRremoteESP8266.h:1089
kTcl112AcFan
const uint8_t kTcl112AcFan
Definition: ir_Tcl.h:73
IRTcl112Ac::toString
String toString(void) const
Convert the current internal state into a human readable string.
Definition: ir_Tcl.cpp:358
kTcl112AcZeroSpace
const uint16_t kTcl112AcZeroSpace
Definition: ir_Tcl.h:64
IRTcl112Ac::getPower
bool getPower(void) const
Get the value of the current power setting.
Definition: ir_Tcl.cpp:124
IRTcl112Ac::toCommonMode
static stdAc::opmode_t toCommonMode(const uint8_t mode)
Convert a native mode into its stdAc equivalent.
Definition: ir_Tcl.cpp:306
IRTcl112Ac::setTurbo
void setTurbo(const bool on)
Set the Turbo setting of the A/C.
Definition: ir_Tcl.cpp:262
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:68
kTcl112AcHeat
const uint8_t kTcl112AcHeat
Definition: ir_Tcl.h:70
IRTcl112Ac::getFan
uint8_t getFan(void) const
Get the current fan speed setting.
Definition: ir_Tcl.cpp:196
stdAc::state_t
Structure to hold a common A/C state.
Definition: IRsend.h:97
Tcl112Protocol::Econo
uint8_t Econo
Definition: ir_Tcl.h:33
Tcl112Protocol::Power
uint8_t Power
Definition: ir_Tcl.h:30
stdAc::opmode_t
opmode_t
Common A/C settings for A/C operating modes.
Definition: IRsend.h:46