2019-05-27 13:11:01 +01:00
|
|
|
// Copyright 2019 David Conran
|
|
|
|
|
2020-06-24 20:48:33 +01:00
|
|
|
/// @file
|
|
|
|
/// @brief Support for TCL protocols.
|
|
|
|
|
2019-07-21 15:01:43 +01:00
|
|
|
// Supports:
|
|
|
|
// Brand: Leberg, Model: LBS-TOR07 A/C
|
|
|
|
|
2019-05-27 13:11:01 +01:00
|
|
|
#ifndef IR_TCL_H_
|
|
|
|
#define IR_TCL_H_
|
|
|
|
|
|
|
|
#ifndef UNIT_TEST
|
|
|
|
#include <Arduino.h>
|
|
|
|
#endif
|
|
|
|
#include "IRremoteESP8266.h"
|
|
|
|
#include "IRsend.h"
|
2019-07-21 15:01:43 +01:00
|
|
|
#include "IRrecv.h"
|
2019-05-27 13:11:01 +01:00
|
|
|
#ifdef UNIT_TEST
|
|
|
|
#include "IRsend_test.h"
|
|
|
|
#endif
|
|
|
|
|
2021-02-13 13:51:52 +00:00
|
|
|
/// Native representation of a TCL 112 A/C message.
|
|
|
|
union Tcl112Protocol{
|
|
|
|
uint8_t raw[kTcl112AcStateLength]; ///< The State in IR code form.
|
|
|
|
struct {
|
|
|
|
// Byte 0~4
|
|
|
|
uint8_t pad0[5];
|
|
|
|
// Byte 5
|
|
|
|
uint8_t :2;
|
|
|
|
uint8_t Power :1;
|
|
|
|
uint8_t :3;
|
|
|
|
uint8_t Light :1;
|
|
|
|
uint8_t Econo :1;
|
|
|
|
// Byte 6
|
|
|
|
uint8_t Mode :4;
|
|
|
|
uint8_t Health :1;
|
|
|
|
uint8_t Turbo :1;
|
|
|
|
uint8_t :2;
|
|
|
|
// Byte 7
|
|
|
|
uint8_t Temp :4;
|
|
|
|
uint8_t :4;
|
|
|
|
// Byte 8
|
|
|
|
uint8_t Fan :3;
|
|
|
|
uint8_t SwingV :3;
|
|
|
|
uint8_t :2;
|
|
|
|
// Byte 9~11
|
|
|
|
uint8_t pad1[3];
|
|
|
|
// Byte 12
|
|
|
|
uint8_t :3;
|
|
|
|
uint8_t SwingH :1;
|
|
|
|
uint8_t :1;
|
|
|
|
uint8_t HalfDegree :1;
|
|
|
|
uint8_t :2;
|
|
|
|
// Byte 13
|
|
|
|
uint8_t Sum :8;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-05-27 13:11:01 +01:00
|
|
|
// 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.
|
2019-11-02 11:21:18 +00:00
|
|
|
// 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.
|
2019-05-27 13:11:01 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2019-11-02 11:21:18 +00:00
|
|
|
const uint8_t kTcl112AcFanAuto = 0b000;
|
|
|
|
const uint8_t kTcl112AcFanLow = 0b010;
|
|
|
|
const uint8_t kTcl112AcFanMed = 0b011;
|
|
|
|
const uint8_t kTcl112AcFanHigh = 0b101;
|
|
|
|
|
2019-05-27 13:11:01 +01:00
|
|
|
const float kTcl112AcTempMax = 31.0;
|
|
|
|
const float kTcl112AcTempMin = 16.0;
|
|
|
|
|
2019-11-02 11:21:18 +00:00
|
|
|
const uint8_t kTcl112AcSwingVOn = 0b111;
|
|
|
|
const uint8_t kTcl112AcSwingVOff = 0b000;
|
2019-05-27 13:11:01 +01:00
|
|
|
|
2020-06-24 20:48:33 +01:00
|
|
|
// Classes
|
|
|
|
/// Class for handling detailed TCL A/C messages.
|
2019-05-27 13:11:01 +01:00
|
|
|
class IRTcl112Ac {
|
|
|
|
public:
|
2019-07-21 15:01:43 +01:00
|
|
|
explicit IRTcl112Ac(const uint16_t pin, const bool inverted = false,
|
|
|
|
const bool use_modulation = true);
|
2019-05-27 13:11:01 +01:00
|
|
|
#if SEND_TCL112AC
|
|
|
|
void send(const uint16_t repeat = kTcl112AcDefaultRepeat);
|
2020-06-24 20:48:33 +01:00
|
|
|
/// Run the calibration to calculate uSec timing offsets for this platform.
|
|
|
|
/// @return The uSec timing offset needed per modulation of the IR Led.
|
|
|
|
/// @note This will produce a 65ms IR signal pulse at 38kHz.
|
|
|
|
/// Only ever needs to be run once per object instantiation, if at all.
|
2020-05-20 11:42:34 +01:00
|
|
|
int8_t calibrate(void) { return _irsend.calibrate(); }
|
2019-05-27 13:11:01 +01:00
|
|
|
#endif // SEND_TCL
|
|
|
|
void begin(void);
|
2020-06-24 20:48:33 +01:00
|
|
|
void stateReset(void);
|
2019-05-27 13:11:01 +01:00
|
|
|
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);
|
2021-02-13 13:51:52 +00:00
|
|
|
bool getPower(void) const;
|
2019-05-27 13:11:01 +01:00
|
|
|
void setTemp(const float celsius); // Celsius in 0.5 increments
|
2021-02-13 13:51:52 +00:00
|
|
|
float getTemp(void) const;
|
2019-05-27 13:11:01 +01:00
|
|
|
void setMode(const uint8_t mode);
|
2021-02-13 13:51:52 +00:00
|
|
|
uint8_t getMode(void) const;
|
2019-05-27 13:11:01 +01:00
|
|
|
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);
|
2021-02-13 13:51:52 +00:00
|
|
|
uint8_t getFan(void) const;
|
2019-05-27 13:11:01 +01:00
|
|
|
void setEcono(const bool on);
|
2021-02-13 13:51:52 +00:00
|
|
|
bool getEcono(void) const;
|
2019-05-27 13:11:01 +01:00
|
|
|
void setHealth(const bool on);
|
2021-02-13 13:51:52 +00:00
|
|
|
bool getHealth(void) const;
|
2019-05-27 13:11:01 +01:00
|
|
|
void setLight(const bool on);
|
2021-02-13 13:51:52 +00:00
|
|
|
bool getLight(void) const;
|
2019-05-27 13:11:01 +01:00
|
|
|
void setSwingHorizontal(const bool on);
|
2021-02-13 13:51:52 +00:00
|
|
|
bool getSwingHorizontal(void) const;
|
2019-05-27 13:11:01 +01:00
|
|
|
void setSwingVertical(const bool on);
|
2021-02-13 13:51:52 +00:00
|
|
|
bool getSwingVertical(void) const;
|
2019-05-27 13:11:01 +01:00
|
|
|
void setTurbo(const bool on);
|
2021-02-13 13:51:52 +00:00
|
|
|
bool getTurbo(void) const;
|
|
|
|
static uint8_t convertMode(const stdAc::opmode_t mode);
|
|
|
|
static uint8_t convertFan(const stdAc::fanspeed_t speed);
|
2019-07-21 15:01:43 +01:00
|
|
|
static stdAc::opmode_t toCommonMode(const uint8_t mode);
|
|
|
|
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
|
2021-02-13 13:51:52 +00:00
|
|
|
stdAc::state_t toCommon(void) const;
|
|
|
|
String toString(void) const;
|
2019-05-27 13:11:01 +01:00
|
|
|
#ifndef UNIT_TEST
|
|
|
|
|
|
|
|
private:
|
2020-06-24 20:48:33 +01:00
|
|
|
IRsend _irsend; ///< Instance of the IR send class
|
|
|
|
#else // UNIT_TEST
|
|
|
|
/// @cond IGNORE
|
|
|
|
IRsendTest _irsend; ///< Instance of the testing IR send class
|
|
|
|
/// @endcond
|
|
|
|
#endif // UNIT_TEST
|
2021-02-13 13:51:52 +00:00
|
|
|
Tcl112Protocol _;
|
2019-05-27 13:11:01 +01:00
|
|
|
void checksum(const uint16_t length = kTcl112AcStateLength);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // IR_TCL_H_
|