mirror of
https://github.com/Show-maket/IR-protocol.git
synced 2025-06-28 05:09:40 +00:00
v1.00
This commit is contained in:
48
IR_Encoder.h
Normal file
48
IR_Encoder.h
Normal file
@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
#include "IR_config.h"
|
||||
|
||||
class IR_Decoder;
|
||||
class IR_Encoder : IR_FOX {
|
||||
friend IR_Decoder;
|
||||
public:
|
||||
uint8_t ir_out;
|
||||
uint16_t addrSelf;
|
||||
private:
|
||||
bool prevPreambBit = true; // предыдущий бит преамбулы
|
||||
|
||||
public:
|
||||
IR_Encoder(uint16_t addr, uint8_t pin, IR_Decoder* decPair = nullptr);
|
||||
|
||||
template<typename T>
|
||||
void sendData(uint16_t addrTo, T& data, bool needAccept = false);
|
||||
void sendACK(uint16_t addrTo, uint8_t addInfo, bool forAll = false);
|
||||
void sendRequest(uint16_t addrTo, uint8_t addInfo = 0);
|
||||
|
||||
|
||||
~IR_Encoder();
|
||||
private:
|
||||
IR_Decoder* decoder;
|
||||
void meanderBlock(uint16_t count, uint16_t _period, bool isNoPause = true);
|
||||
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);
|
||||
void rawSend(uint8_t* ptr, uint8_t len);
|
||||
void _sendData(uint16_t addrTo, uint8_t* data, uint8_t len, uint8_t msgType);
|
||||
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename T>
|
||||
void IR_Encoder::sendData(uint16_t addrTo, T& data, bool needAccept = false) { // TODO: переделать логику LOW_FIRST
|
||||
uint8_t len = sizeof(T);
|
||||
uint8_t packSize = msgBytes + addrBytes + addrBytes + len + crcBytes;
|
||||
|
||||
uint8_t msgType =
|
||||
((needAccept ? IR_MSG_DATA_ACCEPT : IR_MSG_DATA_NOACCEPT) << 5) | ((packSize - crcBytes) & IR_MASK_MSG_INFO);
|
||||
|
||||
_sendData(addrTo, data, len, msgType);
|
||||
}
|
Reference in New Issue
Block a user