Package rstem :: Package led_matrix
[hide private]
[frames] | no frames]

Package led_matrix

source code

Submodules [hide private]

Classes [hide private]
  LEDSprite
Allows the creation of a LED Sprite that is defined in a text file.
  LEDText
A LEDSprite object of a piece of text.
Functions [hide private]
 
_init_check()
Checks that init_matrices has been called and throws an error if not
source code
 
_valid_color(color)
Checks if given color is number between 0-16 if an int or 0-f, or - if string
source code
int
_convert_color(color)
Converts the given color to an int.
source code
tuple
_convert_to_std_coords(x, y)
Converts given math coordinates to standard programming coordinates
source code
 
display_on_terminal()
Toggles on and off the terminal display of the led matrix on show()
source code
 
init_matrices(mat_list=[(0, 0, 0)], math_coords=True, spi_speed=125000, spi_port=0)
Creates a chain of led matrices set at particular offsets into the frame buffer The order of the led matrices in the list indicate the order they are physically hooked up with the first one connected to Pi.
source code
 
init_grid(num_rows=None, num_cols=None, angle=0, math_coords=True, spi_speed=125000, spi_port=0)
Initiallizes led matrices in a grid pattern with either a given number of rows and columns.
source code
int
show()
Shows the current framebuffer on the display.
source code
 
cleanup()
Unintializes matrices and frees all memory.
source code
 
fill(color=15)
Fills the framebuffer with the given color.
source code
 
erase()
Clears display
source code
int
point(x, y=None, color=15)
Sends point to the framebuffer.
source code
 
rect(origin, dimensions, fill=True, color=15)
Creates a rectangle from start point using given dimensions
source code
 
_sign(n) source code
 
line(point_a, point_b, color=15)
Create a line from point_a to point_b.
source code
 
_line_fast(point_a, point_b, color=15)
A faster c implementation of line.
source code
LEDText
text(text, origin=(0, 0), crop_origin=(0, 0), crop_dimensions=None, font_name='small', font_path=None)
Sets given string to be displayed on the led matrix
source code
 
sprite(sprite, origin=(0, 0), crop_origin=(0, 0), crop_dimensions=None)
Sets given sprite into the framebuffer.
source code
 
frame(numpy_bitmap)
Sends the entire frame (represented as a numpy bitmap) to the led matrix.
source code
LEDSprite
_char_to_sprite(char, font_path)
Converts given character to a sprite.
source code
 
_main() source code
Variables [hide private]
  BITS_PER_PIXEL = 4
  DIM_OF_MATRIX = 8
  initialized = False
  spi_initialized = False
  width = 0
The width of the LED matrix grid
  height = 0
The height of the LED matrix grid
  container_math_coords = True
  __package__ = 'rstem.led_matrix'
Function Details [hide private]

_init_check()

source code 

Checks that init_matrices has been called and throws an error if not

Raises:
  • RuntimeError - If matrices have not been initialized.

_valid_color(color)

source code 

Checks if given color is number between 0-16 if an int or 0-f, or - if string

Parameters:
  • color (string or int) - A color to check that is valid

_convert_color(color)

source code 

Converts the given color to an int.

Parameters:
  • color (string or int) - A color to be converted
Returns: int
Either the same int back again if color was an int or the int of a converted string
Raises:

_convert_to_std_coords(x, y)

source code 

Converts given math coordinates to standard programming coordinates

Parameters:
  • x - x coordinate in math coordinates
  • y - y coordinate in math coordinates
Returns: tuple
(x,y) coordinates in standard programming coordinates

init_matrices(mat_list=[(0, 0, 0)], math_coords=True, spi_speed=125000, spi_port=0)

source code 

Creates a chain of led matrices set at particular offsets into the frame buffer The order of the led matrices in the list indicate the order they are physically hooked up with the first one connected to Pi.

Parameters:
  • mat_list (list of size 2 or 3 tuples (mix or match)) - list of tuples that contains led matrix and offset (in math coordinates if math_coords==True, else in programmer coordinate if math_coords==False) ex: [(0,0,0),(7,0,90)]
  • math_coords (Boolean) - True to use math coordinates, False to use programming coordinates

init_grid(num_rows=None, num_cols=None, angle=0, math_coords=True, spi_speed=125000, spi_port=0)

source code 

Initiallizes led matrices in a grid pattern with either a given number of rows and columns. If num_rows and num_cols is not given, it will detect the number of matrices you have and automatically set up a grid pattern with a max number of columns of 4.

Parameters:
  • num_rows - Number of rows the grid is in (when angle == 0)
  • num_cols - Number of columns the gird is in (when angle == 0)
  • math_coords (Boolean) - True to use math coordinates, False to use programming coordinates
  • angle (int) - Angle to rotate the coordinate system once initialized. (must be 90 degree multiple)
Raises:
  • ValueError - num_rows*num_cols != number of matrices
  • ValueError - angle is not a multiple of 90

show()

source code 

Shows the current framebuffer on the display. Tells the led_driver to send framebuffer to SPI port. Refreshes the display using current framebuffer.

Returns: int
1 on success

cleanup()

source code 

Unintializes matrices and frees all memory. Should be called at the end of a program to avoid memory leaks. Also, clears the display.

fill(color=15)

source code 

Fills the framebuffer with the given color.

Parameters:
  • color (int or string (0-F or 16 or '-' for transparent)) - Color to fill the entire display with

point(x, y=None, color=15)

source code 

Sends point to the framebuffer.

Parameters:
  • x, y - Coordinates to place point
  • color (int or string (0-F or 16 or '-' for transparent)) - Color to display at point
Returns: int
1 on success

Note: Will not display the point until show() is called.

rect(origin, dimensions, fill=True, color=15)

source code 

Creates a rectangle from start point using given dimensions

Parameters:
  • origin ((x,y) tuple) - The bottom left corner of rectange (if math_coords == True). The top left corner of rectangle (if math_coords == False)
  • dimensions ((width, height) tuple) - width and height of rectangle
  • fill (boolean) - Whether to fill the rectangle or make it hollow
  • color (int or string (0-F or 16 or '-' for transparent)) - Color to display at point

line(point_a, point_b, color=15)

source code 

Create a line from point_a to point_b. Uses Bresenham's Line Algorithm http://en.wikipedia.org/wiki/Bresenham's_line_algorithm

Parameters:
  • color (int or string (0-F or 16 or '-' for transparent)) - Color to display at point

_line_fast(point_a, point_b, color=15)

source code 

A faster c implementation of line. Use if you need the speed.

text(text, origin=(0, 0), crop_origin=(0, 0), crop_dimensions=None, font_name='small', font_path=None)

source code 

Sets given string to be displayed on the led matrix

Example:

>>> text("Hello World", (0,0), (0,1), (0,5))
>>> show()
Displays only part of the first vertical line in 'H'
Parameters:
  • origin, crop_origin, crop_dimensions - See sprite
  • text - text to display
  • text - string or LEDText
  • font_name (string) - Font folder (or .font) file to use as font face
  • font_path (string) - Directory to use to look for fonts. If None it will used default directory in dist-packages
Returns: LEDText
LEDText sprite object used to create text

sprite(sprite, origin=(0, 0), crop_origin=(0, 0), crop_dimensions=None)

source code 

Sets given sprite into the framebuffer.

Parameters:
  • origin ((x,y) tuple) - Bottom left position to diplay text (top left if math_coords == False)
  • crop_origin ((x,y) tuple) - Position to crop into the sprite relative to the origin
  • crop_dimensions ((x,y) tuple) - x and y distance from the crop_origin to display
    • Keep at None to not crop and display sprite all the way to top right corner (bottom right for math_coords == False)

frame(numpy_bitmap)

source code 

Sends the entire frame (represented as a numpy bitmap) to the led matrix.

Parameters:
  • numpy_bitmap (numpy ndarray) - A ndarray representing the entire framebuffer to display.

Note: bitmap dimensions must be the same as the dimensions of the container (non rotated).

_char_to_sprite(char, font_path)

source code 

Converts given character to a sprite.

Parameters:
  • char (string) - character to convert (must be of length == 1)
  • font_path (string) - Relative location of font face to use.
Returns: LEDSprite