FGInt SwitchLight

From FlightGear wiki
Jump to navigation Jump to search

SwitchLight class will be used to manage "annunciator" light. Base on the HT16K33 chipset, this Class let you manage all the annunciator light you will need. With one HT16K33 you can manage up to 128 annunciator light.

Switch lights displays Class SwitchLight will be used to manage announciator light. Based on the HT16K33, this Class will let you manage up to 128 led.

Why the light is not in the same class as the switch, simply because it is not the same chip as for the switch

Switch Light Configuration File

Displays configuration file : /opt/fgint/Config/RadioPanel/swlights.cfg
This file describes the configuration of the switchlights of the radio panel.
There are two separate parts in this file.

  1. a general configuration part, in the CONF and PROPERTIES sections.
  2. the other sections each describe a display.
[CONF]
confname=SWLIGHTS
library=FGIntSwDisplay
module=SwitchLight
properylist=device,lightname,nblight,port,row,out1,prop,initstate,activemode
createmethod=createDisplays

[PROPERTIES]
prop01=device
prop02=lightname
prop03=nblight
prop04=port
prop05=row
prop06=out1
prop07=prop
prop08=initstate
prop09=activemode

[VHF1SWL]
device=LEDPACK1
lightname=vh1swl
nblight=1
port=B
row=7
out1=1
prop=systems/radio/rmp[0]/sel_chan
initstate=0
activemode=1

[VHF2SWL]
device=LEDPACK1
lightname=vhf2swl
nblight=1
port=B
row=7
out1=8
prop=systems/radio/rmp[0]/sel_chan
initstate=0
activemode=1

[VHF3SWL]
device=LEDPACK1
lightname=vhf3swl
nblight=1
port=B
row=7
out1=3
prop=systems/radio/rmp[0]/sel_chan
initstate=0
activemode=1

[HF1SWL]
device=LEDPACK1
lightname=hf1swl
nblight=1
port=B
row=7
out1=2
prop=systems/radio/rmp[0]/sel_chan
initstate=0
activemode=1

[HF2SWL]
device=LEDPACK1
lightname=hf2swl
nblight=1
port=B
row=7
out1=7
prop=systems/radio/rmp[0]/sel_chan
initstate=0
activemode=1

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.
  • propertylist : List of parameter that are needed to create a switch light object.
  • createmethod : Method from FG interface Class that will be used to create switch light objects.

propertylist and createmethod are deprecated and will be removed in the next release.

PROPERTIES Section

Properties section is defined to declare and order each parameter that is needed to create the elements (Super Class FGInt Segment Display in that case, take some parameters to create a display object, as like Number of digit, Common of the fist digit ... etc). This is how the interface will be able to understand and use the displays configurations to create them.

In Switch Lights , 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
prop02=lightname
prop03=nblight
prop04=port
prop05=row
prop06=out1
prop07=prop
prop08=initstate
prop09=activemode

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 Switch Light

The SwitchLight class

#!/usr/bin/env python3
# -*-coding:Utf-8 -*

# System Modules Import
import os
import sys
import operator
import time

# Standard Modules Import

###################################
# FarmerSoft FlightGear Interface
###################################
# DISPLAY Class (Affichage)
# FarmerSoft © 2015
# By Daweed
###################################

class SwitchLight:
    """
    Cette Class hérite de la Class de gestion des LED Pack HT16K33.
    Elle permet la gestion des témoin lumineux d'un switch.
    Copyright FarmerSoft 2014 (c)
    """

    ###############
    # Properties
    ###############

    ###############
    # Constructor
    ###############
    def __init__(self, device, lightname, nblight, port, row, out1, prop, initstate, activemode, debug=0):
    ....

here how switch lights should be instantiated:

To create a switch light with this class you have to call :

SwitchLight(device, lightname, nblight, port, row, out1, prop, initstate, activemode, [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)

Switch Light Methods

OK, so let's play with one Radio panel switch light. As definied in the configuration, the VHF1SWL is defined to be connected on the LEDPACK1, port B, row 7

[VHF1SWL]
device=LEDPACK1
lightname=vh1swl
nblight=1
port=B
row=7
out1=1
prop=systems/radio/rmp[0]/sel_chan
initstate=0
activemode=1

getName()

fgint@raspberrypi:/opt/fgint $ python3
Python 3.7.3 (default, Apr  3 2019, 05:39:12)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> FGINT1.createDevices()
>>> FGINT1.createElements()
>>> VHF1SWL = FGINT1.getElement('VHF1SWL')
>>> VHF1SWL.getName()
'vh1swl'
>>>

getLightState()

fgint@raspberrypi:/opt/fgint $ python3
Python 3.7.3 (default, Apr  3 2019, 05:39:12)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> FGINT1.createDevices()
>>> FGINT1.createElements()
>>> VHF1SWL = FGINT1.getElement('VHF1SWL')
>>> VHF1SWL.getName()
'vh1swl'
>>> VHF1SWL.getLightState()
'0'
>>>

setLightState()

fgint@raspberrypi:/opt/fgint $ python3
Python 3.7.3 (default, Apr  3 2019, 05:39:12)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> FGINT1.createDevices()
>>> FGINT1.createElements()
>>> LEDPACK1 = FGINT1.getDevice('LEDPACK1')
>>> VHF1SWL = FGINT1.getElement('VHF1SWL')
>>> LEDPACK1.configMCP(1)
>>> LEDPACK1.Start()
1
>>> VHF1SWL.getLightState()
'0'

Radio Panel Airbus, Switch Light VFH1 OFF

>>> VHF1SWL.setLightState('ON')
>>> VHF1SWL.getLightState()
'ON'

Radio Panel Airbus, Switch Light VFH1 ON

>>> VHF1SWL.setLightState('OFF')
>>> VHF1SWL.getLightState()
'OFF'
>>>

Radio Panel Airbus, Switch Light VFH1 OFF