mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-30 22:12:55 +01:00
Small fixes to PR 273 #232
- dynamically toggle hr sleep support when preference changes - check hr support dynaically after device info is available to avoid false error message
This commit is contained in:
parent
7cda9f1923
commit
b129844169
@ -48,4 +48,5 @@ public interface EventHandler {
|
|||||||
|
|
||||||
void onScreenshotReq();
|
void onScreenshotReq();
|
||||||
|
|
||||||
|
void onEnableHeartRateSleepSupport(boolean enable);
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import android.os.Bundle;
|
|||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractSettingsActivity;
|
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractSettingsActivity;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.activities.ControlCenter;
|
import nodomain.freeyourgadget.gadgetbridge.activities.ControlCenter;
|
||||||
@ -44,6 +45,14 @@ public class MiBandPreferencesActivity extends AbstractSettingsActivity {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
final Preference enableHeartrateSleepSupport = findPreference(PREF_MIBAND_USE_HR_FOR_SLEEP_DETECTION);
|
||||||
|
enableHeartrateSleepSupport.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
||||||
|
GBApplication.deviceService().onEnableHeartRateSleepSupport(Boolean.TRUE.equals(newVal));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -55,7 +64,6 @@ public class MiBandPreferencesActivity extends AbstractSettingsActivity {
|
|||||||
PREF_MIBAND_FITNESS_GOAL,
|
PREF_MIBAND_FITNESS_GOAL,
|
||||||
PREF_MIBAND_DONT_ACK_TRANSFER,
|
PREF_MIBAND_DONT_ACK_TRANSFER,
|
||||||
PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR,
|
PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR,
|
||||||
PREF_MIBAND_USE_HR_FOR_SLEEP_DETECTION,
|
|
||||||
getNotificationPrefKey(VIBRATION_PROFILE, ORIGIN_SMS),
|
getNotificationPrefKey(VIBRATION_PROFILE, ORIGIN_SMS),
|
||||||
getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_SMS),
|
getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_SMS),
|
||||||
getNotificationPrefKey(VIBRATION_PROFILE, ORIGIN_INCOMING_CALL),
|
getNotificationPrefKey(VIBRATION_PROFILE, ORIGIN_INCOMING_CALL),
|
||||||
|
@ -205,7 +205,14 @@ public class GBDeviceService implements DeviceService {
|
|||||||
@Override
|
@Override
|
||||||
public void onEnableRealtimeSteps(boolean enable) {
|
public void onEnableRealtimeSteps(boolean enable) {
|
||||||
Intent intent = createIntent().setAction(ACTION_ENABLE_REALTIME_STEPS)
|
Intent intent = createIntent().setAction(ACTION_ENABLE_REALTIME_STEPS)
|
||||||
.putExtra(EXTRA_ENABLE_REALTIME_STEPS, enable);
|
.putExtra(EXTRA_BOOLEAN_ENABLE, enable);
|
||||||
|
invokeService(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnableHeartRateSleepSupport(boolean enable) {
|
||||||
|
Intent intent = createIntent().setAction(ACTION_ENABLE_HEARTRATE_SLEEP_SUPPORT)
|
||||||
|
.putExtra(EXTRA_BOOLEAN_ENABLE, enable);
|
||||||
invokeService(intent);
|
invokeService(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ public interface DeviceService extends EventHandler {
|
|||||||
String ACTION_SET_ALARMS = PREFIX + ".action.set_alarms";
|
String ACTION_SET_ALARMS = PREFIX + ".action.set_alarms";
|
||||||
String ACTION_ENABLE_REALTIME_STEPS = PREFIX + ".action.enable_realtime_steps";
|
String ACTION_ENABLE_REALTIME_STEPS = PREFIX + ".action.enable_realtime_steps";
|
||||||
String ACTION_REALTIME_STEPS = PREFIX + ".action.realtime_steps";
|
String ACTION_REALTIME_STEPS = PREFIX + ".action.realtime_steps";
|
||||||
|
String ACTION_ENABLE_HEARTRATE_SLEEP_SUPPORT = PREFIX + ".action.enable_heartrate_sleep_support";
|
||||||
String EXTRA_DEVICE_ADDRESS = "device_address";
|
String EXTRA_DEVICE_ADDRESS = "device_address";
|
||||||
String EXTRA_NOTIFICATION_BODY = "notification_body";
|
String EXTRA_NOTIFICATION_BODY = "notification_body";
|
||||||
String EXTRA_NOTIFICATION_FLAGS = "notification_flags";
|
String EXTRA_NOTIFICATION_FLAGS = "notification_flags";
|
||||||
@ -58,7 +59,7 @@ public interface DeviceService extends EventHandler {
|
|||||||
String EXTRA_URI = "uri";
|
String EXTRA_URI = "uri";
|
||||||
String EXTRA_ALARMS = "alarms";
|
String EXTRA_ALARMS = "alarms";
|
||||||
String EXTRA_PERFORM_PAIR = "perform_pair";
|
String EXTRA_PERFORM_PAIR = "perform_pair";
|
||||||
String EXTRA_ENABLE_REALTIME_STEPS = "enable_realtime_steps";
|
String EXTRA_BOOLEAN_ENABLE = "enable_realtime_steps";
|
||||||
String EXTRA_REALTIME_STEPS = "realtime_steps";
|
String EXTRA_REALTIME_STEPS = "realtime_steps";
|
||||||
String EXTRA_TIMESTAMP = "timestamp";
|
String EXTRA_TIMESTAMP = "timestamp";
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_CA
|
|||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_CONNECT;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_CONNECT;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_DELETEAPP;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_DELETEAPP;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_DISCONNECT;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_DISCONNECT;
|
||||||
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_ENABLE_HEARTRATE_SLEEP_SUPPORT;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_ENABLE_REALTIME_STEPS;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_ENABLE_REALTIME_STEPS;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_FETCH_ACTIVITY_DATA;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_FETCH_ACTIVITY_DATA;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_FIND_DEVICE;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_FIND_DEVICE;
|
||||||
@ -66,7 +67,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_APP
|
|||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_CALL_COMMAND;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_CALL_COMMAND;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_CALL_PHONENUMBER;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_CALL_PHONENUMBER;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_DEVICE_ADDRESS;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_DEVICE_ADDRESS;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_ENABLE_REALTIME_STEPS;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_BOOLEAN_ENABLE;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_FIND_START;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_FIND_START;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_MUSIC_ALBUM;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_MUSIC_ALBUM;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_MUSIC_ARTIST;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_MUSIC_ARTIST;
|
||||||
@ -331,10 +332,16 @@ public class DeviceCommunicationService extends Service {
|
|||||||
ArrayList<Alarm> alarms = intent.getParcelableArrayListExtra(EXTRA_ALARMS);
|
ArrayList<Alarm> alarms = intent.getParcelableArrayListExtra(EXTRA_ALARMS);
|
||||||
mDeviceSupport.onSetAlarms(alarms);
|
mDeviceSupport.onSetAlarms(alarms);
|
||||||
break;
|
break;
|
||||||
case ACTION_ENABLE_REALTIME_STEPS:
|
case ACTION_ENABLE_REALTIME_STEPS: {
|
||||||
boolean enable = intent.getBooleanExtra(EXTRA_ENABLE_REALTIME_STEPS, false);
|
boolean enable = intent.getBooleanExtra(EXTRA_BOOLEAN_ENABLE, false);
|
||||||
mDeviceSupport.onEnableRealtimeSteps(enable);
|
mDeviceSupport.onEnableRealtimeSteps(enable);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
case ACTION_ENABLE_HEARTRATE_SLEEP_SUPPORT: {
|
||||||
|
boolean enable = intent.getBooleanExtra(EXTRA_BOOLEAN_ENABLE, false);
|
||||||
|
mDeviceSupport.onEnableHeartRateSleepSupport(enable);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return START_STICKY;
|
return START_STICKY;
|
||||||
|
@ -241,4 +241,12 @@ public class ServiceDeviceSupport implements DeviceSupport {
|
|||||||
}
|
}
|
||||||
delegate.onEnableRealtimeSteps(enable);
|
delegate.onEnableRealtimeSteps(enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnableHeartRateSleepSupport(boolean enable) {
|
||||||
|
if (checkBusy("enable heartrate sleep support: " + enable)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
delegate.onEnableHeartRateSleepSupport(enable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.GattCharacteristic;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.GattService;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.GattService;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.AbortTransactionAction;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.AbortTransactionAction;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.ConditionalWriteAction;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.WriteAction;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.WriteAction;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations.FetchActivityOperation;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations.FetchActivityOperation;
|
||||||
@ -369,31 +370,40 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnableHeartRateSleepSupport(boolean enable) {
|
||||||
|
try {
|
||||||
|
TransactionBuilder builder = performInitialized("enable heart rate sleep support: " + enable);
|
||||||
|
setHeartrateSleepSupport(builder);
|
||||||
|
builder.queue(getQueue());
|
||||||
|
} catch (IOException e) {
|
||||||
|
GB.toast(getContext(), "Error toggling heart rate sleep support: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Part of device initialization process. Do not call manually.
|
* Part of device initialization process. Do not call manually.
|
||||||
*
|
* @param builder
|
||||||
* @param transaction
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
private MiBandSupport setHeartrateSleepSupport(TransactionBuilder transaction) {
|
private MiBandSupport setHeartrateSleepSupport(TransactionBuilder builder) {
|
||||||
if (supportsHeartRate()) {
|
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT);
|
||||||
LOG.info("Attempting to set heartrate sleep support...");
|
if (characteristic != null) {
|
||||||
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT);
|
builder.add(new ConditionalWriteAction(characteristic) {
|
||||||
if (characteristic != null) {
|
@Override
|
||||||
if(MiBandCoordinator.getHeartrateSleepSupport(getDevice().getAddress())) {
|
protected byte[] checkCondition() {
|
||||||
LOG.info("Enabling heartrate sleep support...");
|
if (!supportsHeartRate()) {
|
||||||
transaction.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT), startHeartMeasurementSleep);
|
return null;
|
||||||
|
}
|
||||||
|
if (MiBandCoordinator.getHeartrateSleepSupport(getDevice().getAddress())) {
|
||||||
|
LOG.info("Enabling heartrate sleep support...");
|
||||||
|
return startHeartMeasurementSleep;
|
||||||
|
} else {
|
||||||
|
LOG.info("Disabling heartrate sleep support...");
|
||||||
|
return stopHeartMeasurementSleep;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,4 +178,10 @@ public abstract class AbstractSerialDeviceSupport extends AbstractDeviceSupport
|
|||||||
byte[] bytes = gbDeviceProtocol.encodeEnableRealtimeSteps(enable);
|
byte[] bytes = gbDeviceProtocol.encodeEnableRealtimeSteps(enable);
|
||||||
sendToDevice(bytes);
|
sendToDevice(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnableHeartRateSleepSupport(boolean enable) {
|
||||||
|
byte[] bytes = gbDeviceProtocol.encodeEnableHeartRateSleepSupport(enable);
|
||||||
|
sendToDevice(bytes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,8 @@ public abstract class GBDeviceProtocol {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte[] encodeEnableHeartRateSleepSupport(boolean enable) { return null; }
|
||||||
|
|
||||||
public GBDeviceEvent[] decodeResponse(byte[] responseData) {
|
public GBDeviceEvent[] decodeResponse(byte[] responseData) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -124,4 +124,9 @@ public class TestDeviceSupport extends AbstractDeviceSupport {
|
|||||||
public void onEnableRealtimeSteps(boolean enable) {
|
public void onEnableRealtimeSteps(boolean enable) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnableHeartRateSleepSupport(boolean enable) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user