summaryrefslogtreecommitdiff
path: root/src/system.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/system.cc')
-rw-r--r--src/system.cc66
1 files changed, 64 insertions, 2 deletions
diff --git a/src/system.cc b/src/system.cc
index 3dc21d9..dd09b5a 100644
--- a/src/system.cc
+++ b/src/system.cc
@@ -13,9 +13,9 @@
System rocket;
-extern animation_t ohai;
+animation_t active_anim;
-uint8_t disp_buf[128];
+uint8_t disp_buf[260]; // 4 byte header + 256 byte data
uint8_t *rx_buf = disp_buf + 64;
void System::initialize()
@@ -34,6 +34,68 @@ void System::initialize()
storage.enable();
sei();
+
+ if (storage.hasData()) {
+ current_anim_no = 0;
+ loadPattern(0);
+ } else {
+ active_anim.type = AnimationType::TEXT;
+ active_anim.speed = (2 << 4) + 15;
+ active_anim.data = disp_buf;
+ active_anim.length = 26;
+ active_anim.delay = (0 << 4) + 0;
+
+ // no strcpy_P or similar to save space
+ disp_buf[0] = ' ';
+ disp_buf[1] = 1;
+ disp_buf[2] = ' ';
+ disp_buf[3] = 'O';
+ disp_buf[4] = 'h';
+ disp_buf[5] = 'a';
+ disp_buf[6] = 'i';
+ disp_buf[7] = ' ';
+ disp_buf[8] = '-';
+ disp_buf[9] = ' ';
+ disp_buf[10] = 'S';
+ disp_buf[11] = 't';
+ disp_buf[12] = 'o';
+ disp_buf[13] = 'r';
+ disp_buf[14] = 'a';
+ disp_buf[15] = 'g';
+ disp_buf[16] = 'e';
+ disp_buf[17] = ' ';
+ disp_buf[18] = 'i';
+ disp_buf[19] = 's';
+ disp_buf[20] = ' ';
+ disp_buf[21] = 'e';
+ disp_buf[22] = 'm';
+ disp_buf[23] = 'p';
+ disp_buf[24] = 't';
+ disp_buf[25] = 'y';
+ }
+
+ display.show(&active_anim);
+}
+
+void System::loadPattern(uint8_t anim_no)
+{
+ storage.load(anim_no, disp_buf);
+
+ active_anim.type = (AnimationType)(disp_buf[0] >> 4);
+ active_anim.length = disp_buf[1];
+
+ if (active_anim.type == AnimationType::TEXT) {
+ active_anim.speed = (disp_buf[2] & 0xf0) + 15;
+ active_anim.delay = (disp_buf[2] & 0x0f ) << 4;
+ active_anim.direction = disp_buf[3] >> 4;
+ } else if (active_anim.type == AnimationType::FRAMES) {
+ active_anim.speed = ((disp_buf[2] & 0x0f) << 4) + 15;
+ active_anim.delay = (disp_buf[2] & 0x0f) << 4;
+ }
+
+ active_anim.data = disp_buf + 4;
+
+ display.show(&active_anim);
}
// ! This function has not been tested yet