Esempio n. 1
0
        public static async Task DisconnectAsync(bool removeLastDeviceInfo)
        {
            var batteryCharacteristic = await BluetoothDevice.GetGattCharacteristicAsync(GattCharacteristicUuids.BatteryLevel);

            if (batteryCharacteristic != null)
            {
                await batteryCharacteristic.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.None);
            }

            var screenshotsCharacteristic = await BluetoothDevice.GetGattCharacteristicAsync(Asteroid.ScreenshotContentCharacteristicUuid);

            if (screenshotsCharacteristic != null)
            {
                await screenshotsCharacteristic.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.None);
            }

            if (BluetoothDevice != null)
            {
                BluetoothDevice.ConnectionStatusChanged -= OnBluetoothDeviceConnectionStatusChanged;
                BluetoothDevice.Dispose();
                BluetoothDevice = null;
                Current         = null;

                if (removeLastDeviceInfo)
                {
                    UpdateLastSavedDeviceInfo(string.Empty, string.Empty);
                }
            }
        }
Esempio n. 2
0
        public static async Task <bool> UnregisterToScreenshotContentService()
        {
            var characteristic = await BluetoothDevice.GetGattCharacteristicAsync(Asteroid.ScreenshotContentCharacteristicUuid);

            if (characteristic == null)
            {
                return(true);
            }

            try
            {
                var notifyResult = await characteristic.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.None);

                if (notifyResult != GattCommunicationStatus.Success)
                {
                    return(false);
                }

                TotalSize = null;
                TotalData = null;
                Progress  = null;
                Messenger.Default.Send(new Messages.ScreenshotProgressMessage(percentage: 0));

                return(true);
            }
            catch (Exception exception)
            {
                Microsoft.HockeyApp.HockeyClient.Current.TrackException(exception);

                return(false);
            }
        }
Esempio n. 3
0
        public static async Task <bool> RemoveNotificationAsync(string notificationId)
        {
            var xmlNotification = AsteroidHelper.CreateRemoveNotificationCommandXml(notificationId);

            var characteristic = await BluetoothDevice.GetGattCharacteristicAsync(Asteroid.NotificationUpdateCharacteristicUuid);

            return(await characteristic.WriteByteArrayToCharacteristicAsync(Encoding.UTF8.GetBytes(xmlNotification)));
        }
Esempio n. 4
0
        public static async Task <bool> WriteByteArrayToCharacteristicAsync(Guid characteristicUuid, byte[] bytes)
        {
            var characteristic = await BluetoothDevice.GetGattCharacteristicAsync(characteristicUuid);

            if (characteristic == null)
            {
                return(false);
            }

            return(await characteristic.WriteByteArrayToCharacteristicAsync(bytes));
        }
Esempio n. 5
0
        public static async Task <bool> TakeScreenshotAsync()
        {
            var characteristic = await BluetoothDevice.GetGattCharacteristicAsync(Asteroid.ScreenshotRequestCharacteristicUuid);

            if (characteristic == null)
            {
                return(false);
            }

            return(await characteristic.WriteByteArrayToCharacteristicAsync(new byte[] { 0x1 }));
        }
Esempio n. 6
0
        public static async Task <bool> SetTimeAsync(int year, int month, int day, int hour, int minute, int second)
        {
            var characteristic = await BluetoothDevice.GetGattCharacteristicAsync(Asteroid.TimeSetCharacteristicUuid);

            if (characteristic == null)
            {
                return(false);
            }

            var yearByte   = Convert.ToByte(year - 1900);
            var monthByte  = Convert.ToByte(month - 1);
            var dayByte    = Convert.ToByte(day);
            var hourByte   = Convert.ToByte(hour);
            var minuteByte = Convert.ToByte(minute);
            var secondByte = Convert.ToByte(second);

            return(await characteristic.WriteByteArrayToCharacteristicAsync(new[] { yearByte, monthByte, dayByte, hourByte, minuteByte, secondByte }));
        }
Esempio n. 7
0
        public static async Task <bool> RegisterToScreenshotContentService()
        {
            var characteristic = await BluetoothDevice.GetGattCharacteristicAsync(Asteroid.ScreenshotContentCharacteristicUuid);

            if (characteristic == null)
            {
                return(false);
            }

            var notifyResult = await characteristic.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify);

            if (notifyResult != GattCommunicationStatus.Success)
            {
                return(false);
            }

            characteristic.ValueChanged += OnScreenshotContentCharacteristicValueChanged;
            return(true);
        }
Esempio n. 8
0
        public static async Task <int> GetBatteryPercentageAsync()
        {
            if (BluetoothDevice == null)
            {
                return(0);
            }

            var characteristic = await BluetoothDevice.GetGattCharacteristicAsync(GattCharacteristicUuids.BatteryLevel);

            if (characteristic == null)
            {
                return(0);
            }

            var valueResult = await characteristic.ReadValueAsync(BluetoothCacheMode.Uncached);

            if (valueResult.Status != GattCommunicationStatus.Success)
            {
                return(0);
            }

            return(BatteryHelper.GetPercentage(valueResult?.Value));
        }
Esempio n. 9
0
 public static Task <GattCharacteristic> GetGattCharacteristicAsync(Guid characteristicUuid)
 {
     return(BluetoothDevice.GetGattCharacteristicAsync(characteristicUuid));
 }