mirror of
https://github.com/Show-maket/IR-protocol.git
synced 2025-06-27 20:59:37 +00:00
refactor
This commit is contained in:
@ -1,23 +1,26 @@
|
||||
#include "IR_Encoder.h"
|
||||
#include "IR_Decoder.h"
|
||||
#include "IR_DecoderRaw.h"
|
||||
|
||||
#define LoopOut 12
|
||||
#define ISR_Out 10
|
||||
#define TestOut 13
|
||||
|
||||
IR_Encoder::IR_Encoder(uint16_t addr, uint8_t pin, IR_Decoder* decPair = nullptr) {
|
||||
IR_Encoder::IR_Encoder(uint16_t addr, uint8_t pin, IR_DecoderRaw* decPair = nullptr) {
|
||||
id = addr;
|
||||
this->decPair = decPair;
|
||||
signal = noSignal;
|
||||
isSending = false;
|
||||
#if disablePairDec
|
||||
if (decPair != nullptr) {
|
||||
blindDecoders = new IR_Decoder * [1] {decPair};
|
||||
blindDecoders = new IR_DecoderRaw * [1] {decPair};
|
||||
decodersCount = 1;
|
||||
}
|
||||
#endif
|
||||
if (decPair != nullptr) {
|
||||
decPair->encoder = this;
|
||||
}
|
||||
};
|
||||
void IR_Encoder::setBlindDecoders(IR_Decoder* decoders [], uint8_t count) {
|
||||
void IR_Encoder::setBlindDecoders(IR_DecoderRaw* decoders [], uint8_t count) {
|
||||
#if disablePairDec
|
||||
if (blindDecoders != nullptr) delete [] blindDecoders;
|
||||
#endif
|
||||
@ -58,26 +61,29 @@ void IR_Encoder::sendData(uint16_t addrTo, uint8_t* data, uint8_t len, bool need
|
||||
sendBuffer[packSize - crcBytes] = crc8(sendBuffer, 0, packSize - crcBytes, poly1) & 0xFF;
|
||||
sendBuffer[packSize - crcBytes + 1] = crc8(sendBuffer, 0, packSize - crcBytes + 1, poly2) & 0xFF;
|
||||
|
||||
if (decPair != nullptr) {
|
||||
decPair->isWaitingAccept = ((msgType >> 5) & IR_MASK_MSG_TYPE == IR_MSG_DATA_ACCEPT);
|
||||
if (decPair->isWaitingAccept) {
|
||||
decPair->addrWaitingFrom = addrTo;
|
||||
}
|
||||
}
|
||||
// if (decPair != nullptr) {
|
||||
// decPair->isWaitingAccept = ((msgType >> 5) & IR_MASK_MSG_TYPE == IR_MSG_DATA_ACCEPT);
|
||||
// if (decPair->isWaitingAccept) {
|
||||
// decPair->addrWaitingFrom = addrTo;
|
||||
// }
|
||||
// }
|
||||
|
||||
// отправка
|
||||
rawSend(sendBuffer, packSize);
|
||||
}
|
||||
|
||||
void IR_Encoder::sendAccept(uint16_t addrTo, uint8_t addInfo, bool forAll = false) {
|
||||
void IR_Encoder::sendAccept(uint16_t addrTo, uint8_t addInfo) {
|
||||
memset(sendBuffer, 0x00, dataByteSizeMax);
|
||||
sendBuffer[0] = IR_MSG_ACCEPT << 5;
|
||||
sendBuffer[0] |= addInfo & IR_MASK_MSG_INFO;
|
||||
|
||||
// addr_self
|
||||
if (!forAll) {
|
||||
sendBuffer[1] = id >> 8 & 0xFF;
|
||||
sendBuffer[2] = id & 0xFF;
|
||||
}
|
||||
sendBuffer[1] = id >> 8 & 0xFF;
|
||||
sendBuffer[2] = id & 0xFF;
|
||||
|
||||
Serial.print("\nRAW Accept to ");
|
||||
Serial.println(addrTo);
|
||||
|
||||
|
||||
// data crc
|
||||
sendBuffer[3] = crc8(sendBuffer, 0, 3, poly1) & 0xFF;
|
||||
|
Reference in New Issue
Block a user