AwesomeStudioPedal
A programmable, multi-profile foot controller for DAWs, score readers, and studio automation
Loading...
Searching...
No Matches
ConfigLoader Class Reference

Loads pedal configuration from JSON files. More...

#include <config_loader.h>

Public Member Functions

 ConfigLoader ()
 Default constructor: uses production singletons (firmware path)
 
 ConfigLoader (IFileSystem *fs, ILogger *logger)
 Injection constructor: use in tests or wherever DI is needed.
 
bool loadFromFile (ProfileManager &profileManager, IBleKeyboard *keyboard, const std::string &configPath)
 Loads configuration from a file.
 
bool loadFromString (ProfileManager &profileManager, IBleKeyboard *keyboard, const std::string &jsonConfig)
 Loads configuration from a JSON string.
 
bool saveToFile (const ProfileManager &profileManager, const std::string &configPath)
 Saves configuration to a file.
 
bool mergeConfig (ProfileManager &profileManager, IBleKeyboard *keyboard, const std::string &jsonConfig)
 Merges configuration from JSON into existing profiles.
 
bool replaceProfile (ProfileManager &profileManager, IBleKeyboard *keyboard, uint8_t profileIndex, const std::string &jsonConfig)
 Replaces a specific profile with configuration from JSON.
 

Static Public Member Functions

static const char * getDefaultConfig ()
 
static uint8_t getButtonIndex (const char *buttonName)
 Converts button name to button index.
 

Detailed Description

Loads pedal configuration from JSON files.

Responsible for parsing JSON configuration files and creating the appropriate Action objects to populate the ProfileManager.

Definition at line 18 of file config_loader.h.

Constructor & Destructor Documentation

◆ ConfigLoader() [1/2]

ConfigLoader::ConfigLoader ( )

Default constructor: uses production singletons (firmware path)

Default constructor.

Creates a ConfigLoader using production singletons for file system and logging. Used in firmware builds.

Definition at line 60 of file config_loader.cpp.

◆ ConfigLoader() [2/2]

ConfigLoader::ConfigLoader ( IFileSystem fs,
ILogger logger 
)

Injection constructor: use in tests or wherever DI is needed.

Dependency injection constructor.

Creates a ConfigLoader with injected dependencies for testing or custom implementations.

Parameters
fsFile system implementation
loggerLogger implementation

Definition at line 70 of file config_loader.cpp.

Member Function Documentation

◆ getButtonIndex()

uint8_t ConfigLoader::getButtonIndex ( const char *  buttonName)
static

Converts button name to button index.

Parameters
buttonNameThe button name ("A", "B", "C", or "D")
Returns
The corresponding Btn:: index, or 255 if not found

Definition at line 152 of file config_loader.cpp.

◆ getDefaultConfig()

static const char * ConfigLoader::getDefaultConfig ( )
inlinestatic

Definition at line 42 of file config_loader.h.

◆ loadFromFile()

bool ConfigLoader::loadFromFile ( ProfileManager profileManager,
IBleKeyboard keyboard,
const std::string &  configPath 
)

Loads configuration from a file.

Reads the configuration file from the specified path and parses it using loadFromString().

Parameters
profileManagerThe profile manager to populate with loaded profiles
keyboardThe BLE keyboard interface for creating keyboard actions
configPathPath to the configuration file
Returns
true if loading succeeded, false if file read failed

Definition at line 84 of file config_loader.cpp.

◆ loadFromString()

bool ConfigLoader::loadFromString ( ProfileManager profileManager,
IBleKeyboard keyboard,
const std::string &  jsonConfig 
)

Loads configuration from a JSON string.

Parses the JSON configuration and populates the profile manager with the defined profiles. Clears existing profiles before loading new ones.

Parameters
profileManagerThe profile manager to populate
keyboardThe BLE keyboard interface for creating keyboard actions
jsonConfigJSON string containing the configuration
Returns
true if parsing and loading succeeded, false if JSON parsing failed

Definition at line 108 of file config_loader.cpp.

◆ mergeConfig()

bool ConfigLoader::mergeConfig ( ProfileManager profileManager,
IBleKeyboard keyboard,
const std::string &  jsonConfig 
)

Merges configuration from JSON into existing profiles.

Adds new profiles from the JSON configuration to the profile manager, skipping any profiles that already exist by name. Only adds profiles to empty slots in the profile manager.

Parameters
profileManagerThe profile manager to merge profiles into
keyboardThe BLE keyboard interface for creating keyboard actions
jsonConfigJSON string containing profiles to merge
Returns
true if merging succeeded, false if JSON parsing failed

Definition at line 49 of file config_loader_merge.cpp.

◆ replaceProfile()

bool ConfigLoader::replaceProfile ( ProfileManager profileManager,
IBleKeyboard keyboard,
uint8_t  profileIndex,
const std::string &  jsonConfig 
)

Replaces a specific profile with configuration from JSON.

Parses the JSON configuration and replaces the profile at the specified index with the first profile found in the JSON. Validates the profile index before attempting replacement.

Parameters
profileManagerThe profile manager containing the profile to replace
keyboardThe BLE keyboard interface for creating keyboard actions
profileIndexIndex of the profile to replace (0-3)
jsonConfigJSON string containing the replacement profile
Returns
true if replacement succeeded, false if validation failed or JSON parsing failed

Definition at line 108 of file config_loader_merge.cpp.

◆ saveToFile()

bool ConfigLoader::saveToFile ( const ProfileManager profileManager,
const std::string &  configPath 
)

Saves configuration to a file.

Serializes the current profile manager state to JSON and writes it to the specified file. Includes all profiles with their names, descriptions, and button action configurations.

Parameters
profileManagerThe profile manager containing profiles to save
configPathPath to the configuration file to write
Returns
true if saving succeeded, false if file write failed

Definition at line 19 of file config_loader_io.cpp.


The documentation for this class was generated from the following files: