mirror of
https://github.com/Show-maket/IR-protocol.git
synced 2026-04-28 03:08:08 +00:00
fix overflow and mute
This commit is contained in:
@ -15,19 +15,14 @@ IR_Encoder::IR_Encoder(uint8_t pin, uint16_t addr, IR_DecoderRaw *decPair, bool
|
||||
setPin(pin);
|
||||
id = addr;
|
||||
this->decPair = decPair;
|
||||
signal = noSignal;
|
||||
isSending = false;
|
||||
#if disablePairDec
|
||||
if (decPair != nullptr)
|
||||
{
|
||||
blindDecoders = new IR_DecoderRaw *[1]{decPair};
|
||||
singleBlindDecoder = decPair;
|
||||
blindDecoders = &singleBlindDecoder;
|
||||
decodersCount = 1;
|
||||
}
|
||||
#endif
|
||||
if (decPair != nullptr)
|
||||
{
|
||||
decPair->encoder = this;
|
||||
}
|
||||
registerWithBlindDecoders();
|
||||
|
||||
if (autoHandle)
|
||||
{
|
||||
@ -233,7 +228,7 @@ void IR_Encoder::externalFinishSend()
|
||||
}
|
||||
|
||||
isSending = false;
|
||||
setDecoder_isSending();
|
||||
refreshBlindDecoderMuteState();
|
||||
}
|
||||
|
||||
size_t IR_Encoder::buildGateRuns(const uint8_t *packet, uint8_t len, IR_TxGateRun *outRuns, size_t maxRuns)
|
||||
@ -351,12 +346,16 @@ void IR_Encoder::disable()
|
||||
|
||||
void IR_Encoder::setBlindDecoders(IR_DecoderRaw *decoders[], uint8_t count)
|
||||
{
|
||||
#if disablePairDec
|
||||
if (blindDecoders != nullptr)
|
||||
delete[] blindDecoders;
|
||||
#endif
|
||||
if (count > IR_PAIR_MUTE_MAX_ENCODERS)
|
||||
{
|
||||
decodersCount = 0;
|
||||
blindDecoders = nullptr;
|
||||
return;
|
||||
}
|
||||
decodersCount = count;
|
||||
blindDecoders = decoders;
|
||||
registerWithBlindDecoders();
|
||||
refreshBlindDecoderMuteState();
|
||||
}
|
||||
|
||||
IR_Encoder::~IR_Encoder(){};
|
||||
@ -543,18 +542,27 @@ IR_SendResult IR_Encoder::_sendBack(bool isAdressed, uint16_t addrTo, uint8_t *d
|
||||
return IR_SendResult(true, sendTime);
|
||||
}
|
||||
|
||||
void IR_Encoder::setDecoder_isSending()
|
||||
void IR_Encoder::registerWithBlindDecoders()
|
||||
{
|
||||
if (decodersCount)
|
||||
if (!decodersCount || blindDecoders == nullptr)
|
||||
return;
|
||||
|
||||
for (uint8_t i = 0; i < decodersCount; i++)
|
||||
{
|
||||
for (uint8_t i = 0; i < decodersCount; i++)
|
||||
{
|
||||
blindDecoders[i]->isPairSending ^= id;
|
||||
// Serial.print("setDecoder_isSending() id = ");
|
||||
// Serial.print(id);
|
||||
// Serial.print(" isPairSending = ");
|
||||
// Serial.println(blindDecoders[i]->isPairSending);
|
||||
}
|
||||
if (blindDecoders[i] != nullptr)
|
||||
blindDecoders[i]->registerPairMuteEncoder(this);
|
||||
}
|
||||
}
|
||||
|
||||
void IR_Encoder::refreshBlindDecoderMuteState()
|
||||
{
|
||||
if (!decodersCount || blindDecoders == nullptr)
|
||||
return;
|
||||
|
||||
for (uint8_t i = 0; i < decodersCount; i++)
|
||||
{
|
||||
if (blindDecoders[i] != nullptr)
|
||||
blindDecoders[i]->refreshPairMuteState();
|
||||
}
|
||||
}
|
||||
|
||||
@ -572,13 +580,13 @@ void IR_Encoder::rawSend(uint8_t *ptr, uint8_t len)
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.print("IR tx hex: ");
|
||||
for (uint8_t i = 0; i < len; i++)
|
||||
{
|
||||
if (ptr[i] < 0x10) Serial.print("0");
|
||||
Serial.print(ptr[i], HEX);
|
||||
}
|
||||
Serial.println();
|
||||
// Serial.print("IR tx hex: ");
|
||||
// for (uint8_t i = 0; i < len; i++)
|
||||
// {
|
||||
// if (ptr[i] < 0x10) Serial.print("0");
|
||||
// Serial.print(ptr[i], HEX);
|
||||
// }
|
||||
// Serial.println();
|
||||
|
||||
if (externalTxStartFn != nullptr)
|
||||
{
|
||||
@ -587,24 +595,18 @@ void IR_Encoder::rawSend(uint8_t *ptr, uint8_t len)
|
||||
return;
|
||||
}
|
||||
|
||||
// Mark as sending and delegate actual signal output to external backend.
|
||||
setDecoder_isSending();
|
||||
sendLen = len;
|
||||
isSending = true;
|
||||
refreshBlindDecoderMuteState();
|
||||
|
||||
const bool ok = externalTxStartFn(externalTxCtx, this, ptr, len);
|
||||
if (!ok)
|
||||
{
|
||||
isSending = false;
|
||||
setDecoder_isSending();
|
||||
refreshBlindDecoderMuteState();
|
||||
}
|
||||
return;
|
||||
}
|
||||
IR_Encoder::carrierResume();
|
||||
// Serial.println("START");
|
||||
setDecoder_isSending();
|
||||
|
||||
// noInterrupts();
|
||||
sendLen = len;
|
||||
toggleCounter = preambToggle; // Первая генерация для первого signal
|
||||
|
||||
@ -618,8 +620,9 @@ void IR_Encoder::rawSend(uint8_t *ptr, uint8_t len)
|
||||
signal = preamb;
|
||||
isSending = true;
|
||||
state = HIGH;
|
||||
|
||||
currentBitSequence = bitHigh;
|
||||
refreshBlindDecoderMuteState();
|
||||
IR_Encoder::carrierResume();
|
||||
// interrupts();
|
||||
}
|
||||
|
||||
@ -651,7 +654,7 @@ void IR_Encoder::_isr()
|
||||
if (!active)
|
||||
{
|
||||
isSending = false;
|
||||
setDecoder_isSending();
|
||||
refreshBlindDecoderMuteState();
|
||||
carrierStopPending = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user