summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/storage.cc6
-rw-r--r--src/storage.h2
-rw-r--r--src/system.cc26
-rw-r--r--src/system.h2
4 files changed, 23 insertions, 13 deletions
diff --git a/src/storage.cc b/src/storage.cc
index 042b778..8b725be 100644
--- a/src/storage.cc
+++ b/src/storage.cc
@@ -237,6 +237,11 @@ void Storage::reset()
num_anims = 0;
}
+void Storage::sync()
+{
+ i2c_write(0, 0, 1, &num_anims);
+}
+
bool Storage::hasData()
{
// Unprogrammed EEPROM pages always read 0xff
@@ -259,7 +264,6 @@ void Storage::load(uint8_t idx, uint8_t *data)
void Storage::save(uint8_t *data)
{
num_anims++;
- i2c_write(0, 0, 1, &num_anims);
i2c_write(0, num_anims, 1, &first_free_page);
append(data);
}
diff --git a/src/storage.h b/src/storage.h
index 9eedd52..322555b 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -42,6 +42,8 @@ class Storage {
*/
void reset();
+ void sync();
+
/**
* Checks whether the EEPROM contains animathion data.
*
diff --git a/src/system.cc b/src/system.cc
index e829e72..aa21b00 100644
--- a/src/system.cc
+++ b/src/system.cc
@@ -47,8 +47,8 @@ void System::initialize()
sei();
if (storage.hasData()) {
- current_anim_no = 3;
- loadPattern(3);
+ current_anim_no = 0;
+ loadPattern(0);
} else {
active_anim.type = AnimationType::TEXT;
active_anim.speed = (2 << 4) + 15;
@@ -139,36 +139,40 @@ void System::receive(void)
if (rx_byte == 0x99)
rxExpect = START2;
else
- rxExpect = START_OR_PATTERN;
+ rxExpect = NEXT_BLOCK;
break;
case START2:
if (rx_byte == 0x99) {
rxExpect = PATTERN1;
storage.reset();
} else {
- rxExpect = START_OR_PATTERN;
+ rxExpect = NEXT_BLOCK;
}
break;
- case START_OR_PATTERN:
+ case NEXT_BLOCK:
if (rx_byte == 0x99)
rxExpect = START2;
else if (rx_byte == 0xa9)
rxExpect = PATTERN2;
- else
- rxExpect = START_OR_PATTERN;
+ else if (rx_byte == 0x84) {
+ storage.sync();
+ current_anim_no = 0;
+ loadPattern(0);
+ rxExpect = START1;
+ }
break;
case PATTERN1:
if (rx_byte == 0xa9)
rxExpect = PATTERN2;
else
- rxExpect = START_OR_PATTERN;
+ rxExpect = NEXT_BLOCK;
break;
case PATTERN2:
rx_pos = 0;
if (rx_byte == 0xa9)
rxExpect = HEADER1;
else
- rxExpect = START_OR_PATTERN;
+ rxExpect = NEXT_BLOCK;
break;
case HEADER1:
rxExpect = HEADER2;
@@ -186,7 +190,7 @@ void System::receive(void)
break;
case DATA_FIRSTBLOCK:
if (remaining_bytes == 0) {
- rxExpect = START_OR_PATTERN;
+ rxExpect = NEXT_BLOCK;
storage.save(rx_buf);
} else if (rx_pos == 32) {
rxExpect = DATA;
@@ -196,7 +200,7 @@ void System::receive(void)
break;
case DATA:
if (remaining_bytes == 0) {
- rxExpect = START_OR_PATTERN;
+ rxExpect = NEXT_BLOCK;
storage.append(rx_buf);
} else if (rx_pos == 32) {
rx_pos = 0;
diff --git a/src/system.h b/src/system.h
index 5a2c199..f192389 100644
--- a/src/system.h
+++ b/src/system.h
@@ -24,7 +24,7 @@ class System {
enum RxExpect : uint8_t {
START1,
START2,
- START_OR_PATTERN,
+ NEXT_BLOCK,
PATTERN1,
PATTERN2,
HEADER1,