mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-04 09:17:29 +01:00
Mi Band 2/ Bip: Do not send user info if not set up
This commit is contained in:
parent
717eb6ba58
commit
e28085e6af
@ -373,51 +373,57 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
private MiBand2Support setUserInfo(TransactionBuilder transaction) {
|
private MiBand2Support setUserInfo(TransactionBuilder transaction) {
|
||||||
|
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_8_USER_SETTINGS);
|
||||||
|
if (characteristic == null) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.info("Attempting to set user info...");
|
||||||
Prefs prefs = GBApplication.getPrefs();
|
Prefs prefs = GBApplication.getPrefs();
|
||||||
String alias = prefs.getString(MiBandConst.PREF_USER_ALIAS, null);
|
String alias = prefs.getString(MiBandConst.PREF_USER_ALIAS, null);
|
||||||
LOG.info("Attempting to set user info...");
|
ActivityUser activityUser = new ActivityUser();
|
||||||
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_8_USER_SETTINGS);
|
int height = activityUser.getHeightCm();
|
||||||
if (characteristic != null && alias != null) {
|
int weight = activityUser.getWeightKg();
|
||||||
ActivityUser activityUser = new ActivityUser();
|
int birth_year = activityUser.getYearOfBirth();
|
||||||
int birth_year = activityUser.getYearOfBirth();
|
byte birth_month = 7; // not in user attributes
|
||||||
byte birth_month = 7; // not in user attributes
|
byte birth_day = 1; // not in user attributes
|
||||||
byte birth_day = 1; // not in user attributes
|
|
||||||
byte sex = 2; // other
|
|
||||||
switch (activityUser.getGender()) {
|
|
||||||
case ActivityUser.GENDER_MALE:
|
|
||||||
sex = 0;
|
|
||||||
break;
|
|
||||||
case ActivityUser.GENDER_FEMALE:
|
|
||||||
sex = 1;
|
|
||||||
}
|
|
||||||
int height = activityUser.getHeightCm();
|
|
||||||
int weight = activityUser.getWeightKg();
|
|
||||||
int userid = alias.hashCode(); // hash from alias like mi1
|
|
||||||
|
|
||||||
// FIXME: Do encoding like in PebbleProtocol, this is ugly
|
if (alias == null || weight == 0 || height == 0 || birth_year == 0) {
|
||||||
byte bytes[] = new byte[]{
|
LOG.warn("Unable to set user info, make sure it is set up");
|
||||||
MiBand2Service.COMMAND_SET_USERINFO,
|
return this;
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
byte sex = 2; // other
|
||||||
|
switch (activityUser.getGender()) {
|
||||||
|
case ActivityUser.GENDER_MALE:
|
||||||
|
sex = 0;
|
||||||
|
break;
|
||||||
|
case ActivityUser.GENDER_FEMALE:
|
||||||
|
sex = 1;
|
||||||
|
}
|
||||||
|
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);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user