--- /dev/null
+import requests
+import time
+import sacn
+import RPi.GPIO as GPIO
+
+class clock:
+ def __init__(self):
+ self.url = "https://data.ozva.co.uk/shopping/clock.json"
+
+ self.request_speed = 0.1
+
+ self.light_speed = 0.5
+ self.cues = 0
+
+ self.current_position = 0
+ self.last_position = 0
+ self.movement_speed = 10
+ self.function = "linear"
+
+ get_loop = Process(target=self.get(), daemon = True)
+ move_loop = Process(target=self.move(), daemon = True)
+ light_loop = Process(target=self.light(), daemon = True)
+ get_loop.start()
+ move_loop.start()
+ light_loop.start()
+
+ def get(self):
+ try:
+ while True:
+ t = time.time()
+
+ r = requests.get(self.url)
+ data = r.json()
+
+ new_target = int(data["currentPosition"])
+ if new_target != self.target_position:
+ self.last_position = self.current_position
+ self.target_position = new_target
+
+ self.movement_speed = int(data["movementSpeed"])
+ self.function = data["function"]
+ self.cues = data["lightingCues"]
+
+ time.sleep(self.request_speed - (time.time() - t))
+
+ except:
+ pass
+
+ def move(self):
+ GPIO.setmode(GPIO.BOARD)
+ GPIO.setup((11, 13, 15), GPIO.OUT)
+
+ try:
+ while True:
+ t = time.time()
+
+ parked = self.current_position != self.target_position
+ forward = self.target_position >= self.current_position
+ if forward and (not parked):
+ GPIO.output(13, GPIO.HIGH)
+ GPIO.output(11, GPIO.HIGH)
+ elif (not forward) and (not parked):
+ GPIO.output(11, GPIO.HIGH)
+
+ GPIO.output((11, 13, 15), GPIO.LOW)
+
+ time.sleep(self.movement_speed - (time.time() - t))
+
+ except:
+ GPIO.cleanup()
+
+ def light(self):
+ sender = sacn.sACNsender()
+ sender.start()
+ sender.activate_output(2)
+ sender[2].multicast = True
+
+ try:
+ while True:
+ t = time.time()
+
+ data = tuple(255 if i == "true" else 0 for i in self.cues)
+ sender.dmx_data = data
+
+ time.sleep(self.light_speed - (time.time() - t))
+
+ except:
+ sender.stop()
+