Skip to content

Commit 87277e6

Browse files
rmaccrimmarntsonl
andauthored
GPIO-based Input mode and profile select on boot (#1620)
* Add array of new GpioInputMapping type to GamepadOptions * Add new branch to getBootAction which uses gpioInputModeMappings * Use std::optional instead of negative value * Move details of boot mode form out to separate funtion, start on gpio input form * Move FormSelect to a separate component * Outline form for gpio mapping * Update test data * Define useStore hook for input boot modes * Rename boto mode fields. Add profile index to boot mode config * Restoring settings page from main (switching to a brand new page instead) * Moving config to separate Options object. Add pin masks for web config and usb mode (required) * Move INPUT_MODES from settings page to Data/ file * work on BootModeStore * Stub out web api methods, add test data * Create a React component for boot mode mapping * Add profile select, general layout tweaks * UI tweaks * Add a toggle to switch between old and new boot mode mapping * Use nanoid to give a unique key to boot-modes in list. Implement missing actions * combine various add/remove pin funtions. Re-writes to make sure sets are updated immutably * Refactoring components so there are fewer state subscriptions in the top-level BootModeMapping * Split up PinSelect into two types to simplify zustand selectors. Fix deleting of pins * Pull first 2 rows out into a component to memoize, organization. * Check if usb peripheral is available in BootModeSelect * Refactor BootModesStore to use string keys instead of indices * Start replacing labels with useTranslation * Start working on some validation for gpio pin mapping * Renaming fields in config * use InputMode enum instaed of int * Renamed component * Rename APIs, update test data * Move BootModeMapping back to a Page * WIP add a method of highlighting invalid selects * Add nav item for boot modes. Link to page once GPIO mapping is enabled * re-order CSS to fix issue with hover on invalid selects * Work on validaton for required fields * Further validation improvements, group actions together * Disable boot mode page based on setting * Fix typo * Add BootModeOptions to Storage class * Implement pin-checking logic at startup * Add BootModeOptions to Config, change index to unsigned int * Implement the boot mode options API * Disable new boot-mode selection for now * Fix typos in JSON keys * Move enabled switch to Boot mode page. Clear errors after adding pin with capture button * Add missing enabled field, fix save method * Fix typos in JSON keys * Fix issue with profile not being saved correctly * Return profile number along with BootAction from getBootAction * Move error messages out of BootModeStore. Use 1-indexed profile number from controller * Update spaPaths, change profileIndex to profileNumber * Update getBootAction signature * Delete old getBootMode function for now * Ignore prettier config * Add function for setting pin mapping from boot mode options * Define new struct for controlling boot actions. Reduce the amount of mapping between enums in switch statements * Add missing method declaration * Rename profileIndex to profileNumber. Change required masks to uint32_t (no need for -1) * Reverting some upstream changes from post-0.7.12 that were left during rebase * Fix config, broken during rebase * Fixes to getBootAction implementation * Make sure save button is accessible when Gpio mode-select disabled * Add a "dirty" field to boot mode state to better handle saving * Restore old getBootAction func * Rework old getBootAction to work with new BootAction type * Disable reserved pins in drop-down * Fix bug with wrong inputMode being used * Cast enabled to boolean (was showing up as 0 in web config) * Add locale file. Add an explanation and alert-message * Move more text to locale file * Rename BootModeMappingPage.jsx to just BootModeMapping.jsx * Add P5General to InputBootModes (lost in merge) * Call old bootAction method, even if new mode is enabled --------- Co-authored-by: Luke A <arntsonl@gmail.com>
1 parent c9780ac commit 87277e6

21 files changed

Lines changed: 1353 additions & 356 deletions

headers/addons/reverse.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ class ReverseInput : public GPAddon {
6969
uint8_t actionRight;
7070
};
7171

72-
#endif // _Reverse_H_
72+
#endif // _Reverse_H_

headers/gp2040.h

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,29 +43,20 @@ class GP2040 {
4343
};
4444
RebootHotkeys rebootHotkeys;
4545

46-
enum class BootAction {
47-
NONE,
48-
ENTER_WEBCONFIG_MODE,
49-
ENTER_USB_MODE,
50-
SET_INPUT_MODE_SWITCH,
51-
SET_INPUT_MODE_XINPUT,
52-
SET_INPUT_MODE_KEYBOARD,
53-
SET_INPUT_MODE_GENERIC,
54-
SET_INPUT_MODE_PS3,
55-
SET_INPUT_MODE_PS4,
56-
SET_INPUT_MODE_PS5,
57-
SET_INPUT_MODE_P5GENERAL,
58-
SET_INPUT_MODE_XBONE,
59-
SET_INPUT_MODE_NEOGEO,
60-
SET_INPUT_MODE_MDMINI,
61-
SET_INPUT_MODE_PCEMINI,
62-
SET_INPUT_MODE_EGRET,
63-
SET_INPUT_MODE_ASTRO,
64-
SET_INPUT_MODE_PSCLASSIC,
65-
SET_INPUT_MODE_XBOXORIGINAL,
66-
SET_INPUT_MODE_SWITCH_PRO,
67-
};
68-
BootAction getBootAction();
46+
enum class BootActionType {
47+
ENTER_USB_MODE,
48+
SET_INPUT_MODE
49+
};
50+
51+
struct BootAction {
52+
BootActionType type;
53+
InputMode inputMode;
54+
uint32_t profileNumber;
55+
};
56+
57+
BootAction getGpioMappedBootAction();
58+
BootAction getButtonMappedBootAction();
59+
6960
void getReinitGamepad(Gamepad * gamepad);
7061

7162
// GPIO manipulation for setup and profile reinit
@@ -76,9 +67,6 @@ class GP2040 {
7667
void checkRawState(const GamepadState& prevState, const GamepadState& currState);
7768
void checkProcessedState(const GamepadState& prevState, const GamepadState& currState);
7869

79-
// input mask, action
80-
std::map<uint32_t, int32_t> bootActions;
81-
8270
void checkSaveRebootState();
8371
bool saveRequested = false;
8472
bool forceSave = false;

headers/storagemanager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Storage {
4545
ProfileOptions& getProfileOptions() { return config.profileOptions; }
4646
GpioMappingInfo* getProfilePinMappings() { return functionalPinMappings; }
4747
PeripheralOptions& getPeripheralOptions() { return config.peripheralOptions; }
48+
BootModeOptions& getBootModeOptions() { return config.bootModeOptions; }
4849

4950
void init();
5051
bool save();
@@ -60,6 +61,7 @@ class Storage {
6061
void nextProfile();
6162
void previousProfile();
6263
void setFunctionalPinMappings();
64+
void setBootModeFunctionalPinMappings();
6365
char* currentProfileLabel();
6466

6567
void ResetSettings(); // EEPROM Reset Feature

proto/config.proto

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@ syntax = "proto2";
33
import "nanopb.proto";
44
import "enums.proto";
55

6+
message InputModeMapping {
7+
// negative if mapping disabled
8+
optional int32 pinMask = 1;
9+
optional InputMode inputMode = 2;
10+
optional uint32 profileNumber = 3;
11+
}
12+
13+
message BootModeOptions {
14+
optional bool enabled = 1;
15+
optional uint32 webConfigPinMask = 2;
16+
optional uint32 usbModePinMask = 3;
17+
repeated InputModeMapping inputModeMappings = 4 [(nanopb).max_count = 8];
18+
}
19+
620
message GamepadOptions
721
{
822
optional InputMode inputMode = 1;
@@ -955,4 +969,5 @@ message Config
955969
optional GpioMappings gpioMappings = 13;
956970
optional MigrationHistory migrations = 14;
957971
optional PeripheralOptions peripheralOptions = 15;
972+
optional BootModeOptions bootModeOptions = 16;
958973
}

0 commit comments

Comments
 (0)