-
Notifications
You must be signed in to change notification settings - Fork 837
/
Copy pathir_Vestel.h
172 lines (158 loc) · 5.05 KB
/
ir_Vestel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Copyright 2018 Erdem U. Altinyurt
// Copyright 2019 David Conran
/// @file
/// @brief Support for Vestel protocols.
/// Vestel added by Erdem U. Altinyurt
// Supports:
// Brand: Vestel, Model: BIOX CXP-9 A/C (9K BTU)
#ifndef IR_VESTEL_H_
#define IR_VESTEL_H_
#define __STDC_LIMIT_MACROS
#include <stdint.h>
#ifdef ARDUINO
#include <Arduino.h>
#endif
#include "IRremoteESP8266.h"
#include "IRsend.h"
#ifdef UNIT_TEST
#include "IRsend_test.h"
#endif
/// Native representation of a Vestel A/C message.
union VestelProtocol{
struct {
uint64_t cmdState;
uint64_t timeState;
};
struct {
// Command
uint64_t Signature :12; // 0x201
uint64_t CmdSum :8;
uint64_t Swing :4; // auto 0xA, stop 0xF
uint64_t TurboSleep :4; // normal 0x1, sleep 0x3, turbo 0x7
uint64_t :8;
uint64_t Temp :4;
uint64_t Fan :4;
uint64_t Mode :3;
uint64_t :3;
uint64_t Ion :1;
uint64_t :1;
uint64_t Power :2;
uint64_t UseCmd :1;
uint64_t :0;
// Time
uint64_t :12;
uint64_t TimeSum :8;
uint64_t OffTenMins :3;
uint64_t OffHours :5;
uint64_t OnTenMins :3;
uint64_t OnHours :5;
uint64_t Hours :5;
uint64_t OnTimer :1;
uint64_t OffTimer :1;
uint64_t Timer :1;
uint64_t Minutes :8;
uint64_t :0;
};
};
// Constants
const uint16_t kVestelAcHdrMark = 3110;
const uint16_t kVestelAcHdrSpace = 9066;
const uint16_t kVestelAcBitMark = 520;
const uint16_t kVestelAcOneSpace = 1535;
const uint16_t kVestelAcZeroSpace = 480;
const uint16_t kVestelAcTolerance = 30;
const uint8_t kVestelAcMinTempH = 16;
const uint8_t kVestelAcMinTempC = 18;
const uint8_t kVestelAcMaxTemp = 30;
const uint8_t kVestelAcAuto = 0;
const uint8_t kVestelAcCool = 1;
const uint8_t kVestelAcDry = 2;
const uint8_t kVestelAcFan = 3;
const uint8_t kVestelAcHeat = 4;
const uint8_t kVestelAcFanAuto = 1;
const uint8_t kVestelAcFanLow = 5;
const uint8_t kVestelAcFanMed = 9;
const uint8_t kVestelAcFanHigh = 0xB;
const uint8_t kVestelAcFanAutoCool = 0xC;
const uint8_t kVestelAcFanAutoHot = 0xD;
const uint8_t kVestelAcNormal = 1;
const uint8_t kVestelAcSleep = 3;
const uint8_t kVestelAcTurbo = 7;
const uint8_t kVestelAcIon = 4;
const uint8_t kVestelAcSwing = 0xA;
// Default states
const uint64_t kVestelAcStateDefault = 0x0F00D9001FEF201ULL;
const uint64_t kVestelAcTimeStateDefault = 0x201ULL;
// Classes
/// Class for handling detailed Vestel A/C messages.
class IRVestelAc {
public:
explicit IRVestelAc(const uint16_t pin, const bool inverted = false,
const bool use_modulation = true);
void stateReset(void);
#if SEND_VESTEL_AC
void send(const uint16_t repeat = kNoRepeat);
/// Run the calibration to calculate uSec timing offsets for this platform.
/// @return The uSec timing offset needed per modulation of the IR Led.
/// @note This will produce a 65ms IR signal pulse at 38kHz.
/// Only ever needs to be run once per object instantiation, if at all.
int8_t calibrate(void) { return _irsend.calibrate(); }
#endif // SEND_VESTEL_AC
void begin(void);
void on(void);
void off(void);
void setPower(const bool on);
bool getPower(void) const;
void setAuto(const int8_t autoLevel);
void setTimer(const uint16_t minutes);
uint16_t getTimer(void) const;
void setTime(const uint16_t minutes);
uint16_t getTime(void) const;
void setOnTimer(const uint16_t minutes);
uint16_t getOnTimer(void) const;
void setOffTimer(const uint16_t minutes);
uint16_t getOffTimer(void) const;
void setTemp(const uint8_t temp);
uint8_t getTemp(void) const;
void setFan(const uint8_t fan);
uint8_t getFan(void) const;
void setMode(const uint8_t mode);
uint8_t getMode(void) const;
void setRaw(const uint8_t* newState);
void setRaw(const uint64_t newState);
uint64_t getRaw(void);
static bool validChecksum(const uint64_t state);
void setSwing(const bool on);
bool getSwing(void) const;
void setSleep(const bool on);
bool getSleep(void) const;
void setTurbo(const bool on);
bool getTurbo(void) const;
void setIon(const bool on);
bool getIon(void) const;
bool isTimeCommand(void) const;
bool isOnTimerActive(void) const;
void setOnTimerActive(const bool on);
bool isOffTimerActive(void) const;
void setOffTimerActive(const bool on);
bool isTimerActive(void) const;
void setTimerActive(const bool on);
static uint8_t calcChecksum(const uint64_t state);
static uint8_t convertMode(const stdAc::opmode_t mode);
static uint8_t convertFan(const stdAc::fanspeed_t speed);
static stdAc::opmode_t toCommonMode(const uint8_t mode);
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
stdAc::state_t toCommon(void) const;
String toString(void) const;
#ifndef UNIT_TEST
private:
IRsend _irsend; ///< Instance of the IR send class
#else // UNIT_TEST
/// @cond IGNORE
IRsendTest _irsend; ///< Instance of the testing IR send class
/// @endcond
#endif // UNIT_TEST
VestelProtocol _;
void checksum(void);
};
#endif // IR_VESTEL_H_