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

Extract addons #489

Merged
merged 35 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
219bc10
Tiny first step at restructuring addons in web
Pelsin Aug 27, 2023
ab51192
Update AddonsConfigPage.jsx
Pelsin Aug 27, 2023
9f9169d
Remove unused props resulting in "undefined" as class names in html
Pelsin Sep 1, 2023
61945a4
Merge branch 'web-bootsel-onBoardLed' of github.com:Pelsin/GP2040-CE …
Pelsin Sep 1, 2023
a1e957c
Add missing values when using dev server
Pelsin Sep 1, 2023
76c38e0
Change section to title
Pelsin Sep 1, 2023
f501208
Make FormControl check types and remove unused props
Pelsin Sep 1, 2023
4ab38a8
Separate analog addon from page
Pelsin Sep 1, 2023
7ee2ff0
Extract turbo addon and remove button mask duplicate
Pelsin Sep 1, 2023
d8ac5a0
Fix warning for key
Pelsin Sep 1, 2023
08183de
Move DUAL_STICK_MODE const
Pelsin Sep 1, 2023
d470478
Extract joystick slider addon
Pelsin Sep 1, 2023
d3019c0
Extract reverse addon
Pelsin Sep 1, 2023
dcf901a
Extract I2C Analog ADS1219 addon and simply addon rendering
Pelsin Sep 1, 2023
5230f36
Extract dual direction addon
Pelsin Sep 1, 2023
d859ee0
Extract tilt addon
Pelsin Sep 1, 2023
d7699a8
Move missing tilt state to addon
Pelsin Sep 1, 2023
47ef7bf
Extract buzzer addon
Pelsin Sep 1, 2023
bcc2c77
Extract extra button addon
Pelsin Sep 1, 2023
33e1be0
Extract player number addon
Pelsin Sep 1, 2023
5b5bf81
Change some styling to warning text in player number addon
Pelsin Sep 1, 2023
ef4a5cd
Extract socd addon
Pelsin Sep 1, 2023
b06009e
Merge branch 'main' into web-bootsel-onBoardLed
Pelsin Sep 1, 2023
d670cdf
Extract ps4 addon
Pelsin Sep 1, 2023
c98234f
Extract psPassthrough addon
Pelsin Sep 1, 2023
533b5ec
Correcting typo in initial state for extra button
Pelsin Sep 1, 2023
c2113f1
Extract wii addon
Pelsin Sep 1, 2023
360bda2
Remove unused prop
Pelsin Sep 1, 2023
be7fb42
Extract snes addon
Pelsin Sep 1, 2023
769b2e7
Extract focus mode addon
Pelsin Sep 1, 2023
1bbae46
Extract keyboard addon
Pelsin Sep 1, 2023
f754ce6
Fix import for onBoardLed addon
Pelsin Sep 1, 2023
204aa8b
Change filename of snes
Pelsin Sep 1, 2023
a0a9e57
Fix mapping of D-Pad masks
deeebug Sep 2, 2023
bbe2c1b
Merge pull request #1 from deeebug/extract-addons-fixes
Pelsin Sep 2, 2023
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
30 changes: 14 additions & 16 deletions src/addons/bootsel_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,20 @@ void BootselButtonAddon::setup() {
void BootselButtonAddon::preprocess() {
Gamepad * gamepad = Storage::getInstance().GetGamepad();
if (isBootselPressed()) {
if (bootselButtonMap > (GAMEPAD_MASK_A2)) {
switch (bootselButtonMap) {
case (1U << 14):
gamepad->state.dpad |= GAMEPAD_MASK_UP;
break;
case (1U << 15):
gamepad->state.dpad |= GAMEPAD_MASK_DOWN;
break;
case (1U << 16):
gamepad->state.dpad |= GAMEPAD_MASK_LEFT;
break;
case (1U << 17):
gamepad->state.dpad |= GAMEPAD_MASK_RIGHT;
break;
}
switch (bootselButtonMap) {
case (GAMEPAD_MASK_DU):
gamepad->state.dpad |= GAMEPAD_MASK_UP;
break;
case (GAMEPAD_MASK_DD):
gamepad->state.dpad |= GAMEPAD_MASK_DOWN;
break;
case (GAMEPAD_MASK_DL):
gamepad->state.dpad |= GAMEPAD_MASK_LEFT;
break;
case (GAMEPAD_MASK_DR):
gamepad->state.dpad |= GAMEPAD_MASK_RIGHT;
break;
default: gamepad->state.buttons |= bootselButtonMap;
}
else gamepad->state.buttons |= bootselButtonMap;
}
}
30 changes: 14 additions & 16 deletions src/addons/extra_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,20 @@ void ExtraButtonAddon::setup() {
void ExtraButtonAddon::preprocess() {
Gamepad * gamepad = Storage::getInstance().GetGamepad();
if (!gpio_get(extraButtonPin)) {
if (extraButtonMap > (GAMEPAD_MASK_A2)) {
switch (extraButtonMap) {
case (GAMEPAD_MASK_DU):
gamepad->state.dpad |= GAMEPAD_MASK_UP;
break;
case (GAMEPAD_MASK_DD):
gamepad->state.dpad |= GAMEPAD_MASK_DOWN;
break;
case (GAMEPAD_MASK_DL):
gamepad->state.dpad |= GAMEPAD_MASK_LEFT;
break;
case (GAMEPAD_MASK_DR):
gamepad->state.dpad |= GAMEPAD_MASK_RIGHT;
break;
}
switch (extraButtonMap) {
case (GAMEPAD_MASK_DU):
gamepad->state.dpad |= GAMEPAD_MASK_UP;
break;
case (GAMEPAD_MASK_DD):
gamepad->state.dpad |= GAMEPAD_MASK_DOWN;
break;
case (GAMEPAD_MASK_DL):
gamepad->state.dpad |= GAMEPAD_MASK_LEFT;
break;
case (GAMEPAD_MASK_DR):
gamepad->state.dpad |= GAMEPAD_MASK_RIGHT;
break;
default: gamepad->state.buttons |= extraButtonMap;
}
else gamepad->state.buttons |= extraButtonMap;
}
}
2 changes: 2 additions & 0 deletions www/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ app.get('/api/getAddonsOptions', (req, res) => {
AnalogInputEnabled: 1,
BoardLedAddonEnabled: 1,
FocusModeAddonEnabled: 1,
focusModeOledLockEnabled: 0,
focusModeRgbLockEnabled: 0,
BuzzerSpeakerAddonEnabled: 1,
BootselButtonAddonEnabled: 1,
DualDirectionalInputEnabled: 1,
Expand Down
282 changes: 282 additions & 0 deletions www/src/Addons/Analog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
import React, { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { FormCheck, Row } from 'react-bootstrap';
import * as yup from 'yup';

import Section from '../Components/Section';
import FormSelect from '../Components/FormSelect';
import { ANALOG_PINS } from '../Data/Buttons';
import AnalogPinOptions from '../Components/AnalogPinOptions';
import { AppContext } from '../Contexts/AppContext';
import FormControl from '../Components/FormControl';

const ANALOG_STICK_MODES = [
{ label: 'Left Analog', value: 1 },
{ label: 'Right Analog', value: 2 },
];

const INVERT_MODES = [
{ label: 'None', value: 0 },
{ label: 'X Axis', value: 1 },
{ label: 'Y Axis', value: 2 },
{ label: 'X/Y Axis', value: 3 },
];

export const analogScheme = {
AnalogInputEnabled: yup.number().required().label('Analog Input Enabled'),
analogAdc1PinX: yup
.number()
.label('Analog Stick 1 Pin X')
.validatePinWhenValue('AnalogInputEnabled'),
analogAdc1PinY: yup
.number()
.label('Analog Stick 1 Pin Y')
.validatePinWhenValue('AnalogInputEnabled'),
analogAdc1Mode: yup
.number()
.label('Analog Stick 1 Mode')
.validateSelectionWhenValue('AnalogInputEnabled', ANALOG_STICK_MODES),
analogAdc1Invert: yup
.number()
.label('Analog Stick 1 Invert')
.validateSelectionWhenValue('AnalogInputEnabled', INVERT_MODES),
analogAdc2PinX: yup
.number()
.label('Analog Stick 2 Pin X')
.validatePinWhenValue('AnalogInputEnabled'),
analogAdc2PinY: yup
.number()
.label('Analog Stick 2 Pin Y')
.validatePinWhenValue('AnalogInputEnabled'),
analogAdc2Mode: yup
.number()
.label('Analog Stick 2 Mode')
.validateSelectionWhenValue('AnalogInputEnabled', ANALOG_STICK_MODES),
analogAdc2Invert: yup
.number()
.label('Analog Stick 2 Invert')
.validateSelectionWhenValue('AnalogInputEnabled', INVERT_MODES),

forced_circularity: yup
.number()
.label('Force Circularity')
.validateRangeWhenValue('AnalogInputEnabled', 0, 1),
analog_deadzone: yup
.number()
.label('Deadzone Size (%)')
.validateRangeWhenValue('AnalogInputEnabled', 0, 100),
auto_calibrate: yup
.number()
.label('Auto Calibration')
.validateRangeWhenValue('AnalogInputEnabled', 0, 1),
};

export const analogState = {
AnalogInputEnabled: 0,
analogAdc1PinX: -1,
analogAdc1PinY: -1,
analogAdc1Mode: 1,
analogAdc1Invert: 0,
analogAdc2PinX: -1,
analogAdc2PinY: -1,
analogAdc2Mode: 2,
analogAdc2Invert: 0,
forced_circularity: 0,
analog_deadzone: 5,
auto_calibrate: 0,
};

const Analog = ({ values, errors, handleChange, handleCheckbox }) => {
const { usedPins } = useContext(AppContext);
const { t } = useTranslation();
const availableAnalogPins = ANALOG_PINS.filter(
(pin) => !usedPins?.includes(pin),
);
return (
<Section title={t('AddonsConfig:analog-header-text')}>
<div id="AnalogInputOptions" hidden={!values.AnalogInputEnabled}>
<p>{t('AddonsConfig:analog-warning')}</p>
<p>
{t('AddonsConfig:analog-available-pins-text', {
pins: availableAnalogPins.join(', '),
})}
</p>
<Row className="mb-3">
<FormSelect
label={t('AddonsConfig:analog-adc-1-pin-x-label')}
name="analogAdc1PinX"
className="form-select-sm"
groupClassName="col-sm-3 mb-3"
value={values.analogAdc1PinX}
error={errors.analogAdc1PinX}
isInvalid={errors.analogAdc1PinX}
onChange={handleChange}
>
<AnalogPinOptions />
</FormSelect>
<FormSelect
label={t('AddonsConfig:analog-adc-1-pin-y-label')}
name="analogAdc1PinY"
className="form-select-sm"
groupClassName="col-sm-3 mb-3"
value={values.analogAdc1PinY}
error={errors.analogAdc1PinY}
isInvalid={errors.analogAdc1PinY}
onChange={handleChange}
>
<AnalogPinOptions />
</FormSelect>
<FormSelect
label={t('AddonsConfig:analog-adc-1-mode-label')}
name="analogAdc1Mode"
className="form-select-sm"
groupClassName="col-sm-3 mb-3"
value={values.analogAdc1Mode}
error={errors.analogAdc1Mode}
isInvalid={errors.analogAdc1Mode}
onChange={handleChange}
>
{ANALOG_STICK_MODES.map((o, i) => (
<option key={`button-analogAdc1Mode-option-${i}`} value={o.value}>
{o.label}
</option>
))}
</FormSelect>
<FormSelect
label={t('AddonsConfig:analog-adc-1-invert-label')}
name="analogAdc1Invert"
className="form-select-sm"
groupClassName="col-sm-3 mb-3"
value={values.analogAdc1Invert}
error={errors.analogAdc1Invert}
isInvalid={errors.analogAdc1Invert}
onChange={handleChange}
>
{INVERT_MODES.map((o, i) => (
<option
key={`button-analogAdc1Invert-option-${i}`}
value={o.value}
>
{o.label}
</option>
))}
</FormSelect>
</Row>
<Row className="mb-3">
<FormSelect
label={t('AddonsConfig:analog-adc-2-pin-x-label')}
name="analogAdc2PinX"
className="form-select-sm"
groupClassName="col-sm-3 mb-3"
value={values.analogAdc2PinX}
error={errors.analogAdc2PinX}
isInvalid={errors.analogAdc2PinX}
onChange={handleChange}
>
<AnalogPinOptions />
</FormSelect>
<FormSelect
label={t('AddonsConfig:analog-adc-2-pin-y-label')}
name="analogAdc2PinY"
className="form-select-sm"
groupClassName="col-sm-3 mb-3"
value={values.analogAdc2PinY}
error={errors.analogAdc2PinY}
isInvalid={errors.analogAdc2PinY}
onChange={handleChange}
>
<AnalogPinOptions />
</FormSelect>
<FormSelect
label={t('AddonsConfig:analog-adc-2-mode-label')}
name="analogAdc2Mode"
className="form-select-sm"
groupClassName="col-sm-3 mb-3"
value={values.analogAdc2Mode}
error={errors.analogAdc2Mode}
isInvalid={errors.analogAdc2Mode}
onChange={handleChange}
>
{ANALOG_STICK_MODES.map((o, i) => (
<option key={`button-analogAdc2Mode-option-${i}`} value={o.value}>
{o.label}
</option>
))}
</FormSelect>
<FormSelect
label={t('AddonsConfig:analog-adc-2-invert-label')}
name="analogAdc2Invert"
className="form-select-sm"
groupClassName="col-sm-3 mb-3"
value={values.analogAdc2Invert}
error={errors.analogAdc2Invert}
isInvalid={errors.analogAdc2Invert}
onChange={handleChange}
>
{INVERT_MODES.map((o, i) => (
<option
key={`button-analogAdc2Invert-option-${i}`}
value={o.value}
>
{o.label}
</option>
))}
</FormSelect>
</Row>
<Row className="mb-3">
<FormControl
type="number"
label={t('AddonsConfig:analog-deadzone-size')}
name="analog_deadzone"
className="form-control-sm"
groupClassName="col-sm-3 mb-3"
value={values.analog_deadzone}
error={errors.analog_deadzone}
isInvalid={errors.analog_deadzone}
onChange={handleChange}
min={0}
max={100}
/>
<FormCheck
label={t('AddonsConfig:analog-force-circularity')}
type="switch"
id="Forced_circularity"
className="col-sm-3 ms-2"
isInvalid={false}
checked={Boolean(values.forced_circularity)}
onChange={(e) => {
handleCheckbox('forced_circularity', values);
handleChange(e);
}}
/>
<FormCheck
label={t('AddonsConfig:analog-auto-calibrate')}
type="switch"
id="Auto_calibrate"
className="col-sm-3 ms-2"
isInvalid={false}
checked={Boolean(values.auto_calibrate)}
onChange={(e) => {
handleCheckbox('auto_calibrate', values);
handleChange(e);
}}
/>
</Row>
</div>
<FormCheck
label={t('Common:switch-enabled')}
type="switch"
id="AnalogInputButton"
reverse
isInvalid={false}
checked={Boolean(values.AnalogInputEnabled)}
onChange={(e) => {
handleCheckbox('AnalogInputEnabled', values);
handleChange(e);
}}
/>
</Section>
);
};

export default Analog;
Loading