Skip to content

Commit

Permalink
system: allow disabling of forced refresh after preset change
Browse files Browse the repository at this point in the history
  • Loading branch information
paradajz committed Feb 20, 2024
1 parent 2ae8ce8 commit 514cba3
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/firmware/application/system/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ limitations under the License.
#include <functional>
#include <optional>
#include "SysExConf/SysExConf.h"
#include "application/database/Config.h"

namespace sys
{
Expand Down Expand Up @@ -137,6 +138,11 @@ namespace sys
};
};

enum class systemSetting_t : uint8_t
{
ENABLE_FORCED_REFRESH_AFTER_PRESET_CHANGE = static_cast<uint8_t>(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,
Expand Down
3 changes: 2 additions & 1 deletion src/firmware/application/system/Layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ namespace sys

// preset section
{
static_cast<uint16_t>(database::Config::presetSetting_t::AMOUNT),
// all preset related settings are stored in system section in database
static_cast<uint16_t>(database::Config::systemSetting_t::AMOUNT),
0,
0,
},
Expand Down
74 changes: 69 additions & 5 deletions src/firmware/application/system/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<sys::Config::Section::global_t>(section), index, value);
},

// write
[this](uint8_t section, size_t index, uint16_t value)
{
return sysConfigSet(static_cast<sys::Config::Section::global_t>(section), index, value);
});
}

bool Instance::init()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -597,3 +619,45 @@ void Instance::DBhandlers::factoryResetDone()

MIDIDispatcher.notify(messaging::eventType_t::SYSTEM, event);
}

std::optional<uint8_t> 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<size_t>(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<uint8_t> 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<size_t>(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;
}
10 changes: 6 additions & 4 deletions src/firmware/application/system/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t> sysConfigGet(sys::Config::Section::global_t section, size_t index, uint16_t& value);
std::optional<uint8_t> sysConfigSet(sys::Config::Section::global_t section, size_t index, uint16_t value);

HWA& _hwa;
Components& _components;
Expand Down

0 comments on commit 514cba3

Please sign in to comment.