Jump to content
Sign in to follow this  
Guest Patrick_Waugh

Getting the infamous 5th parameter

Recommended Posts

Guest Patrick_Waugh

I am attempting to get the infamous 5th parameter from a gauge line in the panel.cfg, for example: gauge00=B206!Button: Starter,48,66,39,,0x49The "0x49" represents hex 0x49 (the key value of the NUM PAD 9 key in this case for test purposes).I have tried this:// Relevant variables BYTE assignedKey = DIK_STARTER; // Default keystatic bool isStarterPushed; PCHAR pParams = NULL; // Here for testing PCHAR pStr = NULL;static void GetUserDefinedKey( PGAUGEHDR pgauge ){ if( NULL == pgauge ) return; // Pointer not valid pParams = pgauge->parameters; if( (pParams == NULL) || (strlen( pParams ) == 0) ) return; // Parameter not used, use default // Process 0x parameter if ( (pStr = strstr( pParams, "0x" )) != NULL ) { // Found, this is a hex parameter if( sscanf( pStr + 2, "%x", &assignedKey ) == EOF ) { // Error } }}static void CALLBACK Gauge_gcb(PGAUGEHDR pgauge, SINT32 service_id, UINT32 extra_data){ switch (service_id) { //case PANEL_SERVICE_PRE_INSTALL: // Tried both case PANEL_SERVICE_PRE_INITIALIZE: GetUserDefinedKey( pgauge ); break; }}The "default" keypress (0x4A) works fine, but is never overwritten with the new one (0x49), although I have tested that the code does indeed extract the 0x49 correctly (in a separate test program).Yet, when I use a dynamic tooltip to "peek" at the value of assignKey and the pParams, I see the 0x4A value and no parameter string.Anyone point me to the error of my ways (relative to the code anyways) :D

Share this post


Link to post
Share on other sites

Unfortunately I do not have time to check your code at the moment but have you checked sd2gau18.zip from the library? The sample code in there used to work for me, if that is of any help.Cheers, :-beerchugEtienne :-wave

Share this post


Link to post
Share on other sites
Guest Patrick_Waugh

Here is the code in a more readable format... also trying one something suggested by Father Bill.Still no joy.#define GAUGE_NAME "Button: Starter"#define GAUGE_W 41#define DIK_STARTER DIK_SUBTRACT#define BMP_STATIC BMP_BTN_STARTER_OUT#define REF_HELPID HELP_NONE#include #include "Audio.h"#include "DirectInput.h"#include "Bus.h"#include "Resources.h"#include "Btn.Starter.h" char C_GAUGE(gauge_name_)[] = GAUGE_NAME; MODULE_VAR starter = { MODULE_VAR_STARTER }; BYTE assignedKey = DIK_STARTER; // Default key press assignmentstatic bool isStarterPushed;static bool params_read = false;PCHAR pParams = NULL; // Here for testing onlyPCHAR pStr = NULL;static void GetUserDefinedKey( PGAUGEHDR pgauge ){ if( NULL == pgauge ) return; // Pointer not valid if( (pgauge->parameters == NULL) || (strlen( pgauge->parameters ) == 0) ) return; // Parameter not used, use default pParams = pgauge->parameters; // Process 0x parameter if ( (pStr = strstr( pParams, "0x" )) != NULL ) { // Found, this is a hex parameter if( sscanf( pStr + 2, "%x", &assignedKey ) == EOF ) { // Error } }}static void CALLBACK Gauge_gcb(PGAUGEHDR pgauge, SINT32 service_id, UINT32 extra_data){ switch (service_id) { case PANEL_SERVICE_PRE_INSTALL : if (pgauge->parameters && ( params_read == false ) ) { if ( strlen(pgauge->parameters) > 0 ) { GetUserDefinedKey( pgauge ); // 5th parameter in aircraft.cfg params_read = 1; } else if ( strlen(pgauge->parameters) == 0 ) { params_read = 1; } } break; }}static FLOAT64 CALLBACK StarterSwitch_icon_cb(PELEMENT_ICON pelement){ if ( KEYDOWN( diks, assignedKey )) { // Start button pushed isStarterPushed = true; trigger_key_event(KEY_MIXTURE1_SET, 4); } else { // Starter not pushed isStarterPushed = false; trigger_key_event(KEY_MIXTURE1_SET, 0); } return isStarterPushed;}If anyone has any idea how to make this work in FSX, ideas are welcome.

Share this post


Link to post
Share on other sites

I went with this:case PANEL_SERVICE_PRE_UPDATE: if ( pgauge && pgauge->parameters && params_found == 0 ) { pParams = pgauge->parameters; //only used for displaying the results in a string macro pStr = NULL; if ( (pStr = strstr( pgauge->parameters, "0x" )) != NULL ) // Process 0x parameter { sscanf( pStr + 2, "%x", &assignedKey ); if ( assignedKey > 0 ) params_found = 1; } }break;Doug

Share this post


Link to post
Share on other sites
Guest Patrick_Waugh

Turns out my primary problem was: static void CALLBACK Gauge_gcb(){}as static and CALLBACK (not in the sense of __stdcall, but in the sense of external) are mutually exclusive by definition, haha. I changed to using the macro CALLBACK, to highlight that it was a callback, and now I know what my unconscious was trying to tell me, haha.I was trying to eliminate the need for a unique name, and forgot that there was a reason for it being external, duh!Thanks Doug, I'll give that a try as well, although I'm likely going to avoid looking it up 18 times/second if at all possible.

Share this post


Link to post
Share on other sites
Guest Patrick_Waugh

Got it all to work.Turned out that the problem was both my extra "static" and the fact that I forgot to "hook up" the gauge callback by passing it's address in the main gauge macro!Once I found out it was never getting in the function, then I knew where to look, and fixed it.Just goes to show you have to always double check the basics.Works wonderfully now.

Share this post


Link to post
Share on other sites
Guest ghrasko

I use the following code. It is an example reading a scalng and a zeropoint floating point value as 5th and 6th params. I also use static. My gauge callback is called as callBack() in all my modules.//--- Gauge Display Function ------------------static FLOAT64 FSAPI example_display_cb( PELEMENT_SLIDER pelement ){ FLOAT64 val = pelement->source_var_y.var_value.n; // scaling with parameters from panel.cfg. val = val * pelement->gauge_header->user_area[0] + pelement->gauge_header->user_area[1]; if( val < 0.0 ) val = 0.0; else if( val > 180.0 ) val = 180.0; return val;}//--- Gauge Callback Function -------------------static void FSAPI callBack (PGAUGEHDR pgauge, int service_id, UINT32 extra_data){ FLOAT64 scaling, zeropoint; switch(service_id) { case PANEL_SERVICE_PRE_INITIALIZE: // checks 5th and 6th parameters from panel.cfg. // and saves its value with the gauge parameters. // This is a scaling and a zeropoint param for me. if( pgauge->parameters ) { // read floating point panel.cfg params // I am not using comas between the params sscanf( pgauge->parameters, "%lf %lf", &scaling, &zeropoint ); pgauge->user_area[0] = scaling; pgauge->user_area[1] = zeropoint; } break; }}Of couse I am NOT #include-ing the modules, but they are separately compiled modules. That is why I can use the same names (as static of course). In the main module I only define...extern GAUGEHDR ExampleGaugeHdr;... and of course the normal...GAUGE_TABLE_ENTRY(&ExampleGaugeHdr)Within the gauge module:#define GAUGEHDR_VAR_NAME ExampleGaugeHdrstatic PELEMENT_HEADER pbackground;GAUGE_HEADER_FS700(120, "Example", &pbackground, NULL, callBack, 0, 0, 0);and thus the elements could be all static also......static MAKE_STATIC( background, BMP_EXAMPLE_BG, &example_list1, NULL, IMAGE_USE_TRANSPARENCY|IMAGE_USE_ERASE, 0, 0,0)static PELEMENT_HEADER pbackground = &background.header;Gabor

Share this post


Link to post
Share on other sites
Guest Patrick_Waugh

Thanks for sharing.I too do it this way (not like the SDK example), an I guess we can use static after all, as the CALLBACK is called only from within the gauge itself. I probably tested this and forgot, and it just looked wrong to me now.Using the same name makes it easier to create "plug & play" templates, but with the C_GAUGE and C_PLIST macros we can do that even with the unique names.

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...