From 0ee7d763090e32118829fb897ff8ad4261c3c27e Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 12 Mar 2016 22:07:12 +0100 Subject: >255byte pattern support, commit 2/2 --- src/display.cc | 16 ++++++++++++++-- src/display.h | 3 ++- src/storage.cc | 9 ++------- src/storage.h | 2 +- src/system.cc | 5 +++-- 5 files changed, 22 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/display.cc b/src/display.cc index ed1880e..025ebbf 100644 --- a/src/display.cc +++ b/src/display.cc @@ -15,6 +15,7 @@ #include "display.h" #include "font.h" +#include "storage.h" Display display; @@ -84,7 +85,7 @@ void Display::update() { if (current_anim->direction == 0) glyph_addr = (uint8_t *)pgm_read_ptr(&font[current_anim->data[str_pos]]); else - glyph_addr = (uint8_t *)pgm_read_ptr(&font[current_anim->data[current_anim->length - 1 - str_pos]]); + glyph_addr = (uint8_t *)pgm_read_ptr(&font[current_anim->data[current_anim->length - 1 - str_pos]]); // XXX Broken by str_chunk changes, FIXME! glyph_len = pgm_read_byte(&glyph_addr[0]); char_pos++; @@ -113,11 +114,21 @@ void Display::update() { } str_pos += 8; } - if (str_pos >= current_anim->length) { + if ((current_anim->length >= 128) && (str_pos >= 128)) { + str_pos = 0; + str_chunk++; + storage.loadChunk(str_chunk, current_anim->data); + } + if ((str_chunk == (current_anim->length / 128)) + && (str_pos >= (current_anim->length % 128))) { + str_chunk = 0; str_pos = 0; if (current_anim->delay > 0) { status = PAUSED; } + if (current_anim->length >= 128) { + storage.loadChunk(str_chunk, current_anim->data); + } } } else if (status == PAUSED) { str_pos++; @@ -134,6 +145,7 @@ void Display::reset() for (uint8_t i = 0; i < 8; i++) disp_buf[i] = 0xff; str_pos = 0; + str_chunk = 0; char_pos = -1; need_update = 1; status = RUNNING; diff --git a/src/display.h b/src/display.h index 41b3c83..b42c69e 100644 --- a/src/display.h +++ b/src/display.h @@ -34,7 +34,7 @@ struct animation { /** * Length of data in bytes */ - uint8_t length; + uint16_t length; /** * * If type == AnimationType::TEXT: Text scroll speed in columns per TODO @@ -75,6 +75,7 @@ class Display { uint8_t active_col; uint8_t disp_buf[8]; uint8_t str_pos; + uint8_t str_chunk; int8_t char_pos; enum AnimationStatus : uint8_t { diff --git a/src/storage.cc b/src/storage.cc index e965589..7cf404b 100644 --- a/src/storage.cc +++ b/src/storage.cc @@ -268,13 +268,8 @@ void Storage::load(uint8_t idx, uint8_t *data) header[0] = data[0]; header[1] = data[1]; - if (header[0] & 0x0f) { - // read whole byte block - i2c_read(1 + (page_offset / 8), (page_offset % 8) * 32 + 4, 128, data + 4); - i2c_read(1 + (page_offset / 8), (page_offset % 8) * 32 + 4 + 128, 128, data + 4 + 128); - } else { - i2c_read(1 + (page_offset / 8), (page_offset % 8) * 32 + 4, header[1], data + 4); - } + // always read 128 bytes - the system will ignore trailing bytes + i2c_read(1 + (page_offset / 8), (page_offset % 8) * 32 + 4, 128, data + 4); } void Storage::loadChunk(uint8_t chunk, uint8_t *data) diff --git a/src/storage.h b/src/storage.h index e7feedb..c72b766 100644 --- a/src/storage.h +++ b/src/storage.h @@ -80,7 +80,7 @@ class Storage { * * @param idx pattern index (starting with 0) * @param data pointer to data structure for the pattern. Must be - * at least 260 bytes + * at least 132 bytes */ void load(uint8_t idx, uint8_t *data); diff --git a/src/system.cc b/src/system.cc index 759c58e..37e9ea5 100644 --- a/src/system.cc +++ b/src/system.cc @@ -27,7 +27,7 @@ System rocket; animation_t active_anim; -uint8_t disp_buf[260]; // 4 byte header + 256 byte data +uint8_t disp_buf[132]; // 4 byte header + 128 byte data uint8_t *rx_buf = disp_buf + sizeof(disp_buf) - 33; void System::initialize() @@ -78,7 +78,8 @@ void System::loadPattern_P(const uint8_t *pattern_ptr) void System::loadPattern_buf(uint8_t *pattern) { active_anim.type = (AnimationType)(pattern[0] >> 4); - active_anim.length = pattern[1]; + active_anim.length = (pattern[0] & 0x0f) << 8; + active_anim.length += pattern[1]; if (active_anim.type == AnimationType::TEXT) { active_anim.speed = (pattern[2] & 0xf0) + 15; -- cgit v1.2.3