Mercurial > code > home > repos > light9
changeset 2316:a0abf52b06d6
collector: auto find dmx address (at startup) if it reconnects usb with a new one
author | drewp@bigasterisk.com |
---|---|
date | Thu, 01 Jun 2023 14:16:45 -0700 |
parents | 635568de3c9a |
children | bea44be4df38 |
files | light9/collector/service.py |
diffstat | 1 files changed, 13 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/light9/collector/service.py Thu Jun 01 14:15:54 2023 -0700 +++ b/light9/collector/service.py Thu Jun 01 14:16:45 2023 -0700 @@ -9,6 +9,7 @@ import asyncio import functools import logging +import subprocess import traceback from typing import List @@ -35,6 +36,7 @@ STAT_SETATTR = Summary('set_attr', 'setAttr calls') +# this is the rate sent to usb RATE = 20 @@ -91,6 +93,14 @@ traceback.print_exc() raise +def findDevice(): + for line in subprocess.check_output("lsusb").decode('utf8').splitlines(): + if '16c0:05dc' in line: + words = line.split(':')[0].split() + dev = f'/dev/bus/usb/{words[1]}/{words[3]}' + log.info(f'device will be {dev}') + return dev ,int(words[3]) + raise ValueError("no matching uDMX found") def main(): logging.getLogger('autodepgraphapi').setLevel(logging.INFO) @@ -99,16 +109,17 @@ graph = SyncedGraph(networking.rdfdb.url, "collector") + devPath, usbAddress = findDevice() + # if user doesn't have r/w, fail now try: # todo: drive outputs with config files - rate = 30 outputs: List[Output] = [ # ArtnetDmx(L9['output/dmxA/'], # host='127.0.0.1', # port=6445, # rate=rate), #sudo chmod a+rw /dev/bus/usb/003/021 - Udmx(L9['output/dmxA/'], bus=3, address=21, lastDmxChannel=200, rate=RATE), + Udmx(L9['output/dmxA/'], bus=1, address=usbAddress, lastDmxChannel=200, rate=RATE), ] except Exception: log.error("setting up outputs:")