RotarySwitch Class
FG Int Switches Classes |
---|
Navigation |
Switches Class RotarySwitch will be used to manage standard and binary rotary switches.
Standard Rotary Switch are one to one : one position , one pin active.
Binary Rotary Switch give binary code regarding the position.
Number of input depend on how many position you need
Rotary Switches Configuration File
Displays configuration file : /opt/fgint/Config/EfisPanel/rotswitches.cfg
This file describes the rotary switches configuration that setup the ND modeused on the A320 / A330 EFIS panels. It's a standard rotary switch (bincode propoerty is set to 0)
Values to send to simulator for this switch are :
- ils for ils mode
- vor for vor mode
- nav for nav mode
- arc for arc mode
- plan for plan mode
There are two separate parts in this file.
- a general configuration part, in the CONF and PROPERTIES sections.
- the other sections each describe a display.
[CONF]
confname=ROTSWITCHES
library=FGIntSwitch
module=RotarySwitch
properylist=device,name,nbpos,pins,values,valuestype,node,bincode
[PROPERTIES]
prop01=device
prop02=name
prop03=nbpos
prop04=pins
prop05=values
prop06=valuestype
prop07=node
prop08=bincode
[EFIS0ROSERSW]
device=IOPACK1
name=efis0rosersw
nbpos=5
pins=B5,B4,B3,B2,B1
values=ils,vor,nav,arc,plan
valuestype=str
node=None
bincode=0
CONF Section
The CONF describe what type of object are describe here and how they will be built.
- confname : Nothing special here, just a name to set about what we are talking about.
- library : FG Interface python library from which the class will be loaded.
- module : Module name (Class name) in the library file that will be loaded. Here we are using the RotarySwitch Class
- propertylist : List of parameter that are needed to create a rotary switch object.
PROPERTIES Section
Properties section is defined to declare and order each parameter that is needed to create the elements (Super Class FGInt RotarySwitch in that case, take some parameters to create a switch object, as the input where the switch is connected on the interface). This is how the interface will be able to understand and use the switch configurations to create them.
For Rotary Switches, to create one, you will need to provide for each required parameters. And the section gives the order in which the parameters will be called when creating the object.
[PROPERTIES]
prop01=device # Device Logical Name
prop02=name # Switch Name
prop03=nbpos # Number of position to manage
prop04=pins # MCP23017 input list where the switch is connected (format is portpin Ex : B5 is pin 5 on port B)
prop05=values # Values sent in position order seperate by coma (pos1val, pos2val, pos3val ... etc)
prop06=valuestype # Typed Values that is used with this switch
prop07=node # FG Property that is manage by the switch
In PROPERTIES section, you have to provide parameters name and in which order. With this, FG interface just have to read parameters for each object and use them to create each object.
Creating Switches
The order of the parameters does not fall from the sky. If we look more closely at the Class "RotarySwitch" in the FGIntSwitch.py
class RotarySwitch:
"""
Rotary Switch
"""
###############
# Properties
###############
###############
# Constructor
###############
def __init__(self, device, name, nbpos, pins, values, valuestype, node, bincode, debug=0):
here how double switches should be instantiated: To create a double switch with this class you have to call :
RotarySwitch(device, name, nbpos, pins, values, valuestype, node, bincode, [debug])
"debug" is not mandatory. If not provide, il will be automaticly set to 0
But as already explained several times, you should not have to call this method directly. In normal operation, the objects will be created via the methods of the interface itself (with the createElement() and/or createElements() methods)
Switches Methods
getName()
Return the switch Name according the configuration
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('efispanel.cfg', 0)
>>> FGINT1.createDevices()
>>> FGINT1.createElements()
>>> EFIS0ROSERSW = FGINT1.getElement('EFIS0ROSERSW')
>>> EFIS0ROSERSW.getName()
'efis0rosersw'
>>>
getPins()
Return the input list defined in the configuration
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('efispanel.cfg', 0)
>>> FGINT1.createDevices()
>>> FGINT1.createElements()
>>> EFIS0ROSERSW = FGINT1.getElement('EFIS0ROSERSW')
>>> EFIS0ROSERSW.getPins()
{0: {'port': 'B', 'pin': '5'}, 1: {'port': 'B', 'pin': '4'}, 2: {'port': 'B', 'pin': '3'}, 3: {'port': 'B', 'pin': '2'}, 4: {'port': 'B', 'pin': '1'}}
>>>
getValues()
Return values tab
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('efispanel.cfg', 0)
>>> FGINT1.createDevices()
>>> FGINT1.createElements()
>>> EFIS0ROSERSW = FGINT1.getElement('EFIS0ROSERSW')
>>> EFIS0ROSERSW.getValues()
['ils', 'vor', 'nav', 'arc', 'plan']
>>>
getValueType()
Return the type of value that is used witch this switch. Can be bool (boolean), int (integer) or string (string) according with the configuration file.
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('efispanel.cfg', 0)
>>> FGINT1.createDevices()
>>> FGINT1.createElements()
>>> EFIS0ROSERSW = FGINT1.getElement('EFIS0ROSERSW')
>>> EFIS0ROSERSW.getValueType()
'str'
>>>
getNode()
Return the node that is manage by the switch according the configuration file. Node property is not used actually, but could be used to create protocol xml file.
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('efispanel.cfg', 0)
>>> FGINT1.createDevices()
>>> FGINT1.createElements()
>>> EFIS0ROSERSW = FGINT1.getElement('EFIS0ROSERSW')
>>> EFIS0ROSERSW.getNode()
'None'
>>>
getSwitchState()
Return the actual state of the switch by reading the I/O Device
Rotary switch on 'ILS' position
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('efispanel.cfg', 0)
>>> FGINT1.createDevices()
>>> FGINT1.createElements()
>>> EFIS0ROSERSW = FGINT1.getElement('EFIS0ROSERSW')
>>> EFIS0ROSERSW.getSwitchState()
'ils'
>>>