From add2e0b1a46df33837964d4ac956ceac980f957a Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 4 May 2019 13:55:24 +0200 Subject: [PATCH] create Dockerfile and config for rpi udp strip --- clients/strip-rpi-udp/Dockerfile | 11 +++ clients/strip-rpi-udp/config.py | 11 +++ clients/strip-rpi-udp/rpi_udp_strip.py | 20 ++---- clients/strip-rpi-udp/util/RGBStrip.py | 93 ++++++++++++++------------ clients/strip-rpi-udp/util/__init__.py | 0 5 files changed, 77 insertions(+), 58 deletions(-) create mode 100644 clients/strip-rpi-udp/Dockerfile create mode 100644 clients/strip-rpi-udp/config.py create mode 100644 clients/strip-rpi-udp/util/__init__.py diff --git a/clients/strip-rpi-udp/Dockerfile b/clients/strip-rpi-udp/Dockerfile new file mode 100644 index 0000000..31e7f64 --- /dev/null +++ b/clients/strip-rpi-udp/Dockerfile @@ -0,0 +1,11 @@ +FROM python:3.7.2-alpine3.9 + +RUN echo "@community http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories +RUN apk add --update --no-cache ca-certificates gcc g++ curl openblas-dev@community +RUN ln -s /usr/include/locale.h /usr/include/xlocale.h + +RUN pip install --no-cache-dir RPi.GPIO + +WORKDIR /usr/src/rpi-udp-strip +COPY . /usr/src/rpi-udp-strip +CMD python3.7 -u /usr/src/rpi-udp-strip/rpi_udp_strip.py diff --git a/clients/strip-rpi-udp/config.py b/clients/strip-rpi-udp/config.py new file mode 100644 index 0000000..4fdce19 --- /dev/null +++ b/clients/strip-rpi-udp/config.py @@ -0,0 +1,11 @@ +from util.RGBStrip import RGBStrip as RGBStrip + +#use the BCM pin numbers here +rgbStrips = [ + #RGBStrip("Test Dahem", 4, 17 , 22), + RGBStrip("Unter Theke", 20, 16 , 21), + RGBStrip("Über Theke", 22, 13, 27), + RGBStrip("Fensterbank", 5, 26, 6) +] +# set remote address and port +remoteaddr = ("192.168.0.255",8002) \ No newline at end of file diff --git a/clients/strip-rpi-udp/rpi_udp_strip.py b/clients/strip-rpi-udp/rpi_udp_strip.py index bd0379d..a1adbc2 100644 --- a/clients/strip-rpi-udp/rpi_udp_strip.py +++ b/clients/strip-rpi-udp/rpi_udp_strip.py @@ -1,30 +1,20 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from util.RGBStrip import RGBStrip as RGBStrip from util.UDPListner import UDPListner as UDPListner +import config import sys -#use the BCM pin numbers here -rgbStrips = [ - #RGBStrip("Test Dahem", 4, 17 , 22), - RGBStrip("Unter Theke", 20, 16 , 21), - RGBStrip("Über Theke", 22, 13, 27), - RGBStrip("Fensterbank", 5, 26, 6) -] -# set remote address and port -remoteaddr = ("192.168.0.255",8002) - - udplistners = [] -for rgbStrip in rgbStrips: - udplistners.append(UDPListner(rgbStrip,remoteaddr)) + +for rgbStrip in config.rgbStrips: + udplistners.append(UDPListner(rgbStrip,config.remoteaddr)) while True: try: for udplistner in udplistners: udplistner.loop() except KeyboardInterrupt: - for rgbStrip in rgbStrips: + for rgbStrip in config.rgbStrips: rgbStrip.stop() sys.exit() \ No newline at end of file diff --git a/clients/strip-rpi-udp/util/RGBStrip.py b/clients/strip-rpi-udp/util/RGBStrip.py index a7956da..efdead4 100644 --- a/clients/strip-rpi-udp/util/RGBStrip.py +++ b/clients/strip-rpi-udp/util/RGBStrip.py @@ -1,9 +1,12 @@ try: import RPi.GPIO as GPIO + demo = False except ImportError: - print("Install RPi.GPIO") + print("!!! Install RPi.GPIO, running demo !!!") + demo = True # setup PRi.GPIO -GPIO.setmode(GPIO.BCM) +if not demo: + GPIO.setmode(GPIO.BCM) class RGBStrip: STRIP_NAME = None @@ -25,48 +28,52 @@ class RGBStrip: self.GREEN_PIN = GREEN_PIN self.BLUE_PIN = BLUE_PIN - # setup RED - GPIO.setup(self.RED_PIN, GPIO.OUT) - self.RED_PWM = GPIO.PWM(self.RED_PIN, self.hertz) - self.RED_PWM.start(0) - # setup GREEN - GPIO.setup(self.GREEN_PIN, GPIO.OUT) - self.GREEN_PWM = GPIO.PWM(self.GREEN_PIN, self.hertz) - self.GREEN_PWM.start(0) - # setup BLUE - GPIO.setup(self.BLUE_PIN, GPIO.OUT) - self.BLUE_PWM = GPIO.PWM(self.BLUE_PIN, self.hertz) - self.BLUE_PWM.start(0) + if not demo: + # setup RED + GPIO.setup(self.RED_PIN, GPIO.OUT) + self.RED_PWM = GPIO.PWM(self.RED_PIN, self.hertz) + self.RED_PWM.start(0) + # setup GREEN + GPIO.setup(self.GREEN_PIN, GPIO.OUT) + self.GREEN_PWM = GPIO.PWM(self.GREEN_PIN, self.hertz) + self.GREEN_PWM.start(0) + # setup BLUE + GPIO.setup(self.BLUE_PIN, GPIO.OUT) + self.BLUE_PWM = GPIO.PWM(self.BLUE_PIN, self.hertz) + self.BLUE_PWM.start(0) def RGB(self,red,green,blue,brightness = 100): - #print(self.STRIP_NAME,red,green,blue) - if(red < 0): - red = 0 - if(red > 255): - red = 255 - - if(green < 0): - green = 0 - if(green > 255): - green = 255 - - if(blue < 0): - blue = 0 - if(blue > 255): - blue = 255 - - if(brightness < 0): - brightness = 0 - if(brightness > 100): - brightness = 100 - self.RED_PWM.ChangeDutyCycle(round(red/255*100,2)) - self.GREEN_PWM.ChangeDutyCycle(round(green/255*100,2)) - self.BLUE_PWM.ChangeDutyCycle(round(blue/255*100,2)) + if demo: + print(self.STRIP_NAME,red,green,blue) + else: + if(red < 0): + red = 0 + if(red > 255): + red = 255 + + if(green < 0): + green = 0 + if(green > 255): + green = 255 + + if(blue < 0): + blue = 0 + if(blue > 255): + blue = 255 + + if(brightness < 0): + brightness = 0 + if(brightness > 100): + brightness = 100 + self.RED_PWM.ChangeDutyCycle(round(red/255*100,2)) + self.GREEN_PWM.ChangeDutyCycle(round(green/255*100,2)) + self.BLUE_PWM.ChangeDutyCycle(round(blue/255*100,2)) def stop(self): - self.RED_PWM.ChangeDutyCycle(0) - self.GREEN_PWM.ChangeDutyCycle(0) - self.BLUE_PWM.ChangeDutyCycle(0) - self.RED_PWM.stop() - self.GREEN_PWM.stop() - self.BLUE_PWM.stop() \ No newline at end of file + if not demo: + self.RED_PWM.ChangeDutyCycle(0) + self.GREEN_PWM.ChangeDutyCycle(0) + self.BLUE_PWM.ChangeDutyCycle(0) + self.RED_PWM.stop() + self.GREEN_PWM.stop() + self.BLUE_PWM.stop() \ No newline at end of file diff --git a/clients/strip-rpi-udp/util/__init__.py b/clients/strip-rpi-udp/util/__init__.py new file mode 100644 index 0000000..e69de29