1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-29 05:16:51 +01:00

First step for GBDeviceEvents support:

- change fw handling to GBDeviceEvent
- misuse the hw version for showing the MiBand device name (there is still no option to set a custom name)
This commit is contained in:
Daniele Gobbetti 2015-08-10 10:35:55 +02:00
parent fd5a620091
commit b6d3317b2d

View File

@ -20,6 +20,7 @@ import java.util.GregorianCalendar;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo;
import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand; import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand;
@ -95,6 +96,9 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
private byte[] newFirmware; private byte[] newFirmware;
private boolean rebootWhenBandReady = false; private boolean rebootWhenBandReady = false;
GBDeviceEventVersionInfo versionCmd = new GBDeviceEventVersionInfo();
public MiBandSupport() { public MiBandSupport() {
addSupportedService(MiBandService.UUID_SERVICE_MIBAND_SERVICE); addSupportedService(MiBandService.UUID_SERVICE_MIBAND_SERVICE);
} }
@ -495,8 +499,11 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
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 device_info = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_DEVICE_INFO);
builder.read(characteristic).queue(getQueue()); builder.read(device_info);
BluetoothGattCharacteristic device_name = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_DEVICE_NAME);
builder.read(device_name);
builder.queue(getQueue());
} catch (IOException ex) { } catch (IOException ex) {
LOG.error("Unable to read device info from MI", ex); LOG.error("Unable to read device info from MI", ex);
} }
@ -659,6 +666,8 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
UUID characteristicUUID = characteristic.getUuid(); UUID characteristicUUID = characteristic.getUuid();
if (MiBandService.UUID_CHARACTERISTIC_DEVICE_INFO.equals(characteristicUUID)) { if (MiBandService.UUID_CHARACTERISTIC_DEVICE_INFO.equals(characteristicUUID)) {
handleDeviceInfo(characteristic.getValue(), status); handleDeviceInfo(characteristic.getValue(), status);
} else if (MiBandService.UUID_CHARACTERISTIC_DEVICE_NAME.equals(characteristicUUID)) {
handleDeviceName(characteristic.getValue(), status);
} else if (MiBandService.UUID_CHARACTERISTIC_BATTERY.equals(characteristicUUID)) { } else if (MiBandService.UUID_CHARACTERISTIC_BATTERY.equals(characteristicUUID)) {
handleBatteryInfo(characteristic.getValue(), status); handleBatteryInfo(characteristic.getValue(), status);
} }
@ -748,8 +757,15 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
private void handleDeviceInfo(byte[] value, int status) { private void handleDeviceInfo(byte[] value, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) { if (status == BluetoothGatt.GATT_SUCCESS) {
mDeviceInfo = new DeviceInfo(value); mDeviceInfo = new DeviceInfo(value);
getDevice().setFirmwareVersion(mDeviceInfo.getHumanFirmwareVersion()); versionCmd.fwVersion = mDeviceInfo.getHumanFirmwareVersion();
getDevice().sendDeviceUpdateIntent(getContext()); handleGBDeviceEvent(versionCmd);
}
}
private void handleDeviceName(byte[] value, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
versionCmd.hwVersion = new String(value);
handleGBDeviceEvent(versionCmd);
} }
} }