Archived

This topic is now archived and is closed to further replies.

Recommended Posts

I have made a two way switch which, turns the beacon light on and off, but as it only toggles the beacon on/off using KEY_TOGGLE_BEACON_LIGHTS, it is about as useful as a chocolate tea pot. It works fine if you are only using the panel it is in and are starting a new flight. But if for example you load the default B737-400, and turn on the beacon lights on that panel, then load the panel with this switch on it, the switch then works the wrong way around. I have tried adding if BEACON_LIGHTS on beacon_switch on else off, as well as many different alternative, all compile but still have the same problem. I have also tried to code it differently, on the lines of the SDK fuel selector, but that does not work. I need the switch to be able to tell if the beacon light is on, and set its self accordingly, but how ? I have tried using a callback via a FLOAT64 and no joy, I have now exhausted my knowledge. The Code, no errors, compiles fine, but still has the above problem.//Beacon Switchchar beacon_gauge_name[] = GAUGE_NAME;extern PELEMENT_HEADER beacon_list;extern MOUSERECT beacon_mouse_rect[];GAUGE_CALLBACK beacon_callback;GAUGE_HEADER_FS700 ( GAUGE_W, beacon_gauge_name, &beacon_list, beacon_mouse_rect, beacon_callback, 0, 0, 0 );FAILURE_RECORD beacon_fail[] ={ {FAIL_SYSTEM_ELECTRICAL_PANELS, FAIL_ACTION_ZERO}, {FAIL_NONE, FAIL_ACTION_NONE}};UINT32 beacon_switch = 0;MAKE_ICON( beacon_on, SWITCH_ON, NULL, NULL, IMAGE_USE_TRANSPARENCY | IMAGE_USE_ERASE | BIT7, 0, 0,0, MODULE_VAR_NONE, NULL, ICON_SWITCH_TYPE_SET_CUR_ICON, 1, 0, 0 )PELEMENT_HEADER beacon_plist1[] = { &beacon_on.header, NULL};MAKE_ICON( beacon_off, SWITCH_OFF, &beacon_plist1, NULL, IMAGE_USE_TRANSPARENCY | IMAGE_USE_ERASE | BIT7, 0, 0,0, MODULE_VAR_NONE, NULL, ICON_SWITCH_TYPE_SET_CUR_ICON, 1, 0, 0 )PELEMENT_HEADER beacon_plist2[] = { &beacon_off.header, NULL}; MAKE_STATIC( beacon_background, SWITCH_BACKGROUND, &beacon_plist2, NULL, IMAGE_USE_TRANSPARENCY | IMAGE_USE_ERASE | BIT7, 0, 0,0 )PELEMENT_HEADER beacon_list = &beacon_background.header;MOUSE_FUNCTION beacon_switch_mcb;MOUSE_BEGIN( beacon_mouse_rect, HELPID_GAUGE_LIGHT_SWITCH_BEACON, 0, 0 )MOUSE_CHILD_FUNCT( 0, 0, 40, 46, CURSOR_HAND,MOUSE_LEFTSINGLE, beacon_switch_mcb )MOUSE_END///////////////////////////////////////////////////////////////////// BOOL FSAPI beacon_switch_mcb( PPIXPOINT relative_point, FLAGS32 mouse_flags ){ if (beacon_switch == 0) beacon_switch = 1; else beacon_switch = 0; trigger_key_event(KEY_TOGGLE_BEACON_LIGHTS,0); return FALSE;} void FSAPI beacon_callback( PGAUGEHDR pgauge, int service_id, UINT32 extra_data ){ switch(service_id){/* "install_routine()" */ case PANEL_SERVICE_PRE_INSTALL: break;/* "initialize_routine()" */ case PANEL_SERVICE_PRE_INITIALIZE: break;/* "update_routine()" */ case PANEL_SERVICE_PRE_UPDATE: if (beacon_switch == 1 ) {SHOW_LISTELEMENT(pgauge->elements_list[0],2);HIDE_LISTELEMENT(pgauge->elements_list[0],1); } else {SHOW_LISTELEMENT(pgauge->elements_list[0],1);HIDE_LISTELEMENT(pgauge->elements_list[0],2); } break; if (BEACON_LIGHTS == 1) {beacon_switch = 1; } else {beacon_switch = 0; } break; /* "draw_routine()" */ case PANEL_SERVICE_PRE_DRAW: break;/* "kill_routine()" */ case PANEL_SERVICE_PRE_KILL: break;}} #undef GAUGE_NAME#undef GAUGEHDR_VAR_NAME#undef GAUGE_W

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

Ok... first, you don't really want to define a separate icon element for each "state" of the switch. An icon element alows you to define multiple bitmaps for ONE element and then return a numeric index to tell the element which one to show.Second... at no point are you reading the current state of the beacon lights from FS. That's how you initialize your switch's condition when the gauge first loads.

Share this post


Link to post
Share on other sites

Thanks Ed. I used Dai pswitch as a guide to the code, in that he used two MAKE_ICON, but will have a go at only using one. My code now reads the current state of the beacon light in FS and loads the switch correctly now, so if the beacon light are on when I load the panel the switch starts in the on position. The only thing I am unsure about is why when I compile it I get 1 warning.The Warningwarning C4244: '=' : conversion from 'FLOAT64' to 'UINT32', possible loss of dataHave I written abit of code incorrectly ?The Code //Beacon Switchchar beacon_gauge_name[] = GAUGE_NAME;extern PELEMENT_HEADER beacon_list;extern MOUSERECT beacon_mouse_rect[];GAUGE_CALLBACK beacon_callback;GAUGE_HEADER_FS700 ( GAUGE_W, beacon_gauge_name, &beacon_list, beacon_mouse_rect, beacon_callback, 0, 0, 0 );FAILURE_RECORD beacon_fail[] ={ {FAIL_SYSTEM_ELECTRICAL_PANELS, FAIL_ACTION_ZERO}, {FAIL_NONE, FAIL_ACTION_NONE}};UINT32 beacon_switch = 0;MODULE_VAR beacon_position = {BEACON_LIGHTS};UINT32 beacon_position_on = 0;MAKE_ICON( beacon_on, SWITCH_ON, NULL, NULL, IMAGE_USE_TRANSPARENCY | IMAGE_USE_ERASE | BIT7, 0, 0,0, MODULE_VAR_NONE, NULL, ICON_SWITCH_TYPE_SET_CUR_ICON, 1, 0, 0 )PELEMENT_HEADER beacon_plist1[] = { &beacon_on.header, NULL};MAKE_ICON( beacon_off, SWITCH_OFF, &beacon_plist1, NULL, IMAGE_USE_TRANSPARENCY | IMAGE_USE_ERASE | BIT7, 0, 0,0, MODULE_VAR_NONE, NULL, ICON_SWITCH_TYPE_SET_CUR_ICON, 1, 0, 0 )PELEMENT_HEADER beacon_plist2[] = { &beacon_off.header, NULL}; MAKE_STATIC( beacon_background, SWITCH_BACKGROUND, &beacon_plist2, NULL, IMAGE_USE_TRANSPARENCY | IMAGE_USE_ERASE | BIT7, 0, 0,0 )PELEMENT_HEADER beacon_list = &beacon_background.header;MOUSE_FUNCTION beacon_switch_mcb;MOUSE_BEGIN( beacon_mouse_rect, HELPID_GAUGE_LIGHT_SWITCH_BEACON, 0, 0 )MOUSE_CHILD_FUNCT( 0, 0, 40, 46, CURSOR_HAND,MOUSE_LEFTSINGLE, beacon_switch_mcb )MOUSE_END////////////////////////////////////////////////////////////////BOOL FSAPI beacon_switch_mcb( PPIXPOINT relative_point, FLAGS32 mouse_flags ){ if (beacon_switch == 0) beacon_switch = 1; else beacon_switch = 0; trigger_key_event(KEY_TOGGLE_BEACON_LIGHTS,0); return FALSE;} void FSAPI beacon_callback( PGAUGEHDR pgauge, int service_id, UINT32 extra_data ){ switch(service_id){/* "install_routine()" */ case PANEL_SERVICE_PRE_INSTALL: break;/* "initialize_routine()" */ case PANEL_SERVICE_PRE_INITIALIZE: lookup_var(&beacon_position); beacon_position_on = beacon_position.var_value.n; if (beacon_position_on == 1) {beacon_switch = 1; } else {beacon_switch = 0; } break; /* "update_routine()" */ case PANEL_SERVICE_PRE_UPDATE: if (beacon_switch == 1 ) {SHOW_LISTELEMENT(pgauge->elements_list[0],2);HIDE_LISTELEMENT(pgauge->elements_list[0],1); } else {SHOW_LISTELEMENT(pgauge->elements_list[0],1);HIDE_LISTELEMENT(pgauge->elements_list[0],2); } break; /* "draw_routine()" */ case PANEL_SERVICE_PRE_DRAW: break;/* "kill_routine()" */ case PANEL_SERVICE_PRE_KILL: break;}} #undef GAUGE_NAME#undef GAUGEHDR_VAR_NAME#undef GAUGE_WRussell

Share this post


Link to post
Share on other sites

Something like this:char BeaconLights_gauge_name[] = GAUGE_NAME;extern PELEMENT_HEADER BeaconLights_list;extern MOUSERECT BeaconLights_mouse_rect[];GAUGE_HEADER_FS700(GAUGE_W, BeaconLights_gauge_name, &BeaconLights_list, BeaconLights_mouse_rect, NULL, 0, 0, 0);BOOL FSAPI BeaconLightsMouseClick( PPIXPOINT relative_point, FLAGS32 mouse_flags){ send_key_event (KEY_TOGGLE_BEACON_LIGHTS,0) ; return FALSE;}MOUSE_BEGIN(BeaconLights_mouse_rect,HELPID_MIN,0,0) MOUSE_TOOLTIP_TEXT_ID (TOOLTIPTEXT_LIGHT_SWITCH_BEACON,NULL) MOUSE_CHILD_FUNCT(1,1,55,74,CURSOR_HAND,MOUSE_LEFTSINGLE,BeaconLightsMouseClick)MOUSE_ENDMAKE_ICON(BeaconLightsSwitch,SwitchOff,NULL,NULL,IMAGE_USE_ERASE | IMAGE_USE_TRANSPARENCY | BIT7,0,12,38,BEACON_LIGHTS,NULL,ICON_SWITCH_TYPE_STEP_TO,2,0,0)PELEMENT_HEADER BeaconLightsSwitchList[] = {&BeaconLightsSwitch.header,NULL};MAKE_STATIC(BeaconLightsBackground,BeaconLightsBitmap,&BeaconLightsSwitchList,NULL,IMAGE_USE_ERASE | IMAGE_USE_TRANSPARENCY | BIT7,0,0,0)PELEMENT_HEADER BeaconLights_list = &BeaconLightsBackground.header;Note that this code uses the FS variable directly, and so does not use a callback function. It also uses Ed's suggestion of a single icon macro for both the on and off elements.Doug

Share this post


Link to post
Share on other sites

The "down side" to tying the variable directly to the icon element... you can't do such "neat and fancy" things as providing the ability to set up a "cold and dark" flight within your own gauges.I rarely tie the variable directly to the element... for lots of reasons... but that's me. :)

Share this post


Link to post
Share on other sites

Thanks Doug for the code, I converted my two icon code into a single icon, and used the variable directly. I see from Ed post that he perfers using the other approach, which is good for me as I now know two ways to skin the cat :)In the one icon code I used the FS9 tooltip as given to me by Doug, but but perfer to do my own. I have read Dai explaination on them several times, and have seen a couple of post on them, so tonight I gave it a go, as you proberly have guessed I have a problem :)I have delcared the Token Variable, looked it up in a FLOAT64, added the mouse tooltips args and all I get is Beacon: What am I missing ?The Code//Beacon Switchchar beacon_gauge_name[] = GAUGE_NAME;extern PELEMENT_HEADER beacon_list;extern MOUSERECT beacon_mouse_rect[];GAUGE_CALLBACK beacon_callback;GAUGE_HEADER_FS700 ( GAUGE_W, beacon_gauge_name, &beacon_list, beacon_mouse_rect, beacon_callback, 0, 0, 0 );FAILURE_RECORD beacon_fail[] ={ {FAIL_SYSTEM_ELECTRICAL_PANELS, FAIL_ACTION_ZERO}, {FAIL_NONE, FAIL_ACTION_NONE}};MAKE_ICON( beaconswitch, SWITCH_OFF, NULL, NULL, IMAGE_USE_TRANSPARENCY | IMAGE_USE_ERASE | BIT7, 0, 0,0, BEACON_LIGHTS, NULL, ICON_SWITCH_TYPE_STEP_TO, 2, 0, 0 )PELEMENT_HEADER beaconswitchlist[] = { &beaconswitch.header, NULL};MAKE_STATIC( beacon_background, SWITCH_BACKGROUND, &beaconswitchlist, NULL, IMAGE_USE_TRANSPARENCY | IMAGE_USE_ERASE | BIT7, 0, 0,0 )PELEMENT_HEADER beacon_list = &beacon_background.header;MODULE_VAR beacon_position = {BEACON_LIGHTS};FLOAT64 beacon_on;BOOL FSAPI beacon_switch_mcb( PPIXPOINT relative_point, FLAGS32 mouse_flags ){ send_key_event (KEY_TOGGLE_BEACON_LIGHTS,0); return FALSE;}static FLOAT64 FSAPI beacon_tip (FLOAT64 number, ID id, PCSTRINGZ string, MODULE_VAR *source_var, PGAUGEHDR gauge){ lookup_var(&beacon_position); beacon_on = beacon_position.var_value.n; return beacon_on;}MOUSE_TOOLTIP_ARGS (beacon_tooltip)MOUSE_TOOLTIP_ARG (MODULE_VAR_NONE, 0, NULL, NULL, NULL, beacon_tip, NULL, NULL)MOUSE_TOOLTIP_ARGS_ENDMOUSE_BEGIN(beacon_mouse_rect,HELP_NONE,0,0)MOUSE_TOOLTIP_TEXT_STRING("Beacon:%3!s!",beacon_tooltip)MOUSE_CHILD_FUNCT( 0, 0, 40, 46, CURSOR_HAND, MOUSE_LEFTSINGLE, beacon_switch_mcb )MOUSE_END//////////////////////////////////////////////void FSAPI beacon_callback( PGAUGEHDR pgauge, int service_id, UINT32 extra_data ){ switch(service_id){/* "install_routine()" */ case PANEL_SERVICE_PRE_INSTALL: break;/* "initialize_routine()" */ case PANEL_SERVICE_PRE_INITIALIZE: break; /* "update_routine()" */ case PANEL_SERVICE_PRE_UPDATE: break; /* "draw_routine()" */ case PANEL_SERVICE_PRE_DRAW: break;/* "kill_routine()" */ case PANEL_SERVICE_PRE_KILL: break;}} #undef GAUGE_NAME#undef GAUGEHDR_VAR_NAME#undef GAUGE_W

Share this post


Link to post
Share on other sites

Your tooltip callback function (beacon_tip) is returning a FLOAT64, but your tooltip string is formatted to accept a string input.Try:MOUSE_TOOLTIP_TEXT_STRING("Beacon: %1!1.0f!",beacon_tooltip)Doug

Share this post


Link to post
Share on other sites

I spotted that after I had posted, and it works, but not as I want it to. I get Beacon:0 or Beacon:1, what I realy want is Beacon:On and Beacon:Off. After looking through snippets of code I came up with this;static FLOAT64 FSAPI beacon_tip (FLOAT64 number, ID id, PCSTRINGZ string, MODULE_VAR *source_var, PGAUGEHDR gauge){ lookup_var(&beacon_position); beacon_on = beacon_position.var_value.n; if (beacon_position.var_value.n){ return "Beacon: On";}else{ return "Beacon: Off";}}but that just gives me 2 compiler errors.(57) : error C2440: 'return' : cannot convert from 'char [11]' to 'FLOAT64'(60) : error C2440: 'return' : cannot convert from 'char [12]' to 'FLOAT64'

Share this post


Link to post
Share on other sites

Russell,Forgive my intrusion here, but the reason of those errors is so evident that I would dare to give you an advise: you can't program in C/C++ with trial and error; it's not that easy as with XML; in the first case you MUST understand at least the basic concepts of definitions and unit conversions, amongst other things.I have to admit I started in a similar way, but quickly had to go to the books (read Internet articles) because C/C++ intrinsecal's complexity.Save time and avoid head scratching-study first!! :-)TomPS: If you're declaring a function as FLOAT64, it won't be able to return "Beacon: On" or similar, which are char strings...

Share this post


Link to post
Share on other sites

Firstly I do not forgive your intrusion. I have only been coding in C++ for the last ten days, and am currently looking at different books available, while I do this I am sourcing as much code as I can from full gauges or snipets that I have found on forums, and giving simple things a try ie a switch. I am not asking for people to give me code, if you noticed earlier in this post Ed just told me that I was not reading the current state from FS, then with the help of Dai tutorial and the internet I sorted that out, so now I know how to read the current state of a variable. The one thing I did not expect on this forum is ha ha ha post I am better than you, but then I should have guessed when I saw the forum name, have come across a few of your post, where you use the same condescending attitude. A helpful post would have been, you can not declare a function as a FLOAT64 to display characters, you need to use a character string. This is something I found out earlier when looking through a internet article, and no I have not got it to work yet, but I will.So in future if you don't mind, keep your intrusion to yourself :-)

Share this post


Link to post
Share on other sites

Russell,I didn't mean to make you feel upset. I was just trying to say what I really DID -read a lot about C programming before trying to write a decent code, because of the language's inherent difficulties. Even a simple compiler error can be a nightmare at the begginings. That's all. I'm sorry that my attitude may sound condescending. And it's all fair that you don't want to forgive the intrusion. Therefore, from now on and as per your wishes, I will keep from replying to your posts.Tom

Share this post


Link to post
Share on other sites

TomI appoligize for the responce to your first post, I was hoping to get the dynamic tooltips to work before getting into the books, but after many failed attempt last night, you were right and it is time to hit the books. The intrusion which was not a welcome at first,is welcome now. I knew it was something I had to do, but was putting it off. I do catch on quicker if I can do something while learning, so have ordered a couple of books today which I hope will allow me to do this.The books I have orderedC for dummies and C++ for dummies as they look like they could be helpful when programing gauges in FS. C for dummies is recommend by Dai in his tutorial, and it does look like a pretty good book.Does anyone know of any other books which are helpful when learning to program gauges in C++ ??

Share this post


Link to post
Share on other sites

Russell,Now that my intrusions are welcomed :-) I would like to recommend you a bunch of sites:http://www.cplusplus.com --> this is for C++, a great source, very didactical.http://www.codeproject.com/ ---> this for both C/C++, another wonderful source for beginners.and I would like to ask, if you don't mind :-) , why are you starting to code gauges in C instead of XML, is it because of your own interest in the language, as an alternative for copyright protection issues, or what?TomPS: I forgot to add msn2.com, MS knowledge base, for very specific issues it's the best place to go.

Share this post


Link to post
Share on other sites

My reason for learning C++Every time a new FS comes out XML changes, ok from FS2002 to FS2004 the changes were small, but FSX looks like it has changed quite a bit, where as C++ seems to have stay pretty much the same. I have been intersted in learning C++ for a while and it is always good to be able to program in different languages, so thought I would give it a go. I also think the gauges look much clearer in C++ than they do in XML, I have an Airbus ECAM I did in XML and I also have one I am doing in C++, they are running side by side in my test panel and the C++ gauge looks much clearer, funny thing is they are using the same bitmaps. I would also like to be able to do some payware gauge programing at some point, nothing fancy, just some small stuff, but this depends on how good I get a C++.Thanks for the links, will get some studying done over the weekend.

Share this post


Link to post
Share on other sites

As your C/C++ knowledge increases you may want to look at 'C - The Complete Reference Fourth Edition' (Herbert Schildt, Osbourne Publishing, ISBN 0-07-212124-6). It's loaded with short, relevant examples. There's a C++ equivalent which I can't speak for because I still code cross-platform, although 'the company' is forcing me to learn C++ (gah!). Yes, you're better using multiple images in one make_icon whenever possible. pswitch was originally done around seven years ago and I never saw any reason to remove it as it illustrates show/hide; the Cessna magneto example illustrates multiple images in a single make_icon.This late at night (after 2.00am and I'm only just in from work) I'm too lazy to read back through this thread again but whoever said 'don't use a module_var directly' I'm in entire agreement with. I think I do recommend reading in the module_var to a local variable before doing anything with it; apart from being more flexible, you are able to capture a module_var and retain the state of the module_var at that particular instance for further use while the module_var itself carries on with whatever it is doing. That said, there are also times when it is easier to use the module_var directly; airspeed comes to mind. OTOH, you may read (airspeed) directly in the macro but there's nothing to stop you modifying the return in the macro callback. Three ways to skin a cat? My four are starting to eye me a little suspiciously.....-Dai

Share this post


Link to post
Share on other sites