Skip to content
View in the app

A better way to browse. Learn more.

The AVSIM Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

C++ String

Featured Replies

  • Commercial Member

Hey... cut back the length of the line full of the '/' characters. They seriously overextend the web page. LOLOk... in your gauge file you should have at least 3 files... a file with the extention of .h, a file with the extention of .rc and a file with the extension of .c or .cpp (if it's a C++ file).In your .h file (header file) add the following:MODULE_VAR TURB_ENGINE_1_CORRECTED_N1var = {TURB_ENGINE_1_CORRECTED_N1};The header file is used for variable and defines typically. The .c/.cpp file is used for actual function code typically.The .rc file is used for resources: copyright info/bitmaps/etc.

Ed Wilson

Mindstar Aviation
My Playland - I69

Got it to work :)Thanks for all the help Ed, last night I was ready to jack it in, tonight I want to learn more. I think it was Bill who said it (Programming) causes premature graying of the hair, I can now see why.The code for those who might be looking at a later date.In the Header File:MODULE_VAR TURB_ENGINE_1_CORRECTED_N1var = {TURB_ENGINE_1_CORRECTED_N1};Subgauge code, minus the ///// :)//A319 upper eicaschar upper_eicas_gauge_name[] = GAUGE_NAME;extern PELEMENT_HEADER upper_eicas_list;extern MOUSERECT upper_eicas_mouse_rect[];GAUGE_CALLBACK upper_eicas_callback;GAUGE_HEADER_FS700 ( GAUGE_W, upper_eicas_gauge_name, &upper_eicas_list, upper_eicas_mouse_rect, upper_eicas_callback, 0, 0, 0 );FAILURE_RECORD upper_eicas_fail[] = { {FAIL_SYSTEM_ELECTRICAL_PANELS, FAIL_ACTION_NO_DRAW}, {FAIL_NONE, FAIL_ACTION_NONE}};FLOAT64 engine1n1;// Engine 1 N1//StringSTRING_UPDATE_CALLBACK engine1n1string_cb;FLOAT64 FSAPI engine1n1string_cb (PELEMENT_STRING pelement ){ engine1n1 = TURB_ENGINE_1_CORRECTED_N1var.var_value.n; sprintf (pelement->string,"%3.1f", engine1n1); return engine1n1;}MAKE_STRING( engine1n1string, NULL, upper_eicas_fail, IMAGE_USE_ERASE | IMAGE_USE_TRANSPARENCY | BIT2, 0, 32,46, 45,24, 4, TURB_ENGINE_1_CORRECTED_N1, MODULE_VAR_NONE, MODULE_VAR_NONE, RGB (0,255,0), RGB (0,0,0), RGB (0,255,0), ARIAL, GAUGE_WEIGHT_DEFAULT, GAUGE_CHARSET, 0, DT_CENTER | DT_VCENTER, NULL, engine1n1string_cb ) PELEMENT_HEADER engine1n1string_plist[] = { (PELEMENT_HEADER) &engine1n1string.header, NULL};//NeedleNONLINEARITY engine1n1_nonlinearity[] = { {{21, 66}, 00.000000, 0}, {{25, 21}, 50.000000, 0}, {{85, 30}, 100.000000, 0},};FLOAT64 FSAPI engine1n1needle_cb (PELEMENT_NEEDLE pelement ){ engine1n1 = TURB_ENGINE_1_CORRECTED_N1var.var_value.n; return engine1n1;}MAKE_NEEDLE( engine1n1needle, N1_NEEDLE, engine1n1string_plist, upper_eicas_fail, IMAGE_USE_TRANSPARENCY | IMAGE_USE_ERASE | BIT7 | BIT2, 0, 52,44, 0,1, TURB_ENGINE_1_CORRECTED_N1, engine1n1needle_cb, engine1n1_nonlinearity, 0 )PELEMENT_HEADER engine1n1needle_plist[] = { (PELEMENT_HEADER) &engine1n1needle.header, NULL};//BackgroundMAKE_STATIC( upper_eicas_background, UPPER_EICAS_BACKGROUND, engine1n1needle_plist, upper_eicas_fail, IMAGE_USE_TRANSPARENCY | IMAGE_USE_ERASE | BIT2 | BIT7, 0, 0,0 )PELEMENT_HEADER upper_eicas_list = &upper_eicas_background.header;MOUSE_BEGIN( upper_eicas_mouse_rect,HELPID_GAUGE_EICAS, 0, 0 ) MOUSE_END void FSAPI upper_eicas_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: /* Fetch Variables */ lookup_var(&TURB_ENGINE_1_CORRECTED_N1var); engine1n1 = (TURB_ENGINE_1_CORRECTED_N1var.var_value.n); 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

  • Author
  • Moderator

Actually, that is not a "subgauge" code at all.I truly think you'd be better off settling on a boilerplate format which at minimum consists of these files, even if you're actually only planning to have one "subgauge":Main.c// #includes, #define and GAUGE_TABLE entries at a minimumMain.h// Version info, preprocessor instructions, bitmap resource numbersMain.rc// VS_VERSION_INFO, Company String Data, Bitmap filenames and pathsSubGaugenn.c// contains all code relevant to a specific sub-gauge.Write to me at [email protected] and I will send you the SDK sample gauges already set up as a MSVCC solution. If may prove helpful to you as an example to study.

Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

This is sort of a string problem, so thought I would post it here, instead of starting another post/topic.Have now got all the engine gauges on the ecias working ie N1, EGT etc, even managed to sort out the Total fuel quantity and fuel flow in KGS. So as I have got this far I might as well finish it. I want a string to display PARK BRK in the eicas, when the parking brakes are on. When they are off the string should not be displayed.The only token variable I have found for parking brakes is PARKING_BRAKE_POS, 0 being off and 32 being full on. I have then delcared this in the header like I have done the others, and then in a FLOAT64 in the subguge (I have not read the stuff Bill sent me yet) :). I have seen a few code where I think the string has been controlled by codes in the pelement string, so have given this a go but althought the gauge compiles, and works in FS, i just get a bunch of numbers.The relivant bits of code;HeaderMODULE_VAR PARKING_BRAKE_POSvar = {PARKING_BRAKE_POS};FLOAT64 parkingbrakeon;//Parking Brake On //PARK BRK//StringSTRING_UPDATE_CALLBACK parkingbrakeonstring_cb;FLOAT64 FSAPI parkingbrakeonstring_cb (PELEMENT_STRING pelement ){ if( parkingbrakeon == 1){ parkingbrakeon = (PARKING_BRAKE_POSvar.var_value.n); wsprintf (pelement->string,"%8d", "PARK BRK");}else{ wsprintf (pelement->string,"%8d", "");} return parkingbrakeon;}MAKE_STRING( parkingbrakeonstring, NULL, upper_eicas_fail, IMAGE_USE_ERASE | IMAGE_USE_TRANSPARENCY | BIT2, 0, 218,216, 45,24, 8, PARKING_BRAKE_POS, MODULE_VAR_NONE, MODULE_VAR_NONE, RGB (0,255,0), RGB (0,0,0), RGB (0,255,0), ARIAL, GAUGE_WEIGHT_DEFAULT, GAUGE_CHARSET, 0, DT_CENTER | DT_VCENTER, NULL, parkingbrakeonstring_cb ) PELEMENT_HEADER parkingbrakeonstring_plist[] = { (PELEMENT_HEADER) &parkingbrakeonstring.header, NULL};lookup_var(&PARKING_BRAKE_POSvar); parkingbrakeon = (PARKING_BRAKE_POSvar.var_value.n);I have tried using sprintf as well as wsprintf, but still get the same results. I am proberly going completly the wrong way about this, but could not just post can not do this, had to give it a go first. Would it be better for me to learn how to grab XML variables so I could use BRAKE PARKING POSITION,bool ?Russell

Try this for your callback:FLOAT64 FSAPI parkingbrakeonstring_cb (PELEMENT_STRING pelement ){lookup_var(&PARKING_BRAKE_POSvar);if( PARKING_BRAKE_POSvar.var_value.n > 0){sprintf (pelement->string,"%s", "PARK BRK");}else{sprintf (pelement->string,"%s","");}return 0;}You need the %s specification to print an actual string. The %8d is for an 8 character integer value.Doug

Thanks Doug works perfectly.I will also use this code for flap handle position for the flap indicator numbers ie 1,2 etc as I use a string for that, but for the flap indicator its self I need to alter bitmaps for certain flap positions, my first thought was to use Element_Icon, and make each one visible when ceratin conditions are met. There are 5 bitmaps in total so when flap are set to 3 bitmap 3 is the only one visible. Is this the best way or is there a better way ?

I thought Dougs code with a bit of altering would work for the Flap Handle position string, but so far it does not.What I want it to do is display the flap handle position, ie flaps handle pos 1, string show 1.The code I have displays 4 all of the time except when the flap handle is in position 5 when is does show 5.The codeFLOAT64 FSAPI flaphandlepositionstring_cb (PELEMENT_STRING pelement ){ lookup_var(&FLAPS_HANDLE_POSvar); if( FLAPS_HANDLE_POSvar.var_value.n < 3276){ sprintf (pelement->string,"%s", "");}else lookup_var(&FLAPS_HANDLE_POSvar); if( FLAPS_HANDLE_POSvar.var_value.n > 0 <6552 ){ sprintf (pelement->string,"%s", "1");}else lookup_var(&FLAPS_HANDLE_POSvar); if( FLAPS_HANDLE_POSvar.var_value.n > 3276 < 9828){ sprintf (pelement->string,"%s", "2");}else lookup_var(&FLAPS_HANDLE_POSvar); if( FLAPS_HANDLE_POSvar.var_value.n > 6552 < 13104 ){ sprintf (pelement->string,"%s", "3");}else lookup_var(&FLAPS_HANDLE_POSvar); if( FLAPS_HANDLE_POSvar.var_value.n > 9828 < 16384 ){ sprintf (pelement->string,"%s", "4");}else lookup_var(&FLAPS_HANDLE_POSvar); if( FLAPS_HANDLE_POSvar.var_value.n > 13104 ){ sprintf (pelement->string,"%s", "5");} return 0;}

  • Commercial Member

Ok... don't take this wrong... that's some scary code. ;)First... FLAPS_HANDLE_POS is for the physical flaps control on the panel. Is that what your gauge should report... or should it actually report the physical flaps position? If it's the latter, you need TRAILING_EDGE_FLAPS0_LEFT_ANGLE or TRAILING_EDGE_FLAPS0_RIGHT_ANGLE.In your code you're repeatedly calling "lookup_var". No need... one call does it all for each update loop. Also... this code:"if( FLAPS_HANDLE_POSvar.var_value.n > 0 <6552 )" literally won't work. If you're looking to evaluate between a min and max like this... it has to be written this way:if( FLAPS_HANDLE_POSvar.var_value.n > 0 && FLAPS_HANDLE_POSvar.var_value.n <6552 )However, here's a better method of writing what you wrote:FLOAT64 FSAPI flaphandlepositionstring_cb (PELEMENT_STRING pelement ){lookup_var(&FLAPS_HANDLE_POSvar);if( FLAPS_HANDLE_POSvar.var_value.n < 3276){sprintf (pelement->string,"%s", "");}else if( FLAPS_HANDLE_POSvar.var_value.n < 6552 ){sprintf (pelement->string,"%s", "1");}else if( FLAPS_HANDLE_POSvar.var_value.n < 9828){sprintf (pelement->string,"%s", "2");}else if( FLAPS_HANDLE_POSvar.var_value.n < 13104 ){sprintf (pelement->string,"%s", "3");}else if( FLAPS_HANDLE_POSvar.var_value.n < 16384 ){sprintf (pelement->string,"%s", "4");}else{sprintf (pelement->string,"%s", "5");}return 0;} Another consideration... creating a local variable to store the value of FLAPS_HANDLE_POSvar. For the most part, it's no big deal... but the larger and more complex a gauge system becomes... the bigger the impact of performance has for repeatedly calling a variable like FLAPS_HANDLE_POSvar. It deals with near/far pointers to data... and is something you'll need to pay attention to sooner or later.

Ed Wilson

Mindstar Aviation
My Playland - I69

Russell,Do yourself a favour - go out and buy an introductory C++ textbook. No point in guessing at syntax.You can also get help at places like http://www.cplusplus.com/ and MSDN, but having a real book in front of you is often very helpful. If nothing else, it will give you something large and heavy to throw across the room when your gauge fails to compile for the 97th straight time... }( Doug

Thanks for the code and advice Ed. I did want it for the Flap Handle Position, so it shows the handle position on the eicas, I will use TRAILING_EDGE_FLAPS0_LEFT_ANGLE or TRAILING_EDGE_FLAPS0_RIGHT_ANGLE for the 5 bitmaps that I use to show the physical flaps position. I now have the last bit of code I need to finish this. I will then be taking Doug advice and buying a big book, so I can throw it across the room when it compiles ok, but does not work in FS :)Thanks to everyone who posted.Russell

Hi DaiI do not think the problem lies with your tutorial on strings, but with me trying to run before I can walk. The main reason this post has so many replies is because I tried to code everything the same way as I had the airpseed gauge untill Ed and Bill showed me a better way. The only problem I had with the strings not showing, was at the start when I was using wsprintf instead of sprintf, a few lines on when to use sprintf and wsprint would have been helpful. The the rest of the post have been down to me not knowing how to code the PELEMENT_STRING pelement so it displays what I want it to display in the string. I have looked for some examples of codes on forums, but have not found many, maybe that is something that could be added.Thanks for a great tutorial, it is one of the things that got me interested in C++, and although I have a few more grey hairs, I am enjoying learning it most of the time :) Russell

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.