From 4591dc6900c691b78795b1914ce5f6639c491649 Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Mon, 29 Jul 2024 13:38:14 -0500 Subject: [PATCH] Add show mode --- jukebox-web | 2 +- led_control.py | 24 +++++++++++++++++++ read_datasheet.py | 10 ++++---- run.py | 61 +++++++++++++++++++++++++++-------------------- 4 files changed, 65 insertions(+), 32 deletions(-) diff --git a/jukebox-web b/jukebox-web index 5a3943a..98ff934 160000 --- a/jukebox-web +++ b/jukebox-web @@ -1 +1 @@ -Subproject commit 5a3943ae46b62112017641adb06ed48969ae6298 +Subproject commit 98ff93479752e9834fe82e64187473ffb97ec314 diff --git a/led_control.py b/led_control.py index 5d97ca8..837f3d7 100755 --- a/led_control.py +++ b/led_control.py @@ -34,6 +34,9 @@ class LEDSystem(): animation_time = 0 start = uptime() solid_controllers = None + showtoggle = False + clearshow = -1 + showring = -1 def __init__(self): self.start = uptime() @@ -333,6 +336,8 @@ class LEDSystem(): def setmode(self, stmode, r=0,g=0,b=0): if stmode is not None: + if self.mode == "Show": + self.clearshow = self.showring if self.mode != stmode: self.firstrun = True @@ -363,6 +368,9 @@ class LEDSystem(): def runmodes(self, ring = -1, arm_position = None): #fprint("Mode: " + str(self.mode)) + if self.clearshow > -1: + self.setring(0,50,100,self.clearshow) + self.clearshow = -1 if self.mode == "Startup": # loading animation. cable check if self.firstrun: @@ -451,6 +459,22 @@ class LEDSystem(): else: self.setring(0,100,0,ring) self.setmode("Idle") + + elif self.mode == "Show": + if self.firstrun: + self.showring = ring + self.firstrun = False + self.showtoggle = False + self.changecount = self.animation_time / 2 # 100hz + if self.changecount > 0: + #self.changecount = self.fadeorder(self.rings[ring][2],self.rings[ring][3], self.changecount, 0,100,0) + if not self.showtoggle: + self.changecount = self.fadeorder(self.rings[ring][2],self.rings[ring][2]+24, self.changecount, 0,100,0) + else: + self.changecount = self.fadeorder(self.rings[ring][2],self.rings[ring][2]+24, self.changecount, 0,50,100) + else: + self.changecount = self.animation_time / 2 # 100hz + self.showtoggle = not self.showtoggle elif self.mode == "Idle": if self.firstrun: diff --git a/read_datasheet.py b/read_datasheet.py index b47f087..6ea3783 100755 --- a/read_datasheet.py +++ b/read_datasheet.py @@ -368,14 +368,14 @@ def parse(filename, output_dir, partnum, dstype, weburl, extra): output_table["brand"] = extra["brand"] else: output_table["brand"] = dstype - + output_table["datasheet"] = weburl + "datasheet.pdf" if img is not None: output_table["image"] = img - output_table["fullspecs"] = {"partnum": partnum, "id": id, "brand": output_table["brand"], "image": img, "datasheet": output_dir + "/datasheet.pdf", **tables} - output_table["searchspecs"] = {"partnum": partnum, "brand": output_table["brand"], "image": img, "datasheet": output_dir + "/datasheet.pdf", **flatten(tables)} + output_table["fullspecs"] = {"partnum": partnum, "id": id, "brand": output_table["brand"], "image": img, "datasheet": weburl + "datasheet.pdf", **tables} + output_table["searchspecs"] = {"partnum": partnum, "brand": output_table["brand"], "image": img, "datasheet": weburl + "datasheet.pdf", **flatten(tables)} else: - output_table["fullspecs"] = {"partnum": partnum, "id": id, "brand": output_table["brand"], "datasheet": output_dir + "/datasheet.pdf", **tables} - output_table["searchspecs"] = {"partnum": partnum, "brand": output_table["brand"], "datasheet": output_dir + "/datasheet.pdf", **flatten(tables)} + output_table["fullspecs"] = {"partnum": partnum, "id": id, "brand": output_table["brand"], "datasheet": weburl + "datasheet.pdf", **tables} + output_table["searchspecs"] = {"partnum": partnum, "brand": output_table["brand"], "datasheet": weburl + "datasheet.pdf", **flatten(tables)} if "short_description" in extra: output_table["short_description"] = extra["short_description"] diff --git a/run.py b/run.py index 8edaf46..794e0d4 100755 --- a/run.py +++ b/run.py @@ -335,7 +335,9 @@ def check_server(): mainloop_get.put(("return", data["tray"])) else: fprint("Invalid data.") - + elif call == 'request': + if "position" in data: + mainloop_get.put(("show", data["position"])) case _: fprint("Unknown/unimplemented data type: " + decoded["type"]) except Exception as e: @@ -782,36 +784,43 @@ def mainloop_server(pool, manager): mainloop_get.put(("return", newtube)) if not mainloop_get.empty(): - fprint("Movement requested. Keep clear of the machine!") action, get_cable = mainloop_get.get() - if get_cable > -1: - global sensors - if action == "pickup": - spot = get_open_spot(sensors) - if spot is not False: + if action == "show": + animation_wait = False + ring_animation = get_cable + start_animation = True + led_set_mode = "Show" + else: + fprint("Movement requested. Keep clear of the machine!") + + if get_cable > -1: + global sensors + if action == "pickup": + spot = get_open_spot(sensors) + if spot is not False: + arm_ready = False + if real: + animation_wait = False + ring_animation = get_cable + start_animation = True + led_set_mode = "GrabAA" + pool.apply_async(ur5_control.holder_to_tray, (arm, arm_updates, get_cable, spot), callback=arm_start_callback, error_callback=handle_error) + else: + arm_ready = True + fprint("Getting cable at position " + str(get_cable)) + mode = "Pickup" + cable_list_state[get_cable] = False # mark as removed + + + if action == "return": arm_ready = False + fprint("Returning cable from tray position " + str(get_cable)) if real: - animation_wait = False - ring_animation = get_cable - start_animation = True - led_set_mode = "GrabAA" - pool.apply_async(ur5_control.holder_to_tray, (arm, arm_updates, get_cable, spot), callback=arm_start_callback, error_callback=handle_error) + failcount = 0 + pool.apply_async(ur5_control.tray_to_camera, (arm, arm_updates, get_cable), callback=arm_start_callback, error_callback=handle_error) else: arm_ready = True - fprint("Getting cable at position " + str(get_cable)) - mode = "Pickup" - cable_list_state[get_cable] = False # mark as removed - - - if action == "return": - arm_ready = False - fprint("Returning cable from tray position " + str(get_cable)) - if real: - failcount = 0 - pool.apply_async(ur5_control.tray_to_camera, (arm, arm_updates, get_cable), callback=arm_start_callback, error_callback=handle_error) - else: - arm_ready = True - mode = "ReturnC" + mode = "ReturnC" else: # LED idle anim pass