Exemplo n.º 1
0
        public async Task <BatteryInfo> GetBatteryInfo()
        {
            Debug.WriteLine("[miband] recibiendo bateria");
            Byte[] batteryInfoBytes = new Byte[1];
            // skip if received not exactly 10 bytes
            while (batteryInfoBytes.Length != 10)
            {
                batteryInfoBytes = await readFromCharacteristic(MiBand.UUID_CHAR_BATTERY);
            }
            BatteryInfo info = new BatteryInfo(batteryInfoBytes);

            if (info.Valid)
            {
                SettingSet("BatteryInfo", info.ToSetting());
            }
            Debug.WriteLine("[miband] bateria recibida");
            return(info);
        }
Exemplo n.º 2
0
        void batteryValueChanged(GattCharacteristic sender, GattValueChangedEventArgs args)
        {
            if (args.CharacteristicValue == null)
            {
                return;
            }
            byte[] buffer = new byte[args.CharacteristicValue.Length];
            DataReader.FromBuffer(args.CharacteristicValue).ReadBytes(buffer);

            BatteryInfo info = new BatteryInfo(buffer);

            if (info.Valid)
            {
                SettingSet("BatteryInfo", info.ToSetting());
                if (onBatteryCallback != null)
                {
                    onBatteryCallback(info);
                }
            }
        }
Exemplo n.º 3
0
        public static BatteryInfo FromSetting(ApplicationDataCompositeValue setting)
        {
            BatteryInfo info = new BatteryInfo((byte)setting["percentage"], (int)setting["charges"], (BatteryStatus)setting["status"], DateTime.FromBinary((long)setting["lastCharged"]));

            return(info);
        }