summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2016-03-01 19:04:15 +0100
committerDaniel Friesel <derf@finalrewind.org>2016-03-01 19:04:15 +0100
commitfbfadac23b3b8cb868d0a1cfbc232669699c1acd (patch)
treeaa0f5c0995f76de564a6e0253c4a00265b06027d
parent3183889c1f9f41d8cca3b5eee2f1bf00f07b9217 (diff)
move flash and shutdown patterns to PROGMEM
-rw-r--r--src/static_patterns.h27
-rw-r--r--src/system.cc88
-rw-r--r--src/system.h35
3 files changed, 66 insertions, 84 deletions
diff --git a/src/static_patterns.h b/src/static_patterns.h
new file mode 100644
index 0000000..8d708dd
--- /dev/null
+++ b/src/static_patterns.h
@@ -0,0 +1,27 @@
+#ifndef STATIC_PATTERNS_H_
+#define STATIC_PATTERNS_H_
+
+#include <avr/pgmspace.h>
+
+const uint8_t PROGMEM shutdownPattern[] = {
+ 0x20, 0x40,
+ 0x01, 0x0f,
+ 0xff, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xff,
+ 0x7e, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7e,
+ 0x3c, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x3c,
+ 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+ 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00,
+ 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+};
+
+const uint8_t PROGMEM flashingPattern[] = {
+ 0x20, 0x10,
+ 0x06, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x07, 0x33, 0x55, 0x98, 0x00, 0x00
+};
+
+
+#endif /* STATIC_PATTERNS_H_ */
diff --git a/src/system.cc b/src/system.cc
index 3b6ee3c..9e7354d 100644
--- a/src/system.cc
+++ b/src/system.cc
@@ -1,6 +1,7 @@
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
+#include <avr/pgmspace.h>
#include <util/delay.h>
#include <stdlib.h>
@@ -8,6 +9,7 @@
#include "fecmodem.h"
#include "storage.h"
#include "system.h"
+#include "static_patterns.h"
#define SHUTDOWN_THRESHOLD 2048
@@ -50,6 +52,32 @@ void System::initialize()
loadPattern(0);
}
+void System::loadPattern_P(const uint8_t *anim_ptr)
+{
+ uint8_t i;
+
+ for (i = 0; i < 4; i++)
+ disp_buf[i] = pgm_read_byte(anim_ptr + i);
+
+ for (i = 0; i < disp_buf[1]; i++)
+ disp_buf[i+4] = pgm_read_byte(anim_ptr + i + 4);
+
+ 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);
+}
+
void System::loadPattern(uint8_t anim_no)
{
if (storage.hasData()) {
@@ -143,7 +171,7 @@ void System::receive(void)
if (rx_byte == BYTE_START) {
rxExpect = PATTERN1;
storage.reset();
- dispFlashing();
+ loadPattern_P(flashingPattern);
} else {
rxExpect = NEXT_BLOCK;
}
@@ -262,64 +290,24 @@ void System::loop()
display.update();
}
-void System::dispPowerdown()
-{
- 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);
-}
-
-void System::dispFlashing()
-{
- // manually unrolled loop to make sure systemFlashImage doesn't end up
- // in memory
- disp_buf[0] = systemFlashImage[0];
- disp_buf[1] = systemFlashImage[1];
- disp_buf[2] = systemFlashImage[2];
- disp_buf[3] = systemFlashImage[3];
- disp_buf[4] = systemFlashImage[4];
- disp_buf[5] = systemFlashImage[5];
- disp_buf[6] = systemFlashImage[6];
- disp_buf[7] = systemFlashImage[7];
- disp_buf[8] = systemFlashImage[8];
- disp_buf[9] = systemFlashImage[9];
- disp_buf[10] = systemFlashImage[10];
- disp_buf[11] = systemFlashImage[11];
- disp_buf[12] = systemFlashImage[12];
- disp_buf[13] = systemFlashImage[13];
- disp_buf[14] = systemFlashImage[14];
- disp_buf[15] = systemFlashImage[15];
-
- active_anim.data = disp_buf;
- active_anim.type = AnimationType::FRAMES;
- active_anim.length = 16;
- active_anim.delay = 0;
- active_anim.speed = 96;
- display.show(&active_anim);
-}
-
void System::shutdown()
{
+ uint8_t i;
+
modem.disable();
// show power down image
- dispPowerdown();
- display.update(); // we left the main loop, so we need to call this manually
+ loadPattern_P(shutdownPattern);
// wait until both buttons are released
- while (!((PINC & _BV(PC3)) && (PINC & _BV(PC7)))) ;
+ while (!((PINC & _BV(PC3)) && (PINC & _BV(PC7))))
+ display.update();
// and some more to debounce the buttons
- _delay_ms(50);
+ for (i = 0; i < 50; i++) {
+ display.update();
+ _delay_ms(1);
+ }
// turn off display to indicate we're about to shut down
display.disable();
diff --git a/src/system.h b/src/system.h
index 8960b77..5866aec 100644
--- a/src/system.h
+++ b/src/system.h
@@ -2,38 +2,6 @@
#define SHUTDOWN_THRESHOLD 2048
-// TODO find a nice image
-const uint8_t systemPowerdownImage[] = {
- 0x00,
- 0x00,
- 0x08,
- 0x08,
- 0x08,
- 0x08,
- 0x00,
- 0x00
-};
-
-// TODO dito?
-const uint8_t systemFlashImage[] = {
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x07,
- 0x33,
- 0x55,
- 0x98,
- 0x00,
- 0x00
-};
-
/**
* Contains the system idle loop. Checks for button presses, handles
* standby/resume, reads data from the Modem and updates the Display.
@@ -45,8 +13,7 @@ class System {
void shutdown(void);
void receive(void);
void loadPattern(uint8_t anim_no);
- void dispPowerdown();
- void dispFlashing();
+ void loadPattern_P(const uint8_t *anim_ptr);
enum TransmissionControl : uint8_t {
BYTE_END = 0x84,