# IRremoteESP8266: src/ir_Electra.h Source File

ir_Electra.h
Go to the documentation of this file.
// Copyright 2019 David Conran
// Supports:
// Brand: AUX, Model: KFR-35GW/BpNFW=3 A/C
// Brand: AUX, Model: YKR-T/011 remote
// Brand: Electra, Model: Classic INV 17 / AXW12DCS A/C
// Brand: Electra, Model: YKR-M/003E remote
#ifndef IR_ELECTRA_H_
#define IR_ELECTRA_H_
#define __STDC_LIMIT_MACROS
#include <stdint.h>
#ifndef UNIT_TEST
#include <Arduino.h>
#endif
#include "IRremoteESP8266.h"
#include "IRsend.h"
#ifdef UNIT_TEST
#include "IRsend_test.h"
#endif
union ElectraProtocol {
uint8_t raw[kElectraAcStateLength];
struct {
// Byte 0
uint8_t :8;
// Byte 1
uint8_t SwingV :3;
uint8_t Temp :5;
// Byte 2
uint8_t :5;
uint8_t SwingH :3;
// Byte 3
uint8_t :8;
// Byte 4
uint8_t :5;
uint8_t Fan :3;
// Byte 5
uint8_t :6;
uint8_t Turbo :1;
uint8_t :1;
// Byte 6
uint8_t :5;
uint8_t Mode :3;
// Byte 7
uint8_t :8;
// Byte 8
uint8_t :8;
// Byte 9
uint8_t :2;
uint8_t Clean :1;
uint8_t :2;
uint8_t Power :1;
uint8_t :2;
// Byte 10
uint8_t :8;
// Byte 11
uint8_t LightToggle :8;
// Byte 12
uint8_t Sum :8;
};
};
// Constants
const uint8_t kElectraAcMinTemp = 16; // 16C
const uint8_t kElectraAcMaxTemp = 32; // 32C
const uint8_t kElectraAcTempDelta = 8;
const uint8_t kElectraAcSwingOn = 0b000;
const uint8_t kElectraAcSwingOff = 0b111;
const uint8_t kElectraAcFanAuto = 0b101;
const uint8_t kElectraAcFanLow = 0b011;
const uint8_t kElectraAcFanMed = 0b010;
const uint8_t kElectraAcFanHigh = 0b001;
const uint8_t kElectraAcAuto = 0b000;
const uint8_t kElectraAcCool = 0b001;
const uint8_t kElectraAcDry = 0b010;
const uint8_t kElectraAcHeat = 0b100;
const uint8_t kElectraAcFan = 0b110;
const uint8_t kElectraAcLightToggleOn = 0x15;
// Light has known ON values of 0x15 (0b00010101) or 0x19 (0b00011001)
// Thus common bits ON are: 0b00010001 (0x11)
// We will use this for the getLightToggle() test.
const uint8_t kElectraAcLightToggleMask = 0x11;
// and known OFF values of 0x08 (0b00001000) & 0x05 (0x00000101)
const uint8_t kElectraAcLightToggleOff = 0x08;
// Classes
class IRElectraAc {
public:
explicit IRElectraAc(const uint16_t pin, const bool inverted = false,
const bool use_modulation = true);
void stateReset(void);
#if SEND_ELECTRA_AC
void send(const uint16_t repeat = kElectraAcMinRepeat);
int8_t calibrate(void) { return _irsend.calibrate(); }
#endif // SEND_ELECTRA_AC
void begin(void);
void on(void);
void off(void);
void setPower(const bool on);
bool getPower(void) const;
void setMode(const uint8_t mode);
uint8_t getMode(void) const;
void setTemp(const uint8_t temp);
uint8_t getTemp(void) const;
void setFan(const uint8_t speed);
uint8_t getFan(void) const;
void setSwingV(const bool on);
bool getSwingV(void) const;
void setSwingH(const bool on);
bool getSwingH(void) const;
void setClean(const bool on);
bool getClean(void) const;
void setLightToggle(const bool on);
bool getLightToggle(void) const;
void setTurbo(const bool on);
bool getTurbo(void) const;
uint8_t* getRaw(void);
void setRaw(const uint8_t new_code[],
const uint16_t length = kElectraAcStateLength);
static bool validChecksum(const uint8_t state[],
const uint16_t length = kElectraAcStateLength);
static uint8_t calcChecksum(const uint8_t state[],
const uint16_t length = kElectraAcStateLength);
String toString(void) const;
static uint8_t convertMode(const stdAc::opmode_t mode);
static uint8_t convertFan(const stdAc::fanspeed_t speed);
static stdAc::opmode_t toCommonMode(const uint8_t mode);
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
stdAc::state_t toCommon(void) const;
#ifndef UNIT_TEST
private:
IRsend _irsend;
#else
IRsendTest _irsend;
#endif
ElectraProtocol _;
void checksum(const uint16_t length = kElectraAcStateLength);
};
#endif // IR_ELECTRA_H_
ElectraProtocol::Temp
uint8_t Temp
Definition: ir_Electra.h:34
IRElectraAc::getMode
uint8_t getMode(void) const
Get the operating mode setting of the A/C.
Definition: ir_Electra.cpp:158
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:165
IRElectraAc::checksum
void checksum(const uint16_t length=kElectraAcStateLength)
Calculate and set the checksum values for the internal state.
Definition: ir_Electra.cpp:94
IRElectraAc::getRaw
uint8_t * getRaw(void)
Get a PTR to the internal state/code for this protocol.
Definition: ir_Electra.cpp:109
kElectraAcMinTemp
const uint8_t kElectraAcMinTemp
Definition: ir_Electra.h:70
IRElectraAc::getSwingV
bool getSwingV(void) const
Get the Vertical Swing mode of the A/C.
Definition: ir_Electra.cpp:259
ElectraProtocol::Power
uint8_t Power
Definition: ir_Electra.h:58
kElectraAcMaxTemp
const uint8_t kElectraAcMaxTemp
Definition: ir_Electra.h:71
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:135
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:86
IRElectraAc::toCommon
stdAc::state_t toCommon(void) const
Convert the current internal state into its stdAc::state_t equivalent.
Definition: ir_Electra.cpp:314
kElectraAcFanAuto
const uint8_t kElectraAcFanAuto
Definition: ir_Electra.h:76
IRElectraAc::on
void on(void)
Change the power setting to On.
Definition: ir_Electra.cpp:122
ElectraProtocol::Fan
uint8_t Fan
Definition: ir_Electra.h:42
IRElectraAc::setClean
void setClean(const bool on)
Set the Clean mode of the A/C.
Definition: ir_Electra.cpp:290
IRsend.h
kElectraAcMinRepeat
const uint16_t kElectraAcMinRepeat
Definition: IRremoteESP8266.h:940
IRElectraAc::getTemp
uint8_t getTemp(void) const
Get the current temperature setting.
Definition: ir_Electra.cpp:198
IRsend
Class for sending all basic IR protocols.
Definition: IRsend.h:182
IRElectraAc::IRElectraAc
IRElectraAc(const uint16_t pin, const bool inverted=false, const bool use_modulation=true)
Class constructor.
Definition: ir_Electra.cpp:55
IRsend::calibrate
int8_t calibrate(uint16_t hz=38000U)
Calculate & set any offsets to account for execution times during sending.
Definition: IRsend.cpp:207
kElectraAcHeat
const uint8_t kElectraAcHeat
Definition: ir_Electra.h:84
IRElectraAc::_
ElectraProtocol _
Definition: ir_Electra.h:154
String
std::string String
Definition: IRremoteESP8266.h:1178
kElectraAcCool
const uint8_t kElectraAcCool
Definition: ir_Electra.h:82
IRElectraAc::setFan
void setFan(const uint8_t speed)
Set the speed of the fan.
Definition: ir_Electra.cpp:205
ElectraProtocol::Sum
uint8_t Sum
Definition: ir_Electra.h:65
IRElectraAc
Class for handling detailed Electra A/C messages.
Definition: ir_Electra.h:98
kElectraAcAuto
const uint8_t kElectraAcAuto
Definition: ir_Electra.h:81
IRremoteESP8266.h
IRElectraAc::toCommonMode
static stdAc::opmode_t toCommonMode(const uint8_t mode)
Convert a native mode into its stdAc equivalent.
Definition: ir_Electra.cpp:178
kElectraAcDry
const uint8_t kElectraAcDry
Definition: ir_Electra.h:83
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:117
IRElectraAc::getLightToggle
bool getLightToggle(void) const
Get the Light (LED) Toggle mode of the A/C.
Definition: ir_Electra.cpp:283
IRElectraAc::getClean
bool getClean(void) const
Get the Clean mode of the A/C.
Definition: ir_Electra.cpp:296
IRElectraAc::setPower
void setPower(const bool on)
Change the power setting.
Definition: ir_Electra.cpp:129
kElectraAcTempDelta
const uint8_t kElectraAcTempDelta
Definition: ir_Electra.h:72
ElectraProtocol
Native representation of a Electra A/C message.
Definition: ir_Electra.h:27
IRElectraAc::calibrate
int8_t calibrate(void)
Run the calibration to calculate uSec timing offsets for this platform.
Definition: ir_Electra.h:109
kElectraAcLightToggleOff
const uint8_t kElectraAcLightToggleOff
Definition: ir_Electra.h:93
IRElectraAc::toCommonFanSpeed
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed)
Convert a native fan speed into its stdAc equivalent.
Definition: ir_Electra.cpp:242
ElectraProtocol::Clean
uint8_t Clean
Definition: ir_Electra.h:56
IRElectraAc::setTemp
void setTemp(const uint8_t temp)
Set the temperature.
Definition: ir_Electra.cpp:190
kElectraAcLightToggleOn
const uint8_t kElectraAcLightToggleOn
Definition: ir_Electra.h:87
IRElectraAc::setLightToggle
void setLightToggle(const bool on)
Set the Light (LED) Toggle mode of the A/C.
Definition: ir_Electra.cpp:277
ElectraProtocol::Mode
uint8_t Mode
Definition: ir_Electra.h:49
kElectraAcFanLow
const uint8_t kElectraAcFanLow
Definition: ir_Electra.h:77
IRElectraAc::setSwingH
void setSwingH(const bool on)
Set the Horizontal Swing mode of the A/C.
Definition: ir_Electra.cpp:265
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:76
ElectraProtocol::SwingV
uint8_t SwingV
Definition: ir_Electra.h:33
IRElectraAc::off
void off(void)
Change the power setting to Off.
Definition: ir_Electra.cpp:125
IRElectraAc::send
void send(const uint16_t repeat=kElectraAcMinRepeat)
Send the current internal state as an IR message.
Definition: ir_Electra.cpp:102
IRElectraAc::_irsend
IRsend _irsend
instance of the IR send class
Definition: ir_Electra.h:148
kElectraAcSwingOn
const uint8_t kElectraAcSwingOn
Definition: ir_Electra.h:73
IRElectraAc::getFan
uint8_t getFan(void) const
Get the current fan speed setting.
Definition: ir_Electra.cpp:221
kElectraAcFanMed
const uint8_t kElectraAcFanMed
Definition: ir_Electra.h:78
IRElectraAc::toString
String toString(void) const
Convert the current internal state into a human readable string.
Definition: ir_Electra.cpp:342
kElectraAcFanHigh
const uint8_t kElectraAcFanHigh
Definition: ir_Electra.h:79
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:228
IRElectraAc::begin
void begin(void)
Set up hardware to be able to send a message.
Definition: ir_Electra.cpp:70
IRElectraAc::setTurbo
void setTurbo(const bool on)
Set the Turbo mode of the A/C.
Definition: ir_Electra.cpp:302
ElectraProtocol::Turbo
uint8_t Turbo
Definition: ir_Electra.h:45
IRElectraAc::setMode
void setMode(const uint8_t mode)
Set the operating mode of the A/C.
Definition: ir_Electra.cpp:141
IRElectraAc::getTurbo
bool getTurbo(void) const
Get the Turbo mode of the A/C.
Definition: ir_Electra.cpp:308
IRElectraAc::getSwingH
bool getSwingH(void) const
Get the Horizontal Swing mode of the A/C.
Definition: ir_Electra.cpp:271
ElectraProtocol::LightToggle
uint8_t LightToggle
Definition: ir_Electra.h:63
kElectraAcFan
const uint8_t kElectraAcFan
Definition: ir_Electra.h:85
kElectraAcLightToggleMask
const uint8_t kElectraAcLightToggleMask
Definition: ir_Electra.h:91
kElectraAcSwingOff
const uint8_t kElectraAcSwingOff
Definition: ir_Electra.h:74
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:62
ElectraProtocol::raw
uint8_t raw[kElectraAcStateLength]
The state of the IR remote.
Definition: ir_Electra.h:28
ElectraProtocol::SwingH
uint8_t SwingH
Definition: ir_Electra.h:37
IRElectraAc::setSwingV
void setSwingV(const bool on)
Set the Vertical Swing mode of the A/C.
Definition: ir_Electra.cpp:253
kElectraAcStateLength
const uint16_t kElectraAcStateLength
Definition: IRremoteESP8266.h:938
stdAc::opmode_t
opmode_t
Common A/C settings for A/C operating modes.
Definition: IRsend.h:46