IRremoteESP8266

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