From fbfadac23b3b8cb868d0a1cfbc232669699c1acd Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 1 Mar 2016 19:04:15 +0100 Subject: move flash and shutdown patterns to PROGMEM --- src/static_patterns.h | 27 ++++++++++++++++ src/system.cc | 88 ++++++++++++++++++++++----------------------------- src/system.h | 35 +------------------- 3 files changed, 66 insertions(+), 84 deletions(-) create mode 100644 src/static_patterns.h 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 + +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 #include #include +#include #include #include @@ -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, -- cgit v1.2.3