fix isRX flag

This commit is contained in:
2025-05-22 12:08:22 +03:00
parent 89d14919c9
commit 021e1e290d
2 changed files with 43 additions and 4 deletions

View File

@ -112,16 +112,36 @@ void IR_DecoderRaw::firstRX()
void IR_DecoderRaw::listenStart() void IR_DecoderRaw::listenStart()
{ {
if (isRecive && ((micros() - prevRise) > IR_timeout * 2)) if (isReciveRaw && ((micros() - prevRise) > IR_timeout * 2))
{ {
// Serial.print("\nlis>"); // Serial.print("\nlis>");
isRecive = false; isReciveRaw = false;
firstRX(); firstRX();
} }
} }
// ---- быстрая проверка конца пакета ---------------------------------
inline void IR_DecoderRaw::checkTimeout()
{
if (!isRecive) return; // уже не принимаем нечего проверять
if (micros() - lastEdgeTime > IR_timeout * 2U)
{
isRecive = false; // приём завершён
// firstRX(); // подготовка к новому пакету
lastEdgeTime = micros(); // защита от повторного срабатывания
}
}
// ====================================================================
void IR_DecoderRaw::tick() void IR_DecoderRaw::tick()
{ {
// FrontStorage *currentFrontPtr;
// noInterrupts();
// currentFrontPtr = subBuffer.pop();
// interrupts();
FrontStorage currentFront; FrontStorage currentFront;
noInterrupts(); noInterrupts();
listenStart(); listenStart();
@ -130,12 +150,24 @@ void IR_DecoderRaw::tick()
if (currentFrontPtr == nullptr) if (currentFrontPtr == nullptr)
{ {
isSubBufferOverflow = false; isSubBufferOverflow = false;
checkTimeout(); // <--- новое место проверки
interrupts(); interrupts();
return; return;
} // Если данных нет - ничего не делаем } // Если данных нет - ничего не делаем
currentFront = *currentFrontPtr; currentFront = *currentFrontPtr;
interrupts(); interrupts();
// ---------- буфер пуст: фронтов нет, проверяем тайм-аут ----------
// if (currentFrontPtr == nullptr)
// {
// isSubBufferOverflow = false;
// return;
// }
// // ---------- есть фронт: продолжаем обработку ----------
// FrontStorage currentFront = *currentFrontPtr;
lastEdgeTime = currentFront.time; // запоминаем любой фронт
//////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (currentFront.dir) if (currentFront.dir)
@ -197,7 +229,7 @@ void IR_DecoderRaw::tick()
digitalWrite(errOut, currentFront.dir); digitalWrite(errOut, currentFront.dir);
#endif #endif
if (currentFront.time > prevRise && currentFront.time - prevRise > IR_timeout * 2 && !isRecive) if (currentFront.time > prevRise && currentFront.time - prevRise > IR_timeout * 2 && !isReciveRaw)
{ // первый { // первый
#ifdef IRDEBUG #ifdef IRDEBUG
errPulse(up, 50); errPulse(up, 50);
@ -209,6 +241,7 @@ void IR_DecoderRaw::tick()
isPreamb = true; isPreamb = true;
isRecive = true; isRecive = true;
isReciveRaw = true;
isWrongPack = false; isWrongPack = false;
} }
@ -441,6 +474,7 @@ void IR_DecoderRaw::writeToBuffer(bool bit)
if (isBufferOverflow || isPreamb || isWrongPack) if (isBufferOverflow || isPreamb || isWrongPack)
{ {
isRecive = false; isRecive = false;
isReciveRaw = false;
return; return;
} }
@ -564,6 +598,7 @@ void IR_DecoderRaw::writeToBuffer(bool bit)
packInfo.rTime = riseSyncTime; packInfo.rTime = riseSyncTime;
isRecive = false; isRecive = false;
isReciveRaw = false;
isAvailable = crcCheck(packSize - crcBytes, crcValue); isAvailable = crcCheck(packSize - crcBytes, crcValue);
#ifdef BRUTEFORCE_CHECK #ifdef BRUTEFORCE_CHECK

View File

@ -65,6 +65,8 @@ private:
uint16_t riseSyncTime = bitTime; // Подстраиваемое время бита в мкс uint16_t riseSyncTime = bitTime; // Подстраиваемое время бита в мкс
volatile uint32_t lastEdgeTime = 0; // время последнего фронта
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
volatile uint32_t currentSubBufferIndex; // Счетчик текущей позиции во вспомогательном буфере фронтов/спадов volatile uint32_t currentSubBufferIndex; // Счетчик текущей позиции во вспомогательном буфере фронтов/спадов
@ -100,7 +102,9 @@ private:
int16_t bufBitPos = 0; // Позиция для записи бита в буффер int16_t bufBitPos = 0; // Позиция для записи бита в буффер
private: private:
void listenStart(); // @brief Слушатель для работы isReciving() bool isReciveRaw;
void listenStart();
void checkTimeout(); //
/// @brief Проверка CRC. Проверяет len байт со значением crc, пришедшим в пакете /// @brief Проверка CRC. Проверяет len байт со значением crc, пришедшим в пакете
/// @param len Длина в байтах проверяемых данных /// @param len Длина в байтах проверяемых данных