summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2016-02-18 11:19:47 +0100
committerDaniel Friesel <derf@finalrewind.org>2016-02-18 11:19:47 +0100
commit208416b58565ee5a8ea7a1670924dcde4e633663 (patch)
treec8e5540db31850903bd6e8c3d365c52375a6db3d
parent319bb58fa93421283a4c0b9cbf8f474f11a1530e (diff)
system receive state machine: Add START_OR_PATTERN status
Needed so that both continuing the current transaction and sending an entirely new one works
-rw-r--r--src/storage.h3
-rw-r--r--src/system.cc10
-rw-r--r--src/system.h1
3 files changed, 10 insertions, 4 deletions
diff --git a/src/storage.h b/src/storage.h
index 10cdbc5..fd7b0ad 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -13,9 +13,8 @@ class Storage {
int8_t i2c_receive(uint8_t len, uint8_t *data);
int8_t i2c_read(uint16_t addr, uint8_t len, uint8_t *data);
int8_t i2c_write(uint16_t addr, uint8_t len, uint8_t *data);
- // TODO "file system" housekeeping (index of first free page)
public:
- Storage() { num_anims = 0xff; first_free_page = 0;};
+ Storage() { num_anims = 0; first_free_page = 0;};
/**
* Enable the storage hardware: Configures the internal I2C
diff --git a/src/system.cc b/src/system.cc
index eb2caf6..d2231b4 100644
--- a/src/system.cc
+++ b/src/system.cc
@@ -65,6 +65,12 @@ void System::receive(void)
storage.reset();
}
break;
+ case START_OR_PATTERN:
+ if (rx_byte == 0x99)
+ rxExpect = START2;
+ else if (rx_byte == 0xa9)
+ rxExpect = PATTERN2;
+ break;
case PATTERN1:
if (rx_byte == 0xa9)
rxExpect = PATTERN2;
@@ -91,7 +97,7 @@ void System::receive(void)
case DATA_FIRSTBLOCK:
remaining_bytes--;
if (remaining_bytes == 0) {
- rxExpect = PATTERN1; // TODO or new START1
+ rxExpect = START_OR_PATTERN;
storage.save(rx_buf);
} else if (rx_pos == 64) {
rxExpect = DATA;
@@ -102,7 +108,7 @@ void System::receive(void)
case DATA:
remaining_bytes--;
if (remaining_bytes == 0) {
- rxExpect = PATTERN1; // TODO or new START1
+ rxExpect = START_OR_PATTERN;
storage.append(rx_buf);
} else if (rx_pos == 64) {
rx_pos = 0;
diff --git a/src/system.h b/src/system.h
index 764ef95..14dc257 100644
--- a/src/system.h
+++ b/src/system.h
@@ -15,6 +15,7 @@ class System {
enum RxExpect : uint8_t {
START1,
START2,
+ START_OR_PATTERN,
PATTERN1,
PATTERN2,
HEADER1,