Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to allow switching Touchpad and Share buttons #254

Merged
merged 1 commit into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions headers/gamepad/GamepadOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,7 @@ struct GamepadOptions
GamepadHotkeyEntry hotkeyF2Left;
GamepadHotkeyEntry hotkeyF2Right;

bool switchTpShareForDs4;

uint32_t checksum;
};
2 changes: 2 additions & 0 deletions src/configs/webconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ std::string setGamepadOptions()
readDoc(gamepad->options.dpadMode, doc, "dpadMode");
readDoc(gamepad->options.inputMode, doc, "inputMode");
readDoc(gamepad->options.socdMode, doc, "socdMode");
readDoc(gamepad->options.switchTpShareForDs4, doc, "switchTpShareForDs4");

readDoc(gamepad->options.hotkeyF1Up.action, doc, "hotkeyF1", 0, "action");
readDoc(gamepad->options.hotkeyF1Down.action, doc, "hotkeyF1", 1, "action");
Expand All @@ -413,6 +414,7 @@ std::string getGamepadOptions()
writeDoc(doc, "dpadMode", options.dpadMode);
writeDoc(doc, "inputMode", options.inputMode);
writeDoc(doc, "socdMode", options.socdMode);
writeDoc(doc, "switchTpShareForDs4", options.switchTpShareForDs4);

writeDoc(doc, "hotkeyF1", 0, "action", options.hotkeyF1Up.action);
writeDoc(doc, "hotkeyF1", 0, "mask", options.hotkeyF1Up.dpadMask);
Expand Down
10 changes: 8 additions & 2 deletions src/gamepad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,18 @@ void Gamepad::setup()
mapButtonR1 = new GamepadButtonMapping(boardOptions.pinButtonR1, GAMEPAD_MASK_R1);
mapButtonL2 = new GamepadButtonMapping(boardOptions.pinButtonL2, GAMEPAD_MASK_L2);
mapButtonR2 = new GamepadButtonMapping(boardOptions.pinButtonR2, GAMEPAD_MASK_R2);
mapButtonS1 = new GamepadButtonMapping(boardOptions.pinButtonS1, GAMEPAD_MASK_S1);
mapButtonS2 = new GamepadButtonMapping(boardOptions.pinButtonS2, GAMEPAD_MASK_S2);
mapButtonL3 = new GamepadButtonMapping(boardOptions.pinButtonL3, GAMEPAD_MASK_L3);
mapButtonR3 = new GamepadButtonMapping(boardOptions.pinButtonR3, GAMEPAD_MASK_R3);
mapButtonA1 = new GamepadButtonMapping(boardOptions.pinButtonA1, GAMEPAD_MASK_A1);
mapButtonA2 = new GamepadButtonMapping(boardOptions.pinButtonA2, GAMEPAD_MASK_A2);

uint16_t maskS1 = options.inputMode == INPUT_MODE_PS4
&& options.switchTpShareForDs4 ? GAMEPAD_MASK_A2 : GAMEPAD_MASK_S1;
mapButtonS1 = new GamepadButtonMapping(boardOptions.pinButtonS1, maskS1);

uint16_t maskA2 = options.inputMode == INPUT_MODE_PS4
&& options.switchTpShareForDs4 ? GAMEPAD_MASK_S1 : GAMEPAD_MASK_A2;
mapButtonA2 = new GamepadButtonMapping(boardOptions.pinButtonA2, maskA2);

gamepadMappings = new GamepadButtonMapping *[GAMEPAD_DIGITAL_INPUT_COUNT]
{
Expand Down
1 change: 1 addition & 0 deletions www/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ app.get("/api/getGamepadOptions", (req, res) => {
dpadMode: 0,
inputMode: 1,
socdMode: 2,
switchTpShareForDs4: 0,
hotkeyF1: [
{ action: 1, mask: 1<<0 },
{ action: 2, mask: 1<<1 },
Expand Down
19 changes: 17 additions & 2 deletions www/src/Pages/SettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import Section from '../Components/Section';
import WebApi from '../Services/WebApi';
import BUTTONS from '../Data/Buttons.json';

const PS4Mode = 4;
const INPUT_MODES = [
{ label: 'XInput', value: 0 },
{ label: 'Nintendo Switch', value: 1 },
{ label: 'PS3/DirectInput', value: 2 },
{ label: 'Keyboard', value: 3 },
{ label: 'PS4', value: 4 }
{ label: 'PS4', value: PS4Mode }
];

const DPAD_MODES = [
Expand Down Expand Up @@ -65,6 +66,7 @@ const schema = yup.object().shape({
})),
inputMode: yup.number().required().oneOf(INPUT_MODES.map(o => o.value)).label('Input Mode'),
socdMode : yup.number().required().oneOf(SOCD_MODES.map(o => o.value)).label('SOCD Cleaning Mode'),
switchTpShareForDs4: yup.number().required().label('Switch Touchpad and Share'),
});

const FormContext = () => {
Expand All @@ -84,6 +86,8 @@ const FormContext = () => {
values.inputMode = parseInt(values.inputMode);
if (!!values.socdMode)
values.socdMode = parseInt(values.socdMode);
if (!!values.switchTpShareForDs4)
values.switchTpShareForDs4 = parseInt(values.switchTpShareForDs4);
values.hotkeyF1 = values.hotkeyF1?.map( i => ({
action: parseInt(i.action),
mask: parseInt(i.mask)
Expand Down Expand Up @@ -113,6 +117,7 @@ export default function SettingsPage() {
handleChange,
values,
errors,
setFieldValue
}) => console.log('errors', errors) || (
<div>
<Form noValidate onSubmit={handleSubmit}>
Expand All @@ -125,14 +130,24 @@ export default function SettingsPage() {
</Form.Select>
<Form.Control.Feedback type="invalid">{errors.inputMode}</Form.Control.Feedback>
</div>
<div className="col-sm-3">
{values.inputMode === PS4Mode && <Form.Check
label="Switch Touchpad and Share"
type="switch"
name="switchTpShareForDs4"
isInvalid={false}
checked={Boolean(values.switchTpShareForDs4)}
onChange={(e) => { setFieldValue("switchTpShareForDs4", e.target.checked ? 1 : 0); }}
/>}
</div>
</Form.Group>
<Form.Group className="row mb-3">
<Form.Label>D-Pad Mode</Form.Label>
<div className="col-sm-3">
<Form.Select name="dpadMode" className="form-select-sm" value={values.dpadMode} onChange={handleChange} isInvalid={errors.dpadMode}>
{DPAD_MODES.map((o, i) => <option key={`button-dpadMode-option-${i}`} value={o.value}>{o.label}</option>)}
</Form.Select>
<Form.Control.Feedback type="invalid">{errors.dpadMode}</Form.Control.Feedback>
<Form.Control.Feedback type="invalid">{errors.dpadMode}</Form.Control.Feedback>
</div>
</Form.Group>
<Form.Group className="row mb-3">
Expand Down