mirror of
https://github.com/Show-maket/IR-protocol.git
synced 2026-03-13 04:44:44 +00:00
carrierPauseIfIdle/carrierResume
This commit is contained in:
@ -7,6 +7,7 @@
|
||||
|
||||
IR_Encoder *IR_Encoder::head = nullptr;
|
||||
IR_Encoder *IR_Encoder::last = nullptr;
|
||||
volatile bool IR_Encoder::carrierStopPending = false;
|
||||
|
||||
IR_Encoder::IR_Encoder(uint8_t pin, uint16_t addr, IR_DecoderRaw *decPair, bool autoHandle)
|
||||
{
|
||||
@ -47,13 +48,34 @@ HardwareTimer* IR_Encoder::IR_Timer = nullptr;
|
||||
|
||||
inline HardwareTimer* IR_Encoder::get_IR_Timer(){return IR_Encoder::IR_Timer;}
|
||||
|
||||
void IR_Encoder::carrierResume() {
|
||||
if (IR_Timer != nullptr)
|
||||
IR_Timer->resume();
|
||||
}
|
||||
|
||||
void IR_Encoder::carrierPauseIfIdle() {
|
||||
for (IR_Encoder *p = head; p != nullptr; p = p->next)
|
||||
if (p->isSending)
|
||||
return;
|
||||
if (IR_Timer != nullptr)
|
||||
IR_Timer->pause();
|
||||
}
|
||||
|
||||
void IR_Encoder::tick() {
|
||||
if (!carrierStopPending)
|
||||
return;
|
||||
carrierStopPending = false;
|
||||
carrierPauseIfIdle();
|
||||
}
|
||||
|
||||
void IR_Encoder::begin(HardwareTimer* timer, uint8_t channel, IRQn_Type IRQn, uint8_t priority, void(*isrCallback)()){
|
||||
IR_Timer = timer;
|
||||
if(IR_Timer == nullptr) return;
|
||||
IR_Timer->pause();
|
||||
IR_Timer->setOverflow(carrierFrec * 2, HERTZ_FORMAT);
|
||||
IR_Timer->attachInterrupt(channel, (isrCallback == nullptr ? IR_Encoder::isr : isrCallback));
|
||||
NVIC_SetPriority(IRQn, priority);
|
||||
IR_Timer->resume();
|
||||
IR_Timer->pause();
|
||||
}
|
||||
|
||||
|
||||
@ -338,6 +360,7 @@ void IR_Encoder::rawSend(uint8_t *ptr, uint8_t len)
|
||||
{
|
||||
return;
|
||||
}
|
||||
IR_Encoder::carrierResume();
|
||||
// Serial.println("START");
|
||||
setDecoder_isSending();
|
||||
|
||||
@ -397,6 +420,7 @@ void IR_Encoder::_isr()
|
||||
isSending = false;
|
||||
// Serial.println("STOP");
|
||||
setDecoder_isSending();
|
||||
carrierStopPending = true;
|
||||
// Serial.println();
|
||||
return;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user