summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2016-02-01 20:55:10 +0100
committerDaniel Friesel <derf@finalrewind.org>2016-02-01 20:55:10 +0100
commit4bf560b6f3ef6089af04dfc56d078b9978496b07 (patch)
tree1cf523b8b6224de1305a5619f9373daa82085543 /src
parent9d840bb688844458e7ba270ddbb1944d40c317ec (diff)
add animation delay support
Diffstat (limited to 'src')
-rw-r--r--src/display.cc60
-rw-r--r--src/display.h9
-rw-r--r--src/main.cc6
3 files changed, 49 insertions, 26 deletions
diff --git a/src/display.cc b/src/display.cc
index ce7b466..f9be78e 100644
--- a/src/display.cc
+++ b/src/display.cc
@@ -58,33 +58,44 @@ void Display::update() {
if (need_update) {
need_update = 0;
- if (active_anim->type == AnimationType::TEXT) {
- for (i = 0; i < 7; i++) {
- disp_buf[i] = disp_buf[i+1];
+ if (status == RUNNING) {
+ if (active_anim->type == AnimationType::TEXT) {
+ for (i = 0; i < 7; i++) {
+ disp_buf[i] = disp_buf[i+1];
+ }
+
+ glyph_addr = (uint8_t *)pgm_read_ptr(&font[active_anim->data[str_pos]]);
+ glyph_len = pgm_read_byte(&glyph_addr[0]);
+ char_pos++;
+
+ if (char_pos > glyph_len) {
+ char_pos = 0;
+ str_pos++;
+ }
+
+ if (char_pos == 0) {
+ disp_buf[7] = 0xff; // whitespace
+ } else {
+ disp_buf[7] = ~pgm_read_byte(&glyph_addr[char_pos]);
+ }
+ } else if (active_anim->type == AnimationType::FRAMES) {
+ for (i = 0; i < 8; i++) {
+ disp_buf[i] = ~active_anim->data[str_pos+i];
+ }
+ str_pos += 8;
}
-
- glyph_addr = (uint8_t *)pgm_read_ptr(&font[active_anim->data[str_pos]]);
- glyph_len = pgm_read_byte(&glyph_addr[0]);
- char_pos++;
-
- if (char_pos > glyph_len) {
- char_pos = 0;
- str_pos++;
+ if (str_pos >= active_anim->length) {
+ str_pos = 0;
+ if (active_anim->delay > 0) {
+ status = PAUSED;
+ }
}
-
- if (char_pos == 0) {
- disp_buf[7] = 0xff; // whitespace
- } else {
- disp_buf[7] = ~pgm_read_byte(&glyph_addr[char_pos]);
+ } else if (status == PAUSED) {
+ str_pos++;
+ if (str_pos >= active_anim->delay) {
+ str_pos = 0;
+ status = RUNNING;
}
- } else if (active_anim->type == AnimationType::FRAMES) {
- for (i = 0; i < 8; i++) {
- disp_buf[i] = ~active_anim->data[str_pos+i];
- }
- str_pos += 8;
- }
- if (str_pos >= active_anim->length) {
- str_pos = 0;
}
}
}
@@ -95,6 +106,7 @@ void Display::reset()
disp_buf[i] = 0xff;
str_pos = 0;
char_pos = -1;
+ status = RUNNING;
}
void Display::show(animation_t *anim)
diff --git a/src/display.h b/src/display.h
index 5dd6bfe..8e1cca1 100644
--- a/src/display.h
+++ b/src/display.h
@@ -66,6 +66,15 @@ class Display {
uint8_t disp_buf[8];
uint8_t str_pos;
int8_t char_pos;
+
+ enum AnimationStatus : uint8_t {
+ RUNNING,
+ SCROLL_BACK,
+ PAUSED
+ };
+
+ AnimationStatus status;
+
public:
Display();
diff --git a/src/main.cc b/src/main.cc
index 160406c..37dc8bd 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -12,16 +12,18 @@ int main (void)
{
ohai.type = AnimationType::TEXT;
ohai.speed = (2 << 4) + 15;
- ohai.data = (uint8_t *)"\001 Ohai ";
+ ohai.data = (uint8_t *)" Ohai \001";
ohai.length = 8;
+ ohai.delay = (0 << 4) + 0; // -> 4bit 0 remains 0
- uint8_t anim_data[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0 };
+ uint8_t anim_data[] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
animation_t test;
test.type = AnimationType::FRAMES;
test.speed = 14;
test.length = 2*8;
test.data = anim_data;
+ test.delay = (1 << 4);
rocket.initialize();