From e40372b7447897e7ff7c1e85f815ef952e2f7ef8 Mon Sep 17 00:00:00 2001 From: will Date: Mon, 19 Aug 2024 13:34:25 +0100 Subject: [PATCH] Fixed tabulator formatting --- clock.py | 164 +++++++++++++++++++++++++++---------------------------- 1 file changed, 82 insertions(+), 82 deletions(-) diff --git a/clock.py b/clock.py index 2cbbc8a..12e150c 100644 --- a/clock.py +++ b/clock.py @@ -4,86 +4,86 @@ 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() + 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() -- 2.39.2