Skip to content

Commit

Permalink
name it with smartmatrix
Browse files Browse the repository at this point in the history
  • Loading branch information
jabdoa2 committed Oct 13, 2016
1 parent ee54466 commit b02e3c0
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 131 deletions.
5 changes: 1 addition & 4 deletions mpf/core/config_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,13 +844,10 @@
diag_led_driver: single|machine(coils)|
platform: single|str|None
smartmatrix:
__valid_in__: machine
port: single|str|
use_separate_thread: single|bool|true
eli_dmd:
__valid_in__: machine
port: single|str|
baud: single|int|
old_cookie: single|bool|False
smart_virtual:
__valid_in__: machine
simulate_manual_plunger: single|bool|False
Expand Down
3 changes: 1 addition & 2 deletions mpf/mpfconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ mpf:
p3_roc: mpf.platforms.p3_roc.HardwarePlatform
pololu_maestro: mpf.platforms.pololu_maestro.HardwarePlatform
smart_virtual: mpf.platforms.smart_virtual.HardwarePlatform
smartmatrix: mpf.platforms.smartmatrix.HardwarePlatform
eli_dmd: mpf.platforms.eli_dmd.EliDmd
smartmatrix: mpf.platforms.smartmatrix.SmartMatrix
snux: mpf.platforms.snux.HardwarePlatform
virtual: mpf.platforms.virtual.HardwarePlatform

Expand Down
72 changes: 0 additions & 72 deletions mpf/platforms/eli_dmd.py

This file was deleted.

88 changes: 35 additions & 53 deletions mpf/platforms/smartmatrix.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
"""Contains code for an SmartMatrix Shield connected to a Teensy."""
"""Contains code for SmartMatrix RGB DMD."""

import logging
import sys
import threading
import traceback
from queue import Queue
import serial

import asyncio
from mpf.core.platform import RgbDmdPlatform


class HardwarePlatform(RgbDmdPlatform):
class SmartMatrix(RgbDmdPlatform):

"""SmartMatrix shield via Teensy."""
"""SmartMatrix RGB DMD."""

def __init__(self, machine):
"""Initialise smart matrix."""
"""Initialise RGB DMD."""
super().__init__(machine)
self.features['tickless'] = True

self.log = logging.getLogger('SmartMatrix')
self.log.debug("Configuring SmartMatrix hardware interface.")
self.log.debug("Configuring SmartMatrix RGB DMD hardware interface.")

self.queue = None
self.serial_port = None
self.dmd_thread = None
self.update = None
self.reader = None
self.writer = None

self.config = self.machine.config_validator.validate_config(
config_spec='smartmatrix',
Expand All @@ -36,8 +32,8 @@ def initialize(self):
def stop(self):
"""Stop platform."""
try:
self.log.info("Disconnecting from SmartMatrix hardware...")
self.serial_port.close()
self.log.info("Disconnecting from SmartMatrix RGB DMD hardware...")
self.writer.close()
except AttributeError:
pass

Expand All @@ -47,42 +43,28 @@ def __repr__(self):

def configure_rgb_dmd(self):
"""Configure rgb dmd."""
self.log.info("Connecting to SmartMatrix DMD on %s", self.config['port'])
self.serial_port = serial.Serial(port=self.config['port'],
baudrate=2500000)

if self.config['use_separate_thread']:
self.queue = Queue()
self.dmd_thread = threading.Thread(target=self._dmd_sender_thread)
self.dmd_thread.daemon = True
self.dmd_thread.start()
self.update = self._update_separate_thread
else:
self.update = self._update_non_thread

self.machine.clock.loop.run_until_complete(self._connect())
return self

def _update_non_thread(self, data):
try:
self.serial_port.write(bytearray([0x01]))
self.serial_port.write(bytearray(data))
except TypeError:
pass

def _update_separate_thread(self, data):
self.queue.put(bytearray(data))

def _dmd_sender_thread(self):
while True:
data = self.queue.get() # this will block

try:
self.serial_port.write(bytearray([0x01]))
self.serial_port.write(bytearray(data))

except IOError:
exc_type, exc_value, exc_traceback = sys.exc_info()
lines = traceback.format_exception(exc_type, exc_value,
exc_traceback)
msg = ''.join(line for line in lines)
self.machine.crash_queue.put(msg)
@staticmethod
def _done(future):
"""Evaluate result of task.
Will raise exceptions from within task.
"""
future.result()

@asyncio.coroutine
def _connect(self):
self.log.info("Connecting to SmartMatrix RGB DMD on %s baud %s", self.config['port'], self.config['baud'])
connector = self.machine.clock.open_serial_connection(
url=self.config['port'], baudrate=self.config['baud'], limit=0)
self.reader, self.writer = yield from connector

def update(self, data):
if self.writer:
if self.config['old_cookie']:
self.writer.write(bytearray([0x01]))
else:
self.writer.write(bytearray([0xBA, 0x11, 0x00, 0x03, 0x04, 0x00, 0x00, 0x00]))
self.writer.write(bytearray(data))

0 comments on commit b02e3c0

Please sign in to comment.