IRremoteESP8266
ir_Kelon.h
Go to the documentation of this file.
1 // Copyright 2021 Davide Depau
2 
16 
17 // Supports:
18 // Brand: Kelon, Model: ON/OFF 9000-12000 (KELON)
19 // Brand: Kelon, Model: DG11R2-01 remote (KELON168)
20 // Brand: Kelon, Model: AST-09UW4RVETG00A A/C (KELON168)
21 // Brand: Hisense, Model: AST-09UW4RVETG00A A/C (KELON168)
22 
23 #ifndef IR_KELON_H_
24 #define IR_KELON_H_
25 
26 #ifdef UNIT_TEST
27 #include "IRsend_test.h"
28 #endif
29 
30 #include "IRremoteESP8266.h"
31 #include "IRsend.h"
32 #include "IRutils.h"
33 
35  uint64_t raw;
36 
37  struct {
38  uint8_t preamble[2];
39  uint8_t Fan: 2;
40  uint8_t PowerToggle: 1;
41  uint8_t SleepEnabled: 1;
42  uint8_t DehumidifierGrade: 3;
43  uint8_t SwingVToggle: 1;
44  uint8_t Mode: 3;
45  uint8_t TimerEnabled: 1;
46  uint8_t Temperature: 4;
47  uint8_t TimerHalfHour: 1;
48  uint8_t TimerHours: 6;
49  uint8_t SmartModeEnabled: 1;
50  uint8_t pad1: 4;
51  uint8_t SuperCoolEnabled1: 1;
52  uint8_t pad2: 2;
53  uint8_t SuperCoolEnabled2: 1;
54  };
55 };
56 
57 // Constants
58 const uint8_t kKelonModeHeat = 0;
59 const uint8_t kKelonModeSmart = 1; // (temp = 26C, but not shown)
60 const uint8_t kKelonModeCool = 2;
61 const uint8_t kKelonModeDry = 3; // (temp = 25C, but not shown)
62 const uint8_t kKelonModeFan = 4; // (temp = 25C, but not shown)
63 const uint8_t kKelonFanAuto = 0;
64 // Note! Kelon fan speeds are actually 0:AUTO, 1:MAX, 2:MED, 3:MIN
65 // Since this is insane, I decided to invert them in the public API, they are
66 // converted back in setFan/getFan
67 const uint8_t kKelonFanMin = 1;
68 const uint8_t kKelonFanMedium = 2;
69 const uint8_t kKelonFanMax = 3;
70 
71 const int8_t kKelonDryGradeMin = -2;
72 const int8_t kKelonDryGradeMax = +2;
73 const uint8_t kKelonMinTemp = 18;
74 const uint8_t kKelonMaxTemp = 32;
75 
76 
77 class IRKelonAc {
78  public:
79  explicit IRKelonAc(uint16_t pin, bool inverted = false,
80  bool use_modulation = true);
81  void stateReset(void);
82  #if SEND_KELON
83  void send(const uint16_t repeat = kNoRepeat);
88  int8_t calibrate(void) { return _irsend.calibrate(); }
93  void ensurePower(const bool on);
94  #endif // SEND_KELON
95 
96 
97  void begin(void);
98  void setTogglePower(const bool toggle);
99  bool getTogglePower(void) const;
100  void setTemp(const uint8_t degrees);
101  uint8_t getTemp(void) const;
102  void setFan(const uint8_t speed);
103  uint8_t getFan(void) const;
104  void setDryGrade(const int8_t grade);
105  int8_t getDryGrade(void) const;
106  void setMode(const uint8_t mode);
107  uint8_t getMode(void) const;
108  void setToggleSwingVertical(const bool toggle);
109  bool getToggleSwingVertical(void) const;
110  void setSleep(const bool on);
111  bool getSleep(void) const;
112  void setSupercool(const bool on);
113  bool getSupercool(void) const;
114  void setTimer(const uint16_t mins);
115  uint16_t getTimer(void) const;
116  void setTimerEnabled(const bool on);
117  bool getTimerEnabled(void) const;
118  uint64_t getRaw(void) const;
119  void setRaw(const uint64_t new_code);
120  static uint8_t convertMode(const stdAc::opmode_t mode);
121  static uint8_t convertFan(const stdAc::fanspeed_t fan);
122  static stdAc::opmode_t toCommonMode(const uint8_t mode);
123  static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
124  stdAc::state_t toCommon(const stdAc::state_t *prev = nullptr) const;
125  String toString(void) const;
126 
127  private:
128 #ifndef UNIT_TEST
130 #else // UNIT_TEST
131  IRsendTest _irsend;
133 #endif // UNIT_TEST
136 
137  // Used when exiting supercool mode
138  uint8_t _previousMode = 0;
141 };
142 #endif // IR_KELON_H_
IRKelonAc::getMode
uint8_t getMode(void) const
Get the current operation mode setting.
Definition: ir_Kelon.cpp:256
IRKelonAc::getSleep
bool getSleep(void) const
Is the sleep setting on?
Definition: ir_Kelon.cpp:274
IRKelonAc::ensurePower
void ensurePower(const bool on)
Since the AC does not support actually setting the power state to a known value, this utility allow e...
Definition: ir_Kelon.cpp:130
IRKelonAc::setRaw
void setRaw(const uint64_t new_code)
Set the raw state of the object.
Definition: ir_Kelon.cpp:341
IRKelonAc::_previousMode
uint8_t _previousMode
Definition: ir_Kelon.h:138
kKelonFanAuto
const uint8_t kKelonFanAuto
Definition: ir_Kelon.h:63
KelonProtocol::Fan
uint8_t Fan
Definition: ir_Kelon.h:39
stdAc::fanspeed_t
fanspeed_t
Common A/C settings for Fan Speeds.
Definition: IRsend.h:61
KelonProtocol::Mode
uint8_t Mode
Definition: ir_Kelon.h:44
KelonProtocol::SuperCoolEnabled2
uint8_t SuperCoolEnabled2
Definition: ir_Kelon.h:53
IRKelonAc::getRaw
uint64_t getRaw(void) const
Get the raw state of the object, suitable to be sent with the appropriate IRsend object method.
Definition: ir_Kelon.cpp:337
kKelonDryGradeMin
const int8_t kKelonDryGradeMin
Definition: ir_Kelon.h:71
IRKelonAc::setToggleSwingVertical
void setToggleSwingVertical(const bool toggle)
Request toggling the vertical swing - will be reset to false after sending.
Definition: ir_Kelon.cpp:260
KelonProtocol::preamble
uint8_t preamble[2]
Definition: ir_Kelon.h:38
IRsend.h
IRKelonAc::calibrate
int8_t calibrate(void)
Run the calibration to calculate uSec timing offsets for this platform.
Definition: ir_Kelon.h:88
KelonProtocol::TimerEnabled
uint8_t TimerEnabled
Definition: ir_Kelon.h:45
kKelonMaxTemp
const uint8_t kKelonMaxTemp
Definition: ir_Kelon.h:74
IRKelonAc::toString
String toString(void) const
Convert the internal settings into a human readable string.
Definition: ir_Kelon.cpp:428
IRsend
Class for sending all basic IR protocols.
Definition: IRsend.h:237
KelonProtocol::raw
uint64_t raw
Definition: ir_Kelon.h:35
IRsend::calibrate
int8_t calibrate(uint16_t hz=38000U)
Calculate & set any offsets to account for execution times during sending.
Definition: IRsend.cpp:207
IRKelonAc::getToggleSwingVertical
bool getToggleSwingVertical(void) const
Get whether the swing mode is set to be toggled.
Definition: ir_Kelon.cpp:266
IRKelonAc::begin
void begin(void)
Set up hardware to be able to send a message.
Definition: ir_Kelon.cpp:156
IRKelonAc
Definition: ir_Kelon.h:77
kKelonFanMedium
const uint8_t kKelonFanMedium
Definition: ir_Kelon.h:68
String
std::string String
Definition: IRremoteESP8266.h:1521
kKelonModeSmart
const uint8_t kKelonModeSmart
Definition: ir_Kelon.h:59
IRKelonAc::stateReset
void stateReset(void)
Reset the internals of the object to a known good state.
Definition: ir_Kelon.cpp:104
kKelonModeDry
const uint8_t kKelonModeDry
Definition: ir_Kelon.h:61
IRKelonAc::setFan
void setFan(const uint8_t speed)
Set the speed of the fan.
Definition: ir_Kelon.cpp:181
IRKelonAc::send
void send(const uint16_t repeat=kNoRepeat)
Send the current internal state as an IR message.
Definition: ir_Kelon.cpp:114
KelonProtocol::PowerToggle
uint8_t PowerToggle
Definition: ir_Kelon.h:40
IRremoteESP8266.h
IRKelonAc::setTemp
void setTemp(const uint8_t degrees)
Set the temperature setting.
Definition: ir_Kelon.cpp:168
IRKelonAc::toCommonFanSpeed
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed)
Convert a native fan speed to it's stdAc::fanspeed_t equivalent.
Definition: ir_Kelon.cpp:386
kKelonModeCool
const uint8_t kKelonModeCool
Definition: ir_Kelon.h:60
KelonProtocol::TimerHours
uint8_t TimerHours
Definition: ir_Kelon.h:48
kNoRepeat
const uint16_t kNoRepeat
Definition: IRremoteESP8266.h:1145
KelonProtocol::pad1
uint8_t pad1
Definition: ir_Kelon.h:50
IRKelonAc::_previousFan
uint8_t _previousFan
Definition: ir_Kelon.h:140
KelonProtocol::DehumidifierGrade
uint8_t DehumidifierGrade
Definition: ir_Kelon.h:42
kKelonModeHeat
const uint8_t kKelonModeHeat
Definition: ir_Kelon.h:58
IRKelonAc::setDryGrade
void setDryGrade(const int8_t grade)
Set the dehumidification intensity.
Definition: ir_Kelon.cpp:198
IRKelonAc::setSupercool
void setSupercool(const bool on)
Control the current super cool mode setting.
Definition: ir_Kelon.cpp:278
IRKelonAc::getTimer
uint16_t getTimer(void) const
Get the set timer. Timer set time is deleted once the command is sent, so calling this after send() w...
Definition: ir_Kelon.cpp:319
kKelonMinTemp
const uint8_t kKelonMinTemp
Definition: ir_Kelon.h:73
IRKelonAc::convertFan
static uint8_t convertFan(const stdAc::fanspeed_t fan)
Convert a standard A/C fan speed (stdAc::fanspeed_t) into it a native speed.
Definition: ir_Kelon.cpp:359
IRKelonAc::_irsend
IRsend _irsend
Instance of the IR send class.
Definition: ir_Kelon.h:129
IRKelonAc::IRKelonAc
IRKelonAc(uint16_t pin, bool inverted=false, bool use_modulation=true)
Class constructor.
Definition: ir_Kelon.cpp:99
KelonProtocol::SmartModeEnabled
uint8_t SmartModeEnabled
Definition: ir_Kelon.h:49
KelonProtocol::TimerHalfHour
uint8_t TimerHalfHour
Definition: ir_Kelon.h:47
IRKelonAc::getFan
uint8_t getFan(void) const
Get the current fan speed setting.
Definition: ir_Kelon.cpp:192
KelonProtocol::SwingVToggle
uint8_t SwingVToggle
Definition: ir_Kelon.h:43
IRutils.h
IRKelonAc::_
KelonProtocol _
Definition: ir_Kelon.h:135
IRKelonAc::setSleep
void setSleep(const bool on)
Control the current sleep (quiet) setting.
Definition: ir_Kelon.cpp:270
KelonProtocol::SleepEnabled
uint8_t SleepEnabled
Definition: ir_Kelon.h:41
KelonProtocol
Definition: ir_Kelon.h:34
IRKelonAc::toCommon
stdAc::state_t toCommon(const stdAc::state_t *prev=nullptr) const
Convert the internal A/C object state to it's stdAc::state_t equivalent.
Definition: ir_Kelon.cpp:397
IRKelonAc::getTogglePower
bool getTogglePower(void) const
Get whether toggling power will be requested.
Definition: ir_Kelon.cpp:164
IRKelonAc::getDryGrade
int8_t getDryGrade(void) const
Get the current dehumidification intensity setting. In smart mode, this controls the temperature adju...
Definition: ir_Kelon.cpp:214
KelonProtocol::Temperature
uint8_t Temperature
Definition: ir_Kelon.h:46
kKelonFanMax
const uint8_t kKelonFanMax
Definition: ir_Kelon.h:69
IRKelonAc::toCommonMode
static stdAc::opmode_t toCommonMode(const uint8_t mode)
Convert a native mode to it's stdAc::opmode_t equivalent.
Definition: ir_Kelon.cpp:373
IRKelonAc::getSupercool
bool getSupercool(void) const
Is the super cool mode setting on?
Definition: ir_Kelon.cpp:293
KelonProtocol::pad2
uint8_t pad2
Definition: ir_Kelon.h:52
kKelonModeFan
const uint8_t kKelonModeFan
Definition: ir_Kelon.h:62
kKelonDryGradeMax
const int8_t kKelonDryGradeMax
Definition: ir_Kelon.h:72
IRKelonAc::setMode
void setMode(const uint8_t mode)
Set the desired operation mode.
Definition: ir_Kelon.cpp:221
KelonProtocol::SuperCoolEnabled1
uint8_t SuperCoolEnabled1
Definition: ir_Kelon.h:51
IRKelonAc::setTimerEnabled
void setTimerEnabled(const bool on)
Enable or disable the timer. Note that in order to enable the timer the minutes must be set with setT...
Definition: ir_Kelon.cpp:328
kKelonFanMin
const uint8_t kKelonFanMin
Definition: ir_Kelon.h:67
stdAc::state_t
Structure to hold a common A/C state.
Definition: IRsend.h:114
IRKelonAc::convertMode
static uint8_t convertMode(const stdAc::opmode_t mode)
Convert a standard A/C mode (stdAc::opmode_t) into it a native mode.
Definition: ir_Kelon.cpp:346
IRKelonAc::getTimerEnabled
bool getTimerEnabled(void) const
Get the current timer status.
Definition: ir_Kelon.cpp:332
IRKelonAc::getTemp
uint8_t getTemp(void) const
Get the current temperature setting.
Definition: ir_Kelon.cpp:177
IRKelonAc::setTimer
void setTimer(const uint16_t mins)
Set the timer time and enable it. Timer is an off timer if the unit is on, it is an on timer if the u...
Definition: ir_Kelon.cpp:299
IRKelonAc::setTogglePower
void setTogglePower(const bool toggle)
Request toggling power - will be reset to false after sending.
Definition: ir_Kelon.cpp:160
IRKelonAc::_previousTemp
uint8_t _previousTemp
Definition: ir_Kelon.h:139
stdAc::opmode_t
opmode_t
Common A/C settings for A/C operating modes.
Definition: IRsend.h:49