IRremoteESP8266: src/ir_Toshiba.h Source File

IRremoteESP8266

ir_Toshiba.h
Go to the documentation of this file.
1 // Copyright 2017 David Conran
2
11
12 // Supports:
13 // Brand: Toshiba, Model: RAS-B13N3KV2
14 // Brand: Toshiba, Model: Akita EVO II
15 // Brand: Toshiba, Model: RAS-B13N3KVP-E
16 // Brand: Toshiba, Model: RAS 18SKP-ES
17 // Brand: Toshiba, Model: WH-TA04NE
18 // Brand: Toshiba, Model: WC-L03SE
19 // Brand: Carrier, Model: 42NQV060M2 / 38NYV060M2 A/C
20 // Brand: Carrier, Model: 42NQV050M2 / 38NYV050M2 A/C
21 // Brand: Carrier, Model: 42NQV035M2 / 38NYV035M2 A/C
22 // Brand: Carrier, Model: 42NQV025M2 / 38NYV025M2 A/C
23
24 #ifndef IR_TOSHIBA_H_
25 #define IR_TOSHIBA_H_
26
27 #define __STDC_LIMIT_MACROS
28 #include <stdint.h>
29 #ifdef ARDUINO
30 #include <Arduino.h>
31 #endif
32 #include "IRremoteESP8266.h"
33 #include "IRsend.h"
34 #ifdef UNIT_TEST
35 #include "IRsend_test.h"
36 #endif
37
39 union ToshibaProtocol{
40 uint8_t raw[kToshibaACStateLengthLong];
41 struct {
42 // Byte[0] - 0xF2
43 uint8_t :8;
44 // Byte[1] - 0x0D (inverted previous byte's value)
45 uint8_t :8;
46 // Byte[2] - The expected payload length (in bytes) past the Byte[4].
51 uint8_t Length :8;
52 // Byte[3] - The bit-inverted value of the "length" byte.
53 uint8_t :8;
54 // Byte[4]
55 uint8_t :3;
56 uint8_t LongMsg :1;
57 uint8_t :1;
58 uint8_t ShortMsg:1;
59 uint8_t :2;
60 // Byte[5]
61 uint8_t Swing :2;
62 uint8_t :2;
63 uint8_t Temp :4;
64 // Byte[6]
65 uint8_t Mode :3;
66 uint8_t :2;
67 uint8_t Fan :3;
68 // Byte[7]
69 uint8_t :8;
70 // Byte[8]
71 // (Checksum for 72 bit messages, Eco/Turbo for long 80 bit messages)
72 uint8_t EcoTurbo :8;
73 };
74 };
75
76 // Constants
77
78 const uint8_t kToshibaAcLengthByte = 2;
79 const uint8_t kToshibaAcMinLength = 6;
80
81 const uint16_t kToshibaAcInvertedLength = 4;
82
84 const uint8_t kToshibaAcSwingStep = 0;
85 const uint8_t kToshibaAcSwingOn = 1;
86 const uint8_t kToshibaAcSwingOff = 2;
87
88 const uint8_t kToshibaAcMinTemp = 17;
89 const uint8_t kToshibaAcMaxTemp = 30;
90
91 const uint8_t kToshibaAcAuto = 0; // 0b000
92 const uint8_t kToshibaAcCool = 1; // 0b001
93 const uint8_t kToshibaAcDry = 2; // 0b010
94 const uint8_t kToshibaAcHeat = 3; // 0b011
95 const uint8_t kToshibaAcFan = 4; // 0b100
96 const uint8_t kToshibaAcOff = 7; // 0b111
97 const uint8_t kToshibaAcFanAuto = 0; // 0b000
98 const uint8_t kToshibaAcFanMin = 1; // 0b001
99 const uint8_t kToshibaAcFanMed = 3; // 0b011
100 const uint8_t kToshibaAcFanMax = 5; // 0b101
101
102 const uint8_t kToshibaAcTurboOn = 1; // 0b01
103 const uint8_t kToshibaAcEconoOn = 3; // 0b11
104
105 // Legacy defines. (Deprecated)
106 #define TOSHIBA_AC_AUTO kToshibaAcAuto
107 #define TOSHIBA_AC_COOL kToshibaAcCool
108 #define TOSHIBA_AC_DRY kToshibaAcDry
109 #define TOSHIBA_AC_HEAT kToshibaAcHeat
110 #define TOSHIBA_AC_POWER kToshibaAcPower
111 #define TOSHIBA_AC_FAN_AUTO kToshibaAcFanAuto
112 #define TOSHIBA_AC_FAN_MAX kToshibaAcFanMax
113 #define TOSHIBA_AC_MIN_TEMP kToshibaAcMinTemp
114 #define TOSHIBA_AC_MAX_TEMP kToshibaAcMaxTemp
115
116 // Classes
118 class IRToshibaAC {
119 public:
120 explicit IRToshibaAC(const uint16_t pin, const bool inverted = false,
121 const bool use_modulation = true);
122 void stateReset(void);
123 #if SEND_TOSHIBA_AC
124 void send(const uint16_t repeat = kToshibaACMinRepeat);
129 int8_t calibrate(void) { return _irsend.calibrate(); }
130 #endif // SEND_TOSHIBA_AC
131 void begin(void);
132 void on(void);
133 void off(void);
134 void setPower(const bool on);
135 bool getPower(void) const;
136 void setTemp(const uint8_t degrees);
137 uint8_t getTemp(void) const;
138 void setFan(const uint8_t speed);
139 uint8_t getFan(void) const;
140 void setTurbo(const bool on);
141 bool getTurbo(void) const;
142 void setEcono(const bool on);
143 bool getEcono(void) const;
144 void setMode(const uint8_t mode);
145 uint8_t getMode(const bool raw = false) const;
146 void setRaw(const uint8_t newState[]);
147 uint8_t* getRaw(void);
148 static uint16_t getInternalStateLength(const uint8_t state[],
149 const uint16_t size);
150 uint16_t getStateLength(void) const;
151 static bool validChecksum(const uint8_t state[],
152 const uint16_t length = kToshibaACStateLength);
153 uint8_t getSwing(const bool raw = true) const;
154 void setSwing(const uint8_t setting);
155 static uint8_t convertMode(const stdAc::opmode_t mode);
156 static uint8_t convertFan(const stdAc::fanspeed_t speed);
157 static stdAc::opmode_t toCommonMode(const uint8_t mode);
158 static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
159 stdAc::state_t toCommon(void) const;
160 String toString(void) const;
161 #ifndef UNIT_TEST
162
163 private:
164 IRsend _irsend;
165 #else // UNIT_TEST
166 IRsendTest _irsend;
168 #endif // UNIT_TEST
170 ToshibaProtocol _;
171 uint8_t backup[kToshibaACStateLengthLong];
172 uint8_t _prev_mode;
173 bool _send_swing;
174 uint8_t _swing_mode;
175 void checksum(const uint16_t length = kToshibaACStateLength);
176 static uint8_t calcChecksum(const uint8_t state[],
177 const uint16_t length = kToshibaACStateLength);
178 void setStateLength(const uint16_t size);
179 void _backupState(void);
180 void _restoreState(void);
181 };
182
183 #endif // IR_TOSHIBA_H_
IRToshibaAC::off
void off(void)
Set the requested power state of the A/C to off.
Definition: ir_Toshiba.cpp:186
IRToshibaAC::toCommonMode
static stdAc::opmode_t toCommonMode(const uint8_t mode)
Convert a native mode into its stdAc equivalent.
Definition: ir_Toshiba.cpp:368
IRToshibaAC
Class for handling detailed Toshiba A/C messages.
Definition: ir_Toshiba.h:118
IRToshibaAC::getEcono
bool getEcono(void) const
Get the Economy mode setting of the A/C.
Definition: ir_Toshiba.cpp:319
IRToshibaAC::setSwing
void setSwing(const uint8_t setting)
Set the swing setting of the A/C.
Definition: ir_Toshiba.cpp:247
kToshibaAcCool
const uint8_t kToshibaAcCool
Definition: ir_Toshiba.h:92
IRToshibaAC::setTurbo
void setTurbo(const bool on)
Set the Turbo (Powerful) setting of the A/C.
Definition: ir_Toshiba.cpp:308
IRToshibaAC::getSwing
uint8_t getSwing(const bool raw=true) const
Get the swing setting of the A/C.
Definition: ir_Toshiba.cpp:241
IRToshibaAC::calcChecksum
static uint8_t calcChecksum(const uint8_t state[], const uint16_t length=kToshibaACStateLength)
Calculate the checksum for a given state.
Definition: ir_Toshiba.cpp:151
IRToshibaAC::_swing_mode
uint8_t _swing_mode
The saved swing state/mode/command.
Definition: ir_Toshiba.h:174
IRToshibaAC::on
void on(void)
Set the requested power state of the A/C to on.
Definition: ir_Toshiba.cpp:183
IRToshibaAC::_backupState
void _backupState(void)
Make a copy of the internal code-form A/C state.
Definition: ir_Toshiba.cpp:122
IRToshibaAC::convertMode
static uint8_t convertMode(const stdAc::opmode_t mode)
Convert a stdAc::opmode_t enum into its native mode.
Definition: ir_Toshiba.cpp:340
stdAc::fanspeed_t
fanspeed_t
Common A/C settings for Fan Speeds.
Definition: IRsend.h:58
IRToshibaAC::getInternalStateLength
static uint16_t getInternalStateLength(const uint8_t state[], const uint16_t size)
Get the length of the supplied Toshiba state per it's protocol structure.
Definition: ir_Toshiba.cpp:101
kToshibaAcFanAuto
const uint8_t kToshibaAcFanAuto
Definition: ir_Toshiba.h:97
IRToshibaAC::send
void send(const uint16_t repeat=kToshibaACMinRepeat)
Send the current internal state as IR messages.
Definition: ir_Toshiba.cpp:81
IRToshibaAC::setEcono
void setEcono(const bool on)
Set the Economy mode setting of the A/C.
Definition: ir_Toshiba.cpp:328
kToshibaAcInvertedLength
const uint16_t kToshibaAcInvertedLength
Nr. of leading bytes in inverted pairs.
Definition: ir_Toshiba.h:81
IRToshibaAC::setFan
void setFan(const uint8_t speed)
Set the speed of the fan.
Definition: ir_Toshiba.cpp:221
kToshibaAcMinTemp
const uint8_t kToshibaAcMinTemp
17C
Definition: ir_Toshiba.h:88
IRToshibaAC::_irsend
IRsend _irsend
Instance of the IR send class.
Definition: ir_Toshiba.h:164
IRToshibaAC::calibrate
int8_t calibrate(void)
Run the calibration to calculate uSec timing offsets for this platform.
Definition: ir_Toshiba.h:129
IRsend.h
IRToshibaAC::getRaw
uint8_t * getRaw(void)
Get a PTR to the internal state/code for this protocol with all integrity checks passing.
Definition: ir_Toshiba.cpp:134
IRToshibaAC::checksum
void checksum(const uint16_t length=kToshibaACStateLength)
Calculate & set the checksum for the current internal state of the remote.
Definition: ir_Toshiba.cpp:169
ToshibaProtocol::raw
uint8_t raw[kToshibaACStateLengthLong]
The state in code form.
Definition: ir_Toshiba.h:40
ToshibaProtocol::EcoTurbo
uint8_t EcoTurbo
Definition: ir_Toshiba.h:72
IRsend
Class for sending all basic IR protocols.
Definition: IRsend.h:187
IRsend::calibrate
int8_t calibrate(uint16_t hz=38000U)
Calculate & set any offsets to account for execution times during sending.
Definition: IRsend.cpp:207
kToshibaAcSwingOn
const uint8_t kToshibaAcSwingOn
0b01
Definition: ir_Toshiba.h:85
IRToshibaAC::setPower
void setPower(const bool on)
Change the power setting.
Definition: ir_Toshiba.cpp:190
String
std::string String
Definition: IRremoteESP8266.h:1199
IRToshibaAC::IRToshibaAC
IRToshibaAC(const uint16_t pin, const bool inverted=false, const bool use_modulation=true)
Class constructor.
Definition: ir_Toshiba.cpp:60
ToshibaProtocol::Fan
uint8_t Fan
Definition: ir_Toshiba.h:67
IRToshibaAC::getStateLength
uint16_t getStateLength(void) const
Get the length of the current internal state per the protocol structure.
Definition: ir_Toshiba.cpp:110
IRToshibaAC::toString
String toString(void) const
Convert the current internal state into a human readable string.
Definition: ir_Toshiba.cpp:422
ToshibaProtocol::LongMsg
uint8_t LongMsg
Definition: ir_Toshiba.h:56
kToshibaAcSwingOff
const uint8_t kToshibaAcSwingOff
0b10
Definition: ir_Toshiba.h:86
IRToshibaAC::getPower
bool getPower(void) const
Get the value of the current power setting.
Definition: ir_Toshiba.cpp:201
kToshibaAcFanMed
const uint8_t kToshibaAcFanMed
Definition: ir_Toshiba.h:99
IRremoteESP8266.h
IRToshibaAC::begin
void begin(void)
Set up hardware to be able to send a message.
Definition: ir_Toshiba.cpp:76
kToshibaAcMinLength
const uint8_t kToshibaAcMinLength
Min Nr. of bytes in a message.
Definition: ir_Toshiba.h:79
kToshibaAcSwingStep
const uint8_t kToshibaAcSwingStep
0b00
Definition: ir_Toshiba.h:84
IRToshibaAC::stateReset
void stateReset(void)
Reset the state of the remote to a known good state/sequence.
Definition: ir_Toshiba.cpp:66
IRToshibaAC::_restoreState
void _restoreState(void)
Recover the internal code-form A/C state from the backup.
Definition: ir_Toshiba.cpp:127
IRToshibaAC::getTemp
uint8_t getTemp(void) const
Get the current temperature setting.
Definition: ir_Toshiba.cpp:215
kToshibaAcFan
const uint8_t kToshibaAcFan
Definition: ir_Toshiba.h:95
IRToshibaAC::toCommonFanSpeed
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed)
Convert a native fan speed into its stdAc equivalent.
Definition: ir_Toshiba.cpp:382
kToshibaAcHeat
const uint8_t kToshibaAcHeat
Definition: ir_Toshiba.h:94
IRToshibaAC::setMode
void setMode(const uint8_t mode)
Set the operating mode of the A/C.
Definition: ir_Toshiba.cpp:275
ToshibaProtocol::Length
uint8_t Length
< Known lengths are: 1 (56 bit message) 3 (72 bit message) 4 (80 bit message)
Definition: ir_Toshiba.h:51
kToshibaAcTurboOn
const uint8_t kToshibaAcTurboOn
Definition: ir_Toshiba.h:102
IRToshibaAC::setRaw
void setRaw(const uint8_t newState[])
Set the internal state from a valid code for this protocol.
Definition: ir_Toshiba.cpp:141
ToshibaProtocol
Native representation of a Toshiba A/C message.
Definition: ir_Toshiba.h:39
ToshibaProtocol::Swing
uint8_t Swing
Definition: ir_Toshiba.h:61
kToshibaAcLengthByte
const uint8_t kToshibaAcLengthByte
Byte pos of the "length" attribute.
Definition: ir_Toshiba.h:78
IRToshibaAC::getMode
uint8_t getMode(const bool raw=false) const
Get the operating mode setting of the A/C.
Definition: ir_Toshiba.cpp:262
ToshibaProtocol::Mode
uint8_t Mode
Definition: ir_Toshiba.h:65
kToshibaACMinRepeat
const uint16_t kToshibaACMinRepeat
Definition: IRremoteESP8266.h:1096
kToshibaACStateLength
const uint16_t kToshibaACStateLength
Definition: IRremoteESP8266.h:1094
IRToshibaAC::_send_swing
bool _send_swing
Flag indicating if we need to send a swing message.
Definition: ir_Toshiba.h:173
kToshibaACStateLengthLong
const uint16_t kToshibaACStateLengthLong
Definition: IRremoteESP8266.h:1099
IRToshibaAC::validChecksum
static bool validChecksum(const uint8_t state[], const uint16_t length=kToshibaACStateLength)
Verify the checksum is valid for a given state.
Definition: ir_Toshiba.cpp:160
IRToshibaAC::toCommon
stdAc::state_t toCommon(void) const
Convert the current internal state into its stdAc::state_t equivalent.
Definition: ir_Toshiba.cpp:395
kToshibaAcDry
const uint8_t kToshibaAcDry
Definition: ir_Toshiba.h:93
IRToshibaAC::getFan
uint8_t getFan(void) const
Get the current fan speed setting.
Definition: ir_Toshiba.cpp:232
IRToshibaAC::backup
uint8_t backup[kToshibaACStateLengthLong]
A backup copy of the state.
Definition: ir_Toshiba.h:171
ToshibaProtocol::ShortMsg
uint8_t ShortMsg
Definition: ir_Toshiba.h:58
IRToshibaAC::getTurbo
bool getTurbo(void) const
Get the Turbo (Powerful) setting of the A/C.
Definition: ir_Toshiba.cpp:299
kToshibaAcAuto
const uint8_t kToshibaAcAuto
Definition: ir_Toshiba.h:91
kToshibaAcMaxTemp
const uint8_t kToshibaAcMaxTemp
30C
Definition: ir_Toshiba.h:89
IRToshibaAC::convertFan
static uint8_t convertFan(const stdAc::fanspeed_t speed)
Convert a stdAc::fanspeed_t enum into it's native speed.
Definition: ir_Toshiba.cpp:354
IRToshibaAC::setTemp
void setTemp(const uint8_t degrees)
Set the temperature.
Definition: ir_Toshiba.cpp:207
ToshibaProtocol::Temp
uint8_t Temp
Definition: ir_Toshiba.h:63
IRToshibaAC::_prev_mode
uint8_t _prev_mode
Store of the previously set mode.
Definition: ir_Toshiba.h:172
stdAc::state_t
Structure to hold a common A/C state.
Definition: IRsend.h:97
kToshibaAcFanMax
const uint8_t kToshibaAcFanMax
Definition: ir_Toshiba.h:100
kToshibaAcEconoOn
const uint8_t kToshibaAcEconoOn
Definition: ir_Toshiba.h:103
IRToshibaAC::_
ToshibaProtocol _
Definition: ir_Toshiba.h:170
kToshibaAcFanMin
const uint8_t kToshibaAcFanMin
Definition: ir_Toshiba.h:98
IRToshibaAC::setStateLength
void setStateLength(const uint16_t size)
Set the internal length of the current internal state per the protocol.
Definition: ir_Toshiba.cpp:116
kToshibaAcOff
const uint8_t kToshibaAcOff
Definition: ir_Toshiba.h:96
stdAc::opmode_t
opmode_t
Common A/C settings for A/C operating modes.
Definition: IRsend.h:46