Skip to content

Commit

Permalink
action button pin mapping profiles, part 2: API
Browse files Browse the repository at this point in the history
not sure what was going on but this was a bit squirrely on the board.
binary-tools were fine adding nodes, but it seemed as if having
partially-defined data was confusing nanopb or something, so I added
inits just in case. can't reproduce the problem anymore, anyway
  • Loading branch information
bsstephan committed Jul 2, 2023
1 parent 886b5a6 commit c824603
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/config_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,33 @@ void ConfigUtils::initUnsetPropertiesWithDefaults(Config& config)
INIT_UNSET_PROPERTY(config.displayOptions, invert, !!DISPLAY_INVERT);
INIT_UNSET_PROPERTY(config.displayOptions, displaySaverTimeout, DISPLAY_SAVER_TIMEOUT);

// alternate pin mappings
INIT_UNSET_PROPERTY(config.profileOptions.alternativePinMappings[0], pinButtonB1, PIN_BUTTON_B1);
INIT_UNSET_PROPERTY(config.profileOptions.alternativePinMappings[0], pinButtonB2, PIN_BUTTON_B2);
INIT_UNSET_PROPERTY(config.profileOptions.alternativePinMappings[0], pinButtonB3, PIN_BUTTON_B3);
INIT_UNSET_PROPERTY(config.profileOptions.alternativePinMappings[0], pinButtonB4, PIN_BUTTON_B4);
INIT_UNSET_PROPERTY(config.profileOptions.alternativePinMappings[0], pinButtonL1, PIN_BUTTON_L1);
INIT_UNSET_PROPERTY(config.profileOptions.alternativePinMappings[0], pinButtonR1, PIN_BUTTON_R1);
INIT_UNSET_PROPERTY(config.profileOptions.alternativePinMappings[0], pinButtonL2, PIN_BUTTON_L2);
INIT_UNSET_PROPERTY(config.profileOptions.alternativePinMappings[0], pinButtonR2, PIN_BUTTON_R2);
INIT_UNSET_PROPERTY(config.profileOptions.alternativePinMappings[1], pinButtonB1, PIN_BUTTON_B1);
INIT_UNSET_PROPERTY(config.profileOptions.alternativePinMappings[1], pinButtonB2, PIN_BUTTON_B2);
INIT_UNSET_PROPERTY(config.profileOptions.alternativePinMappings[1], pinButtonB3, PIN_BUTTON_B3);
INIT_UNSET_PROPERTY(config.profileOptions.alternativePinMappings[1], pinButtonB4, PIN_BUTTON_B4);
INIT_UNSET_PROPERTY(config.profileOptions.alternativePinMappings[1], pinButtonL1, PIN_BUTTON_L1);
INIT_UNSET_PROPERTY(config.profileOptions.alternativePinMappings[1], pinButtonR1, PIN_BUTTON_R1);
INIT_UNSET_PROPERTY(config.profileOptions.alternativePinMappings[1], pinButtonL2, PIN_BUTTON_L2);
INIT_UNSET_PROPERTY(config.profileOptions.alternativePinMappings[1], pinButtonR2, PIN_BUTTON_R2);
INIT_UNSET_PROPERTY(config.profileOptions.alternativePinMappings[2], pinButtonB1, PIN_BUTTON_B1);
INIT_UNSET_PROPERTY(config.profileOptions.alternativePinMappings[2], pinButtonB2, PIN_BUTTON_B2);
INIT_UNSET_PROPERTY(config.profileOptions.alternativePinMappings[2], pinButtonB3, PIN_BUTTON_B3);
INIT_UNSET_PROPERTY(config.profileOptions.alternativePinMappings[2], pinButtonB4, PIN_BUTTON_B4);
INIT_UNSET_PROPERTY(config.profileOptions.alternativePinMappings[2], pinButtonL1, PIN_BUTTON_L1);
INIT_UNSET_PROPERTY(config.profileOptions.alternativePinMappings[2], pinButtonR1, PIN_BUTTON_R1);
INIT_UNSET_PROPERTY(config.profileOptions.alternativePinMappings[2], pinButtonL2, PIN_BUTTON_L2);
INIT_UNSET_PROPERTY(config.profileOptions.alternativePinMappings[2], pinButtonR2, PIN_BUTTON_R2);
config.profileOptions.alternativePinMappings_count = 3;

// ledOptions
INIT_UNSET_PROPERTY(config.ledOptions, dataPin, BOARD_LEDS_PIN);
INIT_UNSET_PROPERTY(config.ledOptions, ledFormat, static_cast<LEDFormat_Proto>(LED_FORMAT));
Expand Down
33 changes: 33 additions & 0 deletions src/configs/webconfig.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "configs/webconfig.h"
#include "config.pb.h"
#include "configs/base64.h"

#include "storagemanager.h"
Expand Down Expand Up @@ -504,13 +505,45 @@ std::string setProfileOptions()
{
DynamicJsonDocument doc = get_post_data();

ProfileOptions& profileOptions = Storage::getInstance().getProfileOptions();
JsonObject options = doc.as<JsonObject>();
JsonArray alts = options["alternativePinMappings"];
int altsIndex = 0;
for (JsonObject alt : alts) {
profileOptions.alternativePinMappings[altsIndex].pinButtonB1 = alt["pinButtonB1"].as<int>();
profileOptions.alternativePinMappings[altsIndex].pinButtonB2 = alt["pinButtonB2"].as<int>();
profileOptions.alternativePinMappings[altsIndex].pinButtonB3 = alt["pinButtonB3"].as<int>();
profileOptions.alternativePinMappings[altsIndex].pinButtonB4 = alt["pinButtonB4"].as<int>();
profileOptions.alternativePinMappings[altsIndex].pinButtonL1 = alt["pinButtonL1"].as<int>();
profileOptions.alternativePinMappings[altsIndex].pinButtonR1 = alt["pinButtonR1"].as<int>();
profileOptions.alternativePinMappings[altsIndex].pinButtonL2 = alt["pinButtonL2"].as<int>();
profileOptions.alternativePinMappings[altsIndex].pinButtonR2 = alt["pinButtonR2"].as<int>();
profileOptions.alternativePinMappings_count = ++altsIndex;
if (altsIndex > 2) break;
}

Storage::getInstance().save();
return serialize_json(doc);
}

std::string getProfileOptions()
{
DynamicJsonDocument doc(LWIP_HTTPD_POST_MAX_PAYLOAD_LEN);

ProfileOptions& profileOptions = Storage::getInstance().getProfileOptions();
JsonArray alts = doc.createNestedArray("alternativePinMappings");
for (int i = 0; i < profileOptions.alternativePinMappings_count; i++) {
JsonObject altMappings = alts.createNestedObject();
altMappings["pinButtonB1"] = profileOptions.alternativePinMappings[i].pinButtonB1;
altMappings["pinButtonB2"] = profileOptions.alternativePinMappings[i].pinButtonB2;
altMappings["pinButtonB3"] = profileOptions.alternativePinMappings[i].pinButtonB3;
altMappings["pinButtonB4"] = profileOptions.alternativePinMappings[i].pinButtonB4;
altMappings["pinButtonL1"] = profileOptions.alternativePinMappings[i].pinButtonL1;
altMappings["pinButtonR1"] = profileOptions.alternativePinMappings[i].pinButtonR1;
altMappings["pinButtonL2"] = profileOptions.alternativePinMappings[i].pinButtonL2;
altMappings["pinButtonR2"] = profileOptions.alternativePinMappings[i].pinButtonR2;
}

return serialize_json(doc);
}

Expand Down

0 comments on commit c824603

Please sign in to comment.