Reverse swipe
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "effects/Circular.h"
|
||||
#include "effects/Static.h"
|
||||
#include "effects/AlexaSwipe.h"
|
||||
#include "effects/ReverseSwipe.h"
|
||||
#include "effects/RandomTwoColorInterpolation.h"
|
||||
#include "effects/SwipeAndChange.h"
|
||||
|
||||
@@ -101,10 +102,12 @@ enum class MessageHostToFw : uint8_t
|
||||
LED_WHEEL_EFFECT_CIRCULAR = 2,
|
||||
LED_WHEEL_EFFECT_RANDOM_TWO_COLOR_INTERPOLATION = 3,
|
||||
LED_WHEEL_EFFECT_SWIPE_AND_CHANGE = 4,
|
||||
MOUSE_LED_EFFECT_STATIC = 5,
|
||||
MOUSE_LED_EFFECT_CIRCULAR = 6,
|
||||
MOUSE_LED_EFFECT_RANDOM_TWO_COLOR_INTERPOLATION = 7,
|
||||
|
||||
LED_WHEEL_EFFECT_REVERSE_SWIPE = 5,
|
||||
MOUSE_LED_EFFECT_STATIC = 6,
|
||||
MOUSE_LED_EFFECT_CIRCULAR = 7,
|
||||
MOUSE_LED_EFFECT_RANDOM_TWO_COLOR_INTERPOLATION = 8,
|
||||
MOUSE_LED_EFFECT_SWIPE_AND_CHANGE = 9,
|
||||
MOUSE_LED_EFFECT_REVERSE_SWIPE = 10,
|
||||
};
|
||||
|
||||
template <>
|
||||
@@ -201,6 +204,12 @@ inline void handleIncomingMessagesFromHost(LedTask1 *ledTaskCircle, LedTask2 *le
|
||||
auto cfg = reinterpret_cast<EffectSwipeAndChangeConfig *>(msgBuffer);
|
||||
ledTaskCircle->startEffect(*cfg);
|
||||
}
|
||||
else if (msgType == MessageHostToFw::LED_WHEEL_EFFECT_REVERSE_SWIPE)
|
||||
{
|
||||
auto cfg = reinterpret_cast<EffectReverseSwipeConfig *>(msgBuffer);
|
||||
ledTaskCircle->startEffect(*cfg);
|
||||
}
|
||||
//
|
||||
else if (msgType == MessageHostToFw::MOUSE_LED_EFFECT_STATIC)
|
||||
{
|
||||
auto cfg = reinterpret_cast<EffectStaticConfig *>(msgBuffer);
|
||||
@@ -216,6 +225,16 @@ inline void handleIncomingMessagesFromHost(LedTask1 *ledTaskCircle, LedTask2 *le
|
||||
auto cfg = reinterpret_cast<EffectRandomTwoColorInterpolationConfig *>(msgBuffer);
|
||||
ledTaskMouse->startEffect(*cfg);
|
||||
}
|
||||
else if (msgType == MessageHostToFw::MOUSE_LED_EFFECT_SWIPE_AND_CHANGE)
|
||||
{
|
||||
auto cfg = reinterpret_cast<EffectSwipeAndChangeConfig *>(msgBuffer);
|
||||
ledTaskMouse->startEffect(*cfg);
|
||||
}
|
||||
else if (msgType == MessageHostToFw::MOUSE_LED_EFFECT_REVERSE_SWIPE)
|
||||
{
|
||||
auto cfg = reinterpret_cast<EffectReverseSwipeConfig *>(msgBuffer);
|
||||
ledTaskMouse->startEffect(*cfg);
|
||||
}
|
||||
else
|
||||
Serial.println("Unknown message type");
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ void _led_task_func(void *params)
|
||||
else if (dispatchEffectId<EffectId::ALEXA_SWIPE >(id, effectFunction, ledStrip, msgBuffer, effectStorage)) {}
|
||||
else if (dispatchEffectId<EffectId::RANDOM_TWO_COLOR_INTERPOLATION>(id, effectFunction, ledStrip, msgBuffer, effectStorage)) {}
|
||||
else if (dispatchEffectId<EffectId::SWIPE_AND_CHANGE >(id, effectFunction, ledStrip, msgBuffer, effectStorage)) {}
|
||||
else if (dispatchEffectId<EffectId::REVERSE_SWIPE >(id, effectFunction, ledStrip, msgBuffer, effectStorage)) {}
|
||||
// clang-format on
|
||||
|
||||
timeoutMsForEffect = 0;
|
||||
|
||||
@@ -2,25 +2,105 @@
|
||||
#include "containers/LedStripRGBW.h"
|
||||
|
||||
#include "effects/AlexaSwipe.h"
|
||||
#include "effects/ReverseSwipe.h"
|
||||
#include "helpers/ColorConversions.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
|
||||
template <typename T>
|
||||
void printVec(const std::vector<T> &vec)
|
||||
std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec)
|
||||
{
|
||||
std::cout << "[";
|
||||
os << "[";
|
||||
for (const auto &e : vec)
|
||||
std::cout << e << ",";
|
||||
std::cout << "]\n";
|
||||
{
|
||||
if (std::is_same<uint8_t, T>::value)
|
||||
os << int(e) << ",";
|
||||
else
|
||||
os << e << ",";
|
||||
}
|
||||
os << "]";
|
||||
return os;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::ostream &operator<<(std::ostream &os, const std::vector<std::vector<T>> &vec)
|
||||
{
|
||||
os << "[";
|
||||
for (const auto &e : vec)
|
||||
os << e << ",";
|
||||
os << "]";
|
||||
return os;
|
||||
}
|
||||
|
||||
template <typename TEffect, int NLeds>
|
||||
void effectToFile(const std::string &filename, TEffect &effect, LedStripRGBW<NLeds> &strip, int calls = 100)
|
||||
{
|
||||
std::vector<std::vector<uint8_t>> vr(calls);
|
||||
std::vector<std::vector<uint8_t>> vg(calls);
|
||||
std::vector<std::vector<uint8_t>> vb(calls);
|
||||
|
||||
std::vector<std::vector<float>> vh(calls);
|
||||
std::vector<std::vector<float>> vs(calls);
|
||||
std::vector<std::vector<float>> vv(calls);
|
||||
|
||||
for (int time = 0; time < calls; ++time)
|
||||
{
|
||||
effect();
|
||||
vr[time].resize(NLeds);
|
||||
vg[time].resize(NLeds);
|
||||
vb[time].resize(NLeds);
|
||||
|
||||
vh[time].resize(NLeds);
|
||||
vs[time].resize(NLeds);
|
||||
vv[time].resize(NLeds);
|
||||
|
||||
for (int i = 0; i < NLeds; ++i)
|
||||
{
|
||||
uint8_t r, g, b, w;
|
||||
strip.getRGBW(i, r, g, b, w);
|
||||
vr[time][i] = r;
|
||||
vg[time][i] = g;
|
||||
vb[time][i] = b;
|
||||
|
||||
auto hsv = rgb2hsv(ColorRGBW{r, g, b, w});
|
||||
vh[time][i] = hsv.h;
|
||||
vs[time][i] = hsv.s;
|
||||
vv[time][i] = hsv.v;
|
||||
}
|
||||
}
|
||||
|
||||
std::ofstream fs(filename.c_str());
|
||||
fs << "r = " << vr << "\n";
|
||||
fs << "g = " << vg << "\n";
|
||||
fs << "b = " << vb << "\n";
|
||||
fs << "h = " << vh << "\n";
|
||||
fs << "s = " << vs << "\n";
|
||||
fs << "v = " << vv << "\n";
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
auto cfg = EffectAlexaSwipeConfig{20, 20, 90, 5, 180, ColorRGBW{255, 0, 0, 0}, ColorRGBW{0, 0, 255, 0}};
|
||||
LedStripRGBW<51> strip;
|
||||
{
|
||||
auto cfg = EffectAlexaSwipeConfig{20.f, 20.f, 90.f, 5.f, 180, true, ColorRGBW{255, 0, 0, 0}, ColorRGBW{255, 0, 0, 0}};
|
||||
LedStripRGBW<51> strip;
|
||||
|
||||
EffectAlexaSwipe<decltype(strip)> effect(cfg, strip);
|
||||
EffectAlexaSwipe<decltype(strip)> effect(cfg, strip);
|
||||
effectToFile("swipe.py", effect, strip, 200);
|
||||
}
|
||||
|
||||
{
|
||||
auto cfg = EffectReverseSwipeConfig{360.f, 5.f, 180};
|
||||
LedStripRGBW<51> strip;
|
||||
for (int i = 0; i < strip.numLeds(); ++i)
|
||||
setLedRGBW(strip, i, ColorRGBW{255, 255, 255, 0});
|
||||
|
||||
EffectReverseSwipe<decltype(strip)> effect(cfg, strip);
|
||||
effectToFile("reverse_swipe.py", effect, strip, 200);
|
||||
}
|
||||
|
||||
/*
|
||||
effect.currentPosition_ = 150;
|
||||
|
||||
const auto numLeds = strip.numLeds() / 2;
|
||||
@@ -35,6 +115,6 @@ int main(int argc, char **argv)
|
||||
printVec(interpolation);
|
||||
|
||||
effect();
|
||||
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user