Beispiel #1
0
class Printer:
    def __init__(self):
        self.font_width = 6
        self.font_height = 10
        self.max_char_width = 9
        self.max_char_height = 2
        self.matrix = Adafruit_RGBmatrix(32, 2)
        self.fontfile = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            "fonts/{0}x{1}.bdf".format(self.font_width, self.font_height))
        self.offset = [0, 0]

    def offset_x(self):
        return self.offset[0] * self.font_width

    def offset_y(self):
        return self.offset[1] * self.font_height

    def draw_char(self, char):
        # If return, set offset to new line
        try:
            test = ord(char) == 10
        except TypeError:
            test = False
        if test:
            self.offset[0] = 0
            self.offset[1] += 1
        else:
            self.matrix.DrawText(self.fontfile, self.offset_x(),
                                 self.offset_y(), 0xFF, 0xFF, 0xFF, char)
            self.offset[0] += 1
            if self.offset[0] > self.max_char_width:
                self.offset[0] = 0
                self.offset[1] += 1
        if self.offset[1] > self.max_char_height:
            self.offset[1] = 0
            self.matrix.Clear()
Beispiel #2
0
#!/usr/bin/python

import sys, time
from rgbmatrix import Adafruit_RGBmatrix

font_width = 4
font_height = 6
lines = ["Hi Mom!", "I'm cool."]

matrix = Adafruit_RGBmatrix(16, 1)
bdf_font_file = "fonts/{0}x{1}.bdf".format(font_width, font_height)
matrix.DrawText(bdf_font_file, 1, 1, 0xFF, 0xFF, 0, lines[0])
time.sleep(2.0)
matrix.DrawText(bdf_font_file, 1, 1 + font_height, 0xFF, 0, 0xFF, lines[1])
time.sleep(10.0)

matrix.Clear()
Beispiel #3
0
#!/usr/bin/python

from __future__ import print_function
import os, sys
from os import getuid
from time import sleep

if (getuid() != 0):
    print("This script must be run as root!")
    sys.exit(1)

sys.path.append('lib')
from rgbmatrix import Adafruit_RGBmatrix

ROWS = 16
CHAIN_LENGTH = 1
matrix = Adafruit_RGBmatrix(ROWS, CHAIN_LENGTH)

# TODO display spinner while loading

font_width = 4
font_height = 6
bdf_font_file = "fonts/{0}x{1}.bdf".format(font_width, font_height)

matrix.DrawText(bdf_font_file, 0, 0, 0xFF, 0, 0xFF, "TODO")
sleep(10.0)

matrix.Clear()