diff --git a/IR_Decoder.cpp b/IR_Decoder.cpp index 0bb2711..41afe3c 100644 --- a/IR_Decoder.cpp +++ b/IR_Decoder.cpp @@ -1,19 +1,22 @@ #include "IR_Decoder.h" -std::list& IR_Decoder::get_dec_list() // определение функции +std::list &IR_Decoder::get_dec_list() // определение функции { - static std::list dec_list; // статическая локальная переменная - return dec_list; // возвращается ссылка на переменную + static std::list dec_list; // статическая локальная переменная + return 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_DecoderRaw(pin, addr, encPair) { get_dec_list().push_back(this); }; -void IR_Decoder::operator()() { isr(); } +std::function IR_Decoder::operator()() +{ + return std::bind(&IR_Decoder::isr, this); +} IR_Decoder::~IR_Decoder() { diff --git a/IR_Decoder.h b/IR_Decoder.h index 60c40cc..bdd9df3 100644 --- a/IR_Decoder.h +++ b/IR_Decoder.h @@ -24,10 +24,10 @@ public: PacketTypes::Request gotRequest; PacketTypes::BasePack gotRaw; - IR_Decoder(); + // IR_Decoder(); IR_Decoder(const uint8_t pin, uint16_t addr, IR_Encoder *encPair = nullptr); - void operator()() ; + std::function operator()(); ~IR_Decoder(); diff --git a/IR_DecoderRaw.cpp b/IR_DecoderRaw.cpp index c38f964..c0ee268 100644 --- a/IR_DecoderRaw.cpp +++ b/IR_DecoderRaw.cpp @@ -1,7 +1,6 @@ #include "IR_DecoderRaw.h" #include "IR_Encoder.h" -IR_DecoderRaw::IR_DecoderRaw(){}; IR_DecoderRaw::IR_DecoderRaw(const uint8_t pin, uint16_t addr, IR_Encoder *encPair) : encoder(encPair) { setPin(pin); @@ -651,3 +650,179 @@ inline void IR_DecoderRaw::infoPulse(uint8_t pin, uint8_t count) } } #endif + +// Конструктор копирования + IR_DecoderRaw::IR_DecoderRaw(const IR_DecoderRaw& other) + : packInfo(other.packInfo), + encoder(other.encoder), // Если IR_Encoder имеет безопасный копируемый указатель + isAvailable(other.isAvailable), + packSize(other.packSize), + crcValue(other.crcValue), + isPairSending(other.isPairSending), + isRecive(other.isRecive), + isPreamb(other.isPreamb), + isSubBufferOverflow(other.isSubBufferOverflow), + isBufferOverflow(other.isBufferOverflow), + isWrongPack(other.isWrongPack), + riseSyncTime(other.riseSyncTime), + currentSubBufferIndex(other.currentSubBufferIndex), + subBuffer(other.subBuffer), // Копирование буфера + lastFront(other.lastFront), + firstUnHandledFront(other.firstUnHandledFront), + prevRise(other.prevRise), + prevPrevRise(other.prevPrevRise), + prevFall(other.prevFall), + prevPrevFall(other.prevPrevFall), + risePeriod(other.risePeriod), + highTime(other.highTime), + lowTime(other.lowTime), + oldTime(other.oldTime), + wrongCounter(other.wrongCounter), + highCount(other.highCount), + lowCount(other.lowCount), + allCount(other.allCount), + errorCounter(other.errorCounter), + preambFrontCounter(other.preambFrontCounter), + bufBitPos(other.bufBitPos), + isData(other.isData), + i_dataBuffer(other.i_dataBuffer), + nextControlBit(other.nextControlBit), + i_syncBit(other.i_syncBit), + err_syncBit(other.err_syncBit) + { + // Специфическое копирование, если нужно + } + + // Оператор копирующего присваивания + IR_DecoderRaw& IR_DecoderRaw::operator=(const IR_DecoderRaw& other) { + if (this != &other) { // Проверка на самоприсваивание + packInfo = other.packInfo; + encoder = other.encoder; + isAvailable = other.isAvailable; + packSize = other.packSize; + crcValue = other.crcValue; + isPairSending = other.isPairSending; + isRecive = other.isRecive; + isPreamb = other.isPreamb; + isSubBufferOverflow = other.isSubBufferOverflow; + isBufferOverflow = other.isBufferOverflow; + isWrongPack = other.isWrongPack; + riseSyncTime = other.riseSyncTime; + currentSubBufferIndex = other.currentSubBufferIndex; + subBuffer = other.subBuffer; + lastFront = other.lastFront; + firstUnHandledFront = other.firstUnHandledFront; + prevRise = other.prevRise; + prevPrevRise = other.prevPrevRise; + prevFall = other.prevFall; + prevPrevFall = other.prevPrevFall; + risePeriod = other.risePeriod; + highTime = other.highTime; + lowTime = other.lowTime; + oldTime = other.oldTime; + wrongCounter = other.wrongCounter; + highCount = other.highCount; + lowCount = other.lowCount; + allCount = other.allCount; + errorCounter = other.errorCounter; + preambFrontCounter = other.preambFrontCounter; + bufBitPos = other.bufBitPos; + isData = other.isData; + i_dataBuffer = other.i_dataBuffer; + nextControlBit = other.nextControlBit; + i_syncBit = other.i_syncBit; + err_syncBit = other.err_syncBit; + } + return *this; + } + + // Конструктор перемещения + IR_DecoderRaw::IR_DecoderRaw(IR_DecoderRaw&& other) + : packInfo(std::move(other.packInfo)), + encoder(other.encoder), + isAvailable(other.isAvailable), + packSize(other.packSize), + crcValue(other.crcValue), + isPairSending(other.isPairSending), + isRecive(other.isRecive), + isPreamb(other.isPreamb), + isSubBufferOverflow(other.isSubBufferOverflow), + isBufferOverflow(other.isBufferOverflow), + isWrongPack(other.isWrongPack), + riseSyncTime(other.riseSyncTime), + currentSubBufferIndex(other.currentSubBufferIndex), + subBuffer(std::move(other.subBuffer)), + lastFront(other.lastFront), + firstUnHandledFront(other.firstUnHandledFront), + prevRise(other.prevRise), + prevPrevRise(other.prevPrevRise), + prevFall(other.prevFall), + prevPrevFall(other.prevPrevFall), + risePeriod(other.risePeriod), + highTime(other.highTime), + lowTime(other.lowTime), + oldTime(other.oldTime), + wrongCounter(other.wrongCounter), + highCount(other.highCount), + lowCount(other.lowCount), + allCount(other.allCount), + errorCounter(other.errorCounter), + preambFrontCounter(other.preambFrontCounter), + bufBitPos(other.bufBitPos), + isData(other.isData), + i_dataBuffer(other.i_dataBuffer), + nextControlBit(other.nextControlBit), + i_syncBit(other.i_syncBit), + err_syncBit(other.err_syncBit) + { + other.encoder = nullptr; + other.lastFront = nullptr; + other.firstUnHandledFront = nullptr; + } + + // Оператор перемещающего присваивания + IR_DecoderRaw& IR_DecoderRaw::operator=(IR_DecoderRaw&& other) { + if (this != &other) { // Проверка на самоприсваивание + packInfo = std::move(other.packInfo); + encoder = other.encoder; + isAvailable = other.isAvailable; + packSize = other.packSize; + crcValue = other.crcValue; + isPairSending = other.isPairSending; + isRecive = other.isRecive; + isPreamb = other.isPreamb; + isSubBufferOverflow = other.isSubBufferOverflow; + isBufferOverflow = other.isBufferOverflow; + isWrongPack = other.isWrongPack; + riseSyncTime = other.riseSyncTime; + currentSubBufferIndex = other.currentSubBufferIndex; + subBuffer = std::move(other.subBuffer); + lastFront = other.lastFront; + firstUnHandledFront = other.firstUnHandledFront; + prevRise = other.prevRise; + prevPrevRise = other.prevPrevRise; + prevFall = other.prevFall; + prevPrevFall = other.prevPrevFall; + risePeriod = other.risePeriod; + highTime = other.highTime; + lowTime = other.lowTime; + oldTime = other.oldTime; + wrongCounter = other.wrongCounter; + highCount = other.highCount; + lowCount = other.lowCount; + allCount = other.allCount; + errorCounter = other.errorCounter; + preambFrontCounter = other.preambFrontCounter; + bufBitPos = other.bufBitPos; + isData = other.isData; + i_dataBuffer = other.i_dataBuffer; + nextControlBit = other.nextControlBit; + i_syncBit = other.i_syncBit; + err_syncBit = other.err_syncBit; + + other.encoder = nullptr; + other.lastFront = nullptr; + other.firstUnHandledFront = nullptr; + } + return *this; + } diff --git a/IR_DecoderRaw.h b/IR_DecoderRaw.h index 832df7f..90929e1 100644 --- a/IR_DecoderRaw.h +++ b/IR_DecoderRaw.h @@ -36,7 +36,6 @@ protected: public: ////////////////////////////////////////////////////////////////////////// - IR_DecoderRaw(); /// @brief Конструктор /// @param pin Номер вывода прерывания/данных от приёмника (2 или 3 для atmega 328p) /// @param addr Адрес приёмника @@ -133,4 +132,4 @@ private: inline void errPulse(uint8_t pin, uint8_t count); inline void infoPulse(uint8_t pin, uint8_t count); #endif -}; \ No newline at end of file +}; diff --git a/IR_Encoder.cpp b/IR_Encoder.cpp index 8464a46..aec0744 100644 --- a/IR_Encoder.cpp +++ b/IR_Encoder.cpp @@ -11,7 +11,6 @@ std::list& IR_Encoder::get_enc_list() // определение ф return dec_list; // возвращается ссылка на переменную } -IR_Encoder::IR_Encoder(){}; IR_Encoder::IR_Encoder(uint8_t pin, uint16_t addr, IR_DecoderRaw *decPair) { @@ -404,4 +403,4 @@ uint8_t IR_Encoder::bitLow[2] = { // (bitActiveTakts) * 2 - 0}; // uint8_t* IR_Encoder::bitLow = new uint8_t[2]{ // (bitPauseTakts/2 + bitActiveTakts) * 2 - 0, -// (bitPauseTakts) - 0}; \ No newline at end of file +// (bitPauseTakts) - 0}; diff --git a/IR_Encoder.h b/IR_Encoder.h index f6a26c2..b312415 100644 --- a/IR_Encoder.h +++ b/IR_Encoder.h @@ -12,7 +12,6 @@ public: private: uint16_t id; /// @brief Адрес передатчика public: - IR_Encoder(); /// @brief Класс передатчика /// @param addr Адрес передатчика /// @param pin Вывод передатчика