Skip to content

Commit

Permalink
Queue commands to be sent sequentially (so that commands are issued i…
Browse files Browse the repository at this point in the history
…n-order) (#39)
  • Loading branch information
deckerego authored Aug 1, 2021
1 parent 552905a commit c60d9d3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions lib/tallypi/webapp/light/mock.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from tallypi.webapp.light.base import AbstractLight
import logging
import inspect
import time

logger = logging.getLogger('light')

Expand All @@ -11,6 +12,7 @@ class Light(AbstractLight):
red, green, blue = 0, 0, 0

def setColor(self, red, green, blue):
time.sleep(0.5)
self.red = red
self.green = green
self.blue = blue
Expand Down
19 changes: 13 additions & 6 deletions scripts/obs_tally_light.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from concurrent.futures import ThreadPoolExecutor
from queue import SimpleQueue
import obspython as obs
import json
import urllib.request
import urllib.error

threadpool = ThreadPoolExecutor()
threadpool = ThreadPoolExecutor(max_workers = 1)
commandQueue = SimpleQueue()
light_mapping = {}
idle_color = int('FF0000FF', 16)
idle_brightness = 5
Expand Down Expand Up @@ -88,16 +90,21 @@ def handle_event(event):


def call_tally_light(source, color, brightness):
addr = light_mapping[source]
commandQueue.put({'source': source, 'color': color, 'brightness': brightness});
threadpool.submit(fetch_command);

def fetch_command():
command = commandQueue.get()
addr = light_mapping[command['source']]
if not addr:
obs.script_log(obs.LOG_INFO, 'No tally light set for: %s' % (source))
return

hexColor = hex(color)
hexColor = hex(command['color'])
hexBlue = hexColor[4:6]
hexGreen = hexColor[6:8]
hexRed = hexColor[8:10]
pctBright = brightness / 10
pctBright = command['brightness'] / 10
url = 'http://%s:7413/set?color=%s%s%s&brightness=%f' % (addr, hexRed, hexGreen, hexBlue, pctBright)

try:
Expand Down Expand Up @@ -127,14 +134,14 @@ def get_item_names_by_scene(source):
def set_lights_by_items(item_names, color, brightness):
for item_name in item_names:
obs.script_log(obs.LOG_INFO, 'Calling Light for [%s]' % (item_name))
threadpool.submit(call_tally_light, item_name, color, brightness)
call_tally_light(item_name, color, brightness)

def set_idle_lights():
excluded_items = program_items + preview_items

for src, addr in light_mapping.items():
if src not in excluded_items:
threadpool.submit(call_tally_light, src, idle_color, idle_color)
call_tally_light(src, idle_color, idle_color)

def handle_preview_change():
global preview_items
Expand Down

0 comments on commit c60d9d3

Please sign in to comment.