fix forever loop ?

This commit is contained in:
2024-02-26 15:42:27 +03:00
parent 1dc702f05d
commit 1f62eb8c0a
2 changed files with 22 additions and 16 deletions

View File

@ -46,7 +46,7 @@ void IR_DecoderRaw::isr() {
void IR_DecoderRaw::firstRX() {
#ifdef IRDEBUG_INFO
Serial.print("\n>");
Serial.print("\nRX>");
#endif
errors.reset();
@ -67,8 +67,9 @@ void IR_DecoderRaw::firstRX() {
memset(dataBuffer, 0x00, dataByteSizeMax);
}
void IR_DecoderRaw::listenEnd() {
void IR_DecoderRaw::listenStart() {
if (isRecive && ((micros() - prevRise) > IR_timeout * 2)) {
Serial.print("\nlis>");
isRecive = false;
firstRX();
}
@ -77,10 +78,11 @@ void IR_DecoderRaw::listenEnd() {
void IR_DecoderRaw::tick() {
FrontStorage currentFront;
noInterrupts();
listenEnd();
listenStart();
if (firstUnHandledFront == nullptr) { interrupts(); return; } //Если данных нет - ничего не делаем
currentFront = *((FrontStorage*)firstUnHandledFront); //найти следующий необработанный фронт/спад
interrupts();
if (currentFront.next == nullptr) { isRecive = false; return; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (currentFront.time > prevRise && currentFront.time - prevRise > IR_timeout * 2 && !isRecive) { // первый
@ -97,11 +99,11 @@ void IR_DecoderRaw::tick() {
#endif
isRecive = true;
isWrongPack = false;
}
}
}
if (preambFrontCounter > 0) { // в преамбуле
uint32_t risePeriod = currentFront.time - prevRise;
risePeriod = currentFront.time - prevRise;
if (currentFront.dir && risePeriod < IR_timeout) { // __/``` ↑ и мы в внутри пакета
if (risePeriod < riseTimeMin << 1) { // fix рваной единицы
@ -276,7 +278,10 @@ void IR_DecoderRaw::writeToBuffer(bool bit) {
#endif
isBufferOverflow = true;
}
if (isBufferOverflow || isPreamb || isWrongPack) return;
if (isBufferOverflow || isPreamb || isWrongPack) {
isRecive = false;
return;
}
// Переключение флага, data или syncBit
if (bufBitPos == nextControlBit) {
@ -327,7 +332,7 @@ void IR_DecoderRaw::writeToBuffer(bool bit) {
#ifdef IRDEBUG_INFO
Serial.print("****************");
#endif
isRecive = false;
};
}//**************************************************************************************************//
@ -345,11 +350,11 @@ void IR_DecoderRaw::writeToBuffer(bool bit) {
if (i_dataBuffer == ((msgBytes)*bitPerByte)) { Serial.print(" -> "); Serial.print(dataBuffer[0] & IR_MASK_MSG_INFO); Serial.print(" ->"); }
if (i_dataBuffer == ((msgBytes + addrBytes) * bitPerByte)) { Serial.print(" |"); }
if (i_dataBuffer == ((msgBytes + addrBytes + addrBytes) * bitPerByte)) { Serial.print(" ->"); }
if (i_dataBuffer == (((dataBuffer[0] & IR_MASK_MSG_INFO)-2) * bitPerByte)) { Serial.print(" <-"); }
if (i_dataBuffer == (((dataBuffer[0] & IR_MASK_MSG_INFO) - 2) * bitPerByte)) { Serial.print(" <-"); }
}
#endif
if (!isAvailable && isData) {
if (!isAvailable && isData && !isWrongPack) {
if (i_dataBuffer == 8 * msgBytes) {// Ппервый байт
packSize = dataBuffer[0] & IR_MASK_MSG_INFO;
Serial.print(" ["); Serial.print(packSize); Serial.print("] ");