IRremoteESP8266
ir_Electra.h
Go to the documentation of this file.
1 // Copyright 2019-2021 David Conran
5 
6 // Supports:
7 // Brand: AUX, Model: KFR-35GW/BpNFW=3 A/C
8 // Brand: AUX, Model: YKR-T/011 remote
9 // Brand: Electra, Model: Classic INV 17 / AXW12DCS A/C
10 // Brand: Electra, Model: YKR-M/003E remote
11 // Brand: Frigidaire, Model: FGPC102AB1 A/C
12 // Brand: Subtropic, Model: SUB-07HN1_18Y A/C
13 // Brand: Subtropic, Model: YKR-H/102E remote
14 // Brand: Centek, Model: SCT-65Q09 A/C
15 // Brand: Centek, Model: YKR-P/002E remote
16 // Brand: AEG, Model: Chillflex Pro AXP26U338CW A/C
17 
18 #ifndef IR_ELECTRA_H_
19 #define IR_ELECTRA_H_
20 
21 #define __STDC_LIMIT_MACROS
22 #include <stdint.h>
23 #ifndef UNIT_TEST
24 #include <Arduino.h>
25 #endif
26 #include "IRremoteESP8266.h"
27 #include "IRsend.h"
28 #ifdef UNIT_TEST
29 #include "IRsend_test.h"
30 #endif
31 
35  struct {
36  // Byte 0
37  uint8_t :8;
38  // Byte 1
39  uint8_t SwingV :3;
40  uint8_t Temp :5;
41  // Byte 2
42  uint8_t :5;
43  uint8_t SwingH :3;
44  // Byte 3
45  uint8_t :6;
46  uint8_t SensorUpdate :1;
47  uint8_t :1;
48  // Byte 4
49  uint8_t :5;
50  uint8_t Fan :3;
51  // Byte 5
52  uint8_t :6;
53  uint8_t Turbo :1;
54  uint8_t :1;
55  // Byte 6
56  uint8_t :3;
57  uint8_t IFeel :1;
58  uint8_t :1;
59  uint8_t Mode :3;
60  // Byte 7
61  uint8_t SensorTemp :8;
62  // Byte 8
63  uint8_t :8;
64  // Byte 9
65  uint8_t :2;
66  uint8_t Clean :1;
67  uint8_t :2;
68  uint8_t Power :1;
69  uint8_t :2;
70  // Byte 10
71  uint8_t :8;
72  // Byte 11
73  uint8_t LightToggle :8;
74  // Byte 12
75  uint8_t Sum :8;
76  };
77 };
78 
79 // Constants
80 const uint8_t kElectraAcMinTemp = 16; // 16C
81 const uint8_t kElectraAcMaxTemp = 32; // 32C
82 const uint8_t kElectraAcTempDelta = 8;
83 const uint8_t kElectraAcSwingOn = 0b000;
84 const uint8_t kElectraAcSwingOff = 0b111;
85 
86 const uint8_t kElectraAcFanAuto = 0b101;
87 const uint8_t kElectraAcFanLow = 0b011;
88 const uint8_t kElectraAcFanMed = 0b010;
89 const uint8_t kElectraAcFanHigh = 0b001;
90 
91 const uint8_t kElectraAcAuto = 0b000;
92 const uint8_t kElectraAcCool = 0b001;
93 const uint8_t kElectraAcDry = 0b010;
94 const uint8_t kElectraAcHeat = 0b100;
95 const uint8_t kElectraAcFan = 0b110;
96 
97 const uint8_t kElectraAcLightToggleOn = 0x15;
98 // Light has known ON values of 0x15 (0b00010101) or 0x19 (0b00011001)
99 // Thus common bits ON are: 0b00010001 (0x11)
100 // We will use this for the getLightToggle() test.
101 const uint8_t kElectraAcLightToggleMask = 0x11;
102 // and known OFF values of 0x08 (0b00001000) & 0x05 (0x00000101)
103 const uint8_t kElectraAcLightToggleOff = 0x08;
104 
105 // Re: Byte[7]. Or Delta == 0xA and Temperature are stored in last 6 bits,
106 // and bit 7 stores Unknown flag
107 const uint8_t kElectraAcSensorTempDelta = 0x4A;
108 const uint8_t kElectraAcSensorMinTemp = 0; // 0C
109 const uint8_t kElectraAcSensorMaxTemp = 50; // 50C
110 
111 // Classes
113 class IRElectraAc {
114  public:
115  explicit IRElectraAc(const uint16_t pin, const bool inverted = false,
116  const bool use_modulation = true);
117  void stateReset(void);
118 #if SEND_ELECTRA_AC
119  void send(const uint16_t repeat = kElectraAcMinRepeat);
124  int8_t calibrate(void) { return _irsend.calibrate(); }
125 #endif // SEND_ELECTRA_AC
126  void begin(void);
127  void on(void);
128  void off(void);
129  void setPower(const bool on);
130  bool getPower(void) const;
131  void setMode(const uint8_t mode);
132  uint8_t getMode(void) const;
133  void setTemp(const uint8_t temp);
134  uint8_t getTemp(void) const;
135  void setFan(const uint8_t speed);
136  uint8_t getFan(void) const;
137  void setSwingV(const bool on);
138  bool getSwingV(void) const;
139  void setSwingH(const bool on);
140  bool getSwingH(void) const;
141  void setClean(const bool on);
142  bool getClean(void) const;
143  void setLightToggle(const bool on);
144  bool getLightToggle(void) const;
145  void setTurbo(const bool on);
146  bool getTurbo(void) const;
147  void setIFeel(const bool on);
148  bool getIFeel(void) const;
149  void setSensorUpdate(const bool on);
150  bool getSensorUpdate(void) const;
151  void setSensorTemp(const uint8_t temp);
152  uint8_t getSensorTemp(void) const;
153  uint8_t* getRaw(void);
154  void setRaw(const uint8_t new_code[],
155  const uint16_t length = kElectraAcStateLength);
156  static bool validChecksum(const uint8_t state[],
157  const uint16_t length = kElectraAcStateLength);
158  static uint8_t calcChecksum(const uint8_t state[],
159  const uint16_t length = kElectraAcStateLength);
160  String toString(void) const;
161  static uint8_t convertMode(const stdAc::opmode_t mode);
162  static uint8_t convertFan(const stdAc::fanspeed_t speed);
163  static stdAc::opmode_t toCommonMode(const uint8_t mode);
164  static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
165  stdAc::state_t toCommon(void) const;
166 #ifndef UNIT_TEST
167 
168  private:
170 #else
171  IRsendTest _irsend;
173 #endif
176  void checksum(const uint16_t length = kElectraAcStateLength);
177 };
178 #endif // IR_ELECTRA_H_
ElectraProtocol::Temp
uint8_t Temp
Definition: ir_Electra.h:40
IRElectraAc::getMode
uint8_t getMode(void) const
Get the operating mode setting of the A/C.
Definition: ir_Electra.cpp:159
IRElectraAc::convertMode
static uint8_t convertMode(const stdAc::opmode_t mode)
Convert a stdAc::opmode_t enum into its native mode.
Definition: ir_Electra.cpp:166
IRElectraAc::checksum
void checksum(const uint16_t length=kElectraAcStateLength)
Calculate and set the checksum values for the internal state.
Definition: ir_Electra.cpp:95
IRElectraAc::setSensorUpdate
void setSensorUpdate(const bool on)
Set the silent Sensor Update setting of the message. i.e. Is this just a sensor temp update message f...
Definition: ir_Electra.cpp:342
IRElectraAc::getRaw
uint8_t * getRaw(void)
Get a PTR to the internal state/code for this protocol.
Definition: ir_Electra.cpp:110
kElectraAcMinTemp
const uint8_t kElectraAcMinTemp
Definition: ir_Electra.h:80
IRElectraAc::getSwingV
bool getSwingV(void) const
Get the Vertical Swing mode of the A/C.
Definition: ir_Electra.cpp:260
ElectraProtocol::Power
uint8_t Power
Definition: ir_Electra.h:68
IRElectraAc::getSensorUpdate
bool getSensorUpdate(void) const
Get the silent Sensor Update setting of the message. i.e. Is this just a sensor temp update message f...
Definition: ir_Electra.cpp:334
kElectraAcMaxTemp
const uint8_t kElectraAcMaxTemp
Definition: ir_Electra.h:81
stdAc::fanspeed_t
fanspeed_t
Common A/C settings for Fan Speeds.
Definition: IRsend.h:58
IRElectraAc::getPower
bool getPower(void) const
Get the value of the current power setting.
Definition: ir_Electra.cpp:136
IRElectraAc::validChecksum
static bool validChecksum(const uint8_t state[], const uint16_t length=kElectraAcStateLength)
Verify the checksum is valid for a given state.
Definition: ir_Electra.cpp:87
IRElectraAc::toCommon
stdAc::state_t toCommon(void) const
Convert the current internal state into its stdAc::state_t equivalent.
Definition: ir_Electra.cpp:361
kElectraAcFanAuto
const uint8_t kElectraAcFanAuto
Definition: ir_Electra.h:86
IRElectraAc::on
void on(void)
Change the power setting to On.
Definition: ir_Electra.cpp:123
ElectraProtocol::Fan
uint8_t Fan
Definition: ir_Electra.h:50
IRElectraAc::setClean
void setClean(const bool on)
Set the Clean mode of the A/C.
Definition: ir_Electra.cpp:291
IRsend.h
kElectraAcMinRepeat
const uint16_t kElectraAcMinRepeat
Definition: IRremoteESP8266.h:1194
ElectraProtocol::SensorUpdate
uint8_t SensorUpdate
Definition: ir_Electra.h:46
IRElectraAc::getTemp
uint8_t getTemp(void) const
Get the current temperature setting.
Definition: ir_Electra.cpp:199
IRsend
Class for sending all basic IR protocols.
Definition: IRsend.h:212
IRElectraAc::IRElectraAc
IRElectraAc(const uint16_t pin, const bool inverted=false, const bool use_modulation=true)
Class constructor.
Definition: ir_Electra.cpp:56
IRsend::calibrate
int8_t calibrate(uint16_t hz=38000U)
Calculate & set any offsets to account for execution times during sending.
Definition: IRsend.cpp:207
IRElectraAc::setSensorTemp
void setSensorTemp(const uint8_t temp)
Set the Sensor temperature for the IFeel mode.
Definition: ir_Electra.cpp:346
kElectraAcHeat
const uint8_t kElectraAcHeat
Definition: ir_Electra.h:94
IRElectraAc::_
ElectraProtocol _
Definition: ir_Electra.h:175
IRElectraAc::setIFeel
void setIFeel(const bool on)
Set the IFeel mode of the A/C.
Definition: ir_Electra.cpp:319
String
std::string String
Definition: IRremoteESP8266.h:1472
kElectraAcCool
const uint8_t kElectraAcCool
Definition: ir_Electra.h:92
IRElectraAc::setFan
void setFan(const uint8_t speed)
Set the speed of the fan.
Definition: ir_Electra.cpp:206
ElectraProtocol::Sum
uint8_t Sum
Definition: ir_Electra.h:75
ElectraProtocol::SensorTemp
uint8_t SensorTemp
Definition: ir_Electra.h:61
IRElectraAc
Class for handling detailed Electra A/C messages.
Definition: ir_Electra.h:113
kElectraAcAuto
const uint8_t kElectraAcAuto
Definition: ir_Electra.h:91
IRremoteESP8266.h
IRElectraAc::getSensorTemp
uint8_t getSensorTemp(void) const
Get the current sensor temperature setting for the IFeel mode.
Definition: ir_Electra.cpp:354
IRElectraAc::toCommonMode
static stdAc::opmode_t toCommonMode(const uint8_t mode)
Convert a native mode into its stdAc equivalent.
Definition: ir_Electra.cpp:179
kElectraAcDry
const uint8_t kElectraAcDry
Definition: ir_Electra.h:93
ElectraProtocol::IFeel
uint8_t IFeel
Definition: ir_Electra.h:57
kElectraAcSensorMinTemp
const uint8_t kElectraAcSensorMinTemp
Definition: ir_Electra.h:108
IRElectraAc::setRaw
void setRaw(const uint8_t new_code[], const uint16_t length=kElectraAcStateLength)
Set the internal state from a valid code for this protocol.
Definition: ir_Electra.cpp:118
IRElectraAc::getLightToggle
bool getLightToggle(void) const
Get the Light (LED) Toggle mode of the A/C.
Definition: ir_Electra.cpp:284
IRElectraAc::getClean
bool getClean(void) const
Get the Clean mode of the A/C.
Definition: ir_Electra.cpp:297
IRElectraAc::setPower
void setPower(const bool on)
Change the power setting.
Definition: ir_Electra.cpp:130
kElectraAcTempDelta
const uint8_t kElectraAcTempDelta
Definition: ir_Electra.h:82
ElectraProtocol
Native representation of a Electra A/C message.
Definition: ir_Electra.h:33
IRElectraAc::calibrate
int8_t calibrate(void)
Run the calibration to calculate uSec timing offsets for this platform.
Definition: ir_Electra.h:124
kElectraAcSensorMaxTemp
const uint8_t kElectraAcSensorMaxTemp
Definition: ir_Electra.h:109
kElectraAcLightToggleOff
const uint8_t kElectraAcLightToggleOff
Definition: ir_Electra.h:103
IRElectraAc::toCommonFanSpeed
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed)
Convert a native fan speed into its stdAc equivalent.
Definition: ir_Electra.cpp:243
ElectraProtocol::Clean
uint8_t Clean
Definition: ir_Electra.h:66
IRElectraAc::setTemp
void setTemp(const uint8_t temp)
Set the temperature.
Definition: ir_Electra.cpp:191
kElectraAcLightToggleOn
const uint8_t kElectraAcLightToggleOn
Definition: ir_Electra.h:97
IRElectraAc::setLightToggle
void setLightToggle(const bool on)
Set the Light (LED) Toggle mode of the A/C.
Definition: ir_Electra.cpp:278
ElectraProtocol::Mode
uint8_t Mode
Definition: ir_Electra.h:59
kElectraAcFanLow
const uint8_t kElectraAcFanLow
Definition: ir_Electra.h:87
IRElectraAc::setSwingH
void setSwingH(const bool on)
Set the Horizontal Swing mode of the A/C.
Definition: ir_Electra.cpp:266
kElectraAcSensorTempDelta
const uint8_t kElectraAcSensorTempDelta
Definition: ir_Electra.h:107
IRElectraAc::calcChecksum
static uint8_t calcChecksum(const uint8_t state[], const uint16_t length=kElectraAcStateLength)
Calculate the checksum for a given state.
Definition: ir_Electra.cpp:77
ElectraProtocol::SwingV
uint8_t SwingV
Definition: ir_Electra.h:39
IRElectraAc::off
void off(void)
Change the power setting to Off.
Definition: ir_Electra.cpp:126
IRElectraAc::send
void send(const uint16_t repeat=kElectraAcMinRepeat)
Send the current internal state as an IR message.
Definition: ir_Electra.cpp:103
IRElectraAc::_irsend
IRsend _irsend
instance of the IR send class
Definition: ir_Electra.h:169
kElectraAcSwingOn
const uint8_t kElectraAcSwingOn
Definition: ir_Electra.h:83
IRElectraAc::getFan
uint8_t getFan(void) const
Get the current fan speed setting.
Definition: ir_Electra.cpp:222
kElectraAcFanMed
const uint8_t kElectraAcFanMed
Definition: ir_Electra.h:88
IRElectraAc::getIFeel
bool getIFeel(void) const
Get the IFeel mode of the A/C.
Definition: ir_Electra.cpp:315
IRElectraAc::toString
String toString(void) const
Convert the current internal state into a human readable string.
Definition: ir_Electra.cpp:389
kElectraAcFanHigh
const uint8_t kElectraAcFanHigh
Definition: ir_Electra.h:89
IRElectraAc::convertFan
static uint8_t convertFan(const stdAc::fanspeed_t speed)
Convert a stdAc::fanspeed_t enum into it's native speed.
Definition: ir_Electra.cpp:229
IRElectraAc::begin
void begin(void)
Set up hardware to be able to send a message.
Definition: ir_Electra.cpp:71
IRElectraAc::setTurbo
void setTurbo(const bool on)
Set the Turbo mode of the A/C.
Definition: ir_Electra.cpp:303
ElectraProtocol::Turbo
uint8_t Turbo
Definition: ir_Electra.h:53
IRElectraAc::setMode
void setMode(const uint8_t mode)
Set the operating mode of the A/C.
Definition: ir_Electra.cpp:142
IRElectraAc::getTurbo
bool getTurbo(void) const
Get the Turbo mode of the A/C.
Definition: ir_Electra.cpp:309
IRElectraAc::getSwingH
bool getSwingH(void) const
Get the Horizontal Swing mode of the A/C.
Definition: ir_Electra.cpp:272
ElectraProtocol::LightToggle
uint8_t LightToggle
Definition: ir_Electra.h:73
kElectraAcFan
const uint8_t kElectraAcFan
Definition: ir_Electra.h:95
kElectraAcLightToggleMask
const uint8_t kElectraAcLightToggleMask
Definition: ir_Electra.h:101
kElectraAcSwingOff
const uint8_t kElectraAcSwingOff
Definition: ir_Electra.h:84
stdAc::state_t
Structure to hold a common A/C state.
Definition: IRsend.h:97
IRElectraAc::stateReset
void stateReset(void)
Reset the internal state to a fixed known good state.
Definition: ir_Electra.cpp:63
ElectraProtocol::raw
uint8_t raw[kElectraAcStateLength]
The state of the IR remote.
Definition: ir_Electra.h:34
ElectraProtocol::SwingH
uint8_t SwingH
Definition: ir_Electra.h:43
IRElectraAc::setSwingV
void setSwingV(const bool on)
Set the Vertical Swing mode of the A/C.
Definition: ir_Electra.cpp:254
kElectraAcStateLength
const uint16_t kElectraAcStateLength
Definition: IRremoteESP8266.h:1192
stdAc::opmode_t
opmode_t
Common A/C settings for A/C operating modes.
Definition: IRsend.h:46