8
8
import com .github .iamniklas .liocore .network .javalin .models .SmartHomeModel ;
9
9
import com .google .gson .Gson ;
10
10
import io .javalin .Javalin ;
11
+ import org .apache .log4j .Logger ;
11
12
12
13
public class SmartHomeController extends ControllerBase {
13
14
15
+ private static final Logger log = Logger .getLogger (SmartHomeController .class );
14
16
SmartHomeModel smartHomeModel ;
15
17
16
18
LEDStripManager ledStripManager ;
@@ -22,7 +24,10 @@ public SmartHomeController(Javalin _app, LEDStripManager _ledStripManager, Gson
22
24
_app .get ("/smart" , ctx -> ctx .result (gson .toJson (smartHomeModel )));
23
25
24
26
_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
+ });
26
31
27
32
_app .get ("/smart/temperature_k" , ctx -> { ctx .result (gson .toJson (getTemperatureKFromColorRGB (smartHomeModel .getColor ()))); });
28
33
_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
42
47
void updateLEDStrip () {
43
48
ledStripManager .procContainer .removeAllCurrentProcedures ();
44
49
45
- smartHomeModel .setBrightness (Math .max (0 , Math .min (100 , smartHomeModel .getBrightness ())));
50
+ smartHomeModel .setBrightness (Math .max (0 , Math .min (255 , smartHomeModel .getBrightness ())));
46
51
47
52
smartHomeModel .setColor (new ColorRGB (
48
53
Math .max (0 , Math .min (255 , smartHomeModel .getColor ().getR ())),
@@ -52,9 +57,9 @@ void updateLEDStrip() {
52
57
53
58
if (smartHomeModel .getPowerSwitch ()) {
54
59
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 ))
58
63
);
59
64
ledStripManager .setAllPixels (adjustedColor );
60
65
} else {
0 commit comments