mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-23 08:07:33 +01:00
battery info hooked in, dummy for pebble
This commit is contained in:
parent
686ed312d6
commit
4a1a1d59be
@ -81,6 +81,12 @@ public abstract class AbstractBTDeviceSupport extends AbstractDeviceSupport {
|
||||
sendToDevice(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBatteryInfoReq() {
|
||||
byte[] bytes = gbDeviceProtocol.encodeBatteryInfoReq();
|
||||
sendToDevice(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAppInfoReq() {
|
||||
byte[] bytes = gbDeviceProtocol.encodeAppInfoReq();
|
||||
|
@ -13,6 +13,8 @@ public interface EventHandler {
|
||||
|
||||
public void onFirmwareVersionReq();
|
||||
|
||||
public void onBatteryInfoReq();
|
||||
|
||||
public void onAppInfoReq();
|
||||
|
||||
public void onAppDelete(int id, int index);
|
||||
|
@ -142,7 +142,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
@Override
|
||||
public void onFirmwareVersionReq() {
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized("Get MI Band Device Info");
|
||||
TransactionBuilder builder = performInitialized("Get MI Band device info");
|
||||
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_DEVICE_INFO);
|
||||
builder.read(characteristic).queue(getQueue());
|
||||
} catch (IOException ex) {
|
||||
@ -150,6 +150,17 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBatteryInfoReq() {
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized("Get MI Band battery info");
|
||||
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_BATTERY);
|
||||
builder.read(characteristic).queue(getQueue());
|
||||
} catch (IOException ex) {
|
||||
Log.e(TAG, "Unable to read battery info from MI", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAppInfoReq() {
|
||||
// TODO Auto-generated method stub
|
||||
@ -173,16 +184,11 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
BluetoothGattCharacteristic characteristic, int status) {
|
||||
super.onCharacteristicRead(gatt, characteristic, status);
|
||||
|
||||
if (MiBandService.UUID_CHARACTERISTIC_DEVICE_INFO.equals(characteristic.getUuid())) {
|
||||
UUID characteristicUUID = characteristic.getUuid();
|
||||
if (MiBandService.UUID_CHARACTERISTIC_DEVICE_INFO.equals(characteristicUUID)) {
|
||||
handleDeviceInfo(characteristic.getValue(), status);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleDeviceInfo(byte[] value, int status) {
|
||||
if (status == BluetoothGatt.GATT_SUCCESS) {
|
||||
DeviceInfo info = new DeviceInfo(value);
|
||||
getDevice().setFirmwareVersion(info.getFirmwareVersion());
|
||||
getDevice().sendDeviceUpdateIntent(getContext());
|
||||
} else if (MiBandService.UUID_CHARACTERISTIC_BATTERY.equals(characteristicUUID)) {
|
||||
handleBatteryInfo(characteristic.getValue(), status);
|
||||
}
|
||||
}
|
||||
|
||||
@ -197,6 +203,23 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
}
|
||||
|
||||
private void handleDeviceInfo(byte[] value, int status) {
|
||||
if (status == BluetoothGatt.GATT_SUCCESS) {
|
||||
DeviceInfo info = new DeviceInfo(value);
|
||||
getDevice().setFirmwareVersion(info.getFirmwareVersion());
|
||||
getDevice().sendDeviceUpdateIntent(getContext());
|
||||
}
|
||||
}
|
||||
|
||||
private void handleBatteryInfo(byte[] value, int status) {
|
||||
if (status == BluetoothGatt.GATT_SUCCESS) {
|
||||
BatteryInfo info = new BatteryInfo(value);
|
||||
getDevice().setBatteryLevel((short) info.getLevelInPercent());
|
||||
getDevice().setBatteryState(info.getStatus());
|
||||
getDevice().sendDeviceUpdateIntent(getContext());
|
||||
}
|
||||
}
|
||||
|
||||
private void handleUserInfoResult(byte[] value, int status) {
|
||||
// successfully transfered user info means we're initialized
|
||||
if (status == BluetoothGatt.GATT_SUCCESS) {
|
||||
|
@ -28,6 +28,10 @@ public abstract class GBDeviceProtocol {
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] encodeBatteryInfoReq() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] encodeAppInfoReq() {
|
||||
return null;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user