diff --git a/IR_DecoderRaw.cpp b/IR_DecoderRaw.cpp index 66482f2..a230806 100644 --- a/IR_DecoderRaw.cpp +++ b/IR_DecoderRaw.cpp @@ -402,11 +402,15 @@ void IR_DecoderRaw::tick() FrontStorage rawFront; bool processedFront = false; - const bool hasRawFront = subBuffer.pop(rawFront); // B5: копия под одной критсекцией (без торн-рида) - - if (IR_INPUT_MIN_PULSE_US > 0U) + // Батч-выемка (IR_RX_TICK_BATCH): раньше 1 фронт/tick — приём был привязан + // к частоте loop, буфер 250 фронтов (~120мс эфира) переполнялся на медленном + // loop и кадры гибли молча. Семантика idle-пути сохранена: flush + // пульс-фильтра — только когда буфер пуст (как прежняя else-ветка). + uint8_t batchBudget = IR_RX_TICK_BATCH; + bool hasRawFront = subBuffer.pop(rawFront); // B5: копия под одной критсекцией (без торн-рида) + while (hasRawFront) { - if (hasRawFront) + if (IR_INPUT_MIN_PULSE_US > 0U) { pulseFilterPushRaw(rawFront); FrontStorage confirmedFront; @@ -418,19 +422,24 @@ void IR_DecoderRaw::tick() } else { - const uint32_t nowUs = micros(); - FrontStorage confirmedFront; - while (pulseFilterTryFlushOne(nowUs, confirmedFront)) - { - processDecodedFront(confirmedFront); - processedFront = true; - } + processDecodedFront(rawFront); + processedFront = true; } + if (--batchBudget == 0U) + { + break; + } + hasRawFront = subBuffer.pop(rawFront); } - else if (hasRawFront) + if (!hasRawFront && IR_INPUT_MIN_PULSE_US > 0U) { - processDecodedFront(rawFront); - processedFront = true; + const uint32_t nowUs = micros(); + FrontStorage confirmedFront; + while (pulseFilterTryFlushOne(nowUs, confirmedFront)) + { + processDecodedFront(confirmedFront); + processedFront = true; + } } if (!processedFront) diff --git a/IR_config.h b/IR_config.h index d585d9e..afdfff5 100644 --- a/IR_config.h +++ b/IR_config.h @@ -179,6 +179,13 @@ typedef uint16_t crc_t; #ifndef IR_INPUT_MIN_PULSE_US #define IR_INPUT_MIN_PULSE_US 0 #endif +/** Сколько сырых фронтов забирать из ISR-буфера за один tick() (батч-выемка). + * 1 фронт/tick привязывал RX-пропускную способность к частоте loop: медленный + * loop (телеметрия/дисплей) переполнял буфер 250 фронтов (~120мс эфира) и + * кадры терялись молча. Батч развязывает приём от темпа loop. */ +#ifndef IR_RX_TICK_BATCH +#define IR_RX_TICK_BATCH 16U +#endif /** Сколько подтверждённых фронтов держать перед выпуском в декодер (потоковая задержка). */ #ifndef IR_INPUT_FILTER_HOLDBACK_EDGES #define IR_INPUT_FILTER_HOLDBACK_EDGES 3U