IRremoteESP8266
ir_Midea.h
Go to the documentation of this file.
1 // Copyright 2017 David Conran
2 
7 
8 // Supports:
9 // Brand: Pioneer System, Model: RYBO12GMFILCAD A/C (12K BTU) (MIDEA)
10 // Brand: Pioneer System, Model: RUBO18GMFILCAD A/C (18K BTU) (MIDEA)
11 // Brand: Comfee, Model: MPD1-12CRN7 A/C (MIDEA)
12 // Brand: Keystone, Model: RG57H4(B)BGEF remote (MIDEA)
13 // Brand: Midea, Model: FS40-7AR Stand Fan (MIDEA24)
14 // Brand: Danby, Model: DAC080BGUWDB (MIDEA)
15 // Brand: Danby, Model: DAC100BGUWDB (MIDEA)
16 // Brand: Danby, Model: DAC120BGUWDB (MIDEA)
17 // Brand: Danby, Model: R09C/BCGE remote (MIDEA)
18 
19 #ifndef IR_MIDEA_H_
20 #define IR_MIDEA_H_
21 
22 #define __STDC_LIMIT_MACROS
23 #include <stdint.h>
24 #ifdef ARDUINO
25 #include <Arduino.h>
26 #endif
27 #include "IRremoteESP8266.h"
28 #include "IRsend.h"
29 #ifdef UNIT_TEST
30 #include "IRsend_test.h"
31 #endif
32 
33 #if DANBY_DAC
35 #endif
37  uint64_t remote_state;
38  // only use 48bits
39  struct {
40  // Byte 0
41  uint8_t Sum;
42  // Byte 1
43  uint8_t :8; // value=0xFF
44  // Byte 2
45  uint8_t :8; // value=0xFF
46  // Byte 3
47  uint8_t Temp:5;
48  uint8_t useFahrenheit:1;
49  uint8_t :0;
50  // Byte 4
51  uint8_t Mode:3;
52  uint8_t Fan:2;
53  uint8_t :1;
54  uint8_t Sleep:1;
55  uint8_t Power:1;
56  // Byte 5
57  uint8_t :0;
58  };
59 };
60 // Constants
61 const uint8_t kMideaACMinTempF = 62; // Fahrenheit
62 const uint8_t kMideaACMaxTempF = 86; // Fahrenheit
63 const uint8_t kMideaACMinTempC = 17; // Celsius
64 const uint8_t kMideaACMaxTempC = 30; // Celsius
65 const uint8_t kMideaACCool = 0; // 0b000
66 const uint8_t kMideaACDry = 1; // 0b001
67 const uint8_t kMideaACAuto = 2; // 0b010
68 const uint8_t kMideaACHeat = 3; // 0b011
69 const uint8_t kMideaACFan = 4; // 0b100
70 const uint8_t kMideaACFanAuto = 0; // 0b00
71 const uint8_t kMideaACFanLow = 1; // 0b01
72 const uint8_t kMideaACFanMed = 2; // 0b10
73 const uint8_t kMideaACFanHigh = 3; // 0b11
74 const uint64_t kMideaACToggleSwingV = 0x0000A201FFFFFF7C;
75 // For Danby DAC unit, the Ionizer toggle is the same as ToggleSwingV
76 // const uint64_t kMideaACToggleIonizer = 0x0000A201FFFFFF7C;
77 const uint64_t kMideaACToggleEcono = 0x0000A202FFFFFF7E;
78 
79 // Legacy defines. (Deprecated)
80 #define MIDEA_AC_COOL kMideaACCool
81 #define MIDEA_AC_DRY kMideaACDry
82 #define MIDEA_AC_AUTO kMideaACAuto
83 #define MIDEA_AC_HEAT kMideaACHeat
84 #define MIDEA_AC_FAN kMideaACFan
85 #define MIDEA_AC_FAN_AUTO kMideaACFanAuto
86 #define MIDEA_AC_FAN_LOW kMideaACFanLow
87 #define MIDEA_AC_FAN_MED kMideaACFanMed
88 #define MIDEA_AC_FAN_HI kMideaACFanHigh
89 #define MIDEA_AC_POWER kMideaACPower
90 #define MIDEA_AC_SLEEP kMideaACSleep
91 #define MIDEA_AC_MIN_TEMP_F kMideaACMinTempF
92 #define MIDEA_AC_MAX_TEMP_F kMideaACMaxTempF
93 #define MIDEA_AC_MIN_TEMP_C kMideaACMinTempC
94 #define MIDEA_AC_MAX_TEMP_C kMideaACMaxTempC
95 
96 // Classes
99 class IRMideaAC {
100  public:
101  explicit IRMideaAC(const uint16_t pin, const bool inverted = false,
102  const bool use_modulation = true);
103  void stateReset(void);
104 #if SEND_MIDEA
105  void send(const uint16_t repeat = kMideaMinRepeat);
110  int8_t calibrate(void) { return _irsend.calibrate(); }
111 #endif // SEND_MIDEA
112  void begin(void);
113  void on(void);
114  void off(void);
115  void setPower(const bool on);
116  bool getPower(void) const;
117  bool getUseCelsius(void) const;
118  void setUseCelsius(const bool celsius);
119  void setTemp(const uint8_t temp, const bool useCelsius = false);
120  uint8_t getTemp(const bool useCelsius = false) const;
121  void setFan(const uint8_t fan);
122  uint8_t getFan(void) const;
123  void setMode(const uint8_t mode);
124  uint8_t getMode(void) const;
125  void setRaw(const uint64_t newState);
126  uint64_t getRaw(void);
127  static bool validChecksum(const uint64_t state);
128  void setSleep(const bool on);
129  bool getSleep(void) const;
130  bool isSwingVToggle(void) const;
131  void setSwingVToggle(const bool on);
132  bool getSwingVToggle(void);
133  bool isEconoToggle(void) const;
134  void setEconoToggle(const bool on);
135  bool getEconoToggle(void);
136  static uint8_t convertMode(const stdAc::opmode_t mode);
137  static uint8_t convertFan(const stdAc::fanspeed_t speed);
138  static stdAc::opmode_t toCommonMode(const uint8_t mode);
139  static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
140  stdAc::state_t toCommon(const stdAc::state_t *prev = NULL);
141  String toString(void);
142 #ifndef UNIT_TEST
143 
144  private:
146 #else // UNIT_TEST
147  IRsendTest _irsend;
149 #endif // UNIT_TEST
154  void checksum(void);
155  static uint8_t calcChecksum(const uint64_t state);
156 };
157 
158 #endif // IR_MIDEA_H_
MideaProtocol::Sum
uint8_t Sum
Definition: ir_Midea.h:41
kMideaACMinTempF
const uint8_t kMideaACMinTempF
Definition: ir_Midea.h:61
IRMideaAC::begin
void begin(void)
Set up hardware to be able to send a message.
Definition: ir_Midea.cpp:106
IRMideaAC::toCommonFanSpeed
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed)
Convert a native fan speed into its stdAc equivilant.
Definition: ir_Midea.cpp:358
IRMideaAC::setSleep
void setSleep(const bool on)
Set the Sleep setting of the A/C.
Definition: ir_Midea.cpp:240
IRMideaAC::on
void on(void)
Set the requested power state of the A/C to on.
Definition: ir_Midea.cpp:136
IRMideaAC::setUseCelsius
void setUseCelsius(const bool celsius)
Set the A/C unit to use Celsius natively.
Definition: ir_Midea.cpp:161
kMideaMinRepeat
const uint16_t kMideaMinRepeat
Definition: IRremoteESP8266.h:950
IRMideaAC::_EconoToggle
bool _EconoToggle
Definition: ir_Midea.h:153
IRMideaAC::_
MideaProtocol _
Definition: ir_Midea.h:151
IRMideaAC::setTemp
void setTemp(const uint8_t temp, const bool useCelsius=false)
Set the temperature.
Definition: ir_Midea.cpp:172
IRMideaAC::getPower
bool getPower(void) const
Get the value of the current power setting.
Definition: ir_Midea.cpp:149
IRMideaAC::calibrate
int8_t calibrate(void)
Run the calibration to calculate uSec timing offsets for this platform.
Definition: ir_Midea.h:110
IRMideaAC::setEconoToggle
void setEconoToggle(const bool on)
Set the A/C to toggle the Econo (energy saver) mode for the next send.
Definition: ir_Midea.cpp:272
stdAc::fanspeed_t
fanspeed_t
Common A/C settings for Fan Speeds.
Definition: IRsend.h:58
IRMideaAC::_SwingVToggle
bool _SwingVToggle
Definition: ir_Midea.h:152
kMideaACAuto
const uint8_t kMideaACAuto
Definition: ir_Midea.h:67
IRMideaAC::checksum
void checksum(void)
Calculate & set the checksum for the current internal state of the remote.
Definition: ir_Midea.cpp:310
IRMideaAC::IRMideaAC
IRMideaAC(const uint16_t pin, const bool inverted=false, const bool use_modulation=true)
Class constructor.
Definition: ir_Midea.cpp:93
kMideaACFan
const uint8_t kMideaACFan
Definition: ir_Midea.h:69
IRMideaAC::send
void send(const uint16_t repeat=kMideaMinRepeat)
Send the current internal state as an IR message.
Definition: ir_Midea.cpp:111
MideaProtocol::useFahrenheit
uint8_t useFahrenheit
Definition: ir_Midea.h:48
IRsend.h
kMideaACMaxTempF
const uint8_t kMideaACMaxTempF
Definition: ir_Midea.h:62
IRsend
Class for sending all basic IR protocols.
Definition: IRsend.h:176
MideaProtocol::Power
uint8_t Power
Definition: ir_Midea.h:55
IRsend::calibrate
int8_t calibrate(uint16_t hz=38000U)
Calculate & set any offsets to account for execution times during sending.
Definition: IRsend.cpp:207
IRMideaAC::setSwingVToggle
void setSwingVToggle(const bool on)
Set the A/C to toggle the vertical swing toggle for the next send.
Definition: ir_Midea.cpp:253
IRMideaAC::isSwingVToggle
bool isSwingVToggle(void) const
Is the current state a vertical swing toggle message?
Definition: ir_Midea.cpp:258
String
std::string String
Definition: IRremoteESP8266.h:1128
kSwingVToggleStr
kSwingVToggleStr
Definition: ir_Midea.h:34
IRMideaAC::getSwingVToggle
bool getSwingVToggle(void)
Definition: ir_Midea.cpp:265
MideaProtocol::Fan
uint8_t Fan
Definition: ir_Midea.h:52
MideaProtocol::Mode
uint8_t Mode
Definition: ir_Midea.h:51
IRMideaAC::getFan
uint8_t getFan(void) const
Get the current fan speed setting.
Definition: ir_Midea.cpp:212
IRMideaAC::off
void off(void)
Set the requested power state of the A/C to off.
Definition: ir_Midea.cpp:139
IRremoteESP8266.h
kMideaACHeat
const uint8_t kMideaACHeat
Definition: ir_Midea.h:68
IRMideaAC::getUseCelsius
bool getUseCelsius(void) const
Is the device currently using Celsius or the Fahrenheit temp scale?
Definition: ir_Midea.cpp:155
IRMideaAC::toCommonMode
static stdAc::opmode_t toCommonMode(const uint8_t mode)
Convert a native mode into its stdAc equivilant.
Definition: ir_Midea.cpp:345
kMideaACFanAuto
const uint8_t kMideaACFanAuto
Definition: ir_Midea.h:70
kMideaACToggleSwingV
const uint64_t kMideaACToggleSwingV
Definition: ir_Midea.h:74
IRMideaAC::_irsend
IRsend _irsend
Instance of the IR send class.
Definition: ir_Midea.h:145
MideaProtocol::remote_state
uint64_t remote_state
The state in native IR code form.
Definition: ir_Midea.h:37
IRMideaAC
Class for handling detailed Midea A/C messages.
Definition: ir_Midea.h:99
IRMideaAC::setRaw
void setRaw(const uint64_t newState)
Set the internal state from a valid code for this protocol.
Definition: ir_Midea.cpp:133
IRMideaAC::setMode
void setMode(const uint8_t mode)
Set the operating mode of the A/C.
Definition: ir_Midea.cpp:224
IRMideaAC::calcChecksum
static uint8_t calcChecksum(const uint64_t state)
Calculate the checksum for a given state.
Definition: ir_Midea.cpp:290
kIonStr
const PROGMEM char * kIonStr
"Ion"
Definition: IRtext.cpp:55
IRMideaAC::getSleep
bool getSleep(void) const
Get the Sleep setting of the A/C.
Definition: ir_Midea.cpp:246
IRMideaAC::getMode
uint8_t getMode(void) const
Get the operating mode setting of the A/C.
Definition: ir_Midea.cpp:218
kMideaACToggleEcono
const uint64_t kMideaACToggleEcono
Definition: ir_Midea.h:77
IRMideaAC::convertFan
static uint8_t convertFan(const stdAc::fanspeed_t speed)
Convert a stdAc::fanspeed_t enum into it's native speed.
Definition: ir_Midea.cpp:331
MideaProtocol::Sleep
uint8_t Sleep
Definition: ir_Midea.h:54
kMideaACFanMed
const uint8_t kMideaACFanMed
Definition: ir_Midea.h:72
IRMideaAC::getRaw
uint64_t getRaw(void)
Get a copy of the internal state/code for this protocol.
Definition: ir_Midea.cpp:126
kMideaACMinTempC
const uint8_t kMideaACMinTempC
Definition: ir_Midea.h:63
IRMideaAC::convertMode
static uint8_t convertMode(const stdAc::opmode_t mode)
Convert a stdAc::opmode_t enum into its native mode.
Definition: ir_Midea.cpp:318
kMideaACFanHigh
const uint8_t kMideaACFanHigh
Definition: ir_Midea.h:73
IRMideaAC::getEconoToggle
bool getEconoToggle(void)
Definition: ir_Midea.cpp:282
kMideaACMaxTempC
const uint8_t kMideaACMaxTempC
Definition: ir_Midea.h:64
IRMideaAC::toCommon
stdAc::state_t toCommon(const stdAc::state_t *prev=NULL)
Convert the current internal state into its stdAc::state_t equivilant.
Definition: ir_Midea.cpp:370
kMideaACDry
const uint8_t kMideaACDry
Definition: ir_Midea.h:66
IRMideaAC::toString
String toString(void)
Convert the current internal state into a human readable string.
Definition: ir_Midea.cpp:407
IRMideaAC::validChecksum
static bool validChecksum(const uint64_t state)
Verify the checksum is valid for a given state.
Definition: ir_Midea.cpp:305
kMideaACCool
const uint8_t kMideaACCool
Definition: ir_Midea.h:65
MideaProtocol
Definition: ir_Midea.h:36
IRMideaAC::setPower
void setPower(const bool on)
Change the power setting.
Definition: ir_Midea.cpp:143
IRMideaAC::stateReset
void stateReset(void)
Reset the state of the remote to a known good state/sequence.
Definition: ir_Midea.cpp:98
stdAc::state_t
Structure to hold a common A/C state.
Definition: IRsend.h:97
kMideaACFanLow
const uint8_t kMideaACFanLow
Definition: ir_Midea.h:71
IRMideaAC::getTemp
uint8_t getTemp(const bool useCelsius=false) const
Get the current temperature setting.
Definition: ir_Midea.cpp:193
MideaProtocol::Temp
uint8_t Temp
Definition: ir_Midea.h:47
IRMideaAC::setFan
void setFan(const uint8_t fan)
Set the speed of the fan.
Definition: ir_Midea.cpp:206
IRMideaAC::isEconoToggle
bool isEconoToggle(void) const
Is the current state an Econo (energy saver) toggle message?
Definition: ir_Midea.cpp:276
stdAc::opmode_t
opmode_t
Common A/C settings for A/C operating modes.
Definition: IRsend.h:46