diff --git a/firmware/include/pt1.h b/firmware/include/pt1.h index ec627d9..1590f73 100644 --- a/firmware/include/pt1.h +++ b/firmware/include/pt1.h @@ -9,6 +9,7 @@ struct Pt1 /* PT1: y = y_(n-1) + (Ku - y_(n-1)) * dt/T1 */ Pt1(T K, T T1) : T1(T1), K(K){}; + Pt1() = default; T update(T u, T dt) { diff --git a/firmware/src/applications/beat_detect.cpp b/firmware/src/applications/beat_detect.cpp index 04feed0..5a8fa88 100644 --- a/firmware/src/applications/beat_detect.cpp +++ b/firmware/src/applications/beat_detect.cpp @@ -12,9 +12,9 @@ #define SAMPLING_FREQUENCY_CONTROL \ 1 // check number of times per second if the current band pass is the best // one -#define Q 20. // quality factor of band pass filters +#define Q 30. // quality factor of band pass filters #define PI 3.1415926535897932384626433832795 -#define n_BP 30 // number of band pass filters +#define n_BP 40 // number of band pass filters static const unsigned long sampling_period_bp = 1000000L / SAMPLING_FREQUENCY_BP; static const unsigned long sampling_period_control = 1000000L / SAMPLING_FREQUENCY_CONTROL; @@ -23,7 +23,7 @@ static unsigned long last_us_bp = 0L; static unsigned long last_us_control = 0L; static Biquad bp_filters[n_BP]; -static Pt1 y_filter{1.f, 1.f}; +static Pt1 y_filter[n_BP]; static Pt1 pos_filter{1.f, 1.f}; static float yy1[n_BP]; @@ -45,7 +45,6 @@ static float pos_target_filtered = NUM_LEDS / 2; static long initial_time; static int active = 15; -static int candidate = 15; static int rounds = 0; static int n_samples = 0; @@ -78,6 +77,7 @@ set_filter() a1 = -2.f * cos(w0); a2 = 1.f - a; bp_filters[i] = Biquad{a0, a1, a2, b0, b1, b2}; + y_filter[i] = Pt1{1.f, 1.f}; } } @@ -88,7 +88,6 @@ void BeatDetectApp::init() pos_target = NUM_LEDS / 2; pos_target_filtered = NUM_LEDS / 2; active = 15; - candidate = 15; rounds = 0; n_samples = 0; @@ -128,7 +127,7 @@ void BeatDetectApp::loop() yy3[i] = yy2[i]; yy2[i] = yy1[i]; yy1[i] = y[i]; - y_fil[i] = y_filter.update(std::abs(y[i]), + y_fil[i] = y_filter[i].update(std::abs(y[i]), 0.005f); // linie der scheitelpunkte // y_fil[i] += (abs(y[i]) - y_fil[i]) * 0.005; //linie der // scheitelpunkte @@ -181,8 +180,12 @@ void BeatDetectApp::loop() for (int i = 0; i < NUM_LEDS; i++) { + //leds[i].g = get_value(i, pos_target_filtered); + //leds[i].r = get_value(i, pos_target_filtered + 2); + //leds[i].b = get_value(i, pos_target_filtered - 2); + leds[i].g = get_value(i, pos_target_filtered); - leds[i].r = get_value(i, pos_target_filtered + 2); + leds[i].r = 0; //get_value(i, pos_target_filtered + 2); leds[i].b = get_value(i, pos_target_filtered - 2); // leds[i].setRGB(brightness_red, brightness_green, brightness_blue); @@ -205,22 +208,16 @@ void BeatDetectApp::loop() } } - if (argmax > -1) + if (argmax != active) { - if (argmax == candidate) - { - rounds++; - } - else - { - rounds = 0; - candidate = argmax; - } - if (rounds > 3) - { - rounds = 0; - active = candidate; - } + rounds++; } + + if (rounds > 5) + { + rounds = 0; + active = argmax; + } + } } diff --git a/firmware/src/applications/fackel.cpp b/firmware/src/applications/fackel.cpp index 8c5ce58..318d843 100644 --- a/firmware/src/applications/fackel.cpp +++ b/firmware/src/applications/fackel.cpp @@ -95,7 +95,8 @@ void FackelApp::init() for (int i = 0; i < 128; i++) { uint8_t r, g, b; - hsl_to_rgb(i / 5, 255, i * 2 > 128 ? 128 : i * 2, &r, &g, &b); + //hsl_to_rgb(i / 5, 255, i * 2 > 128 ? 128 : i * 2, &r, &g, &b); + hsl_to_rgb(i / 5 + 180, 255, i * 2 > 128 ? 128 : i * 2, &r, &g, &b); g = g == 1 ? 0 : g; b = b == 1 ? 0 : b; palette[i].r = r; diff --git a/firmware/src/main.cpp b/firmware/src/main.cpp index 8463305..173594a 100644 --- a/firmware/src/main.cpp +++ b/firmware/src/main.cpp @@ -22,10 +22,6 @@ std::vector> apps = { std::ref(fackel_app) }; -<<<<<<< HEAD -unsigned int current_app = 1; -unsigned int next_app; -======= static unsigned int current_app = 0; static unsigned int next_app; static bool init_successfull = false; @@ -55,20 +51,14 @@ void switch_app() { next_app = next_app % apps.size(); } ->>>>>>> update main app handling to include an off state void setup() { next_app = current_app; -<<<<<<< HEAD - zauberstab_init(); - //Serial.begin(115200); -======= if (zauberstab_init() != 0) { return; } Serial.begin(115200); ->>>>>>> update main app handling to include an off state init_successfull = true; apps[current_app].get().init();