2013-12-26 21:11:20 +08:00
|
|
|
/*
|
|
|
|
Class to send IR signals using the Arduino PWM
|
|
|
|
*/
|
|
|
|
#ifndef IRSender_h
|
|
|
|
#define IRSender_h
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
2021-04-10 14:15:38 +08:00
|
|
|
#if defined(DEBUG) && (DEBUG > 0)
|
|
|
|
#define LOG(...) Serial.print(__VA_ARGS__)
|
|
|
|
#define LOGLN(...) Serial.println(__VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define LOG(...)
|
|
|
|
#define LOGLN(...)
|
|
|
|
#endif
|
|
|
|
|
2020-09-02 20:16:11 +08:00
|
|
|
#if defined(ESP8266) || defined(ESP32)
|
2017-07-04 14:51:34 +08:00
|
|
|
#include <IRsend.h> // From IRremoteESP8266 library
|
2019-04-02 18:38:32 +08:00
|
|
|
#include <stdint.h>
|
2017-07-04 14:51:34 +08:00
|
|
|
#endif
|
|
|
|
|
2013-12-26 21:11:20 +08:00
|
|
|
class IRSender
|
|
|
|
{
|
2015-12-02 02:17:14 +08:00
|
|
|
protected:
|
|
|
|
IRSender(uint8_t pin); // Cannot create generic IRSender instances
|
|
|
|
|
2013-12-26 21:11:20 +08:00
|
|
|
public:
|
2019-08-21 15:12:08 +08:00
|
|
|
virtual ~IRSender() = default;
|
2015-12-02 02:17:14 +08:00
|
|
|
virtual void setFrequency(int frequency);
|
2024-01-05 23:07:54 +08:00
|
|
|
void sendIRbyte(uint8_t sendByte, int bitMarkLength, int zeroSpaceLength, int oneSpaceLength, uint8_t bitCount = 8);
|
2015-10-01 15:23:49 +08:00
|
|
|
uint8_t bitReverse(uint8_t x);
|
2023-09-10 11:34:52 +08:00
|
|
|
virtual void invert(bool inverted);
|
2015-12-02 02:17:14 +08:00
|
|
|
virtual void space(int spaceLength);
|
|
|
|
virtual void mark(int markLength);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
uint8_t _pin;
|
2023-09-10 11:34:52 +08:00
|
|
|
bool _inverted = false;
|
2015-12-02 02:17:14 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class IRSenderPWM : public IRSender
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
IRSenderPWM(uint8_t pin);
|
|
|
|
void setFrequency(int frequency);
|
2013-12-26 21:11:20 +08:00
|
|
|
void space(int spaceLength);
|
|
|
|
void mark(int markLength);
|
2015-12-02 02:17:14 +08:00
|
|
|
};
|
2013-12-26 21:11:20 +08:00
|
|
|
|
2015-12-02 02:17:14 +08:00
|
|
|
|
|
|
|
class IRSenderBlaster : public IRSender
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
IRSenderBlaster(uint8_t pin);
|
|
|
|
void setFrequency(int frequency);
|
|
|
|
void space(int spaceLength);
|
|
|
|
void mark(int markLength);
|
2013-12-26 21:11:20 +08:00
|
|
|
};
|
|
|
|
|
2016-01-24 23:02:19 +08:00
|
|
|
class IRSenderBitBang : public IRSender
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
IRSenderBitBang(uint8_t pin);
|
|
|
|
void setFrequency(int frequency);
|
|
|
|
void space(int spaceLength);
|
|
|
|
void mark(int markLength);
|
|
|
|
|
|
|
|
protected:
|
2016-01-29 01:35:44 +08:00
|
|
|
int _halfPeriodicTime;
|
2016-01-24 23:02:19 +08:00
|
|
|
};
|
|
|
|
|
2019-08-05 17:35:34 +08:00
|
|
|
#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
|
|
|
|
|
2020-09-02 20:16:11 +08:00
|
|
|
#if defined(ESP8266) || defined(ESP32)
|
2017-07-04 14:51:34 +08:00
|
|
|
class IRSenderIRremoteESP8266 : public IRSender
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
IRSenderIRremoteESP8266(uint8_t pin);
|
|
|
|
void setFrequency(int frequency);
|
|
|
|
void space(int spaceLength);
|
|
|
|
void mark(int markLength);
|
|
|
|
|
|
|
|
private:
|
|
|
|
IRsend _ir;
|
|
|
|
};
|
2019-04-02 18:38:32 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
2019-04-02 18:50:51 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
2017-07-04 14:51:34 +08:00
|
|
|
#endif
|
|
|
|
|
2020-09-02 20:16:11 +08:00
|
|
|
#endif
|