IRremoteESP8266
ir_Goodweather.h
Go to the documentation of this file.
1 // Copyright 2019 ribeirodanielf
2 // Copyright 2019 David Conran
3 
7 
8 // Supports:
9 // Brand: Goodweather, Model: ZH/JT-03 remote
10 
11 #ifndef IR_GOODWEATHER_H_
12 #define IR_GOODWEATHER_H_
13 
14 #define __STDC_LIMIT_MACROS
15 #include <stdint.h>
16 #ifndef UNIT_TEST
17 #include <Arduino.h>
18 #endif
19 #include "IRremoteESP8266.h"
20 #include "IRsend.h"
21 #ifdef UNIT_TEST
22 #include "IRsend_test.h"
23 #endif
24 
25 
26 // Constants
27 // Timing
28 const uint16_t kGoodweatherBitMark = 580;
29 const uint16_t kGoodweatherOneSpace = 580;
30 const uint16_t kGoodweatherZeroSpace = 1860;
31 const uint16_t kGoodweatherHdrMark = 6820;
32 const uint16_t kGoodweatherHdrSpace = 6820;
33 const uint8_t kGoodweatherExtraTolerance = 12; // +12% extra
34 
35 // Masks
36 const uint8_t kGoodweatherBitLight = 8;
37 const uint8_t kGoodweatherBitTurbo = kGoodweatherBitLight + 3; // 11
38 const uint8_t kGoodweatherBitCommand = kGoodweatherBitTurbo + 5; // 16
39 const uint8_t kGoodweatherCommandSize = 4; // Bits
40 const uint8_t kGoodweatherBitSleep = kGoodweatherBitCommand + 8; // 24
41 const uint8_t kGoodweatherBitPower = kGoodweatherBitSleep + 1; // 25
42 const uint8_t kGoodweatherBitSwing = kGoodweatherBitPower + 1; // 26
43 const uint8_t kGoodweatherSwingSize = 2; // Bits
44 const uint8_t kGoodweatherBitAirFlow = kGoodweatherBitSwing + 2; // 28
45 const uint8_t kGoodweatherBitFan = kGoodweatherBitAirFlow + 1; // 29
46 const uint8_t kGoodweatherFanSize = 2; // Bits
47 const uint8_t kGoodweatherBitTemp = kGoodweatherBitFan + 3; // 32
48 const uint8_t kGoodweatherTempSize = 4; // Bits
49 const uint8_t kGoodweatherBitMode = kGoodweatherBitTemp + 5; // 37
50 const uint8_t kGoodweatherBitEOF = kGoodweatherBitMode + 3; // 40
51 const uint64_t kGoodweatherEOFMask = 0xFFULL << kGoodweatherBitEOF;
52 
53 // Modes
54 const uint8_t kGoodweatherAuto = 0b000;
55 const uint8_t kGoodweatherCool = 0b001;
56 const uint8_t kGoodweatherDry = 0b010;
57 const uint8_t kGoodweatherFan = 0b011;
58 const uint8_t kGoodweatherHeat = 0b100;
59 // Swing
60 const uint8_t kGoodweatherSwingFast = 0b00;
61 const uint8_t kGoodweatherSwingSlow = 0b01;
62 const uint8_t kGoodweatherSwingOff = 0b10;
63 // Fan Control
64 const uint8_t kGoodweatherFanAuto = 0b00;
65 const uint8_t kGoodweatherFanHigh = 0b01;
66 const uint8_t kGoodweatherFanMed = 0b10;
67 const uint8_t kGoodweatherFanLow = 0b11;
68 // Temperature
69 const uint8_t kGoodweatherTempMin = 16; // Celsius
70 const uint8_t kGoodweatherTempMax = 31; // Celsius
71 // Commands
72 const uint8_t kGoodweatherCmdPower = 0x00;
73 const uint8_t kGoodweatherCmdMode = 0x01;
74 const uint8_t kGoodweatherCmdUpTemp = 0x02;
75 const uint8_t kGoodweatherCmdDownTemp = 0x03;
76 const uint8_t kGoodweatherCmdSwing = 0x04;
77 const uint8_t kGoodweatherCmdFan = 0x05;
78 const uint8_t kGoodweatherCmdTimer = 0x06;
79 const uint8_t kGoodweatherCmdAirFlow = 0x07;
80 const uint8_t kGoodweatherCmdHold = 0x08;
81 const uint8_t kGoodweatherCmdSleep = 0x09;
82 const uint8_t kGoodweatherCmdTurbo = 0x0A;
83 const uint8_t kGoodweatherCmdLight = 0x0B;
84 // PAD EOF
85 const uint64_t kGoodweatherStateInit = 0xD50000000000;
86 
87 
88 // Classes
91  public:
92  explicit IRGoodweatherAc(const uint16_t pin, const bool inverted = false,
93  const bool use_modulation = true);
94  void stateReset(void);
95 #if SEND_GOODWEATHER
96  void send(const uint16_t repeat = kGoodweatherMinRepeat);
101  int8_t calibrate(void) { return _irsend.calibrate(); }
102 #endif // SEND_GOODWEATHER
103  void begin(void);
104  void on(void);
105  void off(void);
106  void setPower(const bool on);
107  bool getPower(void);
108  void setTemp(const uint8_t temp);
109  uint8_t getTemp(void);
110  void setFan(const uint8_t speed);
111  uint8_t getFan(void);
112  void setMode(const uint8_t mode);
113  uint8_t getMode();
114  void setSwing(const uint8_t speed);
115  uint8_t getSwing(void);
116  void setSleep(const bool toggle);
117  bool getSleep(void);
118  void setTurbo(const bool toggle);
119  bool getTurbo(void);
120  void setLight(const bool toggle);
121  bool getLight(void);
122  void setCommand(const uint8_t cmd);
123  uint8_t getCommand(void);
124  uint64_t getRaw(void);
125  void setRaw(const uint64_t state);
126  uint8_t convertMode(const stdAc::opmode_t mode);
127  uint8_t convertFan(const stdAc::fanspeed_t speed);
128  uint8_t convertSwingV(const stdAc::swingv_t swingv);
129  static stdAc::opmode_t toCommonMode(const uint8_t mode);
130  static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
131  stdAc::state_t toCommon(void);
132  String toString();
133 #ifndef UNIT_TEST
134 
135  private:
137 #else // UNIT_TEST
138  IRsendTest _irsend;
140 #endif // UNIT_TEST
142  uint64_t remote;
143 };
144 #endif // IR_GOODWEATHER_H_
kGoodweatherBitTurbo
const uint8_t kGoodweatherBitTurbo
Definition: ir_Goodweather.h:37
kGoodweatherCmdLight
const uint8_t kGoodweatherCmdLight
Definition: ir_Goodweather.h:83
kGoodweatherCmdDownTemp
const uint8_t kGoodweatherCmdDownTemp
Definition: ir_Goodweather.h:75
IRGoodweatherAc::off
void off(void)
Change the power setting to Off.
Definition: ir_Goodweather.cpp:96
IRGoodweatherAc::on
void on(void)
Change the power setting to On.
Definition: ir_Goodweather.cpp:93
kGoodweatherOneSpace
const uint16_t kGoodweatherOneSpace
Definition: ir_Goodweather.h:29
kGoodweatherCommandSize
const uint8_t kGoodweatherCommandSize
Definition: ir_Goodweather.h:39
IRGoodweatherAc::stateReset
void stateReset(void)
Reset the internal state to a fixed known good state.
Definition: ir_Goodweather.cpp:71
kGoodweatherTempMin
const uint8_t kGoodweatherTempMin
Definition: ir_Goodweather.h:69
IRGoodweatherAc::getLight
bool getLight(void)
Get the Light (LED) Toggle setting of the A/C.
Definition: ir_Goodweather.cpp:184
IRGoodweatherAc::_irsend
IRsend _irsend
Instance of the IR send class.
Definition: ir_Goodweather.h:136
kGoodweatherCmdPower
const uint8_t kGoodweatherCmdPower
Definition: ir_Goodweather.h:72
stdAc::swingv_t
swingv_t
Common A/C settings for Vertical Swing.
Definition: IRsend.h:70
IRGoodweatherAc::toCommon
stdAc::state_t toCommon(void)
Convert the current internal state into its stdAc::state_t equivilant.
Definition: ir_Goodweather.cpp:317
kGoodweatherCmdAirFlow
const uint8_t kGoodweatherCmdAirFlow
Definition: ir_Goodweather.h:79
IRGoodweatherAc::getTurbo
bool getTurbo(void)
Get the Turbo Toggle setting of the A/C.
Definition: ir_Goodweather.cpp:210
stdAc::fanspeed_t
fanspeed_t
Common A/C settings for Fan Speeds.
Definition: IRsend.h:58
kGoodweatherFanSize
const uint8_t kGoodweatherFanSize
Definition: ir_Goodweather.h:46
IRGoodweatherAc::setTurbo
void setTurbo(const bool toggle)
Set the Turbo Toggle setting of the A/C.
Definition: ir_Goodweather.cpp:203
IRGoodweatherAc::getSleep
bool getSleep(void)
Get the Sleep Toggle setting of the A/C.
Definition: ir_Goodweather.cpp:197
IRGoodweatherAc::setLight
void setLight(const bool toggle)
Set the Light (LED) Toggle setting of the A/C.
Definition: ir_Goodweather.cpp:177
kGoodweatherBitMode
const uint8_t kGoodweatherBitMode
Definition: ir_Goodweather.h:49
IRsend.h
kGoodweatherCmdSwing
const uint8_t kGoodweatherCmdSwing
Definition: ir_Goodweather.h:76
kGoodweatherFanMed
const uint8_t kGoodweatherFanMed
Definition: ir_Goodweather.h:66
IRGoodweatherAc::convertSwingV
uint8_t convertSwingV(const stdAc::swingv_t swingv)
Convert a stdAc::swingv_t enum into it's native setting.
Definition: ir_Goodweather.cpp:278
kGoodweatherCmdUpTemp
const uint8_t kGoodweatherCmdUpTemp
Definition: ir_Goodweather.h:74
kGoodweatherHdrSpace
const uint16_t kGoodweatherHdrSpace
Definition: ir_Goodweather.h:32
kGoodweatherEOFMask
const uint64_t kGoodweatherEOFMask
Definition: ir_Goodweather.h:51
IRGoodweatherAc::calibrate
int8_t calibrate(void)
Run the calibration to calculate uSec timing offsets for this platform.
Definition: ir_Goodweather.h:101
IRsend
Class for sending all basic IR protocols.
Definition: IRsend.h:176
kGoodweatherFanAuto
const uint8_t kGoodweatherFanAuto
Definition: ir_Goodweather.h:64
IRsend::calibrate
int8_t calibrate(uint16_t hz=38000U)
Calculate & set any offsets to account for execution times during sending.
Definition: IRsend.cpp:207
IRGoodweatherAc::IRGoodweatherAc
IRGoodweatherAc(const uint16_t pin, const bool inverted=false, const bool use_modulation=true)
Class constructor.
Definition: ir_Goodweather.cpp:66
kGoodweatherZeroSpace
const uint16_t kGoodweatherZeroSpace
Definition: ir_Goodweather.h:30
IRGoodweatherAc::setRaw
void setRaw(const uint64_t state)
Set the internal state from a valid code for this protocol.
Definition: ir_Goodweather.cpp:90
kGoodweatherAuto
const uint8_t kGoodweatherAuto
Definition: ir_Goodweather.h:54
String
std::string String
Definition: IRremoteESP8266.h:1128
IRGoodweatherAc::send
void send(const uint16_t repeat=kGoodweatherMinRepeat)
Send the current internal state as an IR message.
Definition: ir_Goodweather.cpp:79
IRGoodweatherAc::toCommonMode
static stdAc::opmode_t toCommonMode(const uint8_t mode)
Convert a native mode into its stdAc equivilant.
Definition: ir_Goodweather.cpp:293
kGoodweatherExtraTolerance
const uint8_t kGoodweatherExtraTolerance
Definition: ir_Goodweather.h:33
kGoodweatherSwingSlow
const uint8_t kGoodweatherSwingSlow
Definition: ir_Goodweather.h:61
kGoodweatherTempSize
const uint8_t kGoodweatherTempSize
Definition: ir_Goodweather.h:48
IRremoteESP8266.h
kGoodweatherSwingOff
const uint8_t kGoodweatherSwingOff
Definition: ir_Goodweather.h:62
kGoodweatherDry
const uint8_t kGoodweatherDry
Definition: ir_Goodweather.h:56
kGoodweatherSwingFast
const uint8_t kGoodweatherSwingFast
Definition: ir_Goodweather.h:60
kGoodweatherBitFan
const uint8_t kGoodweatherBitFan
Definition: ir_Goodweather.h:45
kGoodweatherCmdSleep
const uint8_t kGoodweatherCmdSleep
Definition: ir_Goodweather.h:81
kGoodweatherCool
const uint8_t kGoodweatherCool
Definition: ir_Goodweather.h:55
IRGoodweatherAc::setTemp
void setTemp(const uint8_t temp)
Set the temperature.
Definition: ir_Goodweather.cpp:113
IRGoodweatherAc::begin
void begin(void)
Set up hardware to be able to send a message.
Definition: ir_Goodweather.cpp:74
kGoodweatherBitEOF
const uint8_t kGoodweatherBitEOF
Definition: ir_Goodweather.h:50
kGoodweatherCmdFan
const uint8_t kGoodweatherCmdFan
Definition: ir_Goodweather.h:77
IRGoodweatherAc::getPower
bool getPower(void)
Get the value of the current power setting.
Definition: ir_Goodweather.cpp:107
kGoodweatherCmdHold
const uint8_t kGoodweatherCmdHold
Definition: ir_Goodweather.h:80
IRGoodweatherAc::setSwing
void setSwing(const uint8_t speed)
Set the Vertical Swing speed of the A/C.
Definition: ir_Goodweather.cpp:216
kGoodweatherFan
const uint8_t kGoodweatherFan
Definition: ir_Goodweather.h:57
kGoodweatherCmdTurbo
const uint8_t kGoodweatherCmdTurbo
Definition: ir_Goodweather.h:82
IRGoodweatherAc::setCommand
void setCommand(const uint8_t cmd)
Set the remote Command type/button pressed.
Definition: ir_Goodweather.cpp:237
IRGoodweatherAc::getFan
uint8_t getFan(void)
Get the current fan speed setting.
Definition: ir_Goodweather.cpp:147
kGoodweatherBitSwing
const uint8_t kGoodweatherBitSwing
Definition: ir_Goodweather.h:42
kGoodweatherStateInit
const uint64_t kGoodweatherStateInit
Definition: ir_Goodweather.h:85
kGoodweatherCmdTimer
const uint8_t kGoodweatherCmdTimer
Definition: ir_Goodweather.h:78
kGoodweatherBitSleep
const uint8_t kGoodweatherBitSleep
Definition: ir_Goodweather.h:40
IRGoodweatherAc::setMode
void setMode(const uint8_t mode)
Set the operating mode of the A/C.
Definition: ir_Goodweather.cpp:153
kGoodweatherBitLight
const uint8_t kGoodweatherBitLight
Definition: ir_Goodweather.h:36
kGoodweatherTempMax
const uint8_t kGoodweatherTempMax
Definition: ir_Goodweather.h:70
IRGoodweatherAc::toCommonFanSpeed
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed)
Convert a native fan speed into its stdAc equivilant.
Definition: ir_Goodweather.cpp:306
IRGoodweatherAc::getCommand
uint8_t getCommand(void)
Get the Command type/button pressed from the current settings.
Definition: ir_Goodweather.cpp:244
kGoodweatherFanLow
const uint8_t kGoodweatherFanLow
Definition: ir_Goodweather.h:67
IRGoodweatherAc::getTemp
uint8_t getTemp(void)
Get the current temperature setting.
Definition: ir_Goodweather.cpp:124
IRGoodweatherAc::toString
String toString()
Convert the current internal state into a human readable string.
Definition: ir_Goodweather.cpp:344
IRGoodweatherAc::setFan
void setFan(const uint8_t speed)
Set the speed of the fan.
Definition: ir_Goodweather.cpp:131
kGoodweatherHeat
const uint8_t kGoodweatherHeat
Definition: ir_Goodweather.h:58
kGoodweatherBitMark
const uint16_t kGoodweatherBitMark
Definition: ir_Goodweather.h:28
IRGoodweatherAc::remote
uint64_t remote
The state of the IR remote in IR code form.
Definition: ir_Goodweather.h:142
kGoodweatherFanHigh
const uint8_t kGoodweatherFanHigh
Definition: ir_Goodweather.h:65
IRGoodweatherAc::convertFan
uint8_t convertFan(const stdAc::fanspeed_t speed)
Convert a stdAc::fanspeed_t enum into it's native speed.
Definition: ir_Goodweather.cpp:264
IRGoodweatherAc::getMode
uint8_t getMode()
Get the operating mode setting of the A/C.
Definition: ir_Goodweather.cpp:171
IRGoodweatherAc::convertMode
uint8_t convertMode(const stdAc::opmode_t mode)
Convert a stdAc::opmode_t enum into its native mode.
Definition: ir_Goodweather.cpp:251
kGoodweatherHdrMark
const uint16_t kGoodweatherHdrMark
Definition: ir_Goodweather.h:31
kGoodweatherSwingSize
const uint8_t kGoodweatherSwingSize
Definition: ir_Goodweather.h:43
kGoodweatherBitAirFlow
const uint8_t kGoodweatherBitAirFlow
Definition: ir_Goodweather.h:44
IRGoodweatherAc::setPower
void setPower(const bool on)
Change the power setting.
Definition: ir_Goodweather.cpp:100
IRGoodweatherAc::setSleep
void setSleep(const bool toggle)
Set the Sleep Toggle setting of the A/C.
Definition: ir_Goodweather.cpp:190
stdAc::state_t
Structure to hold a common A/C state.
Definition: IRsend.h:97
IRGoodweatherAc
Class for handling detailed Goodweather A/C messages.
Definition: ir_Goodweather.h:90
kGoodweatherBitCommand
const uint8_t kGoodweatherBitCommand
Definition: ir_Goodweather.h:38
kGoodweatherBitPower
const uint8_t kGoodweatherBitPower
Definition: ir_Goodweather.h:41
kGoodweatherBitTemp
const uint8_t kGoodweatherBitTemp
Definition: ir_Goodweather.h:47
IRGoodweatherAc::getRaw
uint64_t getRaw(void)
Get a copy of the internal state as a valid code for this protocol.
Definition: ir_Goodweather.cpp:86
kGoodweatherMinRepeat
const uint16_t kGoodweatherMinRepeat
Definition: IRremoteESP8266.h:907
kGoodweatherCmdMode
const uint8_t kGoodweatherCmdMode
Definition: ir_Goodweather.h:73
IRGoodweatherAc::getSwing
uint8_t getSwing(void)
Get the Vertical Swing speed of the A/C.
Definition: ir_Goodweather.cpp:231
stdAc::opmode_t
opmode_t
Common A/C settings for A/C operating modes.
Definition: IRsend.h:46