multiBlind

This commit is contained in:
DashyFox 2024-02-12 18:00:21 +03:00
parent 1c79b812d3
commit bfa978394f
2 changed files with 28 additions and 19 deletions

View File

@ -5,19 +5,24 @@
#define ISR_Out 10
#define TestOut 13
IR_Encoder::IR_Encoder(uint16_t addr, uint8_t pin, uint8_t decPairCount = 0, void* decPair = nullptr) {
IR_Encoder::IR_Encoder(uint16_t addr, uint8_t pin, IR_Decoder* decPair = nullptr) {
// sendBuffer = new uint8_t[dataByteSizeMax] { 0 };
ir_out = pin;
pinMode(ir_out, OUTPUT);
id = addr;
decoders = (IR_Decoder*)decPair;
decodersCount = decPairCount;
this->decPair = decPair;
signal = noSignal;
isSending = false;
if(decPair != nullptr){
// blindDecoders = &decPair;/////////////////////////////////////////////////////////TODO:
// decodersCount = 1;
}
};
void IR_Encoder::setBlindDecoders(IR_Decoder* decoders[], uint8_t count){
decodersCount = count;
blindDecoders = decoders;
}
IR_Encoder::~IR_Encoder() {
delete [] bitHigh;
@ -96,9 +101,11 @@ void IR_Encoder::_sendData(uint16_t addrTo, uint8_t* data, uint8_t len, uint8_t
sendBuffer[packSize - crcBytes] = crc8(sendBuffer, 0, packSize - crcBytes, poly1) & 0xFF;
sendBuffer[packSize - crcBytes + 1] = crc8(sendBuffer, 0, packSize - crcBytes + 1, poly2) & 0xFF;
if (decoders != nullptr) {
decoders->isWaitingAccept = ((msgType >> 5) & IR_MASK_MSG_TYPE == IR_MSG_DATA_ACCEPT);
decoders->addrWaitingFrom = addrTo;
if (decPair != nullptr) {
decPair->isWaitingAccept = ((msgType >> 5) & IR_MASK_MSG_TYPE == IR_MSG_DATA_ACCEPT);
if (decPair->isWaitingAccept) {
decPair->addrWaitingFrom = addrTo;
}
}
// отправка
rawSend(sendBuffer, packSize);
@ -106,9 +113,9 @@ void IR_Encoder::_sendData(uint16_t addrTo, uint8_t* data, uint8_t len, uint8_t
}
void IR_Encoder::setDecoder_isSending() {
if (decodersCount && decoders != nullptr) {
if (decodersCount) {
for (uint8_t i = 0; i < decodersCount; i++) {
(decoders + i)->isPairSending ^= id;
blindDecoders[i]->isPairSending ^= id;
}
}
@ -124,9 +131,8 @@ void IR_Encoder::rawSend(uint8_t* ptr, uint8_t len) {
sendLen = len;
isSending = true;
// setDecoder_isSending();
decoders->isPairSending ^= id;
setDecoder_isSending();
Serial.println("^");
cli();
toggleCounter = preambToggle; // Первая генерация для первого signal
@ -143,6 +149,7 @@ void IR_Encoder::rawSend(uint8_t* ptr, uint8_t len) {
state = HIGH;
currentBitSequence = bitHigh;
isSending = true;
sei();
}
@ -163,8 +170,8 @@ void IR_Encoder::isr() {
// сброс счетчиков
// ...
isSending = false;
// setDecoder_isSending();
decoders->isPairSending ^= id;
setDecoder_isSending();
Serial.println("^^^");
return;
break;

View File

@ -21,8 +21,9 @@ public:
/// @param pin Вывод передатчика
/// @param tune Подстройка несущей частоты
/// @param decPair Приёмник, для которого отключается приём в момент передачи передатчиком
IR_Encoder(uint16_t addr, uint8_t pin, uint8_t decPairCount = 0, void* decPair = nullptr);
IR_Encoder(uint16_t addr, uint8_t pin, IR_Decoder* decPair = nullptr);
void IR_Encoder::setBlindDecoders(IR_Decoder* decoders[], uint8_t count);
template<typename T>
void sendData(uint16_t addrTo, T& data, bool needAccept = false);
void sendData(uint16_t addrTo, uint8_t* data, uint8_t len, bool needAccept = false);
@ -49,13 +50,14 @@ private:
sync = 3
};
IR_Decoder* decoders;
IR_Decoder* decPair;
IR_Decoder** blindDecoders;
uint8_t decodersCount;
uint8_t sendLen;
uint8_t sendBuffer[dataByteSizeMax] { 0 }; /// @brief Буффер данных для отправки
volatile bool isSending = false;
volatile bool isSending;
volatile bool state; /// @brief Текущий уровень генерации
volatile uint8_t dataByteCounter;