mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-23 16:17:32 +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);
|
sendToDevice(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBatteryInfoReq() {
|
||||||
|
byte[] bytes = gbDeviceProtocol.encodeBatteryInfoReq();
|
||||||
|
sendToDevice(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAppInfoReq() {
|
public void onAppInfoReq() {
|
||||||
byte[] bytes = gbDeviceProtocol.encodeAppInfoReq();
|
byte[] bytes = gbDeviceProtocol.encodeAppInfoReq();
|
||||||
|
@ -13,6 +13,8 @@ public interface EventHandler {
|
|||||||
|
|
||||||
public void onFirmwareVersionReq();
|
public void onFirmwareVersionReq();
|
||||||
|
|
||||||
|
public void onBatteryInfoReq();
|
||||||
|
|
||||||
public void onAppInfoReq();
|
public void onAppInfoReq();
|
||||||
|
|
||||||
public void onAppDelete(int id, int index);
|
public void onAppDelete(int id, int index);
|
||||||
|
@ -142,7 +142,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
|||||||
@Override
|
@Override
|
||||||
public void onFirmwareVersionReq() {
|
public void onFirmwareVersionReq() {
|
||||||
try {
|
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);
|
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_DEVICE_INFO);
|
||||||
builder.read(characteristic).queue(getQueue());
|
builder.read(characteristic).queue(getQueue());
|
||||||
} catch (IOException ex) {
|
} 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
|
@Override
|
||||||
public void onAppInfoReq() {
|
public void onAppInfoReq() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
@ -173,16 +184,11 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
|||||||
BluetoothGattCharacteristic characteristic, int status) {
|
BluetoothGattCharacteristic characteristic, int status) {
|
||||||
super.onCharacteristicRead(gatt, characteristic, 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);
|
handleDeviceInfo(characteristic.getValue(), status);
|
||||||
}
|
} else if (MiBandService.UUID_CHARACTERISTIC_BATTERY.equals(characteristicUUID)) {
|
||||||
}
|
handleBatteryInfo(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());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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) {
|
private void handleUserInfoResult(byte[] value, int status) {
|
||||||
// successfully transfered user info means we're initialized
|
// successfully transfered user info means we're initialized
|
||||||
if (status == BluetoothGatt.GATT_SUCCESS) {
|
if (status == BluetoothGatt.GATT_SUCCESS) {
|
||||||
|
@ -28,6 +28,10 @@ public abstract class GBDeviceProtocol {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte[] encodeBatteryInfoReq() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public byte[] encodeAppInfoReq() {
|
public byte[] encodeAppInfoReq() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user