summaryrefslogtreecommitdiff
path: root/src/system.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/system.cc')
-rw-r--r--src/system.cc66
1 files changed, 35 insertions, 31 deletions
diff --git a/src/system.cc b/src/system.cc
index 774127d..8d5c5ad 100644
--- a/src/system.cc
+++ b/src/system.cc
@@ -33,37 +33,7 @@ void System::loop()
want_shutdown++;
}
else {
-
- // turn off display to indicate we're about to shut down
- display.disable();
-
- modem.disable();
-
- // wait until both buttons are released
- while (!((PINC & _BV(PC3)) && (PINC & _BV(PC7)))) ;
-
- // and some more to debounce the buttons
- _delay_ms(10);
-
- // actual naptime
-
- // enable PCINT on PC3 (PCINT11) and PC7 (PCINT15) for wakeup
- PCMSK1 |= _BV(PCINT15) | _BV(PCINT11);
- PCICR |= _BV(PCIE1);
-
- // go to power-down mode
- SMCR = _BV(SM1) | _BV(SE);
- asm("sleep");
-
- // execution will resume here - disable PCINT again.
- // Don't disable PCICR, something else might need it.
- PCMSK1 &= ~(_BV(PCINT15) | _BV(PCINT11));
-
- // turn on display
- display.enable();
-
- // ... and modem
- modem.enable();
+ shutdown();
want_shutdown = 0;
}
@@ -86,6 +56,40 @@ void System::loop()
}
}
+void System::shutdown()
+{
+ // turn off display to indicate we're about to shut down
+ display.disable();
+
+ modem.disable();
+
+ // wait until both buttons are released
+ while (!((PINC & _BV(PC3)) && (PINC & _BV(PC7)))) ;
+
+ // and some more to debounce the buttons
+ _delay_ms(10);
+
+ // actual naptime
+
+ // enable PCINT on PC3 (PCINT11) and PC7 (PCINT15) for wakeup
+ PCMSK1 |= _BV(PCINT15) | _BV(PCINT11);
+ PCICR |= _BV(PCIE1);
+
+ // go to power-down mode
+ SMCR = _BV(SM1) | _BV(SE);
+ asm("sleep");
+
+ // execution will resume here - disable PCINT again.
+ // Don't disable PCICR, something else might need it.
+ PCMSK1 &= ~(_BV(PCINT15) | _BV(PCINT11));
+
+ // turn on display
+ display.enable();
+
+ // ... and modem
+ modem.enable();
+}
+
ISR(PCINT1_vect)
{
// we use PCINT1 for wakeup, so we should catch it here (and do nothing)