From b1658ec6eed20e08f0c7485bcb48b102434ae804 Mon Sep 17 00:00:00 2001 From: Neil Hanlon Date: Wed, 22 Feb 2023 01:25:49 -0500 Subject: [PATCH 1/3] Handle updating certain settings updates over BLE - Fixes #1560 --- source/Core/BSP/Pinecilv2/ble_handlers.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/source/Core/BSP/Pinecilv2/ble_handlers.cpp b/source/Core/BSP/Pinecilv2/ble_handlers.cpp index bc89da98..ad2c3fe8 100644 --- a/source/Core/BSP/Pinecilv2/ble_handlers.cpp +++ b/source/Core/BSP/Pinecilv2/ble_handlers.cpp @@ -21,6 +21,7 @@ #include "uuid.h" #include "OperatingModes.h" +#include "OLED.hpp" #include "USBPD.h" #include "ble_characteristics.h" #include "ble_handlers.h" @@ -242,6 +243,16 @@ int ble_char_write_setting_value_callback(struct bt_conn *conn, const struct bt_ } } else if (uuid_value < SettingsOptions::SettingsOptionsLength) { setSettingValue((SettingsOptions)(uuid_value), new_value); + // @TODO refactor to make this more usable + if (uuid_value == SettingsOptions::OLEDInversion) { + OLED::setInverseDisplay(getSettingValue(SettingsOptions::OLEDInversion)); + } + if (uuid_value == SettingsOptions::OLEDBrightness){ + OLED::setBrightness(getSettingValue(SettingsOptions::OLEDBrightness)); + } + if (uuid_value == SettingsOptions::OrientationMode){ + OLED::setRotation(getSettingValue(SettingsOptions::OrientationMode) & 1); + } return len; } } From a76049acde0d1432643d9f3736d227cd7c7a4cf1 Mon Sep 17 00:00:00 2001 From: Neil Hanlon Date: Wed, 22 Feb 2023 01:26:06 -0500 Subject: [PATCH 2/3] Fix bug in setSettingsValue for values constrained between 0 and 1 Fixed a bug in the `setSettingValue` function that caused valid values within the allowed range to be incorrectly constrained to the minimum value, when the default value of the option was zero and the allowed range was from zero to one. The bug was fixed by updating the order of the `if` statements in the function to ensure that the range check is done before the value is set. This ensures that valid values within the range are correctly retained, while out-of-range values are still constrained to the allowed range. --- source/Core/Src/Settings.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/source/Core/Src/Settings.cpp b/source/Core/Src/Settings.cpp index 9d393d23..542a60fb 100644 --- a/source/Core/Src/Settings.cpp +++ b/source/Core/Src/Settings.cpp @@ -140,15 +140,16 @@ void resetSettings() { void setSettingValue(const enum SettingsOptions option, const uint16_t newValue) { const auto constants = settingsConstants[(int)option]; - systemSettings.settingsValues[(int)option] = newValue; - // If less than min, constrain - if (systemSettings.settingsValues[(int)option] < constants.min) { - systemSettings.settingsValues[(int)option] = constants.min; + uint16_t constrainedValue = newValue; + if (constrainedValue < constants.min) { + // If less than min, constrain + constrainedValue = constants.min; } - // If hit max, constrain - if (systemSettings.settingsValues[(int)option] > constants.max) { - systemSettings.settingsValues[(int)option] = constants.max; + else if (constrainedValue > constants.max) { + // If hit max, constrain + constrainedValue = constants.max; } + systemSettings.settingsValues[(int)option] = constrainedValue; } // Lookup wrapper for ease of use (with typing) uint16_t getSettingValue(const enum SettingsOptions option) { return systemSettings.settingsValues[(int)option]; } From 2a244df7b10a7f6ff0a2ae1ec40e3983eea27b7a Mon Sep 17 00:00:00 2001 From: Neil Hanlon Date: Wed, 22 Feb 2023 01:28:04 -0500 Subject: [PATCH 3/3] Fix typo in BLE settings mapping --- source/Core/BSP/Pinecilv2/ble_characteristics.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Core/BSP/Pinecilv2/ble_characteristics.h b/source/Core/BSP/Pinecilv2/ble_characteristics.h index a782e6c8..abba04c0 100644 --- a/source/Core/BSP/Pinecilv2/ble_characteristics.h +++ b/source/Core/BSP/Pinecilv2/ble_characteristics.h @@ -88,6 +88,6 @@ #define BT_UUID_CHAR_BLE_SETTINGS_VALUE_35 BT_UUID_DECLARE_16(35) #define BT_UUID_CHAR_BLE_SETTINGS_VALUE_36 BT_UUID_DECLARE_16(36) #define BT_UUID_CHAR_BLE_SETTINGS_VALUE_37 BT_UUID_DECLARE_16(37) -#define BT_UUID_CHAR_BLE_SETTINGS_VALUE_38 BT_UUID_DECLARE_16(37) +#define BT_UUID_CHAR_BLE_SETTINGS_VALUE_38 BT_UUID_DECLARE_16(38) #endif