diff options
author | Sebastian Muszytowski <sebastian@muszytowski.net> | 2016-01-22 18:52:10 +0100 |
---|---|---|
committer | Sebastian Muszytowski <sebastian@muszytowski.net> | 2016-01-22 18:52:10 +0100 |
commit | 724f650b968e4029dfdd0f355cc8669e098b6880 (patch) | |
tree | 939baef3b38c1844d0dc35882b640b3b6def7a94 | |
parent | 6e41844bfa547a69a2fbd8effb09aae15b203bff (diff) | |
parent | 84758ec540877a79d2c9a4403b2023aa5d31eb17 (diff) |
Merge branch 'master' of github.com:blinkenrocket/firmware
-rw-r--r-- | src/display.cc | 38 | ||||
-rw-r--r-- | src/display.h | 8 | ||||
-rw-r--r-- | src/main.cc | 17 | ||||
-rw-r--r-- | src/system.cc | 6 |
4 files changed, 43 insertions, 26 deletions
diff --git a/src/display.cc b/src/display.cc index b0bc636..2059c9b 100644 --- a/src/display.cc +++ b/src/display.cc @@ -11,16 +11,8 @@ Display display; Display::Display() { - disp_buf[0] = 0xff; - disp_buf[1] = 0xfb; - disp_buf[2] = 0xdd; - disp_buf[3] = 0xfd; - disp_buf[4] = 0xdd; - disp_buf[5] = 0xfb; - disp_buf[6] = 0xff; - disp_buf[7] = 0xff; char_pos = -1; - scroll_delay = 400; + update_delay = 400; } void Display::disable() @@ -45,8 +37,6 @@ void Display::enable() void Display::multiplex() { static uint16_t scroll; - uint8_t i, glyph_len; - uint8_t *glyph_addr; /* * To avoid flickering, do not put any code (or expensive index @@ -59,8 +49,17 @@ void Display::multiplex() if (++active_col == 8) active_col = 0; - if (++scroll == scroll_delay) { + if (++scroll == update_delay) { scroll = 0; + need_update = 1; + } +} + +void Display::update() { + uint8_t i, glyph_len; + uint8_t *glyph_addr; + if (need_update) { + need_update = 0; for (i = 0; i < 7; i++) { disp_buf[i] = disp_buf[i+1]; @@ -89,12 +88,25 @@ void Display::multiplex() void Display::reset() { - for (int i = 0; i < 8; i++) + for (uint8_t i = 0; i < 8; i++) disp_buf[i] = 0xff; str_pos = 0; char_pos = -1; } +void Display::setString(const char *new_str) +{ + setString((char *)new_str); +} + +void Display::setString(char *new_str) +{ + reset(); + for (uint8_t i = 0; new_str[i] != 0; i++) { + string[i] = new_str[i]; + } +} + /* * Draws a single display column. This function should be called at least once * per millisecond. diff --git a/src/display.h b/src/display.h index 666648a..f48d1c3 100644 --- a/src/display.h +++ b/src/display.h @@ -6,18 +6,22 @@ class Display { private: - uint16_t scroll_delay; + uint16_t update_delay; + uint8_t need_update; uint8_t active_col; uint8_t disp_buf[8]; uint8_t str_pos; int8_t char_pos; + char string[128]; public: Display(); void enable(void); void disable(void); void multiplex(void); void reset(void); - char string[128]; + void update(void); + void setString(const char *str); + void setString(char *str); }; extern Display display; diff --git a/src/main.cc b/src/main.cc index 9558109..4398d02 100644 --- a/src/main.cc +++ b/src/main.cc @@ -20,13 +20,7 @@ int main (void) // Enable pull-ups on PC3 and PC7 (button pins) PORTC |= _BV(PC3) | _BV(PC7); - display.string[0] = 'O'; - display.string[1] = 'h'; - display.string[2] = 'a'; - display.string[3] = 'i'; - display.string[4] = '!'; - display.string[5] = ' '; - display.string[6] = 0; + display.setString("Ohai! "); display.enable(); modem.enable(); @@ -37,9 +31,14 @@ int main (void) // nothing to do here, go to idle to save power SMCR = _BV(SE); asm("sleep"); - // The display timer causes a wakeup after 256µs. Run the system - // loop after the timer's ISR is done. + /* + * The display timer causes a wakeup after 256µs. Run the system + * loop after the timer's ISR is done. + * The Modem also causes wakeups, which is pretty convenient since + * it means we can immediately process the received data. + */ rocket.loop(); + display.update(); } return 0; diff --git a/src/system.cc b/src/system.cc index 6c44a30..5c7b177 100644 --- a/src/system.cc +++ b/src/system.cc @@ -12,6 +12,8 @@ System rocket; +char disp_buf[128]; + void System::loop() { static uint8_t i = 0; @@ -70,12 +72,12 @@ void System::loop() while (modem.buffer_available()) { modem_char = modem.buffer_get(); - display.string[i++] = modem_char; + disp_buf[i++] = modem_char; if (i == 127) { i = 0; } else if (modem_char == 0) { i = 0; - display.reset(); + display.setString(disp_buf); } } } |