Skip to content

Commit 158cd90

Browse files
committed
Fixed smart home controller brightness issue
1 parent 1a7419e commit 158cd90

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

.idea/workspace.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/com/github/iamniklas/liocore/network/javalin/controllers/SmartHomeController.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
import com.github.iamniklas.liocore.network.javalin.models.SmartHomeModel;
99
import com.google.gson.Gson;
1010
import io.javalin.Javalin;
11+
import org.apache.log4j.Logger;
1112

1213
public class SmartHomeController extends ControllerBase {
1314

15+
private static final Logger log = Logger.getLogger(SmartHomeController.class);
1416
SmartHomeModel smartHomeModel;
1517

1618
LEDStripManager ledStripManager;
@@ -22,7 +24,10 @@ public SmartHomeController(Javalin _app, LEDStripManager _ledStripManager, Gson
2224
_app.get("/smart", ctx -> ctx.result(gson.toJson(smartHomeModel)));
2325

2426
_app.get("/smart/brightness", ctx -> ctx.result(gson.toJson(smartHomeModel.getBrightness())));
25-
_app.post("/smart/brightness", ctx -> smartHomeModel.setBrightness(Float.parseFloat(ctx.body())));
27+
_app.post("/smart/brightness", ctx -> {
28+
float brightness = Float.parseFloat(ctx.body());
29+
smartHomeModel.setBrightness(brightness);
30+
});
2631

2732
_app.get("/smart/temperature_k", ctx -> { ctx.result(gson.toJson(getTemperatureKFromColorRGB(smartHomeModel.getColor()))); });
2833
_app.post("/smart/temperature_k", ctx -> smartHomeModel.setColor(KelvinColor.getRGBForKelvin(Integer.parseInt(ctx.body()))));
@@ -42,7 +47,7 @@ public SmartHomeController(Javalin _app, LEDStripManager _ledStripManager, Gson
4247
void updateLEDStrip() {
4348
ledStripManager.procContainer.removeAllCurrentProcedures();
4449

45-
smartHomeModel.setBrightness(Math.max(0, Math.min(100, smartHomeModel.getBrightness())));
50+
smartHomeModel.setBrightness(Math.max(0, Math.min(255, smartHomeModel.getBrightness())));
4651

4752
smartHomeModel.setColor(new ColorRGB(
4853
Math.max(0, Math.min(255, smartHomeModel.getColor().getR())),
@@ -52,9 +57,9 @@ void updateLEDStrip() {
5257

5358
if (smartHomeModel.getPowerSwitch()) {
5459
LIOColor adjustedColor = new LIOColor(
55-
(int) (smartHomeModel.getColor().getR() * (smartHomeModel.getBrightness() / 100.0f)),
56-
(int) (smartHomeModel.getColor().getG() * (smartHomeModel.getBrightness() / 100.0f)),
57-
(int) (smartHomeModel.getColor().getB() * (smartHomeModel.getBrightness() / 100.0f))
60+
(int) (smartHomeModel.getColor().getR() * (smartHomeModel.getBrightness() / 255.0f)),
61+
(int) (smartHomeModel.getColor().getG() * (smartHomeModel.getBrightness() / 255.0f)),
62+
(int) (smartHomeModel.getColor().getB() * (smartHomeModel.getBrightness() / 255.0f))
5863
);
5964
ledStripManager.setAllPixels(adjustedColor);
6065
} else {

0 commit comments

Comments
 (0)