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();
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;
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);
break;
}
@ -163,17 +166,25 @@ static inline void sleepEnd()
}
void sleepUntilButton(uint8_t pinMask)
void sleepUntilButton(uint8_t pinMask, uint8_t ignoreEvents)
{
// Enable pin change interrupts
GIMSK |= _BV(PCIE);
while (1)
{
// Enable pin change interrupts
GIMSK |= _BV(PCIE);
// Set up pin change mask
PCMSK = pinMask;
// Set up pin change mask
PCMSK = pinMask;
sleepStart();
PCMSK = 0;
sleepEnd();
sleepStart();
PCMSK = 0;
sleepEnd();
if (ignoreEvents == 0)
break;
ignoreEvents--;
}
}

View File

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