mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-24 00:27:33 +01:00
Mi Band 3/4, Amazfit Bip/Cor: Add setting to expose the HR sensor to 3rd party apps
Closes #1606
This commit is contained in:
parent
4e13317609
commit
243eec042d
@ -29,6 +29,7 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF
|
|||||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ITEMS;
|
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ITEMS;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ON_LIFT_END;
|
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ON_LIFT_END;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ON_LIFT_START;
|
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ON_LIFT_START;
|
||||||
|
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_EXPOSE_HR_THIRDPARTY;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_LANGUAGE;
|
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_LANGUAGE;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB;
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_END;
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_END;
|
||||||
@ -287,6 +288,7 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
|
|||||||
addPreferenceHandlerFor(PREF_DATEFORMAT);
|
addPreferenceHandlerFor(PREF_DATEFORMAT);
|
||||||
addPreferenceHandlerFor(PREF_DISPLAY_ITEMS);
|
addPreferenceHandlerFor(PREF_DISPLAY_ITEMS);
|
||||||
addPreferenceHandlerFor(PREF_LANGUAGE);
|
addPreferenceHandlerFor(PREF_LANGUAGE);
|
||||||
|
addPreferenceHandlerFor(PREF_EXPOSE_HR_THIRDPARTY);
|
||||||
|
|
||||||
String displayOnLiftState = prefs.getString(PREF_ACTIVATE_DISPLAY_ON_LIFT, PREF_DO_NOT_DISTURB_OFF);
|
String displayOnLiftState = prefs.getString(PREF_ACTIVATE_DISPLAY_ON_LIFT, PREF_DO_NOT_DISTURB_OFF);
|
||||||
boolean displayOnLiftScheduled = displayOnLiftState.equals(PREF_DO_NOT_DISTURB_SCHEDULED);
|
boolean displayOnLiftScheduled = displayOnLiftState.equals(PREF_DO_NOT_DISTURB_SCHEDULED);
|
||||||
|
@ -61,7 +61,7 @@ public class HuamiConst {
|
|||||||
public static final String PREF_DISPLAY_ITEMS = "display_items";
|
public static final String PREF_DISPLAY_ITEMS = "display_items";
|
||||||
public static final String PREF_LANGUAGE = "language";
|
public static final String PREF_LANGUAGE = "language";
|
||||||
public static final String PREF_DATEFORMAT = "dateformat";
|
public static final String PREF_DATEFORMAT = "dateformat";
|
||||||
|
public static final String PREF_EXPOSE_HR_THIRDPARTY = "expose_hr_thirdparty";
|
||||||
|
|
||||||
public static int toActivityKind(int rawType) {
|
public static int toActivityKind(int rawType) {
|
||||||
switch (rawType) {
|
switch (rawType) {
|
||||||
|
@ -251,6 +251,11 @@ public abstract class HuamiCoordinator extends AbstractDeviceCoordinator {
|
|||||||
return prefs.getBoolean(MiBandConst.PREF_SWIPE_UNLOCK, false);
|
return prefs.getBoolean(MiBandConst.PREF_SWIPE_UNLOCK, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean getExposeHRThirdParty(String deviceAddress) {
|
||||||
|
Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(deviceAddress));
|
||||||
|
return prefs.getBoolean(HuamiConst.PREF_EXPOSE_HR_THIRDPARTY, false);
|
||||||
|
}
|
||||||
|
|
||||||
protected static Date getTimePreference(String key, String defaultValue, String deviceAddress) {
|
protected static Date getTimePreference(String key, String defaultValue, String deviceAddress) {
|
||||||
Prefs prefs;
|
Prefs prefs;
|
||||||
|
|
||||||
|
@ -139,6 +139,8 @@ public class HuamiService {
|
|||||||
public static final byte[] DATEFORMAT_TIME_12_HOURS = new byte[] {ENDPOINT_DISPLAY, 0x02, 0x0, 0x0 };
|
public static final byte[] DATEFORMAT_TIME_12_HOURS = new byte[] {ENDPOINT_DISPLAY, 0x02, 0x0, 0x0 };
|
||||||
public static final byte[] DATEFORMAT_TIME_24_HOURS = new byte[] {ENDPOINT_DISPLAY, 0x02, 0x0, 0x1 };
|
public static final byte[] DATEFORMAT_TIME_24_HOURS = new byte[] {ENDPOINT_DISPLAY, 0x02, 0x0, 0x1 };
|
||||||
public static final byte[] DATEFORMAT_DATE_MM_DD_YYYY = new byte[]{ENDPOINT_DISPLAY, 30, 0x00, 'M', 'M', '/', 'd', 'd', '/', 'y', 'y', 'y', 'y'};
|
public static final byte[] DATEFORMAT_DATE_MM_DD_YYYY = new byte[]{ENDPOINT_DISPLAY, 30, 0x00, 'M', 'M', '/', 'd', 'd', '/', 'y', 'y', 'y', 'y'};
|
||||||
|
public static final byte[] COMMAND_ENBALE_HR_CONNECTION = new byte[]{ENDPOINT_DISPLAY, 0x01, 0x00, 0x01};
|
||||||
|
public static final byte[] COMMAND_DISABLE_HR_CONNECTION = new byte[]{ENDPOINT_DISPLAY, 0x01, 0x00, 0x00};
|
||||||
public static final byte[] COMMAND_ENABLE_DISPLAY_ON_LIFT_WRIST = new byte[]{ENDPOINT_DISPLAY, 0x05, 0x00, 0x01};
|
public static final byte[] COMMAND_ENABLE_DISPLAY_ON_LIFT_WRIST = new byte[]{ENDPOINT_DISPLAY, 0x05, 0x00, 0x01};
|
||||||
public static final byte[] COMMAND_DISABLE_DISPLAY_ON_LIFT_WRIST = new byte[]{ENDPOINT_DISPLAY, 0x05, 0x00, 0x00};
|
public static final byte[] COMMAND_DISABLE_DISPLAY_ON_LIFT_WRIST = new byte[]{ENDPOINT_DISPLAY, 0x05, 0x00, 0x00};
|
||||||
public static final byte[] COMMAND_SCHEDULE_DISPLAY_ON_LIFT_WRIST = new byte[]{ENDPOINT_DISPLAY, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00};
|
public static final byte[] COMMAND_SCHEDULE_DISPLAY_ON_LIFT_WRIST = new byte[]{ENDPOINT_DISPLAY, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00};
|
||||||
|
@ -83,6 +83,7 @@ public class AmazfitBipCoordinator extends HuamiCoordinator {
|
|||||||
R.xml.devicesettings_amazfitbip,
|
R.xml.devicesettings_amazfitbip,
|
||||||
R.xml.devicesettings_liftwrist_display,
|
R.xml.devicesettings_liftwrist_display,
|
||||||
R.xml.devicesettings_disconnectnotification,
|
R.xml.devicesettings_disconnectnotification,
|
||||||
|
R.xml.devicesettings_expose_hr_thirdparty,
|
||||||
R.xml.devicesettings_pairingkey
|
R.xml.devicesettings_pairingkey
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -86,6 +86,8 @@ public class AmazfitCorCoordinator extends HuamiCoordinator {
|
|||||||
R.xml.devicesettings_amazfitcor,
|
R.xml.devicesettings_amazfitcor,
|
||||||
R.xml.devicesettings_liftwrist_display,
|
R.xml.devicesettings_liftwrist_display,
|
||||||
R.xml.devicesettings_disconnectnotification,
|
R.xml.devicesettings_disconnectnotification,
|
||||||
R.xml.devicesettings_pairingkey};
|
R.xml.devicesettings_expose_hr_thirdparty,
|
||||||
|
R.xml.devicesettings_pairingkey
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,6 +108,7 @@ public class MiBand3Coordinator extends HuamiCoordinator {
|
|||||||
R.xml.devicesettings_donotdisturb_withauto,
|
R.xml.devicesettings_donotdisturb_withauto,
|
||||||
R.xml.devicesettings_liftwrist_display,
|
R.xml.devicesettings_liftwrist_display,
|
||||||
R.xml.devicesettings_swipeunlock,
|
R.xml.devicesettings_swipeunlock,
|
||||||
|
R.xml.devicesettings_expose_hr_thirdparty,
|
||||||
R.xml.devicesettings_pairingkey
|
R.xml.devicesettings_pairingkey
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,7 @@ public class MiBand4Coordinator extends HuamiCoordinator {
|
|||||||
R.xml.devicesettings_nightmode,
|
R.xml.devicesettings_nightmode,
|
||||||
R.xml.devicesettings_liftwrist_display,
|
R.xml.devicesettings_liftwrist_display,
|
||||||
R.xml.devicesettings_swipeunlock,
|
R.xml.devicesettings_swipeunlock,
|
||||||
|
R.xml.devicesettings_expose_hr_thirdparty,
|
||||||
R.xml.devicesettings_pairingkey
|
R.xml.devicesettings_pairingkey
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1568,6 +1568,9 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
|||||||
case HuamiConst.PREF_LANGUAGE:
|
case HuamiConst.PREF_LANGUAGE:
|
||||||
setLanguage(builder);
|
setLanguage(builder);
|
||||||
break;
|
break;
|
||||||
|
case HuamiConst.PREF_EXPOSE_HR_THIRDPARTY:
|
||||||
|
setExposeHRThridParty(builder);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
builder.queue(getQueue());
|
builder.queue(getQueue());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -2095,6 +2098,20 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private HuamiSupport setExposeHRThridParty(TransactionBuilder builder) {
|
||||||
|
boolean enable = HuamiCoordinator.getExposeHRThirdParty(gbDevice.getAddress());
|
||||||
|
LOG.info("Setting exposure of HR to third party apps to: " + enable);
|
||||||
|
|
||||||
|
if (enable) {
|
||||||
|
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.COMMAND_ENBALE_HR_CONNECTION);
|
||||||
|
} else {
|
||||||
|
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.COMMAND_DISABLE_HR_CONNECTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
protected void writeToChunked(TransactionBuilder builder, int type, byte[] data) {
|
protected void writeToChunked(TransactionBuilder builder, int type, byte[] data) {
|
||||||
final int MAX_CHUNKLENGTH = 17;
|
final int MAX_CHUNKLENGTH = 17;
|
||||||
int remaining = data.length;
|
int remaining = data.length;
|
||||||
@ -2145,6 +2162,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
|||||||
setInactivityWarnings(builder);
|
setInactivityWarnings(builder);
|
||||||
setHeartrateSleepSupport(builder);
|
setHeartrateSleepSupport(builder);
|
||||||
setDisconnectNotification(builder);
|
setDisconnectNotification(builder);
|
||||||
|
setExposeHRThridParty(builder);
|
||||||
setHeartrateMeasurementInterval(builder, getHeartRateMeasurementInterval());
|
setHeartrateMeasurementInterval(builder, getHeartRateMeasurementInterval());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,6 +165,9 @@
|
|||||||
<string name="pref_title_pebble_enable_bgjs">Enable background JS</string>
|
<string name="pref_title_pebble_enable_bgjs">Enable background JS</string>
|
||||||
<string name="pref_summary_pebble_enable_bgjs">When enabled, allows watchfaces to show weather, battery info etc.</string>
|
<string name="pref_summary_pebble_enable_bgjs">When enabled, allows watchfaces to show weather, battery info etc.</string>
|
||||||
<string name="pref_title_pebble_reconnect_attempts">Reconnection attempts</string>
|
<string name="pref_title_pebble_reconnect_attempts">Reconnection attempts</string>
|
||||||
|
<string name="pref_summary_expose_hr">Allows other apps to access HR data in realtime while Gadgetbridge is connected</string>
|
||||||
|
<string name="pref_title_expose_hr">3rd party realtime HR access</string>
|
||||||
|
|
||||||
<!-- HPlus Preferences -->
|
<!-- HPlus Preferences -->
|
||||||
<string name="pref_title_unit_system">Units</string>
|
<string name="pref_title_unit_system">Units</string>
|
||||||
<string name="pref_title_timeformat">Time format</string>
|
<string name="pref_title_timeformat">Time format</string>
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<SwitchPreference
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:key="expose_hr_thirdparty"
|
||||||
|
android:layout="@layout/preference_checkbox"
|
||||||
|
android:summary="@string/pref_summary_expose_hr"
|
||||||
|
android:title="@string/pref_title_expose_hr" />
|
||||||
|
</androidx.preference.PreferenceScreen>
|
Loading…
x
Reference in New Issue
Block a user