mirror of
https://github.com/Show-maket/IR-protocol.git
synced 2025-05-03 23:00:16 +00:00
fix forever loop ?
This commit is contained in:
parent
1dc702f05d
commit
1f62eb8c0a
@ -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("] ");
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
|
||||
class IR_Encoder;
|
||||
class IR_DecoderRaw : public IR_FOX {
|
||||
class IR_DecoderRaw : virtual public IR_FOX {
|
||||
friend IR_Encoder;
|
||||
public:
|
||||
const uint8_t isrPin; // Пин прерывания
|
||||
@ -37,17 +37,17 @@ public:
|
||||
|
||||
void isr(); // Функция прерывания
|
||||
void tick(); // Обработка приёмника, необходима для работы
|
||||
bool available() { if(isAvailable) {isAvailable = false; return true;} else { return false;}};
|
||||
bool available() { if (isAvailable) { isAvailable = false; return true; } else { return false; } };
|
||||
bool isOverflow() { return isBufferOverflow; }; // Буффер переполнился
|
||||
bool isReciving() { return isBufferOverflow; }; // Возвращает true, если происходит приём пакета
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
PackInfo packInfo;
|
||||
uint16_t id;
|
||||
private:
|
||||
ErrorsStruct errors;
|
||||
uint16_t id;
|
||||
bool isAvailable = false;
|
||||
bool isAvailable = false;
|
||||
uint16_t packSize;
|
||||
uint16_t crcValue;
|
||||
IR_Encoder* encoder; // Указатель на парный передатчик
|
||||
@ -71,14 +71,15 @@ private:
|
||||
volatile FrontStorage* firstUnHandledFront = nullptr; // Указатель первого необработанного фронта/спада
|
||||
volatile FrontStorage subBuffer[subBufferSize]; // вспомогательный буфер для хранения необработанных фронтов/спадов
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
uint8_t dataBuffer[dataByteSizeMax]{0}; // Буффер данных
|
||||
uint8_t dataBuffer[dataByteSizeMax] { 0 }; // Буффер данных
|
||||
uint32_t prevRise, prevPrevRise, prevFall, prevPrevFall; // Время предыдущих фронтов/спадов
|
||||
uint32_t risePeriod;
|
||||
uint16_t errorCounter = 0; // Счётчик ошибок
|
||||
int8_t preambFrontCounter = 0; // Счётчик __/``` ↑ преамбулы
|
||||
int16_t bufBitPos = 0; // Позиция для записи бита в буффер
|
||||
|
||||
private:
|
||||
void listenEnd(); // @brief Слушатель для работы isReciving()
|
||||
void listenStart(); // @brief Слушатель для работы isReciving()
|
||||
|
||||
/// @brief Проверка CRC. Проверяет len байт со значением crc, пришедшим в пакете
|
||||
/// @param len Длина в байтах проверяемых данных
|
||||
@ -98,7 +99,7 @@ private:
|
||||
void writeToBuffer(bool);
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
void firstRX(); /// @brief Установка и сброс начальных значений и флагов в готовность к приёму данных
|
||||
|
||||
/// @brief Целочисленное деление с округлением вверх
|
||||
|
Loading…
x
Reference in New Issue
Block a user