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() {};
|
||||||
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)
|
: IR_DecoderRaw(pin, addr, encPair)
|
||||||
{
|
{
|
||||||
get_dec_list().push_back(this);
|
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()()
|
std::function<void()> IR_Decoder::operator()()
|
||||||
{
|
{
|
||||||
return std::bind(&IR_Decoder::isr, this);
|
return std::bind(&IR_Decoder::isr, this);
|
||||||
|
@ -25,10 +25,13 @@ public:
|
|||||||
PacketTypes::BasePack gotRaw;
|
PacketTypes::BasePack gotRaw;
|
||||||
|
|
||||||
// IR_Decoder();
|
// 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()();
|
std::function<void()> operator()();
|
||||||
|
|
||||||
|
void enable();
|
||||||
|
void disable();
|
||||||
|
|
||||||
~IR_Decoder();
|
~IR_Decoder();
|
||||||
|
|
||||||
static void tick();
|
static void tick();
|
||||||
|
@ -11,8 +11,7 @@ std::list<IR_Encoder*>& IR_Encoder::get_enc_list() // определение ф
|
|||||||
return dec_list; // возвращается ссылка на переменную
|
return dec_list; // возвращается ссылка на переменную
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IR_Encoder::IR_Encoder(uint8_t pin, uint16_t addr, IR_DecoderRaw *decPair, bool autoHandle)
|
||||||
IR_Encoder::IR_Encoder(uint8_t pin, uint16_t addr, IR_DecoderRaw *decPair)
|
|
||||||
{
|
{
|
||||||
setPin(pin);
|
setPin(pin);
|
||||||
id = addr;
|
id = addr;
|
||||||
@ -22,8 +21,7 @@ IR_Encoder::IR_Encoder(uint8_t pin, uint16_t addr, IR_DecoderRaw *decPair)
|
|||||||
#if disablePairDec
|
#if disablePairDec
|
||||||
if (decPair != nullptr)
|
if (decPair != nullptr)
|
||||||
{
|
{
|
||||||
blindDecoders = new IR_DecoderRaw *[1]
|
blindDecoders = new IR_DecoderRaw *[1]{decPair};
|
||||||
{ decPair };
|
|
||||||
decodersCount = 1;
|
decodersCount = 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -32,9 +30,32 @@ IR_Encoder::IR_Encoder(uint8_t pin, uint16_t addr, IR_DecoderRaw *decPair)
|
|||||||
decPair->encoder = this;
|
decPair->encoder = this;
|
||||||
}
|
}
|
||||||
pinMode(pin, OUTPUT);
|
pinMode(pin, OUTPUT);
|
||||||
|
|
||||||
|
if (autoHandle)
|
||||||
|
{
|
||||||
get_enc_list().push_back(this);
|
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)
|
void IR_Encoder::setBlindDecoders(IR_DecoderRaw *decoders[], uint8_t count)
|
||||||
{
|
{
|
||||||
#if disablePairDec
|
#if disablePairDec
|
||||||
@ -238,9 +259,11 @@ void IR_Encoder::rawSend(uint8_t *ptr, uint8_t len)
|
|||||||
// interrupts();
|
// interrupts();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IR_Encoder::isr(){
|
void IR_Encoder::isr()
|
||||||
|
{
|
||||||
// Serial.println(get_enc_list().size());
|
// Serial.println(get_enc_list().size());
|
||||||
for(const auto &element : get_enc_list()){
|
for (const auto &element : get_enc_list())
|
||||||
|
{
|
||||||
element->_isr();
|
element->_isr();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -255,7 +278,6 @@ void IR_Encoder::_isr()
|
|||||||
port->ODR &= ~(mask);
|
port->ODR &= ~(mask);
|
||||||
port->ODR |= mask & (ir_out_virtual ? (uint16_t)0xFFFF : (uint16_t)0x0000);
|
port->ODR |= mask & (ir_out_virtual ? (uint16_t)0xFFFF : (uint16_t)0x0000);
|
||||||
|
|
||||||
|
|
||||||
if (toggleCounter)
|
if (toggleCounter)
|
||||||
{
|
{
|
||||||
toggleCounter--;
|
toggleCounter--;
|
||||||
|
@ -16,9 +16,12 @@ public:
|
|||||||
/// @param addr Адрес передатчика
|
/// @param addr Адрес передатчика
|
||||||
/// @param pin Вывод передатчика
|
/// @param pin Вывод передатчика
|
||||||
/// @param decPair Приёмник, для которого отключается приём в момент передачи передатчиком
|
/// @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();
|
static void isr();
|
||||||
|
|
||||||
|
void enable();
|
||||||
|
void disable();
|
||||||
|
|
||||||
void setBlindDecoders(IR_DecoderRaw *decoders[], uint8_t count);
|
void setBlindDecoders(IR_DecoderRaw *decoders[], uint8_t count);
|
||||||
void rawSend(uint8_t *ptr, uint8_t len);
|
void rawSend(uint8_t *ptr, uint8_t len);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user