Skip to content

Commit

Permalink
v1.2.28
Browse files Browse the repository at this point in the history
- Fixes `color-light` rainbow animation effect and turn off level
  • Loading branch information
genemars committed Jun 28, 2024
1 parent e38e889 commit 77f5753
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
32 changes: 18 additions & 14 deletions examples/color-light/color-light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void statusLedCallback(bool isLedOn) {
statusLED->show();
}

bool isConfigured = false;
float currentSaturation;
float hueOffset = 0;
float hueRange = 1;
Expand Down Expand Up @@ -142,7 +143,8 @@ void setup() {
statusLED->setPixelColor(0, 0, 0, 0);
}

if (!Config::isDeviceConfigured()) {
isConfigured = Config::isDeviceConfigured();
if (!isConfigured) {

// Custom status led (builtin NeoPixel RGB on pin 10)
if (statusLED != nullptr) {
Expand Down Expand Up @@ -208,21 +210,23 @@ void loop()
{
homeGenie->loop();

// refresh background/strobe layer
if (currentColor.isAnimating()) {
refresh();
}

// 40 fps animation FX layer
if (millis() - lastRefreshTs > 25) {

// FX - rainbow animation
if (rainbowModule->isOn()) {
fx_rainbow(currentColor);
if (isConfigured) {
// refresh background/strobe layer
if (currentColor.isAnimating()) {
refresh();
}
// TODO: add more FX modules

lastRefreshTs = millis();
// 40 fps animation FX layer
if (millis() - lastRefreshTs > 25) {

// FX - rainbow animation
if (rainbowModule->isOn()) {
fx_rainbow(currentColor);
refresh();
}
// TODO: add more FX modules

lastRefreshTs = millis();
}
}
}
17 changes: 12 additions & 5 deletions src/service/api/devices/ColorLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,31 @@ namespace Service { namespace API { namespace devices {
public:
unsigned long duration = 0;
void setColor(float hue, float saturation, float value, unsigned long transitionMs) {
oh = getHue();
os = getSaturation();
ov = getValue();
oh = h;
os = s;
ov = v;

//oh = getHue();
//os = getSaturation();
//ov = getValue();

// constraints
if (hue > 1) hue = 1;
if (saturation > 1) saturation = 1;
if (value > 1) value = 1;

h = hue;
s = saturation;
v = value;

duration = transitionMs;
if (duration <= 0) duration = 1;
startTime = millis();
}
bool isAnimating() const {
return (millis() - startTime) <= duration + 100;
}
float getProgress() const {
float p = (float)(millis() - startTime) / (float)duration;
float p = (float)(millis() - startTime) / ((float)duration + 1);
return p < 1 ? p : 1;
}
float getHue() const {
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

#define VERSION_MAJOR 1
#define VERSION_MINOR 2
#define VERSION_PATCH 27
#define VERSION_PATCH 28

#define STRING_VALUE(...) STRING_VALUE__(__VA_ARGS__)
#define STRING_VALUE__(...) #__VA_ARGS__
Expand Down

0 comments on commit 77f5753

Please sign in to comment.