diff options
author | Daniel Friesel <derf@finalrewind.org> | 2016-01-26 19:52:54 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2016-01-26 19:52:54 +0100 |
commit | ce235210b76332493ee5c78bded63fb5b69ff6d3 (patch) | |
tree | ea47e5c775409b88f4e5b870aa807e2c84692e7f /src | |
parent | 0e8a263587c91fe0b8bf177ec94a49c207eef4cf (diff) |
preliminary animation support
Diffstat (limited to 'src')
-rw-r--r-- | src/display.cc | 63 | ||||
-rw-r--r-- | src/display.h | 12 | ||||
-rw-r--r-- | src/main.cc | 7 |
3 files changed, 55 insertions, 27 deletions
diff --git a/src/display.cc b/src/display.cc index 0767c4f..f3d48da 100644 --- a/src/display.cc +++ b/src/display.cc @@ -61,27 +61,37 @@ void Display::update() { if (need_update) { need_update = 0; - for (i = 0; i < 7; i++) { - disp_buf[i] = disp_buf[i+1]; - } - - glyph_addr = (uint8_t *)pgm_read_ptr(&font[display.data_buf[str_pos]]); - glyph_len = pgm_read_byte(&glyph_addr[0]); - char_pos++; - - if (char_pos > glyph_len) { - char_pos = 0; - str_pos++; - } - - if (display.data_buf[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]); + if (mode == TEXT) { + for (i = 0; i < 7; i++) { + disp_buf[i] = disp_buf[i+1]; + } + + glyph_addr = (uint8_t *)pgm_read_ptr(&font[display.data_buf[str_pos]]); + glyph_len = pgm_read_byte(&glyph_addr[0]); + char_pos++; + + if (char_pos > glyph_len) { + char_pos = 0; + str_pos++; + } + + if (display.data_buf[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]); + } + } else if (mode == ANIMATION) { + for (i = 0; i < 8; i++) { + disp_buf[i] = ~display.data_buf[str_pos+i]; + } + str_pos += 8; + if (str_pos == 32) { + str_pos = 0; + } } } } @@ -94,9 +104,16 @@ void Display::reset() char_pos = -1; } -void Display::show(text t) +void Display::show(text_t text) +{ + mode = TEXT; + show(text.str); +} + +void Display::show(animation_t anim) { - show(t.str); + mode = ANIMATION; + show(anim.data); } void Display::show(uint8_t *str) diff --git a/src/display.h b/src/display.h index 5c66586..8687874 100644 --- a/src/display.h +++ b/src/display.h @@ -16,8 +16,8 @@ struct __animation { uint8_t *data; }; -typedef struct __text text; -typedef struct __animation animation; +typedef struct __text text_t; +typedef struct __animation animation_t; class Display { private: @@ -28,6 +28,11 @@ class Display { uint8_t str_pos; int8_t char_pos; uint8_t data_buf[128]; + enum DisplayMode : uint8_t { + TEXT = 1, + ANIMATION = 2 + }; + DisplayMode mode; public: Display(); void enable(void); @@ -37,7 +42,8 @@ class Display { void reset(void); void update(void); - void show(text t); + void show(text_t text); + void show(animation_t anim); void show(uint8_t *str); }; diff --git a/src/main.cc b/src/main.cc index b47c848..e3bc2f9 100644 --- a/src/main.cc +++ b/src/main.cc @@ -12,9 +12,14 @@ int main (void) { - text ohai; + text_t ohai; ohai.str = (uint8_t *)"Ohai! "; + //uint8_t anim_data[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0 }; + + //animation_t test; + //test.data = anim_data; + // disable ADC to save power PRR |= _BV(PRADC); |