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 
38 // Constants
39 // Byte[0] - 0xF2
40 // Byte[1] - 0x0D (inverted previous byte's value)
41 // Byte[2] - The expected payload length (in bytes) past the Byte[4].
42 const uint8_t kToshibaAcLengthByte = 2;
43 const uint8_t kToshibaAcMinLength = 6;
44 // Byte[3] - The bit-inverted value of the "length" byte.
49 const uint16_t kToshibaAcInvertedLength = 4;
50 // Byte[4]
52 const uint8_t kToshibaAcShortMsgBit = 5;
53 const uint8_t kToshibaAcLongMsgBit = 3;
54 // Byte[5]
55 const uint8_t kToshibaAcSwingOffset = 0;
56 const uint8_t kToshibaAcSwingSize = 2;
57 const uint8_t kToshibaAcSwingStep = 0;
58 const uint8_t kToshibaAcSwingOn = 1;
59 const uint8_t kToshibaAcSwingOff = 2;
60 
61 const uint8_t kToshibaAcTempOffset = 4;
62 const uint8_t kToshibaAcTempSize = 4;
63 const uint8_t kToshibaAcMinTemp = 17;
64 const uint8_t kToshibaAcMaxTemp = 30;
65 // Byte[6]
66 const uint8_t kToshibaAcModeOffset = 0;
67 const uint8_t kToshibaAcModeSize = 3; // Mask 0b00000xxx
68 const uint8_t kToshibaAcAuto = 0; // 0b000
69 const uint8_t kToshibaAcCool = 1; // 0b001
70 const uint8_t kToshibaAcDry = 2; // 0b010
71 const uint8_t kToshibaAcHeat = 3; // 0b011
72 const uint8_t kToshibaAcFan = 4; // 0b100
73 const uint8_t kToshibaAcOff = 7; // 0b111
74 const uint8_t kToshibaAcFanOffset = 5;
75 const uint8_t kToshibaAcFanSize = 3; // Mask 0bxxx00000
76 const uint8_t kToshibaAcFanAuto = 0; // 0b000
77 const uint8_t kToshibaAcFanMin = 1; // 0b001
78 const uint8_t kToshibaAcFanMed = 3; // 0b011
79 const uint8_t kToshibaAcFanMax = 5; // 0b101
80 // Byte[8] (Checksum for 72 bit messages, Eco/Turbo for long 80 bit messages)
81 const uint8_t kToshibaAcEcoTurboOffset = 0;
82 const uint8_t kToshibaAcEcoTurboSize = 2; // Mask 0b000000xx
83 const uint8_t kToshibaAcTurboOn = 1; // 0b01
84 const uint8_t kToshibaAcEconoOn = 3; // 0b11
85 // Byte[last] - Checksum (xor)
86 
87 // Legacy defines. (Deperecated)
88 #define TOSHIBA_AC_AUTO kToshibaAcAuto
89 #define TOSHIBA_AC_COOL kToshibaAcCool
90 #define TOSHIBA_AC_DRY kToshibaAcDry
91 #define TOSHIBA_AC_HEAT kToshibaAcHeat
92 #define TOSHIBA_AC_POWER kToshibaAcPower
93 #define TOSHIBA_AC_FAN_AUTO kToshibaAcFanAuto
94 #define TOSHIBA_AC_FAN_MAX kToshibaAcFanMax
95 #define TOSHIBA_AC_MIN_TEMP kToshibaAcMinTemp
96 #define TOSHIBA_AC_MAX_TEMP kToshibaAcMaxTemp
97 
98 // Classes
100 class IRToshibaAC {
101  public:
102  explicit IRToshibaAC(const uint16_t pin, const bool inverted = false,
103  const bool use_modulation = true);
104  void stateReset(void);
105 #if SEND_TOSHIBA_AC
106  void send(const uint16_t repeat = kToshibaACMinRepeat);
111  int8_t calibrate(void) { return _irsend.calibrate(); }
112 #endif // SEND_TOSHIBA_AC
113  void begin(void);
114  void on(void);
115  void off(void);
116  void setPower(const bool on);
117  bool getPower(void);
118  void setTemp(const uint8_t degrees);
119  uint8_t getTemp(void);
120  void setFan(const uint8_t speed);
121  uint8_t getFan(void);
122  void setTurbo(const bool on);
123  bool getTurbo(void);
124  void setEcono(const bool on);
125  bool getEcono(void);
126  void setMode(const uint8_t mode);
127  uint8_t getMode(const bool raw = false);
128  void setRaw(const uint8_t newState[]);
129  uint8_t* getRaw(void);
130  static uint16_t getInternalStateLength(const uint8_t state[],
131  const uint16_t size);
132  uint16_t getStateLength(void);
133  static bool validChecksum(const uint8_t state[],
134  const uint16_t length = kToshibaACStateLength);
135  uint8_t getSwing(const bool raw = true);
136  void setSwing(const uint8_t setting);
137  uint8_t convertMode(const stdAc::opmode_t mode);
138  uint8_t convertFan(const stdAc::fanspeed_t speed);
139  static stdAc::opmode_t toCommonMode(const uint8_t mode);
140  static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
141  stdAc::state_t toCommon(void);
142  String toString(void);
143 #ifndef UNIT_TEST
144 
145  private:
147 #else // UNIT_TEST
148  IRsendTest _irsend;
150 #endif // UNIT_TEST
154  uint8_t prev_mode;
155  bool _send_swing;
156  uint8_t _swing_mode;
157  void checksum(const uint16_t length = kToshibaACStateLength);
158  static uint8_t calcChecksum(const uint8_t state[],
159  const uint16_t length = kToshibaACStateLength);
160  void setStateLength(const uint16_t size);
161  void _backupState(void);
162  void _restoreState(void);
163 };
164 
165 #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 equivilant.
Definition: ir_Toshiba.cpp:377
IRToshibaAC
Class for handling detailed Toshiba A/C messages.
Definition: ir_Toshiba.h:100
IRToshibaAC::getStateLength
uint16_t getStateLength(void)
Get the length of the current internal state per the protocol structure.
Definition: ir_Toshiba.cpp:112
kToshibaAcSwingSize
const uint8_t kToshibaAcSwingSize
Mask 0b000000xx.
Definition: ir_Toshiba.h:56
IRToshibaAC::setSwing
void setSwing(const uint8_t setting)
Set the swing setting of the A/C.
Definition: ir_Toshiba.cpp:255
kToshibaAcCool
const uint8_t kToshibaAcCool
Definition: ir_Toshiba.h:69
IRToshibaAC::setTurbo
void setTurbo(const bool on)
Set the Turbo (Powerful) setting of the A/C.
Definition: ir_Toshiba.cpp:317
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:153
IRToshibaAC::_swing_mode
uint8_t _swing_mode
The saved swing state/mode/command.
Definition: ir_Toshiba.h:156
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:124
IRToshibaAC::convertMode
uint8_t convertMode(const stdAc::opmode_t mode)
Convert a stdAc::opmode_t enum into its native mode.
Definition: ir_Toshiba.cpp:349
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:103
kToshibaAcFanAuto
const uint8_t kToshibaAcFanAuto
Definition: ir_Toshiba.h:76
IRToshibaAC::send
void send(const uint16_t repeat=kToshibaACMinRepeat)
Send the current internal state as IR messages.
Definition: ir_Toshiba.cpp:83
IRToshibaAC::setEcono
void setEcono(const bool on)
Set the Economy mode setting of the A/C.
Definition: ir_Toshiba.cpp:337
kToshibaAcInvertedLength
const uint16_t kToshibaAcInvertedLength
Nr. of leading bytes in inverted pairs.
Definition: ir_Toshiba.h:49
kToshibaAcModeOffset
const uint8_t kToshibaAcModeOffset
Definition: ir_Toshiba.h:66
IRToshibaAC::setFan
void setFan(const uint8_t speed)
Set the speed of the fan.
Definition: ir_Toshiba.cpp:227
IRToshibaAC::toCommon
stdAc::state_t toCommon(void)
Convert the current internal state into its stdAc::state_t equivilant.
Definition: ir_Toshiba.cpp:404
kToshibaAcMinTemp
const uint8_t kToshibaAcMinTemp
17C
Definition: ir_Toshiba.h:63
IRToshibaAC::_irsend
IRsend _irsend
Instance of the IR send class.
Definition: ir_Toshiba.h:146
IRToshibaAC::getSwing
uint8_t getSwing(const bool raw=true)
Get the swing setting of the A/C.
Definition: ir_Toshiba.cpp:248
IRToshibaAC::calibrate
int8_t calibrate(void)
Run the calibration to calculate uSec timing offsets for this platform.
Definition: ir_Toshiba.h:111
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:136
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:171
IRsend
Class for sending all basic IR protocols.
Definition: IRsend.h:176
IRToshibaAC::getPower
bool getPower(void)
Get the value of the current power setting.
Definition: ir_Toshiba.cpp:205
IRToshibaAC::getMode
uint8_t getMode(const bool raw=false)
Get the operating mode setting of the A/C.
Definition: ir_Toshiba.cpp:271
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:58
IRToshibaAC::toString
String toString(void)
Convert the current internal state into a human readable string.
Definition: ir_Toshiba.cpp:431
IRToshibaAC::setPower
void setPower(const bool on)
Change the power setting.
Definition: ir_Toshiba.cpp:194
String
std::string String
Definition: IRremoteESP8266.h:1128
IRToshibaAC::IRToshibaAC
IRToshibaAC(const uint16_t pin, const bool inverted=false, const bool use_modulation=true)
Class constructor.
Definition: ir_Toshiba.cpp:62
kToshibaAcSwingOff
const uint8_t kToshibaAcSwingOff
0b10
Definition: ir_Toshiba.h:59
kToshibaAcFanMed
const uint8_t kToshibaAcFanMed
Definition: ir_Toshiba.h:78
IRremoteESP8266.h
kToshibaAcLongMsgBit
const uint8_t kToshibaAcLongMsgBit
Mask 0b00001000.
Definition: ir_Toshiba.h:53
kToshibaAcEcoTurboSize
const uint8_t kToshibaAcEcoTurboSize
Definition: ir_Toshiba.h:82
IRToshibaAC::begin
void begin(void)
Set up hardware to be able to send a message.
Definition: ir_Toshiba.cpp:78
kToshibaAcMinLength
const uint8_t kToshibaAcMinLength
Min Nr. of bytes in a message. Known lengths are: 1 (56 bit message) 3 (72 bit message) 4 (80 bit mes...
Definition: ir_Toshiba.h:43
kToshibaAcSwingStep
const uint8_t kToshibaAcSwingStep
0b00
Definition: ir_Toshiba.h:57
IRToshibaAC::stateReset
void stateReset(void)
Reset the state of the remote to a known good state/sequence.
Definition: ir_Toshiba.cpp:68
kToshibaAcTempSize
const uint8_t kToshibaAcTempSize
Mask 0bxxxx0000.
Definition: ir_Toshiba.h:62
IRToshibaAC::_restoreState
void _restoreState(void)
Recover the internal code-form A/C state from the backup.
Definition: ir_Toshiba.cpp:129
IRToshibaAC::getTemp
uint8_t getTemp(void)
Get the current temperature setting.
Definition: ir_Toshiba.cpp:220
kToshibaAcFan
const uint8_t kToshibaAcFan
Definition: ir_Toshiba.h:72
IRToshibaAC::toCommonFanSpeed
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed)
Convert a native fan speed into its stdAc equivilant.
Definition: ir_Toshiba.cpp:391
kToshibaAcHeat
const uint8_t kToshibaAcHeat
Definition: ir_Toshiba.h:71
IRToshibaAC::setMode
void setMode(const uint8_t mode)
Set the operating mode of the A/C.
Definition: ir_Toshiba.cpp:285
IRToshibaAC::prev_mode
uint8_t prev_mode
Store of the previously set mode.
Definition: ir_Toshiba.h:154
IRToshibaAC::getEcono
bool getEcono(void)
Get the Economy mode setting of the A/C.
Definition: ir_Toshiba.cpp:328
kToshibaAcTurboOn
const uint8_t kToshibaAcTurboOn
Definition: ir_Toshiba.h:83
kToshibaAcModeSize
const uint8_t kToshibaAcModeSize
Definition: ir_Toshiba.h:67
IRToshibaAC::setRaw
void setRaw(const uint8_t newState[])
Set the internal state from a valid code for this protocol.
Definition: ir_Toshiba.cpp:143
kToshibaAcLengthByte
const uint8_t kToshibaAcLengthByte
Byte pos of the "length" attribute.
Definition: ir_Toshiba.h:42
kToshibaACMinRepeat
const uint16_t kToshibaACMinRepeat
Definition: IRremoteESP8266.h:1030
kToshibaACStateLength
const uint16_t kToshibaACStateLength
Definition: IRremoteESP8266.h:1028
IRToshibaAC::_send_swing
bool _send_swing
Flag indicating if we need to send a swing message.
Definition: ir_Toshiba.h:155
kToshibaACStateLengthLong
const uint16_t kToshibaACStateLengthLong
Definition: IRremoteESP8266.h:1033
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:162
kToshibaAcFanSize
const uint8_t kToshibaAcFanSize
Definition: ir_Toshiba.h:75
kToshibaAcFanOffset
const uint8_t kToshibaAcFanOffset
Definition: ir_Toshiba.h:74
kToshibaAcDry
const uint8_t kToshibaAcDry
Definition: ir_Toshiba.h:70
IRToshibaAC::backup
uint8_t backup[kToshibaACStateLengthLong]
A backup copy of the state.
Definition: ir_Toshiba.h:153
kToshibaAcAuto
const uint8_t kToshibaAcAuto
Definition: ir_Toshiba.h:68
kToshibaAcShortMsgBit
const uint8_t kToshibaAcShortMsgBit
Mask 0b00x00000.
Definition: ir_Toshiba.h:52
kToshibaAcMaxTemp
const uint8_t kToshibaAcMaxTemp
30C
Definition: ir_Toshiba.h:64
IRToshibaAC::convertFan
uint8_t convertFan(const stdAc::fanspeed_t speed)
Convert a stdAc::fanspeed_t enum into it's native speed.
Definition: ir_Toshiba.cpp:363
IRToshibaAC::setTemp
void setTemp(const uint8_t degrees)
Set the temperature.
Definition: ir_Toshiba.cpp:211
IRToshibaAC::getTurbo
bool getTurbo(void)
Get the Turbo (Powerful) setting of the A/C.
Definition: ir_Toshiba.cpp:308
IRToshibaAC::remote_state
uint8_t remote_state[kToshibaACStateLengthLong]
The state in code form.
Definition: ir_Toshiba.h:152
kToshibaAcEcoTurboOffset
const uint8_t kToshibaAcEcoTurboOffset
Definition: ir_Toshiba.h:81
kToshibaAcTempOffset
const uint8_t kToshibaAcTempOffset
Bit offset.
Definition: ir_Toshiba.h:61
stdAc::state_t
Structure to hold a common A/C state.
Definition: IRsend.h:97
IRToshibaAC::getFan
uint8_t getFan(void)
Get the current fan speed setting.
Definition: ir_Toshiba.cpp:238
kToshibaAcFanMax
const uint8_t kToshibaAcFanMax
Definition: ir_Toshiba.h:79
kToshibaAcSwingOffset
const uint8_t kToshibaAcSwingOffset
Bit offset.
Definition: ir_Toshiba.h:55
kToshibaAcEconoOn
const uint8_t kToshibaAcEconoOn
Definition: ir_Toshiba.h:84
kToshibaAcFanMin
const uint8_t kToshibaAcFanMin
Definition: ir_Toshiba.h:77
IRToshibaAC::setStateLength
void setStateLength(const uint16_t size)
Set the internal length of the current internal state per the protocol.
Definition: ir_Toshiba.cpp:118
kToshibaAcOff
const uint8_t kToshibaAcOff
Definition: ir_Toshiba.h:73
stdAc::opmode_t
opmode_t
Common A/C settings for A/C operating modes.
Definition: IRsend.h:46