Skip to content

Commit

Permalink
Roll with HTTP errors and latency (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
deckerego committed Jul 5, 2021
1 parent de4779b commit 7fbd508
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
14 changes: 5 additions & 9 deletions lib/tallypi/webapp/routes.py
Expand Up @@ -17,15 +17,11 @@
light_module = configuration.get('light_module')
gpio_module = configuration.get('gpio_module')

if light_module == 'mock':
from tallypi.webapp.light.mock import Light
else:
from tallypi.webapp.light.unicornhat import Light

if gpio_module == 'mock':
from tallypi.webapp.powerswitch.mock import PowerSwitch
else:
from tallypi.webapp.powerswitch.rpi import PowerSwitch
if light_module == 'mock': from tallypi.webapp.light.mock import Light
else: from tallypi.webapp.light.unicornhat import Light

if gpio_module == 'mock': from tallypi.webapp.powerswitch.mock import PowerSwitch
else: from tallypi.webapp.powerswitch.rpi import PowerSwitch

pHat = Light()
power_switch = PowerSwitch()
Expand Down
7 changes: 4 additions & 3 deletions scripts/obs_tally_light.py
@@ -1,8 +1,10 @@
from multiprocessing.dummy import Pool
import obspython as obs
import json
import urllib.request
import urllib.error

threadpool = Pool(20)
light_mapping = {}
idle_color = int('FF0000FF', 16)
idle_brightness = 5
Expand Down Expand Up @@ -106,7 +108,6 @@ def call_tally_light(source, color, brightness):

except urllib.error.URLError as err:
obs.script_log(obs.LOG_WARNING, 'Error connecting to tally light URL %s: %s' % (url, err.reason))
obs.remove_current_callback()

def get_item_names_by_scene(source):
item_names = []
Expand All @@ -126,14 +127,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))
call_tally_light(item_name, color, brightness)
threadpool.apply_async(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:
call_tally_light(src, idle_color, idle_brightness)
threadpool.apply_async(call_tally_light, (src, idle_color, idle_brightness))

def handle_preview_change():
global preview_items
Expand Down

0 comments on commit 7fbd508

Please sign in to comment.