From b02e3c085ff8b7718645e9a72fbcc679bf891e77 Mon Sep 17 00:00:00 2001 From: Jan Kantert Date: Fri, 14 Oct 2016 01:08:01 +0200 Subject: [PATCH] name it with smartmatrix --- mpf/core/config_spec.py | 5 +- mpf/mpfconfig.yaml | 3 +- mpf/platforms/eli_dmd.py | 72 ----------------------------- mpf/platforms/smartmatrix.py | 88 ++++++++++++++---------------------- 4 files changed, 37 insertions(+), 131 deletions(-) delete mode 100644 mpf/platforms/eli_dmd.py diff --git a/mpf/core/config_spec.py b/mpf/core/config_spec.py index f216d40ea..dfce67918 100644 --- a/mpf/core/config_spec.py +++ b/mpf/core/config_spec.py @@ -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 diff --git a/mpf/mpfconfig.yaml b/mpf/mpfconfig.yaml index 772d31e69..d686af659 100644 --- a/mpf/mpfconfig.yaml +++ b/mpf/mpfconfig.yaml @@ -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 diff --git a/mpf/platforms/eli_dmd.py b/mpf/platforms/eli_dmd.py deleted file mode 100644 index 1a837924f..000000000 --- a/mpf/platforms/eli_dmd.py +++ /dev/null @@ -1,72 +0,0 @@ -"""Contains code for a RGB DMD.""" - -import logging -import sys -import threading -import traceback -from queue import Queue - -import asyncio -import serial -from mpf.core.platform import RgbDmdPlatform - - -class EliDmd(RgbDmdPlatform): - - """Elis RGB DMD.""" - - def __init__(self, machine): - """Initialise RGB DMD.""" - super().__init__(machine) - self.features['tickless'] = True - - self.log = logging.getLogger('RgbDmd') - self.log.debug("Configuring RGB DMD hardware interface.") - - self.reader = None - self.writer = None - - self.config = self.machine.config_validator.validate_config( - config_spec='eli_dmd', - source=self.machine.config['eli_dmd']) - - def initialize(self): - """Initialise platform.""" - pass - - def stop(self): - """Stop platform.""" - try: - self.log.info("Disconnecting from RGB DMD hardware...") - self.writer.close() - except AttributeError: - pass - - def __repr__(self): - """Return string representation.""" - return '' - - def configure_rgb_dmd(self): - """Configure rgb dmd.""" - self.machine.clock.loop.run_until_complete(self._connect()) - return self - - @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 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: - self.writer.write(bytearray([0xBA, 0x11, 0x00, 0x03, 0x04, 0x00, 0x00, 0x00])) - self.writer.write(bytearray(data)) diff --git a/mpf/platforms/smartmatrix.py b/mpf/platforms/smartmatrix.py index 3d7701153..137803910 100644 --- a/mpf/platforms/smartmatrix.py +++ b/mpf/platforms/smartmatrix.py @@ -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', @@ -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 @@ -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))