From 208416b58565ee5a8ea7a1670924dcde4e633663 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 18 Feb 2016 11:19:47 +0100 Subject: system receive state machine: Add START_OR_PATTERN status Needed so that both continuing the current transaction and sending an entirely new one works --- src/storage.h | 3 +-- src/system.cc | 10 ++++++++-- src/system.h | 1 + 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, -- cgit v1.2.3