summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MessageSpecification.md3
-rw-r--r--src/storage.cc6
-rw-r--r--src/storage.h2
-rw-r--r--src/system.cc26
-rw-r--r--src/system.h2
-rw-r--r--utilities/blinkenrocket.py2
-rw-r--r--utilities/test_blinkenrocket.py4
7 files changed, 30 insertions, 15 deletions
diff --git a/MessageSpecification.md b/MessageSpecification.md
index 32acb24..62ca1c6 100644
--- a/MessageSpecification.md
+++ b/MessageSpecification.md
@@ -11,6 +11,9 @@ A *`START`* signal which indicates the start of a transmission. It consists of t
##### PATTERN
A *`PATTERN`* signal which indicates that either the start of an animation or text pattern. It consists of two times the 8-bit binary pattern ( `10101001` respectively `0xA9`)
+##### END
+The *`END`* signal indicates End Of Transmission. It consists of two times the 8-bit binary pattern `10000100` respectively `0x84`.
+
##### HEADER
A generic *`HEADER`* which contains two byte of metadata to describe the data that follows. The two byte contain 12 bit of length information and 4 bit of data type information.
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,
diff --git a/utilities/blinkenrocket.py b/utilities/blinkenrocket.py
index a6afe8a..01c7d73 100644
--- a/utilities/blinkenrocket.py
+++ b/utilities/blinkenrocket.py
@@ -195,6 +195,7 @@ class blinkenrocket():
eeprom_size = 65536
startcode = chr(0x99)
patterncode = chr(0xA9)
+ endcode = chr(0x84)
frames = []
def __init__(self,eeprom_size=65536):
@@ -211,6 +212,7 @@ class blinkenrocket():
for frame in self.frames:
output.extend([self.patterncode,self.patterncode])
output.extend(frame.getRepresentation())
+ output.extend([self.endcode,self.endcode])
return output
diff --git a/utilities/test_blinkenrocket.py b/utilities/test_blinkenrocket.py
index b2da0fd..62bd0e3 100644
--- a/utilities/test_blinkenrocket.py
+++ b/utilities/test_blinkenrocket.py
@@ -110,8 +110,8 @@ class TestBlinkenrocket(unittest.TestCase):
self.assertEquals(text.getRepresentation(),[chr(0x01 << 4), chr(4),chr(7 << 4 | 8),chr(1 << 4 | 0),'M','U','Z','Y'])
br = blinkenrocket()
br.addFrame(text)
- expect = [chr(0x99),chr(0x99),chr(0xA9),chr(0xA9),chr(0x01 << 4), chr(4),chr(7 << 4 | 8),chr(1 << 4 | 0),'M','U','Z','Y']
+ expect = [chr(0x99),chr(0x99),chr(0xA9),chr(0xA9),chr(0x01 << 4), chr(4),chr(7 << 4 | 8),chr(1 << 4 | 0),'M','U','Z','Y',chr(0x84),chr(0x84)]
self.assertEquals(br.getMessage(),expect)
if __name__ == '__main__':
- unittest.main() \ No newline at end of file
+ unittest.main()