summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2016-02-29 13:36:34 +0100
committerDaniel Friesel <derf@finalrewind.org>2016-02-29 13:36:34 +0100
commit9f96509a454174fd10ed9924a9da81dd60bc8195 (patch)
tree04b699066b525c254beb85af36dafdce2f078eff /src
parentafbf9bf8e1422d7c810be524365e60973d8ec798 (diff)
add support for a powerdown image
Diffstat (limited to 'src')
-rw-r--r--src/display.cc1
-rw-r--r--src/system.cc74
-rw-r--r--src/system.h12
3 files changed, 57 insertions, 30 deletions
diff --git a/src/display.cc b/src/display.cc
index 87d863f..b7942e8 100644
--- a/src/display.cc
+++ b/src/display.cc
@@ -125,6 +125,7 @@ void Display::reset()
disp_buf[i] = 0xff;
str_pos = 0;
char_pos = -1;
+ need_update = 1;
status = RUNNING;
}
diff --git a/src/system.cc b/src/system.cc
index d8c27ab..9867c17 100644
--- a/src/system.cc
+++ b/src/system.cc
@@ -46,9 +46,28 @@ void System::initialize()
sei();
+ current_anim_no = 0;
+ loadPattern(0);
+}
+
+void System::loadPattern(uint8_t anim_no)
+{
if (storage.hasData()) {
- current_anim_no = 0;
- loadPattern(0);
+ storage.load(anim_no, disp_buf);
+
+ active_anim.type = (AnimationType)(disp_buf[0] >> 4);
+ active_anim.length = disp_buf[1];
+
+ if (active_anim.type == AnimationType::TEXT) {
+ active_anim.speed = (disp_buf[2] & 0xf0) + 15;
+ active_anim.delay = (disp_buf[2] & 0x0f ) << 4;
+ active_anim.direction = disp_buf[3] >> 4;
+ } else if (active_anim.type == AnimationType::FRAMES) {
+ active_anim.speed = ((disp_buf[2] & 0x0f) << 4) + 15;
+ active_anim.delay = (disp_buf[3] & 0x0f) << 2;
+ }
+
+ active_anim.data = disp_buf + 4;
} else {
active_anim.type = AnimationType::TEXT;
active_anim.speed = (2 << 4) + 15;
@@ -88,30 +107,6 @@ void System::initialize()
display.show(&active_anim);
}
-void System::loadPattern(uint8_t anim_no)
-{
- if (!storage.hasData())
- return;
-
- storage.load(anim_no, disp_buf);
-
- active_anim.type = (AnimationType)(disp_buf[0] >> 4);
- active_anim.length = disp_buf[1];
-
- if (active_anim.type == AnimationType::TEXT) {
- active_anim.speed = (disp_buf[2] & 0xf0) + 15;
- active_anim.delay = (disp_buf[2] & 0x0f ) << 4;
- active_anim.direction = disp_buf[3] >> 4;
- } else if (active_anim.type == AnimationType::FRAMES) {
- active_anim.speed = ((disp_buf[2] & 0x0f) << 4) + 15;
- active_anim.delay = (disp_buf[3] & 0x0f) << 2;
- }
-
- active_anim.data = disp_buf + 4;
-
- display.show(&active_anim);
-}
-
// ! This function has not been tested yet
void System::receive(void)
{
@@ -268,16 +263,31 @@ void System::loop()
void System::shutdown()
{
- // turn off display to indicate we're about to shut down
- display.disable();
-
modem.disable();
+ // show power down image
+ disp_buf[0] = systemPowerdownImage[0];
+ disp_buf[1] = systemPowerdownImage[1];
+ disp_buf[2] = systemPowerdownImage[2];
+ disp_buf[3] = systemPowerdownImage[3];
+ disp_buf[4] = systemPowerdownImage[4];
+ disp_buf[5] = systemPowerdownImage[5];
+ disp_buf[6] = systemPowerdownImage[6];
+ disp_buf[7] = systemPowerdownImage[7];
+ active_anim.data = disp_buf;
+ active_anim.type = AnimationType::FRAMES;
+ active_anim.length = 8;
+ display.show(&active_anim);
+ display.update(); // we left the main loop, so we need to call this manually
+
// wait until both buttons are released
while (!((PINC & _BV(PC3)) && (PINC & _BV(PC7)))) ;
// and some more to debounce the buttons
- _delay_ms(10);
+ _delay_ms(50);
+
+ // turn off display to indicate we're about to shut down
+ display.disable();
// actual naptime
@@ -293,7 +303,11 @@ void System::shutdown()
// Don't disable PCICR, something else might need it.
PCMSK1 &= ~(_BV(PCINT15) | _BV(PCINT11));
+ // debounce
+ _delay_ms(50);
+
// turn on display
+ loadPattern(current_anim_no);
display.enable();
// ... and modem
diff --git a/src/system.h b/src/system.h
index d72fe8a..36e8e37 100644
--- a/src/system.h
+++ b/src/system.h
@@ -2,6 +2,18 @@
#define SHUTDOWN_THRESHOLD 2048
+// TODO find a nice image
+const uint8_t systemPowerdownImage[] = {
+ 0x00,
+ 0x00,
+ 0x08,
+ 0x08,
+ 0x08,
+ 0x08,
+ 0x00,
+ 0x00
+};
+
/**
* Contains the system idle loop. Checks for button presses, handles
* standby/resume, reads data from the Modem and updates the Display.