Jump to content
Sign in to follow this  
Guest Joao Muas

Simconnect toggle switch input

Recommended Posts

Guest Joao Muas

Hello all.I got an home built console based on a MJoy16 input card fully working with something like 70 button controls.These controls transmit button states via wired pushbuttons, toggles switches and rotary encoders.I've been using this console for quite sometime now, but only via the ingame keyboard mapping interface.I have to use some extra mapping software to get all controls to work as FS only accepts up to 32 (I wonder why they don't let use all the actual DirectX capabilities well beyond this number).So, we all know that there are plenty of switches on an aircraft panel which one can access via mouse clicks, as they were left out of the ingame key mapping interface.So I (finaly) decided to get into simconnect for the purpose of getting all controls I want at the flick of a switch on my console.I started with the sample scripts provided with the SDK, and I got it working as it should for the pushbuttons. Great.Now for the toggles and rotaries I got stuck with a problem.The MJoy16 card translates changes of toggle switch position into momentary joystick button presses, but I noticed each of these presses send 2 values of the event: 1 and 0. What happens when I flick the toggle to switch the beacon lights on, they actualy switch on and off imediatly after.Here the script I'm using://------------------------------------------------------------------------------//// SimConnect Joystick Control Sample// // Description:// button 17 of joystick 1 toggles the beacon lights////------------------------------------------------------------------------------#include #include #include #include #include "SimConnect.h"int quit = 0;HANDLE hSimConnect = NULL;static enum GROUP_ID { GROUP_0};static enum INPUT_ID { INPUT_0,};static enum EVENT_ID { EVENT_TOGGLE_BEACON_LIGHTS, };void CALLBACK MyDispatchProcJ(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext){ switch(pData->dwID) { case SIMCONNECT_RECV_ID_EVENT: { SIMCONNECT_RECV_EVENT *evt = (SIMCONNECT_RECV_EVENT*)pData; switch(evt->uEventID) { case EVENT_TOGGLE_BEACON_LIGHTS: printf("nEvent toggle beacon lights: %d", evt->dwData); break; default: break; } break; } case SIMCONNECT_RECV_ID_QUIT: { quit = 1; break; } default: break; }}void testInput(){ HRESULT hr; if (SUCCEEDED(SimConnect_Open(&hSimConnect, "Joystick Input", NULL, 0, 0, 0))) { printf("nConnected to Flight Simulator!"); hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_TOGGLE_BEACON_LIGHTS, "TOGGLE_BEACON_LIGHTS"); hr = SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP_0, EVENT_TOGGLE_BEACON_LIGHTS); hr = SimConnect_SetNotificationGroupPriority(hSimConnect, GROUP_0, SIMCONNECT_GROUP_PRIORITY_HIGHEST); hr = SimConnect_MapInputEventToClientEvent(hSimConnect, INPUT_0, "joystick:1:button:17", EVENT_TOGGLE_BEACON_LIGHTS); hr = SimConnect_SetInputGroupState(hSimConnect,INPUT_0, SIMCONNECT_STATE_ON); while( 0 == quit ) { SimConnect_CallDispatch(hSimConnect, MyDispatchProcJ, NULL); Sleep(1); } hr = SimConnect_Close(hSimConnect); }}int __cdecl _tmain(int argc, _TCHAR* argv[]){ testInput(); return 0;}//------------------------------------------------------------------------------I can read the following data event showing the values 1 and 0 each time I flick the switch:Connected to flight SImulator!Event toggle beacon lights: 1Event toggle beacon lights: 0It should show only 0 as I suppose.I'd appreciate someone could sort this out.Thanks in advance.

Share this post


Link to post
Share on other sites
Guest jahman

Any specific reason you're not using Pete Dawson's FSUIPC?Cheers,jahman.

Share this post


Link to post
Share on other sites
Guest Joao Muas

FSUIPC? What's that? I read that name somewhere else, looks like I'm missing something here?...I'm still new to FSX and I d'ont know nothing but the "official" stuff...I'll check that out though.

Share this post


Link to post
Share on other sites
Guest MikePowell

FSUIPC is not needed to interface with FSX. SimConnect provides the API.

Share this post


Link to post
Share on other sites
Guest jahman

No doubt!But perhaps with FSUIPC he can avoid spewing code? ;-)

Share this post


Link to post
Share on other sites

This is the simconnect forum.This is where people ask about simconnect and the simconnect API and simconnect code to get simconnect help.

Share this post


Link to post
Share on other sites
Guest jahman

Indeed, Brian, it is as you say.Nevertheless Joao Muas started out by saying "I have to use some extra mapping software to get all controls to work as FS only accepts up to 32".Since the Joao is writing his own code ("Here's the script I'm using"), I suspected he might not be aware (he wasn't) of the SimConnect utility "FSUIPC".So I recommended he look into FSUIPC as FSUIPC might let him control his hardware console without any programming on his part.Was I wrong in making this recommendation?Cheers,jahman.

Share this post


Link to post
Share on other sites

No, I mean FSUIPC is a great utility, that's a definite, but there's three reasons why I would want to rather help him figure out his issue (something I plan on doing when I get more than a few minutes free)- He asked for help on it- FSUIPC isn't going to be around forever, writing code that interacts directly with Simconnect ensures at least some level of forward compatibility with future versions - I think it's cool to figure out how to do something the hard wayThat was my whole point. But FSUIPC would probably make things easier on him.

Share this post


Link to post
Share on other sites
Guest jahman

Brian,Understood!BTW, I do hope FSUIPC stays around forever :-)Chers,jahman.

Share this post


Link to post
Share on other sites
Guest GregWoods

I realise I'm replying to an old post (again), but you originally mentioned your reason for going the SimConnect route was because the in game mapping was inadequate. Have you checked out all the options available simply by editing \[user profile]\AppData\Roaming\Microsoft\FSX\Controls\standard.xml ??You can input mappings not visible in the FSX UI. Also, all FSX mappings are stored here, but are only saved when you exit.For a full list of events, see the 'Event IDs' section of the SimConnect Help file. There are hundreds of them!Most events which are normally toggled events, such as STROBES_TOGGLE, can be substituted for 2 events, STROBES_ON and STROBES_OFF - which can be assigned to individual keys, or the two states of a toggle switch.My apologies if what you were asking isn't covered by this scenario, but it may save you a lot of programming effort.I started down this route, but as usual with me I end up wantngto do something not covered API, so now I'm going to have to start using DirectX (DirectInput) along with SimConnect, because in my design I want a push button (my rotary encoder push down click) to toggle between (as an example), the events COM2_RADIO_WHOLE_DEC / COM2_RADIO_WHOLE_INC and the events COM2_RADIO_FRACT_DEC / COM2_RADIO_FRACT_INC, so I can use one encoder to quickly tune both the MHz and the KHz portions of the frequency, rather than using 2 encoders per radio.Good luck with SimConnect - it's definately the future. I'm determined to nail it, and using Managed code if possible, too.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...