diff --git a/src/firmware/application/system/Config.h b/src/firmware/application/system/Config.h index ccb8ba925..5a597aa69 100644 --- a/src/firmware/application/system/Config.h +++ b/src/firmware/application/system/Config.h @@ -23,6 +23,7 @@ limitations under the License. #include #include #include "SysExConf/SysExConf.h" +#include "application/database/Config.h" namespace sys { @@ -137,6 +138,11 @@ namespace sys }; }; + enum class systemSetting_t : uint8_t + { + ENABLE_FORCED_REFRESH_AFTER_PRESET_CHANGE = static_cast(database::Config::systemSetting_t::CUSTOM_SYSTEM_SETTING_START), + }; + struct status_t { // Since get/set config messages return uint8_t to allow for custom, user statuses, diff --git a/src/firmware/application/system/Layout.h b/src/firmware/application/system/Layout.h index 2a96e3755..acc595b0f 100644 --- a/src/firmware/application/system/Layout.h +++ b/src/firmware/application/system/Layout.h @@ -50,7 +50,8 @@ namespace sys // preset section { - static_cast(database::Config::presetSetting_t::AMOUNT), + // all preset related settings are stored in system section in database + static_cast(database::Config::systemSetting_t::AMOUNT), 0, 0, }, diff --git a/src/firmware/application/system/System.cpp b/src/firmware/application/system/System.cpp index 56df67100..cb09e9f1f 100644 --- a/src/firmware/application/system/System.cpp +++ b/src/firmware/application/system/System.cpp @@ -94,6 +94,20 @@ Instance::Instance(HWA& hwa, break; } }); + + ConfigHandler.registerConfig( + sys::Config::block_t::GLOBAL, + // read + [this](uint8_t section, size_t index, uint16_t& value) + { + return sysConfigGet(static_cast(section), index, value); + }, + + // write + [this](uint8_t section, size_t index, uint16_t value) + { + return sysConfigSet(static_cast(section), index, value); + }); } bool Instance::init() @@ -368,15 +382,23 @@ void Instance::checkProtocols() void Instance::forceComponentRefresh() { + if (!_components.database().read(database::Config::Section::system_t::SYSTEM_SETTINGS, + Config::systemSetting_t::ENABLE_FORCED_REFRESH_AFTER_PRESET_CHANGE)) + { + return; + } + // extra check here - it's possible that preset was changed and then backup/restore procedure started // in that case this would get called - if (_backupRestoreState == backupRestoreState_t::NONE) + if (_backupRestoreState != backupRestoreState_t::NONE) { - messaging::event_t event; - event.systemMessage = messaging::systemMessage_t::FORCE_IO_REFRESH; - - MIDIDispatcher.notify(messaging::eventType_t::SYSTEM, event); + return; } + + messaging::event_t event; + event.systemMessage = messaging::systemMessage_t::FORCE_IO_REFRESH; + + MIDIDispatcher.notify(messaging::eventType_t::SYSTEM, event); } void Instance::SysExDataHandler::sendResponse(uint8_t* array, uint16_t size) @@ -597,3 +619,45 @@ void Instance::DBhandlers::factoryResetDone() MIDIDispatcher.notify(messaging::eventType_t::SYSTEM, event); } + +std::optional Instance::sysConfigGet(sys::Config::Section::global_t section, size_t index, uint16_t& value) +{ + if (section != sys::Config::Section::global_t::PRESETS) + { + return std::nullopt; + } + + if (index != static_cast(sys::Config::systemSetting_t::ENABLE_FORCED_REFRESH_AFTER_PRESET_CHANGE)) + { + return std::nullopt; + } + + uint32_t readValue; + + auto result = _components.database().read(database::Config::Section::system_t::SYSTEM_SETTINGS, index, readValue) + ? sys::Config::status_t::ACK + : sys::Config::status_t::ERROR_READ; + + value = readValue; + + return result; +} + +std::optional Instance::sysConfigSet(sys::Config::Section::global_t section, size_t index, uint16_t value) +{ + if (section != sys::Config::Section::global_t::PRESETS) + { + return std::nullopt; + } + + if (index != static_cast(sys::Config::systemSetting_t::ENABLE_FORCED_REFRESH_AFTER_PRESET_CHANGE)) + { + return std::nullopt; + } + + auto result = _components.database().update(database::Config::Section::system_t::SYSTEM_SETTINGS, index, value) + ? sys::Config::status_t::ACK + : sys::Config::status_t::ERROR_WRITE; + + return result; +} \ No newline at end of file diff --git a/src/firmware/application/system/System.h b/src/firmware/application/system/System.h index 9ad46811f..f1bdbd16c 100644 --- a/src/firmware/application/system/System.h +++ b/src/firmware/application/system/System.h @@ -122,10 +122,12 @@ namespace sys SCHEDULED_TASK_FORCED_REFRESH, }; - io::ioComponent_t checkComponents(); - void checkProtocols(); - void backup(); - void forceComponentRefresh(); + io::ioComponent_t checkComponents(); + void checkProtocols(); + void backup(); + void forceComponentRefresh(); + std::optional sysConfigGet(sys::Config::Section::global_t section, size_t index, uint16_t& value); + std::optional sysConfigSet(sys::Config::Section::global_t section, size_t index, uint16_t value); HWA& _hwa; Components& _components;