mirror of
https://github.com/Show-maket/IR-protocol.git
synced 2025-05-04 15:20:16 +00:00
refactor
This commit is contained in:
parent
e752d0fb50
commit
d46640b145
@ -6,8 +6,8 @@ std::list<IR_Decoder*>& IR_Decoder::get_dec_list() // определение ф
|
|||||||
return dec_list; // возвращается ссылка на переменную
|
return dec_list; // возвращается ссылка на переменную
|
||||||
}
|
}
|
||||||
|
|
||||||
IR_Decoder::IR_Decoder(const uint8_t isrPin, uint16_t addr, IR_Encoder *encPair)
|
IR_Decoder::IR_Decoder(const uint8_t pin, uint16_t addr, IR_Encoder *encPair)
|
||||||
: IR_DecoderRaw(isrPin, addr, encPair)
|
: IR_DecoderRaw(pin, addr, encPair)
|
||||||
{
|
{
|
||||||
get_dec_list().push_back(this);
|
get_dec_list().push_back(this);
|
||||||
};
|
};
|
||||||
|
@ -24,7 +24,7 @@ public:
|
|||||||
PacketTypes::Request gotRequest;
|
PacketTypes::Request gotRequest;
|
||||||
PacketTypes::BasePack gotRaw;
|
PacketTypes::BasePack gotRaw;
|
||||||
|
|
||||||
IR_Decoder(const uint8_t isrPin, uint16_t addr, IR_Encoder *encPair = nullptr);
|
IR_Decoder(const uint8_t pin, uint16_t addr, IR_Encoder *encPair = nullptr);
|
||||||
~IR_Decoder();
|
~IR_Decoder();
|
||||||
|
|
||||||
static void tick();
|
static void tick();
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
#include "IR_DecoderRaw.h"
|
#include "IR_DecoderRaw.h"
|
||||||
#include "IR_Encoder.h"
|
#include "IR_Encoder.h"
|
||||||
|
|
||||||
IR_DecoderRaw::IR_DecoderRaw(const uint8_t isrPin, uint16_t addr, IR_Encoder *encPair) : isrPin(isrPin), encoder(encPair)
|
IR_DecoderRaw::IR_DecoderRaw(const uint8_t pin, uint16_t addr, IR_Encoder *encPair) : encoder(encPair)
|
||||||
{
|
{
|
||||||
|
setPin(pin);
|
||||||
id = addr;
|
id = addr;
|
||||||
prevRise = prevFall = prevPrevFall = prevPrevRise = 0;
|
prevRise = prevFall = prevPrevFall = prevPrevRise = 0;
|
||||||
if (encPair != nullptr)
|
if (encPair != nullptr)
|
||||||
@ -46,6 +47,11 @@ volatile uint32_t time_;
|
|||||||
|
|
||||||
void IR_DecoderRaw::isr()
|
void IR_DecoderRaw::isr()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if(isPairSending){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
noInterrupts();
|
noInterrupts();
|
||||||
// time_ = HAL_GetTick() * 1000 + ((SysTick->LOAD + 1 - SysTick->VAL) * 1000) / SysTick->LOAD + 1;
|
// time_ = HAL_GetTick() * 1000 + ((SysTick->LOAD + 1 - SysTick->VAL) * 1000) / SysTick->LOAD + 1;
|
||||||
time_ = micros();
|
time_ = micros();
|
||||||
@ -68,7 +74,7 @@ void IR_DecoderRaw::isr()
|
|||||||
oldTime = time_;
|
oldTime = time_;
|
||||||
|
|
||||||
FrontStorage edge;
|
FrontStorage edge;
|
||||||
edge.dir = digitalRead(isrPin);
|
edge.dir = port->IDR & mask;
|
||||||
edge.time = time_;
|
edge.time = time_;
|
||||||
|
|
||||||
subBuffer.push(edge);
|
subBuffer.push(edge);
|
||||||
|
@ -35,14 +35,12 @@ protected:
|
|||||||
bool availableRaw();
|
bool availableRaw();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const uint8_t isrPin; // Пин прерывания
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief Конструктор
|
/// @brief Конструктор
|
||||||
/// @param isrPin Номер вывода прерывания/данных от приёмника (2 или 3 для atmega 328p)
|
/// @param pin Номер вывода прерывания/данных от приёмника (2 или 3 для atmega 328p)
|
||||||
/// @param addr Адрес приёмника
|
/// @param addr Адрес приёмника
|
||||||
/// @param encPair Указатель на передатчик, работающий в паре
|
/// @param encPair Указатель на передатчик, работающий в паре
|
||||||
IR_DecoderRaw(const uint8_t isrPin, uint16_t addr, IR_Encoder *encPair = nullptr);
|
IR_DecoderRaw(const uint8_t pin, uint16_t addr, IR_Encoder *encPair = nullptr);
|
||||||
|
|
||||||
void isr(); // Функция прерывания
|
void isr(); // Функция прерывания
|
||||||
void tick(); // Обработка приёмника, необходима для работы
|
void tick(); // Обработка приёмника, необходима для работы
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
#include "IR_config.h"
|
#include "IR_config.h"
|
||||||
|
|
||||||
|
void IR_FOX::setPin(uint8_t pin){
|
||||||
|
this->pin = pin;
|
||||||
|
port = digitalPinToPort(pin);
|
||||||
|
mask = digitalPinToBitMask(pin);
|
||||||
|
}
|
||||||
|
|
||||||
void IR_FOX::checkAddressRuleApply(uint16_t address, uint16_t id, bool &flag)
|
void IR_FOX::checkAddressRuleApply(uint16_t address, uint16_t id, bool &flag)
|
||||||
{
|
{
|
||||||
flag = false;
|
flag = false;
|
||||||
|
33
IR_config.h
33
IR_config.h
@ -6,7 +6,8 @@
|
|||||||
|
|
||||||
Для работы в паре положить декодер в энкодер
|
Для работы в паре положить декодер в энкодер
|
||||||
|
|
||||||
*/// Адресация с 1 до 65 499
|
*/
|
||||||
|
// Адресация с 1 до 65 499
|
||||||
#define IR_Broadcast 65000 // 65 500 ~ 65 535 - широковещательные пакеты (всем), возможно разделить на 35 типов
|
#define IR_Broadcast 65000 // 65 500 ~ 65 535 - широковещательные пакеты (всем), возможно разделить на 35 типов
|
||||||
/*
|
/*
|
||||||
Адрес 0 запрещен и зарезервирован под NULL, либо тесты
|
Адрес 0 запрещен и зарезервирован под NULL, либо тесты
|
||||||
@ -101,14 +102,14 @@ customByte - контрольная сумма принятых данных п
|
|||||||
/////////////////////////////////////////////////////////////////////////////////////*/
|
/////////////////////////////////////////////////////////////////////////////////////*/
|
||||||
typedef uint16_t crc_t;
|
typedef uint16_t crc_t;
|
||||||
|
|
||||||
#define BRUTEFORCE_CHECK // Перепроверяет пакет на 1 битные ошибки //TODO: зависает
|
// #define BRUTEFORCE_CHECK // Перепроверяет пакет на 1 битные ошибки //TODO: зависает
|
||||||
#define bytePerPack 16 // колличество байтов в пакете
|
#define bytePerPack 16 // колличество байтов в пакете
|
||||||
#ifndef freeFrec
|
#ifndef freeFrec
|
||||||
#define freeFrec false
|
#define freeFrec false
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef subBufferSize
|
#ifndef subBufferSize
|
||||||
#define subBufferSize 5 //Буфер для складирования фронтов, пока их не обработают (передатчик)
|
#define subBufferSize 50 // Буфер для складирования фронтов, пока их не обработают (передатчик)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define preambPulse 3
|
#define preambPulse 3
|
||||||
@ -141,12 +142,11 @@ typedef uint16_t crc_t;
|
|||||||
#define bitTime (bitTakts * carrierPeriod) // Общая длительность бита
|
#define bitTime (bitTakts * carrierPeriod) // Общая длительность бита
|
||||||
#define tolerance 300U
|
#define tolerance 300U
|
||||||
|
|
||||||
|
class IR_FOX
|
||||||
|
{
|
||||||
class IR_FOX {
|
|
||||||
public:
|
public:
|
||||||
|
struct PackOffsets
|
||||||
struct PackOffsets {
|
{
|
||||||
uint8_t msgOffset;
|
uint8_t msgOffset;
|
||||||
uint8_t addrFromOffset;
|
uint8_t addrFromOffset;
|
||||||
uint8_t addrToOffset;
|
uint8_t addrToOffset;
|
||||||
@ -154,21 +154,23 @@ public:
|
|||||||
uint8_t crcOffset;
|
uint8_t crcOffset;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ErrorsStruct {
|
struct ErrorsStruct
|
||||||
|
{
|
||||||
uint8_t lowSignal = 0;
|
uint8_t lowSignal = 0;
|
||||||
uint8_t highSignal = 0;
|
uint8_t highSignal = 0;
|
||||||
uint8_t other = 0;
|
uint8_t other = 0;
|
||||||
|
|
||||||
void reset() {
|
void reset()
|
||||||
|
{
|
||||||
lowSignal = 0;
|
lowSignal = 0;
|
||||||
highSignal = 0;
|
highSignal = 0;
|
||||||
other = 0;
|
other = 0;
|
||||||
}
|
}
|
||||||
uint16_t all() { return lowSignal + highSignal + other; }
|
uint16_t all() { return lowSignal + highSignal + other; }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PackInfo {
|
struct PackInfo
|
||||||
|
{
|
||||||
uint8_t *buffer = nullptr;
|
uint8_t *buffer = nullptr;
|
||||||
uint8_t packSize = 0;
|
uint8_t packSize = 0;
|
||||||
uint16_t crc = 0;
|
uint16_t crc = 0;
|
||||||
@ -176,14 +178,17 @@ public:
|
|||||||
uint16_t rTime = 0;
|
uint16_t rTime = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
inline uint16_t getId() { return id; }
|
inline uint16_t getId() { return id; }
|
||||||
inline void setId(uint16_t id) { this->id = id; }
|
inline void setId(uint16_t id) { this->id = id; }
|
||||||
static void checkAddressRuleApply(uint16_t address, uint16_t id, bool &flag);
|
static void checkAddressRuleApply(uint16_t address, uint16_t id, bool &flag);
|
||||||
|
void setPin(uint8_t pin);
|
||||||
|
inline uint8_t getPin(){return pin;};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint16_t id;
|
uint16_t id;
|
||||||
|
uint8_t pin;
|
||||||
|
GPIO_TypeDef *port;
|
||||||
|
uint16_t mask;
|
||||||
ErrorsStruct errors;
|
ErrorsStruct errors;
|
||||||
uint8_t crc8(uint8_t *data, uint8_t start, uint8_t end, uint8_t poly);
|
uint8_t crc8(uint8_t *data, uint8_t start, uint8_t end, uint8_t poly);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user