add listen and fix

This commit is contained in:
2023-10-17 17:35:02 +03:00
parent 63e8328755
commit 791d90ee00
3 changed files with 54 additions and 40 deletions

View File

@ -35,7 +35,6 @@ void IR_Decoder::writeToBuffer(bool bit) {
//const auto testval = bufferBitSizeMax;
if ((bufBitPos >= (8 * msgBytes) - syncBits) && !isMsgAvaliable) {
switch ((rawBuffer[0] >> 5) & IR_MASK_MSG_TYPE) {
case IR_MSG_ACCEPT:
if (bufBitPos >= ((msgBytes + addrBytes + crcBytes) * (8 + 3)) - syncBits) {
const uint8_t dataSize = msgBytes + addrBytes;
@ -67,11 +66,9 @@ void IR_Decoder::writeToBuffer(bool bit) {
const uint8_t dataSize = (rawBuffer[0] & IR_MASK_MSG_INFO);
isRawAvaliable = true;
isMsgAvaliable = crcCheck(dataSize);
if (isMsgAvaliable && checkAddr(3, 4)
) {
if (isMsgAvaliable && checkAddr(3, 4)) {
gotData._isAvaliable = true;
gotData._set(dataBuffer, (dataSize)+crcBytes, crcValue, errorCounter, riseSyncTime);
} else {
gotRawData._isAvaliable = true;
gotRawData._set(dataBuffer, (dataSize)+crcBytes, crcValue, errorCounter, riseSyncTime);
@ -171,6 +168,10 @@ uint16_t IR_Decoder::ceil_div(uint16_t val, uint16_t divider) {
return ret;
}
void IR_Decoder::listen(){
if(isRecive && micros()-prevRise > IR_timeout*2) {isRecive = false;}
}
////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////// isr ///////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
@ -180,6 +181,7 @@ void IR_Decoder::isr() { // в прерывании вызываем isr()
if (isPairSending) return;
if (micros() - prevRise > IR_timeout) { // первый
isRecive = true;
isPreamb = true;
frontCounter = preambFronts - 1U;
errorCounter = 0;