Jump to content
Sign in to follow this  
badderjet

Simple switch in C

Recommended Posts

Well I made some analogue gauges til now, they work quite fine, although my altimeter gets unacurrate in higher altitudes. I don't know if it's the nonlinearity able or what... :-hmmm But I wanted to make a simple switch and I cannot get anything to work. FS crashes (it won't even start!) there's a very untypical error message when trying to start FS. It immediately shuts down as long as the gauge exists in the GAUGES directory. Then: I have the following warning message referring to the GAUGE_HEADER_FS700 line:GAUGE_HEADER_FS700(GAUGE_W, switch_gauge_name, &switch_list, switch_mouse_rect, switch_cb, 0, 0, 0);Warning W8075 test.switch.c 5: Suspicious pointer conversionAny idea what that is?And regarding the switch, well OK it seems I need an MAKE_ICON macro. So - do I need the SHOW/HIDE macros or is there another way to change the images when clicking on the switch?Thankshttp://flightsimmers.net/airport/etti/signature_pro.jpg

Share this post


Link to post
Share on other sites
Guest bartels

Is switch_cb a GAUGE_CALLBACK or an ICON_UPDATE_CALLBACK? You can't use image callback functions for gauge callback functions. As often stated here you don't need SHOW HIDE for icons just use a callback function that returns -1 (hide) or 0 (show first bitmap).Arne Bartels

Share this post


Link to post
Share on other sites

Until now it does still not work...>Is switch_cb a GAUGE_CALLBACK or an ICON_UPDATE_CALLBACK? It's an ICON_UPDATE_CALLBACK.>As often stated here you don't need SHOW HIDE for >icons just use a callback function that returns -1 (hide) or >0 (show first bitmap). Well I've never seen it here so... :-) But as far as I understand -1 will be hide, 0 will be the first, 1 the second etc. image? Just for confirmation. :-)http://flightsimmers.net/airport/etti/signature_pro.jpg

Share this post


Link to post
Share on other sites

Well I just treid around, and it workes a few times, but now I'm at the beginning again:http://flightsimmers.net/airport/etti/avsi...ers/problem.gif[h6](The message which appears when trying to start FS...)[/h6]WHAT THE HELL!?! :-mad I'M GETTING CRAZY :-hanghttp://flightsimmers.net/airport/etti/signature_pro.jpgEDITAll right, I gotta tell you how I test the gauge... The only way is, DELETING the file from the gauges folder, starting FS and starting a flight with e. g. the Learjet or Extra (the C172 uses the gauge). Then - COMPILE and COPY to the gauges directory WHILE FS is running. Then changing over to the C172 - and, damn it, the gauge works.But tell me, WHY does FS crash when starting??? It gets unstable in general, e. g. when minimizing, then doing something other in Windows and restoring to Fullscreen, it often just terminates. And all this only occurs when the gauge is existent in the gauges directory...

Share this post


Link to post
Share on other sites
Guest bartels

Remove the switch_cb call from the GAUGE_HEADER_FS700 macro. As it is an ICON_UPDATE_CALLBACK you MUST not use it as a gauge callback function. ICON_UPDATE_CALLBACK are for MAKE_ICONs and GAUGE_CALLBACKs are for GAUGE_HEADER_FSXXXs. Don't mix them or expect your kind of crashes.Arne Bartels

Share this post


Link to post
Share on other sites

Okie Dokie, look at the following code for the switch. The variable powered is a (multi-)gauge internal variable just indicating if the Battery is turned on or not. I have the OFF image in the MAKE_STATIC, the ON image is in the MAKE_ICON macro.char switch_gauge_name[] = GAUGE_NAME;extern PELEMENT_HEADER switch_list;extern MOUSERECT switch_mouse_rect[];GAUGE_HEADER_FS700(GAUGE_W, switch_gauge_name, &switch_list, switch_mouse_rect, 0, 0, 0, 0);MOUSE_FUNCTION switch_elec_mcb;MOUSE_BEGIN (switch_mouse_rect,0,0,0) MOUSE_CHILD_FUNCT (0, 0, 128, 256, CURSOR_HAND, MOUSE_LEFTSINGLE, switch_elec_mcb)MOUSE_ENDBOOL FSAPI switch_elec_mcb (PPIXPOINT relative_point, FLAGS32 mouse_flags){ if (powered == 0) { powered = 1; trigger_key_event (KEY_TOGGLE_MASTER_BATTERY, 0); } else { powered = 0; trigger_key_event (KEY_TOGGLE_MASTER_BATTERY, 0); } return FALSE;}ICON_UPDATE_CALLBACK switch_elec_cb;FLOAT64 FSAPI switch_elec_cb (PELEMENT_ICON pelement){ if (powered == 0) return -1; else return 0;}MAKE_ICON ( switch_elec, SWITCH_ON, NULL, NULL, IMAGE_USE_ERASE, 0, 0, 0, MODULE_VAR_NONE, switch_elec_cb, ICON_SWITCH_TYPE_SET_CUR_ICON, 1, 0, 0 )PELEMENT_HEADER switch_icon_list[] = { &switch_elec.header, NULL};MAKE_STATIC ( switch_bg, SWITCH_OFF, &switch_icon_list, NULL, IMAGE_USE_ERASE, 0, 0, 0 )PELEMENT_HEADER switch_list = &switch_bg.header;#undef GAUGE_NAME#undef GAUGEHDR_VAR_NAME#undef GAUGE_WAnd please don't laugh! :-) I have removed the whole switch_cb GAUGE_CALLBACK structure, but still FS crashes.Well as I said in the post above, the gauge works under some circumstances, butit only reacts to mouseclicks, not when pressing CTRL+M for the Battery.http://flightsimmers.net/airport/etti/signature_pro.jpg

Share this post


Link to post
Share on other sites

bump bump bumpyevery 20 min views count increasing by 1... :-dohall right its 0000 local time now, c ya tomorrowplease any1 reply!!! would really appreciate it :-)Etienne

Share this post


Link to post
Share on other sites
Guest bartels

My reply is that I'm tomorrow at the sea and on Monday the holiday is over. The code looks OK on first look, but I don't have the time to check in detail, maybe it's simply not completely rebuilt, VC is infamous for non-complete recompilings, better try "Rebuild All".Arne Bartels

Share this post


Link to post
Share on other sites

>My reply is that I'm tomorrow at the sea and on Monday the >holiday is over. The code looks OK on first look, but I >don't have the time to check in detail, maybe it's simply >not completely rebuilt, VC is infamous for non-complete >recompilings, better try "Rebuild All". >Arne Bartels LOL :-lol Ok mate, have fun @ the sea, well, I have four weeks of vacation left... :-hah I'll try to rebuild it.Thanks :-)http://flightsimmers.net/airport/etti/signature_pro.jpg

Share this post


Link to post
Share on other sites

All right, no. All wrong, guys.Hey crew. I'm getting more and more frustrated about this. You see, the bad thing is, the ****ing gauge works, but it also crashes FS. I've just built a Tachometer based on the code I had posted above before. Same problem. Delete the gauge from the GAUGES folder, start FS, compile the gauge and copy it into the GAUGES folder, select Cessna 172SP, see the gauge, working. Otherwise - gauge already in GAUGES folder and starting FS - crash and error message, see above.I'm saying based on the above code, and the same problem. So I think the error must be the code above (maybe it's a very basic error...) so please someone have a closer look at it.I'd really like to see these working gauges not crashing FS. :-)Thank you for your help, it's much appreciated. Really!http://flightsimmers.net/airport/etti/signature_pro.jpg

Share this post


Link to post
Share on other sites

You shouldn't need to declare the Icon Callback. Try Commenting out ICON_UPDATE_CALLBACK switch_elec_cb;. Other than that, it looks pretty good. If that doesn't do the trick, try emailing me the bitmaps and I'll take a look at what's causing the problems.Matt

Share this post


Link to post
Share on other sites

The only thing I did was move the bitmaps to a seperate directory (just something I like to do ;) ). Built the makefile, compiled it, started up FS and it worked fined. The IMAGE_USE_ERASE flag didn't seem to work, but the rest of the gauge did. Maybe there's a problem with your makefile or BCC. I included my makefile just for reference. I don't use BCC, so I'm not familiar with it's makefiles.http://home.cfl.rr.com/mkaprocki/gauge.zipMatt

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