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:
@ -4,11 +4,11 @@
|
||||
#define IRDEBUG_INFO
|
||||
|
||||
#define checkAddr(h, l) (\
|
||||
((uint16_t)((dataBuffer[h] << 8) | dataBuffer[l]) == addrSelf) || \
|
||||
((uint16_t)((dataBuffer[h] << 8) | dataBuffer[l]) == id) || \
|
||||
((uint16_t)((dataBuffer[h] << 8) | dataBuffer[l]) >= IR_Broadcast)\
|
||||
)
|
||||
|
||||
IR_Decoder::IR_Decoder(const uint8_t isrPin, uint16_t addr, IR_Encoder* encPair = nullptr) : isrPin(isrPin), addrSelf(addr), encoder(encPair) {
|
||||
IR_Decoder::IR_Decoder(const uint8_t isrPin, uint16_t addr, IR_Encoder* encPair = nullptr) : isrPin(isrPin), id(addr), encoder(encPair) {
|
||||
// rawBuffer = new uint8_t[bufferRawSize] { 0 };
|
||||
dataBuffer = new uint8_t[dataByteSizeMax] { 0 };
|
||||
prevRise = prevFall = prevPrevFall = prevPrevRise = 0;
|
||||
@ -124,7 +124,7 @@ void IR_Decoder::tick() {
|
||||
// Serial.print("preambFrontCounter: "); Serial.println(preambFrontCounter);
|
||||
} else {
|
||||
if (isPreamb) {// первый фронт после
|
||||
gotTune._set(riseSyncTime);
|
||||
gotTune.set(dataBuffer, 1, 0, errors, riseSyncTime);
|
||||
}
|
||||
isPreamb = false;
|
||||
}
|
||||
@ -367,7 +367,7 @@ void IR_Decoder::writeToBuffer(bool bit) {
|
||||
packToOutClass(
|
||||
((msgBytes + addrBytes + crcBytes) * bitPerByte), // endBitOffset
|
||||
(msgBytes + addrBytes), // bytesToCheck
|
||||
1, // addressForCheckOffset
|
||||
1, // addressForCheck_Offset
|
||||
&gotAccept // objFine
|
||||
);
|
||||
break;
|
||||
@ -376,7 +376,7 @@ void IR_Decoder::writeToBuffer(bool bit) {
|
||||
packToOutClass(
|
||||
((msgBytes + addrBytes + addrBytes + crcBytes) * bitPerByte), // endBitOffset
|
||||
(msgBytes + addrBytes + addrBytes), // bytesToCheck
|
||||
3, // addressForCheckOffset
|
||||
3, // addressForCheck_Offset
|
||||
&gotRequest // objFine
|
||||
);
|
||||
break;
|
||||
@ -387,7 +387,7 @@ void IR_Decoder::writeToBuffer(bool bit) {
|
||||
packToOutClass(
|
||||
(((dataBuffer[0] & IR_MASK_MSG_INFO) + crcBytes) * bitPerByte), // endBitOffset
|
||||
(dataBuffer[0] & IR_MASK_MSG_INFO), // bytesToCheck
|
||||
3, // addressForCheckOffset
|
||||
3, // addressForCheck_Offset
|
||||
&gotData, // objFine
|
||||
&gotRawData // objWrong
|
||||
);
|
||||
@ -400,9 +400,9 @@ void IR_Decoder::writeToBuffer(bool bit) {
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
void IR_Decoder::packToOutClass(uint8_t endBitOffset, uint8_t bytesToCheck, uint8_t addressForCheckOffset, InputData* objFine, InputData* objWrong = nullptr) {
|
||||
void IR_Decoder::packToOutClass(uint8_t endBitOffset, uint8_t bytesToCheck, uint8_t addressForCheckOffset, IDataPack* objFine, IDataPack* objWrong = nullptr) {
|
||||
uint16_t crcValue;
|
||||
InputData* objResult = nullptr;
|
||||
IDataPack* objResult = nullptr;
|
||||
if (i_dataBuffer == endBitOffset) {
|
||||
#ifdef IRDEBUG_INFO
|
||||
Serial.print(" IN ");
|
||||
@ -420,8 +420,8 @@ void IR_Decoder::packToOutClass(uint8_t endBitOffset, uint8_t bytesToCheck, uint
|
||||
#endif
|
||||
}
|
||||
if (objWrong != nullptr) {
|
||||
objResult->_isAvaliable = true;
|
||||
objResult->_set(dataBuffer, bytesToCheck + crcBytes, crcValue, errors, riseSyncTime);
|
||||
objResult->isAvaliable = true;
|
||||
objResult->set(dataBuffer, bytesToCheck + crcBytes, crcValue, errors, riseSyncTime);
|
||||
}
|
||||
isRecive = false;
|
||||
}
|
||||
@ -442,7 +442,9 @@ bool IR_Decoder::crcCheck(uint8_t len, crc_t& crc) {
|
||||
dataBuffer[len + 1] == (crc & 0xFF)
|
||||
) {
|
||||
crcOK = true;
|
||||
} else { crcOK = false; }
|
||||
} else {
|
||||
crcOK = false;
|
||||
}
|
||||
|
||||
|
||||
return crcOK;
|
||||
|
Reference in New Issue
Block a user