Search in sources :

Example 1 with ColorRange

use of il.ac.technion.cs.smarthouse.developers_api.application_builder.ColorRange in project Smartcity-Smarthouse by TechnionYP5777.

the class StatusRegionBuilderImpl method addTimerStatusField.

/*
     * (non-Javadoc)
     * 
     * @see il.ac.technion.cs.smarthouse.developers_api.application_builder.
     * StatusRegionBuilder#addTimerStatusField(java.lang.String,
     * il.ac.technion.cs.smarthouse.developers_api.application_builder.
     * GuiBinderObject,
     * il.ac.technion.cs.smarthouse.developers_api.application_builder.
     * GuiBinderObject,
     * il.ac.technion.cs.smarthouse.developers_api.application_builder.
     * ColorRange)
     */
@Override
public StatusRegionBuilderImpl addTimerStatusField(String title, GuiBinderObject<Boolean> timerToggle, GuiBinderObject<Double> timerDuration, ColorRange<Double> d) {
    final Label timeLabel = createStatusLabel("");
    final Timeline timeline;
    final GuiBinderObject<Duration> time = new GuiBinderObject<>(Duration.ZERO);
    timeLabel.setText(0.0 + " [sec]");
    timeline = new Timeline(new KeyFrame(Duration.millis(100), ¢ -> {
        time.setData(time.getData().add(((KeyFrame) ¢.getSource()).getTime()));
        timerDuration.setData(time.getData().toSeconds());
        timeLabel.setText(timerDuration.getData() + " [sec]");
    }));
    timerToggle.addOnDataChangedListener(v -> {
        if (v.getData()) {
            timeline.setCycleCount(Animation.INDEFINITE);
            timeline.play();
        } else {
            timeline.stop();
            time.setData(Duration.ZERO);
            timerDuration.setData(time.getData().toSeconds());
            timeLabel.setText(timerDuration.getData() + " [sec]");
        }
    });
    if (d != null)
        timerDuration.addOnDataChangedListener(v -> setColor(v, d, timeLabel));
    addAppBuilderItem(new AppBuilderItem(title, timeLabel));
    return this;
}
Also used : ColorRange(il.ac.technion.cs.smarthouse.developers_api.application_builder.ColorRange) KeyFrame(javafx.animation.KeyFrame) Duration(javafx.util.Duration) Label(javafx.scene.control.Label) Font(javafx.scene.text.Font) Timeline(javafx.animation.Timeline) GuiBinderObject(il.ac.technion.cs.smarthouse.developers_api.application_builder.GuiBinderObject) StatusRegionBuilder(il.ac.technion.cs.smarthouse.developers_api.application_builder.StatusRegionBuilder) Animation(javafx.animation.Animation) Timeline(javafx.animation.Timeline) Label(javafx.scene.control.Label) KeyFrame(javafx.animation.KeyFrame) Duration(javafx.util.Duration) GuiBinderObject(il.ac.technion.cs.smarthouse.developers_api.application_builder.GuiBinderObject)

Example 2 with ColorRange

use of il.ac.technion.cs.smarthouse.developers_api.application_builder.ColorRange in project Smartcity-Smarthouse by TechnionYP5777.

the class StoveModuleGui method onLoad.

/*
     * (non-Javadoc)
     * 
     * @see
     * il.ac.technion.cs.smarthouse.developers_api.SmarthouseApplication#onLoad(
     * )
     */
@Override
public void onLoad() throws Exception {
    final GuiBinderObject<Double> alertAfterSecs = new GuiBinderObject<>(15.0);
    final GuiBinderObject<Integer> alertAboveDegs = new GuiBinderObject<>(120), temps = new GuiBinderObject<>(0);
    final GuiBinderObject<Boolean> isStoveOn = new GuiBinderObject<>(false);
    final GuiBinderObject<Double> timer = new GuiBinderObject<>();
    getAppBuilder().getConfigurationsRegionBuilder().addDoubleInputField("Alert after (seconds):", alertAfterSecs).addIntegerInputField("Alert at (degrees celsius):", alertAboveDegs);
    getAppBuilder().getStatusRegionBuilder().addStatusField("Current temperature:", temps, new ColorRange<Integer>().addRange(alertAboveDegs, Color.RED)).addTimerStatusField("Stove running timer:", isStoveOn, timer, new ColorRange<Double>().addRange(alertAfterSecs, Color.RED));
    super.<SensorsService>getService(ServiceType.SENSORS_SERVICE).getSensor("iStoves", StoveSensor.class).subscribe(stove -> {
        final String t = "Stove is " + (stove.isOn() ? "" : "Not ") + "On at " + stove.getTemperture() + " degrees";
        isStoveOn.setData(stove.isOn());
        temps.setData(!stove.isOn() ? 0 : stove.getTemperture());
        log.debug("App msg (from function subscibed to stove sensor): " + t + " | Sensor is located at: " + stove.getSensorLocation());
    });
    Runnable c = () -> {
        synchronized (alertCalled) {
            if (timer.getData(0.0) <= alertAfterSecs.getData(0.0) && temps.getData(0) <= alertAboveDegs.getData(0))
                alertCalled = false;
            else if (!alertCalled) {
                ((AlertsManager) getService(ServiceType.ALERTS_SERVICE)).sendAlert(getApplicationName(), "Stove is running too long", EmergencyLevel.EMAIL_EMERGENCY_CONTACT);
                alertCalled = true;
            }
        }
    };
    timer.addOnDataChangedListener(c);
    temps.addOnDataChangedListener(c);
    getAppBuilder().getWidgetsRegionBuilder().addWidget(WidgetType.BASIC_DASHBOARD, new InfoCollector().setUnit("C").addInfoEntry("stove.temperature", "temper")).addWidget(WidgetType.LINES_GRAPH, new InfoCollector().setUnit("C").addInfoEntry("stove.temperature", "temper")).addWidget(WidgetType.SWITCH, new InfoCollector().setUnit("Boolean").addInfoEntry("stove.is_on", "isOn"));
}
Also used : InfoCollector(il.ac.technion.cs.smarthouse.system.dashboard.InfoCollector) AlertsManager(il.ac.technion.cs.smarthouse.system.services.alerts_service.AlertsManager) ColorRange(il.ac.technion.cs.smarthouse.developers_api.application_builder.ColorRange) SensorsService(il.ac.technion.cs.smarthouse.system.services.sensors_service.SensorsService) GuiBinderObject(il.ac.technion.cs.smarthouse.developers_api.application_builder.GuiBinderObject)

Aggregations

ColorRange (il.ac.technion.cs.smarthouse.developers_api.application_builder.ColorRange)2 GuiBinderObject (il.ac.technion.cs.smarthouse.developers_api.application_builder.GuiBinderObject)2 StatusRegionBuilder (il.ac.technion.cs.smarthouse.developers_api.application_builder.StatusRegionBuilder)1 InfoCollector (il.ac.technion.cs.smarthouse.system.dashboard.InfoCollector)1 AlertsManager (il.ac.technion.cs.smarthouse.system.services.alerts_service.AlertsManager)1 SensorsService (il.ac.technion.cs.smarthouse.system.services.sensors_service.SensorsService)1 Animation (javafx.animation.Animation)1 KeyFrame (javafx.animation.KeyFrame)1 Timeline (javafx.animation.Timeline)1 Label (javafx.scene.control.Label)1 Font (javafx.scene.text.Font)1 Duration (javafx.util.Duration)1