From abf69bd53f86300d263d3abeeae81a9e1c3cd5c0 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 19 Jan 2016 19:59:51 +0100 Subject: support scrolling arbitrary strings. --- src/display.cc | 48 ++++++++++++++++++++++++++++++++++-------------- src/display.h | 1 + src/font.h | 1 + src/main.cc | 52 ++++++---------------------------------------------- src/system.cc | 11 +++++++---- 5 files changed, 49 insertions(+), 64 deletions(-) diff --git a/src/display.cc b/src/display.cc index b1b0af5..4215983 100644 --- a/src/display.cc +++ b/src/display.cc @@ -5,10 +5,11 @@ #include #include "display.h" +#include "font.h" Display display; -extern volatile uint8_t disp[8]; +uint8_t teststr[] = {'O', 'h', 'a', 'i', '!', 0}; void Display::disable() { @@ -41,22 +42,14 @@ ISR(TIMER0_OVF_vect) { static uint8_t active_col = 0; static uint16_t scroll = 0; - static uint8_t disp_offset = 0; - static uint8_t disp_buf[8]; + static uint8_t disp_buf[] = {0xff,0xfb,0xdd,0xfd,0xdd,0xfb,0xff,0xff}; - uint8_t i; + static uint8_t str_pos = 0; + static int8_t char_pos = -1; - if (++scroll == 512) { - scroll = 0; - if (++disp_offset == sizeof(disp)) { - disp_offset = 0; - } - - for (i = 0; i < 8; i++) { - disp_buf[i] = ~disp[(disp_offset + i) % sizeof(disp)]; - } - } + uint8_t i, glyph_len; + uint8_t *glyph_addr; /* * To avoid flickering, do not put any code (or expensive index @@ -68,4 +61,31 @@ ISR(TIMER0_OVF_vect) if (++active_col == 8) active_col = 0; + + if (++scroll == 512) { + scroll = 0; + + for (i = 0; i < 7; i++) { + disp_buf[i] = disp_buf[i+1]; + } + + glyph_addr = (uint8_t *)pgm_read_ptr(&font[(uint8_t)display.string[str_pos]]); + glyph_len = pgm_read_byte(&glyph_addr[0]); + char_pos++; + + if (char_pos > glyph_len) { + char_pos = 0; + str_pos++; + } + + if (display.string[str_pos] == 0) { + str_pos = 0; + } + + if (char_pos == 0) { + disp_buf[7] = 0xff; // whitespace + } else { + disp_buf[7] = ~pgm_read_byte(&glyph_addr[char_pos]); + } + } } diff --git a/src/display.h b/src/display.h index cb263d0..d239e18 100644 --- a/src/display.h +++ b/src/display.h @@ -9,6 +9,7 @@ class Display { Display() {}; void enable(void); void disable(void); + char string[128]; }; extern Display display; diff --git a/src/font.h b/src/font.h index aea6b8a..a705d57 100644 --- a/src/font.h +++ b/src/font.h @@ -133,6 +133,7 @@ const unsigned char PROGMEM chr_125[] = {0x03,0x41,0x36,0x08}; // } const unsigned char PROGMEM chr_126[] = {0x05,0x08,0x10,0x08,0x04,0x08}; // ~ const glyph_t font[] PROGMEM = { + chr_001, chr_001, chr_002, chr_003, diff --git a/src/main.cc b/src/main.cc index fbb40c9..f665e18 100644 --- a/src/main.cc +++ b/src/main.cc @@ -9,8 +9,6 @@ #include "modem.h" #include "system.h" -volatile uint8_t disp[8]; - int main (void) { // disable ADC to save power @@ -22,50 +20,12 @@ int main (void) // Enable pull-ups on PC3 and PC7 (button pins) PORTC |= _BV(PC3) | _BV(PC7); - disp[0] = 0x01; - disp[1] = 0x02; - disp[2] = 0x04; - disp[3] = 0x08; - disp[4] = 0x10; - disp[5] = 0x20; - disp[6] = 0x40; - disp[7] = 0x80; - -#if 0 - // smile! - disp[0] = 0x08; - disp[1] = 0x04; - disp[2] = 0x62; - disp[3] = 0x02; - disp[4] = 0x02; - disp[5] = 0x62; - disp[6] = 0x04; - disp[7] = 0x08; - disp[8] = 0x00; - disp[9] = 0x00; - disp[10] = 0x00; - disp[11] = 0x00; - disp[12] = 0x00; - disp[13] = 0x00; - disp[14] = 0x00; - disp[15] = 0x00; - disp[16] = 0x28; - disp[17] = 0x44; - disp[18] = 0x22; - disp[19] = 0x02; - disp[20] = 0x02; - disp[21] = 0x22; - disp[22] = 0x44; - disp[23] = 0x28; - disp[24] = 0x00; - disp[25] = 0x00; - disp[26] = 0x00; - disp[27] = 0x00; - disp[28] = 0x00; - disp[29] = 0x00; - disp[30] = 0x00; - disp[31] = 0x00; -#endif + display.string[0] = 'O'; + display.string[1] = 'h'; + display.string[2] = 'a'; + display.string[3] = 'i'; + display.string[4] = '!'; + display.string[5] = 0; display.enable(); modem.enable(); diff --git a/src/system.cc b/src/system.cc index 09c0f53..340615d 100644 --- a/src/system.cc +++ b/src/system.cc @@ -12,11 +12,10 @@ System rocket; -extern volatile uint8_t disp[8]; - void System::loop() { static uint8_t i = 0; + char modem_char; // both buttons are pressed if ((PINC & (_BV(PC3) | _BV(PC7))) == 0) { // naptime! @@ -70,9 +69,13 @@ void System::loop() } while (modem.buffer_available()) { - disp[i++] = modem.buffer_get(); - if (i == 8) + modem_char = modem.buffer_get(); + display.string[i++] = modem_char; + if (i == 127) { + i = 0; + } else if (modem_char == 0) { i = 0; + } } } -- cgit v1.2.3