# IRremoteESP8266: src/ir_Coolix.h Source File

ir_Coolix.h
Go to the documentation of this file.
// Copyright 2018 David Conran
// Supports:
// Brand: Beko, Model: RG57K7(B)/BGEF Remote
// Brand: Beko, Model: BINR 070/071 split-type A/C
// Brand: Midea, Model: RG52D/BGE Remote
// Brand: Midea, Model: MS12FU-10HRDN1-QRD0GW(B) A/C
// Brand: Midea, Model: MSABAU-07HRFN1-QRD0GW A/C (circa 2016)
// Brand: Tokio, Model: AATOEMF17-12CHR1SW split-type RG51|50/BGE Remote
// Brand: Airwell, Model: RC08B remote
// Brand: Kastron, Model: RG57A7/BGEF Inverter remote
// Brand: Kaysun, Model: Casual CF A/C
#ifndef IR_COOLIX_H_
#define IR_COOLIX_H_
#define __STDC_LIMIT_MACROS
#include <stdint.h>
#ifndef UNIT_TEST
#include <Arduino.h>
#endif
#include "IRremoteESP8266.h"
#include "IRsend.h"
#ifdef UNIT_TEST
#include "IRsend_test.h"
#endif
// Constants
// Modes
const uint8_t kCoolixCool = 0b000;
const uint8_t kCoolixDry = 0b001;
const uint8_t kCoolixAuto = 0b010;
const uint8_t kCoolixHeat = 0b011;
const uint8_t kCoolixFan = 0b100; // Synthetic.
// const uint32_t kCoolixModeMask = 0b000000000000000000001100; // 0xC
// const uint32_t kCoolixZoneFollowMask = 0b000010000000000000000010 0x80002
// Fan Control
const uint8_t kCoolixFanMin = 0b100;
const uint8_t kCoolixFanMed = 0b010;
const uint8_t kCoolixFanMax = 0b001;
const uint8_t kCoolixFanAuto = 0b101;
const uint8_t kCoolixFanAuto0 = 0b000;
const uint8_t kCoolixFanZoneFollow = 0b110;
const uint8_t kCoolixFanFixed = 0b111;
// Temperature
const uint8_t kCoolixTempMin = 17; // Celsius
const uint8_t kCoolixTempMax = 30; // Celsius
const uint8_t kCoolixTempRange = kCoolixTempMax - kCoolixTempMin + 1;
const uint8_t kCoolixFanTempCode = 0b1110; // Part of Fan Mode.
const uint8_t kCoolixTempMap[kCoolixTempRange] = {
0b0000, // 17C
0b0001, // 18c
0b0011, // 19C
0b0010, // 20C
0b0110, // 21C
0b0111, // 22C
0b0101, // 23C
0b0100, // 24C
0b1100, // 25C
0b1101, // 26C
0b1001, // 27C
0b1000, // 28C
0b1010, // 29C
0b1011 // 30C
};
const uint8_t kCoolixSensorTempMax = 30; // Celsius
const uint8_t kCoolixSensorTempIgnoreCode = 0b11111; // 0x1F / 31 (DEC)
// kCoolixSensorTempMask = 0b000000000000111100000000; // 0xF00
// Fixed states/messages.
const uint32_t kCoolixOff = 0b101100100111101111100000; // 0xB27BE0
const uint32_t kCoolixSwing = 0b101100100110101111100000; // 0xB26BE0
const uint32_t kCoolixSwingH = 0b101100101111010110100010; // 0xB5F5A2
const uint32_t kCoolixSwingV = 0b101100100000111111100000; // 0xB20FE0
const uint32_t kCoolixSleep = 0b101100101110000000000011; // 0xB2E003
const uint32_t kCoolixTurbo = 0b101101011111010110100010; // 0xB5F5A2
const uint32_t kCoolixLed = 0b101101011111010110100101; // 0xB5F5A5
const uint32_t kCoolixClean = 0b101101011111010110101010; // 0xB5F5AA
const uint32_t kCoolixCmdFan = 0b101100101011111111100100; // 0xB2BFE4
// On, 25C, Mode: Auto, Fan: Auto, Zone Follow: Off, Sensor Temp: Ignore.
const uint32_t kCoolixDefaultState = 0b101100100001111111001000; // 0xB21FC8
union CoolixProtocol {
uint32_t raw;
struct { // Only 24 bits are used.
// Byte
uint32_t :1; // Unknown
uint32_t ZoneFollow1:1;
uint32_t Mode :2;
uint32_t Temp :4;
// Byte
uint32_t SensorTemp :5;
uint32_t Fan :3;
// Byte
uint32_t :3; // Unknown
uint32_t ZoneFollow2:1;
uint32_t :4;
};
};
// Classes
class IRCoolixAC {
public:
explicit IRCoolixAC(const uint16_t pin, const bool inverted = false,
const bool use_modulation = true);
void stateReset(void);
#if SEND_COOLIX
void send(const uint16_t repeat = kCoolixDefaultRepeat);
int8_t calibrate(void) { return _irsend.calibrate(); }
#endif // SEND_COOLIX
void begin(void);
void on(void);
void off(void);
void setPower(const bool on);
bool getPower(void) const;
void setTemp(const uint8_t temp);
uint8_t getTemp(void) const;
void setSensorTemp(const uint8_t temp);
uint8_t getSensorTemp(void) const;
void clearSensorTemp(void);
void setFan(const uint8_t speed, const bool modecheck = true);
uint8_t getFan(void) const;
void setMode(const uint8_t mode);
uint8_t getMode(void) const;
void setSwing(void);
bool getSwing(void) const;
void setSwingVStep(void);
bool getSwingVStep(void) const;
void setSleep(void);
bool getSleep(void) const;
void setTurbo(void);
bool getTurbo(void) const;
void setLed(void);
bool getLed(void) const;
void setClean(void);
bool getClean(void) const;
bool getZoneFollow(void) const;
uint32_t getRaw(void) const;
void setRaw(const uint32_t new_code);
static uint8_t convertMode(const stdAc::opmode_t mode);
static 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(const stdAc::state_t *prev = NULL) const;
String toString(void) const;
#ifndef UNIT_TEST
private:
IRsend _irsend;
#else
IRsendTest _irsend;
#endif
CoolixProtocol _;
CoolixProtocol _saved;
// Internal State settings
bool powerFlag;
bool turboFlag;
bool ledFlag;
bool cleanFlag;
bool sleepFlag;
bool swingFlag;
uint8_t savedFan;
void setTempRaw(const uint8_t code);
uint8_t getTempRaw(void) const;
void setSensorTempRaw(const uint8_t code);
void setZoneFollow(const bool on);
bool isSpecialState(void) const;
bool handleSpecialState(const uint32_t data);
void updateAndSaveState(const uint32_t raw_state);
void recoverSavedState(void);
uint32_t getNormalState(void);
};
#endif // IR_COOLIX_H_
IRCoolixAC::getSwing
bool getSwing(void) const
Get the Swing setting of the A/C.
Definition: ir_Coolix.cpp:280
kCoolixFanZoneFollow
const uint8_t kCoolixFanZoneFollow
Definition: ir_Coolix.h:50
IRCoolixAC::getClean
bool getClean(void) const
Get the Clean setting of the A/C.
Definition: ir_Coolix.cpp:332
IRCoolixAC::getNormalState
uint32_t getNormalState(void)
IRCoolixAC::savedFan
uint8_t savedFan
Definition: ir_Coolix.h:179
IRCoolixAC::setTempRaw
void setTempRaw(const uint8_t code)
Set the raw (native) temperature value.
Definition: ir_Coolix.cpp:213
IRCoolixAC::getFan
uint8_t getFan(void) const
Get the current fan speed setting.
Definition: ir_Coolix.cpp:400
IRCoolixAC::setSensorTempRaw
void setSensorTempRaw(const uint8_t code)
Set the raw (native) sensor temperature value.
Definition: ir_Coolix.cpp:240
kCoolixFanMin
const uint8_t kCoolixFanMin
Definition: ir_Coolix.h:45
IRCoolixAC::calibrate
int8_t calibrate(void)
Run the calibration to calculate uSec timing offsets for this platform.
Definition: ir_Coolix.h:123
IRCoolixAC::setZoneFollow
void setZoneFollow(const bool on)
Change the Zone Follow setting.
Definition: ir_Coolix.cpp:349
IRCoolixAC::setMode
void setMode(const uint8_t mode)
Set the operating mode of the A/C.
Definition: ir_Coolix.cpp:363
kCoolixSwingH
const uint32_t kCoolixSwingH
Definition: ir_Coolix.h:79
IRCoolixAC::getRaw
uint32_t getRaw(void) const
Get a copy of the internal state as a valid code for this protocol.
Definition: ir_Coolix.cpp:124
IRCoolixAC::send
void send(const uint16_t repeat=kCoolixDefaultRepeat)
Send the current internal state as an IR message.
Definition: ir_Coolix.cpp:109
IRCoolixAC::clearSensorTemp
void clearSensorTemp(void)
Clear the Sensor Temperature setting..
Definition: ir_Coolix.cpp:356
IRCoolixAC::on
void on(void)
Change the power setting to On.
Definition: ir_Coolix.cpp:273
kCoolixFanAuto0
const uint8_t kCoolixFanAuto0
Definition: ir_Coolix.h:49
stdAc::fanspeed_t
fanspeed_t
Common A/C settings for Fan Speeds.
Definition: IRsend.h:58
kCoolixDry
const uint8_t kCoolixDry
Definition: ir_Coolix.h:38
IRCoolixAC::getLed
bool getLed(void) const
Get the Led (light) setting of the A/C.
Definition: ir_Coolix.cpp:321
IRCoolixAC::getTurbo
bool getTurbo(void) const
Get the Turbo setting of the A/C.
Definition: ir_Coolix.cpp:310
kCoolixFanMed
const uint8_t kCoolixFanMed
Definition: ir_Coolix.h:46
IRCoolixAC::_irsend
IRsend _irsend
Instance of the IR send class.
Definition: ir_Coolix.h:163
IRCoolixAC::turboFlag
bool turboFlag
Definition: ir_Coolix.h:174
IRsend.h
IRCoolixAC::ledFlag
bool ledFlag
Definition: ir_Coolix.h:175
kCoolixSwing
const uint32_t kCoolixSwing
Definition: ir_Coolix.h:78
IRCoolixAC::setLed
void setLed(void)
Toggle the Led (light) mode of the A/C.
Definition: ir_Coolix.cpp:324
kCoolixCool
const uint8_t kCoolixCool
Definition: ir_Coolix.h:37
kCoolixAuto
const uint8_t kCoolixAuto
Definition: ir_Coolix.h:39
IRsend
Class for sending all basic IR protocols.
Definition: IRsend.h:182
IRCoolixAC::cleanFlag
bool cleanFlag
Definition: ir_Coolix.h:176
IRCoolixAC::toCommonFanSpeed
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed)
Convert a native fan speed into its stdAc equivalent.
Definition: ir_Coolix.cpp:485
CoolixProtocol
Native representation of a Coolix A/C message.
Definition: ir_Coolix.h:90
IRsend::calibrate
int8_t calibrate(uint16_t hz=38000U)
Calculate & set any offsets to account for execution times during sending.
Definition: IRsend.cpp:207
kCoolixHeat
const uint8_t kCoolixHeat
Definition: ir_Coolix.h:40
IRCoolixAC::convertMode
static uint8_t convertMode(const stdAc::opmode_t mode)
Convert a standard A/C mode into its native mode.
Definition: ir_Coolix.cpp:445
kCoolixOff
const uint32_t kCoolixOff
Definition: ir_Coolix.h:77
String
std::string String
Definition: IRremoteESP8266.h:1178
IRCoolixAC::recoverSavedState
void recoverSavedState(void)
Restore the current internal state from backup as long as it isn't a special state.
Definition: ir_Coolix.cpp:202
kCoolixFanTempCode
const uint8_t kCoolixFanTempCode
Definition: ir_Coolix.h:56
IRCoolixAC::setSensorTemp
void setSensorTemp(const uint8_t temp)
Set the sensor temperature.
Definition: ir_Coolix.cpp:246
IRCoolixAC::setTurbo
void setTurbo(void)
Toggle the Turbo mode of the A/C.
Definition: ir_Coolix.cpp:313
IRCoolixAC::getTemp
uint8_t getTemp(void) const
Get the current temperature setting.
Definition: ir_Coolix.cpp:230
IRCoolixAC::off
void off(void)
Change the power setting to Off.
Definition: ir_Coolix.cpp:276
IRremoteESP8266.h
CoolixProtocol::Fan
uint32_t Fan
Fan speed.
Definition: ir_Coolix.h:100
kCoolixTempMap
const uint8_t kCoolixTempMap[kCoolixTempRange]
Definition: ir_Coolix.h:57
kCoolixClean
const uint32_t kCoolixClean
Definition: ir_Coolix.h:84
IRCoolixAC::_
CoolixProtocol _
The state of the IR remote in IR code form.
Definition: ir_Coolix.h:169
kCoolixFanFixed
const uint8_t kCoolixFanFixed
Definition: ir_Coolix.h:51
IRCoolixAC::stateReset
void stateReset(void)
Reset the internal state to a fixed known good state.
Definition: ir_Coolix.cpp:91
IRCoolixAC::getSleep
bool getSleep(void) const
Get the Sleep setting of the A/C.
Definition: ir_Coolix.cpp:300
kCoolixDefaultState
const uint32_t kCoolixDefaultState
Definition: ir_Coolix.h:87
CoolixProtocol::SensorTemp
uint32_t SensorTemp
The temperature sensor in the IR remote.
Definition: ir_Coolix.h:99
kCoolixDefaultRepeat
const uint16_t kCoolixDefaultRepeat
Definition: IRremoteESP8266.h:890
IRCoolixAC::convertFan
static uint8_t convertFan(const stdAc::fanspeed_t speed)
Convert a stdAc::fanspeed_t enum into it's native speed.
Definition: ir_Coolix.cpp:458
IRCoolixAC::toCommonMode
static stdAc::opmode_t toCommonMode(const uint8_t mode)
Convert a native mode to it's common stdAc::opmode_t equivalent.
Definition: ir_Coolix.cpp:472
IRCoolixAC::setTemp
void setTemp(const uint8_t temp)
Set the temperature.
Definition: ir_Coolix.cpp:221
IRCoolixAC::setSwingVStep
void setSwingVStep(void)
Set the Vertical Swing Step setting of the A/C.
Definition: ir_Coolix.cpp:294
IRCoolixAC::getSensorTemp
uint8_t getSensorTemp(void) const
Get the sensor temperature setting.
Definition: ir_Coolix.cpp:253
IRCoolixAC
Class for handling detailed Coolix A/C messages.
Definition: ir_Coolix.h:112
IRCoolixAC::getTempRaw
uint8_t getTempRaw(void) const
Get the raw (native) temperature value.
Definition: ir_Coolix.cpp:217
IRCoolixAC::getZoneFollow
bool getZoneFollow(void) const
Get the Zone Follow setting of the A/C.
Definition: ir_Coolix.cpp:342
IRCoolixAC::_saved
CoolixProtocol _saved
Copy of the state if we required a special mode.
Definition: ir_Coolix.h:170
IRCoolixAC::setClean
void setClean(void)
Toggle the Clean mode of the A/C.
Definition: ir_Coolix.cpp:335
kCoolixLed
const uint32_t kCoolixLed
Definition: ir_Coolix.h:83
IRCoolixAC::setSwing
void setSwing(void)
Toggle the Swing mode of the A/C.
Definition: ir_Coolix.cpp:283
IRCoolixAC::setRaw
void setRaw(const uint32_t new_code)
Set the internal state from a valid code for this protocol.
Definition: ir_Coolix.cpp:128
CoolixProtocol::Mode
uint32_t Mode
Operation mode.
Definition: ir_Coolix.h:96
kCoolixCmdFan
const uint32_t kCoolixCmdFan
Definition: ir_Coolix.h:85
CoolixProtocol::raw
uint32_t raw
The state in IR code form.
Definition: ir_Coolix.h:91
kCoolixTempMax
const uint8_t kCoolixTempMax
Definition: ir_Coolix.h:54
IRCoolixAC::swingFlag
bool swingFlag
Definition: ir_Coolix.h:178
kCoolixFan
const uint8_t kCoolixFan
Definition: ir_Coolix.h:41
IRCoolixAC::begin
void begin(void)
Set up hardware to be able to send a message.
Definition: ir_Coolix.cpp:104
kCoolixSwingV
const uint32_t kCoolixSwingV
Definition: ir_Coolix.h:80
IRCoolixAC::updateAndSaveState
void updateAndSaveState(const uint32_t raw_state)
Backup the current internal state as long as it isn't a special state and set the new state.
Definition: ir_Coolix.cpp:195
IRCoolixAC::getMode
uint8_t getMode(void) const
Get the operating mode setting of the A/C.
Definition: ir_Coolix.cpp:391
IRCoolixAC::sleepFlag
bool sleepFlag
Definition: ir_Coolix.h:177
kCoolixSleep
const uint32_t kCoolixSleep
Definition: ir_Coolix.h:81
CoolixProtocol::ZoneFollow2
uint32_t ZoneFollow2
Additional control bit for Zone Follow mode.
Definition: ir_Coolix.h:103
IRCoolixAC::IRCoolixAC
IRCoolixAC(const uint16_t pin, const bool inverted=false, const bool use_modulation=true)
Class constructor.
Definition: ir_Coolix.cpp:86
IRCoolixAC::isSpecialState
bool isSpecialState(void) const
Is the current state is a special state?
Definition: ir_Coolix.cpp:144
kCoolixTempRange
const uint8_t kCoolixTempRange
Definition: ir_Coolix.h:55
kCoolixTempMin
const uint8_t kCoolixTempMin
Definition: ir_Coolix.h:53
IRCoolixAC::setSleep
void setSleep(void)
Toggle the Sleep mode of the A/C.
Definition: ir_Coolix.cpp:303
kCoolixSensorTempMax
const uint8_t kCoolixSensorTempMax
Definition: ir_Coolix.h:73
IRCoolixAC::toCommon
stdAc::state_t toCommon(const stdAc::state_t *prev=NULL) const
Convert the A/C state to it's common stdAc::state_t equivalent.
Definition: ir_Coolix.cpp:497
kCoolixFanMax
const uint8_t kCoolixFanMax
Definition: ir_Coolix.h:47
IRCoolixAC::getPower
bool getPower(void) const
Get the value of the current power setting.
Definition: ir_Coolix.cpp:258
kCoolixFanAuto
const uint8_t kCoolixFanAuto
Definition: ir_Coolix.h:48
IRCoolixAC::powerFlag
bool powerFlag
Definition: ir_Coolix.h:173
CoolixProtocol::Temp
uint32_t Temp
Desired temperature (Celsius)
Definition: ir_Coolix.h:97
IRCoolixAC::toString
String toString(void) const
Convert the internal state into a human readable string.
Definition: ir_Coolix.cpp:556
CoolixProtocol::ZoneFollow1
uint32_t ZoneFollow1
Control bit for Zone Follow mode.
Definition: ir_Coolix.h:95
IRCoolixAC::getSwingVStep
bool getSwingVStep(void) const
Get the Vertical Swing Step setting of the A/C.
Definition: ir_Coolix.cpp:291
IRCoolixAC::setFan
void setFan(const uint8_t speed, const bool modecheck=true)
Set the speed of the fan.
Definition: ir_Coolix.cpp:405
IRCoolixAC::handleSpecialState
bool handleSpecialState(const uint32_t data)
Adjust any internal settings based on the type of special state we are supplied. Does nothing if it i...
Definition: ir_Coolix.cpp:164
stdAc::state_t
Structure to hold a common A/C state.
Definition: IRsend.h:97
kCoolixSensorTempIgnoreCode
const uint8_t kCoolixSensorTempIgnoreCode
Definition: ir_Coolix.h:74
IRCoolixAC::setPower
void setPower(const bool on)
Change the power setting.
Definition: ir_Coolix.cpp:262
kCoolixTurbo
const uint32_t kCoolixTurbo
Definition: ir_Coolix.h:82
stdAc::opmode_t
opmode_t
Common A/C settings for A/C operating modes.
Definition: IRsend.h:46