Extra Powers for Switch Sockets

Great to see this forum. Hope it’s a success and people find lots of useful information here eventually.

My side, I have another request for help please for more disabled users, including those using just one or two switches to interact with a game. Could you help me with code / solutions for the following, please?

A. One Switch Look Left/Right = Right-stick LEFT / Right-stick RIGHT alternating (with an option in the code to adjust the strength of the Left/Right movement from 15%-100%).

B. Walk forwards (momentary) = Left-stick UP with a way to adjust the strength from 15%-100%.

C. Accelerate (with speed limiter) = RT with a way to adjust the strength from 15%-100% (sorry I’ve forgotten how to do that)… Would be good to be able to restrict RT from a gamepad too.

Would be lovely to have a latched version of B and C too.

Any help appreciated.

Depending on how you want the percentages to be adjustable, “B” and “C” are fairly straightforward, you just set the output on a mapping to, say, Left stick Y, and you use the scaling parameter to control how much the stick (or trigger) is actuated.

For sticks: 0=up/left, 128=neutral, 255=down/right.

For triggers: 0=not pressed, 255=fully pressed.

To make them latching, just set the sticky flag on the relevant mappings.

“A” could be done using layers, with the GPIO pin mapped to Right stick X with scaling=0 on one layer and with scaling=255 on another layer, and also separately mapped to activate the layer with the sticky flag set.

If you go this road, just make sure all the other mappings are present on both layers as pressing the left/right switch will toggle between the layers.

The entire configuration could look something like this:

The right trigger is both a button and an axis on a PlayStation controller so we map to both, with the percentage controlled by the scaling parameter on the “R2 axis” mapping.

hid-remapper-switches.json (3.0 KB)

1 Like

Brilliant. Thank you!

I have a problem with trying to set GPIO 20 as “sticky”. This would be so a player could tap their switch, and make a player walk forwards until the switch is tapped again.

I’m finding that GPIO 19 (look left/right alternatively) is causing problems with the WALK switch. Sometimes it won’t unlatch/latch.

Ah, you’re right, it doesn’t unlatch when we’re on a different layer than when it latched. :frowning:

I was hoping to avoid this, but you can do it without layers, using an expression.

/* if GPIO 19 just pressed */
0xfff40013 input_state_binary
0xfff40013 prev_input_state_binary not mul 
/* flip the direction */
2 recall not
2 recall
ifte
dup 2 store

/* left or right */
-128 127 ifte
0xfff40013 input_state_binary
mul
128 add
1 store

hid-remapper-switches2.json (2.6 KB)

1 Like

Nice one. Thanks Jacek. I found I had to place that code in the first expression. If i used it after a couple of other expressions I had (even though they weren’t storing in register 1 and 2) it wasn’t working.

Cheers again. Brilliant stuff.