12pos absolute switch to rotary encoder via software?
I'm trying to figure out whether this can be done entirely within SimHub using its scripting/formula capabilities.
My controller is an STM32 running FreeJoy. I have multiple 12-position rotary switches connected to it. It behaves as an absolute switch: each position corresponds to a separate joystick button, and the button for the current position stays permanently pressed.
So essentially:
- Position 1 = Button 1 held
- Position 2 = Button 2 held
- ...
- Position 12 = Button 12 held
I'd like SimHub to treat this as if it were a normal incremental rotary encoder.
For example:
- 4 → 5 = CW
- 5 → 6 = CW
- 5 → 8 = 3 x CW
- 5 → 4 = CCW
- 1 → 12 = CCW
- 12 → 1 = CW
Since the current position is always held, SimHub could also determine the initial position when it starts without generating an input. It would then only need to remember the previous position and compare it against the new one whenever the switch moves.
Ideally I'd like to end up with two SimHub events/actions, CW and CCW per rotary switch, which I can map like the outputs of a normal encoder.
I specifically want to solve this inside SimHub. I don't want to modify the FreeJoy firmware or move all devices to a new microcontroller, because on Arduino i solved this already.
From what I've seen in the past, i would not be surprised if there is a way to create these 2 new virtual inputs based on that logic.
Has anyone done something similar, or is there a good way to create these CW/CCW events per a defined set of 12 inputs? I can work with JavaScript and have the feeling i am just one nudge away from knowing where t start.
Thank you for anything that leads me in the right direction!