private async void MainPage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) { var gpioService = new GpioService(); var fanSwitch = new SwitchDevice(gpioService, Settings.SwitchPinId); var controller = new AnalogTemperatureSensorController(gpioService); var thermometer = new Thermometer(gpioService, controller); var poster = new TemperatureQueueClient(QueueMode.Send); var fanCommandListener = new FanSwitchQueueClient(QueueMode.Listen); await fanCommandListener.Start(); fanCommandListener.OnDataReceived += (cs, cmd) => { Debug.WriteLine($"Fanswitchcommand received {cmd.Status}; current status fan on = {fanSwitch.IsOn} at {DateTime.Now}"); var newStatus = cmd.Status == FanStatus.On; if (newStatus != fanSwitch.IsOn) { fanSwitch.Toggle(); } }; thermometer.OnTemperatureMeasured += OnTemperatureMeasured; thermometer.OnTemperatureMeasured += async (thObject, data) => { data.FanStatus = fanSwitch.IsOn ? FanStatus.On : FanStatus.Off; await poster.PostData(data); }; await poster.Start(); await thermometer.Start(); }
public TemperatureListener() { _client = new TemperatureQueueClient(QueueMode.Listen); _client.OnDataReceived += ProcessTemperatureData; }