WhiteMagic / JoystickGremlin

A tool for configuring and managing joystick devices.
http://whitemagic.github.io/JoystickGremlin/
GNU General Public License v3.0
313 stars 45 forks source link

Question concerning vjoy initialization of buttons #469

Open IstiCusi opened 1 year ago

IstiCusi commented 1 year ago

Dear devs,

this evening i tried your great tool mapping a three-state switch from my throttle (where the middle state is not mapped to a Button) programmatically using your plugin feature to three corresponding vjoy buttons. All works fine. The only problem is, that I cannot initialize the truth values of the three vjoy buttons in an init() function. That means, that in case I have not moved the three state switch on my throttle, I get all three vjoy buttons in unpressed state.

I think that I miss an updating function call, so that the state is taken in consideration by vjoy. Is there a way to achieve this ? In case you need my file for cross-checking, I can send to you.

Thank you very much for your hints and help,

Stephan

WhiteMagic commented 1 year ago

There is no support for initialization functions, partly due to the black magic that makes the user plugins work and partly because plugins are still bound to the reactive paradigm of Gremlin. There is no way to reliably know the state of a button before an event changes its state. Attempting to read out button state information during initialization is therefore not well defined as depending on what has been done before that information may or may not exist. Essentially, initialization code wanting to access physical joystick state information is invalid as it is guaranteed to fail eventually.

IstiCusi commented 1 year ago

Thank you very much, dear mate. Concerning the truth table I am not so sure, because the mapping of truth values of the joystick to the truth values of virtual device is unique, so there should be no ambiguity. Meaning when for a three state switch, one of the states is not represented by a value, than you can conduct, that this state is C = (not A) and (not B). This should be sufficient for all times as long you allow to evaluate the joysticks values once and at the same time get the mapping to vjoy: C' = C ; B' = B ; A' = A where the primed are three buttons in the vjoy button state. Maybe I can help you to get this fixed. I looked into your code -- the dll interface is very clean. Nice work. You mentioned there, that the boolean state is in one case int. Old C had no boolean ... probably the reason, just int ... So what we would need is an layer between the physical devices and the virtual one, that sets consistent to the physical states based on a rule virtual states of vjoy without having a joystick event (change of button state). Shall we try this together. I think, that this is nice useful project and your software is already better than most commercial products. Cheers and have a good day! Stephan

WhiteMagic commented 1 year ago

The main issue is that DirectInput is an event-driven system, i.e. querying a joystick for state information is not supported. The API permits it for certain devices, but that only acts as a buffer and doesn't actually query the true device. I'm not sure what kind of layer you're talking about, as the connections between physical and virtual devices are created as described by the user, and there is no automated mapping or synchronization, as that would defeat its purpose of it.

Having a tri-state switch work should be possible via either a plugin or probably through a combination of macros and conditions. However, initializing it correctly will always be impossible, as the true value of the physical buttons cannot be queried.

IstiCusi commented 1 year ago

I am not a Windows expert but a linux guy: When i go to the windows joystick properties I see always the state of the physical input device. This seems not to be obtained by a event-driven process. I found this article here:

Raw Input

This Raw Input API we could use -- this does not effect the vjoy part. Do I miss there something? Somehow the windows internal tools know nothing about an undefined state, but always know the real button state (on or off).

If you point me to your joystick reading interface, we could try to do some experiments. But maybe I still miss something, you know Windows better.

I wish you a good weekend -- in case I convinced you, that this could be done, I am happy to help you getting this done. Would be really great.

WhiteMagic commented 1 year ago

I've played around with it some, it can at times see the full device state but appears to require some trigger, i.e. some other input after the program has been started. I don't know if Windows has some magic internal buffer or if it does some odd form of polling. In any case obtaining that information through a sort of polling would become the realm of the input library used in Gremlin and not so much Gremlin's issue itself.