-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMainController.cs
46 lines (35 loc) · 1.44 KB
/
MainController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using AmbientRoomMonitor.Hardware;
using AmbientRoomMonitor.Services;
using Meadow;
using System;
namespace AmbientRoomMonitor;
internal class MainController
{
IAmbientRoomMonitorHardware hardware;
DisplayController displayService;
public MainController(IAmbientRoomMonitorHardware hardware)
{
this.hardware = hardware;
}
public void Initialize()
{
hardware.Initialize();
displayService = new DisplayController(hardware.Display);
hardware.EnvironmentalSensor.Updated += EnvironmentalSensorUpdated;
}
private void EnvironmentalSensorUpdated(object sender, Meadow.IChangeResult<(Meadow.Units.Temperature? Temperature, Meadow.Units.RelativeHumidity? Humidity, Meadow.Units.Pressure? Pressure, Meadow.Units.Resistance? GasResistance)> e)
{
hardware.RgbPwmLed.StartBlink(Color.Orange);
displayService.UpdateAtmosphericConditions(
light: $"{hardware.LightSensor.Illuminance.Value.Lux:N0}",
pressure: $"{e.New.Pressure.Value.Millibar:N0}",
humidity: $"{e.New.Humidity.Value.Percent:N0}",
temperature: $"{e.New.Temperature.Value.Celsius:N0}");
hardware.RgbPwmLed.StartBlink(Color.Green);
}
public void Run()
{
hardware.LightSensor.StartUpdating(TimeSpan.FromSeconds(5));
hardware.EnvironmentalSensor.StartUpdating(TimeSpan.FromSeconds(5));
}
}