Пример #1
0
        private async void TemperaturTest()
        {
            decimal min = 29;
            decimal max = 33;

            SenseHat = await SenseHatFactory.GetSenseHat().ConfigureAwait(false);

            while (true)
            {
                SenseHat.Sensors.HumiditySensor.Update();

                if (SenseHat.Sensors.Temperature.HasValue)
                {
                    var temperatur      = SenseHat.Sensors.Temperature.Value;
                    var temperaturColor = HeatMap((decimal)temperatur, min, max);

                    SetScreenText($"Temp: {temperatur.ToString()}");


                    SenseHat.Display.Clear();
                    SenseHat.Display.Fill(temperaturColor);
                    SenseHat.Display.Update();

                    await Task.Delay(1000);
                }
                else
                {
                    await Task.Delay(500);
                }
            }
        }
Пример #2
0
        public async Task Activate()
        {
            _senseHat = await SenseHatFactory.GetSenseHat().ConfigureAwait(false);

            _senseHat.Display.Clear();
            _senseHat.Display.Update();
        }
        private void SetUpAndLaunchTimer()
        {
            Task.Run(async() =>
            {
                var senseHat = await SenseHatFactory.GetSenseHat().ConfigureAwait(false);

                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
                    CoreDispatcherPriority.Normal,
                    () =>
                {
                    if (senseHat == null)
                    {
                        this.state("0-", senseHat);
                        WaitingTextBlock.Text = "No Sense Hat found. Please restart the app to try again.";
                    }
                    else
                    {
                        this.state("-0", senseHat);

                        WaitingTextBlock.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                        LogList.Visibility          = Windows.UI.Xaml.Visibility.Visible;
                    }
                });

                this.state("01", senseHat);
                var actions = new List <ILoggerAction <double> >();

                this.state("02", senseHat);

                actions.Add(new SenseHatTemperatureDisplay(senseHat));
                this.state("03", senseHat);

                var table = new TableStorageTemperatureLogger("Aquarium", "TemperatureLog");
                this.state("04", senseHat);

                actions.Add(new AverageTemperatureAction(this, table));

                this.state("05", senseHat);
                table.initStorageConnection("DefaultEndpointsProtocol=https;AccountName=aquariumlogger;AccountKey=MKcarWLA8QU+1eXz13jP13PYE722SZk/MMIwX8F86qOSLNhuI5//N2E2SjUP0uNNlYGX2NzB0FwCDoJvYI86Pw==;EndpointSuffix=core.windows.net");

                this.state("06", senseHat);

                TimeSpan period = TimeSpan.FromSeconds(5);
                ThreadPoolTimer PeriodicTimer = ThreadPoolTimer.CreatePeriodicTimer(async(source) =>
                {
                    this.state("--", senseHat);
                    senseHat.Sensors.HumiditySensor.Update();

                    if (senseHat.Sensors.Temperature.HasValue)
                    {
                        double temperatureValue = senseHat.Sensors.Temperature.Value;

                        foreach (var action in actions)
                        {
                            await action.LogAction(temperatureValue).ConfigureAwait(false);
                        }
                    }
                }, period);
            }).ConfigureAwait(false);
        }
Пример #4
0
        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);

            if (connectionString.StartsWith("<<") || !(connectionString.IndexOf("DeviceId=" + deviceId) > 0))
            {
                Debug.WriteLine("Please set collect 'connectionString'");
                throw new ArgumentOutOfRangeException("invalid connection string");
            }

            InitGpio();

            senseHat = await SenseHatFactory.GetSenseHat();

            LedArrayOff();
            senseHat.Display.Update();

            StartHoL();
        }
Пример #5
0
        private async Task CollectSensorData(IProgress <Measurement> progress)
        {
            using (ISenseHat senseHat = await SenseHatFactory.GetSenseHat())
            {
                for (; ;)
                {
                    try
                    {
                        senseHat.Sensors.HumiditySensor.Update();
                        senseHat.Sensors.PressureSensor.Update();
                        senseHat.Sensors.ImuSensor.Update();

                        var measurement = new Measurement()
                        {
                            Temperature   = senseHat.Sensors.Temperature ?? 0,
                            Humidity      = senseHat.Sensors.Humidity ?? 0,
                            Pressure      = senseHat.Sensors.Pressure ?? 0,
                            MagneticField = (Vector3)senseHat.Sensors.MagneticField,
                            Gyroscope     = (Vector3)senseHat.Sensors.Gyro,
                            Acceleration  = (Vector3)senseHat.Sensors.Acceleration
                        };
                        progress.Report(measurement);

                        await AzureIoTHub.SendDeviceToCloudMessageAsync(measurement);
                    } catch (Exception e)
                    {
                        Debug.WriteLine("Exception: " + e.Message);
                    }
                    await Task.Delay(1000);
                }
            }
        }
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            //Try to get a reference to a SenseHat in case we are running on a Raspberry Pi device
            //that has a SenseHat attached.
            try
            {
                _senseHat = await SenseHatFactory.GetSenseHat();

                _senseHat.Display.Clear();
                _senseHat.Display.Update();
            }
            catch (Exception)
            {
            }

            deviceInfoTextBlock.Text = $"Device IP Address: {Util.GetIpAddress()}";

            // Trigger IoT Hub initialization. It might potentially fail right away (e.g. no internet connection), so we will also
            // keep checking for it in the processing loop
            await CheckIoTHubConnectionAsync();

            IoTHubWrapper.Instance.UploadTrainingImagesRequested += UploadTrainingImagesRequested;
            IoTHubWrapper.Instance.DeleteCurrentModelRequested   += DeleteCurrentModelRequested;

            await LoadONNXModelAsync();
            await InitCameraAsync();

            // start processing loop
            this._processingLoopTask = Task.Run(() => this.ProcessingLoop());

            base.OnNavigatedTo(e);
        }
Пример #7
0
        private static void Main(string[] args)
        {
            ISenseHat senseHat = SenseHatFactory.GetSenseHat();

            // DiscoLights dl = new DiscoLights(senseHat);
            // dl.Run();

            // MultiColorScrollText colorScroll = new MultiColorScrollText(senseHat, "Hello Raspberry Pi 3 Sense HAT!");
            // colorScroll.Run();

            // SpriteAnimation mario = new SpriteAnimation(senseHat);
            // mario.Run();

            // BinaryClock bc = new BinaryClock(senseHat, null);
            // bc.Run();

            // Compass compass = new Compass(senseHat, null);
            // compass.Run();

            // GravityBlob gb = new GravityBlob(senseHat, null);
            // gb.Run();

            // JoystickPixel js = new JoystickPixel(senseHat, null);
            // js.Run();

            // ReadAllSensors ras = new ReadAllSensors(senseHat, null);
            // ras.Run();

            // SingleColorScrollText scroll = new SingleColorScrollText(senseHat, "Hello Raspberry Pi 3 Sense HAT!");
            // scroll.Run();

            WriteTemperature wt = new WriteTemperature(senseHat, null);

            wt.Run();
        }
Пример #8
0
        private async void DisplayTest()
        {
            SenseHat = await SenseHatFactory.GetSenseHat().ConfigureAwait(false);

            while (true)
            {
                var rand = new Random();

                for (int y = 0; y < 8; y++)
                {
                    for (int x = 0; x < 8; x++)
                    {
                        Color pixel = Color.FromArgb(
                            255,
                            (byte)rand.Next(256),
                            (byte)rand.Next(256),
                            (byte)rand.Next(256));

                        SenseHat.Display.Screen[x, y] = pixel;
                    }
                }

                SenseHat.Display.Update();
                await Task.Delay(500);
            }
        }
Пример #9
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            try
            {
                _senseHat = SenseHatFactory.GetSenseHat().Result;



                _senseHat.Display.Clear();
                _senseHat.Display.Fill(_color);
                _senseHat.Display.Update();
                //_senseHat = SenseHatFactory.GetSenseHat().Result;


                //_senseHat.Display.Clear();
                //_senseHat.Display.Fill(Colors.GreenYellow);
                //_senseHat.Display.Update();
                _deferral   = taskInstance.GetDeferral();
                this._timer = ThreadPoolTimer.CreatePeriodicTimer(Timer_TickAsync, TimeSpan.FromSeconds(3));
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                throw;
            }
        }
Пример #10
0
 public MainPage()
 {
     this.InitializeComponent();
     Task.Run(async() =>
     {
         hat = await SenseHatFactory.GetSenseHat().ConfigureAwait(false);
         //UpdateSensors();
         //DispatcherTimerSetup();
         UpdateSensors();
         await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                                                     () =>
         {
             dispatcherTimer          = new DispatcherTimer();
             dispatcherTimer.Tick    += dispatcherTimer_Tick;
             dispatcherTimer.Interval = new TimeSpan(0, 0, 10);
             //IsEnabled defaults to false
             TimerLog += "dispatcherTimer.IsEnabled = " + dispatcherTimer.IsEnabled + "\n";
             startTime = DateTimeOffset.Now;
             lastTime  = startTime;
             TimerLog += "Calling dispatcherTimer.Start()\n";
             dispatcherTimer.Start();
             //IsEnabled should now be true after calling start
             TimerLog += "dispatcherTimer.IsEnabled = " + dispatcherTimer.IsEnabled + "\n";
             Debug.WriteLine(TimerLog);
         });
     });
 }
Пример #11
0
        private async Task SendDeviceToCloudMessagesAsync()
        {
            var hat = await SenseHatFactory.GetSenseHat().ConfigureAwait(true);

            hat.Display.Fill(Colors.Aqua);
            hat.Display.Update();
            hat.Sensors.HumiditySensor.Update();

            while (true)
            {
                hat.Sensors.HumiditySensor.Update();
                var currentTemp = hat.Sensors.Temperature.GetValueOrDefault();
                Debug.WriteLine(currentTemp);

                var telemetryDataPoint = new
                {
                    temperature = currentTemp,
                };
                var messageString = JsonConvert.SerializeObject(telemetryDataPoint);
                var message       = new Message(Encoding.ASCII.GetBytes(messageString));

                await s_deviceClient.SendEventAsync(message);

                Console.WriteLine("{0} > Sending message: {1}", DateTime.Now, messageString);

                await Task.Delay(1000);
            }
        }
Пример #12
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            EnterKioskMode();

            if (string.IsNullOrEmpty(SettingsHelper.Instance.FaceApiKey))
            {
                await new MessageDialog("Missing Face API Key. Please enter a key in the Settings page.", "Missing API Key").ShowAsync();
            }
            else
            {
                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);
        }
Пример #13
0
        static async Task Main(string[] args)
        {
            ISenseHat senseHat = await SenseHatFactory.GetSenseHat().ConfigureAwait(false);

            senseHat.Display.Fill(Color.Blue);
            senseHat.Display.Update();
            //BinaryClock(senseHat);
        }
Пример #14
0
        /// <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);
        }
Пример #15
0
        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);
        }
Пример #16
0
        public async Task InitDevices()
        {
            hat = await SenseHatFactory.GetSenseHat().ConfigureAwait(false);

            hat.Display.Fill(Colors.Aqua);
            hat.Display.Update();

            ConnectIoTHub();
        }
Пример #17
0
        private async void InitSenseHat()
        {
            ISenseHat senseHat = await SenseHatFactory.GetSenseHat();

            this.SenseHat = senseHat;

            SenseHat.Display.Clear();
            timer.Start();
        }
Пример #18
0
        public async Task InitializeHat()
        {
            ISenseHat senseHat = await SenseHatFactory.GetSenseHat();

            this.SenseHat = senseHat;

            SenseHat.Display.Clear();
            await SenseHat.Sensors.HumiditySensor.InitAsync();
        }
Пример #19
0
 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();
     });
 }
Пример #20
0
        private static void Main(string[] args)
        {
            CoreDeviceFactory.Init();

            ISenseHat senseHat = SenseHatFactory.GetSenseHat();

            DemoSelector
            .GetDemo(senseHat, text => { })
            .Run();
        }
Пример #21
0
        private async void InitSenseHat()
        {
            ISenseHat senseHat = await SenseHatFactory.GetSenseHat();

            this.SenseHat = senseHat;

            SenseHat.Display.Clear();
            timer.Start();

            lblMessage.Text = "Running ...";
        }
Пример #22
0
        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);
        }
Пример #23
0
        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();
        }
        /// <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);
        }
Пример #25
0
        private async void InitSenseHat()
        {
            await iotClient.InitializeIoTServiceConnection();

            ISenseHat senseHat = await SenseHatFactory.GetSenseHat();

            this.SenseHat = senseHat;

            SenseHat.Display.Clear();
            timer.Start();
        }
Пример #26
0
        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);
        }
Пример #27
0
        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();
        }
Пример #28
0
        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();
        }
Пример #29
0
        public MainPage()
        {
            InitializeComponent();

            UwpI2CDeviceFactory.Init();

            Task.Factory.StartNew(() =>
            {
                ISenseHat senseHat = SenseHatFactory.GetSenseHat();
                SenseHatDemo demo  = DemoSelector.GetDemo(senseHat, SetScreenText);
                demo.Run();
            });
        }
Пример #30
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            try
            {
                senseHat = await SenseHatFactory.GetSenseHat();

                timer.Start();
            }
            catch
            {
                return;
            }
        }