Beispiel #1
0
        async void NotifyTemperature(GattCharacteristic sender, GattValueChangedEventArgs args)
        {
            byte[] rawData = BLE_Utilities.getDataBytes(args);
            float  temp    = SensorConvert.convertTemperature(rawData);

            await this.Dispatcher.BeginInvoke((Action)(() => setTemperature(temp)));
        }
Beispiel #2
0
        //## Magnetometer
        async Task ReadMagnetometer()
        {
            byte[] rawData = await BLE_Utilities.ReadData(Sensor.Accelerometer);

            float[] vals = SensorConvert.convertAccelerometer(rawData);
            await this.Dispatcher.BeginInvoke((Action)(() => setMagnetometer(vals[0], vals[1], vals[2])));
        }
Beispiel #3
0
        async void NotifyHumidity(GattCharacteristic sender, GattValueChangedEventArgs args)
        {
            byte[] rawData = BLE_Utilities.getDataBytes(args);
            float  acthum  = SensorConvert.convertHumidity(rawData);

            await this.Dispatcher.BeginInvoke((Action)(() => setHumidity(acthum)));
        }
Beispiel #4
0
        //## Gyroscope
        async Task ReadGyroscope()
        {
            byte[] rawData = await BLE_Utilities.ReadData(Sensor.Gyroscope);

            float[] vals = SensorConvert.convertGyroscope(rawData);
            await this.Dispatcher.BeginInvoke((Action)(() => setGyroscope(vals[0], vals[1], vals[2])));
        }
Beispiel #5
0
        //##Temperature
        async Task ReadTemperature()
        {
            byte[] rawData = await BLE_Utilities.ReadData(Sensor.Temperature);

            float temp = SensorConvert.convertTemperature(rawData);

            await this.Dispatcher.BeginInvoke((Action)(() => setTemperature(temp)));
        }
Beispiel #6
0
        //## Humidity
        async Task ReadHumidity()
        {
            byte[] rawData = await BLE_Utilities.ReadData(Sensor.Humidity);

            float acthum = SensorConvert.convertHumidity(rawData);

            await this.Dispatcher.BeginInvoke((Action)(() => setHumidity(acthum)));
        }
Beispiel #7
0
        //Buttons
        async void notifyButton(GattCharacteristic sender, GattValueChangedEventArgs args)
        {
            byte[] data = BLE_Utilities.getDataBytes(args);

            //My method is actually " setButton setButtons(data[0]) "
            //But if you want to change ANYTHING in the UI you have to wrap
            //like I did below.
            await this.Dispatcher.BeginInvoke((Action)(() => setButtons(data[0])));
        }
Beispiel #8
0
        private async Task DisableSensors()
        {
            await BLE_Utilities.DisableSensor(Sensor.Accelerometer);

            await BLE_Utilities.DisableSensor(Sensor.Gyroscope);

            await BLE_Utilities.DisableSensor(Sensor.Temperature);

            await BLE_Utilities.DisableSensor(Sensor.Magnetometer);

            await BLE_Utilities.DisableSensor(Sensor.Pressure);

            await BLE_Utilities.DisableSensor(Sensor.Humidity);
        }
Beispiel #9
0
        /// <summary>
        /// An event handler that keeps the onChange eventListener of the different sensors alive.
        /// </summary>
        /// <param name="sender"> a timer object</param>
        /// <param name="e"> </param>
        private async void refreshNotifications(object sender, ElapsedEventArgs e)
        {
            if (notificationsEnabled)
            {
                await BLE_Utilities.executeOnNotification(Sensor.Keys, notifyButton);

                await BLE_Utilities.executeOnNotification(Sensor.Accelerometer, NotifyAccelerometer);

                await BLE_Utilities.executeOnNotification(Sensor.Humidity, NotifyHumidity);

                await BLE_Utilities.executeOnNotification(Sensor.Gyroscope, NotifyGyroscope);

                await BLE_Utilities.executeOnNotification(Sensor.Magnetometer, NotifyMagnetometer);

                await BLE_Utilities.executeOnNotification(Sensor.Temperature, NotifyTemperature);
            }
        }
Beispiel #10
0
        //#EVENT LISTENERS FOR GUI COMPONENTS
        private async void buttonEnableNotifications_Click(object sender, RoutedEventArgs e)
        {
            notificationsEnabled = !notificationsEnabled;
            if (notificationsEnabled)
            {
                buttonEnableNotifications.Content = "Disable Notifications";
                Title = "Demo - Notifications [On]";

                await BLE_Utilities.executeOnNotification(Sensor.Keys, notifyButton);

                await BLE_Utilities.executeOnNotification(Sensor.Accelerometer, NotifyAccelerometer);

                await BLE_Utilities.executeOnNotification(Sensor.Humidity, NotifyHumidity);

                await BLE_Utilities.executeOnNotification(Sensor.Gyroscope, NotifyGyroscope);

                await BLE_Utilities.executeOnNotification(Sensor.Magnetometer, NotifyMagnetometer);

                await BLE_Utilities.executeOnNotification(Sensor.Pressure, NotifyPressure);

                await BLE_Utilities.executeOnNotification(Sensor.Temperature, NotifyTemperature);
            }
            else
            {
                Title = "Demo - Notifications [Off]";
                buttonEnableNotifications.Content = "Enable Notifications";

                await BLE_Utilities.dispose(Sensor.Keys);

                await BLE_Utilities.dispose(Sensor.Accelerometer);

                await BLE_Utilities.dispose(Sensor.Humidity);

                await BLE_Utilities.dispose(Sensor.Gyroscope);

                await BLE_Utilities.dispose(Sensor.Magnetometer);

                await BLE_Utilities.dispose(Sensor.Pressure);

                await BLE_Utilities.dispose(Sensor.Temperature);
            }
        }
Beispiel #11
0
 async void NotifyMagnetometer(GattCharacteristic sender, GattValueChangedEventArgs args)
 {
     byte[]  rawData = BLE_Utilities.getDataBytes(args);
     float[] vals    = SensorConvert.convertAccelerometer(rawData);
     await this.Dispatcher.BeginInvoke((Action)(() => setMagnetometer(vals[0], vals[1], vals[2])));
 }