summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2016-02-22 20:12:53 +0100
committerDaniel Friesel <derf@finalrewind.org>2016-02-22 20:12:53 +0100
commit82a7e72c9dc6bb94180b8b860488b27099939b7c (patch)
treefbf1946e238b365407cb19ffe9e52af841d4b700 /src
parentcb1c87e6a371d405b7064b66002127c9d500c7d4 (diff)
quick&dirty animation switcher
Diffstat (limited to 'src')
-rw-r--r--src/storage.cc1
-rw-r--r--src/storage.h2
-rw-r--r--src/system.cc35
-rw-r--r--src/system.h10
4 files changed, 43 insertions, 5 deletions
diff --git a/src/storage.cc b/src/storage.cc
index 21eed31..2b3ea7c 100644
--- a/src/storage.cc
+++ b/src/storage.cc
@@ -231,6 +231,7 @@ bool Storage::hasData()
return true;
}
+// TODO support multi-page reads
void Storage::load(uint8_t idx, uint8_t *data)
{
uint8_t page_offset;
diff --git a/src/storage.h b/src/storage.h
index d0a4a67..ea294cb 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -47,6 +47,8 @@ class Storage {
*/
bool hasData();
+ uint8_t numPatterns() { return num_anims; };
+
/**
* Load pattern from EEPROM.
*
diff --git a/src/system.cc b/src/system.cc
index 1cbeec1..91c064a 100644
--- a/src/system.cc
+++ b/src/system.cc
@@ -35,13 +35,20 @@ void System::initialize()
storage.reset();
storage.save((uint8_t *)"\x10\x0a\x11\x00nootnoot");
- storage.save((uint8_t *)"\x10\x0a\x20\x00nootnoot");
+ storage.save((uint8_t *)"\x10\x09\x20\x00" "fnordor");
+ storage.save((uint8_t *)"\x10\x05\x20\x00 \x01 ");
+ storage.save((uint8_t *)"\x20\x22\x08\x02"
+ "\x00\x04\x22\x02\x22\x04\x00\x00"
+ "\x00\x00\x00\x00\x00\x00\x00\x00"
+ "\x00\x04\x22\x02\x22\x04\x00\x00"
+ "\x00\x00\x00\x00");
+ storage.append((uint8_t *)"\x00\x00\x00\x00");
sei();
if (storage.hasData()) {
- current_anim_no = 0;
- loadPattern(1);
+ current_anim_no = 3;
+ loadPattern(3);
} else {
active_anim.type = AnimationType::TEXT;
active_anim.speed = (2 << 4) + 15;
@@ -94,7 +101,7 @@ void System::loadPattern(uint8_t anim_no)
active_anim.direction = disp_buf[3] >> 4;
} else if (active_anim.type == AnimationType::FRAMES) {
active_anim.speed = ((disp_buf[2] & 0x0f) << 4) + 15;
- active_anim.delay = (disp_buf[2] & 0x0f) << 4;
+ active_anim.delay = (disp_buf[3] & 0x0f) << 2;
}
active_anim.data = disp_buf + 4;
@@ -233,6 +240,26 @@ void System::loop()
want_shutdown = 0;
}
+ if ((PINC & _BV(PC3)) == 0) {
+ btnMask = (ButtonMask)(btnMask | BUTTON_RIGHT);
+ }
+ if ((PINC & _BV(PC7)) == 0) {
+ btnMask = (ButtonMask)(btnMask | BUTTON_LEFT);
+ }
+ if ((PINC & (_BV(PC3) | _BV(PC7))) == (_BV(PC3) | _BV(PC7))) {
+ if (btnMask == BUTTON_RIGHT) {
+ current_anim_no = (current_anim_no + 1) % storage.numPatterns();
+ loadPattern(current_anim_no);
+ } else if (btnMask == BUTTON_LEFT) {
+ if (current_anim_no == 0)
+ current_anim_no = storage.numPatterns() - 1;
+ else
+ current_anim_no--;
+ loadPattern(current_anim_no);
+ }
+ btnMask = BUTTON_NONE;
+ }
+
while (modem.buffer_available()) {
receive();
}
diff --git a/src/system.h b/src/system.h
index 165ce7b..5a2c199 100644
--- a/src/system.h
+++ b/src/system.h
@@ -14,6 +14,13 @@ class System {
void receive(void);
void loadPattern(uint8_t anim_no);
+ enum ButtonMask : uint8_t {
+ BUTTON_NONE = 0,
+ BUTTON_LEFT = 1,
+ BUTTON_RIGHT = 2,
+ BUTTON_BOTH = 3
+ };
+
enum RxExpect : uint8_t {
START1,
START2,
@@ -29,9 +36,10 @@ class System {
};
RxExpect rxExpect;
+ ButtonMask btnMask;
public:
- System() { want_shutdown = 0; rxExpect = START1; current_anim_no = 0;};
+ System() { want_shutdown = 0; rxExpect = START1; current_anim_no = 0; btnMask = BUTTON_NONE;};
/**
* Initial MCU setup. Turns off unused peripherals to save power