Skip to content

Commit

Permalink
Config migration and input history additions (#672)
Browse files Browse the repository at this point in the history
* Fix tilt defaults on webconfig dev to allow validation to pass

* Added migration for I2C and USB addons to peripherals

* Added new input modes to input history

* Added input mode groupings to mode selection dropdowns

* Added input mode permissions to detect if required/optional settings are enabled.

* Set PS4 mode permissions to optional instead of required

* Adjustments to Astro City and Egret button mapping

* Updated addons, display, and settings pages to reload peripherals data on load
  • Loading branch information
mikepparks authored Dec 19, 2023
1 parent e3f10c6 commit 214079f
Show file tree
Hide file tree
Showing 11 changed files with 412 additions and 93 deletions.
12 changes: 6 additions & 6 deletions headers/gamepad/descriptors/AstroDescriptors.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
#define ASTRO_HAT_NOTHING 0x08

// Buttons (16 bits)
#define ASTRO_MASK_A 0x0080
#define ASTRO_MASK_B 0x0010
#define ASTRO_MASK_C 0x0100
#define ASTRO_MASK_D 0x0040
#define ASTRO_MASK_E 0x0020
#define ASTRO_MASK_F 0x0200
#define ASTRO_MASK_A 0x0040
#define ASTRO_MASK_B 0x0020
#define ASTRO_MASK_C 0x0200
#define ASTRO_MASK_D 0x0080
#define ASTRO_MASK_E 0x0010
#define ASTRO_MASK_F 0x0100
#define ASTRO_MASK_CREDIT 0x1000
#define ASTRO_MASK_START 0x2000

Expand Down
73 changes: 61 additions & 12 deletions src/addons/inputhistory.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
#include <map>
#include "addons/inputhistory.h"
#include "storagemanager.h"
#include "math.h"
#include "usb_driver.h"
#include "helper.h"
#include "config.pb.h"

const map<uint16_t, uint16_t> displayModeLookup = {
{INPUT_MODE_HID, 0},
{INPUT_MODE_SWITCH, 1},
{INPUT_MODE_XINPUT, 2},
{INPUT_MODE_KEYBOARD, 3},
{INPUT_MODE_PS4, 4},
{INPUT_MODE_PSCLASSIC, 4},
{INPUT_MODE_CONFIG, 5},
{INPUT_MODE_MDMINI, 6},
{INPUT_MODE_NEOGEO, 7},
{INPUT_MODE_PCEMINI, 8},
{INPUT_MODE_EGRET, 9},
{INPUT_MODE_ASTRO, 10},
{INPUT_MODE_XBOXORIGINAL, 11},
};

static const std::string displayNames[][INPUT_HISTORY_MAX_INPUTS] = {
{ // HID / DINPUT
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
Expand Down Expand Up @@ -47,7 +64,49 @@ static const std::string displayNames[][INPUT_HISTORY_MAX_INPUTS] = {
"B1", "B2", "B3", "B4",
"L1", "R1", "L2", "R2",
"S1", "S2", "L3", "R3", "A1", "A2"
}
},
{ // GEN/MD Mini
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
"A", "B", "X", "Y",
"", "Z", "", "C",
"M", "S", "", "", "", ""
},
{ // Neo Geo Mini
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
"B", "D", "A", "C",
"", "", "", "",
"SE", "ST", "", "", "", ""
},
{ // PC Engine/TG16 Mini
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
"I", "II", "", "",
"", "", "", "",
"SE", "RUN", "", "", "", ""
},
{ // Egret II Mini
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
"A", "B", "C", "D",
"", "E", "", "F",
"CRD", "ST", "", "", "MN", ""
},
{ // Astro City Mini
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
"A", "B", "D", "E",
"", "C", "", "F",
"CRD", "ST", "", "", "", ""
},
{ // Original Xbox
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
"A", "B", "X", "Y",
"BL", "WH", "L", "R",
"BK", "ST", "LS", "RS", "", ""
},
};

bool InputHistoryAddon::available() {
Expand Down Expand Up @@ -98,17 +157,7 @@ void InputHistoryAddon::process() {
gamepad->pressedA2(),
};

uint8_t mode;
switch (gamepad->getOptions().inputMode)
{
case INPUT_MODE_HID: mode=0; break;
case INPUT_MODE_SWITCH: mode=1; break;
case INPUT_MODE_XINPUT: mode=2; break;
case INPUT_MODE_KEYBOARD: mode=3; break;
case INPUT_MODE_PS4: mode=4; break;
case INPUT_MODE_CONFIG: mode=5; break;
default: mode=0; break;
}
uint8_t mode = ((displayModeLookup.count(gamepad->getOptions().inputMode) > 0) ? displayModeLookup.at(gamepad->getOptions().inputMode) : 0);

// Check if any new keys have been pressed
if (lastInput != currentInput) {
Expand Down
189 changes: 177 additions & 12 deletions src/config_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,10 @@ void gpioMappingsMigrationCore(Config& config)
DualDirectionalOptions& ddiOptions = config.addonOptions.dualDirectionalOptions;
SliderOptions& jsSliderOptions = config.addonOptions.sliderOptions;
SOCDSliderOptions& socdSliderOptions = config.addonOptions.socdSliderOptions;
PeripheralOptions& peripheralOptions = config.peripheralOptions;
TiltOptions& tiltOptions = config.addonOptions.tiltOptions;
KeyboardHostOptions& keyboardHostOptions = config.addonOptions.keyboardHostOptions;
PSPassthroughOptions& psPassthroughOptions = config.addonOptions.psPassthroughOptions;

const auto gamepadMaskToGpioAction = [&](Mask_t gpMask) -> GpioAction
{
Expand Down Expand Up @@ -639,6 +643,11 @@ void gpioMappingsMigrationCore(Config& config)
GpioAction::NONE, GpioAction::NONE, GpioAction::NONE,
GpioAction::NONE, GpioAction::NONE, GpioAction::NONE};

// flag additional pins as being used by an addon not managed here
const auto markAddonPinIfUsed = [&](Pin_t gpPin) -> void {
if (isValidPin(gpPin)) actions[gpPin] = GpioAction::ASSIGNED_TO_ADDON;
};

const auto fromPBorBC = [&](bool isInProtobuf, Pin_t *protobufEntry, Pin_t boardconfigValue,
GpioAction action) -> void {
// get the core config value for a pin either from protobuf or, failing that, BoardConfig.h
Expand Down Expand Up @@ -834,10 +843,166 @@ void gpioMappingsMigrationCore(Config& config)
}
}

// flag additional pins as being used by an addon not managed here
const auto markAddonPinIfUsed = [&](Pin_t gpPin) -> void {
if (isValidPin(gpPin)) actions[gpPin] = GpioAction::ASSIGNED_TO_ADDON;
};
// verify that tilt factors are not set to -1
if (tiltOptions.enabled) {
if (tiltOptions.factorTilt1LeftX == -1) tiltOptions.factorTilt1LeftX = TILT1_FACTOR_LEFT_X;
if (tiltOptions.factorTilt1LeftY == -1) tiltOptions.factorTilt1LeftY = TILT1_FACTOR_LEFT_Y;
if (tiltOptions.factorTilt1RightX == -1) tiltOptions.factorTilt1RightX = TILT1_FACTOR_RIGHT_X;
if (tiltOptions.factorTilt1RightY == -1) tiltOptions.factorTilt1RightY = TILT1_FACTOR_RIGHT_Y;
if (tiltOptions.factorTilt2LeftX == -1) tiltOptions.factorTilt2LeftX = TILT2_FACTOR_LEFT_X;
if (tiltOptions.factorTilt2LeftY == -1) tiltOptions.factorTilt2LeftY = TILT2_FACTOR_LEFT_Y;
if (tiltOptions.factorTilt2RightX == -1) tiltOptions.factorTilt2RightX = TILT2_FACTOR_RIGHT_X;
if (tiltOptions.factorTilt2RightY == -1) tiltOptions.factorTilt2RightY = TILT2_FACTOR_RIGHT_Y;
}

// migrate I2C addons to use peripheral manager
if (!peripheralOptions.blockI2C0.enabled && (
(config.displayOptions.enabled && (config.displayOptions.i2cBlock == 0)) ||
(config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.i2cBlock == 0)) ||
(config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.i2cBlock == 0))
)
) {
peripheralOptions.blockI2C0.enabled = (
(config.displayOptions.enabled && (config.displayOptions.i2cBlock == 0)) |
(config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.i2cBlock == 0)) |
(config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.i2cBlock == 0)) |
false
);

// pin configuration
peripheralOptions.blockI2C0.sda = (
isValidPin(config.displayOptions.i2cSDAPin) && (config.displayOptions.i2cBlock == 0) ?
config.displayOptions.i2cSDAPin :
(
isValidPin(config.addonOptions.analogADS1219Options.i2cSDAPin) && (config.addonOptions.analogADS1219Options.i2cBlock == 0) ?
config.addonOptions.analogADS1219Options.i2cSDAPin :
(
isValidPin(config.addonOptions.wiiOptions.i2cSDAPin) && (config.addonOptions.wiiOptions.i2cBlock == 0) ?
config.addonOptions.wiiOptions.i2cSDAPin :
-1
)
)
);

peripheralOptions.blockI2C0.scl = (
isValidPin(config.displayOptions.i2cSCLPin) && (config.displayOptions.i2cBlock == 0) ?
config.displayOptions.i2cSCLPin :
(
isValidPin(config.addonOptions.analogADS1219Options.i2cSCLPin) && (config.addonOptions.analogADS1219Options.i2cBlock == 0) ?
config.addonOptions.analogADS1219Options.i2cSCLPin :
(
isValidPin(config.addonOptions.wiiOptions.i2cSCLPin) && (config.addonOptions.wiiOptions.i2cBlock == 0) ?
config.addonOptions.wiiOptions.i2cSCLPin :
-1
)
)
);

// option configuration
peripheralOptions.blockI2C0.speed = (
isValidPin(config.displayOptions.i2cSpeed) && (config.displayOptions.i2cBlock == 0) ?
config.displayOptions.i2cSpeed :
(
isValidPin(config.addonOptions.analogADS1219Options.i2cSpeed) && (config.addonOptions.analogADS1219Options.i2cBlock == 0) ?
config.addonOptions.analogADS1219Options.i2cSpeed :
(
isValidPin(config.addonOptions.wiiOptions.i2cSpeed) && (config.addonOptions.wiiOptions.i2cBlock == 0) ?
config.addonOptions.wiiOptions.i2cSpeed :
-1
)
)
);
}

if (!peripheralOptions.blockI2C1.enabled && (
(config.displayOptions.enabled && (config.displayOptions.i2cBlock == 1)) ||
(config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.i2cBlock == 1)) ||
(config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.i2cBlock == 1))
)
) {
peripheralOptions.blockI2C1.enabled = (
(config.displayOptions.enabled && (config.displayOptions.i2cBlock == 1)) |
(config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.i2cBlock == 1)) |
(config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.i2cBlock == 1)) |
false
);

// pin configuration
peripheralOptions.blockI2C1.sda = (
isValidPin(config.displayOptions.i2cSDAPin) && (config.displayOptions.i2cBlock == 1) ?
config.displayOptions.i2cSDAPin :
(
isValidPin(config.addonOptions.analogADS1219Options.i2cSDAPin) && (config.addonOptions.analogADS1219Options.i2cBlock == 1) ?
config.addonOptions.analogADS1219Options.i2cSDAPin :
(
isValidPin(config.addonOptions.wiiOptions.i2cSDAPin) && (config.addonOptions.wiiOptions.i2cBlock == 1) ?
config.addonOptions.wiiOptions.i2cSDAPin :
-1
)
)
);

peripheralOptions.blockI2C1.scl = (
isValidPin(config.displayOptions.i2cSCLPin) && (config.displayOptions.i2cBlock == 1) ?
config.displayOptions.i2cSCLPin :
(
isValidPin(config.addonOptions.analogADS1219Options.i2cSCLPin) && (config.addonOptions.analogADS1219Options.i2cBlock == 1) ?
config.addonOptions.analogADS1219Options.i2cSCLPin :
(
isValidPin(config.addonOptions.wiiOptions.i2cSCLPin) && (config.addonOptions.wiiOptions.i2cBlock == 1) ?
config.addonOptions.wiiOptions.i2cSCLPin :
-1
)
)
);

// option configuration
peripheralOptions.blockI2C1.speed = (
isValidPin(config.displayOptions.i2cSpeed) && (config.displayOptions.i2cBlock == 1) ?
config.displayOptions.i2cSpeed :
(
isValidPin(config.addonOptions.analogADS1219Options.i2cSpeed) && (config.addonOptions.analogADS1219Options.i2cBlock == 1) ?
config.addonOptions.analogADS1219Options.i2cSpeed :
(
isValidPin(config.addonOptions.wiiOptions.i2cSpeed) && (config.addonOptions.wiiOptions.i2cBlock == 1) ?
config.addonOptions.wiiOptions.i2cSpeed :
-1
)
)
);
}

// migrate USB addons to use peripheral manager
if (!peripheralOptions.blockUSB0.enabled && (keyboardHostOptions.enabled || psPassthroughOptions.enabled)) {
peripheralOptions.blockUSB0.enabled = keyboardHostOptions.enabled | psPassthroughOptions.enabled | false;

if (peripheralOptions.blockUSB0.enabled) {
peripheralOptions.blockUSB0.enable5v = (
isValidPin(keyboardHostOptions.pin5V) ?
keyboardHostOptions.pin5V :
(
isValidPin(psPassthroughOptions.pin5V) ?
psPassthroughOptions.pin5V :
-1
)
);
markAddonPinIfUsed(peripheralOptions.blockUSB0.enable5v);

peripheralOptions.blockUSB0.dp = (
isValidPin(keyboardHostOptions.pinDplus) ?
keyboardHostOptions.pinDplus :
(
isValidPin(psPassthroughOptions.pinDplus) ?
psPassthroughOptions.pinDplus :
-1
)
);
markAddonPinIfUsed(peripheralOptions.blockUSB0.dp);
if (isValidPin(peripheralOptions.blockUSB0.dp))
actions[peripheralOptions.blockUSB0.dp+1] = GpioAction::ASSIGNED_TO_ADDON;
}
}

markAddonPinIfUsed(config.displayOptions.i2cSCLPin);
markAddonPinIfUsed(config.displayOptions.i2cSDAPin);
markAddonPinIfUsed(config.ledOptions.dataPin);
Expand Down Expand Up @@ -877,14 +1042,14 @@ void gpioMappingsMigrationCore(Config& config)
markAddonPinIfUsed(config.addonOptions.snesOptions.clockPin);
markAddonPinIfUsed(config.addonOptions.snesOptions.latchPin);
markAddonPinIfUsed(config.addonOptions.snesOptions.dataPin);
markAddonPinIfUsed(config.addonOptions.keyboardHostOptions.pin5V);
markAddonPinIfUsed(config.addonOptions.keyboardHostOptions.pinDplus);
if (isValidPin(config.addonOptions.keyboardHostOptions.pinDplus))
actions[config.addonOptions.keyboardHostOptions.pinDplus+1] = GpioAction::ASSIGNED_TO_ADDON;
markAddonPinIfUsed(config.addonOptions.psPassthroughOptions.pin5V);
markAddonPinIfUsed(config.addonOptions.psPassthroughOptions.pinDplus);
if (isValidPin(config.addonOptions.psPassthroughOptions.pinDplus))
actions[config.addonOptions.psPassthroughOptions.pinDplus+1] = GpioAction::ASSIGNED_TO_ADDON;
//markAddonPinIfUsed(config.addonOptions.keyboardHostOptions.pin5V);
//markAddonPinIfUsed(config.addonOptions.keyboardHostOptions.pinDplus);
//if (isValidPin(config.addonOptions.keyboardHostOptions.pinDplus))
// actions[config.addonOptions.keyboardHostOptions.pinDplus+1] = GpioAction::ASSIGNED_TO_ADDON;
//markAddonPinIfUsed(config.addonOptions.psPassthroughOptions.pin5V);
//markAddonPinIfUsed(config.addonOptions.psPassthroughOptions.pinDplus);
//if (isValidPin(config.addonOptions.psPassthroughOptions.pinDplus))
// actions[config.addonOptions.psPassthroughOptions.pinDplus+1] = GpioAction::ASSIGNED_TO_ADDON;
markAddonPinIfUsed(config.addonOptions.macroOptions.pin);
markAddonPinIfUsed(config.addonOptions.macroOptions.macroList[0].macroTriggerPin);
markAddonPinIfUsed(config.addonOptions.macroOptions.macroList[1].macroTriggerPin);
Expand Down
12 changes: 6 additions & 6 deletions src/gamepad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -962,8 +962,8 @@ AstroReport *Gamepad::getAstroReport()
| (pressedB2() ? ASTRO_MASK_B : 0)
| (pressedB3() ? ASTRO_MASK_D : 0)
| (pressedB4() ? ASTRO_MASK_E : 0)
| (pressedR1() ? ASTRO_MASK_C : 0)
| (pressedR2() ? ASTRO_MASK_F : 0)
| (pressedR1() ? ASTRO_MASK_F : 0)
| (pressedR2() ? ASTRO_MASK_C : 0)
| (pressedS1() ? ASTRO_MASK_CREDIT : 0)
| (pressedS2() ? ASTRO_MASK_START : 0)
;
Expand All @@ -990,10 +990,10 @@ EgretReport *Gamepad::getEgretReport()
egretReport.buttons = 0
| (pressedB1() ? EGRET_MASK_A : 0)
| (pressedB2() ? EGRET_MASK_B : 0)
| (pressedB3() ? EGRET_MASK_C : 0)
| (pressedB4() ? EGRET_MASK_D : 0)
| (pressedR1() ? EGRET_MASK_E : 0)
| (pressedR2() ? EGRET_MASK_F : 0)
| (pressedB3() ? EGRET_MASK_D : 0)
| (pressedB4() ? EGRET_MASK_E : 0)
| (pressedR1() ? EGRET_MASK_F : 0)
| (pressedR2() ? EGRET_MASK_C : 0)
| (pressedS1() ? EGRET_MASK_CREDIT : 0)
| (pressedS2() ? EGRET_MASK_START : 0)
| (pressedA1() ? EGRET_MASK_MENU : 0)
Expand Down
16 changes: 8 additions & 8 deletions www/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,15 @@ app.get('/api/getAddonsOptions', (req, res) => {
dualDirCombineMode: 0,
dualDirFourWayMode: 0,
tilt1Pin: -1,
factorTilt1LeftX: -1,
factorTilt1LeftY: -1,
factorTilt1RightX: -1,
factorTilt1RightY: -1,
factorTilt1LeftX: 0,
factorTilt1LeftY: 0,
factorTilt1RightX: 0,
factorTilt1RightY: 0,
tilt2Pin: -1,
factorTilt2LeftX: -1,
factorTilt2LeftY: -1,
factorTilt2RightX: -1,
factorTilt2RightY: -1,
factorTilt2LeftX: 0,
factorTilt2LeftY: 0,
factorTilt2RightX: 0,
factorTilt2RightY: 0,
tiltLeftAnalogUpPin: -1,
tiltLeftAnalogDownPin: -1,
tiltLeftAnalogLeftPin: -1,
Expand Down
Loading

0 comments on commit 214079f

Please sign in to comment.