Skip to content

Commit

Permalink
multi mapping page (#7)
Browse files Browse the repository at this point in the history
* remove double initialization of gamepad GPIOs

* have getProfilePinMappings return whole GpioMappingInfos

before it returned just the actions, which was fine, but now we're
adding more stuff to the infos, so return the whole struct rather than
just the GpioAction within it

* define a custom button combo to a GPIO pin

this expands GpioMappingInfo to include dpad and button masks and uses
those masks when setting up the button maps in Gamepad. this allows for
a GPIO pin to trigger any arbitrary set of buttons

* Add a WIP multi mapping page

* have getProfilePinMappings return whole GpioMappingInfos

before it returned just the actions, which was fine, but now we're
adding more stuff to the infos, so return the whole struct rather than
just the GpioAction within it

* define a custom button combo to a GPIO pin

this expands GpioMappingInfo to include dpad and button masks and uses
those masks when setting up the button maps in Gamepad. this allows for
a GPIO pin to trigger any arbitrary set of buttons

* implement get/setPinMappingsV2 which includes the new masks

* Start moving to new payload structure, new endpoint, translation keys

* Set action if mask is set

* Multi-mapping route added to webconfig, start adding customDpadMask

* Revert endpoint test for v2

* fix issue where setPinMappingsV2 was actually ignoring input

* Rename BUTTON_MASK -> BUTTON_MASK_OPTIONS to prepare for multi mapping data

* Removed some unused imports

* Add support for dpad mask

* Add text for assigned to multi mapping on pin mapping page

* Add support for swapping button labels

* Update pins after setting multi pin

* Set correct default in multi mapping, disables selection on non selectable actions
  • Loading branch information
Pelsin authored and bsstephan committed Mar 25, 2024
1 parent f842e25 commit 7aef83e
Show file tree
Hide file tree
Showing 23 changed files with 1,012 additions and 357 deletions.
2 changes: 1 addition & 1 deletion src/configs/webconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ using namespace std;

extern struct fsdata_file file__index_html[];

const static char* spaPaths[] = { "/backup", "/display-config", "/led-config", "/pin-mapping", "/settings", "/reset-settings", "/add-ons", "/custom-theme", "/macro", "/peripheral-mapping" };
const static char* spaPaths[] = { "/backup", "/display-config", "/led-config", "/pin-mapping", "/multi-mapping", "/settings", "/reset-settings", "/add-ons", "/custom-theme", "/macro", "/peripheral-mapping" };
const static char* excludePaths[] = { "/css", "/images", "/js", "/static" };
const static uint32_t rebootDelayMs = 500;
static string http_post_uri;
Expand Down
38 changes: 19 additions & 19 deletions src/gp2040.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void GP2040::setup() {
DriverManager::getInstance().setup(inputMode);

// Save the changed input mode
if (inputMode != gamepad->getOptions().inputMode) {
if (inputMode != gamepad->getOptions().inputMode) {
gamepad->setInputMode(inputMode);
gamepad->save();
}
Expand Down Expand Up @@ -258,15 +258,15 @@ void GP2040::run() {

// Do any queued saves in StorageManager
Storage::getInstance().performEnqueuedSaves();

// Debounce
debounceGpioGetAll();
// Read Gamepad
gamepad->read();

// Config Loop (Web-Config does not require gamepad)
if (configMode == true) {

ConfigManager::getInstance().loop();
rebootHotkeys.process(gamepad, configMode);
continue;
Expand All @@ -280,7 +280,7 @@ void GP2040::run() {

gamepad->hotkey(); // check for MPGS hotkeys
rebootHotkeys.process(gamepad, configMode);

gamepad->process(); // process through MPGS

// (Post) Process for add-ons
Expand All @@ -291,10 +291,10 @@ void GP2040::run() {

// Process Input Driver
inputDriver->process(gamepad, featureData);

// Process USB Report Addons
addons.ProcessAddons(ADDON_PROCESS::CORE0_USBREPORT);

tud_task(); // TinyUSB Task update
}
}
Expand Down Expand Up @@ -337,13 +337,13 @@ GP2040::BootAction GP2040::getBootAction() {
// Determine boot action based on gamepad state during boot
Gamepad * gamepad = Storage::getInstance().GetGamepad();
Gamepad * processedGamepad = Storage::getInstance().GetProcessedGamepad();

debounceGpioGetAll();
gamepad->read();

// Pre-Process add-ons for MPGS
addons.PreprocessAddons(ADDON_PROCESS::CORE0_INPUT);

gamepad->process(); // process through MPGS

// (Post) Process for add-ons
Expand All @@ -367,31 +367,31 @@ GP2040::BootAction GP2040::getBootAction() {
if (!modeSwitchLocked) {
if (auto search = bootActions.find(gamepad->state.buttons); search != bootActions.end()) {
switch (search->second) {
case INPUT_MODE_XINPUT:
case INPUT_MODE_XINPUT:
return BootAction::SET_INPUT_MODE_XINPUT;
case INPUT_MODE_SWITCH:
case INPUT_MODE_SWITCH:
return BootAction::SET_INPUT_MODE_SWITCH;
case INPUT_MODE_HID:
case INPUT_MODE_HID:
return BootAction::SET_INPUT_MODE_HID;
case INPUT_MODE_KEYBOARD:
case INPUT_MODE_KEYBOARD:
return BootAction::SET_INPUT_MODE_KEYBOARD;
case INPUT_MODE_PS4:
case INPUT_MODE_PS4:
return BootAction::SET_INPUT_MODE_PS4;
case INPUT_MODE_PS5:
return BootAction::SET_INPUT_MODE_PS5;
case INPUT_MODE_NEOGEO:
return BootAction::SET_INPUT_MODE_NEOGEO;
case INPUT_MODE_MDMINI:
case INPUT_MODE_MDMINI:
return BootAction::SET_INPUT_MODE_MDMINI;
case INPUT_MODE_PCEMINI:
case INPUT_MODE_PCEMINI:
return BootAction::SET_INPUT_MODE_PCEMINI;
case INPUT_MODE_EGRET:
case INPUT_MODE_EGRET:
return BootAction::SET_INPUT_MODE_EGRET;
case INPUT_MODE_ASTRO:
case INPUT_MODE_ASTRO:
return BootAction::SET_INPUT_MODE_ASTRO;
case INPUT_MODE_PSCLASSIC:
case INPUT_MODE_PSCLASSIC:
return BootAction::SET_INPUT_MODE_PSCLASSIC;
case INPUT_MODE_XBOXORIGINAL:
case INPUT_MODE_XBOXORIGINAL:
return BootAction::SET_INPUT_MODE_XBOXORIGINAL;
case INPUT_MODE_XBONE:
return BootAction::SET_INPUT_MODE_XBONE;
Expand Down
12 changes: 12 additions & 0 deletions www/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,18 @@ app.get('/api/getCustomTheme', (req, res) => {
});
});

app.get('/api/getPinMappingsV2', (req, res) => {
return res.send(
Object.entries(picoController).reduce(
(acc, [key, value]) => ({
...acc,
[key]: { action: value, customButtonMask: 0, customDpadMask: 0 },
}),
{},
),
);
});

app.get('/api/getPinMappings', (req, res) => {
return res.send(picoController);
});
Expand Down
9 changes: 6 additions & 3 deletions www/src/Addons/Bootsel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as yup from 'yup';

import Section from '../Components/Section';
import FormSelect from '../Components/FormSelect';
import { BUTTON_MASKS } from '../Data/Buttons';
import { BUTTON_MASKS_OPTIONS } from '../Data/Buttons';

export const bootselScheme = {
BootselButtonAddonEnabled: yup
Expand All @@ -15,7 +15,10 @@ export const bootselScheme = {
bootselButtonMap: yup
.number()
.label('BOOTSEL Button Map')
.validateSelectionWhenValue('BootselButtonAddonEnabled', BUTTON_MASKS),
.validateSelectionWhenValue(
'BootselButtonAddonEnabled',
BUTTON_MASKS_OPTIONS,
),
};

export const bootselState = {
Expand All @@ -42,7 +45,7 @@ const Bootsel = ({ values, errors, handleChange, handleCheckbox }) => {
isInvalid={errors.bootselButtonMap}
onChange={handleChange}
>
{BUTTON_MASKS.map((o, i) => (
{BUTTON_MASKS_OPTIONS.map((o, i) => (
<option key={`bootselButtonMap-option-${i}`} value={o.value}>
{o.label}
</option>
Expand Down
8 changes: 4 additions & 4 deletions www/src/Addons/FocusMode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Section from '../Components/Section';

import FormControl from '../Components/FormControl';
import FormSelect from '../Components/FormSelect';
import { BUTTON_MASKS } from '../Data/Buttons';
import { BUTTON_MASKS_OPTIONS } from '../Data/Buttons';

export const focusModeScheme = {
FocusModeAddonEnabled: yup
Expand Down Expand Up @@ -93,7 +93,7 @@ const FocusMode = ({
/>
</div>
<Row>
{BUTTON_MASKS.map((mask) =>
{BUTTON_MASKS_OPTIONS.map((mask) =>
values.focusModeButtonLockMask & mask.value ? (
<FormSelect
key={`focusModeButtonLockMask-${mask.label}`}
Expand All @@ -111,7 +111,7 @@ const FocusMode = ({
);
}}
>
{BUTTON_MASKS.map((o, i) => (
{BUTTON_MASKS_OPTIONS.map((o, i) => (
<option
key={`focusModeButtonLockMask-option-${i}`}
value={o.value}
Expand All @@ -138,7 +138,7 @@ const FocusMode = ({
);
}}
>
{BUTTON_MASKS.map((o, i) => (
{BUTTON_MASKS_OPTIONS.map((o, i) => (
<option
key={`focusModeButtonLockMask-option-${i}`}
value={o.value}
Expand Down
18 changes: 9 additions & 9 deletions www/src/Addons/Turbo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Section from '../Components/Section';
import FormSelect from '../Components/FormSelect';
import FormControl from '../Components/FormControl';
import AnalogPinOptions from '../Components/AnalogPinOptions';
import { BUTTON_MASKS } from '../Data/Buttons';
import { BUTTON_MASKS_OPTIONS } from '../Data/Buttons';
import { DUAL_STICK_MODES } from '../Data/Addons';

const SHMUP_MIXED_MODES = [
Expand Down Expand Up @@ -70,35 +70,35 @@ export const turboScheme = {
shmupAlwaysOn1: yup
.number()
.label('Turbo-Button 1 (Always On)')
.validateSelectionWhenValue('TurboInputEnabled', BUTTON_MASKS),
.validateSelectionWhenValue('TurboInputEnabled', BUTTON_MASKS_OPTIONS),
shmupAlwaysOn2: yup
.number()
.label('Turbo-Button 2 (Always On)')
.validateSelectionWhenValue('TurboInputEnabled', BUTTON_MASKS),
.validateSelectionWhenValue('TurboInputEnabled', BUTTON_MASKS_OPTIONS),
shmupAlwaysOn3: yup
.number()
.label('Turbo-Button 3 (Always On)')
.validateSelectionWhenValue('TurboInputEnabled', BUTTON_MASKS),
.validateSelectionWhenValue('TurboInputEnabled', BUTTON_MASKS_OPTIONS),
shmupAlwaysOn4: yup
.number()
.label('Turbo-Button 4 (Always On)')
.validateSelectionWhenValue('TurboInputEnabled', BUTTON_MASKS),
.validateSelectionWhenValue('TurboInputEnabled', BUTTON_MASKS_OPTIONS),
shmupBtnMask1: yup
.number()
.label('Charge Shot Button 1 Map')
.validateSelectionWhenValue('TurboInputEnabled', BUTTON_MASKS),
.validateSelectionWhenValue('TurboInputEnabled', BUTTON_MASKS_OPTIONS),
shmupBtnMask2: yup
.number()
.label('Charge Shot Button 2 Map')
.validateSelectionWhenValue('TurboInputEnabled', BUTTON_MASKS),
.validateSelectionWhenValue('TurboInputEnabled', BUTTON_MASKS_OPTIONS),
shmupBtnMask3: yup
.number()
.label('Charge Shot Button 3 Map')
.validateSelectionWhenValue('TurboInputEnabled', BUTTON_MASKS),
.validateSelectionWhenValue('TurboInputEnabled', BUTTON_MASKS_OPTIONS),
shmupBtnMask4: yup
.number()
.label('Charge Shot Button 4 Map')
.validateSelectionWhenValue('TurboInputEnabled', BUTTON_MASKS),
.validateSelectionWhenValue('TurboInputEnabled', BUTTON_MASKS_OPTIONS),
};

export const turboState = {
Expand Down
Loading

0 comments on commit 7aef83e

Please sign in to comment.