aboutsummaryrefslogtreecommitdiff
path: root/software
diff options
context:
space:
mode:
Diffstat (limited to 'software')
-rw-r--r--software/animation.c0
-rw-r--r--software/animation.h3
-rw-r--r--software/animation.ino5
-rw-r--r--software/consts.h2
-rw-r--r--software/effects.c0
-rw-r--r--software/effects.h13
-rw-r--r--software/effects.ino11
-rw-r--r--software/notes.txt2
-rw-r--r--software/scan.h13
-rw-r--r--software/scan.ino57
-rw-r--r--software/shift.h11
-rw-r--r--software/shift.ino32
-rw-r--r--software/software.h4
-rw-r--r--software/software.ino51
14 files changed, 158 insertions, 46 deletions
diff --git a/software/animation.c b/software/animation.c
deleted file mode 100644
index e69de29..0000000
--- a/software/animation.c
+++ /dev/null
diff --git a/software/animation.h b/software/animation.h
index fce7081..2626291 100644
--- a/software/animation.h
+++ b/software/animation.h
@@ -2,5 +2,4 @@
#include "consts.h"
-unsigned long clamp_time(unsigned long unclamped_time) {
-}
+unsigned long clamp_time(unsigned long unclamped_time);
diff --git a/software/animation.ino b/software/animation.ino
new file mode 100644
index 0000000..547caaa
--- /dev/null
+++ b/software/animation.ino
@@ -0,0 +1,5 @@
+#include "software.h"
+
+unsigned long clamp_time(unsigned long unclamped_time) {
+ return unclamped_time / frame_time_millis * frame_time_millis;
+}
diff --git a/software/consts.h b/software/consts.h
index b9ddb73..4c577e1 100644
--- a/software/consts.h
+++ b/software/consts.h
@@ -10,4 +10,4 @@
#define CONFIG_SRSER_DELAY 20
#define CONFIG_SERIAL_BAUD 115200
-//#define DEBUG
+// #define DEBUG
diff --git a/software/effects.c b/software/effects.c
deleted file mode 100644
index e69de29..0000000
--- a/software/effects.c
+++ /dev/null
diff --git a/software/effects.h b/software/effects.h
index e69de29..04a878a 100644
--- a/software/effects.h
+++ b/software/effects.h
@@ -0,0 +1,13 @@
+#pragma once
+
+// configuratie opties voor de 'diavoorstelling' van de effecten
+#define SLIDESHOW_SIZE (int) 1
+#define SLIDESHOW_DURATION (int) 5e3
+
+// definition of done voor sprint 3
+void fx_roundabout (unsigned long relative_time, bool (*leds)[64]);
+void fx_wipexyz (unsigned long relative_time, bool (*leds)[64]);
+void fx_rainfall (unsigned long relative_time, bool (*leds)[64]);
+
+// evil function pointer array
+extern void ( * slideshow_effects [SLIDESHOW_SIZE] )( unsigned long relative_time, bool (*leds)[64] );
diff --git a/software/effects.ino b/software/effects.ino
new file mode 100644
index 0000000..0600095
--- /dev/null
+++ b/software/effects.ino
@@ -0,0 +1,11 @@
+#include "effects.h"
+
+void fx_roundabout (unsigned long relative_time, bool (*leds)[64]) {
+ return;
+}
+
+void ( * slideshow_effects [SLIDESHOW_SIZE] )( unsigned long relative_time, bool (*leds)[64] ) = {
+ fx_roundabout,
+// fx_wipexyz,
+// fx_rainfall
+};
diff --git a/software/notes.txt b/software/notes.txt
new file mode 100644
index 0000000..1b2580a
--- /dev/null
+++ b/software/notes.txt
@@ -0,0 +1,2 @@
+example [ 0, 1, 1, 0, 1, 0, 0 ]
+result [ 0, 1, 1, 0, 1, 0, 0 ]
diff --git a/software/scan.h b/software/scan.h
new file mode 100644
index 0000000..0c19763
--- /dev/null
+++ b/software/scan.h
@@ -0,0 +1,13 @@
+#pragma once
+
+#define SCAN_HOR 0
+#define SCAN_VER 1
+extern unsigned char scan_direction;
+extern unsigned char scan_index;
+extern unsigned char scan_order[8];
+
+unsigned char get_state_row(unsigned char row, unsigned char direction);
+
+void scan();
+void optimize_scan();
+
diff --git a/software/scan.ino b/software/scan.ino
new file mode 100644
index 0000000..5500f98
--- /dev/null
+++ b/software/scan.ino
@@ -0,0 +1,57 @@
+#include "scan.h"
+#include "shift.h"
+#include "software.h"
+
+unsigned char scan_direction = 0;
+unsigned char scan_index = 0;
+unsigned char scan_order[8] = {1};
+
+unsigned char get_state_row(unsigned char row, unsigned char direction) {
+ unsigned char return_value;
+
+ for (int i = 0; i < 8; i++)
+ return_value = return_value | ( led_state[ direction == SCAN_HOR ?
+ (i + row * 8) : (row + i * 8) ] << (7 - i));
+
+ return return_value;
+}
+
+void scan() {
+ unsigned char scan_row = 0xff ^ (1 << scan_index);
+
+ shift_state[scan_direction] = scan_row;
+ shift_state[!scan_direction] = get_state_row(scan_index, scan_direction);
+
+ // update physical state of shift register
+ update_shift_state();
+
+ // go to next row/column
+ for(int i = scan_index + 1; i < (scan_index + 7); i++) {
+ if (scan_order[i % 8] == 0) continue;
+ scan_index = i % 8;
+ break;
+ }
+}
+
+void optimize_scan() {
+ unsigned char optimal_direction = 0,
+ hv_emptyc[2] = {0},
+ hv_empty[2][8] = {0},
+ optimal_scan_index = 0;
+
+ // calculate empty rows/columns
+ for(unsigned char direction = 0; direction < 2; direction++) {
+ for(unsigned char row; row < 8; row++) {
+ if (get_state_row(row, direction) == 0) {
+ hv_empty[direction][row] = 1;
+ hv_emptyc[direction]++;
+ }
+ }
+ }
+
+ optimal_direction = hv_emptyc[0] > hv_emptyc[1] ? 0 : 1;
+ memcpy(&scan_order, &hv_emptyc[optimal_direction], sizeof(scan_order));
+
+ return;
+}
+
diff --git a/software/shift.h b/software/shift.h
new file mode 100644
index 0000000..61b0557
--- /dev/null
+++ b/software/shift.h
@@ -0,0 +1,11 @@
+#pragma once
+
+#define SR_ROW 0
+#define SR_COL 1
+extern unsigned char shift_state[2];
+
+/** @brief shift shift_state naar de shift registers */
+void update_shift_state();
+
+/** @brief direct data naar de shift registers sturen */
+void shift(unsigned char data);
diff --git a/software/shift.ino b/software/shift.ino
new file mode 100644
index 0000000..b27795a
--- /dev/null
+++ b/software/shift.ino
@@ -0,0 +1,32 @@
+#include "shift.h"
+#include "consts.h"
+
+unsigned char shift_state[2] = {0};
+
+void update_shift_state() {
+ for(int i = 0; i < 2; i++)
+ shift(shift_state[i]);
+}
+
+void shift(unsigned char data) {
+ #ifdef DEBUG
+ Serial.print("Sending data to shift register: ");
+ Serial.println(data, BIN);
+ #endif
+
+ // pull down latch
+ digitalWrite(PINOUT_LCK, LOW);
+
+ for(int i = 0; i < 8; i++) {
+ bool bit = (data & 1 << i) > 0;
+
+ // schrijf bit en pulse serial clock
+ digitalWrite(PINOUT_SER, bit);
+ digitalWrite(PINOUT_SCK, HIGH);
+ delayMicroseconds(CONFIG_SRSER_DELAY);
+ digitalWrite(PINOUT_SCK, LOW);
+ }
+
+ // pull up latch
+ digitalWrite(PINOUT_LCK, HIGH);
+}
diff --git a/software/software.h b/software/software.h
new file mode 100644
index 0000000..45fe907
--- /dev/null
+++ b/software/software.h
@@ -0,0 +1,4 @@
+#pragma once
+
+extern bool led_state[64];
+extern unsigned long frame_time_millis;
diff --git a/software/software.ino b/software/software.ino
index 8c454ac..323a79b 100644
--- a/software/software.ino
+++ b/software/software.ino
@@ -1,30 +1,13 @@
+#include "software.h"
#include "consts.h"
+#include "effects.h"
+#include "scan.h"
-extern unsigned long frame_time_millis;
-bool led_state[64];
-
-void shift(unsigned char data) {
- #ifdef DEBUG
- Serial.print("Sending data to shift register: ");
- Serial.println(data, BIN);
- #endif
+unsigned long frame_time_millis = 0;
- // pull down latch register
- digitalWrite(PINOUT_LCK, LOW);
-
- for(int i = 0; i < 8; i++) {
- bool bit = data & 1 << i > 0;
+bool led_state[64];
- // schrijf bit en pulse serial clock
- digitalWrite(PINOUT_SER, bit);
- digitalWrite(PINOUT_SCK, HIGH);
- delayMicroseconds(CONFIG_SRSER_DELAY);
- digitalWrite(PINOUT_SCK, LOW);
- }
-
- // pull up latch register
- digitalWrite(PINOUT_LCK, HIGH);
-}
+bool scan_enable = true;
void setup() {
pinMode(PINOUT_SER, OUTPUT);
@@ -38,26 +21,6 @@ void setup() {
frame_time_millis = 1000 / CONFIG_FRAMERATE * CONFIG_FRAMERATE;
}
-void test_effect1(unsigned long relative_time, bool (*leds)[64]) {
- return;
-}
-void test_effect2(unsigned long relative_time, bool (*leds)[64]) {
- return;
-}
-void test_effect3(unsigned long relative_time, bool (*leds)[64]) {
- return;
-}
-
-
-#define SLIDESHOW_SIZE ( (int) 3 )
-#define SLIDESHOW_DURATION ( (int) 5e3 )
-// evil function pointer array
-void ( * slideshow_effects [SLIDESHOW_SIZE] )( unsigned long relative_time, bool (*leds)[64] ) = {
- test_effect1,
- test_effect2,
- test_effect3
-};
-
void loop() {
unsigned long current_time = millis();
@@ -65,4 +28,6 @@ void loop() {
unsigned int slide_index = (current_time / SLIDESHOW_DURATION) % SLIDESHOW_SIZE;
slideshow_effects[slide_index](slide_time, &led_state);
+
+ if (scan_enable) scan();
}