mirror of
https://github.com/Show-maket/IR-protocol.git
synced 2025-06-27 20:59:37 +00:00
Compare commits
4 Commits
d0c3138c52
...
STM32
Author | SHA1 | Date | |
---|---|---|---|
bc9563fbb5 | |||
021e1e290d | |||
89d14919c9 | |||
403b8e6850 |
@ -61,6 +61,7 @@ void IR_Decoder::tick()
|
||||
void IR_Decoder::_tick()
|
||||
{
|
||||
IR_DecoderRaw::tick();
|
||||
|
||||
if (availableRaw())
|
||||
{
|
||||
#ifdef IRDEBUG_INFO
|
||||
@ -102,4 +103,8 @@ void IR_Decoder::_tick()
|
||||
encoder->sendAccept(addrAcceptSendTo, acceptCustomByte);
|
||||
isWaitingAcceptSend = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool IR_Decoder::isReceive(uint8_t type) {
|
||||
return (msgTypeReceive & 0b11111000) && ((msgTypeReceive & IR_MASK_MSG_TYPE) == type);
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ public:
|
||||
|
||||
void enable();
|
||||
void disable();
|
||||
|
||||
bool isReceive(uint8_t type);
|
||||
|
||||
~IR_Decoder();
|
||||
|
||||
|
@ -112,16 +112,37 @@ 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; // приём завершён
|
||||
msgTypeReceive = 0;
|
||||
// firstRX(); // подготовка к новому пакету
|
||||
lastEdgeTime = micros(); // защита от повторного срабатывания
|
||||
}
|
||||
}
|
||||
// ====================================================================
|
||||
|
||||
void IR_DecoderRaw::tick()
|
||||
{
|
||||
// FrontStorage *currentFrontPtr;
|
||||
// noInterrupts();
|
||||
// currentFrontPtr = subBuffer.pop();
|
||||
// interrupts();
|
||||
|
||||
FrontStorage currentFront;
|
||||
noInterrupts();
|
||||
listenStart();
|
||||
@ -130,12 +151,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 +230,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 +242,7 @@ void IR_DecoderRaw::tick()
|
||||
isPreamb = true;
|
||||
|
||||
isRecive = true;
|
||||
isReciveRaw = true;
|
||||
isWrongPack = false;
|
||||
}
|
||||
|
||||
@ -441,6 +475,8 @@ void IR_DecoderRaw::writeToBuffer(bool bit)
|
||||
if (isBufferOverflow || isPreamb || isWrongPack)
|
||||
{
|
||||
isRecive = false;
|
||||
isReciveRaw = false;
|
||||
msgTypeReceive = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -564,6 +600,8 @@ void IR_DecoderRaw::writeToBuffer(bool bit)
|
||||
packInfo.rTime = riseSyncTime;
|
||||
|
||||
isRecive = false;
|
||||
isReciveRaw = false;
|
||||
msgTypeReceive = 0;
|
||||
isAvailable = crcCheck(packSize - crcBytes, crcValue);
|
||||
|
||||
#ifdef BRUTEFORCE_CHECK
|
||||
@ -594,6 +632,12 @@ void IR_DecoderRaw::writeToBuffer(bool bit)
|
||||
OUT_BRUTEFORCE:;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (packSize && (i_dataBuffer == 8)) {
|
||||
msgTypeReceive = (dataBuffer[0]>>5) | 0b11111000;
|
||||
// SerialUSB.println(msgTypeReceive & IR_MASK_MSG_TYPE);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -31,9 +31,10 @@ class IR_DecoderRaw : virtual public IR_FOX
|
||||
friend IR_Encoder;
|
||||
|
||||
protected:
|
||||
PackInfo packInfo;
|
||||
IR_Encoder *encoder; // Указатель на парный передатчик
|
||||
bool availableRaw();
|
||||
PackInfo packInfo;
|
||||
uint8_t msgTypeReceive = 0;
|
||||
IR_Encoder *encoder; // Указатель на парный передатчик
|
||||
bool availableRaw();
|
||||
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@ -48,7 +49,7 @@ public:
|
||||
|
||||
inline bool isOverflow() { return isBufferOverflow; }; // Буффер переполнился
|
||||
bool isSubOverflow();
|
||||
inline bool isReciving() { return isBufferOverflow; }; // Возвращает true, если происходит приём пакета
|
||||
volatile inline bool isReciving() { return isRecive; }; // Возвращает true, если происходит приём пакета
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
private:
|
||||
@ -65,6 +66,8 @@ private:
|
||||
|
||||
uint16_t riseSyncTime = bitTime; // Подстраиваемое время бита в мкс
|
||||
|
||||
volatile uint32_t lastEdgeTime = 0; // время последнего фронта
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
volatile uint32_t currentSubBufferIndex; // Счетчик текущей позиции во вспомогательном буфере фронтов/спадов
|
||||
|
||||
@ -100,7 +103,9 @@ private:
|
||||
int16_t bufBitPos = 0; // Позиция для записи бита в буффер
|
||||
|
||||
private:
|
||||
void listenStart(); // @brief Слушатель для работы isReciving()
|
||||
bool isReciveRaw;
|
||||
void listenStart();
|
||||
void checkTimeout(); //
|
||||
|
||||
/// @brief Проверка CRC. Проверяет len байт со значением crc, пришедшим в пакете
|
||||
/// @param len Длина в байтах проверяемых данных
|
||||
|
@ -122,7 +122,7 @@ typedef uint16_t crc_t;
|
||||
#endif
|
||||
|
||||
#ifndef subBufferSize
|
||||
#define subBufferSize 50 // Буфер для складирования фронтов, пока их не обработают (передатчик)
|
||||
#define subBufferSize 250 // Буфер для складирования фронтов, пока их не обработают (передатчик)
|
||||
#endif
|
||||
|
||||
#define preambPulse 3
|
||||
|
Reference in New Issue
Block a user