mirror of
https://github.com/Show-maket/IR-protocol.git
synced 2025-06-27 20:59:37 +00:00
enable-disable func
This commit is contained in:
@ -7,12 +7,37 @@ std::list<IR_Decoder *> &IR_Decoder::get_dec_list() // определение ф
|
||||
}
|
||||
|
||||
// IR_Decoder::IR_Decoder() {};
|
||||
IR_Decoder::IR_Decoder(const uint8_t pin, uint16_t addr, IR_Encoder *encPair)
|
||||
IR_Decoder::IR_Decoder(const uint8_t pin, uint16_t addr, IR_Encoder *encPair, bool autoHandle)
|
||||
: IR_DecoderRaw(pin, addr, encPair)
|
||||
{
|
||||
get_dec_list().push_back(this);
|
||||
if(autoHandle){
|
||||
enable();
|
||||
}
|
||||
};
|
||||
|
||||
void IR_Decoder::enable()
|
||||
{
|
||||
auto &dec_list = get_dec_list();
|
||||
if (std::find(dec_list.begin(), dec_list.end(), this) == dec_list.end())
|
||||
{
|
||||
dec_list.push_back(this);
|
||||
}
|
||||
attachInterrupt(pin, (*this)(), CHANGE);
|
||||
}
|
||||
|
||||
void IR_Decoder::disable()
|
||||
{
|
||||
detachInterrupt(pin);
|
||||
auto &dec_list = get_dec_list();
|
||||
auto it = std::find(dec_list.begin(), dec_list.end(), this);
|
||||
if (it != dec_list.end())
|
||||
{
|
||||
dec_list.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::function<void()> IR_Decoder::operator()()
|
||||
{
|
||||
return std::bind(&IR_Decoder::isr, this);
|
||||
|
@ -25,10 +25,13 @@ public:
|
||||
PacketTypes::BasePack gotRaw;
|
||||
|
||||
// IR_Decoder();
|
||||
IR_Decoder(const uint8_t pin, uint16_t addr, IR_Encoder *encPair = nullptr);
|
||||
IR_Decoder(const uint8_t pin, uint16_t addr, IR_Encoder *encPair = nullptr, bool autoHandle = true);
|
||||
|
||||
std::function<void()> operator()();
|
||||
|
||||
void enable();
|
||||
void disable();
|
||||
|
||||
~IR_Decoder();
|
||||
|
||||
static void tick();
|
||||
|
@ -5,14 +5,13 @@
|
||||
#define ISR_Out 10
|
||||
#define TestOut 13
|
||||
|
||||
std::list<IR_Encoder*>& IR_Encoder::get_enc_list() // определение функции
|
||||
std::list<IR_Encoder *> &IR_Encoder::get_enc_list() // определение функции
|
||||
{
|
||||
static std::list<IR_Encoder*> dec_list; // статическая локальная переменная
|
||||
return dec_list; // возвращается ссылка на переменную
|
||||
static std::list<IR_Encoder *> dec_list; // статическая локальная переменная
|
||||
return dec_list; // возвращается ссылка на переменную
|
||||
}
|
||||
|
||||
|
||||
IR_Encoder::IR_Encoder(uint8_t pin, uint16_t addr, IR_DecoderRaw *decPair)
|
||||
IR_Encoder::IR_Encoder(uint8_t pin, uint16_t addr, IR_DecoderRaw *decPair, bool autoHandle)
|
||||
{
|
||||
setPin(pin);
|
||||
id = addr;
|
||||
@ -22,8 +21,7 @@ IR_Encoder::IR_Encoder(uint8_t pin, uint16_t addr, IR_DecoderRaw *decPair)
|
||||
#if disablePairDec
|
||||
if (decPair != nullptr)
|
||||
{
|
||||
blindDecoders = new IR_DecoderRaw *[1]
|
||||
{ decPair };
|
||||
blindDecoders = new IR_DecoderRaw *[1]{decPair};
|
||||
decodersCount = 1;
|
||||
}
|
||||
#endif
|
||||
@ -31,10 +29,33 @@ IR_Encoder::IR_Encoder(uint8_t pin, uint16_t addr, IR_DecoderRaw *decPair)
|
||||
{
|
||||
decPair->encoder = this;
|
||||
}
|
||||
pinMode(pin,OUTPUT);
|
||||
get_enc_list().push_back(this);
|
||||
pinMode(pin, OUTPUT);
|
||||
|
||||
if (autoHandle)
|
||||
{
|
||||
get_enc_list().push_back(this);
|
||||
}
|
||||
};
|
||||
|
||||
void IR_Encoder::enable()
|
||||
{
|
||||
auto &enc_list = get_enc_list();
|
||||
if (std::find(enc_list.begin(), enc_list.end(), this) == enc_list.end())
|
||||
{
|
||||
enc_list.push_back(this);
|
||||
}
|
||||
}
|
||||
|
||||
void IR_Encoder::disable()
|
||||
{
|
||||
auto &enc_list = get_enc_list();
|
||||
auto it = std::find(enc_list.begin(), enc_list.end(), this);
|
||||
if (it != enc_list.end())
|
||||
{
|
||||
enc_list.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
void IR_Encoder::setBlindDecoders(IR_DecoderRaw *decoders[], uint8_t count)
|
||||
{
|
||||
#if disablePairDec
|
||||
@ -149,7 +170,7 @@ void IR_Encoder::sendBack(uint8_t data)
|
||||
_sendBack(false, 0, &data, 1);
|
||||
}
|
||||
|
||||
void IR_Encoder::sendBack(uint8_t *data , uint8_t len)
|
||||
void IR_Encoder::sendBack(uint8_t *data, uint8_t len)
|
||||
{
|
||||
_sendBack(false, 0, data, len);
|
||||
}
|
||||
@ -238,9 +259,11 @@ void IR_Encoder::rawSend(uint8_t *ptr, uint8_t len)
|
||||
// interrupts();
|
||||
}
|
||||
|
||||
void IR_Encoder::isr(){
|
||||
void IR_Encoder::isr()
|
||||
{
|
||||
// Serial.println(get_enc_list().size());
|
||||
for(const auto &element : get_enc_list()){
|
||||
for (const auto &element : get_enc_list())
|
||||
{
|
||||
element->_isr();
|
||||
}
|
||||
}
|
||||
@ -254,7 +277,6 @@ void IR_Encoder::_isr()
|
||||
|
||||
port->ODR &= ~(mask);
|
||||
port->ODR |= mask & (ir_out_virtual ? (uint16_t)0xFFFF : (uint16_t)0x0000);
|
||||
|
||||
|
||||
if (toggleCounter)
|
||||
{
|
||||
@ -389,11 +411,11 @@ void IR_Encoder::addSync(bool *prev, bool *next)
|
||||
}
|
||||
|
||||
uint8_t IR_Encoder::bitHigh[2] = {
|
||||
(bitPauseTakts) * 2 - 1,
|
||||
(bitActiveTakts) * 2 - 1};
|
||||
(bitPauseTakts) * 2 - 1,
|
||||
(bitActiveTakts) * 2 - 1};
|
||||
uint8_t IR_Encoder::bitLow[2] = {
|
||||
(bitPauseTakts/2 + bitActiveTakts) * 2 - 1,
|
||||
(bitPauseTakts) - 1};
|
||||
(bitPauseTakts / 2 + bitActiveTakts) * 2 - 1,
|
||||
(bitPauseTakts)-1};
|
||||
|
||||
// uint8_t* IR_Encoder::bitHigh = new uint8_t[2]{
|
||||
// (bitPauseTakts) * 2 - 0,
|
||||
|
@ -16,9 +16,12 @@ public:
|
||||
/// @param addr Адрес передатчика
|
||||
/// @param pin Вывод передатчика
|
||||
/// @param decPair Приёмник, для которого отключается приём в момент передачи передатчиком
|
||||
IR_Encoder(uint8_t pin, uint16_t addr, IR_DecoderRaw *decPair = nullptr);
|
||||
IR_Encoder(uint8_t pin, uint16_t addr, IR_DecoderRaw *decPair = nullptr, bool autoHandle = true);
|
||||
static void isr();
|
||||
|
||||
void enable();
|
||||
void disable();
|
||||
|
||||
void setBlindDecoders(IR_DecoderRaw *decoders[], uint8_t count);
|
||||
void rawSend(uint8_t *ptr, uint8_t len);
|
||||
|
||||
|
Reference in New Issue
Block a user