Merge pull request #1592 from NeilHanlon/ble-fixes
Fix updating certain settings over BLE
This commit is contained in:
@@ -88,6 +88,6 @@
|
|||||||
#define BT_UUID_CHAR_BLE_SETTINGS_VALUE_35 BT_UUID_DECLARE_16(35)
|
#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_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_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
|
#endif
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include "uuid.h"
|
#include "uuid.h"
|
||||||
|
|
||||||
#include "OperatingModes.h"
|
#include "OperatingModes.h"
|
||||||
|
#include "OLED.hpp"
|
||||||
#include "USBPD.h"
|
#include "USBPD.h"
|
||||||
#include "ble_characteristics.h"
|
#include "ble_characteristics.h"
|
||||||
#include "ble_handlers.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) {
|
} else if (uuid_value < SettingsOptions::SettingsOptionsLength) {
|
||||||
setSettingValue((SettingsOptions)(uuid_value), new_value);
|
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;
|
return len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,15 +140,16 @@ void resetSettings() {
|
|||||||
|
|
||||||
void setSettingValue(const enum SettingsOptions option, const uint16_t newValue) {
|
void setSettingValue(const enum SettingsOptions option, const uint16_t newValue) {
|
||||||
const auto constants = settingsConstants[(int)option];
|
const auto constants = settingsConstants[(int)option];
|
||||||
systemSettings.settingsValues[(int)option] = newValue;
|
uint16_t constrainedValue = newValue;
|
||||||
// If less than min, constrain
|
if (constrainedValue < constants.min) {
|
||||||
if (systemSettings.settingsValues[(int)option] < constants.min) {
|
// If less than min, constrain
|
||||||
systemSettings.settingsValues[(int)option] = constants.min;
|
constrainedValue = constants.min;
|
||||||
}
|
}
|
||||||
// If hit max, constrain
|
else if (constrainedValue > constants.max) {
|
||||||
if (systemSettings.settingsValues[(int)option] > constants.max) {
|
// If hit max, constrain
|
||||||
systemSettings.settingsValues[(int)option] = constants.max;
|
constrainedValue = constants.max;
|
||||||
}
|
}
|
||||||
|
systemSettings.settingsValues[(int)option] = constrainedValue;
|
||||||
}
|
}
|
||||||
// Lookup wrapper for ease of use (with typing)
|
// Lookup wrapper for ease of use (with typing)
|
||||||
uint16_t getSettingValue(const enum SettingsOptions option) { return systemSettings.settingsValues[(int)option]; }
|
uint16_t getSettingValue(const enum SettingsOptions option) { return systemSettings.settingsValues[(int)option]; }
|
||||||
|
|||||||
Reference in New Issue
Block a user