battery info hooked in, dummy for pebble

master
cpfeiffer 2015-04-19 22:31:09 +02:00
parent 686ed312d6
commit 4a1a1d59be
4 changed files with 45 additions and 10 deletions

View File

@ -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();

View File

@ -13,6 +13,8 @@ public interface EventHandler {
public void onFirmwareVersionReq();
public void onBatteryInfoReq();
public void onAppInfoReq();
public void onAppDelete(int id, int index);

View File

@ -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) {

View File

@ -28,6 +28,10 @@ public abstract class GBDeviceProtocol {
return null;
}
public byte[] encodeBatteryInfoReq() {
return null;
}
public byte[] encodeAppInfoReq() {
return null;
}