diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2ea484 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +generated_3d +build +*.FCStd1 +*.blend1 \ No newline at end of file diff --git a/espmusicmouse/lib/ledtl/effects/AlexaSwipe.h b/espmusicmouse/lib/ledtl/effects/AlexaSwipe.h index d21557b..5809793 100644 --- a/espmusicmouse/lib/ledtl/effects/AlexaSwipe.h +++ b/espmusicmouse/lib/ledtl/effects/AlexaSwipe.h @@ -13,6 +13,7 @@ struct EffectAlexaSwipeConfig float swipeSpeed; // in degrees per second float bellCurveWidthInLeds; float startPosition; + bool forward; ColorRGBW primaryColor; ColorRGBW secondaryColor; }; @@ -39,6 +40,16 @@ public: primaryColor_(rgb2hsv(cfg.primaryColor)), secondaryColor_(rgb2hsv(cfg.secondaryColor)) { + if (cfg.forward) + { + currentPosition_ = 0; + direction_ = 1; + } + else + { + currentPosition_ = float(NUM_LEDS) / 2.0f + bellCurveWidth_ / 2; + direction_ = -1; + } //#ifndef PLATFORM_NATIVE // Serial.printf("Primary color %f, %f, %f\n", primaryColor_.h, primaryColor_.s, primaryColor_.v); // Serial.printf("Secondary color %f, %f, %f\n", secondaryColor_.h, secondaryColor_.s, secondaryColor_.v); @@ -60,19 +71,17 @@ public: const int led1 = startPosition_ + i; const int led2 = startPosition_ - i; const ColorRGBW color = getColor(x); - //#ifndef PLATFORM_NATIVE - // Serial.printf("Setting %d and %d to %d, %d, %d\n", led1, led2, color.r, color.g, color.b); - //#endif setLedRGBW(ledStrip_, led1, color); setLedRGBW(ledStrip_, led2, color); } } - currentPosition_ += speed_; + currentPosition_ += direction_ * speed_; currentPosition_ = std::min(currentPosition_, float(NUM_LEDS) / 2.0f + bellCurveWidth_ / 2); + currentPosition_ = std::max(currentPosition_, 0.0f); return DELAY_MS; } - //private: +private: void getParams(float x, float &interpFac, float &brightness) { brightness = (x < bellCurveWidth_) ? bellCurveApproximation(bellCurveWidth_ / 2 - x, invBellCurveWidth_) : 1.0f; @@ -95,14 +104,7 @@ public: interpFac * secondaryColor_.s + (1.0f - interpFac) * primaryColor_.s, interpFac * secondaryColor_.v + (1.0f - interpFac) * primaryColor_.v}; result.v *= brightness; - - const auto converted = hsv2rgb(result); - //#ifndef PLATFORM_NATIVE - // Serial.printf("Coord %f, interp %f, bright %f, h %f, s %f, v %f, r %d, g %d, b %d\n", x, - // interpFac, brightness, result.h, result.s, result.v, converted.r, - // converted.g, converted.b); - //#endif - return converted; + return hsv2rgb(result); } TLedStrip &ledStrip_; @@ -120,6 +122,7 @@ public: const ColorHSV primaryColor_; const ColorHSV secondaryColor_; + float direction_; }; // Traits diff --git a/espmusicmouse/src/main.cpp b/espmusicmouse/src/main.cpp index b31c25a..7a36dda 100644 --- a/espmusicmouse/src/main.cpp +++ b/espmusicmouse/src/main.cpp @@ -22,6 +22,7 @@ Esp32DriverRGBW ledDriver; LedTask ledTask; +bool fox; void tag_handler(uint8_t *sn) { // serial number is always 5 bytes long @@ -33,19 +34,27 @@ void tag_handler(uint8_t *sn) if (sn[4] == 0x30) { Serial.println("Fuchs"); + fox = true; //ledTask.startEffect(EffectCircularConfig{2 * 360, 180, ColorRGBW{0, 0, 255, 0}}); - ledTask.startEffect(EffectAlexaSwipeConfig{20, 30, 3 * 360, 3, 180, ColorRGBW{0, 255, 0, 0}, ColorRGBW{0, 0, 255, 0}}); + ledTask.startEffect(EffectAlexaSwipeConfig{20, 30, 3 * 360, 3, 180, true, ColorRGBW{0, 255, 0, 0}, ColorRGBW{0, 0, 255, 0}}); } if (sn[4] == 0xf0) { Serial.println("Eule"); + fox = false; ledTask.startEffect(EffectCircularConfig{360, 180, ColorRGBW{0, 0, 255, 0}}); } } else { Serial.println("Nichts"); - ledTask.startEffect(EffectStaticConfig{ColorRGBW{0, 0, 0, 0}}); + if (fox) + { + fox = false; + ledTask.startEffect(EffectAlexaSwipeConfig{20, 30, 3 * 360, 3, 180, false, ColorRGBW{0, 255, 0, 0}, ColorRGBW{0, 0, 255, 0}}); + } + else + ledTask.startEffect(EffectStaticConfig{ColorRGBW{0, 0, 0, 0}}); } //led.transmit(); }