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()
|
void IR_Decoder::_tick()
|
||||||
{
|
{
|
||||||
IR_DecoderRaw::tick();
|
IR_DecoderRaw::tick();
|
||||||
|
|
||||||
if (availableRaw())
|
if (availableRaw())
|
||||||
{
|
{
|
||||||
#ifdef IRDEBUG_INFO
|
#ifdef IRDEBUG_INFO
|
||||||
@ -102,4 +103,8 @@ void IR_Decoder::_tick()
|
|||||||
encoder->sendAccept(addrAcceptSendTo, acceptCustomByte);
|
encoder->sendAccept(addrAcceptSendTo, acceptCustomByte);
|
||||||
isWaitingAcceptSend = false;
|
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 enable();
|
||||||
void disable();
|
void disable();
|
||||||
|
|
||||||
|
bool isReceive(uint8_t type);
|
||||||
|
|
||||||
~IR_Decoder();
|
~IR_Decoder();
|
||||||
|
|
||||||
|
@ -112,16 +112,37 @@ void IR_DecoderRaw::firstRX()
|
|||||||
|
|
||||||
void IR_DecoderRaw::listenStart()
|
void IR_DecoderRaw::listenStart()
|
||||||
{
|
{
|
||||||
if (isRecive && ((micros() - prevRise) > IR_timeout * 2))
|
if (isReciveRaw && ((micros() - prevRise) > IR_timeout * 2))
|
||||||
{
|
{
|
||||||
// Serial.print("\nlis>");
|
// Serial.print("\nlis>");
|
||||||
isRecive = false;
|
isReciveRaw = false;
|
||||||
firstRX();
|
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()
|
void IR_DecoderRaw::tick()
|
||||||
{
|
{
|
||||||
|
// FrontStorage *currentFrontPtr;
|
||||||
|
// noInterrupts();
|
||||||
|
// currentFrontPtr = subBuffer.pop();
|
||||||
|
// interrupts();
|
||||||
|
|
||||||
FrontStorage currentFront;
|
FrontStorage currentFront;
|
||||||
noInterrupts();
|
noInterrupts();
|
||||||
listenStart();
|
listenStart();
|
||||||
@ -130,12 +151,24 @@ void IR_DecoderRaw::tick()
|
|||||||
if (currentFrontPtr == nullptr)
|
if (currentFrontPtr == nullptr)
|
||||||
{
|
{
|
||||||
isSubBufferOverflow = false;
|
isSubBufferOverflow = false;
|
||||||
|
checkTimeout(); // <--- новое место проверки
|
||||||
interrupts();
|
interrupts();
|
||||||
return;
|
return;
|
||||||
} // Если данных нет - ничего не делаем
|
} // Если данных нет - ничего не делаем
|
||||||
currentFront = *currentFrontPtr;
|
currentFront = *currentFrontPtr;
|
||||||
interrupts();
|
interrupts();
|
||||||
|
|
||||||
|
// ---------- буфер пуст: фронтов нет, проверяем тайм-аут ----------
|
||||||
|
// if (currentFrontPtr == nullptr)
|
||||||
|
// {
|
||||||
|
// isSubBufferOverflow = false;
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // ---------- есть фронт: продолжаем обработку ----------
|
||||||
|
// FrontStorage currentFront = *currentFrontPtr;
|
||||||
|
lastEdgeTime = currentFront.time; // запоминаем любой фронт
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
if (currentFront.dir)
|
if (currentFront.dir)
|
||||||
@ -197,7 +230,7 @@ void IR_DecoderRaw::tick()
|
|||||||
digitalWrite(errOut, currentFront.dir);
|
digitalWrite(errOut, currentFront.dir);
|
||||||
#endif
|
#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
|
#ifdef IRDEBUG
|
||||||
errPulse(up, 50);
|
errPulse(up, 50);
|
||||||
@ -209,6 +242,7 @@ void IR_DecoderRaw::tick()
|
|||||||
isPreamb = true;
|
isPreamb = true;
|
||||||
|
|
||||||
isRecive = true;
|
isRecive = true;
|
||||||
|
isReciveRaw = true;
|
||||||
isWrongPack = false;
|
isWrongPack = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -441,6 +475,8 @@ void IR_DecoderRaw::writeToBuffer(bool bit)
|
|||||||
if (isBufferOverflow || isPreamb || isWrongPack)
|
if (isBufferOverflow || isPreamb || isWrongPack)
|
||||||
{
|
{
|
||||||
isRecive = false;
|
isRecive = false;
|
||||||
|
isReciveRaw = false;
|
||||||
|
msgTypeReceive = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -564,6 +600,8 @@ void IR_DecoderRaw::writeToBuffer(bool bit)
|
|||||||
packInfo.rTime = riseSyncTime;
|
packInfo.rTime = riseSyncTime;
|
||||||
|
|
||||||
isRecive = false;
|
isRecive = false;
|
||||||
|
isReciveRaw = false;
|
||||||
|
msgTypeReceive = 0;
|
||||||
isAvailable = crcCheck(packSize - crcBytes, crcValue);
|
isAvailable = crcCheck(packSize - crcBytes, crcValue);
|
||||||
|
|
||||||
#ifdef BRUTEFORCE_CHECK
|
#ifdef BRUTEFORCE_CHECK
|
||||||
@ -594,6 +632,12 @@ void IR_DecoderRaw::writeToBuffer(bool bit)
|
|||||||
OUT_BRUTEFORCE:;
|
OUT_BRUTEFORCE:;
|
||||||
#endif
|
#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;
|
friend IR_Encoder;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PackInfo packInfo;
|
PackInfo packInfo;
|
||||||
IR_Encoder *encoder; // Указатель на парный передатчик
|
uint8_t msgTypeReceive = 0;
|
||||||
bool availableRaw();
|
IR_Encoder *encoder; // Указатель на парный передатчик
|
||||||
|
bool availableRaw();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
@ -48,7 +49,7 @@ public:
|
|||||||
|
|
||||||
inline bool isOverflow() { return isBufferOverflow; }; // Буффер переполнился
|
inline bool isOverflow() { return isBufferOverflow; }; // Буффер переполнился
|
||||||
bool isSubOverflow();
|
bool isSubOverflow();
|
||||||
inline bool isReciving() { return isBufferOverflow; }; // Возвращает true, если происходит приём пакета
|
volatile inline bool isReciving() { return isRecive; }; // Возвращает true, если происходит приём пакета
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
private:
|
private:
|
||||||
@ -65,6 +66,8 @@ private:
|
|||||||
|
|
||||||
uint16_t riseSyncTime = bitTime; // Подстраиваемое время бита в мкс
|
uint16_t riseSyncTime = bitTime; // Подстраиваемое время бита в мкс
|
||||||
|
|
||||||
|
volatile uint32_t lastEdgeTime = 0; // время последнего фронта
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
volatile uint32_t currentSubBufferIndex; // Счетчик текущей позиции во вспомогательном буфере фронтов/спадов
|
volatile uint32_t currentSubBufferIndex; // Счетчик текущей позиции во вспомогательном буфере фронтов/спадов
|
||||||
|
|
||||||
@ -100,7 +103,9 @@ private:
|
|||||||
int16_t bufBitPos = 0; // Позиция для записи бита в буффер
|
int16_t bufBitPos = 0; // Позиция для записи бита в буффер
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void listenStart(); // @brief Слушатель для работы isReciving()
|
bool isReciveRaw;
|
||||||
|
void listenStart();
|
||||||
|
void checkTimeout(); //
|
||||||
|
|
||||||
/// @brief Проверка CRC. Проверяет len байт со значением crc, пришедшим в пакете
|
/// @brief Проверка CRC. Проверяет len байт со значением crc, пришедшим в пакете
|
||||||
/// @param len Длина в байтах проверяемых данных
|
/// @param len Длина в байтах проверяемых данных
|
||||||
|
@ -122,7 +122,7 @@ typedef uint16_t crc_t;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef subBufferSize
|
#ifndef subBufferSize
|
||||||
#define subBufferSize 50 // Буфер для складирования фронтов, пока их не обработают (передатчик)
|
#define subBufferSize 250 // Буфер для складирования фронтов, пока их не обработают (передатчик)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define preambPulse 3
|
#define preambPulse 3
|
||||||
|
Reference in New Issue
Block a user