mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-28 19:45:50 +01:00
Mi Band 2: Change distance unit
This commit is contained in:
parent
58c7691142
commit
5701707e87
@ -37,6 +37,7 @@ import java.util.Set;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband2.MiBand2FWInstallHandler;
|
||||
@ -189,6 +190,16 @@ public class MiBand2Coordinator extends MiBandCoordinator {
|
||||
return new Date();
|
||||
}
|
||||
|
||||
public static MiBandConst.DistanceUnit getDistanceUnit() {
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
String unit = prefs.getString(SettingsActivity.PREF_MEASUREMENT_SYSTEM, GBApplication.getContext().getString(R.string.p_unit_metric));
|
||||
if (unit.equals(GBApplication.getContext().getString(R.string.p_unit_metric))) {
|
||||
return MiBandConst.DistanceUnit.METRIC;
|
||||
} else {
|
||||
return MiBandConst.DistanceUnit.IMPERIAL;
|
||||
}
|
||||
}
|
||||
|
||||
public static DoNotDisturb getDoNotDisturb(Context context) {
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
|
||||
|
@ -144,6 +144,8 @@ public class MiBand2Service {
|
||||
public static final byte[] COMMAND_DISABLE_DISPLAY_CALLER = new byte[]{ENDPOINT_DISPLAY, 0x10, 0x00, 0x00, 0x00};
|
||||
public static final byte[] DISPLAY_XXX = new byte[] {ENDPOINT_DISPLAY, 0x03, 0x0, 0x0 };
|
||||
public static final byte[] DISPLAY_YYY = new byte[] {ENDPOINT_DISPLAY, 0x10, 0x0, 0x1, 0x1 };
|
||||
public static final byte[] COMMAND_DISTANCE_UNIT_METRIC = new byte[] { ENDPOINT_DISPLAY, 0x03, 0x00, 0x00 };
|
||||
public static final byte[] COMMAND_DISTANCE_UNIT_IMPERIAL = new byte[] { ENDPOINT_DISPLAY, 0x03, 0x00, 0x01 };
|
||||
|
||||
// The third byte controls the threshold, in minutes
|
||||
// The last 8 bytes represent 2 separate time intervals for the inactivity warnings
|
||||
|
@ -81,6 +81,11 @@ public final class MiBandConst {
|
||||
public static final Version MI2_FW_VERSION_MIN_TEXT_NOTIFICATIONS = new Version("1.0.1.28");
|
||||
public static final Version MI2_FW_VERSION_INTERMEDIATE_UPGRADE_53 = new Version("1.0.0.53");
|
||||
|
||||
public enum DistanceUnit {
|
||||
METRIC,
|
||||
IMPERIAL
|
||||
}
|
||||
|
||||
public static int getNotificationPrefIntValue(String pref, String origin, Prefs prefs, int defaultValue) {
|
||||
String key = getNotificationPrefKey(pref, origin);
|
||||
return prefs.getInt(key, defaultValue);
|
||||
|
@ -48,6 +48,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.Logging;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo;
|
||||
@ -1252,6 +1253,9 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
||||
case MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_DND_END:
|
||||
setInactivityWarnings(builder);
|
||||
break;
|
||||
case SettingsActivity.PREF_MEASUREMENT_SYSTEM:
|
||||
setDistanceUnit(builder);
|
||||
break;
|
||||
}
|
||||
builder.queue(getQueue());
|
||||
} catch (IOException e) {
|
||||
@ -1452,6 +1456,17 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
||||
return this;
|
||||
}
|
||||
|
||||
private MiBand2Support setDistanceUnit(TransactionBuilder builder) {
|
||||
MiBandConst.DistanceUnit unit = MiBand2Coordinator.getDistanceUnit();
|
||||
LOG.info("Setting distance unit to " + unit);
|
||||
if (unit == MiBandConst.DistanceUnit.METRIC) {
|
||||
builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION), MiBand2Service.COMMAND_DISTANCE_UNIT_METRIC);
|
||||
} else {
|
||||
builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION), MiBand2Service.COMMAND_DISTANCE_UNIT_IMPERIAL);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public void phase2Initialize(TransactionBuilder builder) {
|
||||
LOG.info("phase2Initialize...");
|
||||
requestBatteryInfo(builder);
|
||||
@ -1462,6 +1477,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
||||
setDateDisplay(builder);
|
||||
setTimeFormat(builder);
|
||||
setUserInfo(builder);
|
||||
setDistanceUnit(builder);
|
||||
setWearLocation(builder);
|
||||
setFitnessGoal(builder);
|
||||
setDisplayItems(builder);
|
||||
|
Loading…
Reference in New Issue
Block a user