mirror of
https://github.com/Show-maket/IR-protocol.git
synced 2025-05-04 07:10:16 +00:00
multiBlind
This commit is contained in:
parent
1c79b812d3
commit
bfa978394f
@ -5,19 +5,24 @@
|
|||||||
#define ISR_Out 10
|
#define ISR_Out 10
|
||||||
#define TestOut 13
|
#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 };
|
// sendBuffer = new uint8_t[dataByteSizeMax] { 0 };
|
||||||
ir_out = pin;
|
ir_out = pin;
|
||||||
pinMode(ir_out, OUTPUT);
|
pinMode(ir_out, OUTPUT);
|
||||||
id = addr;
|
id = addr;
|
||||||
|
this->decPair = decPair;
|
||||||
decoders = (IR_Decoder*)decPair;
|
|
||||||
decodersCount = decPairCount;
|
|
||||||
|
|
||||||
|
|
||||||
signal = noSignal;
|
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() {
|
IR_Encoder::~IR_Encoder() {
|
||||||
delete [] bitHigh;
|
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] = crc8(sendBuffer, 0, packSize - crcBytes, poly1) & 0xFF;
|
||||||
sendBuffer[packSize - crcBytes + 1] = crc8(sendBuffer, 0, packSize - crcBytes + 1, poly2) & 0xFF;
|
sendBuffer[packSize - crcBytes + 1] = crc8(sendBuffer, 0, packSize - crcBytes + 1, poly2) & 0xFF;
|
||||||
|
|
||||||
if (decoders != nullptr) {
|
if (decPair != nullptr) {
|
||||||
decoders->isWaitingAccept = ((msgType >> 5) & IR_MASK_MSG_TYPE == IR_MSG_DATA_ACCEPT);
|
decPair->isWaitingAccept = ((msgType >> 5) & IR_MASK_MSG_TYPE == IR_MSG_DATA_ACCEPT);
|
||||||
decoders->addrWaitingFrom = addrTo;
|
if (decPair->isWaitingAccept) {
|
||||||
|
decPair->addrWaitingFrom = addrTo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// отправка
|
// отправка
|
||||||
rawSend(sendBuffer, packSize);
|
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() {
|
void IR_Encoder::setDecoder_isSending() {
|
||||||
if (decodersCount && decoders != nullptr) {
|
if (decodersCount) {
|
||||||
for (uint8_t i = 0; i < decodersCount; i++) {
|
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;
|
sendLen = len;
|
||||||
|
|
||||||
isSending = true;
|
setDecoder_isSending();
|
||||||
// setDecoder_isSending();
|
Serial.println("^");
|
||||||
decoders->isPairSending ^= id;
|
|
||||||
|
|
||||||
cli();
|
cli();
|
||||||
toggleCounter = preambToggle; // Первая генерация для первого signal
|
toggleCounter = preambToggle; // Первая генерация для первого signal
|
||||||
@ -143,6 +149,7 @@ void IR_Encoder::rawSend(uint8_t* ptr, uint8_t len) {
|
|||||||
state = HIGH;
|
state = HIGH;
|
||||||
|
|
||||||
currentBitSequence = bitHigh;
|
currentBitSequence = bitHigh;
|
||||||
|
isSending = true;
|
||||||
sei();
|
sei();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,8 +170,8 @@ void IR_Encoder::isr() {
|
|||||||
// сброс счетчиков
|
// сброс счетчиков
|
||||||
// ...
|
// ...
|
||||||
isSending = false;
|
isSending = false;
|
||||||
// setDecoder_isSending();
|
setDecoder_isSending();
|
||||||
decoders->isPairSending ^= id;
|
Serial.println("^^^");
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -21,8 +21,9 @@ public:
|
|||||||
/// @param pin Вывод передатчика
|
/// @param pin Вывод передатчика
|
||||||
/// @param tune Подстройка несущей частоты
|
/// @param tune Подстройка несущей частоты
|
||||||
/// @param decPair Приёмник, для которого отключается приём в момент передачи передатчиком
|
/// @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>
|
template<typename T>
|
||||||
void sendData(uint16_t addrTo, T& data, bool needAccept = false);
|
void sendData(uint16_t addrTo, T& data, bool needAccept = false);
|
||||||
void sendData(uint16_t addrTo, uint8_t* data, uint8_t len, bool needAccept = false);
|
void sendData(uint16_t addrTo, uint8_t* data, uint8_t len, bool needAccept = false);
|
||||||
@ -49,13 +50,14 @@ private:
|
|||||||
sync = 3
|
sync = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
IR_Decoder* decoders;
|
IR_Decoder* decPair;
|
||||||
|
IR_Decoder** blindDecoders;
|
||||||
uint8_t decodersCount;
|
uint8_t decodersCount;
|
||||||
|
|
||||||
uint8_t sendLen;
|
uint8_t sendLen;
|
||||||
uint8_t sendBuffer[dataByteSizeMax] { 0 }; /// @brief Буффер данных для отправки
|
uint8_t sendBuffer[dataByteSizeMax] { 0 }; /// @brief Буффер данных для отправки
|
||||||
|
|
||||||
volatile bool isSending = false;
|
volatile bool isSending;
|
||||||
volatile bool state; /// @brief Текущий уровень генерации
|
volatile bool state; /// @brief Текущий уровень генерации
|
||||||
|
|
||||||
volatile uint8_t dataByteCounter;
|
volatile uint8_t dataByteCounter;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user