aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2021-11-27 16:38:14 +0100
committerlonkaars <loek@pipeframe.xyz>2021-11-27 16:38:14 +0100
commit2536355a1e48dba558b5c4beceae9aa63c1900c9 (patch)
tree2da1a0da313b12944f976c75d5b9e1f938cba4ee
parent9514e58a83f66b57c24bc6a2b4141e9ef475e326 (diff)
implemented animation 3
also fixed memory leak caused by pointer arithmetic -> 0xf0 != 0x10
-rw-r--r--software/animation.ino8
-rw-r--r--software/consts.h5
-rw-r--r--software/effects.h8
-rw-r--r--software/effects.ino39
-rw-r--r--software/software.ino13
-rw-r--r--software/util.h4
-rw-r--r--software/util.ino20
7 files changed, 71 insertions, 26 deletions
diff --git a/software/animation.ino b/software/animation.ino
index e59bfa1..edd0c82 100644
--- a/software/animation.ino
+++ b/software/animation.ino
@@ -4,6 +4,10 @@ unsigned long clamp_time(unsigned long unclamped_time) {
return unclamped_time / frame_time_millis * frame_time_millis;
}
+unsigned long get_frame(unsigned long relative_time) {
+ return relative_time / frame_time_millis;
+}
+
unsigned int zigzag(unsigned int size, int index) {
unsigned int zigzag_size = 2 * size - 2;
unsigned int mod = index % zigzag_size;
@@ -19,11 +23,11 @@ void fill_plane(unsigned int direction, unsigned int offset) {
unsigned int axis2_weight = pow((direction - 1) % 3, 4);
unsigned int axis3_weight = pow((direction ) % 3, 4);
- led_state[
+ led_state[led_map[
axis1_offset * axis1_weight +
axis2_offset * axis2_weight +
offset * axis3_weight
- ] = 1;
+ ]] = 1;
}
}
diff --git a/software/consts.h b/software/consts.h
index b0b7075..ed4572d 100644
--- a/software/consts.h
+++ b/software/consts.h
@@ -4,13 +4,14 @@
#define PINOUT_SCK 4
#define PINOUT_SER 2
#define PINOUT_LCK 3
+#define PINOUT_NOISE A0
// animation framerate
#define CONFIG_FRAMERATE 60
// debug options
-// #define CONFIG_SERIAL_BAUD 115200
-// #define DEBUG
+#define CONFIG_SERIAL_BAUD 115200
+#define DEBUG
/**
* @brief map 3D cube coordinates to `led_state` indices
diff --git a/software/effects.h b/software/effects.h
index 9f7ec39..745c149 100644
--- a/software/effects.h
+++ b/software/effects.h
@@ -6,12 +6,12 @@
// #define SLIDESHOW_DURATION (int) 5e3
// definition of done 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]);
+void fx_roundabout (unsigned long relative_time);
+void fx_wipexyz (unsigned long relative_time);
+void fx_rainfall (unsigned long relative_time);
// evil function pointer array
-extern void ( * slideshow_effects [SLIDESHOW_SIZE] )( unsigned long relative_time, bool (*leds)[64] );
+extern void ( * slideshow_effects [SLIDESHOW_SIZE] )( unsigned long relative_time );
#ifndef SLIDESHOW_DURATION
extern unsigned long slideshow_lengths[SLIDESHOW_SIZE];
#endif
diff --git a/software/effects.ino b/software/effects.ino
index 0fc776a..6cf2cfc 100644
--- a/software/effects.ino
+++ b/software/effects.ino
@@ -1,10 +1,10 @@
-#include "const.h"
+#include "consts.h"
#include "effects.h"
#include "animation.h"
#define FX_LEN_ROUNDABOUT 5e3
-void fx_roundabout (unsigned long relative_time, bool (*leds)[64]) {
- memset(leds, 0, sizeof(leds));
+void fx_roundabout (unsigned long relative_time) {
+ memset(led_state, 0, sizeof(led_state));
unsigned long tick = relative_time / 300;
unsigned int roundabout_coordinates[12] = {
0x0, 0x1, 0x2, 0x3, 0x7, 0xb,
@@ -13,15 +13,15 @@ void fx_roundabout (unsigned long relative_time, bool (*leds)[64]) {
for(int trail = 0; trail < 4; trail++) {
unsigned int xy_coords = roundabout_coordinates[(tick + trail) % 12];
- for(int z = 0; z < 4; z++) *leds[led_map[xy_coords + z * 0xf0]] = 1;
+ for(int z = 0; z < 4; z++) led_state[led_map[xy_coords + z * 0x10]] = 1;
}
return;
}
#define FX_LEN_WIPEXYZ 6e3
-void fx_wipexyz (unsigned long relative_time, bool (*leds)[64]) {
- memset(leds, 0, sizeof(leds));
+void fx_wipexyz (unsigned long relative_time) {
+ memset(led_state, 0, sizeof(led_state));
unsigned long tick = relative_time / 200;
unsigned int direction = (tick / 6) % 3;
@@ -31,29 +31,36 @@ void fx_wipexyz (unsigned long relative_time, bool (*leds)[64]) {
}
#define FX_LEN_RAINFALL 7e3
-void fx_rainfall (unsigned long relative_time, bool (*leds)[64]) {
-
+unsigned long last_frame;
+void fx_rainfall (unsigned long relative_time) {
+ unsigned long frame = get_frame(relative_time);
+ // only update on new frame
+ if (last_frame != frame) {
+ for (int i = 0x00; i < 0x30; i++) led_state[led_map[i]] = led_state[led_map[i + 0x10]];
+ for (int i = 0x30; i < 0x40; i++) led_state[led_map[i]] = random(0xff) < 0x10;
+ }
+ last_frame = frame;
return;
}
-void ( * slideshow_effects [SLIDESHOW_SIZE] )( unsigned long relative_time, bool (*leds)[64] ) = {
- fx_roundabout,
- fx_wipexyz,
- fx_rainfall
+void ( * slideshow_effects [SLIDESHOW_SIZE] )( unsigned long relative_time ) = {
+ fx_roundabout,
+ fx_wipexyz,
+ fx_rainfall,
};
#ifndef SLIDESHOW_DURATION
unsigned long slideshow_lengths[SLIDESHOW_SIZE] = {
FX_LEN_ROUNDABOUT,
FX_LEN_WIPEXYZ,
- FX_LEN_RAINFALL
+ FX_LEN_RAINFALL,
};
#endif
-/* void test_leds_inorder (unsigned long relative_time, bool (*leds)[64]) {
+/* void test_leds_inorder (unsigned long relative_time)[64]) {
+ memset(led_state, 0, sizeof(led_state));
unsigned long segment_time = SLIDESHOW_DURATION / 64;
- memset(leds, 0, sizeof(leds));
- *leds[(relative_time / segment_time) % 64] = 1;
+ led_state[(relative_time / segment_time) % 64] = 1;
return;
} */
diff --git a/software/software.ino b/software/software.ino
index ca2b7c0..4cea2b4 100644
--- a/software/software.ino
+++ b/software/software.ino
@@ -15,8 +15,12 @@ void setup() {
pinMode(PINOUT_SCK, OUTPUT);
pinMode(PINOUT_LCK, OUTPUT);
+ pinMode(PINOUT_NOISE, INPUT); // random noise voor RNG
+ randomSeed(analogRead(PINOUT_NOISE));
+
#ifdef DEBUG
Serial.begin(CONFIG_SERIAL_BAUD);
+ Serial.println("startup");
#endif
#ifndef SLIDESHOW_DURATION
@@ -24,7 +28,7 @@ void setup() {
slideshow_length_total += slideshow_lengths[i];
#endif
- frame_time_millis = 1000 / CONFIG_FRAMERATE * CONFIG_FRAMERATE;
+ frame_time_millis = (int)((double) 1000 / (double) CONFIG_FRAMERATE);
}
void loop() {
@@ -41,10 +45,15 @@ void loop() {
slide_sum += slideshow_lengths[i];
if (slide_time >= slide_sum) continue;
slide_index = i;
+ slide_time -= slide_sum - slideshow_lengths[i];
break;
}
#endif
- slideshow_effects[slide_index](slide_time, &led_state);
+
+ #ifdef DEBUG
+ print_ani_debug(slide_index, slide_time);
+ #endif
+ slideshow_effects[slide_index](slide_time);
if (scan_enable) scan();
}
diff --git a/software/util.h b/software/util.h
index 654fa95..1dcca8c 100644
--- a/software/util.h
+++ b/software/util.h
@@ -5,5 +5,9 @@
void print_binary_number(unsigned char data);
/** @brief [DEBUG] print led_state in 8x8 grid */
void print_led_state();
+/** @brief [DEBUG] pad and print number */
+void print_padded_number(unsigned int number, char* pad_with, unsigned int pad_count);
+/** @brief [DEBUG] print time and animation info */
+void print_ani_debug(unsigned int effect_index, unsigned long relative_time);
#endif
diff --git a/software/util.ino b/software/util.ino
index ef680c4..5a8ed12 100644
--- a/software/util.ino
+++ b/software/util.ino
@@ -1,5 +1,6 @@
#ifdef DEBUG
#include "software.h"
+#include "animation.h"
void print_binary_number(unsigned char data) {
for(int i = 7; i >= 0; i--) Serial.print((data & (1 << i)) > 0, DEC);
@@ -15,4 +16,23 @@ void print_led_state() {
}
}
+void print_padded_number(unsigned int number, char* pad_with, unsigned int pad_count) {
+ unsigned int pad_amount = pad_count - (int) log10(number);
+ for(int i = 0; i < pad_amount; i++) Serial.print(pad_with);
+ Serial.print(number, DEC);
+}
+
+void print_ani_debug(unsigned int effect_index, unsigned long relative_time) {
+ Serial.print("[");
+ print_padded_number(effect_index + 1, "0", 2);
+ Serial.print("] time ");
+ print_padded_number(relative_time / 1000, " ", 2);
+ Serial.print(",");
+ print_padded_number(relative_time % 1000, "0", 2);
+ Serial.print(" frame ");
+ print_padded_number(get_frame(relative_time), " ", 2);
+ Serial.print("\r\n");
+}
+
#endif
+