IRremoteESP8266
ir_Coolix.h
Go to the documentation of this file.
1 // Copyright 2018 David Conran
11 
12 // Supports:
13 // Brand: Beko, Model: RG57K7(B)/BGEF Remote
14 // Brand: Beko, Model: BINR 070/071 split-type A/C
15 // Brand: Midea, Model: RG52D/BGE Remote
16 // Brand: Midea, Model: MS12FU-10HRDN1-QRD0GW(B) A/C
17 // Brand: Midea, Model: MSABAU-07HRFN1-QRD0GW A/C (circa 2016)
18 // Brand: Tokio, Model: AATOEMF17-12CHR1SW split-type RG51|50/BGE Remote
19 // Brand: Airwell, Model: RC08B remote
20 // Brand: Kastron, Model: RG57A7/BGEF Inverter remote
21 // Brand: Kaysun, Model: Casual CF A/C
22 // Brand: Toshiba, Model: RAS-M10YKV-E A/C
23 // Brand: Toshiba, Model: RAS-M13YKV-E A/C
24 // Brand: Toshiba, Model: RAS-4M27YAV-E A/C
25 // Brand: Toshiba, Model: WH-E1YE remote
26 // Brand: Bosch, Model: RG36B4/BGE remote
27 // Brand: Bosch, Model: B1ZAI2441W/B1ZAO2441W A/C
28 
29 #ifndef IR_COOLIX_H_
30 #define IR_COOLIX_H_
31 
32 #define __STDC_LIMIT_MACROS
33 #include <stdint.h>
34 #ifndef UNIT_TEST
35 #include <Arduino.h>
36 #endif
37 #include "IRremoteESP8266.h"
38 #include "IRsend.h"
39 #ifdef UNIT_TEST
40 #include "IRsend_test.h"
41 #endif
42 
43 // Constants
44 // Modes
45 const uint8_t kCoolixCool = 0b000;
46 const uint8_t kCoolixDry = 0b001;
47 const uint8_t kCoolixAuto = 0b010;
48 const uint8_t kCoolixHeat = 0b011;
49 const uint8_t kCoolixFan = 0b100; // Synthetic.
50 // const uint32_t kCoolixModeMask = 0b000000000000000000001100; // 0xC
51 // const uint32_t kCoolixZoneFollowMask = 0b000010000000000000000010 0x80002
52 // Fan Control
53 const uint8_t kCoolixFanMin = 0b100;
54 const uint8_t kCoolixFanMed = 0b010;
55 const uint8_t kCoolixFanMax = 0b001;
56 const uint8_t kCoolixFanAuto = 0b101;
57 const uint8_t kCoolixFanAuto0 = 0b000;
58 const uint8_t kCoolixFanZoneFollow = 0b110;
59 const uint8_t kCoolixFanFixed = 0b111;
60 // Temperature
61 const uint8_t kCoolixTempMin = 17; // Celsius
62 const uint8_t kCoolixTempMax = 30; // Celsius
64 const uint8_t kCoolixFanTempCode = 0b1110; // Part of Fan Mode.
65 const uint8_t kCoolixTempMap[kCoolixTempRange] = {
66  0b0000, // 17C
67  0b0001, // 18c
68  0b0011, // 19C
69  0b0010, // 20C
70  0b0110, // 21C
71  0b0111, // 22C
72  0b0101, // 23C
73  0b0100, // 24C
74  0b1100, // 25C
75  0b1101, // 26C
76  0b1001, // 27C
77  0b1000, // 28C
78  0b1010, // 29C
79  0b1011 // 30C
80 };
81 const uint8_t kCoolixSensorTempMax = 30; // Celsius
82 const uint8_t kCoolixSensorTempIgnoreCode = 0b11111; // 0x1F / 31 (DEC)
83 // kCoolixSensorTempMask = 0b000000000000111100000000; // 0xF00
84 // Fixed states/messages.
85 const uint32_t kCoolixOff = 0b101100100111101111100000; // 0xB27BE0
86 const uint32_t kCoolixSwing = 0b101100100110101111100000; // 0xB26BE0
87 const uint32_t kCoolixSwingH = 0b101100101111010110100010; // 0xB5F5A2
88 const uint32_t kCoolixSwingV = 0b101100100000111111100000; // 0xB20FE0
89 const uint32_t kCoolixSleep = 0b101100101110000000000011; // 0xB2E003
90 const uint32_t kCoolixTurbo = 0b101101011111010110100010; // 0xB5F5A2
91 const uint32_t kCoolixLed = 0b101101011111010110100101; // 0xB5F5A5
92 const uint32_t kCoolixClean = 0b101101011111010110101010; // 0xB5F5AA
93 const uint32_t kCoolixCmdFan = 0b101100101011111111100100; // 0xB2BFE4
94 // On, 25C, Mode: Auto, Fan: Auto, Zone Follow: Off, Sensor Temp: Ignore.
95 const uint32_t kCoolixDefaultState = 0b101100100001111111001000; // 0xB21FC8
96 
99  uint32_t raw;
100  struct { // Only 24 bits are used.
101  // Byte
102  uint32_t :1; // Unknown
103  uint32_t ZoneFollow1:1;
104  uint32_t Mode :2;
105  uint32_t Temp :4;
106  // Byte
107  uint32_t SensorTemp :5;
108  uint32_t Fan :3;
109  // Byte
110  uint32_t :3; // Unknown
111  uint32_t ZoneFollow2:1;
112  uint32_t :4;
113  };
114 };
115 
116 // Classes
117 
120 class IRCoolixAC {
121  public:
122  explicit IRCoolixAC(const uint16_t pin, const bool inverted = false,
123  const bool use_modulation = true);
124  void stateReset(void);
125 #if SEND_COOLIX
126  void send(const uint16_t repeat = kCoolixDefaultRepeat);
131  int8_t calibrate(void) { return _irsend.calibrate(); }
132 #endif // SEND_COOLIX
133  void begin(void);
134  void on(void);
135  void off(void);
136  void setPower(const bool on);
137  bool getPower(void) const;
138  void setTemp(const uint8_t temp);
139  uint8_t getTemp(void) const;
140  void setSensorTemp(const uint8_t temp);
141  uint8_t getSensorTemp(void) const;
142  void clearSensorTemp(void);
143  void setFan(const uint8_t speed, const bool modecheck = true);
144  uint8_t getFan(void) const;
145  void setMode(const uint8_t mode);
146  uint8_t getMode(void) const;
147  void setSwing(void);
148  bool getSwing(void) const;
149  void setSwingVStep(void);
150  bool getSwingVStep(void) const;
151  void setSleep(void);
152  bool getSleep(void) const;
153  void setTurbo(void);
154  bool getTurbo(void) const;
155  void setLed(void);
156  bool getLed(void) const;
157  void setClean(void);
158  bool getClean(void) const;
159  bool getZoneFollow(void) const;
160  uint32_t getRaw(void) const;
161  void setRaw(const uint32_t new_code);
162  static uint8_t convertMode(const stdAc::opmode_t mode);
163  static uint8_t convertFan(const stdAc::fanspeed_t speed);
164  static stdAc::opmode_t toCommonMode(const uint8_t mode);
165  static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
166  stdAc::state_t toCommon(const stdAc::state_t *prev = NULL) const;
167  String toString(void) const;
168  void setZoneFollow(const bool on);
169 #ifndef UNIT_TEST
170 
171  private:
173 #else
174  IRsendTest _irsend;
176 #endif
180 
181  // Internal State settings
182  bool powerFlag;
183  bool turboFlag;
184  bool ledFlag;
185  bool cleanFlag;
186  bool sleepFlag;
187  bool swingFlag;
188  uint8_t savedFan;
189 
190  void setTempRaw(const uint8_t code);
191  uint8_t getTempRaw(void) const;
192  void setSensorTempRaw(const uint8_t code);
193  bool isSpecialState(void) const;
194  bool handleSpecialState(const uint32_t data);
195  void updateAndSaveState(const uint32_t raw_state);
196  void recoverSavedState(void);
197  uint32_t getNormalState(void);
198 };
199 
200 #endif // IR_COOLIX_H_
IRCoolixAC::getSwing
bool getSwing(void) const
Get the Swing setting of the A/C.
Definition: ir_Coolix.cpp:281
kCoolixFanZoneFollow
const uint8_t kCoolixFanZoneFollow
Definition: ir_Coolix.h:58
IRCoolixAC::getClean
bool getClean(void) const
Get the Clean setting of the A/C.
Definition: ir_Coolix.cpp:333
IRCoolixAC::getNormalState
uint32_t getNormalState(void)
IRCoolixAC::savedFan
uint8_t savedFan
Definition: ir_Coolix.h:188
IRCoolixAC::setTempRaw
void setTempRaw(const uint8_t code)
Set the raw (native) temperature value.
Definition: ir_Coolix.cpp:214
IRCoolixAC::getFan
uint8_t getFan(void) const
Get the current fan speed setting.
Definition: ir_Coolix.cpp:401
IRCoolixAC::setSensorTempRaw
void setSensorTempRaw(const uint8_t code)
Set the raw (native) sensor temperature value.
Definition: ir_Coolix.cpp:241
kCoolixFanMin
const uint8_t kCoolixFanMin
Definition: ir_Coolix.h:53
IRCoolixAC::calibrate
int8_t calibrate(void)
Run the calibration to calculate uSec timing offsets for this platform.
Definition: ir_Coolix.h:131
IRCoolixAC::setZoneFollow
void setZoneFollow(const bool on)
Change the Zone Follow setting.
Definition: ir_Coolix.cpp:350
IRCoolixAC::setMode
void setMode(const uint8_t mode)
Set the operating mode of the A/C.
Definition: ir_Coolix.cpp:364
kCoolixSwingH
const uint32_t kCoolixSwingH
Definition: ir_Coolix.h:87
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:125
IRCoolixAC::send
void send(const uint16_t repeat=kCoolixDefaultRepeat)
Send the current internal state as an IR message.
Definition: ir_Coolix.cpp:110
IRCoolixAC::clearSensorTemp
void clearSensorTemp(void)
Clear the Sensor Temperature setting..
Definition: ir_Coolix.cpp:357
IRCoolixAC::on
void on(void)
Change the power setting to On.
Definition: ir_Coolix.cpp:274
kCoolixFanAuto0
const uint8_t kCoolixFanAuto0
Definition: ir_Coolix.h:57
stdAc::fanspeed_t
fanspeed_t
Common A/C settings for Fan Speeds.
Definition: IRsend.h:61
kCoolixDry
const uint8_t kCoolixDry
Definition: ir_Coolix.h:46
IRCoolixAC::getLed
bool getLed(void) const
Get the Led (light) setting of the A/C.
Definition: ir_Coolix.cpp:322
IRCoolixAC::getTurbo
bool getTurbo(void) const
Get the Turbo setting of the A/C.
Definition: ir_Coolix.cpp:311
kCoolixFanMed
const uint8_t kCoolixFanMed
Definition: ir_Coolix.h:54
IRCoolixAC::_irsend
IRsend _irsend
Instance of the IR send class.
Definition: ir_Coolix.h:172
IRCoolixAC::turboFlag
bool turboFlag
Definition: ir_Coolix.h:183
IRsend.h
IRCoolixAC::ledFlag
bool ledFlag
Definition: ir_Coolix.h:184
kCoolixSwing
const uint32_t kCoolixSwing
Definition: ir_Coolix.h:86
IRCoolixAC::setLed
void setLed(void)
Toggle the Led (light) mode of the A/C.
Definition: ir_Coolix.cpp:325
kCoolixCool
const uint8_t kCoolixCool
Definition: ir_Coolix.h:45
kCoolixAuto
const uint8_t kCoolixAuto
Definition: ir_Coolix.h:47
IRsend
Class for sending all basic IR protocols.
Definition: IRsend.h:237
IRCoolixAC::cleanFlag
bool cleanFlag
Definition: ir_Coolix.h:185
IRCoolixAC::toCommonFanSpeed
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed)
Convert a native fan speed into its stdAc equivalent.
Definition: ir_Coolix.cpp:486
CoolixProtocol
Native representation of a Coolix A/C message.
Definition: ir_Coolix.h:98
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:48
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:446
kCoolixOff
const uint32_t kCoolixOff
Definition: ir_Coolix.h:85
String
std::string String
Definition: IRremoteESP8266.h:1521
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:203
kCoolixFanTempCode
const uint8_t kCoolixFanTempCode
Definition: ir_Coolix.h:64
IRCoolixAC::setSensorTemp
void setSensorTemp(const uint8_t temp)
Set the sensor temperature.
Definition: ir_Coolix.cpp:247
IRCoolixAC::setTurbo
void setTurbo(void)
Toggle the Turbo mode of the A/C.
Definition: ir_Coolix.cpp:314
IRCoolixAC::getTemp
uint8_t getTemp(void) const
Get the current temperature setting.
Definition: ir_Coolix.cpp:231
IRCoolixAC::off
void off(void)
Change the power setting to Off.
Definition: ir_Coolix.cpp:277
IRremoteESP8266.h
CoolixProtocol::Fan
uint32_t Fan
Fan speed.
Definition: ir_Coolix.h:108
kCoolixTempMap
const uint8_t kCoolixTempMap[kCoolixTempRange]
Definition: ir_Coolix.h:65
kCoolixClean
const uint32_t kCoolixClean
Definition: ir_Coolix.h:92
IRCoolixAC::_
CoolixProtocol _
The state of the IR remote in IR code form.
Definition: ir_Coolix.h:178
kCoolixFanFixed
const uint8_t kCoolixFanFixed
Definition: ir_Coolix.h:59
IRCoolixAC::stateReset
void stateReset(void)
Reset the internal state to a fixed known good state.
Definition: ir_Coolix.cpp:92
IRCoolixAC::getSleep
bool getSleep(void) const
Get the Sleep setting of the A/C.
Definition: ir_Coolix.cpp:301
kCoolixDefaultState
const uint32_t kCoolixDefaultState
Definition: ir_Coolix.h:95
CoolixProtocol::SensorTemp
uint32_t SensorTemp
The temperature sensor in the IR remote.
Definition: ir_Coolix.h:107
kCoolixDefaultRepeat
const uint16_t kCoolixDefaultRepeat
Definition: IRremoteESP8266.h:1172
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:459
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:473
IRCoolixAC::setTemp
void setTemp(const uint8_t temp)
Set the temperature.
Definition: ir_Coolix.cpp:222
IRCoolixAC::setSwingVStep
void setSwingVStep(void)
Set the Vertical Swing Step setting of the A/C.
Definition: ir_Coolix.cpp:295
IRCoolixAC::getSensorTemp
uint8_t getSensorTemp(void) const
Get the sensor temperature setting.
Definition: ir_Coolix.cpp:254
IRCoolixAC
Class for handling detailed Coolix A/C messages.
Definition: ir_Coolix.h:120
IRCoolixAC::getTempRaw
uint8_t getTempRaw(void) const
Get the raw (native) temperature value.
Definition: ir_Coolix.cpp:218
IRCoolixAC::getZoneFollow
bool getZoneFollow(void) const
Get the Zone Follow setting of the A/C.
Definition: ir_Coolix.cpp:343
IRCoolixAC::_saved
CoolixProtocol _saved
Copy of the state if we required a special mode.
Definition: ir_Coolix.h:179
IRCoolixAC::setClean
void setClean(void)
Toggle the Clean mode of the A/C.
Definition: ir_Coolix.cpp:336
kCoolixLed
const uint32_t kCoolixLed
Definition: ir_Coolix.h:91
IRCoolixAC::setSwing
void setSwing(void)
Toggle the Swing mode of the A/C.
Definition: ir_Coolix.cpp:284
IRCoolixAC::setRaw
void setRaw(const uint32_t new_code)
Set the internal state from a valid code for this protocol.
Definition: ir_Coolix.cpp:129
CoolixProtocol::Mode
uint32_t Mode
Operation mode.
Definition: ir_Coolix.h:104
kCoolixCmdFan
const uint32_t kCoolixCmdFan
Definition: ir_Coolix.h:93
CoolixProtocol::raw
uint32_t raw
The state in IR code form.
Definition: ir_Coolix.h:99
kCoolixTempMax
const uint8_t kCoolixTempMax
Definition: ir_Coolix.h:62
IRCoolixAC::swingFlag
bool swingFlag
Definition: ir_Coolix.h:187
kCoolixFan
const uint8_t kCoolixFan
Definition: ir_Coolix.h:49
IRCoolixAC::begin
void begin(void)
Set up hardware to be able to send a message.
Definition: ir_Coolix.cpp:105
kCoolixSwingV
const uint32_t kCoolixSwingV
Definition: ir_Coolix.h:88
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:196
IRCoolixAC::getMode
uint8_t getMode(void) const
Get the operating mode setting of the A/C.
Definition: ir_Coolix.cpp:392
IRCoolixAC::sleepFlag
bool sleepFlag
Definition: ir_Coolix.h:186
kCoolixSleep
const uint32_t kCoolixSleep
Definition: ir_Coolix.h:89
CoolixProtocol::ZoneFollow2
uint32_t ZoneFollow2
Additional control bit for Zone Follow mode.
Definition: ir_Coolix.h:111
IRCoolixAC::IRCoolixAC
IRCoolixAC(const uint16_t pin, const bool inverted=false, const bool use_modulation=true)
Class constructor.
Definition: ir_Coolix.cpp:87
IRCoolixAC::isSpecialState
bool isSpecialState(void) const
Is the current state is a special state?
Definition: ir_Coolix.cpp:145
kCoolixTempRange
const uint8_t kCoolixTempRange
Definition: ir_Coolix.h:63
kCoolixTempMin
const uint8_t kCoolixTempMin
Definition: ir_Coolix.h:61
IRCoolixAC::setSleep
void setSleep(void)
Toggle the Sleep mode of the A/C.
Definition: ir_Coolix.cpp:304
kCoolixSensorTempMax
const uint8_t kCoolixSensorTempMax
Definition: ir_Coolix.h:81
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:498
kCoolixFanMax
const uint8_t kCoolixFanMax
Definition: ir_Coolix.h:55
IRCoolixAC::getPower
bool getPower(void) const
Get the value of the current power setting.
Definition: ir_Coolix.cpp:259
kCoolixFanAuto
const uint8_t kCoolixFanAuto
Definition: ir_Coolix.h:56
IRCoolixAC::powerFlag
bool powerFlag
Definition: ir_Coolix.h:182
CoolixProtocol::Temp
uint32_t Temp
Desired temperature (Celsius)
Definition: ir_Coolix.h:105
IRCoolixAC::toString
String toString(void) const
Convert the internal state into a human readable string.
Definition: ir_Coolix.cpp:562
CoolixProtocol::ZoneFollow1
uint32_t ZoneFollow1
Control bit for Zone Follow mode.
Definition: ir_Coolix.h:103
IRCoolixAC::getSwingVStep
bool getSwingVStep(void) const
Get the Vertical Swing Step setting of the A/C.
Definition: ir_Coolix.cpp:292
IRCoolixAC::setFan
void setFan(const uint8_t speed, const bool modecheck=true)
Set the speed of the fan.
Definition: ir_Coolix.cpp:406
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:165
stdAc::state_t
Structure to hold a common A/C state.
Definition: IRsend.h:114
kCoolixSensorTempIgnoreCode
const uint8_t kCoolixSensorTempIgnoreCode
Definition: ir_Coolix.h:82
IRCoolixAC::setPower
void setPower(const bool on)
Change the power setting.
Definition: ir_Coolix.cpp:263
kCoolixTurbo
const uint32_t kCoolixTurbo
Definition: ir_Coolix.h:90
stdAc::opmode_t
opmode_t
Common A/C settings for A/C operating modes.
Definition: IRsend.h:49