create Dockerfile and config for rpi udp strip

This commit is contained in:
simon 2019-05-04 13:55:24 +02:00
parent 99787f74a1
commit add2e0b1a4
5 changed files with 77 additions and 58 deletions

View File

@ -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

View File

@ -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)

View File

@ -1,30 +1,20 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from util.RGBStrip import RGBStrip as RGBStrip
from util.UDPListner import UDPListner as UDPListner from util.UDPListner import UDPListner as UDPListner
import config
import sys 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 = [] udplistners = []
for rgbStrip in rgbStrips:
udplistners.append(UDPListner(rgbStrip,remoteaddr)) for rgbStrip in config.rgbStrips:
udplistners.append(UDPListner(rgbStrip,config.remoteaddr))
while True: while True:
try: try:
for udplistner in udplistners: for udplistner in udplistners:
udplistner.loop() udplistner.loop()
except KeyboardInterrupt: except KeyboardInterrupt:
for rgbStrip in rgbStrips: for rgbStrip in config.rgbStrips:
rgbStrip.stop() rgbStrip.stop()
sys.exit() sys.exit()

View File

@ -1,8 +1,11 @@
try: try:
import RPi.GPIO as GPIO import RPi.GPIO as GPIO
demo = False
except ImportError: except ImportError:
print("Install RPi.GPIO") print("!!! Install RPi.GPIO, running demo !!!")
demo = True
# setup PRi.GPIO # setup PRi.GPIO
if not demo:
GPIO.setmode(GPIO.BCM) GPIO.setmode(GPIO.BCM)
class RGBStrip: class RGBStrip:
@ -25,6 +28,7 @@ class RGBStrip:
self.GREEN_PIN = GREEN_PIN self.GREEN_PIN = GREEN_PIN
self.BLUE_PIN = BLUE_PIN self.BLUE_PIN = BLUE_PIN
if not demo:
# setup RED # setup RED
GPIO.setup(self.RED_PIN, GPIO.OUT) GPIO.setup(self.RED_PIN, GPIO.OUT)
self.RED_PWM = GPIO.PWM(self.RED_PIN, self.hertz) self.RED_PWM = GPIO.PWM(self.RED_PIN, self.hertz)
@ -39,7 +43,9 @@ class RGBStrip:
self.BLUE_PWM.start(0) self.BLUE_PWM.start(0)
def RGB(self,red,green,blue,brightness = 100): def RGB(self,red,green,blue,brightness = 100):
#print(self.STRIP_NAME,red,green,blue) if demo:
print(self.STRIP_NAME,red,green,blue)
else:
if(red < 0): if(red < 0):
red = 0 red = 0
if(red > 255): if(red > 255):
@ -64,6 +70,7 @@ class RGBStrip:
self.BLUE_PWM.ChangeDutyCycle(round(blue/255*100,2)) self.BLUE_PWM.ChangeDutyCycle(round(blue/255*100,2))
def stop(self): def stop(self):
if not demo:
self.RED_PWM.ChangeDutyCycle(0) self.RED_PWM.ChangeDutyCycle(0)
self.GREEN_PWM.ChangeDutyCycle(0) self.GREEN_PWM.ChangeDutyCycle(0)
self.BLUE_PWM.ChangeDutyCycle(0) self.BLUE_PWM.ChangeDutyCycle(0)

View File