Swipe backwards

This commit is contained in:
Martin Bauer 2021-11-19 17:28:48 +01:00
parent aa76900244
commit 0bbb5d278c
3 changed files with 31 additions and 15 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
generated_3d
build
*.FCStd1
*.blend1

View File

@ -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

View File

@ -22,6 +22,7 @@ Esp32DriverRGBW ledDriver;
LedTask<decltype(ledStrip)> ledTask;
bool fox;
void tag_handler(uint8_t *sn)
{
// serial number is always 5 bytes long
@ -33,18 +34,26 @@ 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");
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();