FGInt Segment Display: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
 
(No difference)

Latest revision as of 14:47, 26 November 2019

Segments displays Class SegDisplay will be used to manage 7 segments digit displays. Based on the HT16K33, this Class will let you manage a full displays up to 8 digits per displays.

Displays Configuration File

Displays configuration file : /opt/fgint/Config/RadioPanel/displays.cfg
This file describes the configuration of the 7-segment displays 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=DISPLAYS
library=FGIntSegDisplay
module=SegDisplay
properylist=device,dispname,nbdigit,port,com1,decdigit
createmethod=createDisplays

[PROPERTIES]
prop01=device
prop02=name
prop03=nbdigit
prop04=port
prop05=com1
prop06=decdigit

[ACTVFREQ]
name=ACTVFREQ
device=LEDPACK1
nbdigit=6
com1=1
port=B
decdigit=3

[STBYFREQ]
name=STBYFREQ
device=LEDPACK1
nbdigit=6
com1=1
port=A
decdigit=3

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 display object.
  • createmethod : Method from FG interface Class that will be used to create display 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 Segment Display, 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     # Display Name
prop03=nbdigit  # Number of Digits that make up the display
prop04=port     # HT16K33 Port that will own the display
prop05=com1     # First Common that will be used for the first digit. Other common will be determined with the digit number.
prop06=decdigit # Digit number where should be the dot.

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 Displays

The order of the parameters does not fall from the sky. If we look more closely at the Class "SegDisplay" in the FGIntSegDisplay.py

class SegDisplay:
    """
    This class allow Segment Display management
    based on hardware driver HT16K33
    Copyright FarmerSoft © 2017
    By Daweed
    """

    ###############
    # Properties
    ###############
    digitnumber = {
        '0': 0x3F, '1': 0x06, '2': 0x5B, '3': 0x4F,
        '4': 0x66, '5': 0x6D, '6': 0x7D, '7': 0x07,
        '8': 0x7F, '9': 0x6F, 'A': 0x77, 'B': 0x7C,
        'C': 0x39, 'D': 0x5E, 'E': 0x79, 'F': 0x71,
        '-': 0x40, 'S': 0x6D, 't': 0x78, 'd': 0x5e,
        ' ' : 0x00
        }

    ###############
    # Constructor
    ###############
    def __init__(self, device, name, nbdigit, port, com1, decdigit, debug=0)
    .....

here how Segment display should be instantiated:

To create a 7 segment display with this class you have to call :

SegDisplay(device, name, nbdigit, port, com1, decdigit, [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)

Segments Displays Methods

getName()

Returns the display name according to you configuration.

daweed@farmerfgint:/opt/fgint $ python3
Python 3.4.2 (default, Oct 19 2014, 13:31:11) 
[GCC 4.9.1] 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()
>>> STBYFREQ = FGINT1.getElement('STBYFREQ')
>>> print(STBYFREQ)
<FGIntSegDisplay.SegDisplay object at 0x76939a50>
>>> STBYFREQ.getName()
'STBYFREQ'
>>>

getType()

Return display type.

Python 3.4.2 (default, Oct 19 2014, 13:31:11) 
[GCC 4.9.1] 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()
>>> STBYFREQ = FGINT1.getElement('STBYFREQ')
>>> print(STBYFREQ)
<FGIntSegDisplay.SegDisplay object at 0x768a8190>
>>> STBYFREQ.getType()
'Segment Display'
>>>

getDigitNumer()

Return the number of digit defined for the display according to your configuration.

Python 3.4.2 (default, Oct 19 2014, 13:31:11) 
[GCC 4.9.1] 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()
>>> STBYFREQ = FGINT1.getElement('STBYFREQ')
>>> print(STBYFREQ)
<FGIntSegDisplay.SegDisplay object at 0x768a8190>
>>> STBYFREQ.getDigitNumber()
6
>>>

getStatus()

Return the display status

Python 3.4.2 (default, Oct 19 2014, 13:31:11) 
[GCC 4.9.1] 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()
>>> STBYFREQ = FGINT1.getElement('STBYFREQ')
>>> STBYFREQ.getStatus()
'OFF'
>>>

setStatus(status)

Set the Status display. status is 'ON' of 'OFF'

Python 3.4.2 (default, Oct 19 2014, 13:31:11) 
[GCC 4.9.1] 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()
>>> STBYFREQ = FGINT1.getElement('STBYFREQ')
>>> STBYFREQ.getStatus()
'OFF'
>>> STBYFREQ.setStatus('ON')
>>> STBYFREQ.getStatus()
'ON'
>>>

listDigitsRegister()

Return display digit list according to your configuration

Python 3.4.2 (default, Oct 19 2014, 13:31:11) 
[GCC 4.9.1] 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()
>>> STBYFREQ = FGINT1.getElement('STBYFREQ')
>>> STBYFREQ.listDigitsRegister()
# Digit 1 à l'adresse 0x0

# Digit 2 à l'adresse 0x2

# Digit 3 à l'adresse 0x4

# Digit 4 à l'adresse 0x6

# Digit 5 à l'adresse 0x8

# Digit 6 à l'adresse 0xa
>>>

getDigitRegister(digit)

Return register address for the digit. Here we are getting digit register address for digit number 1, 2 and 3.
Except for development or debugging, there is no reason to invoke this method directly. It is a system method internal to the operation of the driver.

Python 3.4.2 (default, Oct 19 2014, 13:31:11) 
[GCC 4.9.1] 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()
>>> STBYFREQ = FGINT1.getElement('STBYFREQ')
>>> print(hex(STBYFREQ.getDigitRegister(1))) # Digit Nb 3 is at address 0x02
0x1
>>> 
>>> print(hex(STBYFREQ.getDigitRegister(2))) # Digit Nb 3 is at address 0x03
0x3
>>> 
>>> print(hex(STBYFREQ.getDigitRegister(3))) # Digit Nb 3 is at address 0x05
0x5
>>>

writeDigit(digit, value, decimal)

Send value' on the digit number digit. If decimal is set to 1, the dot on segement display digit will be on.

Python 3.4.2 (default, Oct 19 2014, 13:31:11) 
[GCC 4.9.1] 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')
>>> STBYFREQ = FGINT1.getElement('STBYFREQ')
>>> LEDPACK1.configMCP(1)
>>> LEDPACK1.Start()
1
>>>
>>> STBYFREQ.writeDigit(1, 2, 0) # will display '2' on digit number 1, Digit Number 1 is the first from the left (counting from left to right)
>>> 
>>> STBYFREQ.writeDigit(2,'-', 0) # will display a - on digit 2. Pay attention that the value have been set bewteen '', important if not a number
>>>
>>> STBYFREQ.writeDigit(3, 8, 1) # will display '8' on digit number 3, dot activated
>>>

WriteDigit Method, Segment display object exemple
Pay attention that display have been connected with the first digit on the left

writeDisplay(value, decimal)

Will send value to display. If you need to send decimal value (Ex Frequency like 123.456), decimal need to be set to 1.
For a decimal value, dot need to be remove before calling this methode. For Displaying 123.456 frequency , value need to be 123456.

Python 3.4.2 (default, Oct 19 2014, 13:31:11) 
[GCC 4.9.1] 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')
>>> STBYFREQ = FGINT1.getElement('STBYFREQ')
>>> LEDPACK1.configMCP(1)
>>> LEDPACK1.Start()
1
>>> STBYFREQ.writeDisplay(str('123.456').replace('.', ''), 1)

WriteDisplay Methode

As you can see, as according to the configuration file and because the decimal mode have been activated, dot is setup to be on after the third digit.