static async Task Main(string[] args) { Pi.Init <BootstrapWiringPi>(); Console.WriteLine("Before call"); ISenseHat senseHat = await SenseHatFactory.GetSenseHat().ConfigureAwait(false); Console.WriteLine("After call"); BinaryClock(senseHat); }
public async Task InitializeHat() { ISenseHat senseHat = await SenseHatFactory.GetSenseHat(); this.SenseHat = senseHat; SenseHat.Display.Clear(); await SenseHat.Sensors.HumiditySensor.InitAsync(); }
public async Task InitDevices() { hat = await SenseHatFactory.GetSenseHat().ConfigureAwait(false); hat.Display.Fill(Colors.Aqua); hat.Display.Update(); ConnectIoTHub(); }
/// <summary> /// Call this (for example) from the constructor of the MainPage. /// Example: /// <code>Runner.Run(senseHat => new Views.DiscoLights(senseHat));</code> /// </summary> /// <param name="createView">The view to run.</param> public static void Run(Func <ISenseHat, SenseHatView> createView) { Task.Run(async() => { ISenseHat senseHat = await SenseHatFactory.GetSenseHat().ConfigureAwait(false); SenseHatView view = createView(senseHat); view.Run(); }).ConfigureAwait(false); }
private static void Main(string[] args) { CoreDeviceFactory.Init(); ISenseHat senseHat = SenseHatFactory.GetSenseHat(); DemoSelector .GetDemo(senseHat, text => { }) .Run(); }
public MainPage() { this.InitializeComponent(); Task.Run(async() => { ISenseHat hat = await SenseHatFactory.GetSenseHat().ConfigureAwait(false); var temp = hat.Sensors.Temperature.Value; this.SensorDisplay.Text = temp.ToString(); }); }
private async void InitSenseHat() { ISenseHat senseHat = await SenseHatFactory.GetSenseHat(); this.SenseHat = senseHat; SenseHat.Display.Clear(); timer.Start(); lblMessage.Text = "Running ..."; }
public static void Run(Func <ISenseHat, SenseHatRPi> createAction) { Task.Run(async() => { ISenseHat senseHat = await SenseHatFactory.GetSenseHat().ConfigureAwait(false); SenseHatRPi action = createAction(senseHat); action.Run(); }).ConfigureAwait(false); }
private async void InitSenseHat() { await iotClient.InitializeIoTServiceConnection(); ISenseHat senseHat = await SenseHatFactory.GetSenseHat(); this.SenseHat = senseHat; SenseHat.Display.Clear(); timer.Start(); }
/// <summary> /// Call this (for example) from the constructor of the MainPage. /// Example: /// <code>DemoRunner.Run(senseHat => new Demos.DiscoLights(senseHat));</code> /// </summary> /// <param name="createDemo">The demo to run.</param> public static void Run(Func <ISenseHat, SenseHatDemo> createDemo) { Task.Run(async() => { ISenseHat senseHat = await SenseHatFactory.GetSenseHat().ConfigureAwait(false); SenseHatDemo demo = createDemo(senseHat); demo.Run(); }).ConfigureAwait(false); }
public async void InitializeAsync() { // this must be separated from the constructor because await is not allowed there senseHat = await SenseHatFactory.GetSenseHat(); senseHat.Display.Reset(); senseHat.Display.Update(); measurementTimer.Start(); ListenForMessagesAsync(); }
public async void Run(IBackgroundTaskInstance taskInstance) { deferral = taskInstance.GetDeferral(); telemetry = new Telemetry("Sydney", Measure, 4); hat = await SenseHatFactory.GetSenseHat().ConfigureAwait(false); display = hat.Display; q.Dequeued += Q_Dequeued; // simple mechanism to decouple received messages ReceiveC2dAsync(deviceClient); }
private async void InitSenseHat() { ISenseHat senseHat = await SenseHatFactory.GetSenseHat(); this.SenseHat = senseHat; await iotClient.InitializeIoTServiceConnection(); SenseHat.Display.Clear(); SenseHat.Display.Fill(Windows.UI.Colors.Black); SenseHat.Display.Update(); }
private async void MainPage_Loaded(object sender, RoutedEventArgs e) { //get a reference to SenseHat senseHat = await SenseHatFactory.GetSenseHat(); //initialize the timer DispatcherTimer timer = new DispatcherTimer(); timer.Tick += Timer_Tick; timer.Interval = TimeSpan.FromSeconds(10); timer.Start(); }
public MainPage() { InitializeComponent(); UwpI2CDeviceFactory.Init(); Task.Factory.StartNew(() => { ISenseHat senseHat = SenseHatFactory.GetSenseHat(); SenseHatDemo demo = DemoSelector.GetDemo(senseHat, SetScreenText); demo.Run(); }); }
protected override async void OnNavigatedTo(NavigationEventArgs e) { try { senseHat = await SenseHatFactory.GetSenseHat(); timer.Start(); } catch { return; } }
// initialization async void Initialize() { senseHat = await SenseHatFactory.GetSenseHat().ConfigureAwait(false); // access to sensehat display = senseHat.Display; // access to sensehat display logFile = await logFolder.CreateFileAsync("log.txt", Windows.Storage.CreationCollisionOption.ReplaceExisting); // if log file already exists replace existing writeToLog("Weather Awareness 0.1\r\n---------------\r\nInitialized " + DateTime.Now.ToString()); writeToLog(DateTime.Now.TimeOfDay.ToString()); appInitialized = true; }
private async void MainPage_Loaded(object sender, RoutedEventArgs e) { //get a reference to SenseHat SenseHat = await SenseHatFactory.GetSenseHat(); SenseHat.Display.Clear(); SenseHat.Display.Update(); _timer = new DispatcherTimer(); _timer.Interval = new TimeSpan(0, 0, 0, 0, 1); CameraOn(); _timer.Start(); _timer.Tick += _timer_Tick; }
private void getsense() { try { Task.Run(async() => { senseHat = await SenseHatFactory.GetSenseHat().ConfigureAwait(false); }).ConfigureAwait(false); } catch (ArgumentOutOfRangeException e) { System.Diagnostics.Debug.WriteLine(e.ActualValue); } }
private async Task CollectSensorDataAsync(IProgress <Measurement> progress) { using (ISenseHat senseHat = await SenseHatFactory.GetSenseHat()) { while (Closing == false) { try { senseHat.Sensors.HumiditySensor.Update(); senseHat.Sensors.PressureSensor.Update(); var measurement = new Measurement() { Temperature = (senseHat.Sensors.Temperature ?? 0) - 12.5, Humidity = senseHat.Sensors.Humidity ?? 0, Pressure = senseHat.Sensors.Pressure ?? 0, }; #region SenseHAT LED senseHat.Display.Clear(); int temperature = (int)Math.Round(measurement.Temperature); string temperatureText = temperature.ToString(); tinyFont.Write(senseHat.Display, temperatureText, Colors.Aqua); senseHat.Display.Screen[2, 5] = Colors.Orange; senseHat.Display.Screen[4, 5] = Colors.Orange; senseHat.Display.Screen[5, 5] = Colors.Orange; senseHat.Display.Screen[4, 6] = Colors.Orange; senseHat.Display.Screen[4, 7] = Colors.Orange; senseHat.Display.Screen[5, 7] = Colors.Orange; senseHat.Display.Update(); #endregion progress.Report(measurement); //await AzureIoTHub.SendDeviceToCloudMessageAsync(measurement); } catch (Exception e) { Debug.WriteLine("Exception: " + e.Message); } await Task.Delay(5000); } } }
public void Run() { Task.Run(async() => { ISenseHat senseHat = await SenseHatFactory.GetSenseHat().ConfigureAwait(false); while (1 == 1) { senseHat.Sensors.HumiditySensor.Update(); var temp = senseHat.Sensors.Temperature; UpdateSensor(temp); Sleep(new TimeSpan(0, 0, 1)); } }).ConfigureAwait(false); }
public async Task InitDevice() { var hat = await SenseHatFactory.GetSenseHat().ConfigureAwait(false); hat.Display.Fill(Windows.UI.Colors.BlueViolet); hat.Display.Update(); this.hat = hat; await ConnectIoTHub(); await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { this.timer.Start(); }); }
private void SetUpAndLaunchTimer() { Task.Run(async() => { var senseHat = await SenseHatFactory.GetSenseHat().ConfigureAwait(false); await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, () => { if (senseHat == null) { WaitingTextBlock.Text = "No Sense Hat found. Please restart the app to try again."; } else { WaitingTextBlock.Visibility = Windows.UI.Xaml.Visibility.Collapsed; LogList.Visibility = Windows.UI.Xaml.Visibility.Visible; } }); var actions = new List <ILoggerAction <double> >(); actions.Add(new SenseHatHumidityDisplay(senseHat)); actions.Add(new AverageHumidityAction(this, new TableStorageHumidityLogger("TODO - Location code", "TODO - Azure table storage connection string", "HumidityLog"))); TimeSpan period = TimeSpan.FromSeconds(5); ThreadPoolTimer PeriodicTimer = ThreadPoolTimer.CreatePeriodicTimer(async(source) => { senseHat.Sensors.HumiditySensor.Update(); if (senseHat.Sensors.Humidity.HasValue) { double humidityValue = senseHat.Sensors.Humidity.Value; foreach (var action in actions) { await action.LogAction(humidityValue).ConfigureAwait(false); } } }, period); }).ConfigureAwait(false); }
private async void MainPage_Loaded(object sender, RoutedEventArgs e) { FixDeviceId(); if (deviceId == "minwinpc") { Debug.Write("Please set deviceID or unique machine name"); throw new ArgumentOutOfRangeException("Please set deviceID or unique machine name"); } Debug.WriteLine("Fixed - DeviceId:" + deviceId); InitGpio(); senseHat = await SenseHatFactory.GetSenseHat(); LedArrayOff(); senseHat.Display.Update(); StartHoL(); }
/// <summary> /// Makes sure tat Sensehat is instantiated /// and initiated /// </summary> private void EnsureSenseHatActivated() { // if sense hat is not created // create it and set the display blank if (_senseHat == null) { ManualResetEvent evt = new ManualResetEvent(false); Task.Run(async() => { _senseHat = await SenseHatFactory.GetSenseHat(); _senseHat.Display.Fill(Color.FromArgb(0, 0, 0, 0)); _senseHat.Display.Update(); evt.Set(); }); evt.WaitOne(); } }
public void Start() { Task.Run(async() => { senseHat = await SenseHatFactory.GetSenseHat(); actions = new List <BaseAction> { new OneColorAction(senseHat, Colors.White), new OneColorAction(senseHat, Colors.Red), new OneColorAction(senseHat, Colors.DarkRed), new OneColorAction(senseHat, Colors.Green), new OneColorAction(senseHat, Colors.DarkGreen), new OneColorAction(senseHat, Colors.Yellow), new OneColorAction(senseHat, Colors.DarkOrange), new OneColorAction(senseHat, Colors.Blue), new OneColorAction(senseHat, Colors.DarkBlue), new OneColorAction(senseHat, Colors.Magenta), new OneColorAction(senseHat, Colors.Purple), new OneColorAction(senseHat, Colors.DarkOrchid), new OneColorAction(senseHat, Colors.GhostWhite), new OneColorAction(senseHat, Colors.LavenderBlush), new OneColorAction(senseHat, Colors.Moccasin), new OneColorAction(senseHat, Colors.MintCream), new OneColorAction(senseHat, Colors.RosyBrown), new OneColorAction(senseHat, Colors.Violet), new OneColorAction(senseHat, Colors.Khaki), new RgbAction(senseHat), new HelloAction(senseHat), new ClockAction(senseHat), new DisplayTextAction(senseHat), new OffAction(senseHat) }; actionIndex = 0; if (useHttpRequestHandler) { new HttpRequestHandler(new HtmlGenerator(), ExecuteNextAction).Start(); } Loop(); }); }
private async void CompasTest() { SenseHat = await SenseHatFactory.GetSenseHat().ConfigureAwait(false); while (true) { SenseHat.Sensors.ImuSensor.Update(); if (SenseHat.Sensors.Pose.HasValue) { double northAngle = SenseHat.Sensors.Pose.Value.Z; SetScreenText($"Pos: {northAngle.ToString()}"); } await Task.Delay(2000); } }
protected override async void OnNavigatedTo(NavigationEventArgs e) { this.SleepingApertureThreshold = SettingsHelper.Instance.DriverMonitoringSleepingThreshold; this.YawningApertureThreshold = SettingsHelper.Instance.DriverMonitoringYawningThreshold; using (var speech = new SpeechSynthesizer()) { speech.Voice = SpeechSynthesizer.AllVoices.First(gender => gender.Gender == VoiceGender.Female); SpeechSynthesisStream stream = await speech.SynthesizeTextToStreamAsync("Wake up!"); this.alarmSound.SetSource(stream, stream.ContentType); } EnterKioskMode(); if (string.IsNullOrEmpty(SettingsHelper.Instance.FaceApiKey) || string.IsNullOrEmpty(SettingsHelper.Instance.VisionApiKey)) { await new MessageDialog("Missing Face API or Vision API Key. Please enter a key in the Settings page.", "Missing API Key").ShowAsync(); } else { FaceListManager.FaceListsUserDataFilter = SettingsHelper.Instance.WorkspaceKey + "_DriverIoT"; await this.cameraControl.StartStreamAsync(isForRealTimeProcessing : true); this.StartProcessingLoop(); } //get a reference to SenseHat try { senseHat = await SenseHatFactory.GetSenseHat(); senseHat.Display.Clear(); senseHat.Display.Update(); } catch (Exception) { } base.OnNavigatedTo(e); }
private async void StartTimer() { await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { await InicializarTimer(); if (!_timer.IsEnabled) { _timer.Start(); this._timerRun = true; } }); _senseHat = await SenseHatFactory.GetSenseHat().ConfigureAwait(false); _senseHat.Display.Clear(); _senseHat.Display.Update(); _display = _senseHat.Display; _unitText = GetUnitText(TemperatureUnit.Celcius); }
public override async void StartInitialize() { try { _sensehat = await SenseHatFactory.GetSenseHat().ConfigureAwait(false); if (_sensehat == null) { _isSensorHubInstalled = false; return; } // Pressure var pressure = new SensehatPressureSensor(); pressure.SetSensehat(_sensehat); AddSensor(pressure); // Humidity var humidity = new SensehatHumiditySensor(); humidity.SetSensehat(_sensehat); AddSensor(humidity); // Temperature Sensor var temperature = new SensehatTemperatureSensor(); temperature.SetSensehat(_sensehat); AddSensor(temperature); // Compass var compass = new Compass(); compass.SetSensehat(_sensehat); AddSensor(compass); OnSuccessfulInitialized(); } catch (Exception exc) { _isSensorHubInstalled = false; Console.WriteLine(exc.Message); OnInitializationFailed(exc); } }