IRremoteESP8266
ir_Gree.h
Go to the documentation of this file.
1 // Copyright 2016 David Conran
2 
7 
8 // Supports:
9 // Brand: Ultimate, Model: Heat Pump
10 // Brand: EKOKAI, Model: A/C
11 // Brand: RusClimate, Model: EACS/I-09HAR_X/N3 A/C
12 // Brand: RusClimate, Model: YAW1F remote
13 // Brand: Green, Model: YBOFB remote
14 // Brand: Green, Model: YBOFB2 remote
15 // Brand: Gree, Model: YAA1FBF remote
16 // Brand: Gree, Model: YB1F2F remote
17 // Brand: Amana, Model: PBC093G00CC A/C
18 // Brand: Amana, Model: YX1FF remote
19 // Brand: Cooper & Hunter, Model: YB1F2 remote
20 // Brand: Cooper & Hunter, Model: CH-S09FTXG A/C
21 
22 #ifndef IR_GREE_H_
23 #define IR_GREE_H_
24 
25 #define __STDC_LIMIT_MACROS
26 #include <stdint.h>
27 #ifndef UNIT_TEST
28 #include <Arduino.h>
29 #endif
30 #include "IRremoteESP8266.h"
31 #include "IRsend.h"
32 #ifdef UNIT_TEST
33 #include "IRsend_test.h"
34 #endif
35 
39  struct {
40  // Byte 0
41  uint8_t Mode :3;
42  uint8_t Power :1;
43  uint8_t Fan :2;
44  uint8_t SwingAuto :1;
45  uint8_t Sleep :1;
46  // Byte 1
47  uint8_t Temp :4;
48  uint8_t TimerHalfHr :1;
49  uint8_t TimerTensHr :2;
50  uint8_t TimerEnabled:1;
51  // Byte 2
52  uint8_t TimerHours:4;
53  uint8_t Turbo :1;
54  uint8_t Light :1;
55  uint8_t ModelA :1; // model==YAW1F
56  uint8_t Xfan :1;
57  // Byte 3
58  uint8_t :2;
59  uint8_t TempExtraDegreeF:1;
60  uint8_t UseFahrenheit :1;
61  uint8_t unknown1 :4; // value=0b0101
62  // Byte 4
63  uint8_t Swing:4;
64  uint8_t :0;
65  // Byte 5
66  uint8_t DisplayTemp :2;
67  uint8_t IFeel :1;
68  uint8_t unknown2 :3; // value = 0b100
69  uint8_t WiFi :1;
70  uint8_t :0;
71  // Byte 6
72  uint8_t :8;
73  // Byte 7
74  uint8_t :4;
75  uint8_t Sum:4;
76  };
77 };
78 
79 // Constants
80 
81 const uint8_t kGreeAuto = 0;
82 const uint8_t kGreeCool = 1;
83 const uint8_t kGreeDry = 2;
84 const uint8_t kGreeFan = 3;
85 const uint8_t kGreeHeat = 4;
86 
87 const uint8_t kGreeFanAuto = 0;
88 const uint8_t kGreeFanMin = 1;
89 const uint8_t kGreeFanMed = 2;
90 const uint8_t kGreeFanMax = 3;
91 
92 const uint8_t kGreeMinTempC = 16; // Celsius
93 const uint8_t kGreeMaxTempC = 30; // Celsius
94 const uint8_t kGreeMinTempF = 61; // Fahrenheit
95 const uint8_t kGreeMaxTempF = 86; // Fahrenheit
96 const uint16_t kGreeTimerMax = 24 * 60;
97 
98 const uint8_t kGreeSwingLastPos = 0b0000;
99 const uint8_t kGreeSwingAuto = 0b0001;
100 const uint8_t kGreeSwingUp = 0b0010;
101 const uint8_t kGreeSwingMiddleUp = 0b0011;
102 const uint8_t kGreeSwingMiddle = 0b0100;
103 const uint8_t kGreeSwingMiddleDown = 0b0101;
104 const uint8_t kGreeSwingDown = 0b0110;
105 const uint8_t kGreeSwingDownAuto = 0b0111;
106 const uint8_t kGreeSwingMiddleAuto = 0b1001;
107 const uint8_t kGreeSwingUpAuto = 0b1011;
108 
109 const uint8_t kGreeDisplayTempOff = 0b00; // 0
110 const uint8_t kGreeDisplayTempSet = 0b01; // 1
111 const uint8_t kGreeDisplayTempInside = 0b10; // 2
112 const uint8_t kGreeDisplayTempOutside = 0b11; // 3
113 
114 // Legacy defines.
115 #define GREE_AUTO kGreeAuto
116 #define GREE_COOL kGreeCool
117 #define GREE_DRY kGreeDry
118 #define GREE_FAN kGreeFan
119 #define GREE_HEAT kGreeHeat
120 #define GREE_MIN_TEMP kGreeMinTempC
121 #define GREE_MAX_TEMP kGreeMaxTempC
122 #define GREE_FAN_MAX kGreeFanMax
123 #define GREE_SWING_LAST_POS kGreeSwingLastPos
124 #define GREE_SWING_AUTO kGreeSwingAuto
125 #define GREE_SWING_UP kGreeSwingUp
126 #define GREE_SWING_MIDDLE_UP kGreeSwingMiddleUp
127 #define GREE_SWING_MIDDLE kGreeSwingMiddle
128 #define GREE_SWING_MIDDLE_DOWN kGreeSwingMiddleDown
129 #define GREE_SWING_DOWN kGreeSwingDown
130 #define GREE_SWING_DOWN_AUTO kGreeSwingDownAuto
131 #define GREE_SWING_MIDDLE_AUTO kGreeSwingMiddleAuto
132 #define GREE_SWING_UP_AUTO kGreeSwingUpAuto
133 
134 // Classes
136 class IRGreeAC {
137  public:
138  explicit IRGreeAC(
139  const uint16_t pin,
141  const bool inverted = false, const bool use_modulation = true);
142  void stateReset(void);
143 #if SEND_GREE
144  void send(const uint16_t repeat = kGreeDefaultRepeat);
149  int8_t calibrate(void) { return _irsend.calibrate(); }
150 #endif // SEND_GREE
151  void begin(void);
152  void on(void);
153  void off(void);
154  void setModel(const gree_ac_remote_model_t model);
155  gree_ac_remote_model_t getModel(void) const;
156  void setPower(const bool on);
157  bool getPower(void) const;
158  void setTemp(const uint8_t temp, const bool fahrenheit = false);
159  uint8_t getTemp(void) const;
160  void setUseFahrenheit(const bool on);
161  bool getUseFahrenheit(void) const;
162  void setFan(const uint8_t speed);
163  uint8_t getFan(void) const;
164  void setMode(const uint8_t new_mode);
165  uint8_t getMode(void) const;
166  void setLight(const bool on);
167  bool getLight(void) const;
168  void setXFan(const bool on);
169  bool getXFan(void) const;
170  void setSleep(const bool on);
171  bool getSleep(void) const;
172  void setTurbo(const bool on);
173  bool getTurbo(void) const;
174  void setIFeel(const bool on);
175  bool getIFeel(void) const;
176  void setWiFi(const bool on);
177  bool getWiFi(void) const;
178  void setSwingVertical(const bool automatic, const uint8_t position);
179  bool getSwingVerticalAuto(void) const;
180  uint8_t getSwingVerticalPosition(void) const;
181  uint16_t getTimer(void) const;
182  void setTimer(const uint16_t minutes);
183  void setDisplayTempSource(const uint8_t mode);
184  uint8_t getDisplayTempSource(void) const;
185  static uint8_t convertMode(const stdAc::opmode_t mode);
186  static uint8_t convertFan(const stdAc::fanspeed_t speed);
187  static uint8_t convertSwingV(const stdAc::swingv_t swingv);
188  static stdAc::opmode_t toCommonMode(const uint8_t mode);
189  static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
190  static stdAc::swingv_t toCommonSwingV(const uint8_t pos);
191  stdAc::state_t toCommon(void);
192  uint8_t* getRaw(void);
193  void setRaw(const uint8_t new_code[]);
194  static bool validChecksum(const uint8_t state[],
195  const uint16_t length = kGreeStateLength);
196  String toString(void);
197 #ifndef UNIT_TEST
198 
199  private:
201 #else // UNIT_TEST
202  IRsendTest _irsend;
204 #endif // UNIT_TEST
208  void checksum(const uint16_t length = kGreeStateLength);
209  void fixup(void);
210  void setTimerEnabled(const bool on);
211  bool getTimerEnabled(void) const;
212 };
213 
214 #endif // IR_GREE_H_
IRGreeAC::setSwingVertical
void setSwingVertical(const bool automatic, const uint8_t position)
Set the Vertical Swing mode of the A/C.
Definition: ir_Gree.cpp:387
GreeProtocol::ModelA
uint8_t ModelA
Definition: ir_Gree.h:55
GreeProtocol::Temp
uint8_t Temp
Definition: ir_Gree.h:47
GreeProtocol::Mode
uint8_t Mode
Definition: ir_Gree.h:41
IRGreeAC::_
GreeProtocol _
Definition: ir_Gree.h:206
IRGreeAC::getMode
uint8_t getMode(void) const
Get the operating mode setting of the A/C.
Definition: ir_Gree.cpp:308
IRGreeAC::getWiFi
bool getWiFi(void) const
Get the Wifi (enabled) setting of the A/C.
Definition: ir_Gree.cpp:344
kGreeStateLength
const uint16_t kGreeStateLength
Definition: IRremoteESP8266.h:1038
kGreeSwingUp
const uint8_t kGreeSwingUp
Definition: ir_Gree.h:100
stdAc::swingv_t
swingv_t
Common A/C settings for Vertical Swing.
Definition: IRsend.h:70
IRGreeAC::validChecksum
static bool validChecksum(const uint8_t state[], const uint16_t length=kGreeStateLength)
Verify the checksum is valid for a given state.
Definition: ir_Gree.cpp:177
IRGreeAC::toString
String toString(void)
Convert the current internal state into a human readable string.
Definition: ir_Gree.cpp:596
IRGreeAC::off
void off(void)
Change the power setting to Off.
Definition: ir_Gree.cpp:201
kGreeFan
const uint8_t kGreeFan
Definition: ir_Gree.h:84
IRGreeAC::setXFan
void setXFan(const bool on)
Set the XFan (Mould) setting of the A/C.
Definition: ir_Gree.cpp:350
IRGreeAC::toCommonMode
static stdAc::opmode_t toCommonMode(const uint8_t mode)
Convert a native mode into its stdAc equivalent.
Definition: ir_Gree.cpp:529
IRGreeAC::getIFeel
bool getIFeel(void) const
Get the IFeel setting of the A/C.
Definition: ir_Gree.cpp:332
stdAc::fanspeed_t
fanspeed_t
Common A/C settings for Fan Speeds.
Definition: IRsend.h:58
IRGreeAC::getLight
bool getLight(void) const
Get the Light (LED) setting of the A/C.
Definition: ir_Gree.cpp:320
GreeProtocol::SwingAuto
uint8_t SwingAuto
Definition: ir_Gree.h:44
GreeProtocol::TempExtraDegreeF
uint8_t TempExtraDegreeF
Definition: ir_Gree.h:59
IRGreeAC::convertMode
static uint8_t convertMode(const stdAc::opmode_t mode)
Convert a stdAc::opmode_t enum into its native mode.
Definition: ir_Gree.cpp:488
kGreeDry
const uint8_t kGreeDry
Definition: ir_Gree.h:83
GreeProtocol::unknown1
uint8_t unknown1
Definition: ir_Gree.h:61
kGreeFanMax
const uint8_t kGreeFanMax
Definition: ir_Gree.h:90
kGreeMaxTempF
const uint8_t kGreeMaxTempF
Definition: ir_Gree.h:95
IRGreeAC::getTimer
uint16_t getTimer(void) const
Get the timer time value from the A/C.
Definition: ir_Gree.cpp:441
IRGreeAC::setMode
void setMode(const uint8_t new_mode)
Set the operating mode of the A/C.
Definition: ir_Gree.cpp:290
GreeProtocol::Fan
uint8_t Fan
Definition: ir_Gree.h:43
IRGreeAC::toCommon
stdAc::state_t toCommon(void)
Convert the current internal state into its stdAc::state_t equivalent.
Definition: ir_Gree.cpp:567
GreeProtocol::WiFi
uint8_t WiFi
Definition: ir_Gree.h:69
gree_ac_remote_model_t
gree_ac_remote_model_t
Gree A/C model numbers.
Definition: IRsend.h:134
IRGreeAC::send
void send(const uint16_t repeat=kGreeDefaultRepeat)
Send the current internal state as an IR message.
Definition: ir_Gree.cpp:141
kGreeSwingUpAuto
const uint8_t kGreeSwingUpAuto
Definition: ir_Gree.h:107
kGreeDisplayTempOutside
const uint8_t kGreeDisplayTempOutside
Definition: ir_Gree.h:112
IRGreeAC::fixup
void fixup(void)
Fix up the internal state so it is correct.
Definition: ir_Gree.cpp:130
GreeProtocol::remote_state
uint8_t remote_state[kGreeStateLength]
The state in native IR code form.
Definition: ir_Gree.h:38
kGreeSwingDownAuto
const uint8_t kGreeSwingDownAuto
Definition: ir_Gree.h:105
IRsend.h
IRGreeAC::setPower
void setPower(const bool on)
Change the power setting.
Definition: ir_Gree.cpp:206
IRGreeAC::setTimerEnabled
void setTimerEnabled(const bool on)
Set the timer enable setting of the A/C.
Definition: ir_Gree.cpp:429
IRGreeAC::getRaw
uint8_t * getRaw(void)
Get a PTR to the internal state/code for this protocol.
Definition: ir_Gree.cpp:148
IRsend
Class for sending all basic IR protocols.
Definition: IRsend.h:190
GreeProtocol::Turbo
uint8_t Turbo
Definition: ir_Gree.h:53
IRsend::calibrate
int8_t calibrate(uint16_t hz=38000U)
Calculate & set any offsets to account for execution times during sending.
Definition: IRsend.cpp:207
GreeProtocol::Swing
uint8_t Swing
Definition: ir_Gree.h:63
String
std::string String
Definition: IRremoteESP8266.h:1279
kGreeDisplayTempSet
const uint8_t kGreeDisplayTempSet
Definition: ir_Gree.h:110
GreeProtocol::TimerHours
uint8_t TimerHours
Definition: ir_Gree.h:52
GreeProtocol::TimerHalfHr
uint8_t TimerHalfHr
Definition: ir_Gree.h:48
kGreeSwingMiddleDown
const uint8_t kGreeSwingMiddleDown
Definition: ir_Gree.h:103
IRGreeAC::IRGreeAC
IRGreeAC(const uint16_t pin, const gree_ac_remote_model_t model=gree_ac_remote_model_t::YAW1F, const bool inverted=false, const bool use_modulation=true)
Class constructor.
Definition: ir_Gree.cpp:111
GreeProtocol::Sum
uint8_t Sum
Definition: ir_Gree.h:75
kGreeFanMed
const uint8_t kGreeFanMed
Definition: ir_Gree.h:89
IRremoteESP8266.h
kGreeSwingMiddleAuto
const uint8_t kGreeSwingMiddleAuto
Definition: ir_Gree.h:106
IRGreeAC::convertFan
static uint8_t convertFan(const stdAc::fanspeed_t speed)
Convert a stdAc::fanspeed_t enum into it's native speed.
Definition: ir_Gree.cpp:501
kGreeHeat
const uint8_t kGreeHeat
Definition: ir_Gree.h:85
IRGreeAC::setSleep
void setSleep(const bool on)
Set the Sleep setting of the A/C.
Definition: ir_Gree.cpp:362
IRGreeAC::begin
void begin(void)
Set up hardware to be able to send a message.
Definition: ir_Gree.cpp:136
kGreeTimerMax
const uint16_t kGreeTimerMax
Definition: ir_Gree.h:96
YAW1F
@ YAW1F
Definition: IRsend.h:135
kGreeMaxTempC
const uint8_t kGreeMaxTempC
Definition: ir_Gree.h:93
IRGreeAC::calibrate
int8_t calibrate(void)
Run the calibration to calculate uSec timing offsets for this platform.
Definition: ir_Gree.h:149
GreeProtocol::Sleep
uint8_t Sleep
Definition: ir_Gree.h:45
kGreeMinTempF
const uint8_t kGreeMinTempF
Definition: ir_Gree.h:94
kGreeDisplayTempOff
const uint8_t kGreeDisplayTempOff
Definition: ir_Gree.h:109
IRGreeAC::setFan
void setFan(const uint8_t speed)
Set the speed of the fan.
Definition: ir_Gree.cpp:275
IRGreeAC::setUseFahrenheit
void setUseFahrenheit(const bool on)
Set the default temperature units to use.
Definition: ir_Gree.cpp:223
IRGreeAC::toCommonFanSpeed
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed)
Convert a native fan speed into its stdAc equivalent.
Definition: ir_Gree.cpp:542
GreeProtocol::unknown2
uint8_t unknown2
Definition: ir_Gree.h:68
IRGreeAC::getTurbo
bool getTurbo(void) const
Get the Turbo setting of the A/C.
Definition: ir_Gree.cpp:380
GreeProtocol::TimerTensHr
uint8_t TimerTensHr
Definition: ir_Gree.h:49
IRGreeAC::getPower
bool getPower(void) const
Get the value of the current power setting.
Definition: ir_Gree.cpp:215
IRGreeAC::getXFan
bool getXFan(void) const
Get the XFan (Mould) setting of the A/C.
Definition: ir_Gree.cpp:356
IRGreeAC::checksum
void checksum(const uint16_t length=kGreeStateLength)
Calculate and set the checksum values for the internal state.
Definition: ir_Gree.cpp:168
GreeProtocol::Xfan
uint8_t Xfan
Definition: ir_Gree.h:56
GreeProtocol::Light
uint8_t Light
Definition: ir_Gree.h:54
IRGreeAC::setTimer
void setTimer(const uint16_t minutes)
Set the A/C's timer to turn off in X many minutes.
Definition: ir_Gree.cpp:451
IRGreeAC::setModel
void setModel(const gree_ac_remote_model_t model)
Set the model of the A/C to emulate.
Definition: ir_Gree.cpp:185
IRGreeAC::getModel
gree_ac_remote_model_t getModel(void) const
Get/Detect the model of the A/C.
Definition: ir_Gree.cpp:195
kGreeAuto
const uint8_t kGreeAuto
Definition: ir_Gree.h:81
IRGreeAC::setWiFi
void setWiFi(const bool on)
Set the Wifi (enabled) setting of the A/C.
Definition: ir_Gree.cpp:338
IRGreeAC::getFan
uint8_t getFan(void) const
Get the current fan speed setting.
Definition: ir_Gree.cpp:284
IRGreeAC::convertSwingV
static uint8_t convertSwingV(const stdAc::swingv_t swingv)
Convert a stdAc::swingv_t enum into it's native setting.
Definition: ir_Gree.cpp:515
IRGreeAC::getUseFahrenheit
bool getUseFahrenheit(void) const
Get the default temperature units in use.
Definition: ir_Gree.cpp:229
IRGreeAC::setIFeel
void setIFeel(const bool on)
Set the IFeel setting of the A/C.
Definition: ir_Gree.cpp:326
kGreeSwingMiddleUp
const uint8_t kGreeSwingMiddleUp
Definition: ir_Gree.h:101
IRGreeAC::getTemp
uint8_t getTemp(void) const
Get the set temperature.
Definition: ir_Gree.cpp:262
GreeProtocol::IFeel
uint8_t IFeel
Definition: ir_Gree.h:67
kGreeFanMin
const uint8_t kGreeFanMin
Definition: ir_Gree.h:88
kGreeCool
const uint8_t kGreeCool
Definition: ir_Gree.h:82
IRGreeAC::getSwingVerticalPosition
uint8_t getSwingVerticalPosition(void) const
Get the Vertical Swing position setting of the A/C.
Definition: ir_Gree.cpp:423
kGreeSwingMiddle
const uint8_t kGreeSwingMiddle
Definition: ir_Gree.h:102
GreeProtocol
Native representation of a Gree A/C message.
Definition: ir_Gree.h:37
kGreeSwingLastPos
const uint8_t kGreeSwingLastPos
Definition: ir_Gree.h:98
IRGreeAC::setTemp
void setTemp(const uint8_t temp, const bool fahrenheit=false)
Set the temp. in degrees.
Definition: ir_Gree.cpp:239
IRGreeAC::getTimerEnabled
bool getTimerEnabled(void) const
Get the timer enabled setting of the A/C.
Definition: ir_Gree.cpp:435
IRGreeAC::_model
gree_ac_remote_model_t _model
Definition: ir_Gree.h:207
IRGreeAC::getSwingVerticalAuto
bool getSwingVerticalAuto(void) const
Get the Vertical Swing Automatic mode setting of the A/C.
Definition: ir_Gree.cpp:417
IRGreeAC::setTurbo
void setTurbo(const bool on)
Set the Turbo setting of the A/C.
Definition: ir_Gree.cpp:374
kGreeSwingDown
const uint8_t kGreeSwingDown
Definition: ir_Gree.h:104
IRGreeAC::toCommonSwingV
static stdAc::swingv_t toCommonSwingV(const uint8_t pos)
Convert a native Vertical Swing into its stdAc equivalent.
Definition: ir_Gree.cpp:554
kGreeFanAuto
const uint8_t kGreeFanAuto
Definition: ir_Gree.h:87
GreeProtocol::Power
uint8_t Power
Definition: ir_Gree.h:42
IRGreeAC::getSleep
bool getSleep(void) const
Get the Sleep setting of the A/C.
Definition: ir_Gree.cpp:368
GreeProtocol::TimerEnabled
uint8_t TimerEnabled
Definition: ir_Gree.h:50
kGreeMinTempC
const uint8_t kGreeMinTempC
Definition: ir_Gree.h:92
IRGreeAC::getDisplayTempSource
uint8_t getDisplayTempSource(void) const
Get the temperature display mode. i.e. Internal, External temperature sensing.
Definition: ir_Gree.cpp:481
IRGreeAC::setDisplayTempSource
void setDisplayTempSource(const uint8_t mode)
Set temperature display mode. i.e. Internal, External temperature sensing.
Definition: ir_Gree.cpp:474
GreeProtocol::UseFahrenheit
uint8_t UseFahrenheit
Definition: ir_Gree.h:60
kGreeSwingAuto
const uint8_t kGreeSwingAuto
Definition: ir_Gree.h:99
IRGreeAC
Class for handling detailed Gree A/C messages.
Definition: ir_Gree.h:136
GreeProtocol::DisplayTemp
uint8_t DisplayTemp
Definition: ir_Gree.h:66
kGreeDisplayTempInside
const uint8_t kGreeDisplayTempInside
Definition: ir_Gree.h:111
IRGreeAC::stateReset
void stateReset(void)
Reset the internal state to a fixed known good state.
Definition: ir_Gree.cpp:119
stdAc::state_t
Structure to hold a common A/C state.
Definition: IRsend.h:97
IRGreeAC::setRaw
void setRaw(const uint8_t new_code[])
Set the internal state from a valid code for this protocol.
Definition: ir_Gree.cpp:155
IRGreeAC::_irsend
IRsend _irsend
Instance of the IR send class.
Definition: ir_Gree.h:200
IRGreeAC::on
void on(void)
Change the power setting to On.
Definition: ir_Gree.cpp:198
IRGreeAC::setLight
void setLight(const bool on)
Set the Light (LED) setting of the A/C.
Definition: ir_Gree.cpp:314
kGreeDefaultRepeat
const uint16_t kGreeDefaultRepeat
Definition: IRremoteESP8266.h:1040
stdAc::opmode_t
opmode_t
Common A/C settings for A/C operating modes.
Definition: IRsend.h:46