예제 #1
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            //
            // TODO: Insert code to perform background work
            //
            // If you start any asynchronous methods here, prevent the task
            // from closing prematurely by using BackgroundTaskDeferral as
            // described in http://aka.ms/backgroundtaskdeferral

            _deferral = taskInstance.GetDeferral();

            await Task.Delay(30000);

            bs = new RateSensor();
            bs.RateSensorInit();

            await Task.Delay(1000);

            bs.RateMonitorON();

            deviceWatcher = DeviceInformation.CreateWatcher(
                "System.ItemNameDisplay:~~\"Adafruit\"",
                new string[] {
                "System.Devices.Aep.DeviceAddress",
                "System.Devices.Aep.IsConnected"
            },
                DeviceInformationKind.AssociationEndpoint);

            deviceWatcher.Added   += DeviceWatcher_Added;
            deviceWatcher.Removed += DeviceWatcher_Removed;
            deviceWatcher.Start();

            // NFC
            proxDevice = ProximityDevice.GetDefault();
            if (proxDevice != null)
            {
                proxDevice.SubscribeForMessage("NDEF", messagedReceived);
            }
            else
            {
                Debug.WriteLine("No proximity device found\n");
            }

            this.timer = ThreadPoolTimer.CreateTimer(Timer_Tick, TimeSpan.FromSeconds(2));

            try
            {
                await Task.Run(async() =>
                {
                    while (true)
                    {
                        await Task.Delay(100000);
                    }
                });
            }
            catch (Exception ex)
            {
            }
            deviceWatcher.Stop();
        }
예제 #2
0
        const string UUID_UART_RX   = "6e400002-b5a3-f393-e0a9-e50e24dcca9e"; //RX, Write characteristic

        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            //
            // TODO: Insert code to perform background work
            //
            // If you start any asynchronous methods here, prevent the task
            // from closing prematurely by using BackgroundTaskDeferral as
            // described in http://aka.ms/backgroundtaskdeferral

            _deferral = taskInstance.GetDeferral();

            await Task.Delay(30000);

            bs = new RateSensor();
            bs.RateSensorInit();

            await Task.Delay(1000);

            bs.RateMonitorON();

            deviceWatcher = DeviceInformation.CreateWatcher(
                "System.ItemNameDisplay:~~\"Adafruit\"",
                new string[] {
                "System.Devices.Aep.DeviceAddress",
                "System.Devices.Aep.IsConnected"
            },
                DeviceInformationKind.AssociationEndpoint);

            deviceWatcher.Added   += DeviceWatcher_Added;
            deviceWatcher.Removed += DeviceWatcher_Removed;
            deviceWatcher.Start();

            this.timer = ThreadPoolTimer.CreateTimer(Timer_Tick, TimeSpan.FromSeconds(2));

            try
            {
                await Task.Run(async() =>
                {
                    while (true)
                    {
                        await Task.Delay(100000);
                    }
                });
            }
            catch (Exception ex)
            {
            }
            deviceWatcher.Stop();

            //
            // Once the asynchronous method(s) are done, close the deferral.
            //
            //_deferral.Complete();
            //
        }
        public async void UpdateAllData()
        {
            leDevice = await BluetoothLEDevice.FromIdAsync(device.Id);

            string selector = "(System.DeviceInterface.Bluetooth.DeviceAddress:=\"" + leDevice.BluetoothAddress.ToString("X") + "\")";

            var services = await leDevice.GetGattServicesAsync();

            foreach (var service in services.Services)
            {
                switch (service.Uuid.ToString())
                {
                case SensorUUIDs.UUID_UART_SERV:
                {
                    var characteristics = await service.GetCharacteristicsAsync();

                    foreach (var character in characteristics.Characteristics)
                    {
                        switch (character.Uuid.ToString())
                        {
                        case SensorUUIDs.UUID_UART_RX:
                        {
                            var writer = new DataWriter();
                            // DATA:SET command not yet working
                            //string message = "DATA:SET #22046524f4d205741544348\n";
                            //writer.WriteString(message);
                            //await character.WriteValueAsync(writer.DetachBuffer());

                            // Reading and displaying heartrate from BioSensor
                            RateSensor bs = new RateSensor();
                            bs.RateSensorInit();
                            // await Task.Delay(1000);
                            bs.RateMonitorON();
                            hrmHeartRate = bs.GetHeartRate();
                            Debug.WriteLine($"Current heartrate: {hrmHeartRate}");
                            // hrmHeartRate = bs.I2C_ReadRegData(HrmSensor, AS7000_REG_HRM_HEARTRATE);
                            //await Task.Delay(1);



                            //writing TRIGGER to the AdafruitBT
                            writer.WriteString("TRIGGER\n");
                            //writing current HeartRate to the Adafruit bluetooth
                            //writer.WriteString(hrmHeartRate);
                            await character.WriteValueAsync(writer.DetachBuffer());
                        }
                        break;
                        }
                    }
                }
                break;
                }
            }
        }