From 43a1613f95534c08c5af00b37fd0b75f2b71c259 Mon Sep 17 00:00:00 2001 From: Arjan Schrijver Date: Thu, 2 Jan 2025 22:43:34 +0100 Subject: [PATCH] Colmi R09: Add preference to toggle temperature measurements --- .../DeviceSettingsPreferenceConst.java | 1 + .../DeviceSpecificSettingsFragment.java | 1 + .../devices/colmi/AbstractColmiR0xCoordinator.java | 3 +++ .../devices/colmi/ColmiR0xConstants.java | 1 + .../devices/colmi/ColmiR0xPacketHandler.java | 11 +++++++++++ .../devices/colmi/ColmiR0xDeviceSupport.java | 14 ++++++++++++++ 6 files changed, 31 insertions(+) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java index 52985d75e..341d38cf2 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java @@ -206,6 +206,7 @@ public class DeviceSettingsPreferenceConst { public static final String PREF_SPO2_ALL_DAY_MONITORING = "spo2_all_day_monitoring_enabled"; public static final String PREF_SPO2_LOW_ALERT_THRESHOLD = "spo2_low_alert_threshold"; public static final String PREF_HRV_ALL_DAY_MONITORING = "hrv_all_day_monitoring_enabled"; + public static final String PREF_TEMPERATURE_ALL_DAY_MONITORING = "continuous_skin_temperature_measurement"; public static final String PREF_AUTOHEARTRATE_SWITCH = "pref_autoheartrate_switch"; public static final String PREF_AUTOHEARTRATE_SLEEP = "pref_autoheartrate_sleep"; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java index 69f807c38..33a50f426 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java @@ -554,6 +554,7 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i addPreferenceHandlerFor(PREF_SPO2_ALL_DAY_MONITORING); addPreferenceHandlerFor(PREF_SPO2_LOW_ALERT_THRESHOLD); addPreferenceHandlerFor(PREF_HRV_ALL_DAY_MONITORING); + addPreferenceHandlerFor(PREF_TEMPERATURE_ALL_DAY_MONITORING); addPreferenceHandlerFor(PREF_DO_NOT_DISTURB_NOAUTO); addPreferenceHandlerFor(PREF_DO_NOT_DISTURB_NOAUTO_START); addPreferenceHandlerFor(PREF_DO_NOT_DISTURB_NOAUTO_END); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/colmi/AbstractColmiR0xCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/colmi/AbstractColmiR0xCoordinator.java index dc5a5aa02..44f0038b2 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/colmi/AbstractColmiR0xCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/colmi/AbstractColmiR0xCoordinator.java @@ -235,6 +235,9 @@ public abstract class AbstractColmiR0xCoordinator extends AbstractBLEDeviceCoord final DeviceSpecificSettings deviceSpecificSettings = new DeviceSpecificSettings(); final List health = deviceSpecificSettings.addRootScreen(DeviceSpecificSettingsScreen.HEALTH); health.add(R.xml.devicesettings_colmi_r0x); + if (supportsContinuousTemperature()) { + health.add(R.xml.devicesettings_temperature_automatic_enable); + } return deviceSpecificSettings; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/colmi/ColmiR0xConstants.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/colmi/ColmiR0xConstants.java index 8db709715..c5e465b94 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/colmi/ColmiR0xConstants.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/colmi/ColmiR0xConstants.java @@ -40,6 +40,7 @@ public class ColmiR0xConstants { public static final byte CMD_SYNC_STRESS = 0x37; public static final byte CMD_AUTO_HRV_PREF = 0x38; public static final byte CMD_SYNC_HRV = 0x39; + public static final byte CMD_AUTO_TEMP_PREF = 0x3a; public static final byte CMD_SYNC_ACTIVITY = 0x43; public static final byte CMD_FIND_DEVICE = 0x50; public static final byte CMD_MANUAL_HEART_RATE = 0x69; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/colmi/ColmiR0xPacketHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/colmi/ColmiR0xPacketHandler.java index 33d753e56..469fabd42 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/colmi/ColmiR0xPacketHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/colmi/ColmiR0xPacketHandler.java @@ -111,6 +111,17 @@ public class ColmiR0xPacketHandler { support.evaluateGBDeviceEvent(eventUpdatePreferences); } + public static void tempSettings(ColmiR0xDeviceSupport support, byte[] value) { + boolean enabled = value[3] == 0x01; + LOG.info("Received temperature preference: {}", enabled ? "enabled" : "disabled"); + GBDeviceEventUpdatePreferences eventUpdatePreferences = new GBDeviceEventUpdatePreferences(); + eventUpdatePreferences.withPreference( + DeviceSettingsPreferenceConst.PREF_TEMPERATURE_ALL_DAY_MONITORING, + enabled + ); + support.evaluateGBDeviceEvent(eventUpdatePreferences); + } + public static void goalsSettings(byte[] value) { int steps = BLETypeConversions.toUint32(value[2], value[3], value[4], (byte) 0); int calories = BLETypeConversions.toUint32(value[5], value[6], value[7], (byte) 0); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/colmi/ColmiR0xDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/colmi/ColmiR0xDeviceSupport.java index 00a479172..572d79620 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/colmi/ColmiR0xDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/colmi/ColmiR0xDeviceSupport.java @@ -270,6 +270,11 @@ public class ColmiR0xDeviceSupport extends AbstractBTLEDeviceSupport { case ColmiR0xConstants.CMD_AUTO_HRV_PREF: ColmiR0xPacketHandler.hrvSettings(this, value); break; + case ColmiR0xConstants.CMD_AUTO_TEMP_PREF: + if (value[1] == 0x03) { // so far always observed to be 0x03 + ColmiR0xPacketHandler.tempSettings(this, value); + } + break; case ColmiR0xConstants.CMD_SYNC_STRESS: ColmiR0xPacketHandler.historicalStress(getDevice(), getContext(), value); if (!getDevice().isBusy()) { @@ -511,6 +516,12 @@ public class ColmiR0xDeviceSupport extends AbstractBTLEDeviceSupport { LOG.info("HRV preference request sent: {}", StringUtils.bytesToHex(hrvPrefsPacket)); sendWrite("hrvPreferenceRequest", hrvPrefsPacket); break; + case DeviceSettingsPreferenceConst.PREF_TEMPERATURE_ALL_DAY_MONITORING: + final boolean tempEnabled = prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_TEMPERATURE_ALL_DAY_MONITORING, false); + byte[] tempPrefsPacket = buildPacket(new byte[]{ColmiR0xConstants.CMD_AUTO_TEMP_PREF, 0x03, ColmiR0xConstants.PREF_WRITE, (byte) (tempEnabled ? 0x01 : 0x00)}); + LOG.info("Temperature preference request sent: {}", StringUtils.bytesToHex(tempPrefsPacket)); + sendWrite("tempPreferenceRequest", tempPrefsPacket); + break; } } @@ -574,6 +585,9 @@ public class ColmiR0xDeviceSupport extends AbstractBTLEDeviceSupport { request = buildPacket(new byte[]{ColmiR0xConstants.CMD_AUTO_HRV_PREF, ColmiR0xConstants.PREF_READ}); LOG.info("Request HRV measurement setting from ring: {}", StringUtils.bytesToHex(request)); sendWrite("hrvSettingRequest", request); + request = buildPacket(new byte[]{ColmiR0xConstants.CMD_AUTO_TEMP_PREF, 0x03, ColmiR0xConstants.PREF_READ}); + LOG.info("Request temperature measurement setting from ring: {}", StringUtils.bytesToHex(request)); + sendWrite("tempSettingRequest", request); request = buildPacket(new byte[]{ColmiR0xConstants.CMD_GOALS, ColmiR0xConstants.PREF_READ}); LOG.info("Request goals from ring: {}", StringUtils.bytesToHex(request)); sendWrite("goalsSettingRequest", request);