DoubleSwitch Class
FG Int Switches Classes |
---|
Navigation |
Switches Class DoubleSwitch will be used to manage standard 3 position switches (2 input needed per switch) and is based on the MCP23017.
Double Switches Configuration File
Displays configuration file : /opt/fgint/Config/OverHeadPanel/dblswitches.cfg
This file describes the double switch Strobe Light configuration used on the External & Internal Light panel on the Overhead.
Values to send to simulator for this switch are :
- 0 for off
- 0.5 for auto
- 1 for on
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=DBLSWITCHES
library=FGIntSwitch
module=DoubleSwitch
properylist=device,name,port,pin1,pin2,values,valuestype,node
[PROPERTIES]
prop01=device
prop02=name
prop03=port
prop04=pin1
prop05=pin2
prop06=values
prop07=valuestype
prop08=node
[LTSSTROBESW]
name=ltstrobesw
device=IOPACK5
port=A
pin1=8
pin2=7
values=0,0.5,1
valuestype=int
node=None
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 DoubleSwitch Class
- propertylist : List of parameter that are needed to create a double switch object.
PROPERTIES Section
Properties section is defined to declare and order each parameter that is needed to create the elements (Super Class FGInt Switches 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 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=port # MCP23017 port where the switch is connected
prop04=pin1 # MCP23017 input1 where the switch is connected
prop04=pin2 # MCP23017 input2 where the switch is connected
prop05=values # Values that will be provided for the switch state (order is pin state dependant : pin1=1 & pin2=0 => value1, pin1=0 & pin2=0 => value2, pin1=0 & pin2=1 => value3)
prop06=valuestype # Typed Values that is used with this switch
prop07=invert # Describe if the input need to be manage inverted [ activate = 0 ]
prop08=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 "DoubleSwitch" in the FGIntSwitch.py
class DoubleSwitch:
"""
"""
###############
# Properties
###############
###############
# Constructor
###############
def __init__(self, device, name, port, pin1, pin2, values, valuestype, node, debug=0):
here how double switches should be instantiated To create a double switch with this class you have to call :
DoubleSwitch(device, name, port, pin1, pin2, values, valuestype, invert, node, [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, Jan 22 2021, 20:04:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('overheadpanel.cfg')
>>> FGINT1.createDevices()
>>> FGINT1.createElements()
>>> LTSSTROBESW = FGINT1.getElement('LTSSTROBESW')
>>> LTSSTROBESW.getName()
'ltstrobesw'
>>>
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, Jan 22 2021, 20:04:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('overheadpanel.cfg')
>>> FGINT1.createDevices()
>>> FGINT1.createElements()
>>> LTSSTROBESW = FGINT1.getElement('LTSSTROBESW')
>>> LTSSTROBESW.getValueType()
'int'
>>>
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, Jan 22 2021, 20:04:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('overheadpanel.cfg')
>>> FGINT1.createDevices()
>>> FGINT1.createElements()
>>> LTSSTROBESW = FGINT1.getElement('LTSSTROBESW')
>>> LTSSTROBESW.getNode()
'None'
>>>
getTypedData()
Return the typed value given as agument according to what have been set in the valuestype property
Python 3.7.3 (default, Jan 22 2021, 20:04:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('overheadpanel.cfg')
>>> FGINT1.createDevices()
>>> FGINT1.createElements()
>>> LTSSTROBESW = FGINT1.getElement('LTSSTROBESW')
>>> LTSSTROBESW.getTypedData('0')
0
>>> LTSSTROBESW.getTypedData('1')
1
>>>
getSwitchState()
Return the actual state of the switch by reading the I/O Device
Double Switch in postiion 1
Python 3.7.3 (default, Jan 22 2021, 20:04:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('overheadpanel.cfg')
>>> FGINT1.createDevices()
>>> FGINT1.createElements()
>>> LTSSTROBESW = FGINT1.getElement('LTSSTROBESW')
>>> LTSSTROBESW.getSwitchState()
'0'
>>>
Double Switch in postiion 2
>>> RMP0PWSW.getSwitchState()
'0.5'
>>>
Double Switch in postiion 3
>>> LTSSTROBESW.getSwitchState()
'1'
>>>
Combined with the value typing function
>>> LTSSTROBESW.getTypedData(LTSSTROBESW.getSwitchState()) # Switch in position 1
0
>>> LTSSTROBESW.getTypedData(LTSSTROBESW.getSwitchState()) # Switch in position 2
0.5
>>> LTSSTROBESW.getTypedData(LTSSTROBESW.getSwitchState()) # Switch in position 3
1
>>>