Skip to content

Commit f46acd5

Browse files
committed
Fixate brightness and speed sliders
1 parent 1aa8ff1 commit f46acd5

File tree

6 files changed

+20
-15
lines changed

6 files changed

+20
-15
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ Control multiple FastLED lightstrip animations on the ESP8266 without reuploadin
88

99
- Start/stop/pause multiple animations
1010
- Set custom static color
11-
- Set animation speed
12-
- Control saturation
11+
- Set animation speed and brightness
1312
- Alarm: Be woken up to an animation slowly fading in
1413
- Sunset: Automatically fade in an animation when the sun sets at your location
1514
- Compatible with [ha-bridge](https://github.com/bwssytems/ha-bridge) via [http requests](https://github.com/stnkl/FastLEDManager/blob/master/Webserver.cpp)

src/Config.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ bool ConfigClass::parseJson(char *input)
7272
startupAnimation = doc["startupAnimation"].as<String>();
7373
if (doc.containsKey("color"))
7474
color = doc["color"].as<String>();
75-
if (doc.containsKey("speed"))
76-
speed = doc["speed"];
77-
if (doc.containsKey("saturation"))
78-
saturation = doc["saturation"];
7975

8076
return !error;
8177
}
@@ -100,8 +96,6 @@ DynamicJsonDocument ConfigClass::getJson(DynamicJsonDocument doc)
10096
doc["sunsetAnimation"] = sunsetAnimation;
10197
doc["startupAnimation"] = startupAnimation;
10298
doc["color"] = color;
103-
doc["speed"] = speed;
104-
doc["saturation"] = saturation;
10599

106100
return doc;
107101
}

src/Config.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ class ConfigClass
4444
String startupAnimation = "";
4545
/// Lastly used color for Color animation
4646
String color = "";
47-
/// Current animation speed
48-
uint8_t speed = 128;
49-
/// Current led saturation
50-
uint8_t saturation = 255;
5147

5248
/// Initialize config object by mounting file system and
5349
/// reading the config file.

src/FastLEDManager.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ void FastLEDManagerClass::initialize(uint16_t numberOfLeds)
3737
Webserver::initialize();
3838
Fade::initialize();
3939
}
40+
41+
registerSlider(new Slider("Brightness", 0, 255, 255, 1));
42+
registerSlider(new Slider("Speed", 0, 255, 127, 1));
4043
}
4144

4245
void FastLEDManagerClass::enableCycleButton(uint8_t pin)
@@ -130,9 +133,8 @@ void FastLEDManagerClass::clear(bool writeData)
130133
void FastLEDManagerClass::delay(uint16_t ms)
131134
{
132135
unsigned long start = micros();
133-
while (micros() - start < 1000.0 * ms * pow(Config.speed - 255, 2) / 16384)
136+
while (micros() - start < 1000.0 * ms * pow((FastLEDManager.speed - 255) / 128.0, 2))
134137
{
135-
show();
136138
handleESPEssentials();
137139
Fade::handle();
138140
WebSocket::socket.loop();

src/FastLEDManager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ class FastLEDManagerClass : public CFastLED
145145
/// Current animation status
146146
AnimationStatus status = STOPPED;
147147

148+
/// Current animation speed
149+
uint8_t speed = 255;
150+
148151
/// Current brightness value in 10bit
149152
int16_t brightness10;
150153

src/WebSocket.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,18 @@ void handleBinary(uint8_t *binary, uint8_t id)
8585
FastLEDManager.leds[i] = CRGB(binary[1 + i * 3], binary[2 + i * 3], binary[3 + i * 3]);
8686
break;
8787
case 20: // Slider data
88-
FastLEDManager.getSlider(binary[1])->value = binary[2];
88+
switch (binary[1])
89+
{
90+
case 0:
91+
FastLEDManager.brightness10 = binary[2] * 4 + 3;
92+
break;
93+
case 1:
94+
FastLEDManager.speed = binary[2];
95+
break;
96+
default:
97+
FastLEDManager.getSlider(binary[1])->value = binary[2];
98+
break;
99+
}
89100
break;
90101
case 30: // Request configuration
91102
DynamicJsonDocument doc(2048);

0 commit comments

Comments
 (0)