From f1b38b9bcebf75a2d804b1ba3203cd735f29df80 Mon Sep 17 00:00:00 2001 From: Jens Ullmert Date: Wed, 27 Jul 2022 11:57:34 +0200 Subject: [PATCH] sleep longer and run in pi --- Python/sock.py | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/Python/sock.py b/Python/sock.py index 4d319f1..91b1d7d 100644 --- a/Python/sock.py +++ b/Python/sock.py @@ -3,16 +3,26 @@ # WS server example that synchronizes state across clients import asyncio -# import json +import json import logging import websockets -# import redis +import redis import time import serial import numpy as np -#import RPi.GPIO as GPIO +import RPi.GPIO as GPIO import threading +import os + +def is_raspberrypi(): + try: + with io.open('/sys/firmware/devicetree/base/model', 'r') as m: + if 'raspberry pi' in m.read().lower(): return True + except Exception: pass + return False +print(is_raspberrypi) + # Colordefinition for console print class pcol: @@ -46,7 +56,7 @@ DMXRST = 88.0 # typical 88µs DMXBRK = 8.0 # 8µs (min) to 1s (max) # DMX Sequence sleep [ms]/float -DMXSLP = 250.0 # 0µs (min) to 1s (max) +DMXSLP = 5000.0 #250.0 # 0µs (min) to 1s (max) # Buffer for RDM DMXRDM = 0 @@ -95,7 +105,7 @@ def sendDMX(data): DMXSER.cancel_read() # GPIO_18 to switch RS-485 driver (IC1) to TX-mode - #GPIO.output(18, GPIO.HIGH) + GPIO.output(18, GPIO.HIGH) # send reset DMXSER.send_break(DMXRST / 1000000.0) @@ -108,7 +118,7 @@ def sendDMX(data): # GPIO_18 to switch RS-485 driver (IC1) to RX-mode DMXSER.reset_input_buffer() - #GPIO.output(18, GPIO.LOW) + GPIO.output(18, GPIO.LOW) # Sleep between TX packages, use time to get RDM packages DMXRDM = "" @@ -297,19 +307,20 @@ async def websworker(websocket, path): # ########################### # We have to set GPIO -#GPIO.setmode(GPIO.BCM) -#GPIO.setwarnings(False) +GPIO.setmode(GPIO.BCM) +GPIO.setwarnings(False) -#GPIO.setup(18, GPIO.OUT) -#GPIO.setup(4, GPIO.OUT) +GPIO.setup(18, GPIO.OUT) +GPIO.setup(4, GPIO.OUT) # GPIO_18 to switch RS-485 driver (IC1) to RX-mode #GPIO.output(18, GPIO.LOW) +# V2: will be done in send-loop for rdm # Powercycle 3V3 on HAT to ensure a cleaned up buffer -#GPIO.output(4, GPIO.HIGH) -#time.sleep(0.25) -#GPIO.output(4, GPIO.LOW) +GPIO.output(4, GPIO.HIGH) +time.sleep(0.25) +GPIO.output(4, GPIO.LOW)