IRremoteESP8266: src/ir_Coolix.h Source File

IRremoteESP8266

ir_Coolix.h
Go to the documentation of this file.
1 // Copyright 2018 David Conran
9
10 // Supports:
11 // Brand: Beko, Model: RG57K7(B)/BGEF Remote
12 // Brand: Beko, Model: BINR 070/071 split-type A/C
13 // Brand: Midea, Model: RG52D/BGE Remote
14 // Brand: Midea, Model: MS12FU-10HRDN1-QRD0GW(B) A/C
15 // Brand: Midea, Model: MSABAU-07HRFN1-QRD0GW A/C (circa 2016)
16 // Brand: Tokio, Model: AATOEMF17-12CHR1SW split-type RG51|50/BGE Remote
17 // Brand: Airwell, Model: RC08B remote
18 // Brand: Kastron, Model: RG57A7/BGEF Inverter remote
19 // Brand: Kaysun, Model: Casual CF A/C
20
21 #ifndef IR_COOLIX_H_
22 #define IR_COOLIX_H_
23
24 #define __STDC_LIMIT_MACROS
25 #include <stdint.h>
26 #ifndef UNIT_TEST
27 #include <Arduino.h>
28 #endif
29 #include "IRremoteESP8266.h"
30 #include "IRsend.h"
31 #ifdef UNIT_TEST
32 #include "IRsend_test.h"
33 #endif
34
35 // Constants
36 // Modes
37 const uint8_t kCoolixCool = 0b000;
38 const uint8_t kCoolixDry = 0b001;
39 const uint8_t kCoolixAuto = 0b010;
40 const uint8_t kCoolixHeat = 0b011;
41 const uint8_t kCoolixFan = 0b100; // Synthetic.
42 // const uint32_t kCoolixModeMask = 0b000000000000000000001100; // 0xC
43 // const uint32_t kCoolixZoneFollowMask = 0b000010000000000000000010 0x80002
44 // Fan Control
45 const uint8_t kCoolixFanMin = 0b100;
46 const uint8_t kCoolixFanMed = 0b010;
47 const uint8_t kCoolixFanMax = 0b001;
48 const uint8_t kCoolixFanAuto = 0b101;
49 const uint8_t kCoolixFanAuto0 = 0b000;
50 const uint8_t kCoolixFanZoneFollow = 0b110;
51 const uint8_t kCoolixFanFixed = 0b111;
52 // Temperature
53 const uint8_t kCoolixTempMin = 17; // Celsius
54 const uint8_t kCoolixTempMax = 30; // Celsius
55 const uint8_t kCoolixTempRange = kCoolixTempMax - kCoolixTempMin + 1;
56 const uint8_t kCoolixFanTempCode = 0b1110; // Part of Fan Mode.
57 const uint8_t kCoolixTempMap[kCoolixTempRange] = {
58 0b0000, // 17C
59 0b0001, // 18c
60 0b0011, // 19C
61 0b0010, // 20C
62 0b0110, // 21C
63 0b0111, // 22C
64 0b0101, // 23C
65 0b0100, // 24C
66 0b1100, // 25C
67 0b1101, // 26C
68 0b1001, // 27C
69 0b1000, // 28C
70 0b1010, // 29C
71 0b1011 // 30C
72 };
73 const uint8_t kCoolixSensorTempMax = 30; // Celsius
74 const uint8_t kCoolixSensorTempIgnoreCode = 0b11111; // 0x1F / 31 (DEC)
75 // kCoolixSensorTempMask = 0b000000000000111100000000; // 0xF00
76 // Fixed states/messages.
77 const uint32_t kCoolixOff = 0b101100100111101111100000; // 0xB27BE0
78 const uint32_t kCoolixSwing = 0b101100100110101111100000; // 0xB26BE0
79 const uint32_t kCoolixSwingH = 0b101100101111010110100010; // 0xB5F5A2
80 const uint32_t kCoolixSwingV = 0b101100100000111111100000; // 0xB20FE0
81 const uint32_t kCoolixSleep = 0b101100101110000000000011; // 0xB2E003
82 const uint32_t kCoolixTurbo = 0b101101011111010110100010; // 0xB5F5A2
83 const uint32_t kCoolixLed = 0b101101011111010110100101; // 0xB5F5A5
84 const uint32_t kCoolixClean = 0b101101011111010110101010; // 0xB5F5AA
85 const uint32_t kCoolixCmdFan = 0b101100101011111111100100; // 0xB2BFE4
86 // On, 25C, Mode: Auto, Fan: Auto, Zone Follow: Off, Sensor Temp: Ignore.
87 const uint32_t kCoolixDefaultState = 0b101100100001111111001000; // 0xB21FC8
88
90 union CoolixProtocol {
91 uint32_t raw;
92 struct { // Only 24 bits are used.
93 // Byte
94 uint32_t :1; // Unknown
95 uint32_t ZoneFollow1:1;
96 uint32_t Mode :2;
97 uint32_t Temp :4;
98 // Byte
99 uint32_t SensorTemp :5;
100 uint32_t Fan :3;
101 // Byte
102 uint32_t :3; // Unknown
103 uint32_t ZoneFollow2:1;
104 uint32_t :4;
105 };
106 };
107
108 // Classes
109
112 class IRCoolixAC {
113 public:
114 explicit IRCoolixAC(const uint16_t pin, const bool inverted = false,
115 const bool use_modulation = true);
116 void stateReset(void);
117 #if SEND_COOLIX
118 void send(const uint16_t repeat = kCoolixDefaultRepeat);
123 int8_t calibrate(void) { return _irsend.calibrate(); }
124 #endif // SEND_COOLIX
125 void begin(void);
126 void on(void);
127 void off(void);
128 void setPower(const bool on);
129 bool getPower(void) const;
130 void setTemp(const uint8_t temp);
131 uint8_t getTemp(void) const;
132 void setSensorTemp(const uint8_t temp);
133 uint8_t getSensorTemp(void) const;
134 void clearSensorTemp(void);
135 void setFan(const uint8_t speed, const bool modecheck = true);
136 uint8_t getFan(void) const;
137 void setMode(const uint8_t mode);
138 uint8_t getMode(void) const;
139 void setSwing(void);
140 bool getSwing(void) const;
141 void setSwingVStep(void);
142 bool getSwingVStep(void) const;
143 void setSleep(void);
144 bool getSleep(void) const;
145 void setTurbo(void);
146 bool getTurbo(void) const;
147 void setLed(void);
148 bool getLed(void) const;
149 void setClean(void);
150 bool getClean(void) const;
151 bool getZoneFollow(void) const;
152 uint32_t getRaw(void) const;
153 void setRaw(const uint32_t new_code);
154 static uint8_t convertMode(const stdAc::opmode_t mode);
155 static uint8_t convertFan(const stdAc::fanspeed_t speed);
156 static stdAc::opmode_t toCommonMode(const uint8_t mode);
157 static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
158 stdAc::state_t toCommon(const stdAc::state_t *prev = NULL) const;
159 String toString(void) const;
160 #ifndef UNIT_TEST
161
162 private:
163 IRsend _irsend;
164 #else
165 IRsendTest _irsend;
167 #endif
169 CoolixProtocol _;
170 CoolixProtocol _saved;
171
172 // Internal State settings
173 bool powerFlag;
174 bool turboFlag;
175 bool ledFlag;
176 bool cleanFlag;
177 bool sleepFlag;
178 bool swingFlag;
179 uint8_t savedFan;
180
181 void setTempRaw(const uint8_t code);
182 uint8_t getTempRaw(void) const;
183 void setSensorTempRaw(const uint8_t code);
184 void setZoneFollow(const bool on);
185 bool isSpecialState(void) const;
186 bool handleSpecialState(const uint32_t data);
187 void updateAndSaveState(const uint32_t raw_state);
188 void recoverSavedState(void);
189 uint32_t getNormalState(void);
190 };
191
192 #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:187
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:1199
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:906
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