Mi Band 2/Bip: implement setting user info (experimental, disabled)

master
Andreas Shimokawa 2017-09-23 00:08:34 +02:00
parent 6ec1555178
commit 2be84435ce
2 changed files with 55 additions and 3 deletions

View File

@ -45,7 +45,7 @@ public class MiBand2Service {
public static final UUID UUID_CHARACTERISTIC_5_ACTIVITY_DATA = UUID.fromString("00000005-0000-3512-2118-0009af100700");
public static final UUID UUID_CHARACTERISTIC_6_BATTERY_INFO = UUID.fromString("00000006-0000-3512-2118-0009af100700");
public static final UUID UUID_CHARACTERISTIC_7_REALTIME_STEPS = UUID.fromString("00000007-0000-3512-2118-0009af100700");
public static final UUID UUID_UNKNOWN_CHARACTERISTIC8 = UUID.fromString("00000008-0000-3512-2118-0009af100700");
public static final UUID UUID_CHARACTERISTIC_8_USER_SETTINGS = UUID.fromString("00000008-0000-3512-2118-0009af100700");
// service uuid fee1
public static final UUID UUID_CHARACTERISTIC_AUTH = UUID.fromString("00000009-0000-3512-2118-0009af100700");
public static final UUID UUID_CHARACTERISTIC_10_BUTTON = UUID.fromString("00000010-0000-3512-2118-0009af100700");
@ -110,6 +110,8 @@ public class MiBand2Service {
public static final byte[] COMMAND_SET_FITNESS_GOAL_START = new byte[] { 0x10, 0x0, 0x0 };
public static final byte[] COMMAND_SET_FITNESS_GOAL_END = new byte[] { 0, 0 };
public static final byte COMMAND_SET_USERINFO = 0x4f;
public static final byte ICON_HIGH_PRIORITY = 0x7;
public static byte ENDPOINT_DISPLAY_ITEMS = 0x0a;

View File

@ -350,7 +350,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
private MiBand2Support setFitnessGoal(TransactionBuilder transaction) {
LOG.info("Attempting to set Fitness Goal...");
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBand2Service.UUID_UNKNOWN_CHARACTERISTIC8);
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_8_USER_SETTINGS);
if (characteristic != null) {
int fitnessGoal = GBApplication.getPrefs().getInt(ActivityUser.PREF_USER_STEPS_GOAL, 10000);
byte[] bytes = ArrayUtils.addAll(
@ -365,6 +365,55 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
return this;
}
/**
* Part of device initialization process. Do not call manually.
*
* @param transaction
* @return
*/
private MiBand2Support setUserInfo(TransactionBuilder transaction) {
Prefs prefs = GBApplication.getPrefs();
String alias = prefs.getString(MiBandConst.PREF_USER_ALIAS, null);
LOG.info("Attempting to set user info...");
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_8_USER_SETTINGS);
if (characteristic != null || alias == null) {
// TODO: get all from userattributes
short birth_year = 1980;
byte birth_month = 12;
byte birth_day = 24;
byte sex = 0; // male 0. female 1, other 2
short height = 175;
short weight = 70;
int userid = alias.hashCode(); // hash from alias like mi1
// FIXME: Do encoding like in PebbleProtocol, this is ugly
byte bytes[] = new byte[]{
MiBand2Service.COMMAND_SET_USERINFO,
0,
0,
(byte) (birth_year & 0xff),
(byte) ((birth_year >> 8) & 0xff),
birth_month,
birth_day,
sex,
(byte) (height & 0xff),
(byte) ((height >> 8) & 0xff),
(byte) ((weight * 200) & 0xff),
(byte) (((weight * 200) >> 8) & 0xff),
(byte) (userid & 0xff),
(byte) ((userid >> 8) & 0xff),
(byte) ((userid >> 16) & 0xff),
(byte) ((userid >> 24) & 0xff)
};
transaction.write(characteristic, bytes);
} else {
LOG.warn("Unable to set user info");
}
return this;
}
/**
* Part of device initialization process. Do not call manually.
*
@ -373,7 +422,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
*/
private MiBand2Support setWearLocation(TransactionBuilder builder) {
LOG.info("Attempting to set wear location...");
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBand2Service.UUID_UNKNOWN_CHARACTERISTIC8);
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_8_USER_SETTINGS);
if (characteristic != null) {
builder.notify(characteristic, true);
int location = MiBandCoordinator.getWearLocation(getDevice().getAddress());
@ -1395,6 +1444,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
LOG.info("phase3Initialize...");
setDateDisplay(builder);
setTimeFormat(builder);
///setUserInfo(builder);
setWearLocation(builder);
setFitnessGoal(builder);
setDisplayItems(builder);