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 
17 #ifndef IR_ELECTRA_H_
18 #define IR_ELECTRA_H_
19 
20 #define __STDC_LIMIT_MACROS
21 #include <stdint.h>
22 #ifndef UNIT_TEST
23 #include <Arduino.h>
24 #endif
25 #include "IRremoteESP8266.h"
26 #include "IRsend.h"
27 #ifdef UNIT_TEST
28 #include "IRsend_test.h"
29 #endif
30 
34  struct {
35  // Byte 0
36  uint8_t :8;
37  // Byte 1
38  uint8_t SwingV :3;
39  uint8_t Temp :5;
40  // Byte 2
41  uint8_t :5;
42  uint8_t SwingH :3;
43  // Byte 3
44  uint8_t :6;
45  uint8_t SensorUpdate :1;
46  uint8_t :1;
47  // Byte 4
48  uint8_t :5;
49  uint8_t Fan :3;
50  // Byte 5
51  uint8_t :6;
52  uint8_t Turbo :1;
53  uint8_t :1;
54  // Byte 6
55  uint8_t :3;
56  uint8_t IFeel :1;
57  uint8_t :1;
58  uint8_t Mode :3;
59  // Byte 7
60  uint8_t SensorTemp :8;
61  // Byte 8
62  uint8_t :8;
63  // Byte 9
64  uint8_t :2;
65  uint8_t Clean :1;
66  uint8_t :2;
67  uint8_t Power :1;
68  uint8_t :2;
69  // Byte 10
70  uint8_t :8;
71  // Byte 11
72  uint8_t LightToggle :8;
73  // Byte 12
74  uint8_t Sum :8;
75  };
76 };
77 
78 // Constants
79 const uint8_t kElectraAcMinTemp = 16; // 16C
80 const uint8_t kElectraAcMaxTemp = 32; // 32C
81 const uint8_t kElectraAcTempDelta = 8;
82 const uint8_t kElectraAcSwingOn = 0b000;
83 const uint8_t kElectraAcSwingOff = 0b111;
84 
85 const uint8_t kElectraAcFanAuto = 0b101;
86 const uint8_t kElectraAcFanLow = 0b011;
87 const uint8_t kElectraAcFanMed = 0b010;
88 const uint8_t kElectraAcFanHigh = 0b001;
89 
90 const uint8_t kElectraAcAuto = 0b000;
91 const uint8_t kElectraAcCool = 0b001;
92 const uint8_t kElectraAcDry = 0b010;
93 const uint8_t kElectraAcHeat = 0b100;
94 const uint8_t kElectraAcFan = 0b110;
95 
96 const uint8_t kElectraAcLightToggleOn = 0x15;
97 // Light has known ON values of 0x15 (0b00010101) or 0x19 (0b00011001)
98 // Thus common bits ON are: 0b00010001 (0x11)
99 // We will use this for the getLightToggle() test.
100 const uint8_t kElectraAcLightToggleMask = 0x11;
101 // and known OFF values of 0x08 (0b00001000) & 0x05 (0x00000101)
102 const uint8_t kElectraAcLightToggleOff = 0x08;
103 
104 // Re: Byte[7]. Or Delta == 0xA and Temperature are stored in last 6 bits,
105 // and bit 7 stores Unknown flag
106 const uint8_t kElectraAcSensorTempDelta = 0x4A;
107 const uint8_t kElectraAcSensorMinTemp = 0; // 0C
108 const uint8_t kElectraAcSensorMaxTemp = 50; // 50C
109 
110 // Classes
112 class IRElectraAc {
113  public:
114  explicit IRElectraAc(const uint16_t pin, const bool inverted = false,
115  const bool use_modulation = true);
116  void stateReset(void);
117 #if SEND_ELECTRA_AC
118  void send(const uint16_t repeat = kElectraAcMinRepeat);
123  int8_t calibrate(void) { return _irsend.calibrate(); }
124 #endif // SEND_ELECTRA_AC
125  void begin(void);
126  void on(void);
127  void off(void);
128  void setPower(const bool on);
129  bool getPower(void) const;
130  void setMode(const uint8_t mode);
131  uint8_t getMode(void) const;
132  void setTemp(const uint8_t temp);
133  uint8_t getTemp(void) const;
134  void setFan(const uint8_t speed);
135  uint8_t getFan(void) const;
136  void setSwingV(const bool on);
137  bool getSwingV(void) const;
138  void setSwingH(const bool on);
139  bool getSwingH(void) const;
140  void setClean(const bool on);
141  bool getClean(void) const;
142  void setLightToggle(const bool on);
143  bool getLightToggle(void) const;
144  void setTurbo(const bool on);
145  bool getTurbo(void) const;
146  void setIFeel(const bool on);
147  bool getIFeel(void) const;
148  void setSensorUpdate(const bool on);
149  bool getSensorUpdate(void) const;
150  void setSensorTemp(const uint8_t temp);
151  uint8_t getSensorTemp(void) const;
152  uint8_t* getRaw(void);
153  void setRaw(const uint8_t new_code[],
154  const uint16_t length = kElectraAcStateLength);
155  static bool validChecksum(const uint8_t state[],
156  const uint16_t length = kElectraAcStateLength);
157  static uint8_t calcChecksum(const uint8_t state[],
158  const uint16_t length = kElectraAcStateLength);
159  String toString(void) const;
160  static uint8_t convertMode(const stdAc::opmode_t mode);
161  static uint8_t convertFan(const stdAc::fanspeed_t speed);
162  static stdAc::opmode_t toCommonMode(const uint8_t mode);
163  static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
164  stdAc::state_t toCommon(void) const;
165 #ifndef UNIT_TEST
166 
167  private:
169 #else
170  IRsendTest _irsend;
172 #endif
175  void checksum(const uint16_t length = kElectraAcStateLength);
176 };
177 #endif // IR_ELECTRA_H_
ElectraProtocol::Temp
uint8_t Temp
Definition: ir_Electra.h:39
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:79
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:67
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:80
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:85
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:49
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:1053
ElectraProtocol::SensorUpdate
uint8_t SensorUpdate
Definition: ir_Electra.h:45
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:208
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:93
IRElectraAc::_
ElectraProtocol _
Definition: ir_Electra.h:174
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:1309
kElectraAcCool
const uint8_t kElectraAcCool
Definition: ir_Electra.h:91
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:74
ElectraProtocol::SensorTemp
uint8_t SensorTemp
Definition: ir_Electra.h:60
IRElectraAc
Class for handling detailed Electra A/C messages.
Definition: ir_Electra.h:112
kElectraAcAuto
const uint8_t kElectraAcAuto
Definition: ir_Electra.h:90
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:92
ElectraProtocol::IFeel
uint8_t IFeel
Definition: ir_Electra.h:56
kElectraAcSensorMinTemp
const uint8_t kElectraAcSensorMinTemp
Definition: ir_Electra.h:107
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:81
ElectraProtocol
Native representation of a Electra A/C message.
Definition: ir_Electra.h:32
IRElectraAc::calibrate
int8_t calibrate(void)
Run the calibration to calculate uSec timing offsets for this platform.
Definition: ir_Electra.h:123
kElectraAcSensorMaxTemp
const uint8_t kElectraAcSensorMaxTemp
Definition: ir_Electra.h:108
kElectraAcLightToggleOff
const uint8_t kElectraAcLightToggleOff
Definition: ir_Electra.h:102
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:65
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:96
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:58
kElectraAcFanLow
const uint8_t kElectraAcFanLow
Definition: ir_Electra.h:86
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:106
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:38
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:168
kElectraAcSwingOn
const uint8_t kElectraAcSwingOn
Definition: ir_Electra.h:82
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:87
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:88
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:52
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:72
kElectraAcFan
const uint8_t kElectraAcFan
Definition: ir_Electra.h:94
kElectraAcLightToggleMask
const uint8_t kElectraAcLightToggleMask
Definition: ir_Electra.h:100
kElectraAcSwingOff
const uint8_t kElectraAcSwingOff
Definition: ir_Electra.h:83
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:33
ElectraProtocol::SwingH
uint8_t SwingH
Definition: ir_Electra.h:42
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:1051
stdAc::opmode_t
opmode_t
Common A/C settings for A/C operating modes.
Definition: IRsend.h:46