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);
|
||||
|
Reference in New Issue
Block a user