• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

FSX:SE Reading from a File in a C Gauge

Messages
7
Country
us-florida
Hey everyone! I'm working on a project right now that involves reading a value from a text file and then displaying it on a gauge. I started working off of the SDK.Fuel.cpp in the SDK sample code to try to get it to work. The gauge loads fine and no errors are sent from FSX, but the gauge never updates. Here is my code:
Code:
#include <fstream>
//    Set up gauge header
char fuel_gauge_name[]        = GAUGE_NAME;
extern PELEMENT_HEADER        fuel_list;
extern MOUSERECT            fuel_mouse_rect[];

GAUGE_HEADER_FS700( GAUGE_W, fuel_gauge_name, &fuel_list, \
                        fuel_mouse_rect, 0, 0, 0, 0 );



/////////////////////////////////////////////////////////////////////////////
#define    GAUGE_MIN_FUEL    0
#define    GAUGE_MAX_FUEL    75

NONLINEARITY  fuel_nonlinearity[] =
{
    {{30,    182},     0, 0},
    {{119,     47},    25, 0},
    {{246,     93},    50, 0},
    {{241,    221},    75, 0}
};

//TODO: Add file reading for gauge readout
FLOAT64 FSAPI fuel_needle_cb( PELEMENT_NEEDLE pelement )
{
    static int time = 18;
    static FLOAT64 realVal = 0;
    FLOAT64 val = pelement->source_var.var_value.n;
        if (time >= 18) {
            int ival;
            std::ifstream file("data.txt");
            file >> ival;
            val = ival;
            realVal = val;
            file.close();
            time = 0;
        }
        else {
            time++;
            val = realVal;
        }

    return val;
}

MAKE_NEEDLE
(
    fuel_needle,
    BMP_FUEL_SMALL_NEEDLE,
    NULL,
    NULL,
    IMAGE_USE_TRANSPARENCY|IMAGE_USE_ERASE|IMAGE_BILINEAR_COLOR,
    0,
    150, 150,
    6, 12,
    TOTAL_FUEL_QUANTITY_GALLONS,fuel_needle_cb,
    fuel_nonlinearity,
    0
)


PELEMENT_HEADER        fuel_needle_list[] =
{
    (PELEMENT_HEADER)&fuel_needle,
    NULL
};


/////////////////////////////////////////////////////////////////////////////
MAKE_STATIC
(
    fuel_background,
    BMP_FUEL_SMALL_BACKGROUND,
    &fuel_needle_list,
    NULL,
    IMAGE_USE_TRANSPARENCY,
    0,
    9, 0
)

PELEMENT_HEADER        fuel_list    = &fuel_background.header;

/////////////////////////////////////////////////////////////////////////////
MOUSE_BEGIN( fuel_mouse_rect, HELPID_GAUGE_FUEL, 0, 0 )
MOUSE_END


/////////////////////////////////////////////////////////////////////////////
#undef GAUGE_NAME
#undef GAUGEHDR_VAR_NAME
#undef GAUGE_W
Any help is appreciated!
 

DragonflightDesign

Resource contributor
Messages
760
Country
northernireland
Have you tried stepping though with a debugger to see what is actually being returned? I still use fopen(), fclose(), etc. rather than C++ streams so I can't help with 'is the code okay?'.
 
Messages
7
Country
us-florida
Have you tried stepping though with a debugger to see what is actually being returned? I still use fopen(), fclose(), etc. rather than C++ streams so I can't help with 'is the code okay?'.
I'll do this tomorrow and let you know how it goes. Your guide is godly by the way. I have learned so much more with that than with just the documentation.
 
Messages
7
Country
us-florida
Have you tried stepping though with a debugger to see what is actually being returned? I still use fopen(), fclose(), etc. rather than C++ streams so I can't help with 'is the code okay?'.
I figured out that I just had the file I was reading from in the wrong location. I had it in the gauges folder instead of the main FSX folder with the exe where it should be.
 

DragonflightDesign

Resource contributor
Messages
760
Country
northernireland
Yeah, that's caught a few people out. One of the first things that any aircraft of mine does is to load a set of paths to various sim folders so I can read/write anything/anywhere as needed.
 
Top