Coding the COMM Radio and Using a Swap Button

This shows you how to code a COMM radio for FS2000. We also goes into detail on how to add a functioning Swap button for a dual Active/Standby frequency display

While at first this may seem daunting, it is quite easy, and you can always leave out the Swap functionality for now if you wish


Prerequisites:
You must have Peter Dowson's EPIC.VXD loaded and working correctly

The EPL Header:
A typical EPL file will start with something like
what you see on the right. It loads macros such as a #Divide function, and enables the use of Peter Dowson's EPIC.VXD
  EPL HEADER
#include EPICVXD.INC
#include MACROS.HPL
#define FASTSCAN 0
#define SLOWSCAN 1
#define OUTPUT 2
definemodule(0, FASTSCAN, 0, 3) definemodule(0, SLOWSCAN, 4, 3) definemodule(0, OUTPUT, 0, 8)
definemodule(1, SLOWSCAN, 0,16)

Start by defining the display numbers which will be addressed later on in the EPL code. My numbers will vary from yours, as the physical wiring will be different for each sim project.
  #define C1_STB_LO 48
#define C1_STB_HI 50
#define C1_ACT_LO 52
#define C1_ACT_HI 54

Flag COM1_FLAG will be used to track the status of the SWAP button later on.

  Flag(COM1_FLAG, False)
These are the variables you will need to make the COMM1 radio and swap functions work correctly.
  Var16(Remdr)
var16(Temp16)
var(Temp)
var(temp8)
var(Result)
var(var_VHF1stby_d, 0) var(var_VHF1stby_h, 18) var(var_VHF1act_d) var(var_VHF1act_h) var(var_VHF1tmp_d) var(var_VHF1tmp_h)
word(wrd_VHF1)

Now we define the displays and their behavior. This is really saying: "The Display called C1_STB_LO is on Module #2, begins at Digit #48 and contains 2 digits. The 0b11111111 merely turns on and off the decimal point.

A closer look reveals that the display named C1_STB_HI has a decimal point turned on because of the zero in '0b11111110'

definedisplay(C1_STB_LO, 2, 48, 2, 0,0,FALSE, 0b11111111)
definedisplay(C1_STB_HI, 2, 50, 2, 0,0,FALSE, 0b11111110)
definedisplay(C1_ACT_LO, 2, 52, 2, 0,0,FALSE, 0b11111111)
definedisplay(C1_ACT_HI, 2, 54, 2, 0,0,FALSE, 0b11111110)

Now, if you want EPIC to automaticaly update your displays, you have to write the following. DefinePH enables (in this case) a routine called COMM_DISP to be called every time the value in PH1 changes. Pigeon hole #1 contains the value for COMM1

DefinePH(1, COMM_DISP, 0,0,0,0) ;COMM 1 Frequency Display


A simple routine, COM1_TOGGLE is called every time the integrated rotary pushbutton is pressed. This allows us to tune both the lower and upper digits of COMM1

:COM1_TOGGLE
{IF(COM1_FLAG) {CLEARFLAG(COM1_FLAG)}
ELSE {SETFLAG(COM1_FLAG)}}

Now it gets ugly. This is the routine that swaps the active and standby displays. It utilizes the MAKEDEC16, which is in the macro file EPICVXD.Inc. If your EPICVXD.Inc file doesn't contain the MAKEDEC etc facilities, you do not have an up-to-date version. Make sure your EPICVXD.Inc file is up to date, otherwise your compiler will fail on these facilities

:COM1_SWAP{
Setvar(var_VHF1tmp_h, var_VHF1stby_h)
Setvar(var_VHF1tmp_d, var_VHF1stby_d)
#Expand getPH8(var_VHF1stby_d, 0x0001)
#Expand getPH8(var_VHF1stby_h, 0x0101)
#Expand Makedec16(wrd_VHF1, var_VHF1tmp_h, var_VHF1tmp_d)
Enque16(SetBCDPov5, wrd_VHF1)
SETDISPLAY(C1_STB_LO, var_VHF1stby_d)
SETDISPLAY(C1_STB_HI, var_VHF1stby_h)
}

Even uglier is this routine called when the rotary knob is turned to tune the radio. I should add that you can call your variables anything you want. It will be easier if you develop your own naming standard and exercise strict adherence to the standard when you write your own EPL code.

:COM1_FREQ
{IF(COM1_FLAG){IFACTIVE(183)
{ADDVAR(var_VHF1stby_d, 1)
IFVAR(var_VHF1stby_d, GT, 99)
{SETVAR(var_VHF1stby_d, 0)}
}
ELSE{SUBVAR( var_VHF1stby_d, 1)
IFVAR( var_VHF1stby_d, LT, 1 )
{SETVAR( var_VHF1stby_d, 100)}}
}
ELSE{IFACTIVE(183)
{ADDVAR(var_VHF1stby_h, 1)
IFVAR(var_VHF1stby_h, GT, 36)
{SETVAR(var_VHF1stby_h, 18)}
}
ELSE{SUBVAR( var_VHF1stby_h, 1)
IFVAR( var_VHF1stby_h, LT, 18 )
{SETVAR( var_VHF1stby_h, 36)}}
}
;UPDATE DISPLAY HERE
SETDISPLAY(C1_STB_LO, var_VHF1stby_d)
SETDISPLAY(C1_STB_HI, var_VHF1stby_h)

}

Remember this? It's called by DefinePH way up at the top. Pretty simple but remember your display numbers will vary from mine, so document what each display in your EPIC setup represents!

:COMM_DISP{
#expand getPH8(var_VHF1act_d, 0x0001)
setdisplay(C1_ACT_LO, var_VHF1act_d)
#expand getPH8(var_VHF1act_h, 0x0101)
setdisplay(C1_ACT_HI, var_VHF1act_h)
}

Almost done. Now we're at the bottom of the EPL file. Buttons 148 and 149 aren't COMM-related, they are just the button numbers that happen to be wired up to my COMM radio. Your numbers will vary.

DefineButton(148, ON, COM1_SWAP) ;Active/Standby SWAP button

Button 149 is the integrated rotary pushbutton to toggle if I'm tuning the high digits or the low digits. Example: in 123.00, 123 are the high digits, and 00 are the low digits

DefineButton(149, ON, COM1_TOGGLE)

This is the rotary control routine. COM1_FREQ is called when it goes on & off.

DefineButton(182, ON, COM1_FREQ)
DefineButton(182, OFF, COM1_FREQ)

That's it for the EPL file. The only thing left is to modify your FS2000.CFG file to use the SetBCDPOVx facility. Since I used SetBCDPOV5, we'll use that for an example:

Here's my FS2000.CFG that allows the SWAP facility:

[JOYSTICK_05]
LOCKED=1
TYPE=0
AXIS_FLAGS=64
AXIS_EVENT_06=COM_RADIO_SET
AXIS_SCALE_06=1
AXIS_NULL_06=0

That's it! This is a very complicated undertaking, but if you really want the authenticity of the big airliners, you will need the SWAP button.