diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandCoordinator.java index afdc3e4e9..14e6c21ea 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandCoordinator.java @@ -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")); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandService.java index c376c10ce..0aa803723 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandService.java @@ -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 diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandSupport.java index f6e3e61b6..255df734d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandSupport.java @@ -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);