mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-15 06:29:24 +01:00
Merge branch 'heartrate-sleep-support' of https://github.com/computerlyrik/Gadgetbridge into computerlyrik-heartrate-sleep-support
This commit is contained in:
commit
b54fe53cd5
@ -33,7 +33,7 @@ public abstract class AbstractSettingsActivity extends PreferenceActivity {
|
||||
}
|
||||
|
||||
public void updateSummary(Preference preference, Object value) {
|
||||
String stringValue = value.toString();
|
||||
String stringValue = String.valueOf(value);
|
||||
|
||||
if (preference instanceof ListPreference) {
|
||||
// For list preferences, look up the correct display value in
|
||||
|
@ -15,6 +15,8 @@ public final class MiBandConst {
|
||||
public static final String PREF_MIBAND_FITNESS_GOAL = "mi_fitness_goal";
|
||||
public static final String PREF_MIBAND_DONT_ACK_TRANSFER = "mi_dont_ack_transfer";
|
||||
public static final String PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR = "mi_reserve_alarm_calendar";
|
||||
public static final String PREF_MIBAND_USE_HR_FOR_SLEEP_DETECTION = "mi_hr_sleep_detection";
|
||||
|
||||
|
||||
|
||||
public static final String ORIGIN_SMS = "sms";
|
||||
|
@ -135,6 +135,11 @@ public class MiBandCoordinator extends AbstractDeviceCoordinator {
|
||||
return location;
|
||||
}
|
||||
|
||||
public static boolean getHeartrateSleepSupport(String miBandAddress) throws IllegalArgumentException {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(GBApplication.getContext());
|
||||
return prefs.getBoolean(MiBandConst.PREF_MIBAND_USE_HR_FOR_SLEEP_DETECTION, false);
|
||||
}
|
||||
|
||||
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"));
|
||||
|
@ -18,6 +18,7 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PR
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_DONT_ACK_TRANSFER;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_FITNESS_GOAL;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_USE_HR_FOR_SLEEP_DETECTION;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_WEARSIDE;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_USER_ALIAS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.VIBRATION_COUNT;
|
||||
@ -54,6 +55,7 @@ public class MiBandPreferencesActivity extends AbstractSettingsActivity {
|
||||
PREF_MIBAND_FITNESS_GOAL,
|
||||
PREF_MIBAND_DONT_ACK_TRANSFER,
|
||||
PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR,
|
||||
PREF_MIBAND_USE_HR_FOR_SLEEP_DETECTION,
|
||||
getNotificationPrefKey(VIBRATION_PROFILE, ORIGIN_SMS),
|
||||
getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_SMS),
|
||||
getNotificationPrefKey(VIBRATION_PROFILE, ORIGIN_INCOMING_CALL),
|
||||
|
@ -109,6 +109,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
.sendUserInfo(builder)
|
||||
.checkAuthenticationNeeded(builder, getDevice())
|
||||
.setWearLocation(builder)
|
||||
.setHeartrateSleepSupport(builder)
|
||||
.setFitnessGoal(builder)
|
||||
.enableFurtherNotifications(builder, true)
|
||||
.setCurrentTime(builder)
|
||||
@ -368,6 +369,34 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Part of device initialization process. Do not call manually.
|
||||
*
|
||||
* @param transaction
|
||||
* @return
|
||||
*/
|
||||
private MiBandSupport setHeartrateSleepSupport(TransactionBuilder transaction) {
|
||||
if (supportsHeartRate()) {
|
||||
LOG.info("Attempting to set heartrate sleep support...");
|
||||
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT);
|
||||
if (characteristic != null) {
|
||||
if(MiBandCoordinator.getHeartrateSleepSupport(getDevice().getAddress())) {
|
||||
LOG.info("Enabling heartrate sleep support...");
|
||||
transaction.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT), startHeartMeasurementSleep);
|
||||
}
|
||||
else {
|
||||
LOG.info("Disabling heartrate sleep support...");
|
||||
transaction.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT), stopHeartMeasurementSleep);
|
||||
}
|
||||
} else {
|
||||
LOG.info("Unable to set Heartrate sleep support");
|
||||
}
|
||||
|
||||
} else
|
||||
GB.toast(getContext(), "Heart rate is not supported on this device", Toast.LENGTH_LONG, GB.ERROR);
|
||||
return this;
|
||||
}
|
||||
|
||||
private void performDefaultNotification(String task, short repeat, BtLEAction extraAction) {
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized(task);
|
||||
|
@ -213,6 +213,8 @@
|
||||
<string name="miband_fwinstaller_incompatible_version">Incompatible firmware</string>
|
||||
<string name="fwinstaller_firmware_not_compatible_to_device">This firmware is not compatible with the device</string>
|
||||
<string name="miband_prefs_reserve_alarm_calendar">Alarms to reserve for upcoming events</string>
|
||||
<string name="miband_prefs_hr_sleep_detection">Use Heartrate Sensor to improve sleep detection</string>
|
||||
|
||||
<string name="waiting_for_reconnect">waiting for reconnect</string>
|
||||
<string name="appmananger_app_reinstall">Reinstall</string>
|
||||
|
||||
|
@ -30,6 +30,10 @@
|
||||
android:maxLength="1"
|
||||
android:digits="0123"
|
||||
android:title="@string/miband_prefs_reserve_alarm_calendar" />
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="mi_hr_sleep_detection"
|
||||
android:title="@string/miband_prefs_hr_sleep_detection" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
|
Loading…
Reference in New Issue
Block a user