aboutsummaryrefslogtreecommitdiff
path: root/software/scan.ino
diff options
context:
space:
mode:
Diffstat (limited to 'software/scan.ino')
-rw-r--r--software/scan.ino21
1 files changed, 13 insertions, 8 deletions
diff --git a/software/scan.ino b/software/scan.ino
index b369609..156627b 100644
--- a/software/scan.ino
+++ b/software/scan.ino
@@ -1,7 +1,10 @@
#include "scan.h"
#include "shift.h"
#include "software.h"
+
+#ifdef DEBUG
#include "util.h"
+#endif
// 0 = horizontal (top-bottom), 1 = vertical (left-right)
unsigned char scan_direction = 0;
@@ -19,7 +22,7 @@ unsigned char get_state_row(unsigned char row, unsigned char direction) {
}
void scan() {
- optimize_scan();
+ // optimize_scan();
shift_state[0] = 0x00 ^ (1 << scan_index);
shift_state[1] = 0xff ^ get_state_row(scan_index, scan_direction);
@@ -33,27 +36,29 @@ void scan() {
break;
}
}
+
void optimize_scan() {
unsigned char optimal_direction,
- hv_emptyc[2] = {0},
- hv_empty[2][8] = {0};
+ hv_emptyc[2] = {0, 0},
+ hv_empty[2][8];
// 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]++;
- }
+ hv_empty[direction][row] = get_state_row(row, direction) == 0;
+ hv_emptyc[direction] += hv_empty[direction][row];
}
}
+ // print_led_state();
+ // delay(20);
+
Serial.print("[ ");
for(int i = 0; i < 8; i++) {
Serial.print((unsigned int) hv_empty[0][i], DEC);
if(i != 7) Serial.print(", ");
}
- Serial.print(" ]");
+ Serial.print(" ] ");
optimal_direction = hv_emptyc[0] > hv_emptyc[1] ? 0 : 1;