mirror of
https://github.com/Show-maket/IR-protocol.git
synced 2025-05-04 07:10:16 +00:00
fix forever loop
This commit is contained in:
parent
a143dcf80d
commit
a0ca86909d
@ -1,7 +1,7 @@
|
|||||||
#include "IR_Decoder.h"
|
#include "IR_Decoder.h"
|
||||||
#include "IR_Encoder.h"
|
#include "IR_Encoder.h"
|
||||||
|
|
||||||
#define IRDEBUG_INFO
|
// #define IRDEBUG_INFO
|
||||||
|
|
||||||
#define checkAddr(h, l) (\
|
#define checkAddr(h, l) (\
|
||||||
((uint16_t)((dataBuffer[h] << 8) | dataBuffer[l]) == addrSelf) || \
|
((uint16_t)((dataBuffer[h] << 8) | dataBuffer[l]) == addrSelf) || \
|
||||||
@ -12,7 +12,7 @@ IR_Decoder::IR_Decoder(const uint8_t isrPin, uint16_t addr, IR_Encoder* encPair
|
|||||||
// rawBuffer = new uint8_t[bufferRawSize] { 0 };
|
// rawBuffer = new uint8_t[bufferRawSize] { 0 };
|
||||||
dataBuffer = new uint8_t[dataByteSizeMax] { 0 };
|
dataBuffer = new uint8_t[dataByteSizeMax] { 0 };
|
||||||
prevRise = prevFall = prevPrevFall = prevPrevRise = 0;
|
prevRise = prevFall = prevPrevFall = prevPrevRise = 0;
|
||||||
start_RX();
|
// start_RX();
|
||||||
}
|
}
|
||||||
|
|
||||||
IR_Decoder::~IR_Decoder() {
|
IR_Decoder::~IR_Decoder() {
|
||||||
@ -78,27 +78,33 @@ void IR_Decoder::start_RX() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void IR_Decoder::listen() {
|
void IR_Decoder::listen() {
|
||||||
if (isRecive && ((micros() - prevRise) > IR_timeout)) {
|
if (isRecive && ((micros() - prevRise) > IR_timeout * 2)) {
|
||||||
isRecive = false;
|
isRecive = false;
|
||||||
start_RX();
|
start_RX();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IR_Decoder::tick() {
|
void IR_Decoder::tick() {
|
||||||
listen();
|
|
||||||
if (firstUnHandledFront == nullptr) return; //Если данных нет - ничего не делаем
|
|
||||||
|
|
||||||
FrontStorage currentFront;
|
FrontStorage currentFront;
|
||||||
//найти следующий необработанный фронт/спад
|
|
||||||
noInterrupts();
|
noInterrupts();
|
||||||
currentFront = *((FrontStorage*)firstUnHandledFront);
|
listen();
|
||||||
|
if (firstUnHandledFront == nullptr) { interrupts(); return; } //Если данных нет - ничего не делаем
|
||||||
|
currentFront = *((FrontStorage*)firstUnHandledFront); //найти следующий необработанный фронт/спад
|
||||||
interrupts();
|
interrupts();
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
if (currentFront.time - prevRise > IR_timeout * 2 /* && !isRecive */) { // первый
|
if (currentFront.time > prevRise && currentFront.time - prevRise > IR_timeout * 2 && !isRecive) { // первый
|
||||||
preambFrontCounter = preambFronts - 1U;
|
preambFrontCounter = preambFronts - 1U;
|
||||||
|
|
||||||
|
|
||||||
if (!currentFront.dir) {
|
if (!currentFront.dir) {
|
||||||
|
#ifdef IRDEBUG_INFO
|
||||||
|
// Serial.print(" currentFront.time: "); Serial.print(currentFront.time);
|
||||||
|
// Serial.print(" currentFront.dir: "); Serial.print(currentFront.dir ? "UP" : "DOWN");
|
||||||
|
// Serial.print(" next: "); Serial.print(currentFront.next == nullptr);
|
||||||
|
// Serial.print(" prevRise: "); Serial.print(prevRise);
|
||||||
|
// Serial.print(" SUB: "); Serial.println(currentFront.time - prevRise);
|
||||||
|
#endif
|
||||||
isRecive = true;
|
isRecive = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -328,6 +334,7 @@ void IR_Decoder::writeToBuffer(bool bit) {
|
|||||||
////////////////////// Проверка наличия битов синхранизации //////////////////////
|
////////////////////// Проверка наличия битов синхранизации //////////////////////
|
||||||
if (isWrongPack = (err_syncBit >= syncBits)) {
|
if (isWrongPack = (err_syncBit >= syncBits)) {
|
||||||
start_RX();
|
start_RX();
|
||||||
|
firstUnHandledFront = firstUnHandledFront->next;
|
||||||
#ifdef IRDEBUG_INFO
|
#ifdef IRDEBUG_INFO
|
||||||
Serial.print("****************");
|
Serial.print("****************");
|
||||||
#endif
|
#endif
|
||||||
|
15
IR_Decoder.h
15
IR_Decoder.h
@ -218,18 +218,9 @@ private:
|
|||||||
volatile uint8_t currentSubBufferIndex; // Счетчик текущей позиции во вспомогательном буфере фронтов/спадов
|
volatile uint8_t currentSubBufferIndex; // Счетчик текущей позиции во вспомогательном буфере фронтов/спадов
|
||||||
|
|
||||||
struct FrontStorage { // Структура для хранения времени и направления фронта/спада
|
struct FrontStorage { // Структура для хранения времени и направления фронта/спада
|
||||||
volatile uint32_t time; // Время
|
volatile uint32_t time = 0; // Время
|
||||||
volatile bool dir; // Направление (true = ↑; false = ↓)
|
volatile bool dir = false; // Направление (true = ↑; false = ↓)
|
||||||
volatile FrontStorage* next; // Указатель на следующий связанный фронт/спад, или nullptr если конец
|
volatile FrontStorage* next = nullptr; // Указатель на следующий связанный фронт/спад, или nullptr если конец
|
||||||
|
|
||||||
// Операторо присвоения
|
|
||||||
FrontStorage& operator= (FrontStorage& val) {
|
|
||||||
this->next = val.next;
|
|
||||||
this->time = val.time;
|
|
||||||
this->dir = val.dir;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
volatile FrontStorage* lastFront = nullptr; // Указатель последнего фронта/спада
|
volatile FrontStorage* lastFront = nullptr; // Указатель последнего фронта/спада
|
||||||
volatile FrontStorage* firstUnHandledFront = nullptr; // Указатель первого необработанного фронта/спада
|
volatile FrontStorage* firstUnHandledFront = nullptr; // Указатель первого необработанного фронта/спада
|
||||||
|
Loading…
x
Reference in New Issue
Block a user