Module Disp4tronix :: Class Disp4tronix
[hide private]
[frames] | no frames]

Class Disp4tronix

source code

Abstraction of the 4 digit 7-segment display from 4tronix attached to the I2C port. If no display is found, all methods return immediately. Be aware that the display is multiplexed by an internal display thread. So while a text is displayed the thread is running and the program will not terminate. Call clear() to terminate the display thread.

Instance Methods [hide private]
 
__init__(self) source code
 
setDigit(self, char, digit)
Shows the given character at one of the 4 7-segment digits.
source code
 
setBinary(self, value, digit)
Shows the pattern of the binary value 0..255.
source code
 
setDecimalPoint(self, id)
Shows one of the 3 decimal points.
source code
 
clearDigit(self, digit)
Clears the given digit.
source code
 
clear(self)
Turns all digits off.
source code
 
showText(self, text, pos=0, dp=[0,0,0])
Displays 4 characters of the given text.
source code
 
scrollToLeft(self)
Scrolls the current text one step to the left by increasing the text pointer.
source code
 
scrollToRight(self)
Scrolls the current text one step to the left by decreasing the text pointer.
source code
 
setToStart(self)
Shows the scrollable text at the start position by setting the text pointer to its start value.
source code
 
showTicker(self, text, count=1, speed=2, blocking=False)
Shows a ticker text that scroll to left until the last 4 characters are displayed.
source code
 
stopTicker(self)
Stops a running ticker.
source code
 
isTickerAlive(self)
Returns: True, if the ticker is displaying; otherwise False
source code
 
showBlinker(self, text, dp=[0,0,0,0], count=3, speed=1, blocking=False)
Shows a ticker text that scroll to the left until the last 4 characters are displayed.
source code
 
stopBlinker(self)
Stops a running blinker.
source code
 
isBlinkerAlive(self)
Returns: True, if the blinker is displaying; otherwise False
source code
 
showVersion(self)
Displays current version.
source code
 
isAvailable(self) source code
 
_getData(self, pos) source code
Static Methods [hide private]
 
toHex(intValue)
Returns a string with hex digits from given number (>0, any size).
source code
 
toBytes(intValue)
Returns a list of four byte values [byte#24-#31, byte#16-#23, byte#8-#15, byte#0-#7] of given integer.
source code
 
toInt(hexValue)
Returns an integer from given hex string
source code
 
debug(msg) source code
 
getVersion() source code
 
getDisplayableChars()
Returns a string with all displayable characters taken from PATTERN dictionary.
source code
 
delay(interval) source code
Class Variables [hide private]
  DEBUG = False
  VERSION = "1.00"
  i2c_address = 0x20
  _myInstance = None
pi
  PATTERN = {' ': 0, '!': 134, '"': 34, '#': 0, '$': 0, '%': 0, ...
Method Details [hide private]

toHex(intValue)
Static Method

source code 

Returns a string with hex digits from given number (>0, any size).

Parameters:
  • number - the number to convert (must be positive)
Returns:
string of hex digits (uppercase), e.g. 0xFE

toBytes(intValue)
Static Method

source code 

Returns a list of four byte values [byte#24-#31, byte#16-#23, byte#8-#15, byte#0-#7] of given integer.

Parameters:
  • number - an integer
Returns:
list with integers of 4 bytes [MSB,..., LSB]

toInt(hexValue)
Static Method

source code 

Returns an integer from given hex string

Parameters:
  • number - a string with the number to convert, e.g. "FE" or "fe" or "0xFE" or "0XFE"
Returns:
integer number

getDisplayableChars()
Static Method

source code 

Returns a string with all displayable characters taken from PATTERN dictionary.

Returns:
The character set that can be displayed

setDigit(self, char, digit)

source code 

Shows the given character at one of the 4 7-segment digits. The character is mapped to its binary value using the PATTERN dictionary defined in PATTERN dictonary. Only one digit can be used at the same time. This method has much less overhead than calling setValue(), because no internal display thread is started. The display remains active even when the program terminates.

Parameters:
  • char - the character to display, can be an int 0..9
  • digit - the display ID (0 is leftmost, 3 is rightmost)
Returns:
True, if successful; False, if the character is not displayable or digit not in 0..3

setBinary(self, value, digit)

source code 

Shows the pattern of the binary value 0..255.

Parameters:
  • value - the byte value
  • digit - the display ID (0 is leftmost, 3 is rightmost)
Returns:
True, if successful; False, if value not in 0..255 or digit not in 0..3

setDecimalPoint(self, id)

source code 

Shows one of the 3 decimal points.

Parameters:
  • id - select the DP to show: 0: right bottom, 1: middle bottom, 2: middle top
Returns:
True, if successful; False, if id not in 0..2

clearDigit(self, digit)

source code 

Clears the given digit.

Parameters:
  • digit - the display ID (0 is right most, 3 is left most)
Returns:
True, if successful; False, if digit not in 0..3

clear(self)

source code 

Turns all digits off. Stops a running display thread. To clear all digits without terminating the display thread, call showText(" ").

showText(self, text, pos=0, dp=[0,0,0])

source code 

Displays 4 characters of the given text. The text is considered to be prefixed and postfixed by spaces and the 4 character window is selected by the text pointer pos that determines the character displayed at the leftmost digit, e.g. (_: empty): showText("AbCdEF") -> AbCd showText("AbCdEF", 1) -> bCdE showText("AbCdEF", -1) ->_AbC showText("AbCdEF", 4) -> EF__ If the display thread is not yet running, it is started now.

Parameters:
  • text - the text to display (list, tuple, string or integer)
  • pos - the start value of the text pointer (character index positioned a leftmost digit)
  • dp - a list with one to three 1 or 0, if the decimal point is shown or not. First element in list corresponds to right dp, second to center floor dp, third to center ceil dp. More than 3 elements are ignored
Returns:
True, if successful; False, if the display is not available, text or dp has illegal type or one of the characters can't be displayed

scrollToLeft(self)

source code 

Scrolls the current text one step to the left by increasing the text pointer.

Returns:
the number of characters hidden, but remaining to be displayed at the right (>=0); -1, if error

scrollToRight(self)

source code 

Scrolls the current text one step to the left by decreasing the text pointer.

Returns:
the number of characters hidden, but remaining to be displayed at the left (>=0); -1, if error

setToStart(self)

source code 

Shows the scrollable text at the start position by setting the text pointer to its start value.

Returns:
0, if successful; -1, if error

showTicker(self, text, count=1, speed=2, blocking=False)

source code 

Shows a ticker text that scroll to left until the last 4 characters are displayed. The method blocks until the ticker thread is successfully started and isTickerAlive() returns True.

Parameters:
  • text - the text to display, if short than 4 characters, scrolling is disabled
  • count - the number of repetitions (default: 1). For count = 0, infinite duration, may be stopped by calling stopTicker().
  • speed - the speed number of scrolling operations per sec (default: 2)
  • blocking - if True, the method blocks until the ticker has finished; otherwise it returns immediately (default: False)

stopTicker(self)

source code 

Stops a running ticker. The method blocks until the ticker thread is finished and isTickerAlive() returns False.

isTickerAlive(self)

source code 
Returns:
True, if the ticker is displaying; otherwise False

showBlinker(self, text, dp=[0,0,0,0], count=3, speed=1, blocking=False)

source code 

Shows a ticker text that scroll to the left until the last 4 characters are displayed. The method blocks until the ticker thread is successfully started and isTickerAlive() returns True.

Parameters:
  • text - the text to display, if short than 4 characters, scrolling is disabled
  • count - the number of repetitions (default: 2). For count = 0, infinite duration, may be stopped by calling stopBlinker().
  • speed - the speed number of blinking operations per sec (default: 1)
  • blocking - if True, the method blocks until the blinker has finished; otherwise it returns immediately (default: False)

stopBlinker(self)

source code 

Stops a running blinker. The method blocks until the blinker thread is finished and isBlinkerAlive() returns False.

isBlinkerAlive(self)

source code 
Returns:
True, if the blinker is displaying; otherwise False

showVersion(self)

source code 

Displays current version. Format X (three horz bars) + n.nn


Class Variable Details [hide private]

_myInstance

pi

Character to binary value mapping for 4 digit 7 segment display

Value:
None

PATTERN

Value:
{' ': 0, '!': 134, '"': 34, '#': 0, '$': 0, '%': 0, '&': 0, '\'': 2, '\
(': 0, ')': 0, '*': 0, '+': 0, ',': 4, '-': 64, '.': 128, '/': 82, '0'\
: 63, '1': 6, '2': 91, '3': 79, '4': 102, '5': 109, '6': 125, '7': 7, \
'8': 127, '9': 111, ':': 0, ';': 0, '<': 0, '=': 72, '>': 0, '?': 0, '\
@': 93, 'A': 119, 'B': 124, 'C': 57, 'D': 94, 'E': 121, 'F': 113, 'G':\
 61, 'H': 118, 'I': 48, 'J': 14, 'K': 112, 'L': 56, 'M': 85, 'N': 84, \
'O': 63, 'P': 115, 'Q': 103, 'R': 80, 'S': 45, 'T': 120, 'U': 62, 'V':\
 54, 'W': 106, 'X': 73, 'Y': 110, 'Z': 27, '[': 57, '\\': 100, ']': 15\
...