5#include <ArduinoJson.h>
7using namespace ArduinoJson;
21 DynamicJsonDocument doc(8192);
22 JsonArray profiles = doc.createNestedArray(
"profiles");
32 JsonObject profileObj = profiles.createNestedObject();
33 profileObj[
"name"] = profile->
getName().c_str();
36 JsonObject buttons = profileObj.createNestedObject(
"buttons");
45 JsonObject actionObj = buttons.createNestedObject(btnName);
46 actionToJson(action, actionObj);
52 serializeJson(doc, content);
54 if (! fileSystem_->
writeFile(configPath.c_str(), content))
56 logger_->
log(
"Failed to write config file");
73 logger_->
log(
"--- Config loaded ---");
82 logger_->
log(
"Profile: ", profile->
getName().c_str());
96 std::string line =
" ";
106 logger_->
log(line.c_str());
111void ConfigLoader::actionToJson(
const Action* action, JsonObject& out)
115 out[
"name"] = action->
getName().c_str();
121 out[
"type"] =
"SendStringAction";
125 out[
"type"] =
"SendCharAction";
129 out[
"type"] =
"SendKeyAction";
133 out[
"type"] =
"SendMediaKeyAction";
137 out[
"type"] =
"SerialOutputAction";
141 out[
"type"] =
"DelayedAction";
145 out[
"type"] =
"UnknownAction";
Base class for all pedal actions.
virtual Type getType() const
virtual void getJsonProperties(JsonObject &json) const
const std::string & getName() const
bool saveToFile(const ProfileManager &profileManager, const std::string &configPath)
Saves configuration to a file.
virtual bool writeFile(const char *path, const std::string &content)=0
Write content to a file.
virtual void log(const char *message)=0
Logs a single message.
Manages up to MAX_PROFILES profiles with LED feedback.
const Profile * getProfile(uint8_t profileIndex) const
static const char * getActionTypeString(Action::Type actionType)
Represents a single button configuration profile.
const std::string & getDescription() const
Gets the description of this profile.
Action * getAction(uint8_t button) const
Gets the action associated with a button in this profile.
const std::string & getName() const
Gets the name of this profile.
const HardwareConfig hardwareConfig
Global hardware configuration instance.
ProfileManager * profileManager
void name(uint8_t index, char *buf)
Write the letter name for a button index into buf.
uint8_t numButtons
Action buttons wired (1..26, A–Z)
uint8_t numProfiles
Number of active profiles (1..MAX_PROFILES)