forked from ToniA/arduino-heatpumpir
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IRSender.h
124 lines (103 loc) · 2.42 KB
/
IRSender.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
/*
Class to send IR signals using the Arduino PWM
*/
#ifndef IRSender_h
#define IRSender_h
#include <Arduino.h>
#if defined(DEBUG) && (DEBUG > 0)
#define LOG(...) Serial.print(__VA_ARGS__)
#define LOGLN(...) Serial.println(__VA_ARGS__)
#else
#define LOG(...)
#define LOGLN(...)
#endif
#ifdef ESP8266
#include <IRsend.h> // From IRremoteESP8266 library
#include <stdint.h>
#endif
class IRSender
{
protected:
IRSender(uint8_t pin); // Cannot create generic IRSender instances
public:
virtual ~IRSender() = default;
virtual void setFrequency(int frequency);
void sendIRbyte(uint8_t sendByte, int bitMarkLength, int zeroSpaceLength, int oneSpaceLength);
uint8_t bitReverse(uint8_t x);
virtual void space(int spaceLength);
virtual void mark(int markLength);
protected:
uint8_t _pin;
};
class IRSenderPWM : public IRSender
{
public:
IRSenderPWM(uint8_t pin);
void setFrequency(int frequency);
void space(int spaceLength);
void mark(int markLength);
};
class IRSenderBlaster : public IRSender
{
public:
IRSenderBlaster(uint8_t pin);
void setFrequency(int frequency);
void space(int spaceLength);
void mark(int markLength);
};
class IRSenderBitBang : public IRSender
{
public:
IRSenderBitBang(uint8_t pin);
void setFrequency(int frequency);
void space(int spaceLength);
void mark(int markLength);
protected:
int _halfPeriodicTime;
};
#ifdef ESP32
class IRSenderESP32 : public IRSender
{
public:
IRSenderESP32(uint8_t pin, uint8_t pwmChannel);
void setFrequency(int frequency);
void space(int spaceLength);
void mark(int markLength);
protected:
uint32_t _frequency;
uint8_t _pwmChannel;
};
#endif
#ifdef ESP8266
class IRSenderIRremoteESP8266 : public IRSender
{
public:
IRSenderIRremoteESP8266(uint8_t pin);
void setFrequency(int frequency);
void space(int spaceLength);
void mark(int markLength);
private:
IRsend _ir;
};
class IRSenderESP8266 : public IRSender
{
public:
IRSenderESP8266(uint8_t pin);
void setFrequency(int frequency);
void space(int spaceLength);
void mark(int markLength);
protected:
uint32_t _halfPeriodicTime;
};
class IRSenderESP8266Alt : public IRSender
{
public:
IRSenderESP8266Alt(uint8_t pin);
void setFrequency(int frequency);
void space(int spaceLength);
void mark(int markLength);
protected:
uint32_t _halfPeriodicTime;
};
#endif
#endif