testMultiBlind

This commit is contained in:
2024-02-12 16:41:16 +03:00
parent 9d315c8f23
commit 1c79b812d3
5 changed files with 56 additions and 61 deletions

View File

@ -5,15 +5,16 @@
#define ISR_Out 10
#define TestOut 13
IR_Encoder::IR_Encoder(uint16_t addr, uint8_t pin, uint8_t tune = 0, IR_Decoder* decPair) {
IR_Encoder::IR_Encoder(uint16_t addr, uint8_t pin, uint8_t decPairCount = 0, void* decPair = nullptr) {
// sendBuffer = new uint8_t[dataByteSizeMax] { 0 };
ir_out = pin;
pinMode(ir_out, OUTPUT);
addrSelf = addr;
decoder = decPair;
carrierTune = tune;
halfPeriod = (carrierPeriod / 2) - carrierTune;
dataBitCounter = 0 - preambFronts;
id = addr;
decoders = (IR_Decoder*)decPair;
decodersCount = decPairCount;
signal = noSignal;
};
@ -24,7 +25,7 @@ IR_Encoder::~IR_Encoder() {
// delete [] sendBuffer;
};
void IR_Encoder::sendData(uint16_t addrTo, uint8_t* data, uint8_t len, bool needAccept = false) {
void IR_Encoder::sendData(uint16_t addrTo, uint8_t* data, uint8_t len, bool needAccept = false) {
uint8_t packSize = msgBytes + addrBytes + addrBytes + len + crcBytes;
uint8_t msgType =
((needAccept ? IR_MSG_DATA_ACCEPT : IR_MSG_DATA_NOACCEPT) << 5) | ((packSize - crcBytes) & IR_MASK_MSG_INFO);
@ -38,8 +39,8 @@ void IR_Encoder::sendACK(uint16_t addrTo, uint8_t addInfo, bool forAll = false)
// addr_self
if (!forAll) {
sendBuffer[1] = addrSelf >> 8 & 0xFF;
sendBuffer[2] = addrSelf & 0xFF;
sendBuffer[1] = id >> 8 & 0xFF;
sendBuffer[2] = id & 0xFF;
}
// data crc
@ -55,8 +56,8 @@ void IR_Encoder::sendRequest(uint16_t addrTo, uint8_t addInfo) {
sendBuffer[0] |= addInfo & IR_MASK_MSG_INFO;
// addr_self
sendBuffer[1] = addrSelf >> 8 & 0xFF;
sendBuffer[2] = addrSelf & 0xFF;
sendBuffer[1] = id >> 8 & 0xFF;
sendBuffer[2] = id & 0xFF;
//addr_to
sendBuffer[3] = addrTo >> 8 & 0xFF;
@ -80,8 +81,8 @@ void IR_Encoder::_sendData(uint16_t addrTo, uint8_t* data, uint8_t len, uint8_t
sendBuffer[0] = msgType;
// addr_self
sendBuffer[1] = addrSelf >> 8 & 0xFF;
sendBuffer[2] = addrSelf & 0xFF;
sendBuffer[1] = id >> 8 & 0xFF;
sendBuffer[2] = id & 0xFF;
// addr_to
sendBuffer[3] = addrTo >> 8 & 0xFF;
@ -95,33 +96,39 @@ 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 (decoder != nullptr) {
decoder->isWaitingAccept = ((msgType >> 5) & IR_MASK_MSG_TYPE == IR_MSG_DATA_ACCEPT);
decoder->addrWaitingFrom = addrTo;
if (decoders != nullptr) {
decoders->isWaitingAccept = ((msgType >> 5) & IR_MASK_MSG_TYPE == IR_MSG_DATA_ACCEPT);
decoders->addrWaitingFrom = addrTo;
}
// отправка
rawSend(sendBuffer, packSize);
}
void IR_Encoder::setDecoder_isSending() {
if (decodersCount && decoders != nullptr) {
for (uint8_t i = 0; i < decodersCount; i++) {
(decoders + i)->isPairSending ^= id;
}
}
}
void IR_Encoder::rawSend(uint8_t* ptr, uint8_t len) {
if(isSending){
if (isSending) {
//TODO: Обработка повторной отправки
return;
}
digitalToggle(9); digitalToggle(9);
// memset(sendBuffer, 0x00, dataByteSizeMax);
// memcpy(sendBuffer, ptr, len);
sendLen = len;
// *sendBuffer = 0b10010011;
isSending = true;
// setDecoder_isSending();
decoders->isPairSending ^= id;
cli();
if (decoder != nullptr) { decoder->isPairSending = isSending; }
// #define preambToggle 2*2-1 //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#define preambToggle ((bitPauseTakts * 2 + bitActiveTakts) * 2 - 1) //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
toggleCounter = preambToggle; // Первая генерация для первого signal
dataBitCounter = bitPerByte - 1;
@ -152,9 +159,12 @@ void IR_Encoder::isr() {
IsrStart:
switch (signal) {
case noSignal:
signal = preamb;
// сброс счетчиков
// ...
isSending = false;
// setDecoder_isSending();
decoders->isPairSending ^= id;
return;
break;
@ -228,7 +238,7 @@ void old() {///////////////////////////////////////////////////////
// void IR_Encoder::rawSend(uint8_t* ptr, uint8_t len) {
// /*tmp*/bool LOW_FIRST = false;/*tmp*/
// if (decoder != nullptr) { decoder->isPairSending = true; }
// if (decoders != nullptr) { decoders->isPairSending = true; }
// bool prev = 1;
// bool next;
@ -244,7 +254,7 @@ void old() {///////////////////////////////////////////////////////
// addSync(&prev, &next);
// }
// if (decoder != nullptr) { decoder->isPairSending = false; }
// if (decoders != nullptr) { decoders->isPairSending = false; }
// }
}