IRremoteESP8266
ir_Kelon.h
Go to the documentation of this file.
1 // Copyright 2021 Davide Depau
2 
13 // Supports:
14 // Brand: Kelon, Model: ON/OFF 9000-12000
15 
16 #ifndef IR_KELON_H_
17 #define IR_KELON_H_
18 
19 #ifdef UNIT_TEST
20 #include "IRsend_test.h"
21 #endif
22 
23 #include "IRremoteESP8266.h"
24 #include "IRsend.h"
25 #include "IRutils.h"
26 
28  uint64_t raw;
29 
30  struct {
31  uint8_t preamble[2];
32  uint8_t Fan: 2;
33  uint8_t PowerToggle: 1;
34  uint8_t SleepEnabled: 1;
35  uint8_t DehumidifierGrade: 3;
36  uint8_t SwingVToggle: 1;
37  uint8_t Mode: 3;
38  uint8_t TimerEnabled: 1;
39  uint8_t Temperature: 4;
40  uint8_t TimerHalfHour: 1;
41  uint8_t TimerHours: 6;
42  uint8_t SmartModeEnabled: 1;
43  uint8_t pad1: 4;
44  uint8_t SuperCoolEnabled1: 1;
45  uint8_t pad2: 2;
46  uint8_t SuperCoolEnabled2: 1;
47  };
48 };
49 
50 // Constants
51 const uint8_t kKelonModeHeat = 0;
52 const uint8_t kKelonModeSmart = 1; // (temp = 26C, but not shown)
53 const uint8_t kKelonModeCool = 2;
54 const uint8_t kKelonModeDry = 3; // (temp = 25C, but not shown)
55 const uint8_t kKelonModeFan = 4; // (temp = 25C, but not shown)
56 const uint8_t kKelonFanAuto = 0;
57 // Note! Kelon fan speeds are actually 0:AUTO, 1:MAX, 2:MED, 3:MIN
58 // Since this is insane, I decided to invert them in the public API, they are
59 // converted back in setFan/getFan
60 const uint8_t kKelonFanMin = 1;
61 const uint8_t kKelonFanMedium = 2;
62 const uint8_t kKelonFanMax = 3;
63 
64 const int8_t kKelonDryGradeMin = -2;
65 const int8_t kKelonDryGradeMax = +2;
66 const uint8_t kKelonMinTemp = 18;
67 const uint8_t kKelonMaxTemp = 32;
68 
69 
70 class IRKelonAc {
71  public:
72  explicit IRKelonAc(uint16_t pin, bool inverted = false,
73  bool use_modulation = true);
74 
75  void stateReset(void);
76 
77  #if SEND_KELON
78 
79  void send(const uint16_t repeat = kNoRepeat);
80 
85  int8_t calibrate(void) { return _irsend.calibrate(); }
86 
91  void ensurePower(const bool on);
92 
93  #endif
94 
95 
96  void begin(void);
97 
98  void setTogglePower(const bool toggle);
99 
100  bool getTogglePower(void) const;
101 
102  void setTemp(const uint8_t degrees);
103 
104  uint8_t getTemp(void) const;
105 
106  void setFan(const uint8_t speed);
107 
108  uint8_t getFan(void) const;
109 
110  void setDryGrade(const int8_t grade);
111 
112  int8_t getDryGrade(void) const;
113 
114  void setMode(const uint8_t mode);
115 
116  uint8_t getMode(void) const;
117 
118  void setToggleSwingVertical(const bool toggle);
119 
120  bool getToggleSwingVertical(void) const;
121 
122  void setSleep(const bool on);
123 
124  bool getSleep(void) const;
125 
126  void setSupercool(const bool on);
127 
128  bool getSupercool(void) const;
129 
130  void setTimer(const uint16_t mins);
131 
132  uint16_t getTimer(void) const;
133 
134  void setTimerEnabled(const bool on);
135 
136  bool getTimerEnabled(void) const;
137 
138  uint64_t getRaw(void) const;
139 
140  void setRaw(const uint64_t new_code);
141 
142  static uint8_t convertMode(const stdAc::opmode_t mode);
143 
144  static uint8_t convertFan(const stdAc::fanspeed_t fan);
145 
146  static stdAc::opmode_t toCommonMode(const uint8_t mode);
147 
148  static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
149 
150  stdAc::state_t toCommon(const stdAc::state_t *prev = nullptr) const;
151 
152  String toString(void) const;
153 
154  private:
155 #ifndef UNIT_TEST
157 #else // UNIT_TEST
158  IRsendTest _irsend;
160 #endif // UNIT_TEST
163 
164  // Used when exiting supercool mode
165  uint8_t _previousMode = 0;
168 };
169 
170 #endif // IR_KELON_H_
IRKelonAc::getMode
uint8_t getMode(void) const
Get the current operation mode setting.
Definition: ir_Kelon.cpp:263
IRKelonAc::getSleep
bool getSleep(void) const
Is the sleep setting on?
Definition: ir_Kelon.cpp:287
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:128
IRKelonAc::setRaw
void setRaw(const uint64_t new_code)
Set the raw state of the object.
Definition: ir_Kelon.cpp:366
IRKelonAc::_previousMode
uint8_t _previousMode
Definition: ir_Kelon.h:165
kKelonFanAuto
const uint8_t kKelonFanAuto
Definition: ir_Kelon.h:56
KelonProtocol::Fan
uint8_t Fan
Definition: ir_Kelon.h:32
stdAc::fanspeed_t
fanspeed_t
Common A/C settings for Fan Speeds.
Definition: IRsend.h:58
KelonProtocol::Mode
uint8_t Mode
Definition: ir_Kelon.h:37
KelonProtocol::SuperCoolEnabled2
uint8_t SuperCoolEnabled2
Definition: ir_Kelon.h:46
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:360
kKelonDryGradeMin
const int8_t kKelonDryGradeMin
Definition: ir_Kelon.h:64
IRKelonAc::setToggleSwingVertical
void setToggleSwingVertical(const bool toggle)
Request toggling the vertical swing - will be reset to false after sending.
Definition: ir_Kelon.cpp:269
KelonProtocol::preamble
uint8_t preamble[2]
Definition: ir_Kelon.h:31
IRsend.h
IRKelonAc::calibrate
int8_t calibrate(void)
Run the calibration to calculate uSec timing offsets for this platform.
Definition: ir_Kelon.h:85
KelonProtocol::TimerEnabled
uint8_t TimerEnabled
Definition: ir_Kelon.h:38
kKelonMaxTemp
const uint8_t kKelonMaxTemp
Definition: ir_Kelon.h:67
IRKelonAc::toString
String toString(void) const
Convert the internal settings into a human readable string.
Definition: ir_Kelon.cpp:474
IRsend
Class for sending all basic IR protocols.
Definition: IRsend.h:190
KelonProtocol::raw
uint64_t raw
Definition: ir_Kelon.h:28
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:275
IRKelonAc::begin
void begin(void)
Set up hardware to be able to send a message.
Definition: ir_Kelon.cpp:154
IRKelonAc
Definition: ir_Kelon.h:70
kKelonFanMedium
const uint8_t kKelonFanMedium
Definition: ir_Kelon.h:61
String
std::string String
Definition: IRremoteESP8266.h:1279
kKelonModeSmart
const uint8_t kKelonModeSmart
Definition: ir_Kelon.h:52
IRKelonAc::stateReset
void stateReset(void)
Reset the internals of the object to a known good state.
Definition: ir_Kelon.cpp:102
kKelonModeDry
const uint8_t kKelonModeDry
Definition: ir_Kelon.h:54
IRKelonAc::setFan
void setFan(const uint8_t speed)
Set the speed of the fan.
Definition: ir_Kelon.cpp:187
IRKelonAc::send
void send(const uint16_t repeat=kNoRepeat)
Send the current internal state as an IR message.
Definition: ir_Kelon.cpp:112
KelonProtocol::PowerToggle
uint8_t PowerToggle
Definition: ir_Kelon.h:33
IRremoteESP8266.h
IRKelonAc::setTemp
void setTemp(const uint8_t degrees)
Set the temperature setting.
Definition: ir_Kelon.cpp:172
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:427
kKelonModeCool
const uint8_t kKelonModeCool
Definition: ir_Kelon.h:53
KelonProtocol::TimerHours
uint8_t TimerHours
Definition: ir_Kelon.h:41
kNoRepeat
const uint16_t kNoRepeat
Definition: IRremoteESP8266.h:959
KelonProtocol::pad1
uint8_t pad1
Definition: ir_Kelon.h:43
IRKelonAc::_previousFan
uint8_t _previousFan
Definition: ir_Kelon.h:167
KelonProtocol::DehumidifierGrade
uint8_t DehumidifierGrade
Definition: ir_Kelon.h:35
kKelonModeHeat
const uint8_t kKelonModeHeat
Definition: ir_Kelon.h:51
IRKelonAc::setDryGrade
void setDryGrade(const int8_t grade)
Set the dehumidification intensity.
Definition: ir_Kelon.cpp:204
IRKelonAc::setSupercool
void setSupercool(const bool on)
Control the current super cool mode setting.
Definition: ir_Kelon.cpp:293
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:336
kKelonMinTemp
const uint8_t kKelonMinTemp
Definition: ir_Kelon.h:66
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:391
IRKelonAc::_irsend
IRsend _irsend
Instance of the IR send class.
Definition: ir_Kelon.h:156
IRKelonAc::IRKelonAc
IRKelonAc(uint16_t pin, bool inverted=false, bool use_modulation=true)
Class constructor.
Definition: ir_Kelon.cpp:97
KelonProtocol::SmartModeEnabled
uint8_t SmartModeEnabled
Definition: ir_Kelon.h:42
KelonProtocol::TimerHalfHour
uint8_t TimerHalfHour
Definition: ir_Kelon.h:40
IRKelonAc::getFan
uint8_t getFan(void) const
Get the current fan speed setting.
Definition: ir_Kelon.cpp:198
KelonProtocol::SwingVToggle
uint8_t SwingVToggle
Definition: ir_Kelon.h:36
IRutils.h
IRKelonAc::_
KelonProtocol _
Definition: ir_Kelon.h:162
IRKelonAc::setSleep
void setSleep(const bool on)
Control the current sleep (quiet) setting.
Definition: ir_Kelon.cpp:281
KelonProtocol::SleepEnabled
uint8_t SleepEnabled
Definition: ir_Kelon.h:34
KelonProtocol
Definition: ir_Kelon.h:27
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:442
IRKelonAc::getTogglePower
bool getTogglePower(void) const
Get whether toggling power will be requested.
Definition: ir_Kelon.cpp:166
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:221
KelonProtocol::Temperature
uint8_t Temperature
Definition: ir_Kelon.h:39
kKelonFanMax
const uint8_t kKelonFanMax
Definition: ir_Kelon.h:62
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:409
IRKelonAc::getSupercool
bool getSupercool(void) const
Is the super cool mode setting on?
Definition: ir_Kelon.cpp:308
KelonProtocol::pad2
uint8_t pad2
Definition: ir_Kelon.h:45
kKelonModeFan
const uint8_t kKelonModeFan
Definition: ir_Kelon.h:55
kKelonDryGradeMax
const int8_t kKelonDryGradeMax
Definition: ir_Kelon.h:65
IRKelonAc::setMode
void setMode(const uint8_t mode)
Set the desired operation mode.
Definition: ir_Kelon.cpp:228
KelonProtocol::SuperCoolEnabled1
uint8_t SuperCoolEnabled1
Definition: ir_Kelon.h:44
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:346
kKelonFanMin
const uint8_t kKelonFanMin
Definition: ir_Kelon.h:60
stdAc::state_t
Structure to hold a common A/C state.
Definition: IRsend.h:97
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:373
IRKelonAc::getTimerEnabled
bool getTimerEnabled(void) const
Get the current timer status.
Definition: ir_Kelon.cpp:352
IRKelonAc::getTemp
uint8_t getTemp(void) const
Get the current temperature setting.
Definition: ir_Kelon.cpp:181
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:316
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:166
stdAc::opmode_t
opmode_t
Common A/C settings for A/C operating modes.
Definition: IRsend.h:46