diff options
author | Daniel Friesel <derf@finalrewind.org> | 2016-01-28 15:05:15 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2016-01-28 15:05:15 +0100 |
commit | edf5f5ab92520b6af3151bca2b97c618a9d1d7f9 (patch) | |
tree | 29f710563194c1fbe6fcfc5dffa892bb6e204710 /src | |
parent | c079af446d61c892b867a9ab4efd2e496dfb9cce (diff) |
merge text_t and animation_t into single animation type to reduce code and memory overhead
Diffstat (limited to 'src')
-rw-r--r-- | src/display.cc | 34 | ||||
-rw-r--r-- | src/display.h | 30 | ||||
-rw-r--r-- | src/main.cc | 17 | ||||
-rw-r--r-- | src/system.cc | 2 |
4 files changed, 31 insertions, 52 deletions
diff --git a/src/display.cc b/src/display.cc index 6b81684..5a652c8 100644 --- a/src/display.cc +++ b/src/display.cc @@ -47,7 +47,7 @@ void Display::multiplex() if (++active_col == 8) { active_col = 0; - if (++scroll == active_text.speed) { + if (++scroll == active_anim->speed) { scroll = 0; need_update = 1; } @@ -60,12 +60,12 @@ void Display::update() { if (need_update) { need_update = 0; - if (mode == TEXT) { + if (active_anim->mode == AnimationType::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_addr = (uint8_t *)pgm_read_ptr(&font[active_anim->data[str_pos]]); glyph_len = pgm_read_byte(&glyph_addr[0]); char_pos++; @@ -74,7 +74,7 @@ void Display::update() { str_pos++; } - if (display.data_buf[str_pos] == 0) { + if (active_anim->data[str_pos] == 0) { str_pos = 0; } @@ -83,12 +83,12 @@ void Display::update() { } else { disp_buf[7] = ~pgm_read_byte(&glyph_addr[char_pos]); } - } else if (mode == ANIMATION) { + } else if (active_anim->mode == AnimationType::FRAMES) { for (i = 0; i < 8; i++) { - disp_buf[i] = ~display.data_buf[str_pos+i]; + disp_buf[i] = ~active_anim->data[str_pos+i]; } str_pos += 8; - if (str_pos == 32) { + if (str_pos == active_anim->length) { str_pos = 0; } } @@ -103,27 +103,9 @@ void Display::reset() char_pos = -1; } -void Display::show(text_t text) +void Display::show(animation_t *anim) { - mode = TEXT; - active_text = text; - show(text.str); -} - -void Display::show(animation_t anim) -{ - mode = ANIMATION; active_anim = anim; - show(anim.data); -} - -void Display::show(uint8_t *str) -{ - int i; - for (i = 0; str[i] != 0; i++) { - data_buf[i] = str[i]; - } - data_buf[i] = 0; // trailing null byte reset(); } diff --git a/src/display.h b/src/display.h index 70939ca..abea377 100644 --- a/src/display.h +++ b/src/display.h @@ -4,39 +4,33 @@ #include <util/delay.h> #include <stdlib.h> -struct __text { - uint8_t speed; - uint8_t delay; - uint8_t direction; - uint8_t *str; +enum class AnimationType : uint8_t { + TEXT = 1, + FRAMES = 2 }; -struct __animation { +struct animation { + AnimationType mode; + uint8_t length; uint8_t speed; uint8_t delay; + uint8_t direction; uint8_t *data; }; -typedef struct __text text_t; -typedef struct __animation animation_t; +typedef struct animation animation_t; class Display { private: - text_t active_text; - animation_t active_anim; + animation_t *active_anim; uint8_t need_update; uint8_t active_col; uint8_t disp_buf[8]; 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); void disable(void); @@ -44,9 +38,7 @@ class Display { void reset(void); void update(void); - void show(text_t text); - void show(animation_t anim); - void show(uint8_t *str); + void show(animation_t *anim); }; extern Display display; diff --git a/src/main.cc b/src/main.cc index 76a2046..a8fb5d3 100644 --- a/src/main.cc +++ b/src/main.cc @@ -12,14 +12,19 @@ int main (void) { - text_t ohai; + animation_t ohai; + ohai.mode = AnimationType::TEXT; ohai.speed = (4 << 4) + 15; - ohai.str = (uint8_t *)"Ohai! "; + ohai.data = (uint8_t *)"Ohai! "; + ohai.length = 6; - //uint8_t anim_data[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0 }; + 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; + animation_t test; + test.mode = AnimationType::FRAMES; + test.speed = 14; + test.length = 2*8; + test.data = anim_data; // disable ADC to save power PRR |= _BV(PRADC); @@ -30,7 +35,7 @@ int main (void) // Enable pull-ups on PC3 and PC7 (button pins) PORTC |= _BV(PC3) | _BV(PC7); - display.show(ohai); + display.show(&ohai); display.enable(); modem.enable(); diff --git a/src/system.cc b/src/system.cc index a53b8f1..fa039ce 100644 --- a/src/system.cc +++ b/src/system.cc @@ -77,7 +77,7 @@ void System::loop() i = 0; } else if (modem_byte == 0) { i = 0; - display.show(disp_buf); + //display.show(disp_buf); } } } |