mirror of
https://github.com/Show-maket/IR-protocol.git
synced 2025-05-04 07:10:16 +00:00
95 lines
2.9 KiB
C++
95 lines
2.9 KiB
C++
#pragma once
|
|
#include "IR_config.h"
|
|
|
|
// TODO: Отложенная передача после завершения приема
|
|
|
|
class IR_DecoderRaw;
|
|
class IR_Encoder : public IR_FOX
|
|
{
|
|
friend IR_DecoderRaw;
|
|
|
|
public:
|
|
private:
|
|
// uint16_t id; /// @brief Адрес передатчика
|
|
public:
|
|
/// @brief Класс передатчика
|
|
/// @param addr Адрес передатчика
|
|
/// @param pin Вывод передатчика
|
|
/// @param decPair Приёмник, для которого отключается приём в момент передачи передатчиком
|
|
IR_Encoder(uint8_t pin, uint16_t addr = 0, IR_DecoderRaw *decPair = nullptr, bool autoHandle = true);
|
|
static void isr();
|
|
|
|
void enable();
|
|
void disable();
|
|
|
|
void setBlindDecoders(IR_DecoderRaw *decoders[], uint8_t count);
|
|
void rawSend(uint8_t *ptr, uint8_t len);
|
|
|
|
void sendData(uint16_t addrTo, uint8_t dataByte, bool needAccept = false);
|
|
void sendData(uint16_t addrTo, uint8_t *data = nullptr, uint8_t len = 0, bool needAccept = false);
|
|
void sendDataFULL(uint16_t addrFrom, uint16_t addrTo, uint8_t *data = nullptr, uint8_t len = 0, bool needAccept = false);
|
|
|
|
|
|
void sendAccept(uint16_t addrTo, uint8_t customByte = 0);
|
|
void sendRequest(uint16_t addrTo);
|
|
|
|
void sendBack(uint8_t data);
|
|
void sendBack(uint8_t *data = nullptr, uint8_t len = 0);
|
|
void sendBackTo(uint16_t addrTo, uint8_t *data = nullptr, uint8_t len = 0);
|
|
|
|
|
|
~IR_Encoder();
|
|
volatile bool ir_out_virtual;
|
|
|
|
private:
|
|
static std::list<IR_Encoder*>& get_enc_list();
|
|
void _sendBack(bool isAdressed, uint16_t addrTo, uint8_t *data, uint8_t len);
|
|
void _isr();
|
|
|
|
void setDecoder_isSending();
|
|
void sendByte(uint8_t byte, bool *prev, bool LOW_FIRST);
|
|
void addSync(bool *prev, bool *next);
|
|
void send_HIGH(bool = 1);
|
|
void send_LOW();
|
|
void send_EMPTY(uint8_t count);
|
|
|
|
enum SignalPart : uint8_t
|
|
{
|
|
noSignal = 0,
|
|
preamb = 1,
|
|
data = 2,
|
|
sync = 3
|
|
};
|
|
|
|
IR_DecoderRaw *decPair;
|
|
IR_DecoderRaw **blindDecoders;
|
|
uint8_t decodersCount;
|
|
|
|
uint8_t sendLen;
|
|
uint8_t sendBuffer[dataByteSizeMax]{0}; /// @brief Буффер данных для отправки
|
|
|
|
volatile bool isSending;
|
|
volatile bool state; /// @brief Текущий уровень генерации
|
|
|
|
volatile uint8_t dataByteCounter;
|
|
|
|
volatile uint8_t toggleCounter; /// @brief Счётчик переключений
|
|
volatile uint8_t dataBitCounter;
|
|
|
|
volatile uint8_t preambFrontCounter;
|
|
volatile uint8_t dataSequenceCounter;
|
|
volatile uint8_t syncSequenceCounter;
|
|
volatile bool syncLastBit;
|
|
|
|
struct BitSequence
|
|
{
|
|
uint8_t low;
|
|
uint8_t high;
|
|
};
|
|
static uint8_t bitHigh[2];
|
|
static uint8_t bitLow[2];
|
|
uint8_t *currentBitSequence = bitLow;
|
|
volatile SignalPart signal;
|
|
};
|
|
|