1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-23 18:36:50 +01:00

Send the wear location (left hand / right hand) to the MiBand.

This commit is contained in:
Daniele Gobbetti 2015-07-31 13:48:11 +02:00
parent 69ddead8fb
commit 46ee5a5499
3 changed files with 34 additions and 2 deletions

View File

@ -107,6 +107,15 @@ public class MiBandCoordinator implements DeviceCoordinator {
return info;
}
public static int getWearLocation(String miBandAddress) throws IllegalArgumentException {
int location = 0; //left hand
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(GBApplication.getContext());
if (prefs.getString(MiBandConst.PREF_MIBAND_WEARSIDE, "left") == "right") {
location = 1; // right hand
}
return location;
}
public static int getFitnessGoal(String miBandAddress) throws IllegalArgumentException {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(GBApplication.getContext());
return Integer.parseInt(prefs.getString(MiBandConst.PREF_MIBAND_FITNESS_GOAL, "10000"));

View File

@ -141,6 +141,8 @@ public class MiBandService {
public static final byte COMMAND_REBOOT = 0xc;
public static final byte COMMAND_SET_WEAR_LOCATION = 0xf;
public static final byte COMMAND_STOP_MOTOR_VIBRATE = 0x13;
/*
@ -148,10 +150,8 @@ public class MiBandService {
public static final byte COMMAND_FACTORY_RESET = 0x9t;
public static final byte COMMAND_GET_SENSOR_DATA = 0x12t
public static final int COMMAND_SET_COLOR_THEME = et;
public static final COMMAND_SET_REALTIME_STEP = 0x10t

View File

@ -97,6 +97,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
builder.add(new SetDeviceStateAction(getDevice(), State.INITIALIZING, getContext()));
pair(builder)
.sendUserInfo(builder)
.setWearLocation(builder)
.setFitnessGoal(builder)
.enableNotifications(builder, true)
.setCurrentTime(builder)
@ -291,6 +292,28 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
}
return this;
}
/**
* Part of device initialization process. Do not call manually.
*
* @param transaction
* @return
*/
private MiBandSupport setWearLocation(TransactionBuilder transaction) {
LOG.info("Attempting to set wear location...");
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT);
if (characteristic != null) {
int location = MiBandCoordinator.getWearLocation(getDevice().getAddress());
transaction.write(characteristic, new byte[]{
MiBandService.COMMAND_SET_WEAR_LOCATION,
(byte) location
});
} else {
LOG.info("Unable to set Wear Location");
}
return this;
}
private void performDefaultNotification(String task, short repeat, BtLEAction extraAction) {
try {
TransactionBuilder builder = performInitialized(task);