-
Notifications
You must be signed in to change notification settings - Fork 1
/
Seville.h
109 lines (88 loc) · 3.3 KB
/
Seville.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
// Seville Classics Ultra Slimline Fan
//
// Copyright 2019 Robbie Trencheny (@robbie)
#ifndef SEVILLE_H_
#define SEVILLE_H_
#define __STDC_LIMIT_MACROS
#include <stdint.h>
#ifndef UNIT_TEST
#include <Arduino.h>
#else
#include <string>
#endif
#include "IRremoteESP8266.h"
#include "IRsend.h"
// Constants
const uint16_t kSevilleBits = 64;
const uint16_t kSevilleDefaultRepeat = kNoRepeat;
const uint16_t kSevilleStateLength = 8;
const uint16_t kSevilleHdrMark = 9350;
const uint16_t kSevilleHdrSpace = 4500;
const uint16_t kSevilleBitMark = 590;
const uint16_t kSevilleOneSpace = 1671;
const uint16_t kSevilleZeroSpace = 546;
const uint16_t kSevilleMsgSpace = 10000;
// Digit 2, Byte 1 - Power
const uint8_t kSevillePowerOn = 0x11;
const uint8_t kSevillePowerOff = 0x10;
// Digit 4, Byte 3 - Timer
const uint8_t kSevilleTimerNone = 0x20;
const uint8_t kSevilleTimerHalfHour = 0x21;
const uint8_t kSevilleTimerHour = 0x22;
const uint8_t kSevilleTimerHourAndAHalfHours = 0x23;
const uint8_t kSevilleTimerTwoHours = 0x24;
const uint8_t kSevilleTimerTwoAndAHalfHours = 0x25;
const uint8_t kSevilleTimerThreeHours = 0x26;
const uint8_t kSevilleTimerThreeAndAHalfHours = 0x27;
const uint8_t kSevilleTimerFourHours = 0x28;
const uint8_t kSevilleTimerFourAndAHalfHours = 0x29;
const uint8_t kSevilleTimerFiveHours = 0x2A;
const uint8_t kSevilleTimerFiveAndAHalfHours = 0x2B;
const uint8_t kSevilleTimerSixHours = 0x2C;
const uint8_t kSevilleTimerSixAndAHalfHours = 0x2D;
const uint8_t kSevilleTimerSevenHours = 0x2E;
const uint8_t kSevilleTimerSevenAndAHalfHours = 0x2F;
// Digit 6, Byte 5 - Oscillation
const uint8_t kSevilleOscillationOn = 0x31;
const uint8_t kSevilleOscillationOff = 0x30;
// Digit 8, Byte 7 - Speed
const uint8_t kSevilleSpeedEco = 0x43;
const uint8_t kSevilleSpeedLow = 0x40;
const uint8_t kSevilleSpeedMedium = 0x41;
const uint8_t kSevilleSpeedHigh = 0x42;
// Digit 10, Byte 9 - "Wind" mode
const uint8_t kSevilleWindNormal = 0x50;
const uint8_t kSevilleWindNatural = 0x51;
const uint8_t kSevilleWindSleeping = 0x52;
class IRSevilleFan {
public:
explicit IRSevilleFan(uint16_t pin);
void send(const uint16_t repeat = kSevilleDefaultRepeat);
void begin();
void setPower(bool state);
bool getPower();
char* getPowerString();
void setTimer(uint8_t timer);
uint8_t getTimer();
char* getTimerString();
void setOscillation(bool osc);
bool getOscillation();
char* getOscillationString();
void setSpeed(uint8_t speed);
uint8_t getSpeed();
char* getSpeedString();
void setWind(uint8_t wind);
uint8_t getWind();
char* getWindString();
uint8_t* getRaw();
void reset();
private:
uint8_t remote_state[kSevilleStateLength];
void checksum();
IRsend _irsend;
void sendSeville(uint64_t data, uint16_t nbits = kSevilleBits,
uint16_t repeat = kSevilleDefaultRepeat);
void sendSeville(unsigned char data[], uint16_t nbytes = kSevilleStateLength,
uint16_t repeat = kSevilleDefaultRepeat);
};
#endif // SEVILLE_H_