Search in sources :

Example 1 with AcuAction

use of il.ac.technion.cs.simulation.Simulation.AcuAction in project Smartcity-Smarthouse by TechnionYP5777.

the class AcuGui method onLoad.

/*
     * (non-Javadoc)
     * 
     * @see
     * il.ac.technion.cs.smarthouse.developers_api.SmarthouseApplication#onLoad(
     * )
     */
/**
 * [[SuppressWarningsSpartan]]
 */
@Override
public void onLoad() throws Exception {
    final GuiBinderObject<Integer> currentTemp = new GuiBinderObject<>(20);
    final GuiBinderObject<Integer> wantedTemp = new GuiBinderObject<>(18);
    final GuiBinderObject<String> AcuState = new GuiBinderObject<>(OFF);
    final SensorApi<ACUSensor> sensor = super.<SensorsService>getService(ServiceType.SENSORS_SERVICE).getSensor(Simulation.commname, ACUSensor.class);
    sensor.subscribe(data -> {
        // update GUI
        currentTemp.setData(data.getTemp());
        AcuState.setData(data.isOn() ? ON : OFF);
        // instruct sensor
        Integer want = wantedTemp.getData(100), have = currentTemp.getData(0);
        AcuAction nextAction = (have < want) ? AcuAction.HOTTER : (have > want) ? AcuAction.COLDER : AcuAction.STOP;
        sensor.instruct(nextAction + "", setStatePath);
    });
    wantedTemp.addOnDataChangedListener(desiredT -> desiredT.getDataAsOptional().ifPresent(t -> sensor.instruct(t + 0.2 + "", setTempPath)));
    getAppBuilder().getStatusRegionBuilder().addStatusField("Current temperature in controlled location:", currentTemp).addStatusField("The air conditioner in controlled location is", AcuState);
    getAppBuilder().getConfigurationsRegionBuilder().addIntegerInputField("Desired Temperature:", wantedTemp).addSensorAliasSelectionField("The Controlled location:", sensor, (oldA, newA) -> {
        super.<SensorsService>getService(ServiceType.SENSORS_SERVICE).getSensor(Simulation.commname, ACUSensor.class, oldA).instruct(AcuAction.STOP + "", setStatePath);
        wantedTemp.getDataAsOptional().ifPresent(t -> super.<SensorsService>getService(ServiceType.SENSORS_SERVICE).getSensor(Simulation.commname, ACUSensor.class, newA).instruct(t + 0.3 + "", setTempPath));
    });
    simulation.getAliases().forEach(alias -> {
        SensorApi<ACUSensor> currSensor = super.<SensorsService>getService(ServiceType.SENSORS_SERVICE).getSensor(Simulation.commname, ACUSensor.class, alias);
        getAppBuilder().getWidgetsRegionBuilder().addWidget(WidgetType.PROGRESS_LINE_GRAPH, new InfoCollector().addInfoEntry(getTempPath, "temperature").setTitle(alias), currSensor, acu -> {
            Map<String, Object> data = new HashMap<>();
            data.put(getTempPath, acu.getTemp());
            return data;
        });
    });
}
Also used : Collection(java.util.Collection) ServiceType(il.ac.technion.cs.smarthouse.system.services.ServiceType) SystemPath(il.ac.technion.cs.smarthouse.system.services.sensors_service.SystemPath) HashMap(java.util.HashMap) GuiBinderObject(il.ac.technion.cs.smarthouse.developers_api.application_builder.GuiBinderObject) SensorsService(il.ac.technion.cs.smarthouse.system.services.sensors_service.SensorsService) InfoCollector(il.ac.technion.cs.smarthouse.system.dashboard.InfoCollector) AcuAction(il.ac.technion.cs.simulation.Simulation.AcuAction) SmarthouseApplication(il.ac.technion.cs.smarthouse.developers_api.SmarthouseApplication) SensorApi(il.ac.technion.cs.smarthouse.system.services.sensors_service.SensorApi) GenericSensor(il.ac.technion.cs.smarthouse.sensors.simulator.GenericSensor) SensorData(il.ac.technion.cs.smarthouse.system.services.sensors_service.SensorData) Map(java.util.Map) Simulation(il.ac.technion.cs.simulation.Simulation) PathType(il.ac.technion.cs.smarthouse.sensors.PathType) Simulatable(il.ac.technion.cs.smarthouse.sensors.Simulatable) WidgetType(il.ac.technion.cs.smarthouse.system.dashboard.WidgetType) InfoCollector(il.ac.technion.cs.smarthouse.system.dashboard.InfoCollector) HashMap(java.util.HashMap) AcuAction(il.ac.technion.cs.simulation.Simulation.AcuAction) GuiBinderObject(il.ac.technion.cs.smarthouse.developers_api.application_builder.GuiBinderObject) SensorsService(il.ac.technion.cs.smarthouse.system.services.sensors_service.SensorsService) GuiBinderObject(il.ac.technion.cs.smarthouse.developers_api.application_builder.GuiBinderObject)

Aggregations

Simulation (il.ac.technion.cs.simulation.Simulation)1 AcuAction (il.ac.technion.cs.simulation.Simulation.AcuAction)1 SmarthouseApplication (il.ac.technion.cs.smarthouse.developers_api.SmarthouseApplication)1 GuiBinderObject (il.ac.technion.cs.smarthouse.developers_api.application_builder.GuiBinderObject)1 PathType (il.ac.technion.cs.smarthouse.sensors.PathType)1 Simulatable (il.ac.technion.cs.smarthouse.sensors.Simulatable)1 GenericSensor (il.ac.technion.cs.smarthouse.sensors.simulator.GenericSensor)1 InfoCollector (il.ac.technion.cs.smarthouse.system.dashboard.InfoCollector)1 WidgetType (il.ac.technion.cs.smarthouse.system.dashboard.WidgetType)1 ServiceType (il.ac.technion.cs.smarthouse.system.services.ServiceType)1 SensorApi (il.ac.technion.cs.smarthouse.system.services.sensors_service.SensorApi)1 SensorData (il.ac.technion.cs.smarthouse.system.services.sensors_service.SensorData)1 SensorsService (il.ac.technion.cs.smarthouse.system.services.sensors_service.SensorsService)1 SystemPath (il.ac.technion.cs.smarthouse.system.services.sensors_service.SystemPath)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1