Added (somewhat hacky) workaround for the pin change interrupt waking the device up after releasing a long press to power down

This commit is contained in:
Mark van Renswoude 2017-08-05 23:22:04 +02:00
parent b7d7bf405f
commit f92f7d8794
3 changed files with 22 additions and 11 deletions

View File

@ -33,7 +33,7 @@ int main()
handleCurrentScreen(); handleCurrentScreen();
if (!buttons_active() && !peekScreenInvalidated()) if (!buttons_active() && !peekScreenInvalidated())
sleepUntilButton(_BV(BUTTON_UP) | _BV(BUTTON_DOWN) | _BV(BUTTON_OPTION)); sleepUntilButton(_BV(BUTTON_UP) | _BV(BUTTON_DOWN) | _BV(BUTTON_OPTION), 0);
} }
} }

View File

@ -65,7 +65,10 @@ void checkPower()
break; break;
case ManualOff: case ManualOff:
sleepUntilButton(_BV(BUTTON_OPTION)); // Skip the next button change since it's on a long press. I don't
// really like that this is set here instead of in the call to
// setPowerState, but that's a refactoring for another day....
sleepUntilButton(_BV(BUTTON_OPTION), 1);
setPowerState(On); setPowerState(On);
break; break;
} }
@ -163,7 +166,9 @@ static inline void sleepEnd()
} }
void sleepUntilButton(uint8_t pinMask) void sleepUntilButton(uint8_t pinMask, uint8_t ignoreEvents)
{
while (1)
{ {
// Enable pin change interrupts // Enable pin change interrupts
GIMSK |= _BV(PCIE); GIMSK |= _BV(PCIE);
@ -174,6 +179,12 @@ void sleepUntilButton(uint8_t pinMask)
sleepStart(); sleepStart();
PCMSK = 0; PCMSK = 0;
sleepEnd(); sleepEnd();
if (ignoreEvents == 0)
break;
ignoreEvents--;
}
} }

View File

@ -13,7 +13,7 @@ extern uint16_t vcc;
extern void checkPower(); extern void checkPower();
extern void setPowerState(PowerState newState); extern void setPowerState(PowerState newState);
extern void sleepUntilButton(uint8_t pinMask); extern void sleepUntilButton(uint8_t pinMask, uint8_t ignoreEvents);
// 0 = 16 ms // 0 = 16 ms
// 1 = 32 ms // 1 = 32 ms