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

View File

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