Example #1
0
def test_monochrome_display():
    """
    SSD1322 OLED screen can draw and display a monochrome image.
    """
    device = ssd1322(serial, mode="1", framebuffer=full_frame())
    serial.reset_mock()

    recordings = []

    def data(data):
        recordings.append({'data': data})

    def command(*cmd):
        recordings.append({'command': list(cmd)})

    serial.command.side_effect = command
    serial.data.side_effect = data

    # Use the same drawing primitives as the demo
    with canvas(device) as draw:
        primitives(device, draw)

    assert serial.data.called
    assert serial.command.called

    # To regenerate test data, uncomment the following (remember not to commit though)
    # ================================================================================
    # from baseline_data import save_reference_data
    # save_reference_data("demo_ssd1322_monochrome", recordings)

    assert recordings == get_reference_data('demo_ssd1322_monochrome')
Example #2
0
    def __init__(self, config, core):
        super(oledScreen, self).__init__()
        self.menu = False
        self.core = core
        self.config = config

        if config['oledScreen']['bus'] and config['oledScreen']['address']:
            self.serial = i2c(bus=SMBus(config['oledScreen']['bus']),
                              address=config['oledScreen']['address'])
        else:
            self.serial = i2c(bus=SMBus(2), address=0x3c)
        self.driver = config['oledScreen']['driver']
        if self.driver == 'ssd1306':
            self.device = ssd1306(self.serial)
        elif self.driver == 'ssd1322':
            self.device = ssd1322(self.serial)
        elif self.driver == 'ssd1325':
            self.device = ssd1325(self.serial)
        elif self.driver == 'ssd1331':
            self.device = ssd1331(self.serial)
        elif self.driver == 'sh1106':
            self.device = sh1106(self.serial)
        else:
            self.device = ssd1306(self.serial)

        self.font = self.make_font('Vera.ttf', 26)
        self.fontSmall = self.make_font('Vera.ttf', 15)
        self.set_image('radio.gif')
Example #3
0
def test_init_256x64():
    """
    SSD1322 OLED with a 256 x 64 resolution works correctly.
    """
    recordings = []

    def data(data):
        recordings.append({'data': data})

    def command(*cmd):
        recordings.append({'command': list(cmd)})

    serial.command.side_effect = command
    serial.data.side_effect = data

    ssd1322(serial)

    assert serial.data.called
    assert serial.command.called

    assert recordings == [
        {'command': [253]}, {'data': [18]},
        {'command': [164]},
        {'command': [179]}, {'data': [242]},
        {'command': [202]}, {'data': [63]},
        {'command': [162]}, {'data': [0]},
        {'command': [161]}, {'data': [0]},
        {'command': [160]}, {'data': [20, 17]},
        {'command': [181]}, {'data': [0]},
        {'command': [171]}, {'data': [1]},
        {'command': [180]}, {'data': [160, 253]},
        {'command': [199]}, {'data': [15]},
        {'command': [185]},
        {'command': [177]}, {'data': [240]},
        {'command': [209]}, {'data': [130, 32]},
        {'command': [187]}, {'data': [13]},
        {'command': [182]}, {'data': [8]},
        {'command': [190]}, {'data': [0]},
        {'command': [166]},
        {'command': [169]},
        {'command': [193]}, {'data': [127]},
        {'command': [21]}, {'data': [28, 91]},
        {'command': [117]}, {'data': [0, 63]},
        {'command': [92]}, {'data': [0] * (256 * 64 // 2)},
        {'command': [175]}
    ]
Example #4
0
 def run_blocking(self, oled, cmdline, reason, showerror=True, timeout=60):
     result = subprocess.run(cmdline, capture_output=True, timeout=timeout, env=self.environment)
     if (result.returncode != 0) or (len(result.stderr) != 0):
         if showerror:
             if oled == None: # special case when we're running an EC process that scrambles the OLED pins
                 oled = ssd1322(bitbang(SCLK=11, SDA=10, CE=7, DC=1, RST=12))
             self.display_error(oled, result.stdout, result.stderr)
         self.reasons.append(reason)
         self.passing = False
         return self.passing
    def init_display(self):
        if Config.get("debug.dummy", False):
            self.device = dummy(width=256, height=64, rotate=0, mode="1")
        else:
            serial = spi(bus_speed_hz=Config.get("debug.bus_speed", 16000000))
            self.device = ssd1322(serial, mode="1", rotate=0)

        self.viewport = viewport(self.device,
                                 width=self.device.width,
                                 height=self.device.height)
Example #6
0
 def __init__(self):
     threading.Thread.__init__(self)
     serial = spi(device=0, port=0)
     self._device = ssd1322(serial_interface=serial, mode="1")
     self._display_mode = "start"
     self.__icon_font = "iconfont.ttf"
     self.__text_font = "NotoSansCJKsc-Regular.otf"
     self.__uri = ""
     self.__status_monitor = StatusMonitor()
     self.__status_monitor.start()
     self.title_text_window = TextWindow(self.DISPLAY_FPS)
     self.artist_text_window = TextWindow(self.DISPLAY_FPS)
Example #7
0
def main():
    global SCRIPT
    oled = ssd1322(bitbang(SCLK=11, SDA=10, CE=7, DC=1, RST=12))
    oled.clear()
    with canvas(oled) as draw:
        draw.text((0, 0), "scriptminder.py started...", fill="White")
    time.sleep(3)

    while True:
        if checkIfProcessRunning(SCRIPT):
            print(SCRIPT + " is running, sleeping!")
            time.sleep(3)
        else:
            print(SCRIPT + " is not running, restarting it!")
            killScript(
                SCRIPT)  # just in case, so we don't have multiple copies
            subprocess.run(
                ['/home/pi/code/bootstrap-mainboard/factory-firmware.py'])
            time.sleep(3)
Example #8
0
    def __init__(self, config, core):
        super(serialRFID, self).__init__()
        self.menu = False
        self.core = core
        self.config = config
        self.deviceName = config['serialRFID']['device']
        self.rate = config['serialRFID']['rate']
        self.oledEnabled = config['serialRFID']['oled_enabled']
        #if screen is used
        if self.oledEnabled:
            if config['serialRFID']['oled_bus'] and config['serialRFID'][
                    'oled_address']:
                self.serial = i2c(bus=SMBus(config['serialRFID']['oled_bus']),
                                  address=config['serialRFID']['oled_address'])
            self.driver = config['serialRFID']['oled_driver']
            if self.driver == 'ssd1306':
                self.device = ssd1306(self.serial)
            elif self.driver == 'ssd1322':
                self.device = ssd1322(self.serial)
            elif self.driver == 'ssd1325':
                self.device = ssd1325(self.serial)
            elif self.driver == 'ssd1331':
                self.device = ssd1331(self.serial)
            elif self.driver == 'sh1106':
                self.device = sh1106(self.serial)
            else:
                self.device = ssd1306(self.serial)

        GPIO.setmode(GPIO.BOARD)

        #register buttons
        if config['serialRFID']['button']:
            GPIO.setup(config['serialRFID']['button'],
                       GPIO.IN,
                       pull_up_down=GPIO.PUD_UP)
            GPIO.add_event_detect(config['serialRFID']['button'],
                                  GPIO.RISING,
                                  bouncetime=600)
            GPIO.add_event_callback(config['serialRFID']['button'],
                                    self.eventDetected)

        if self.oledEnabled:
            self.set_image("radio.gif")
Example #9
0
from PIL import ImageFont, Image

from luma.core.interface.serial import spi
from luma.core.virtual import viewport, snapshot, hotspot
from luma.oled.device import ssd1322

import constants as CONST
import sensors as sensors
import utils as utils
from enums import DrawType, PowerState

logger = utils.create_logger(__name__)
STATE = utils.state()

spi_for_display = spi(device=0, port=0)
display_device = ssd1322(spi_for_display)

virtual = viewport(display_device,
                   width=display_device.width,
                   height=display_device.height)

sleep_time = 1 / CONST.FPS
main_text_dirty = True  # main text was overdrawn
forced_visualisation = False  # forced visualisation for a time frame


def get_font(font_size, font_path='ressources/hel_new.otf'):
    return ImageFont.truetype(font_path, font_size)


font_18 = get_font(18)
Example #10
0
volumioIO = SocketIO(volumio_host, volumio_port)

STATE_NONE = -1
STATE_PLAYER = 0
STATE_PLAYLIST_MENU = 1
STATE_QUEUE_MENU = 2
STATE_VOLUME = 3
STATE_SHOW_INFO = 4
STATE_LIBRARY_MENU = 5

UPDATE_INTERVAL = 0.034
PIXEL_SHIFT_TIME = 120  #time between picture position shifts in sec.

interface = spi(device=0, port=0)
oled = ssd1322(interface)

oled.WIDTH = 256
oled.HEIGHT = 64
oled.state = STATE_NONE
oled.stateTimeout = 0
oled.timeOutRunning = False
oled.activeSong = ''
oled.activeArtist = 'VOLuMIO'
oled.playState = 'unknown'
oled.playPosition = 0
oled.modal = False
oled.playlistoptions = []
oled.queue = []
oled.libraryFull = []
oled.libraryNames = []