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 static MainViewModel CreateNew() { var fanStatusPoster = new FanSwitchQueueClient(QueueMode.Send); fanStatusPoster.Start(); var listener = new TemperatureListener(); var errorLogger = SimpleIoc.Default.GetInstance<IErrorLogger>(); var messageDisplayer = SimpleIoc.Default.GetInstance<IMessageDisplayer>(); var bandOperator = new BandOperator(fanStatusPoster); return (new MainViewModel( listener, bandOperator, messageDisplayer, errorLogger)); }