;CHAFF/FLARE CONTROLER DISPLAY phy digits 0-3... 2 displays of 2 digits each display definedisplay(1,2,0,2,0,0,false,0b00000011) ;flares definedisplay(2,2,2,2,0,0,false,0b00000011) ;chaff :init {setinterkey(1) ;initialize the displays, #1 is flares #2 is Chaff setdisplay(1,30) ;note this is the display value only not the variable count!!!! setdisplay(2,60) ;the variable is set later in the code! ;VARIABLES ; like right here! var (chaff_count,60) ; sets the number of chaff avail var (flare_count,30) ; sets the number of flares avail var (flare_lnch,0) ; var for count loop of multi launch var (chaff_lnch,0) ; ditto ;FLAGS flag(CM) ;Null flag.... see note 3 flag(AR) ;a flag that the switch is in the Auto Release Mode flag(MR) ;Null flag... see note 3 flag(AO) ;a flag that the switch is in the Manual Release Mode flag(SR) ;Null flag ;FLARE CHAFF CONTROLER :CMArmed {if (AR) ;when you arm the CM controler check state of AutoReleas Mode {althit (z) ;if it is in auto send a keypress to the software } ;See note 1 for a more in depth explanation of these blocks!!!! } :CMoff {if (AO) ;check the Release Mode, if it is in Manual.... jump return ;do nothing else ;if it isn't in manual {althit (z) ;switch it to manual when you Unarm the Countermeasures } ;this effectively turns off the Auto Mode if you shut down the Controler!!! } :Multion {setflag (MR)} ;Null procedure, see note 3 :Singleon {setflag (SR)} ;Null proceedure, see note 3 :Autorel {setflag (AR) ;if the switch is in Auto mode set the flag to tell switch position!!! clearflag (AO) ;since you are in Auto you clear the Manual flag {ifactive (176) ;if the Arm Switch is active, send a keypress to the software.....normal {althit (z)} ;operation of the switch... see note 4 } } :Manualrel {clearflag (AR) ;sets the flag to match switch position, auto off this line.... setflag (AO) ;and manual on this line! {ifactive (176) ;Normal operation of the switch for the software {althit (z)} ;sends the usual keypress to toggle } } :flarerel {ifactive (176) ;checks to see if button (176) {countermeasures is on} active {keyhit (z) ;simple keypress to the software to release a flare subvar (flare_count,1) ;decrements the number of flares available subdisplay(1,1) ;decrements the display to ensure sync with the software } } :Chaffrel {ifactive (176) ; see above, same procedure but for chaff, {keyhit (x) ; keypress to release a chaff pod, software subvar(chaff_count,1) ;decrements the available chaff subdisplay(2,1) ;decrement the chaff display } } :MultirelF {ifactive (176) ;if the switch is set to ARMED proceed with block {ifactive (180) ;if the switch is in the Multi postion proceed with otherwise go to singel rel block {keyhit (z) ;kepress to lauch a flare delay (10) ;delay is to time flare lauches and prevent overflow of the stack, see note 2 subvar (flare_count,1) ;decrement the available flares by 1 subdisplay(1,1) ;decrement the display by 1 addvar (flare_lnch,1) ;start counting the number of launches {ifvar (flare_lnch,LT,3) ;if you have not launched 3 flares yet.... or count up to 3 then exit Jump MultirelF ;return to the launch block,(recurse) else call resetflare ;reset the launch count } } else jump flarerel} ;if multi swicth is off, go to single release } :MultirelC {ifactive (176) ;see MultirelF for each line... {ifactive (180) {keyhit (x) delay (10) subvar (chaff_count,1) subdisplay(2,1) addvar (chaff_lnch,1) {ifvar (chaff_lnch,LT,3) Jump MultirelC else call resetchaff } } else jump chaffrel} } :resetflare {setvar (flare_lnch,0)} :resetchaff {setvar (chaff_lnch,0)} ;COUNTERMEASURES definebutton(176,on,CMArmed) definebutton(176,off,CMoff) definebutton(177,on,MultirelF) definebutton(178,on,MultirelC) definebutton(179,on,Autorel) definebutton(179,off,Manualrel) definebutton(180,on,Multion) definebutton(181,on,Singleon) Note 1: A toggle (the same keypress either sets it on or off, either in the software or the switches...) in this case the switch is a SPST which means either one of two postions is always ON. now this can have advantages and disadvantages... the advantage is that since one of two settings is always active, for simulator purposes you can use it to control whether another switch will work or not with very little programming... see the :Flarerel example above. If it is on the next switch will send an output, if it is off it will do nothing... this works well for momentary switches that only send a keypress to the EPIC/software..... HOWEVER... it can cause some sync problems with toggle switches.... if the "master" switch is off, the second switch can change positions without sending a signal to the EPIC/software. Consider this, if the Armed switch is OFF we can set the auto/manual switch to the manual position without sending a signal to the EPIC/software that such a position change has occured... so then we turn the Arm switch ON and flip the toggle switch... now the toggle has move from auto to manual, (hardware) and sends a keypress to the software as it is programed to do... however the software is in the manual position and now switches to the auto postion.... but our simulator switch is in the manual position... and we are out of sync... So what are our choices..... We can use flags.... but they suffer from the same problem that a toggle does, it is either true or false, on or off, using the same comparison above just use flag instead of switch... logically the result is the same, and again we are chasing the software with our switches instead of the software following or switches!!! BUT!!!!! There is a way around this... using flags (cheshire cat grin) Instead of making one switch (the auto/manual) dependent on the state of the "Master"... we ingeniously reverse the case, making what happens when the "MASTER" is activated, or deactivated, dependent on what the secondary switch position is.... look closely at how the :CMArmed and the :CMOff proceedures work... When the countermeasures are turn on it uses the flags to check the position of the Man/Auto switch... if the switch is in the manual position it does nothing!!! it is ONLY, repeat ONLY looking to see if flag (AR) is true... if so it sends a keypress to the software to "activate" the Auto mode... Now when you shut down the Countermeasures is looks again... BUT this time to see if the switch is in the MANUAL mode, if not it sends a keypress to shut off the Auto and return to manual mode! Look closely at how the flags are switched as the position changes in the :AutoRel and :ManualRel blocks, the thing to see is how the switch changes the flag state BEFORE sending any keypresses... it is the sequence of functions here that make the CMarmed and CMoff proceedure blocks work correctly!!! Essentially in :AutoRel and ManualRel there are two totally seperate things happening during thread execution... Setting flags for the :CMarmed/:CMoff proceedure blocks and simply toggling the software to either state when the switch is flipped AND the thing is armed, if the CMArmed switch is OFF it only keeps track of it's own position thru flags!! Note 3: In order to define a button it is my understanding, of the EPIC PL (and experience thru trial and error as well), that a procedure must be associtated with it. In many cases when building a simulator we wish only to read a button state, not necessarily do any sort of hardware or software procedure... In order to accomplish this I have utilized Null flags... as written above, flags have good uses, but can be a HUGH problem keeping them in the right state thru repetative proceedures, however I have found that setting them or clearing them makes for great Null prodecures! they generally do nothing to the software or hardware except exist and keep the EPL compiler happy with the order of things... I believe that you are supposed to be able to set a {return} as a null proceedure as well, however I've never had it work so... the flag thing is my method... if anyone can enlighten me I'd be most happy to switch methods! Note 4: generally I've found it easier and more straight forward to utilize an ifactive statement rather than a flag.... they also added bonus of always being already "set" and not needing to be initialized in some fashion. If you notice in test128 that there are always some buttons "ON". for example if you don't care to go thru a series of steps (preflight) your simulator, you can simply set the buttons to the proper positions and the proceedure blocks will already be functioning for you! ie the Countermeasures pannel... by using the active statement... you can already have your the thing armed, auto on, and Multirelease options set before the software even loads! Once airborne no need to worry about flipping a series of switches to defined yourself, just start dumping chaff and flares till your empty! Final Comments: Written for Falcon 4.08i, EPIC and so on and so forth... The panel defined above has 5 switches... momentary PB flare, momentary PB chaff, DPDT single/multi switch, SPST Master Arm, and a SPST Manual/Auto release modes (don't confuse manual with multi/single, manual only means YOU activate the lauch of countermeasures... Auto is a software function of the plane... if a launch is detected by the TWS against you it will Automatically dispense countermeasures! Multi is a manual multi launch by the pilot, either thru the buttons or a call from the HOTAS, just reference the procedures above from the stick buttons, and it also keeps track on the digital display as well! Doug "Loco" Meador