Skip to content

Commit

Permalink
Pulling main into my gpio pin config branch (#797)
Browse files Browse the repository at this point in the history
* use if-else block logic instead of switch in jslider debouncer (#793)

I'm not going to say we *understand* why this fixes #790, but it appears
to.

* Adds a "pin viewer" in pin mapping page (#794)

---------

Co-authored-by: Brian S. Stephan <[email protected]>
Co-authored-by: Pelsin <[email protected]>
  • Loading branch information
3 people authored Jan 14, 2024
1 parent 657e1a4 commit 3e67a02
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 41 deletions.
17 changes: 5 additions & 12 deletions src/addons/jslider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,14 @@ void JSliderInput::debounce()
}

uint32_t uNowTime = getMillis();

if ((uNowTime - uDebTime) > JSLIDER_DEBOUNCE_MILLIS) {
switch (dpadState ^ dDebState)
{
// Bounce Right Analog
case DPAD_MODE_RIGHT_ANALOG:
dDebState = (DpadMode)(dDebState ^ DPAD_MODE_RIGHT_ANALOG);

// Bounce Left Analog
case DPAD_MODE_LEFT_ANALOG:
dDebState = (DpadMode)(dDebState ^ DPAD_MODE_LEFT_ANALOG);
}
if ( (dpadState ^ dDebState) == DPAD_MODE_RIGHT_ANALOG )
dDebState = (DpadMode)(dDebState ^ DPAD_MODE_RIGHT_ANALOG); // Bounce Right Analog
else if ( (dpadState ^ dDebState) & DPAD_MODE_LEFT_ANALOG )
dDebState = (DpadMode)(dDebState ^ DPAD_MODE_LEFT_ANALOG); // Bounce Left Analog
uDebTime = uNowTime;
dpadState = dDebState;
}
dpadState = dDebState;
}

void JSliderInput::process()
Expand Down
12 changes: 10 additions & 2 deletions www/src/Components/CaptureButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import WebApi from '../Services/WebApi';

type CaptureButtonTypes = {
labels: string[];
onChange: (label: string, pin: string) => void;
onChange: (label: string, pin: number) => void;
small?: boolean;
buttonLabel?: string;
};

const CaptureButton = ({
labels,
onChange,
small = false,
buttonLabel,
}: CaptureButtonTypes) => {
const { t } = useTranslation('');
const controller = useRef<null | AbortController>(null);
Expand Down Expand Up @@ -102,7 +104,13 @@ const CaptureButton = ({
</Modal.Footer>
</Modal>
<Button variant="secondary" onClick={() => setTriggerCapture(true)}>
{small ? '🎮' : `${t('CaptureButton:capture-button-button-label')} 🎮`}
{small
? '🎮'
: `${
buttonLabel
? buttonLabel
: t('CaptureButton:capture-button-button-label')
} 🎮`}
</Button>
</>
);
Expand Down
2 changes: 1 addition & 1 deletion www/src/Locales/de-DE/PinMapping.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export default {
'sub-header-text':
'Verwenden Sie das Formular unten, um Ihre Tasten-zu-Pin-Zuordnung neu zu konfigurieren.',
'alert-text':
"Die Zuordnung von Tasten zu Pins, die nicht verbunden oder verfügbar sind, kann das Gerät in einen nicht funktionsfähigen Zustand versetzen. Um die ungültige Konfiguration zu löschen, gehen Sie zur Seite <1>Einstellungen zurücksetzen</1>.",
'Die Zuordnung von Tasten zu Pins, die nicht verbunden oder verfügbar sind, kann das Gerät in einen nicht funktionsfähigen Zustand versetzen. Um die ungültige Konfiguration zu löschen, gehen Sie zur Seite <2>Einstellungen zurücksetzen</2>.',
'pin-header-label': 'Pin',
errors: {
conflict: 'Pin {{pin}} ist bereits zugewiesen zu {{conflictedMappings}}',
Expand Down
7 changes: 4 additions & 3 deletions www/src/Locales/en/PinMapping.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
export default {
'header-text': 'Pin Mapping',
'sub-header-text':
'Use the form below to reconfigure your button-to-pin mapping.',
'sub-header-text': `Here you can configure what pin has what action. If you're unsure what button is connect to what pin, try out the pin viewer.`,
'alert-text':
"Mapping buttons to pins that aren't connected or available can leave the device in non-functional state. To clear the invalid configuration go to the <1>Reset Settings</1> page.",
"Mapping buttons to pins that aren't connected or available can leave the device in non-functional state. To clear the invalid configuration go to the <2>Reset Settings</2> page.",
'pin-viewer': 'Pin viewer',
'pin-pressed': 'Pressed pin: {{pressedPin}}',
'pin-header-label': 'Pin',
'profile-pins-warning':
'Try to avoid changing the buttons and/or directions used for the switch profile hotkeys. Otherwise, it will be difficult to understand what profile is being selected!',
Expand Down
2 changes: 1 addition & 1 deletion www/src/Locales/pt-BR/PinMapping.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export default {
'sub-header-text':
'Utilize o formulário abaixo para reconfigurar o mapeamento de botões para pinos.',
'alert-text':
'Associar botões a pinos que não estão conectados ou disponíveis pode deixar o dispositivo em um estado não funcional. Para limpar a configuração inválida, vá para a página <1>Redefinir Configurações</1>.',
'Associar botões a pinos que não estão conectados ou disponíveis pode deixar o dispositivo em um estado não funcional. Para limpar a configuração inválida, vá para a página <2>Redefinir Configurações</2>.',
'pin-header-label': 'Pino',
'profile-pins-warning':
'Tente evitar alterar os botões/direções usados para seus atalhos de perfil de troca, caso contrário, ficará difícil entender qual perfil você está selecionando!',
Expand Down
61 changes: 39 additions & 22 deletions www/src/Pages/PinMapping.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ export default function PinMappingPage() {
const { fetchProfiles, profiles, saveProfiles, setProfileAction } =
useProfilesStore();

const [pressedPin, setPressedPin] = useState<number | null>(null);

const { t } = useTranslation('');

useEffect(() => {
Expand All @@ -164,8 +166,7 @@ export default function PinMappingPage() {
}, [savePins, saveProfiles]);

return (
<Section title={t('PinMapping:header-text')}>
<p>{t('PinMapping:sub-header-text')}</p>
<>
<div className="alert alert-warning">
<Trans ns="PinMapping" i18nKey="alert-text">
Mapping buttons to pins that aren&apos;t connected or available can
Expand All @@ -177,30 +178,46 @@ export default function PinMappingPage() {
<br />
{t(`PinMapping:profile-pins-warning`)}
</div>
<Tabs id="profiles">
<Tab eventKey="Base" title="Base(Profile 1)">
<PinsForm
pins={pins}
savePins={saveAll}
setPinAction={setPinAction}
<Section title={t('PinMapping:header-text')}>
<p>{t('PinMapping:sub-header-text')}</p>
<div className="mb-3">
<CaptureButton
buttonLabel={t('PinMapping:pin-viewer')}
labels={['']}
onChange={(_, pin) => setPressedPin(pin)}
/>
</Tab>
{profiles.map((profilePins, profileIndex) => (
<Tab
key={`Profile${profileIndex + 2}`}
eventKey={`Profile${profileIndex + 2}`}
title={`Profile ${profileIndex + 2}`}
>
</div>
{pressedPin !== null && (
<div className="alert alert-info">
<strong>{t('PinMapping:pin-pressed', { pressedPin })}</strong>
</div>
)}

<Tabs id="profiles">
<Tab eventKey="Base" title="Base(Profile 1)">
<PinsForm
pins={profilePins}
pins={pins}
savePins={saveAll}
setPinAction={(pin, action) => {
setProfileAction(profileIndex, pin, action);
}}
setPinAction={setPinAction}
/>
</Tab>
))}
</Tabs>
</Section>
{profiles.map((profilePins, profileIndex) => (
<Tab
key={`Profile${profileIndex + 2}`}
eventKey={`Profile${profileIndex + 2}`}
title={`Profile ${profileIndex + 2}`}
>
<PinsForm
pins={profilePins}
savePins={saveAll}
setPinAction={(pin, action) => {
setProfileAction(profileIndex, pin, action);
}}
/>
</Tab>
))}
</Tabs>
</Section>
</>
);
}

0 comments on commit 3e67a02

Please sign in to comment.