5#include <ArduinoJson.h>
8using namespace ArduinoJson;
51 const std::string& jsonConfig)
53 DynamicJsonDocument doc(8192);
54 DeserializationError error = deserializeJson(doc, jsonConfig);
58 logger_->
log(
"JSON parsing failed:", error.c_str());
62 JsonArray profiles = doc[
"profiles"];
67 JsonObject profileJson = profiles[newIdx];
68 const char* profileName = profileJson[
"name"] |
"";
69 const char* profileDescription = profileJson[
"description"] |
"";
73 logger_->
log(
"Profile already exists, skipping: ", profileName);
78 if (targetIndex == 255)
80 logger_->
log(
"No empty profile slots available for merging");
84 auto newProfile = std::unique_ptr<Profile>(
new Profile(profileName));
85 newProfile->setDescription(profileDescription);
86 populateProfileFromJson(*newProfile, profileJson[
"buttons"], keyboard);
88 logger_->
log(
"Added profile: ", profileName);
110 uint8_t profileIndex,
111 const std::string& jsonConfig)
115 logger_->
log(
"Invalid profile index");
119 DynamicJsonDocument doc(8192);
120 DeserializationError error = deserializeJson(doc, jsonConfig);
124 logger_->
log(
"JSON parsing failed:", error.c_str());
128 JsonArray profiles = doc[
"profiles"];
129 if (profiles.size() == 0)
131 logger_->
log(
"No profiles found in JSON config");
135 JsonObject profileJson = profiles[0];
136 const char* profileName = profileJson[
"name"] |
"";
137 const char* profileDescription = profileJson[
"description"] |
"";
139 auto newProfile = std::unique_ptr<Profile>(
new Profile(profileName));
140 newProfile->setDescription(profileDescription);
141 populateProfileFromJson(*newProfile, profileJson[
"buttons"], keyboard);
143 logger_->
log(
"Replaced profile with: ", profileName);
bool replaceProfile(ProfileManager &profileManager, IBleKeyboard *keyboard, uint8_t profileIndex, const std::string &jsonConfig)
Replaces a specific profile with configuration from JSON.
bool mergeConfig(ProfileManager &profileManager, IBleKeyboard *keyboard, const std::string &jsonConfig)
Merges configuration from JSON into existing profiles.
Interface for Bluetooth LE keyboard functionality.
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
void addProfile(uint8_t profileIndex, std::unique_ptr< Profile > profile)
Represents a single button configuration profile.
const std::string & getName() const
Gets the name of this profile.
const HardwareConfig hardwareConfig
Global hardware configuration instance.
ProfileManager * profileManager
uint8_t numProfiles
Number of active profiles (1..MAX_PROFILES)