summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2016-01-30 20:46:07 +0100
committerDaniel Friesel <derf@finalrewind.org>2016-01-30 20:46:07 +0100
commit134c20875f03d1885d0f08a8fb2717166d6e41ba (patch)
tree3b0a48265d31aa6097886f0ac6570cc39f6a6047 /src
parentf92e6d19a901941ac608af4fd658834d0404abb0 (diff)
system: make shutdown method private and actually use it
Diffstat (limited to 'src')
-rw-r--r--src/system.cc66
-rw-r--r--src/system.h6
2 files changed, 40 insertions, 32 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)
diff --git a/src/system.h b/src/system.h
index e944bb2..6e2d1b0 100644
--- a/src/system.h
+++ b/src/system.h
@@ -6,13 +6,17 @@
#define SHUTDOWN_THRESHOLD 2048
+/**
+ * Contains the system idle loop. Checks for button presses, handles
+ * standby/resume, reads data from the Modem and updates the Display.
+ */
class System {
private:
uint16_t want_shutdown;
+ void shutdown(void);
public:
System() { want_shutdown = 0; };
void loop(void);
- void shutdown(void);
};
extern System rocket;