mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-27 02:55:50 +01:00
Xiaomi: Fix heart rate interval and sleep support
This commit is contained in:
parent
03dbf7533f
commit
130e2ab85c
@ -417,14 +417,12 @@ public class XiaomiSupport extends AbstractBTLEDeviceSupport {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnableHeartRateSleepSupport(final boolean enable) {
|
public void onEnableHeartRateSleepSupport(final boolean enable) {
|
||||||
// TODO onEnableHeartRateSleepSupport
|
healthService.setHeartRateConfig();
|
||||||
super.onEnableHeartRateSleepSupport(enable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSetHeartRateMeasurementInterval(final int seconds) {
|
public void onSetHeartRateMeasurementInterval(final int seconds) {
|
||||||
// TODO
|
healthService.setHeartRateConfig();
|
||||||
super.onSetHeartRateMeasurementInterval(seconds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -121,15 +121,28 @@ public class XiaomiHealthService extends AbstractXiaomiService {
|
|||||||
case CMD_CONFIG_SPO2_GET:
|
case CMD_CONFIG_SPO2_GET:
|
||||||
handleSpo2Config(cmd.getHealth().getSpo2());
|
handleSpo2Config(cmd.getHealth().getSpo2());
|
||||||
return;
|
return;
|
||||||
|
case CMD_CONFIG_SPO2_SET:
|
||||||
|
LOG.debug("Got spo2 set ack, status={}", cmd.getStatus());
|
||||||
|
return;
|
||||||
|
case CMD_CONFIG_HEART_RATE_SET:
|
||||||
|
LOG.debug("Got heart rate set ack, status={}", cmd.getStatus());
|
||||||
|
return;
|
||||||
|
|
||||||
case CMD_CONFIG_HEART_RATE_GET:
|
case CMD_CONFIG_HEART_RATE_GET:
|
||||||
handleHeartRateConfig(cmd.getHealth().getHeartRate());
|
handleHeartRateConfig(cmd.getHealth().getHeartRate());
|
||||||
return;
|
return;
|
||||||
case CMD_CONFIG_STANDING_REMINDER_GET:
|
case CMD_CONFIG_STANDING_REMINDER_GET:
|
||||||
handleStandingReminderConfig(cmd.getHealth().getStandingReminder());
|
handleStandingReminderConfig(cmd.getHealth().getStandingReminder());
|
||||||
return;
|
return;
|
||||||
|
case CMD_CONFIG_STANDING_REMINDER_SET:
|
||||||
|
LOG.debug("Got standing reminder set ack, status={}", cmd.getStatus());
|
||||||
|
return;
|
||||||
case CMD_CONFIG_STRESS_GET:
|
case CMD_CONFIG_STRESS_GET:
|
||||||
handleStressConfig(cmd.getHealth().getStress());
|
handleStressConfig(cmd.getHealth().getStress());
|
||||||
return;
|
return;
|
||||||
|
case CMD_CONFIG_STRESS_SET:
|
||||||
|
LOG.debug("Got stress set ack, status={}", cmd.getStatus());
|
||||||
|
return;
|
||||||
case CMD_WORKOUT_WATCH_STATUS:
|
case CMD_WORKOUT_WATCH_STATUS:
|
||||||
handleWorkoutStatus(cmd.getHealth().getWorkoutStatusWatch());
|
handleWorkoutStatus(cmd.getHealth().getWorkoutStatusWatch());
|
||||||
return;
|
return;
|
||||||
@ -311,18 +324,35 @@ public class XiaomiHealthService extends AbstractXiaomiService {
|
|||||||
getSupport().evaluateGBDeviceEvent(eventUpdatePreferences);
|
getSupport().evaluateGBDeviceEvent(eventUpdatePreferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setHeartRateConfig() {
|
public void setHeartRateConfig() {
|
||||||
final Prefs prefs = getDevicePrefs();
|
final Prefs prefs = getDevicePrefs();
|
||||||
|
|
||||||
final boolean sleepDetection = prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_HEARTRATE_USE_FOR_SLEEP_DETECTION, false);
|
final boolean sleepDetection = prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_HEARTRATE_USE_FOR_SLEEP_DETECTION, false);
|
||||||
final boolean sleepBreathingQuality = prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_HEARTRATE_SLEEP_BREATHING_QUALITY_MONITORING, false);
|
final boolean sleepBreathingQuality = prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_HEARTRATE_SLEEP_BREATHING_QUALITY_MONITORING, false);
|
||||||
final int intervalMin = prefs.getInt(DeviceSettingsPreferenceConst.PREF_HEARTRATE_MEASUREMENT_INTERVAL, 0);
|
final int intervalSeconds = prefs.getInt(DeviceSettingsPreferenceConst.PREF_HEARTRATE_MEASUREMENT_INTERVAL, 0);
|
||||||
final int alertHigh = prefs.getInt(DeviceSettingsPreferenceConst.PREF_HEARTRATE_ALERT_HIGH_THRESHOLD, 0);
|
final int alertHigh = prefs.getInt(DeviceSettingsPreferenceConst.PREF_HEARTRATE_ALERT_HIGH_THRESHOLD, 0);
|
||||||
final int alertLow = prefs.getInt(DeviceSettingsPreferenceConst.PREF_HEARTRATE_ALERT_LOW_THRESHOLD, 0);
|
final int alertLow = prefs.getInt(DeviceSettingsPreferenceConst.PREF_HEARTRATE_ALERT_LOW_THRESHOLD, 0);
|
||||||
|
|
||||||
|
int intervalMin;
|
||||||
|
if (intervalSeconds == -1) {
|
||||||
|
// Smart
|
||||||
|
intervalMin = 0;
|
||||||
|
} else {
|
||||||
|
intervalMin = intervalSeconds / 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.debug(
|
||||||
|
"Set heart rate config: sleepDetection={}, sleepBreathingQuality={}, intervalSeconds={}, alertHigh={}, alertLow={}",
|
||||||
|
sleepDetection,
|
||||||
|
sleepBreathingQuality,
|
||||||
|
intervalSeconds,
|
||||||
|
alertHigh,
|
||||||
|
alertLow
|
||||||
|
);
|
||||||
|
|
||||||
final XiaomiProto.HeartRate.Builder heartRate = XiaomiProto.HeartRate.newBuilder()
|
final XiaomiProto.HeartRate.Builder heartRate = XiaomiProto.HeartRate.newBuilder()
|
||||||
.setDisabled(intervalMin == 0)
|
.setDisabled(intervalSeconds == 0)
|
||||||
.setInterval(Math.max(intervalMin, 0)) // smart will be -1 from pref
|
.setInterval(intervalMin)
|
||||||
.setAdvancedMonitoring(XiaomiProto.AdvancedMonitoring.newBuilder()
|
.setAdvancedMonitoring(XiaomiProto.AdvancedMonitoring.newBuilder()
|
||||||
.setEnabled(sleepDetection))
|
.setEnabled(sleepDetection))
|
||||||
.setBreathingScore(sleepBreathingQuality ? 1 : 2)
|
.setBreathingScore(sleepBreathingQuality ? 1 : 2)
|
||||||
|
Loading…
Reference in New Issue
Block a user