IRremoteESP8266
ir_Sanyo.h
Go to the documentation of this file.
1 // Copyright 2020 David Conran
2 
14 
15 // Supports:
16 // Brand: Sanyo, Model: SA 8650B - disabled
17 // Brand: Sanyo, Model: LC7461 transmitter IC (SANYO_LC7461)
18 // Brand: Sanyo, Model: SAP-K121AHA A/C (SANYO_AC)
19 // Brand: Sanyo, Model: RCS-2HS4E remote (SANYO_AC)
20 // Brand: Sanyo, Model: SAP-K242AH A/C (SANYO_AC)
21 // Brand: Sanyo, Model: RCS-2S4E remote (SANYO_AC)
22 
23 #ifndef IR_SANYO_H_
24 #define IR_SANYO_H_
25 
26 #define __STDC_LIMIT_MACROS
27 #include <stdint.h>
28 #ifdef ARDUINO
29 #include <Arduino.h>
30 #endif
31 #include "IRremoteESP8266.h"
32 #include "IRsend.h"
33 #ifdef UNIT_TEST
34 #include "IRsend_test.h"
35 #endif
36 
37 // Constants
38 
39 // Sanyo A/C
40 // Ref: https://docs.google.com/spreadsheets/d/1dYfLsnYvpjV-SgO8pdinpfuBIpSzm8Q1R5SabrLeskw/edit?usp=sharing
41 // Byte[0] - 0x6A (Fixed?)
42 // Byte[1] - Address + Temperature
43 const uint8_t kSanyoAcTempByte = 1;
44 const uint8_t kSanyoAcTempOffset = 0;
45 const uint8_t kSanyoAcTempSize = 5;
46 const uint8_t kSanyoAcTempMin = 16;
47 const uint8_t kSanyoAcTempMax = 30;
48 const uint8_t kSanyoAcTempDelta = 4;
49 // Byte[2] - Ambient Temp + Sensor
50 const uint8_t kSanyoAcSensorByte = 2;
51 const uint8_t kSanyoAcSensorBit = 2;
52 // Ambient Temp Mask 0b000xxxxx
53 const uint8_t kSanyoAcBeepBit = 6;
54 // Byte[3] - Off Hour
55 const uint8_t kSanyoAcOffHourByte = 3;
56 const uint8_t kSanyoAcOffHourOffset = 0;
57 const uint8_t kSanyoAcOffHourSize = 4;
58 const uint8_t kSanyoAcHourMax = 15;
59 // Byte[4] - Mode + Fan + Timer Enables
60 const uint8_t kSanyoAcModeByte = 4;
61 const uint8_t kSanyoAcModeOffset = 4;
62 const uint8_t kSanyoAcModeSize = 3;
63 const uint8_t kSanyoAcHeat = 1;
64 const uint8_t kSanyoAcCool = 2;
65 const uint8_t kSanyoAcDry = 3;
66 const uint8_t kSanyoAcAuto = 4;
67 const uint8_t kSanyoAcOffTimerEnableBit = 2;
68 const uint8_t kSanyoAcFanOffset = 0;
69 const uint8_t kSanyoAcFanSize = 2;
70 const uint8_t kSanyoAcFanAuto = 0;
71 const uint8_t kSanyoAcFanHigh = 1;
72 const uint8_t kSanyoAcFanLow = 2;
73 const uint8_t kSanyoAcFanMedium = 3;
74 // Byte[5] - Power + SwingV
75 const uint8_t kSanyoAcPowerByte = 5;
76 const uint8_t kSanyoAcPowerOffset = 6;
77 const uint8_t kSanyoAcPowerSize = 2;
78 // const uint8_t kSanyoAcPowerStandby = 0b00; ///< Standby?
79 const uint8_t kSanyoAcPowerOff = 0b01;
80 const uint8_t kSanyoAcPowerOn = 0b10;
81 const uint8_t kSanyoAcSwingVOffset = 0;
82 const uint8_t kSanyoAcSwingVSize = 3;
83 const uint8_t kSanyoAcSwingVAuto = 0;
84 const uint8_t kSanyoAcSwingVLowest = 2;
85 const uint8_t kSanyoAcSwingVLow = 3;
86 const uint8_t kSanyoAcSwingVLowerMiddle = 4;
87 const uint8_t kSanyoAcSwingVUpperMiddle = 5;
88 const uint8_t kSanyoAcSwingVHigh = 6;
89 const uint8_t kSanyoAcSwingVHighest = 7;
90 // Byte[6] - Sleep
91 const uint8_t kSanyoAcSleepByte = 6;
92 const uint8_t kSanyoAcSleepBit = 3;
93 // Byte[8] - Checksum (8-bit Sum of all preceeding nibbles)
94 
95 
96 // Classes
98 class IRSanyoAc {
99  public:
100  explicit IRSanyoAc(const uint16_t pin, const bool inverted = false,
101  const bool use_modulation = true);
102  void stateReset(void);
103 #if SEND_SANYO_AC
104  void send(const uint16_t repeat = kNoRepeat);
109  int8_t calibrate(void) { return _irsend.calibrate(); }
110 #endif // SEND_SANYO_AC
111  void begin(void);
112  void on(void);
113  void off(void);
114  void setPower(const bool on);
115  bool getPower(void);
116  void setTemp(const uint8_t degrees);
117  uint8_t getTemp(void);
118  void setSensorTemp(const uint8_t degrees);
119  uint8_t getSensorTemp(void);
120  void setFan(const uint8_t speed);
121  uint8_t getFan(void);
122  void setMode(const uint8_t mode);
123  uint8_t getMode(void);
124  void setSleep(const bool on);
125  bool getSleep(void);
126  void setSensor(const bool location);
127  bool getSensor(void);
128  void setBeep(const bool on);
129  bool getBeep(void);
130  void setSwingV(const uint8_t setting);
131  uint8_t getSwingV(void);
132  void setRaw(const uint8_t newState[]);
133  uint8_t* getRaw(void);
134  uint16_t getOffTimer(void);
135  void setOffTimer(const uint16_t mins);
136  static bool validChecksum(const uint8_t state[],
137  const uint16_t length = kSanyoAcStateLength);
138  uint8_t convertMode(const stdAc::opmode_t mode);
139  uint8_t convertFan(const stdAc::fanspeed_t speed);
140  uint8_t convertSwingV(const stdAc::swingv_t position);
141  static stdAc::opmode_t toCommonMode(const uint8_t mode);
142  static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
143  static stdAc::swingv_t toCommonSwingV(const uint8_t setting);
144  stdAc::state_t toCommon(void);
145  String toString(void);
146 #ifndef UNIT_TEST
147 
148  private:
150 #else // UNIT_TEST
151  IRsendTest _irsend;
153 #endif // UNIT_TEST
156  void checksum(void);
157  static uint8_t calcChecksum(const uint8_t state[],
158  const uint16_t length = kSanyoAcStateLength);
159  void _setTemp(uint8_t *ptr, const uint8_t degrees);
160  uint8_t _getTemp(uint8_t *ptr);
161 };
162 
163 #endif // IR_SANYO_H_
kSanyoAcSensorBit
const uint8_t kSanyoAcSensorBit
Mask 0b00x00000.
Definition: ir_Sanyo.h:51
kSanyoAcTempByte
const uint8_t kSanyoAcTempByte
Index.
Definition: ir_Sanyo.h:43
kSanyoAcModeSize
const uint8_t kSanyoAcModeSize
Mask 0b0xxx0000.
Definition: ir_Sanyo.h:62
kSanyoAcTempDelta
const uint8_t kSanyoAcTempDelta
Celsius to Native Temp difference.
Definition: ir_Sanyo.h:48
stdAc::swingv_t
swingv_t
Common A/C settings for Vertical Swing.
Definition: IRsend.h:70
stdAc::fanspeed_t
fanspeed_t
Common A/C settings for Fan Speeds.
Definition: IRsend.h:58
IRSanyoAc::remote_state
uint8_t remote_state[kSanyoAcStateLength]
The state in IR code form.
Definition: ir_Sanyo.h:155
IRSanyoAc::convertSwingV
uint8_t convertSwingV(const stdAc::swingv_t position)
Convert a stdAc::swingv_t enum into it's native setting.
Definition: ir_Sanyo.cpp:536
kSanyoAcHourMax
const uint8_t kSanyoAcHourMax
0b1111
Definition: ir_Sanyo.h:58
IRSanyoAc::calcChecksum
static uint8_t calcChecksum(const uint8_t state[], const uint16_t length=kSanyoAcStateLength)
Calculate the checksum for a given state.
Definition: ir_Sanyo.cpp:346
kSanyoAcOffHourSize
const uint8_t kSanyoAcOffHourSize
Mask 0b0000xxxx.
Definition: ir_Sanyo.h:57
IRSanyoAc::_setTemp
void _setTemp(uint8_t *ptr, const uint8_t degrees)
Set the temperature at a given location.
Definition: ir_Sanyo.cpp:436
kSanyoAcCool
const uint8_t kSanyoAcCool
0b010
Definition: ir_Sanyo.h:64
kSanyoAcPowerOffset
const uint8_t kSanyoAcPowerOffset
Mask 0bxx000000.
Definition: ir_Sanyo.h:76
kSanyoAcPowerSize
const uint8_t kSanyoAcPowerSize
Mask 0bxx000000.
Definition: ir_Sanyo.h:77
IRSanyoAc::_irsend
IRsend _irsend
Instance of the IR send class.
Definition: ir_Sanyo.h:149
IRsend.h
kSanyoAcSleepBit
const uint8_t kSanyoAcSleepBit
Mask 0b0000x000.
Definition: ir_Sanyo.h:92
IRSanyoAc::setPower
void setPower(const bool on)
Change the power setting.
Definition: ir_Sanyo.cpp:374
kSanyoAcTempSize
const uint8_t kSanyoAcTempSize
Mask 0b000xxxxx.
Definition: ir_Sanyo.h:45
IRSanyoAc::send
void send(const uint16_t repeat=kNoRepeat)
Send the current internal state as IR messages.
Definition: ir_Sanyo.cpp:323
kSanyoAcDry
const uint8_t kSanyoAcDry
0b011
Definition: ir_Sanyo.h:65
IRSanyoAc::getOffTimer
uint16_t getOffTimer(void)
Get the nr of minutes the Off Timer is set to.
Definition: ir_Sanyo.cpp:604
IRSanyoAc::setMode
void setMode(const uint8_t mode)
Set the operating mode of the A/C.
Definition: ir_Sanyo.cpp:396
kSanyoAcFanOffset
const uint8_t kSanyoAcFanOffset
Mask 0b000000xx.
Definition: ir_Sanyo.h:68
IRsend
Class for sending all basic IR protocols.
Definition: IRsend.h:176
IRsend::calibrate
int8_t calibrate(uint16_t hz=38000U)
Calculate & set any offsets to account for execution times during sending.
Definition: IRsend.cpp:207
kSanyoAcSwingVHigh
const uint8_t kSanyoAcSwingVHigh
0b110
Definition: ir_Sanyo.h:88
IRSanyoAc
Class for handling detailed Sanyo A/C messages.
Definition: ir_Sanyo.h:98
kSanyoAcPowerOff
const uint8_t kSanyoAcPowerOff
Off.
Definition: ir_Sanyo.h:79
IRSanyoAc::setSensor
void setSensor(const bool location)
Set the Sensor Location setting of the A/C. i.e. Where the ambient temperature is measured.
Definition: ir_Sanyo.cpp:577
String
std::string String
Definition: IRremoteESP8266.h:1128
IRSanyoAc::getMode
uint8_t getMode(void)
Get the operating mode setting of the A/C.
Definition: ir_Sanyo.cpp:388
kSanyoAcFanAuto
const uint8_t kSanyoAcFanAuto
0b00
Definition: ir_Sanyo.h:70
IRSanyoAc::setTemp
void setTemp(const uint8_t degrees)
Set the desired temperature.
Definition: ir_Sanyo.cpp:452
IRSanyoAc::calibrate
int8_t calibrate(void)
Run the calibration to calculate uSec timing offsets for this platform.
Definition: ir_Sanyo.h:109
kSanyoAcSwingVHighest
const uint8_t kSanyoAcSwingVHighest
0b111
Definition: ir_Sanyo.h:89
IRremoteESP8266.h
IRSanyoAc::getTemp
uint8_t getTemp(void)
Get the current desired temperature setting.
Definition: ir_Sanyo.cpp:458
kSanyoAcSensorByte
const uint8_t kSanyoAcSensorByte
Index.
Definition: ir_Sanyo.h:50
kSanyoAcSwingVAuto
const uint8_t kSanyoAcSwingVAuto
0b000
Definition: ir_Sanyo.h:83
kNoRepeat
const uint16_t kNoRepeat
Definition: IRremoteESP8266.h:835
kSanyoAcModeOffset
const uint8_t kSanyoAcModeOffset
Mask 0b0xxx0000.
Definition: ir_Sanyo.h:61
IRSanyoAc::getFan
uint8_t getFan(void)
Get the current fan speed setting.
Definition: ir_Sanyo.cpp:483
kSanyoAcTempMin
const uint8_t kSanyoAcTempMin
Celsius.
Definition: ir_Sanyo.h:46
kSanyoAcFanHigh
const uint8_t kSanyoAcFanHigh
0b01
Definition: ir_Sanyo.h:71
kSanyoAcSwingVLow
const uint8_t kSanyoAcSwingVLow
0b011
Definition: ir_Sanyo.h:85
IRSanyoAc::IRSanyoAc
IRSanyoAc(const uint16_t pin, const bool inverted=false, const bool use_modulation=true)
Class constructor.
Definition: ir_Sanyo.cpp:305
IRSanyoAc::getSleep
bool getSleep(void)
Get the Sleep (Night Setback) setting of the A/C.
Definition: ir_Sanyo.cpp:570
IRSanyoAc::getSensor
bool getSensor(void)
Get the Sensor Location setting of the A/C. i.e. Where the ambient temperature is measured.
Definition: ir_Sanyo.cpp:584
IRSanyoAc::checksum
void checksum(void)
Calculate & set the checksum for the current internal state of the remote.
Definition: ir_Sanyo.cpp:360
kSanyoAcAuto
const uint8_t kSanyoAcAuto
0b100
Definition: ir_Sanyo.h:66
IRSanyoAc::getBeep
bool getBeep(void)
Get the Beep setting of the A/C.
Definition: ir_Sanyo.cpp:596
IRSanyoAc::convertMode
uint8_t convertMode(const stdAc::opmode_t mode)
Convert a stdAc::opmode_t enum into its native mode.
Definition: ir_Sanyo.cpp:412
IRSanyoAc::begin
void begin(void)
Set up hardware to be able to send a message.
Definition: ir_Sanyo.cpp:318
kSanyoAcSleepByte
const uint8_t kSanyoAcSleepByte
Index.
Definition: ir_Sanyo.h:91
kSanyoAcOffTimerEnableBit
const uint8_t kSanyoAcOffTimerEnableBit
Mask 0b00000x00.
Definition: ir_Sanyo.h:67
kSanyoAcHeat
const uint8_t kSanyoAcHeat
0b001
Definition: ir_Sanyo.h:63
IRSanyoAc::setSwingV
void setSwingV(const uint8_t setting)
Set the vertical swing setting of the A/C.
Definition: ir_Sanyo.cpp:523
kSanyoAcModeByte
const uint8_t kSanyoAcModeByte
Index.
Definition: ir_Sanyo.h:60
IRSanyoAc::toCommonSwingV
static stdAc::swingv_t toCommonSwingV(const uint8_t setting)
Convert a native vertical swing postion to it's common equivalent.
Definition: ir_Sanyo.cpp:550
IRSanyoAc::convertFan
uint8_t convertFan(const stdAc::fanspeed_t speed)
Convert a stdAc::fanspeed_t enum into it's native speed.
Definition: ir_Sanyo.cpp:491
IRSanyoAc::getSensorTemp
uint8_t getSensorTemp(void)
Get the current sensor temperature setting.
Definition: ir_Sanyo.cpp:470
IRSanyoAc::toCommonMode
static stdAc::opmode_t toCommonMode(const uint8_t mode)
Convert a native mode into its stdAc equivilant.
Definition: ir_Sanyo.cpp:424
kSanyoAcSwingVUpperMiddle
const uint8_t kSanyoAcSwingVUpperMiddle
0b101
Definition: ir_Sanyo.h:87
kSanyoAcSwingVSize
const uint8_t kSanyoAcSwingVSize
Mask 0b00000xxx.
Definition: ir_Sanyo.h:82
kSanyoAcTempOffset
const uint8_t kSanyoAcTempOffset
Mask 0b000xxxxx.
Definition: ir_Sanyo.h:44
IRSanyoAc::_getTemp
uint8_t _getTemp(uint8_t *ptr)
Get the temperature from a given location.
Definition: ir_Sanyo.cpp:445
kSanyoAcSwingVOffset
const uint8_t kSanyoAcSwingVOffset
Mask 0b00000xxx.
Definition: ir_Sanyo.h:81
kSanyoAcFanMedium
const uint8_t kSanyoAcFanMedium
0b11
Definition: ir_Sanyo.h:73
IRSanyoAc::getPower
bool getPower(void)
Get the value of the current power setting.
Definition: ir_Sanyo.cpp:381
IRSanyoAc::setSleep
void setSleep(const bool on)
Set the Sleep (Night Setback) setting of the A/C.
Definition: ir_Sanyo.cpp:564
kSanyoAcPowerOn
const uint8_t kSanyoAcPowerOn
On.
Definition: ir_Sanyo.h:80
kSanyoAcTempMax
const uint8_t kSanyoAcTempMax
Celsius.
Definition: ir_Sanyo.h:47
kSanyoAcOffHourOffset
const uint8_t kSanyoAcOffHourOffset
Mask 0b0000xxxx.
Definition: ir_Sanyo.h:56
IRSanyoAc::setFan
void setFan(const uint8_t speed)
Set the speed of the fan.
Definition: ir_Sanyo.cpp:476
kSanyoAcFanLow
const uint8_t kSanyoAcFanLow
0b10
Definition: ir_Sanyo.h:72
kSanyoAcSwingVLowest
const uint8_t kSanyoAcSwingVLowest
0b010
Definition: ir_Sanyo.h:84
kSanyoAcPowerByte
const uint8_t kSanyoAcPowerByte
Index.
Definition: ir_Sanyo.h:75
kSanyoAcOffHourByte
const uint8_t kSanyoAcOffHourByte
Index.
Definition: ir_Sanyo.h:55
kSanyoAcSwingVLowerMiddle
const uint8_t kSanyoAcSwingVLowerMiddle
0b100
Definition: ir_Sanyo.h:86
IRSanyoAc::getSwingV
uint8_t getSwingV(void)
Get the vertical swing setting of the A/C.
Definition: ir_Sanyo.cpp:516
kSanyoAcFanSize
const uint8_t kSanyoAcFanSize
Mask 0b000000xx.
Definition: ir_Sanyo.h:69
IRSanyoAc::setBeep
void setBeep(const bool on)
Set the Beep setting of the A/C.
Definition: ir_Sanyo.cpp:590
kSanyoAcStateLength
const uint16_t kSanyoAcStateLength
Definition: IRremoteESP8266.h:1001
IRSanyoAc::getRaw
uint8_t * getRaw(void)
Get a PTR to the internal state/code for this protocol with all integrity checks passing.
Definition: ir_Sanyo.cpp:331
IRSanyoAc::setSensorTemp
void setSensorTemp(const uint8_t degrees)
Set the sensor temperature.
Definition: ir_Sanyo.cpp:464
IRSanyoAc::stateReset
void stateReset(void)
Reset the state of the remote to a known good state/sequence.
Definition: ir_Sanyo.cpp:311
IRSanyoAc::toCommon
stdAc::state_t toCommon(void)
Convert the current internal state into its stdAc::state_t equivilant.
Definition: ir_Sanyo.cpp:625
IRSanyoAc::on
void on(void)
Set the requested power state of the A/C to on.
Definition: ir_Sanyo.cpp:367
IRSanyoAc::setRaw
void setRaw(const uint8_t newState[])
Set the internal state from a valid code for this protocol.
Definition: ir_Sanyo.cpp:338
IRSanyoAc::setOffTimer
void setOffTimer(const uint16_t mins)
Set the nr of minutes for the Off Timer.
Definition: ir_Sanyo.cpp:616
IRSanyoAc::validChecksum
static bool validChecksum(const uint8_t state[], const uint16_t length=kSanyoAcStateLength)
Verify the checksum is valid for a given state.
Definition: ir_Sanyo.cpp:355
IRSanyoAc::toString
String toString(void)
Convert the current internal state into a human readable string.
Definition: ir_Sanyo.cpp:651
stdAc::state_t
Structure to hold a common A/C state.
Definition: IRsend.h:97
IRSanyoAc::toCommonFanSpeed
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed)
Convert a native fan speed into its stdAc equivilant.
Definition: ir_Sanyo.cpp:505
kSanyoAcBeepBit
const uint8_t kSanyoAcBeepBit
Mask 0b0x000000.
Definition: ir_Sanyo.h:53
IRSanyoAc::off
void off(void)
Set the requested power state of the A/C to off.
Definition: ir_Sanyo.cpp:370
stdAc::opmode_t
opmode_t
Common A/C settings for A/C operating modes.
Definition: IRsend.h:46