/// <summary>
        /// Retrieves the sensor device and saves it for further usage.
        /// IMPORTANT: Has to be called from UI thread the first time the app uses the device to be able to ask the user for permission to use it
        /// </summary>
        /// <returns>Indicates if the gatt service could be retrieved and set successfully</returns>
        /// <exception cref="DeviceNotFoundException">Thrown if there isn't a device which matches the sensor service id.</exception>
        public async Task <bool> Initialize()
        {
            if (this.deviceService != null)
            {
                Clean();
            }
            this.deviceService = await GattUtils.GetDeviceService(SensorTagUuid.UUID_INF_SERV);

            if (this.deviceService == null)
            {
                return(false);
            }
            return(true);
        }
Esempio n. 2
0
        public async Task <string> tagstext()
        {
            Accelerometer            acc  = new Accelerometer();
            List <DeviceInformation> list = await GattUtils.GetDevicesOfService(acc.SensorServiceUuid);

            //lbTags.ItemsSource = list;
            if (list != null)
            {
                return("Total: " + list.Count);
            }
            else
            {
                return(string.Empty);
            }
        }
Esempio n. 3
0
        private async void btnShowSensorTags_Click(object sender, RoutedEventArgs e)
        {
            Accelerometer            acc  = new Accelerometer();
            List <DeviceInformation> list = await GattUtils.GetDevicesOfService(acc.SensorServiceUuid);

            lbTags.ItemsSource = list;
            if (list != null)
            {
                tbNumberOfTags.Text = "Total: " + list.Count;
            }
            else
            {
                tbNumberOfTags.Text = string.Empty;
            }
        }
Esempio n. 4
0
        private async void SetupSensors(bool serviceAsParameter)
        {
            pbar.Visibility = Windows.UI.Xaml.Visibility.Visible;
            ClearSensors();
            btnSetup.IsEnabled       = false;
            btnSetupParam.IsEnabled  = false;
            spTestButtons.Visibility = Windows.UI.Xaml.Visibility.Collapsed;

            Exception ex = null;

            try
            {
                if (serviceAsParameter)
                {
                    acc = new Accelerometer();
                    acc.SensorValueChanged += SensorValueChanged;
                    await acc.Initialize((await GattUtils.GetDevicesOfService(acc.SensorServiceUuid))[0]);

                    await acc.EnableSensor();

                    gyro = new Gyroscope();
                    gyro.SensorValueChanged += SensorValueChanged;
                    await gyro.Initialize((await GattUtils.GetDevicesOfService(gyro.SensorServiceUuid))[0]);

                    await gyro.EnableSensor();

                    hum = new HumiditySensor();
                    hum.SensorValueChanged += SensorValueChanged;
                    await hum.Initialize((await GattUtils.GetDevicesOfService(hum.SensorServiceUuid))[0]);

                    await hum.EnableSensor();

                    ks = new SimpleKeyService();
                    ks.SensorValueChanged += SensorValueChanged;
                    await ks.Initialize((await GattUtils.GetDevicesOfService(ks.SensorServiceUuid))[0]);

                    await ks.EnableSensor();

                    mg = new Magnetometer();
                    mg.SensorValueChanged += SensorValueChanged;
                    await mg.Initialize((await GattUtils.GetDevicesOfService(mg.SensorServiceUuid))[0]);

                    await mg.EnableSensor();

                    ps = new PressureSensor();
                    ps.SensorValueChanged += SensorValueChanged;
                    await ps.Initialize((await GattUtils.GetDevicesOfService(ps.SensorServiceUuid))[0]);

                    await ps.EnableSensor();

                    tempSen = new IRTemperatureSensor();
                    tempSen.SensorValueChanged += SensorValueChanged;
                    await tempSen.Initialize((await GattUtils.GetDevicesOfService(tempSen.SensorServiceUuid))[0]);

                    await tempSen.EnableSensor();

                    spTestButtons.Visibility = Windows.UI.Xaml.Visibility.Visible;
                }
                else
                {
                    acc = new Accelerometer();
                    acc.SensorValueChanged += SensorValueChanged;
                    await acc.Initialize();

                    await acc.EnableSensor();

                    gyro = new Gyroscope();
                    gyro.SensorValueChanged += SensorValueChanged;
                    await gyro.Initialize();

                    await gyro.EnableSensor();

                    hum = new HumiditySensor();
                    hum.SensorValueChanged += SensorValueChanged;
                    await hum.Initialize();

                    await hum.EnableSensor();

                    ks = new SimpleKeyService();
                    ks.SensorValueChanged += SensorValueChanged;
                    await ks.Initialize();

                    await ks.EnableSensor();

                    mg = new Magnetometer();
                    mg.SensorValueChanged += SensorValueChanged;
                    await mg.Initialize();

                    await mg.EnableSensor();

                    ps = new PressureSensor();
                    ps.SensorValueChanged += SensorValueChanged;
                    await ps.Initialize();

                    await ps.EnableSensor();

                    tempSen = new IRTemperatureSensor();
                    tempSen.SensorValueChanged += SensorValueChanged;
                    await tempSen.Initialize();

                    await tempSen.EnableSensor();

                    spTestButtons.Visibility = Windows.UI.Xaml.Visibility.Visible;
                }
            }
            catch (Exception exc)
            {
                ex = exc;
            }

            if (ex != null)
            {
                await new MessageDialog(ex.Message).ShowAsync();
            }

            pbar.Visibility         = Windows.UI.Xaml.Visibility.Collapsed;
            btnSetup.IsEnabled      = true;
            btnSetupParam.IsEnabled = true;
        }