mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-26 20:06:52 +01:00
Add wear sensor toggle to Bowers and Wilkins P Series
This commit is contained in:
parent
82f221752e
commit
31b8fd683d
@ -107,6 +107,7 @@ public class DeviceSettingsPreferenceConst {
|
|||||||
public static final String PREF_DEVICE_INTENTS = "device_intents";
|
public static final String PREF_DEVICE_INTENTS = "device_intents";
|
||||||
|
|
||||||
public static final String PREF_ACTIVE_NOISE_CANCELLING_TOGGLE = "active_noise_cancelling_toggle";
|
public static final String PREF_ACTIVE_NOISE_CANCELLING_TOGGLE = "active_noise_cancelling_toggle";
|
||||||
|
public static final String PREF_WEAR_SENSOR_TOGGLE = "wear_sensor_toggle";
|
||||||
public static final String PREF_BANDW_PSERIES_VPT_ENABLED = "bandw_pseries_vpt_enabled";
|
public static final String PREF_BANDW_PSERIES_VPT_ENABLED = "bandw_pseries_vpt_enabled";
|
||||||
public static final String PREF_BANDW_PSERIES_VPT_LEVEL = "bandw_pseries_vpt_level";
|
public static final String PREF_BANDW_PSERIES_VPT_LEVEL = "bandw_pseries_vpt_level";
|
||||||
public static final String PREF_BANDW_PSERIES_GUI_VPT_LEVEL = "bandw_pseries_gui_vpt_level";
|
public static final String PREF_BANDW_PSERIES_GUI_VPT_LEVEL = "bandw_pseries_gui_vpt_level";
|
||||||
|
@ -612,6 +612,7 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
|
|||||||
addPreferenceHandlerFor(PREF_SLEEP_MODE_SMART_ENABLE);
|
addPreferenceHandlerFor(PREF_SLEEP_MODE_SMART_ENABLE);
|
||||||
|
|
||||||
addPreferenceHandlerFor(PREF_ACTIVE_NOISE_CANCELLING_TOGGLE);
|
addPreferenceHandlerFor(PREF_ACTIVE_NOISE_CANCELLING_TOGGLE);
|
||||||
|
addPreferenceHandlerFor(PREF_WEAR_SENSOR_TOGGLE);
|
||||||
addPreferenceHandlerFor(PREF_BANDW_PSERIES_GUI_VPT_LEVEL);
|
addPreferenceHandlerFor(PREF_BANDW_PSERIES_GUI_VPT_LEVEL);
|
||||||
|
|
||||||
addPreferenceHandlerFor(PREF_HYBRID_HR_DRAW_WIDGET_CIRCLES);
|
addPreferenceHandlerFor(PREF_HYBRID_HR_DRAW_WIDGET_CIRCLES);
|
||||||
|
@ -55,7 +55,8 @@ public class BandWPSeriesDeviceCoordinator extends AbstractBLEDeviceCoordinator
|
|||||||
public int[] getSupportedDeviceSpecificSettings(GBDevice device) {
|
public int[] getSupportedDeviceSpecificSettings(GBDevice device) {
|
||||||
return new int[] {
|
return new int[] {
|
||||||
R.xml.devicesettings_active_noise_cancelling_toggle,
|
R.xml.devicesettings_active_noise_cancelling_toggle,
|
||||||
R.xml.devicesettings_bandw_pseries
|
R.xml.devicesettings_bandw_pseries,
|
||||||
|
R.xml.devicesettings_wear_sensor_toggle
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +50,10 @@ public class BandWBLEProfile<T extends AbstractBTLEDeviceSupport> extends Abstra
|
|||||||
sendRequest(builder, (byte) 0x03, (byte) 0x03);
|
sendRequest(builder, (byte) 0x03, (byte) 0x03);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void requestWearSensorEnabled(final TransactionBuilder builder) {
|
||||||
|
sendRequest(builder, (byte) 0x0a, (byte) 0x01);
|
||||||
|
}
|
||||||
|
|
||||||
public void setAncModeState(final TransactionBuilder builder, final boolean mode) throws IOException {
|
public void setAncModeState(final TransactionBuilder builder, final boolean mode) throws IOException {
|
||||||
BandWPSeriesRequest req = new BandWPSeriesRequest((byte) 0x03, (byte) 0x02).addToPayload(mode ? ANC_MODE_ON : ANC_MODE_OFF);
|
BandWPSeriesRequest req = new BandWPSeriesRequest((byte) 0x03, (byte) 0x02).addToPayload(mode ? ANC_MODE_ON : ANC_MODE_OFF);
|
||||||
builder.write(getCharacteristic(UUID_RPC_REQUEST_CHARACTERISTIC), req.finishAndGetBytes());
|
builder.write(getCharacteristic(UUID_RPC_REQUEST_CHARACTERISTIC), req.finishAndGetBytes());
|
||||||
@ -65,6 +69,11 @@ public class BandWBLEProfile<T extends AbstractBTLEDeviceSupport> extends Abstra
|
|||||||
builder.write(getCharacteristic(UUID_RPC_REQUEST_CHARACTERISTIC), req.finishAndGetBytes());
|
builder.write(getCharacteristic(UUID_RPC_REQUEST_CHARACTERISTIC), req.finishAndGetBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setWearSensorEnabled(final TransactionBuilder builder, final boolean mode) throws IOException {
|
||||||
|
BandWPSeriesRequest req = new BandWPSeriesRequest((byte) 0x0a, (byte) 0x02).addToPayload(mode);
|
||||||
|
builder.write(getCharacteristic(UUID_RPC_REQUEST_CHARACTERISTIC), req.finishAndGetBytes());
|
||||||
|
}
|
||||||
|
|
||||||
private void sendRequest(final TransactionBuilder builder, byte namespace, byte commandID) {
|
private void sendRequest(final TransactionBuilder builder, byte namespace, byte commandID) {
|
||||||
BandWPSeriesRequest req;
|
BandWPSeriesRequest req;
|
||||||
try {
|
try {
|
||||||
|
@ -4,6 +4,7 @@ import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.Dev
|
|||||||
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BANDW_PSERIES_GUI_VPT_LEVEL;
|
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BANDW_PSERIES_GUI_VPT_LEVEL;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BANDW_PSERIES_VPT_ENABLED;
|
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BANDW_PSERIES_VPT_ENABLED;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BANDW_PSERIES_VPT_LEVEL;
|
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BANDW_PSERIES_VPT_LEVEL;
|
||||||
|
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_WEAR_SENSOR_TOGGLE;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.impl.GBDevice.BATTERY_UNKNOWN;
|
import static nodomain.freeyourgadget.gadgetbridge.impl.GBDevice.BATTERY_UNKNOWN;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.service.devices.bandwpseries.BandWBLEProfile.ANC_MODE_ON;
|
import static nodomain.freeyourgadget.gadgetbridge.service.devices.bandwpseries.BandWBLEProfile.ANC_MODE_ON;
|
||||||
|
|
||||||
@ -78,6 +79,7 @@ public class BandWPSeriesDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
BandWBLEProfile.requestAncModeState(builder);
|
BandWBLEProfile.requestAncModeState(builder);
|
||||||
BandWBLEProfile.requestVptEnabled(builder);
|
BandWBLEProfile.requestVptEnabled(builder);
|
||||||
BandWBLEProfile.requestVptLevel(builder);
|
BandWBLEProfile.requestVptLevel(builder);
|
||||||
|
BandWBLEProfile.requestWearSensorEnabled(builder);
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,6 +131,12 @@ public class BandWPSeriesDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
if (response.commandId == 0x17) {
|
if (response.commandId == 0x17) {
|
||||||
return handleBatteryLevels(response);
|
return handleBatteryLevels(response);
|
||||||
}
|
}
|
||||||
|
} else if (response.namespace == 0x0a) {
|
||||||
|
if (response.commandId == 0x01) {
|
||||||
|
return handleGetWearSensorEnabledResponse(response);
|
||||||
|
} else if (response.commandId == 0x02) {
|
||||||
|
return getBooleanResponseStatus(response);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -168,6 +176,24 @@ public class BandWPSeriesDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean handleGetWearSensorEnabledResponse(BandWPSeriesResponse response) {
|
||||||
|
if (!response.messageType.hasPayload) {
|
||||||
|
GB.toast("No payload in response!", Toast.LENGTH_SHORT, GB.ERROR);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
boolean wearSensorEnabled;
|
||||||
|
try {
|
||||||
|
wearSensorEnabled = response.getPayloadBoolean();
|
||||||
|
} catch (IOException e) {
|
||||||
|
GB.toast("Failed to unpack wear sensor status from payload " + Arrays.toString(response.payload), Toast.LENGTH_SHORT, GB.ERROR);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Editor editor = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).edit();
|
||||||
|
editor.putBoolean(PREF_WEAR_SENSOR_TOGGLE, wearSensorEnabled);
|
||||||
|
editor.apply();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean handleFirmwareVersionResponse(BandWPSeriesResponse response) {
|
private boolean handleFirmwareVersionResponse(BandWPSeriesResponse response) {
|
||||||
String firmwareString = response.getPayloadString();
|
String firmwareString = response.getPayloadString();
|
||||||
if (firmwareString == null) {
|
if (firmwareString == null) {
|
||||||
@ -249,6 +275,10 @@ public class BandWPSeriesDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
BandWBLEProfile.setVptLevel(builder, level - 1);
|
BandWBLEProfile.setVptLevel(builder, level - 1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case PREF_WEAR_SENSOR_TOGGLE:
|
||||||
|
boolean wearSensorEnabled = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getBoolean(PREF_WEAR_SENSOR_TOGGLE, true);
|
||||||
|
BandWBLEProfile.setWearSensorEnabled(builder, wearSensorEnabled);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
performImmediately(builder);
|
performImmediately(builder);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -77,4 +77,8 @@ public class BandWPSeriesResponse {
|
|||||||
}
|
}
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getPayloadBoolean() throws IOException{
|
||||||
|
return payloadUnpacker.unpackBoolean();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2581,6 +2581,8 @@
|
|||||||
<string name="pref_header_stress">Stress</string>
|
<string name="pref_header_stress">Stress</string>
|
||||||
<string name="pref_header_spo2">Blood Oxygen</string>
|
<string name="pref_header_spo2">Blood Oxygen</string>
|
||||||
<string name="pref_header_hrv_status">HRV Status</string>
|
<string name="pref_header_hrv_status">HRV Status</string>
|
||||||
|
<string name="pref_wear_sensor_summary">Detect when the device is not being worn</string>
|
||||||
|
<string name="pref_wear_sensor_title">Wear Sensor</string>
|
||||||
<string name="body_energy">Body Energy</string>
|
<string name="body_energy">Body Energy</string>
|
||||||
<string name="vo2max_running">Running VO₂ Max</string>
|
<string name="vo2max_running">Running VO₂ Max</string>
|
||||||
<string name="vo2max_cycling">Cycling VO₂ Max</string>
|
<string name="vo2max_cycling">Cycling VO₂ Max</string>
|
||||||
|
10
app/src/main/res/xml/devicesettings_wear_sensor_toggle.xml
Normal file
10
app/src/main/res/xml/devicesettings_wear_sensor_toggle.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<SwitchPreferenceCompat
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:icon="@drawable/ic_hearing"
|
||||||
|
android:key="wear_sensor_toggle"
|
||||||
|
android:layout="@layout/preference_checkbox"
|
||||||
|
android:summary="@string/pref_wear_sensor_summary"
|
||||||
|
android:title="@string/pref_wear_sensor_title" />
|
||||||
|
</androidx.preference.PreferenceScreen>
|
Loading…
Reference in New Issue
Block a user