Anyone having problems looking up MODULE_VARs?

#3
No. Not at all. Everything works just as expected. What exactly is happening (or not happening) in your gauges?
Well, the variables (mine, not FS's) are not getting initialized apparently as there is just garbage in them instead of the com freq's. I use the same code in both FS9, and FS X:

wstring RadioPage::GetCom1Active()
{
lookup_var(&m_com_frequency);
lookup_var(&m_com_radio_25_khz_tunable);

UINT32 bcd = m_com_frequency.var_value.d;

m_Com1Freq[0] = '1';
m_Com1Freq[1] = ((bcd >> 12) & 0xF) + 0x30;
m_Com1Freq[2] = ((bcd >> 8) & 0xF) + 0x30;
m_Com1Freq[3] = '.';
m_Com1Freq[4] = ((bcd >> 4) & 0xF) + 0x30;
m_Com1Freq[5] = ((bcd) & 0xF) + 0x30;
if(m_Com1Freq[5] == '2' || m_Com1Freq[5] == '7')
{
m_Com1Freq[6] = '5';
m_Com1Freq[7] = '\0'; // NULL Terminator
}
else
{
m_Com1Freq[6] = '\0'; // NULL Terminator
}
m_Com1Freq[7] = '\0'; // NULL Terminator

return m_Com1Freq;
}

So, I'm baffled as to why they don't make it into the vars in FSX. In FS9, they show up as planned, in FS X there is just random stuff put on the screen instead of the freq's.
 

ddawson

Resource contributor
#4
UINT32 bcd = m_com_frequency.var_value.d;

Patrick,

Try:
UINT32 bcd = (UINT32)m_com_frequency.var_value.n;

I think you will find that all numeric values are returned as floats, even the ones that would be more appropriate in another format.

Doug
 

n4gix

Resource contributor
#6
UINT32 bcd = m_com_frequency.var_value.d;

Patrick,

Try:
UINT32 bcd = (UINT32)m_com_frequency.var_value.n;

I think you will find that all numeric values are returned as floats, even the ones that would be more appropriate in another format.

Doug
Odd, that... This routine still seems to work fine in FSX, considering that I'm still reading the .d member:

double COM2freq=0;
WCHAR com2freq_wch[8] = L"";

sprintf(charWork, "1%02x.%02x", COM2_bcd.var_value.d/256, COM2_bcd.var_value.d % 256);
COM2freq = atof(charWork);
swprintf(com2freq_wch, L"%3.3f", COM2freq);

Note also the rather neat way to obtain the decimal display of the freq without having to use any BCD2DEC conversion... ;)
 
#8
This is all fixed for me thanks to help from Doug. Turned out it was just my not getting the number of bytes returned in my printf's right, or the length of my WCHAR[]'s.

Thanks Doug.
 
Top