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 
40  // Ref: https://docs.google.com/spreadsheets/d/1dYfLsnYvpjV-SgO8pdinpfuBIpSzm8Q1R5SabrLeskw/edit?usp=sharing
41  struct {
42  // Byte 0
43  uint8_t :8; // 0x6A (Fixed?)
44  // Byte 1
45  uint8_t Temp :5;
46  uint8_t :3;
47  // Byte 2
48  uint8_t SensorTemp :5;
49  uint8_t Sensor :1;
50  uint8_t Beep :1;
51  uint8_t :1;
52  // Byte 3
53  uint8_t OffHour :4;
54  uint8_t :4;
55  // Byte 4
56  uint8_t Fan :2;
57  uint8_t OffTimer :1;
58  uint8_t :1;
59  uint8_t Mode :3;
60  uint8_t :1;
61  // Byte 5
62  uint8_t SwingV :3;
63  uint8_t :3;
64  uint8_t Power :2;
65  // Byte 6
66  uint8_t :3;
67  uint8_t Sleep :1;
68  uint8_t :4;
69  // Byte 7
70  uint8_t :8;
71  // Byte 8
72  uint8_t Sum :8;
73  };
74 };
75 
76 // Constants
77 
78 const uint8_t kSanyoAcTempMin = 16;
79 const uint8_t kSanyoAcTempMax = 30;
80 const uint8_t kSanyoAcTempDelta = 4;
81 
82 const uint8_t kSanyoAcHourMax = 15;
83 
84 const uint8_t kSanyoAcHeat = 1;
85 const uint8_t kSanyoAcCool = 2;
86 const uint8_t kSanyoAcDry = 3;
87 const uint8_t kSanyoAcAuto = 4;
88 const uint8_t kSanyoAcFanAuto = 0;
89 const uint8_t kSanyoAcFanHigh = 1;
90 const uint8_t kSanyoAcFanLow = 2;
91 const uint8_t kSanyoAcFanMedium = 3;
92 
93 // const uint8_t kSanyoAcPowerStandby = 0b00; ///< Standby?
94 const uint8_t kSanyoAcPowerOff = 0b01;
95 const uint8_t kSanyoAcPowerOn = 0b10;
96 const uint8_t kSanyoAcSwingVAuto = 0;
97 const uint8_t kSanyoAcSwingVLowest = 2;
98 const uint8_t kSanyoAcSwingVLow = 3;
99 const uint8_t kSanyoAcSwingVLowerMiddle = 4;
100 const uint8_t kSanyoAcSwingVUpperMiddle = 5;
101 const uint8_t kSanyoAcSwingVHigh = 6;
102 const uint8_t kSanyoAcSwingVHighest = 7;
103 
104 // Classes
106 class IRSanyoAc {
107  public:
108  explicit IRSanyoAc(const uint16_t pin, const bool inverted = false,
109  const bool use_modulation = true);
110  void stateReset(void);
111 #if SEND_SANYO_AC
112  void send(const uint16_t repeat = kNoRepeat);
117  int8_t calibrate(void) { return _irsend.calibrate(); }
118 #endif // SEND_SANYO_AC
119  void begin(void);
120  void on(void);
121  void off(void);
122  void setPower(const bool on);
123  bool getPower(void) const;
124  void setTemp(const uint8_t degrees);
125  uint8_t getTemp(void) const;
126  void setSensorTemp(const uint8_t degrees);
127  uint8_t getSensorTemp(void) const;
128  void setFan(const uint8_t speed);
129  uint8_t getFan(void) const;
130  void setMode(const uint8_t mode);
131  uint8_t getMode(void) const;
132  void setSleep(const bool on);
133  bool getSleep(void) const;
134  void setSensor(const bool location);
135  bool getSensor(void) const;
136  void setBeep(const bool on);
137  bool getBeep(void) const;
138  void setSwingV(const uint8_t setting);
139  uint8_t getSwingV(void) const;
140  void setRaw(const uint8_t newState[]);
141  uint8_t* getRaw(void);
142  uint16_t getOffTimer(void) const;
143  void setOffTimer(const uint16_t mins);
144  static bool validChecksum(const uint8_t state[],
145  const uint16_t length = kSanyoAcStateLength);
146  static uint8_t convertMode(const stdAc::opmode_t mode);
147  static uint8_t convertFan(const stdAc::fanspeed_t speed);
148  static uint8_t convertSwingV(const stdAc::swingv_t position);
149  static stdAc::opmode_t toCommonMode(const uint8_t mode);
150  static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
151  static stdAc::swingv_t toCommonSwingV(const uint8_t setting);
152  stdAc::state_t toCommon(void) const;
153  String toString(void) const;
154 #ifndef UNIT_TEST
155 
156  private:
158 #else // UNIT_TEST
159  IRsendTest _irsend;
161 #endif // UNIT_TEST
164  void checksum(void);
165  static uint8_t calcChecksum(const uint8_t state[],
166  const uint16_t length = kSanyoAcStateLength);
167 };
168 
169 #endif // IR_SANYO_H_
SanyoProtocol::Sleep
uint8_t Sleep
Definition: ir_Sanyo.h:67
IRSanyoAc::_
SanyoProtocol _
Definition: ir_Sanyo.h:163
kSanyoAcTempDelta
const uint8_t kSanyoAcTempDelta
Celsius to Native Temp difference.
Definition: ir_Sanyo.h:80
stdAc::swingv_t
swingv_t
Common A/C settings for Vertical Swing.
Definition: IRsend.h:70
IRSanyoAc::getSensorTemp
uint8_t getSensorTemp(void) const
Get the current sensor temperature setting.
Definition: ir_Sanyo.cpp:452
SanyoProtocol::Fan
uint8_t Fan
Definition: ir_Sanyo.h:56
SanyoProtocol::Beep
uint8_t Beep
Definition: ir_Sanyo.h:50
stdAc::fanspeed_t
fanspeed_t
Common A/C settings for Fan Speeds.
Definition: IRsend.h:58
IRSanyoAc::convertSwingV
static uint8_t convertSwingV(const stdAc::swingv_t position)
Convert a stdAc::swingv_t enum into it's native setting.
Definition: ir_Sanyo.cpp:513
kSanyoAcHourMax
const uint8_t kSanyoAcHourMax
0b1111
Definition: ir_Sanyo.h:82
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:345
IRSanyoAc::getMode
uint8_t getMode(void) const
Get the operating mode setting of the A/C.
Definition: ir_Sanyo.cpp:385
IRSanyoAc::getPower
bool getPower(void) const
Get the value of the current power setting.
Definition: ir_Sanyo.cpp:379
kSanyoAcCool
const uint8_t kSanyoAcCool
0b010
Definition: ir_Sanyo.h:85
IRSanyoAc::_irsend
IRsend _irsend
Instance of the IR send class.
Definition: ir_Sanyo.h:157
IRsend.h
IRSanyoAc::setPower
void setPower(const bool on)
Change the power setting.
Definition: ir_Sanyo.cpp:373
IRSanyoAc::send
void send(const uint16_t repeat=kNoRepeat)
Send the current internal state as IR messages.
Definition: ir_Sanyo.cpp:322
kSanyoAcDry
const uint8_t kSanyoAcDry
0b011
Definition: ir_Sanyo.h:86
IRSanyoAc::setMode
void setMode(const uint8_t mode)
Set the operating mode of the A/C.
Definition: ir_Sanyo.cpp:392
IRsend
Class for sending all basic IR protocols.
Definition: IRsend.h:187
IRSanyoAc::getFan
uint8_t getFan(void) const
Get the current fan speed setting.
Definition: ir_Sanyo.cpp:464
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:101
IRSanyoAc
Class for handling detailed Sanyo A/C messages.
Definition: ir_Sanyo.h:106
IRSanyoAc::getSleep
bool getSleep(void) const
Get the Sleep (Night Setback) setting of the A/C.
Definition: ir_Sanyo.cpp:547
kSanyoAcPowerOff
const uint8_t kSanyoAcPowerOff
Off.
Definition: ir_Sanyo.h:94
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:554
String
std::string String
Definition: IRremoteESP8266.h:1199
kSanyoAcFanAuto
const uint8_t kSanyoAcFanAuto
0b00
Definition: ir_Sanyo.h:88
IRSanyoAc::getSensor
bool getSensor(void) const
Get the Sensor Location setting of the A/C. i.e. Where the ambient temperature is measured.
Definition: ir_Sanyo.cpp:561
IRSanyoAc::setTemp
void setTemp(const uint8_t degrees)
Set the desired temperature.
Definition: ir_Sanyo.cpp:430
SanyoProtocol::OffTimer
uint8_t OffTimer
Definition: ir_Sanyo.h:57
IRSanyoAc::calibrate
int8_t calibrate(void)
Run the calibration to calculate uSec timing offsets for this platform.
Definition: ir_Sanyo.h:117
kSanyoAcSwingVHighest
const uint8_t kSanyoAcSwingVHighest
0b111
Definition: ir_Sanyo.h:102
IRremoteESP8266.h
IRSanyoAc::toString
String toString(void) const
Convert the current internal state into a human readable string.
Definition: ir_Sanyo.cpp:626
kSanyoAcSwingVAuto
const uint8_t kSanyoAcSwingVAuto
0b000
Definition: ir_Sanyo.h:96
kNoRepeat
const uint16_t kNoRepeat
Definition: IRremoteESP8266.h:891
kSanyoAcTempMin
const uint8_t kSanyoAcTempMin
Celsius.
Definition: ir_Sanyo.h:78
kSanyoAcFanHigh
const uint8_t kSanyoAcFanHigh
0b01
Definition: ir_Sanyo.h:89
kSanyoAcSwingVLow
const uint8_t kSanyoAcSwingVLow
0b011
Definition: ir_Sanyo.h:98
IRSanyoAc::IRSanyoAc
IRSanyoAc(const uint16_t pin, const bool inverted=false, const bool use_modulation=true)
Class constructor.
Definition: ir_Sanyo.cpp:304
IRSanyoAc::checksum
void checksum(void)
Calculate & set the checksum for the current internal state of the remote.
Definition: ir_Sanyo.cpp:359
kSanyoAcAuto
const uint8_t kSanyoAcAuto
0b100
Definition: ir_Sanyo.h:87
IRSanyoAc::getOffTimer
uint16_t getOffTimer(void) const
Get the nr of minutes the Off Timer is set to.
Definition: ir_Sanyo.cpp:581
IRSanyoAc::toCommon
stdAc::state_t toCommon(void) const
Convert the current internal state into its stdAc::state_t equivalent.
Definition: ir_Sanyo.cpp:600
IRSanyoAc::convertMode
static uint8_t convertMode(const stdAc::opmode_t mode)
Convert a stdAc::opmode_t enum into its native mode.
Definition: ir_Sanyo.cpp:407
SanyoProtocol::raw
uint8_t raw[kSanyoAcStateLength]
The state in IR code form.
Definition: ir_Sanyo.h:39
IRSanyoAc::begin
void begin(void)
Set up hardware to be able to send a message.
Definition: ir_Sanyo.cpp:317
SanyoProtocol::OffHour
uint8_t OffHour
Definition: ir_Sanyo.h:53
kSanyoAcHeat
const uint8_t kSanyoAcHeat
0b001
Definition: ir_Sanyo.h:84
IRSanyoAc::setSwingV
void setSwingV(const uint8_t setting)
Set the vertical swing setting of the A/C.
Definition: ir_Sanyo.cpp:502
SanyoProtocol::SensorTemp
uint8_t SensorTemp
Definition: ir_Sanyo.h:48
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:527
IRSanyoAc::convertFan
static uint8_t convertFan(const stdAc::fanspeed_t speed)
Convert a stdAc::fanspeed_t enum into it's native speed.
Definition: ir_Sanyo.cpp:471
IRSanyoAc::toCommonMode
static stdAc::opmode_t toCommonMode(const uint8_t mode)
Convert a native mode into its stdAc equivalent.
Definition: ir_Sanyo.cpp:419
kSanyoAcSwingVUpperMiddle
const uint8_t kSanyoAcSwingVUpperMiddle
0b101
Definition: ir_Sanyo.h:100
SanyoProtocol::Mode
uint8_t Mode
Definition: ir_Sanyo.h:59
SanyoProtocol
Native representation of a Sanyo A/C message.
Definition: ir_Sanyo.h:38
IRSanyoAc::getTemp
uint8_t getTemp(void) const
Get the current desired temperature setting.
Definition: ir_Sanyo.cpp:438
IRSanyoAc::getSwingV
uint8_t getSwingV(void) const
Get the vertical swing setting of the A/C.
Definition: ir_Sanyo.cpp:496
kSanyoAcFanMedium
const uint8_t kSanyoAcFanMedium
0b11
Definition: ir_Sanyo.h:91
IRSanyoAc::setSleep
void setSleep(const bool on)
Set the Sleep (Night Setback) setting of the A/C.
Definition: ir_Sanyo.cpp:541
SanyoProtocol::Temp
uint8_t Temp
Definition: ir_Sanyo.h:45
kSanyoAcPowerOn
const uint8_t kSanyoAcPowerOn
On.
Definition: ir_Sanyo.h:95
kSanyoAcTempMax
const uint8_t kSanyoAcTempMax
Celsius.
Definition: ir_Sanyo.h:79
IRSanyoAc::setFan
void setFan(const uint8_t speed)
Set the speed of the fan.
Definition: ir_Sanyo.cpp:458
kSanyoAcFanLow
const uint8_t kSanyoAcFanLow
0b10
Definition: ir_Sanyo.h:90
kSanyoAcSwingVLowest
const uint8_t kSanyoAcSwingVLowest
0b010
Definition: ir_Sanyo.h:97
SanyoProtocol::Power
uint8_t Power
Definition: ir_Sanyo.h:64
kSanyoAcSwingVLowerMiddle
const uint8_t kSanyoAcSwingVLowerMiddle
0b100
Definition: ir_Sanyo.h:99
IRSanyoAc::setBeep
void setBeep(const bool on)
Set the Beep setting of the A/C.
Definition: ir_Sanyo.cpp:567
kSanyoAcStateLength
const uint16_t kSanyoAcStateLength
Definition: IRremoteESP8266.h:1067
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:330
IRSanyoAc::setSensorTemp
void setSensorTemp(const uint8_t degrees)
Set the sensor temperature.
Definition: ir_Sanyo.cpp:444
IRSanyoAc::stateReset
void stateReset(void)
Reset the state of the remote to a known good state/sequence.
Definition: ir_Sanyo.cpp:310
IRSanyoAc::on
void on(void)
Set the requested power state of the A/C to on.
Definition: ir_Sanyo.cpp:366
SanyoProtocol::Sum
uint8_t Sum
Definition: ir_Sanyo.h:72
IRSanyoAc::setRaw
void setRaw(const uint8_t newState[])
Set the internal state from a valid code for this protocol.
Definition: ir_Sanyo.cpp:337
IRSanyoAc::setOffTimer
void setOffTimer(const uint16_t mins)
Set the nr of minutes for the Off Timer.
Definition: ir_Sanyo.cpp:592
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:354
stdAc::state_t
Structure to hold a common A/C state.
Definition: IRsend.h:97
SanyoProtocol::Sensor
uint8_t Sensor
Sensor location (0 = remote, 1 = A/C)
Definition: ir_Sanyo.h:49
IRSanyoAc::getBeep
bool getBeep(void) const
Get the Beep setting of the A/C.
Definition: ir_Sanyo.cpp:573
IRSanyoAc::toCommonFanSpeed
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed)
Convert a native fan speed into its stdAc equivalent.
Definition: ir_Sanyo.cpp:485
IRSanyoAc::off
void off(void)
Set the requested power state of the A/C to off.
Definition: ir_Sanyo.cpp:369
SanyoProtocol::SwingV
uint8_t SwingV
Definition: ir_Sanyo.h:62
stdAc::opmode_t
opmode_t
Common A/C settings for A/C operating modes.
Definition: IRsend.h:46