Jump to content


* * * * * 1 votes

Can't catch custom events from c code


  • Please log in to reply
1 reply to this topic

#1 madevgeny

madevgeny

    Passenger

  • New Members
  • Pip
  • 1 posts

Posted 07 November 2010 - 01:54 PM

Hi, I can't get custom events from 3d cockpit to my c++ code.

I do the following steps:

1) In the modeldef.xml set <EventID>0x11001</EventID> for corresponding element.

2) in c code:
void FSAPI module_init(void)
{
register_key_event_handler((GAUGE_KEY_EVENT_HANDLE R)ClockButtonsHandler, NULL);
}

void FSAPI ClockButtonsHandler(ID32 event, UINT32 evdata, PVOID userdata)
{
// some code
}

And nothing happen, but when I set standard event id e.g. TOGGLE_ELECT_FUEL_PUMP1, ClockButtonsHandler is called with proper event parameter.

In sdk example for custom event there are strange lines (marked with *):

void FSAPI module_init(void)
{
* if (NULL != Panels)
* {
* ImportTable.PANELSentry.fnptr = (PPANELS)Panels;
* PanelCallbackInit();
* }
register_key_event_handler((GAUGE_KEY_EVENT_HANDLE R)EventHandler, NULL);
}

As I could understand it's some initialization of panel callback, but I don't know how to do it in my code and how to create variable Panels.

#2 n4gix

n4gix

    Student Pilot

  • Members
  • PipPip
  • 71 posts

Posted 12 November 2011 - 02:00 PM

I know this is a very old (and unanswered!) post, but just in case someone else is looking for the answers to this fellow's questions:

First, you need to register and unregister the event_handler. The SDK method requires modifying your gauges.h file to allow for the module_init and module_deinit functions to work.

An easier way is to simply add those calls to the PANEL_SERVICE callbaks like this:

In the PANEL_SERVICE_PRE_UPDATE gauge callback you have to do the following:

if (init_event_hook == false)
		{
			// 'hook' our custom event handler in
			register_key_event_handler((GAUGE_KEY_EVENT_HANDLER)CustomEventHandler,NULL);
			init_event_hook = true;
		 }
In the PANEL_SERVICE_DISCONNECT gauge callback you have to do the following:

if (init_event_hook==true)
	 {
		  unregister_key_event_handler((GAUGE_KEY_EVENT_HANDLER)CustomEventHandler,NULL);
		  init_event_hook = false;
}

To "catch" the custom ID events, add this to the PANEL_SERVICE_UPDATE callback:
void CALLBACK CustomEventHandler(ID32 eventID, UINT32 evdata, PVOID
userdata)
{
	Switch (eventID)
	{
				   case 0x11001;
						{
							// insert what you want to happen here
							break;
						 }
				   case 0x18162:
						{
							// insert what you want to happen here
							break;
						 }
	}
}