1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-01 06:22:55 +01:00

add preference to set hartrate sleep detection

This commit is contained in:
Christian Fischer 2016-04-02 16:09:30 +02:00
parent 72258c178c
commit 20aa7d9ad9
6 changed files with 40 additions and 0 deletions

View File

@ -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";

View File

@ -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"));

View File

@ -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),

View File

@ -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,30 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
return this;
}
/**
* Part of device initialization process. Do not call manually.
*
* @param transaction
* @return
*/
private MiBandSupport setHeartrateSleepSupport(TransactionBuilder transaction) {
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 Wear Location");
}
return this;
}
private void performDefaultNotification(String task, short repeat, BtLEAction extraAction) {
try {
TransactionBuilder builder = performInitialized(task);

View File

@ -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>

View File

@ -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