1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 21:06:50 +01:00

Amazfit Bip: try to support weather in newer firmwares

This commit is contained in:
Andreas Shimokawa 2018-07-21 17:18:08 +02:00
parent d1253348dc
commit e96dcc69ab
3 changed files with 39 additions and 3 deletions

View File

@ -50,6 +50,8 @@ public class MiBand2Service {
public static final UUID UUID_CHARACTERISTIC_AUTH = UUID.fromString("00000009-0000-3512-2118-0009af100700");
public static final UUID UUID_CHARACTERISTIC_DEVICEEVENT = UUID.fromString("00000010-0000-3512-2118-0009af100700");
public static final UUID UUID_CHARACTERISTIC_CHUNKEDTRANSFER = UUID.fromString("00000020-0000-3512-2118-0009af100700");
public static final int ALERT_LEVEL_NONE = 0;
public static final int ALERT_LEVEL_MESSAGE = 1;
public static final int ALERT_LEVEL_PHONE_CALL = 2;

View File

@ -310,7 +310,6 @@ public class AmazfitBipSupport extends MiBand2Support {
for (WeatherSpec.Forecast forecast : weatherSpec.forecasts) {
condition = HuamiWeatherConditions.mapToAmazfitBipWeatherCode(forecast.conditionCode);
buf.put(condition);
buf.put(condition);
buf.put((byte) (forecast.maxTemp - 273));
@ -321,7 +320,12 @@ public class AmazfitBipSupport extends MiBand2Support {
}
}
builder.write(getCharacteristic(AmazfitBipService.UUID_CHARACTERISTIC_WEATHER), buf.array());
if (characteristicChunked != null) {
writeToChunked(builder, 1, buf.array());
} else {
builder.write(getCharacteristic(AmazfitBipService.UUID_CHARACTERISTIC_WEATHER), buf.array());
}
builder.queue(getQueue());
} catch (Exception ex) {
LOG.error("Error sending weather forecast", ex);

View File

@ -156,7 +156,8 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
}
};
BluetoothGattCharacteristic characteristicHRControlPoint;
private BluetoothGattCharacteristic characteristicHRControlPoint;
protected BluetoothGattCharacteristic characteristicChunked;
private boolean needsAuth;
private volatile boolean telephoneRinging;
@ -216,6 +217,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
}
new InitOperation(authenticate, authFlags, this, builder).perform();
characteristicHRControlPoint = getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT);
characteristicChunked = getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_CHUNKEDTRANSFER);
} catch (IOException e) {
GB.toast(getContext(), "Initializing Mi Band 2 failed", Toast.LENGTH_SHORT, GB.ERROR, e);
}
@ -1609,6 +1611,34 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
return this;
}
protected void writeToChunked(TransactionBuilder builder, int type, byte[] data) {
final int MAX_CHUNKLENGTH = 17;
int remaining = data.length;
byte count = 0;
while (remaining > 0) {
int copybytes = Math.min(remaining, MAX_CHUNKLENGTH);
byte[] chunk = new byte[copybytes + 3];
byte flags = 0;
if (remaining <= MAX_CHUNKLENGTH) {
flags |= 0x80; // last chunk
if (count == 0) {
flags |= 0x40; // weird but true
}
} else if (count > 0) {
flags |= 0x40; // consecutive chunk
}
chunk[0] = 0;
chunk[1] = (byte) (flags | type);
chunk[2] = (byte) (count & 0xff);
System.arraycopy(data, count++ * MAX_CHUNKLENGTH, chunk, 3, copybytes);
builder.write(characteristicChunked, chunk);
remaining -= copybytes;
}
}
public void phase2Initialize(TransactionBuilder builder) {
LOG.info("phase2Initialize...");
requestBatteryInfo(builder);