mirror of
https://github.com/Show-maket/IR-protocol.git
synced 2025-06-28 05:09:40 +00:00
add Accept logic
This commit is contained in:
25
IR_Decoder.h
25
IR_Decoder.h
@ -1,16 +1,23 @@
|
||||
#pragma once
|
||||
#include "IR_DecoderRaw.h"
|
||||
#include "PacketTypes.h"
|
||||
#include "IR_Encoder.h"
|
||||
|
||||
class IR_Decoder : public IR_DecoderRaw {
|
||||
uint32_t acceptSendTimer;
|
||||
bool isWaitingAcceptSend;
|
||||
uint16_t addrAcceptSendTo;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
PacketTypes::Data gotData;
|
||||
PacketTypes::DataBack gotBackData;
|
||||
PacketTypes::Accept gotAccept;
|
||||
PacketTypes::Request gotRequest;
|
||||
|
||||
IR_Decoder(const uint8_t isrPin, uint16_t addr, IR_Encoder* encPair = nullptr) : IR_DecoderRaw(isrPin, addr, encPair) {
|
||||
}
|
||||
IR_Decoder(const uint8_t isrPin, uint16_t addr, IR_Encoder* encPair = nullptr) : IR_DecoderRaw(isrPin, addr, encPair) {}
|
||||
|
||||
void tick() {
|
||||
IR_DecoderRaw::tick();
|
||||
@ -18,10 +25,9 @@ public:
|
||||
#ifdef IRDEBUG_INFO
|
||||
Serial.println("PARSING RAW DATA");
|
||||
#endif
|
||||
bool isNeenAccept = false;
|
||||
isWaitingAcceptSend = false;
|
||||
switch (packInfo.buffer[0] >> 5 & IR_MASK_MSG_TYPE) {
|
||||
case IR_MSG_DATA_ACCEPT:
|
||||
isNeenAccept = true;
|
||||
case IR_MSG_DATA_NOACCEPT:
|
||||
gotData.set(&packInfo, id);
|
||||
break;
|
||||
@ -39,8 +45,15 @@ public:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (gotData.isAvailable && (gotData.getMsgType() == IR_MSG_DATA_ACCEPT)) {
|
||||
acceptSendTimer = millis();
|
||||
addrAcceptSendTo = gotData.getAddrFrom();
|
||||
if(addrAcceptSendTo && addrAcceptSendTo < IR_Broadcast) isWaitingAcceptSend = true;
|
||||
}
|
||||
}
|
||||
if (isWaitingAcceptSend && millis() - acceptSendTimer > 75) {
|
||||
encoder->sendAccept(addrAcceptSendTo);
|
||||
isWaitingAcceptSend = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user