Switch Class: Difference between revisions

3,086 bytes added ,  2 December 2019
Adding Switches Methods
(Initial Création)
 
(Adding Switches Methods)
Line 52: Line 52:
node=None
node=None
invert=0
invert=0
</syntaxhighlight>
=== 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 '''Switch''' Class
* '''propertylist''' : List of parameter that are needed to create a '''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.
<syntaxhighlight lang="ini">
[PROPERTIES]
prop01=device
prop02=name
prop03=port
prop04=pin
prop05=values
prop06=valuestype
prop07=invert
prop08=node
</syntaxhighlight>
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 "Switch" in the '''FGIntSwitch.py'''
<syntaxhighlight lang="python">
class Switch:
    """
    """
    ###############
    # Properties
    ###############
    ###############
    # Constructor
    ###############
    def __init__(self, device, name, port, pin, values, valuestype, invert, node, debug=0):
</syntaxhighlight>
here how switches should be instantiated:
To create a switch with this class you have to call :
<syntaxhighlight lang="code">
Switch(device, name, port, pin, values, valuestype, invert, node, [debug])
</syntaxhighlight>
"'''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 ==
=== 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.
<syntaxhighlight lang="python">
</syntaxhighlight>
=== getNode() ===
Return the node that is manage by the switch according the configuration file.
<syntaxhighlight lang="python">
</syntaxhighlight>
=== getTypedData() ===
Return the typed value given as agument
<syntaxhighlight lang="python">
</syntaxhighlight>
=== getSwitchState() ===
Return the actual state of the switch by reading the I/O Device
<syntaxhighlight lang="python">
</syntaxhighlight>
</syntaxhighlight>
534

edits