C: Decimal to BCD: Difference between revisions
From FSDeveloper Wiki
Jump to navigationJump to search
(New page: {{Infobox-Applicable-FSVersion | FSXI = false | FSXA = true | FSX = true | FS2004 = true | FS2002 = false | FS2000 = unknown | FS98 = unknown }} == C: BCD to Decimal and Decimal to BCD == ...) |
|||
| (6 intermediate revisions by 2 users not shown) | |||
| Line 4: | Line 4: | ||
| FSX = true | | FSX = true | ||
| FS2004 = true | | FS2004 = true | ||
| FS2002 = | | FS2002 = true | ||
| FS2000 = | | FS2000 = true | ||
| FS98 = | | FS98 = true | ||
}} | }} | ||
== C: BCD to Decimal and Decimal to BCD == | == C: BCD to Decimal and Decimal to BCD == | ||
| Line 30: | Line 30: | ||
Bcd2Dec(bcd_number) for BCD to decimal and | Bcd2Dec(bcd_number) for BCD to decimal and | ||
Dec2Bcd(dec_number) for decimal to BCD conversions. | Dec2Bcd(dec_number) for decimal to BCD conversions. | ||
In order to send frequencies to the ADF radios, multiply the desired frequency by 10000: | |||
float adf_freq = 0; | |||
adf_freq = 286.5; | |||
trigger_key_event(KEY_ADF_COMPLETE_SET, Dec2Bcd(adf_freq*10000)); | |||
In order to send frequencies to the COM or NAV radios, multiply the desired frequency by 100: | |||
float com_freq = 0; | |||
com_freq = 122.875; | |||
trigger_key_event(KEY_COM_RADIO_SET, Dec2Bcd(com_freq * 100));//Change the event ID as needed for the NAV radio or the particular COM radio you wish to set | |||
[[Category:Aircraft Design]] | [[Category:Aircraft Design]] | ||
[[Category:Panel and Gauge Design]] | [[Category:Panel and Gauge Design]] | ||
Latest revision as of 14:39, 5 December 2017
C: BCD to Decimal and Decimal to BCD
This scheme was supplied by Arne Bartels which allows BCD conversion in both directions. Add the following to the master source file:-
#include <math.h>
#define Bcd2Dec(BcdNum) HornerScheme(BcdNum,0x10,10)
#define Dec2Bcd(DecNum) HornerScheme(DecNum,10,0x10)
UINT32 HornerScheme(UINT32 Num,UINT32 Divider,UINT32 Factor)
{
UINT32 Remainder=0,Quotient=0,Result=0;
Remainder=Num%Divider;
Quotient=Num/Divider;
if(!(Quotient==0&&Remainder==0))
Result+=HornerScheme(Quotient,Divider,Factor)*Factor+Remainder;
return Result;
}
Then for each sub-gauge that requires a BCD conversion use the following syntax:-
Bcd2Dec(bcd_number) for BCD to decimal and Dec2Bcd(dec_number) for decimal to BCD conversions.
In order to send frequencies to the ADF radios, multiply the desired frequency by 10000:
float adf_freq = 0; adf_freq = 286.5; trigger_key_event(KEY_ADF_COMPLETE_SET, Dec2Bcd(adf_freq*10000));
In order to send frequencies to the COM or NAV radios, multiply the desired frequency by 100:
float com_freq = 0; com_freq = 122.875; trigger_key_event(KEY_COM_RADIO_SET, Dec2Bcd(com_freq * 100));//Change the event ID as needed for the NAV radio or the particular COM radio you wish to set