# IRremoteESP8266: src/ir_Tcl.h Source File

ir_Tcl.h
Go to the documentation of this file.
// Copyright 2019 David Conran
// Supports:
// Brand: Leberg, Model: LBS-TOR07 A/C
#ifndef IR_TCL_H_
#define IR_TCL_H_
#ifndef UNIT_TEST
#include <Arduino.h>
#endif
#include "IRremoteESP8266.h"
#include "IRsend.h"
#include "IRrecv.h"
#ifdef UNIT_TEST
#include "IRsend_test.h"
#endif
// Constants
const uint16_t kTcl112AcHdrMark = 3000;
const uint16_t kTcl112AcHdrSpace = 1650;
const uint16_t kTcl112AcBitMark = 500;
const uint16_t kTcl112AcOneSpace = 1050;
const uint16_t kTcl112AcZeroSpace = 325;
const uint32_t kTcl112AcGap = kDefaultMessageGap; // Just a guess.
// Total tolerance percentage to use for matching the header mark.
const uint8_t kTcl112AcHdrMarkTolerance = 6;
const uint8_t kTcl112AcTolerance = 5; // Extra Percentage for the rest.
const uint8_t kTcl112AcHeat = 1;
const uint8_t kTcl112AcDry = 2;
const uint8_t kTcl112AcCool = 3;
const uint8_t kTcl112AcFan = 7;
const uint8_t kTcl112AcAuto = 8;
const uint8_t kTcl112AcModeSize = 4; // Nr. of Bits
const uint8_t kTcl112AcFanSize = 3; // Nr. of Bits. Mask = 0b00000111
const uint8_t kTcl112AcFanAuto = 0b000;
const uint8_t kTcl112AcFanLow = 0b010;
const uint8_t kTcl112AcFanMed = 0b011;
const uint8_t kTcl112AcFanHigh = 0b101;
const uint8_t kTcl112AcHalfDegreeOffset = 5;
const float kTcl112AcTempMax = 31.0;
const float kTcl112AcTempMin = 16.0;
const uint8_t kTcl112AcPowerOffset = 2;
const uint8_t kTcl112AcBitEconoOffset = 7;
const uint8_t kTcl112AcBitLightOffset = 6;
const uint8_t kTcl112AcBitHealthOffset = 4;
const uint8_t kTcl112AcBitSwingHOffset = 3;
const uint8_t kTcl112AcSwingVOffset = 3; // Mask 0b00111000
const uint8_t kTcl112AcSwingVSize = 3; // Nr. of bits.
const uint8_t kTcl112AcSwingVOn = 0b111;
const uint8_t kTcl112AcSwingVOff = 0b000;
const uint8_t kTcl112AcBitTurboOffset = 6;
// Classes
class IRTcl112Ac {
public:
explicit IRTcl112Ac(const uint16_t pin, const bool inverted = false,
const bool use_modulation = true);
#if SEND_TCL112AC
void send(const uint16_t repeat = kTcl112AcDefaultRepeat);
int8_t calibrate(void) { return _irsend.calibrate(); }
#endif // SEND_TCL
void begin(void);
void stateReset(void);
uint8_t* getRaw(void);
void setRaw(const uint8_t new_code[],
const uint16_t length = kTcl112AcStateLength);
void on(void);
void off(void);
void setPower(const bool on);
bool getPower(void);
void setTemp(const float celsius); // Celsius in 0.5 increments
float getTemp(void);
void setMode(const uint8_t mode);
uint8_t getMode(void);
static uint8_t calcChecksum(uint8_t state[],
const uint16_t length = kTcl112AcStateLength);
static bool validChecksum(uint8_t state[],
const uint16_t length = kTcl112AcStateLength);
void setFan(const uint8_t speed);
uint8_t getFan(void);
void setEcono(const bool on);
bool getEcono(void);
void setHealth(const bool on);
bool getHealth(void);
void setLight(const bool on);
bool getLight(void);
void setSwingHorizontal(const bool on);
bool getSwingHorizontal(void);
void setSwingVertical(const bool on);
bool getSwingVertical(void);
void setTurbo(const bool on);
bool getTurbo(void);
uint8_t convertMode(const stdAc::opmode_t mode);
uint8_t convertFan(const stdAc::fanspeed_t speed);
static stdAc::opmode_t toCommonMode(const uint8_t mode);
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
stdAc::state_t toCommon(void);
String toString(void);
#ifndef UNIT_TEST
private:
IRsend _irsend;
#else // UNIT_TEST
IRsendTest _irsend;
#endif // UNIT_TEST
uint8_t remote_state[kTcl112AcStateLength];
void checksum(const uint16_t length = kTcl112AcStateLength);
};
#endif // IR_TCL_H_
IRTcl112Ac::getSwingHorizontal
bool getSwingHorizontal(void)
Get the horizontal swing setting of the A/C.
Definition: ir_Tcl.cpp:248
IRTcl112Ac::setSwingHorizontal
void setSwingHorizontal(const bool on)
Set the horizontal swing setting of the A/C.
Definition: ir_Tcl.cpp:242
kTcl112AcBitSwingHOffset
const uint8_t kTcl112AcBitSwingHOffset
Definition: ir_Tcl.h:54
IRTcl112Ac::convertFan
uint8_t convertFan(const stdAc::fanspeed_t speed)
Convert a stdAc::fanspeed_t enum into it's native speed.
Definition: ir_Tcl.cpp:297
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:66
kTcl112AcTempMin
const float kTcl112AcTempMin
Definition: ir_Tcl.h:48
IRTcl112Ac::setSwingVertical
void setSwingVertical(const bool on)
Set the vertical swing setting of the A/C.
Definition: ir_Tcl.cpp:254
IRTcl112Ac::getEcono
bool getEcono(void)
Get the economy setting of the A/C.
Definition: ir_Tcl.cpp:212
kTcl112AcHdrSpace
const uint16_t kTcl112AcHdrSpace
Definition: ir_Tcl.h:24
IRTcl112Ac::convertMode
uint8_t convertMode(const stdAc::opmode_t mode)
Convert a stdAc::opmode_t enum into its native mode.
Definition: ir_Tcl.cpp:284
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
IRTcl112Ac::toString
String toString(void)
Convert the current internal state into a human readable string.
Definition: ir_Tcl.cpp:363
kTcl112AcFanLow
const uint8_t kTcl112AcFanLow
Definition: ir_Tcl.h:42
IRTcl112Ac::send
void send(const uint16_t repeat=kTcl112AcDefaultRepeat)
Send the current internal state as an IR message.
Definition: ir_Tcl.cpp:57
kTcl112AcBitMark
const uint16_t kTcl112AcBitMark
Definition: ir_Tcl.h:25
kTcl112AcSwingVOffset
const uint8_t kTcl112AcSwingVOffset
Definition: ir_Tcl.h:55
kTcl112AcFanMed
const uint8_t kTcl112AcFanMed
Definition: ir_Tcl.h:43
IRTcl112Ac::getLight
bool getLight(void)
Get the Light (LED/Display) setting of the A/C.
Definition: ir_Tcl.cpp:236
IRTcl112Ac::getHealth
bool getHealth(void)
Get the Health (Filter) setting of the A/C.
Definition: ir_Tcl.cpp:224
IRsend.h
IRsend
Class for sending all basic IR protocols.
Definition: IRsend.h:182
IRTcl112Ac::setEcono
void setEcono(const bool on)
Set the economy setting of the A/C.
Definition: ir_Tcl.cpp:206
IRTcl112Ac::getFan
uint8_t getFan(void)
Get the current fan speed setting.
Definition: ir_Tcl.cpp:200
IRsend::calibrate
int8_t calibrate(uint16_t hz=38000U)
Calculate & set any offsets to account for execution times during sending.
Definition: IRsend.cpp:207
kTcl112AcBitLightOffset
const uint8_t kTcl112AcBitLightOffset
Definition: ir_Tcl.h:52
kTcl112AcOneSpace
const uint16_t kTcl112AcOneSpace
Definition: ir_Tcl.h:26
String
std::string String
Definition: IRremoteESP8266.h:1178
IRTcl112Ac::stateReset
void stateReset(void)
Reset the internal state of the emulation. (On, Cool, 24C)
Definition: ir_Tcl.cpp:90
IRTcl112Ac::getMode
uint8_t getMode(void)
Get the operating mode setting of the A/C.
Definition: ir_Tcl.cpp:132
IRTcl112Ac
Class for handling detailed TCL A/C messages.
Definition: ir_Tcl.h:63
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:75
IRTcl112Ac::toCommon
stdAc::state_t toCommon(void)
Convert the current internal state into its stdAc::state_t equivalent.
Definition: ir_Tcl.cpp:335
IRremoteESP8266.h
IRTcl112Ac::_irsend
IRsend _irsend
Instance of the IR send class.
Definition: ir_Tcl.h:115
IRTcl112Ac::setTemp
void setTemp(const float celsius)
Set the temperature.
Definition: ir_Tcl.cpp:160
IRTcl112Ac::getRaw
uint8_t * getRaw(void)
Get a PTR to the internal state/code for this protocol.
Definition: ir_Tcl.cpp:100
IRTcl112Ac::setLight
void setLight(const bool on)
Set the Light (LED/Display) setting of the A/C.
Definition: ir_Tcl.cpp:230
kTcl112AcHalfDegreeOffset
const uint8_t kTcl112AcHalfDegreeOffset
Definition: ir_Tcl.h:46
IRTcl112Ac::setPower
void setPower(const bool on)
Change the power setting.
Definition: ir_Tcl.cpp:120
IRTcl112Ac::calibrate
int8_t calibrate(void)
Run the calibration to calculate uSec timing offsets for this platform.
Definition: ir_Tcl.h:73
kTcl112AcGap
const uint32_t kTcl112AcGap
Definition: ir_Tcl.h:28
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:85
IRTcl112Ac::begin
void begin(void)
Set up hardware to be able to send a message.
Definition: ir_Tcl.cpp:52
kTcl112AcSwingVOn
const uint8_t kTcl112AcSwingVOn
Definition: ir_Tcl.h:57
kTcl112AcAuto
const uint8_t kTcl112AcAuto
Definition: ir_Tcl.h:37
kTcl112AcDefaultRepeat
const uint16_t kTcl112AcDefaultRepeat
Definition: IRremoteESP8266.h:1073
IRTcl112Ac::toCommonFanSpeed
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed)
Convert a native fan speed into its stdAc equivalent.
Definition: ir_Tcl.cpp:324
kTcl112AcTempMax
const float kTcl112AcTempMax
Definition: ir_Tcl.h:47
kTcl112AcHdrMark
const uint16_t kTcl112AcHdrMark
Definition: ir_Tcl.h:23
IRTcl112Ac::setMode
void setMode(const uint8_t mode)
Set the operating mode of the A/C.
Definition: ir_Tcl.cpp:140
kTcl112AcBitHealthOffset
const uint8_t kTcl112AcBitHealthOffset
Definition: ir_Tcl.h:53
kTcl112AcFanAuto
const uint8_t kTcl112AcFanAuto
Definition: ir_Tcl.h:41
kTcl112AcModeSize
const uint8_t kTcl112AcModeSize
Definition: ir_Tcl.h:38
kTcl112AcSwingVSize
const uint8_t kTcl112AcSwingVSize
Definition: ir_Tcl.h:56
kTcl112AcCool
const uint8_t kTcl112AcCool
Definition: ir_Tcl.h:35
IRTcl112Ac::getTemp
float getTemp(void)
Get the current temperature setting.
Definition: ir_Tcl.cpp:175
IRTcl112Ac::on
void on(void)
Set the requested power state of the A/C to on.
Definition: ir_Tcl.cpp:113
kTcl112AcFanSize
const uint8_t kTcl112AcFanSize
Definition: ir_Tcl.h:40
IRrecv.h
kTcl112AcPowerOffset
const uint8_t kTcl112AcPowerOffset
Definition: ir_Tcl.h:50
IRTcl112Ac::setHealth
void setHealth(const bool on)
Set the Health (Filter) setting of the A/C.
Definition: ir_Tcl.cpp:218
IRTcl112Ac::off
void off(void)
Set the requested power state of the A/C to off.
Definition: ir_Tcl.cpp:116
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:108
kTcl112AcSwingVOff
const uint8_t kTcl112AcSwingVOff
Definition: ir_Tcl.h:58
IRTcl112Ac::setFan
void setFan(const uint8_t speed)
Set the speed of the fan.
Definition: ir_Tcl.cpp:185
kTcl112AcHdrMarkTolerance
const uint8_t kTcl112AcHdrMarkTolerance
Definition: ir_Tcl.h:30
IRTcl112Ac::remote_state
uint8_t remote_state[kTcl112AcStateLength]
The State in IR code form.
Definition: ir_Tcl.h:121
kTcl112AcDry
const uint8_t kTcl112AcDry
Definition: ir_Tcl.h:34
kTcl112AcFanHigh
const uint8_t kTcl112AcFanHigh
Definition: ir_Tcl.h:44
kTcl112AcStateLength
const uint16_t kTcl112AcStateLength
Definition: IRremoteESP8266.h:1071
kTcl112AcFan
const uint8_t kTcl112AcFan
Definition: ir_Tcl.h:36
kTcl112AcBitTurboOffset
const uint8_t kTcl112AcBitTurboOffset
Definition: ir_Tcl.h:59
IRTcl112Ac::getPower
bool getPower(void)
Get the value of the current power setting.
Definition: ir_Tcl.cpp:126
kTcl112AcBitEconoOffset
const uint8_t kTcl112AcBitEconoOffset
Definition: ir_Tcl.h:51
kTcl112AcZeroSpace
const uint16_t kTcl112AcZeroSpace
Definition: ir_Tcl.h:27
IRTcl112Ac::toCommonMode
static stdAc::opmode_t toCommonMode(const uint8_t mode)
Convert a native mode into its stdAc equivalent.
Definition: ir_Tcl.cpp:311
IRTcl112Ac::setTurbo
void setTurbo(const bool on)
Set the Turbo setting of the A/C.
Definition: ir_Tcl.cpp:267
IRTcl112Ac::IRTcl112Ac
IRTcl112Ac(const uint16_t pin, const bool inverted=false, const bool use_modulation=true)
Class constructor.
Definition: ir_Tcl.cpp:47
IRTcl112Ac::getTurbo
bool getTurbo(void)
Get the Turbo setting of the A/C.
Definition: ir_Tcl.cpp:277
kTcl112AcTolerance
const uint8_t kTcl112AcTolerance
Definition: ir_Tcl.h:31
kTcl112AcHeat
const uint8_t kTcl112AcHeat
Definition: ir_Tcl.h:33
stdAc::state_t
Structure to hold a common A/C state.
Definition: IRsend.h:97
IRTcl112Ac::getSwingVertical
bool getSwingVertical(void)
Get the vertical swing setting of the A/C.
Definition: ir_Tcl.cpp:261
stdAc::opmode_t
opmode_t
Common A/C settings for A/C operating modes.
Definition: IRsend.h:46