Ankündigung

Einklappen
Keine Ankündigung bisher.

Plugin OLA DMX

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

    [Codebeispiel] Plugin OLA DMX

    Hallo,

    nachdem ich bereits im Besitz eines USB DMX Dongels bin, der leider
    vom bestehenden Plugin nicht unterstützt wird hab ich ein Plugin für OLA
    ( Open Lighting Architecture - OpenDMX.net ) gebastelt.

    Code:
    #!/usr/bin/env python
    # vim: set encoding=utf-8 tabstop=4 softtabstop=4 shiftwidth=4 expandtab
    #########################################################################
    # 2013                                                       dalai@gmx.at
    #########################################################################
    #  OLA-Plugin for SmartHome.py.   
    #
    #  This plugin is free software: you can redistribute it and/or modify
    #  it under the terms of the GNU General Public License as published by
    #  the Free Software Foundation, either version 3 of the License, or
    #  (at your option) any later version.
    #
    #  This plugin is distributed in the hope that it will be useful,
    #  but WITHOUT ANY WARRANTY; without even the implied warranty of
    #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    #  GNU General Public License for more details.
    #
    #  You should have received a copy of the GNU General Public License
    #  along with SmartHome.py. If not, see <http://www.gnu.org/licenses/>.
    #########################################################################
    
    import logging
    import threading
    
    import array
    from ola.ClientWrapper import ClientWrapper
    
    logger = logging.getLogger('')
    
    class OLA():
    
        def __init__(self, smarthome, universe=1):
            self._sh = smarthome
            self.TICK_INTERVAL=100
            self.wrapper = None
            self.universe = universe
            self.data = array.array('B', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,])
    
    
        def _DmxSent(self,state):
            if not state.Succeeded():
                self.wrapper.Stop()
    
    
        def _SendDMXFrame(self):
            # schdule a function call in 100ms
            # we do this first in case the frame computation takes a long time.
            self.wrapper.AddEvent(self.TICK_INTERVAL, self._SendDMXFrame)
            # send
            self.wrapper.Client().SendDmx(1, self.data, self._DmxSent)
    
        def run(self):
            self.alive = True        
            self.wrapper = ClientWrapper()
            self.wrapper.AddEvent(self.TICK_INTERVAL, self._SendDMXFrame)
            self.wrapper.Run()
    
        def stop(self):
            self.alive = False
            self.wrapper.Stop()
    
        #def send(self):
            #self.wrapper = ClientWrapper()
            #client = self.wrapper.Client()
            #self.client.SendDmx(int(self.universe), self.data, self._DmxSent)
    
            #self.wrapper.Run()
    
    
        def parse_item(self, item):
            if 'dmx_ch' in item.conf:
                channels = item.conf['dmx_ch']
                if isinstance(channels, str):
                    channels = [channels, ]
                channels = map(int, channels)
                item.conf['dmx_ch'] = channels
                return self.update_item
            else:
                return None
    
        def update_item(self, item, caller=None, source=None, dest=None):
            for channel in item.conf['dmx_ch']:
                    if (int(channel) < 512): 
                        if (int(item()) < 255):
                            self.data[int(channel)]=int(item())
                            #self.send()
                        else:
                            logger.error("dmx: value for channel {0} bigger than 255".format(int(channel)))
    
                    else:
                        logger.error("dmx: channel is bigger than 512".format(int(channel)))
    die Funktionsweise ist analog zum bestehenden DMX Plugin.
    gesteuert kann ein in OLA konfiguriertes DMX Universe werden.

    als Voraussetzung wird eine funktionierende OLA Installation und der OLA Python ClientWrapper benötigt.

    das ganze funktioniert wunderbar auf einem RasPi mit einigen DMX LED Controllern.

    schönen Abend
    Lai

    #2
    Hey,

    find ich Hammer! PS: Die Unterstützung die du suchst hab ich vor ein paar Wochen geschrieben, zumindest geh ich davon aus, so viel Protokolltypen für USB DMX Dongles gibts ja nicht - ich kenn nur zwei.

    https://knx-user-forum.de/smarthome-...b-devices.html

    Cool wäre es natürlich (finde ich) wenn die Unterstützung für OLA auch im DMX Plugin Platz finden würde - über Parameter in der Plugin-Config entsprechend konfigurierbar. Meine Anpassung hat auch schon den Weg ins offizielle Repo gefunden.

    Vielen Dank,

    ich werd das Plugin möglicherweise in Zunkunft auch brauchen.

    ciao,

    flo

    Kommentar


      #3
      Hi,

      mein DMX Dongle ist technisch eigentlich nichts anders als eine
      Serielle USB Schnittstelle mit Pegelwandler auf RS-485
      ( Enttec OpenDMX-Interface kompatibel ;-).
      Das Zyklische aussenden des DMX-Paket muss der Rechner übernehmen.
      OLA kümmert sich um um alles ( man braucht allerdings das kernel modul
      https://github.com/lowlander/dmx_usb_module dazu )

      ebenfalls interessant für den RasPi dürfte das I2C LED Pixel Modul sein
      OLA LED Pixels - OpenDMX.net

      und nicht zu vergessen die DMX over IP und artnet Treiber sowie die
      Weboberfläche für die Konfiguration.

      Abend
      Lai

      Kommentar

      Lädt...
      X