54 lines
1.3 KiB
C#
54 lines
1.3 KiB
C#
using Assets.Scripts.Ble;
|
|
using Assets.Scripts.Devices.Ble.Interfaces;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
|
|
namespace Assets.Scripts.Devices.Ble.Characteristic
|
|
{
|
|
public class BatteryLevel : ICharacteristic
|
|
{
|
|
public Guid Uuid => ServiceUuids.Characteristics.BatteryLevel;
|
|
|
|
public Guid ServiceUuid => ServiceUuids.Get(ServiceUuids.Battery).IdGuid;
|
|
|
|
private ICharacteristic _characteristicUnavailable = null;
|
|
public ICharacteristic CharacteristicUnavailable
|
|
{
|
|
get
|
|
{
|
|
return this._characteristicUnavailable;
|
|
}
|
|
}
|
|
|
|
public virtual bool IsOptional
|
|
{
|
|
get
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public int BatteryLevelValue { get; private set; }
|
|
|
|
public void HandleAttributeReceived(byte[] data)
|
|
{
|
|
if(data.Length < 1)
|
|
{
|
|
return;
|
|
}
|
|
BatteryLevelValue = (int)data[0];
|
|
|
|
//Debug.Log($"电量:{ BatteryLevelValue }");
|
|
}
|
|
|
|
public void SetUnavailable()
|
|
{
|
|
this._characteristicUnavailable = this;
|
|
}
|
|
}
|
|
}
|