create Dockerfile and config for rpi udp strip
This commit is contained in:
parent
99787f74a1
commit
add2e0b1a4
11
clients/strip-rpi-udp/Dockerfile
Normal file
11
clients/strip-rpi-udp/Dockerfile
Normal 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
|
11
clients/strip-rpi-udp/config.py
Normal file
11
clients/strip-rpi-udp/config.py
Normal 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)
|
@ -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()
|
@ -1,9 +1,12 @@
|
|||||||
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
|
||||||
GPIO.setmode(GPIO.BCM)
|
if not demo:
|
||||||
|
GPIO.setmode(GPIO.BCM)
|
||||||
|
|
||||||
class RGBStrip:
|
class RGBStrip:
|
||||||
STRIP_NAME = None
|
STRIP_NAME = None
|
||||||
@ -25,48 +28,52 @@ class RGBStrip:
|
|||||||
self.GREEN_PIN = GREEN_PIN
|
self.GREEN_PIN = GREEN_PIN
|
||||||
self.BLUE_PIN = BLUE_PIN
|
self.BLUE_PIN = BLUE_PIN
|
||||||
|
|
||||||
# setup RED
|
if not demo:
|
||||||
GPIO.setup(self.RED_PIN, GPIO.OUT)
|
# setup RED
|
||||||
self.RED_PWM = GPIO.PWM(self.RED_PIN, self.hertz)
|
GPIO.setup(self.RED_PIN, GPIO.OUT)
|
||||||
self.RED_PWM.start(0)
|
self.RED_PWM = GPIO.PWM(self.RED_PIN, self.hertz)
|
||||||
# setup GREEN
|
self.RED_PWM.start(0)
|
||||||
GPIO.setup(self.GREEN_PIN, GPIO.OUT)
|
# setup GREEN
|
||||||
self.GREEN_PWM = GPIO.PWM(self.GREEN_PIN, self.hertz)
|
GPIO.setup(self.GREEN_PIN, GPIO.OUT)
|
||||||
self.GREEN_PWM.start(0)
|
self.GREEN_PWM = GPIO.PWM(self.GREEN_PIN, self.hertz)
|
||||||
# setup BLUE
|
self.GREEN_PWM.start(0)
|
||||||
GPIO.setup(self.BLUE_PIN, GPIO.OUT)
|
# setup BLUE
|
||||||
self.BLUE_PWM = GPIO.PWM(self.BLUE_PIN, self.hertz)
|
GPIO.setup(self.BLUE_PIN, GPIO.OUT)
|
||||||
self.BLUE_PWM.start(0)
|
self.BLUE_PWM = GPIO.PWM(self.BLUE_PIN, self.hertz)
|
||||||
|
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:
|
||||||
if(red < 0):
|
print(self.STRIP_NAME,red,green,blue)
|
||||||
red = 0
|
else:
|
||||||
if(red > 255):
|
if(red < 0):
|
||||||
red = 255
|
red = 0
|
||||||
|
if(red > 255):
|
||||||
|
red = 255
|
||||||
|
|
||||||
if(green < 0):
|
if(green < 0):
|
||||||
green = 0
|
green = 0
|
||||||
if(green > 255):
|
if(green > 255):
|
||||||
green = 255
|
green = 255
|
||||||
|
|
||||||
if(blue < 0):
|
if(blue < 0):
|
||||||
blue = 0
|
blue = 0
|
||||||
if(blue > 255):
|
if(blue > 255):
|
||||||
blue = 255
|
blue = 255
|
||||||
|
|
||||||
if(brightness < 0):
|
if(brightness < 0):
|
||||||
brightness = 0
|
brightness = 0
|
||||||
if(brightness > 100):
|
if(brightness > 100):
|
||||||
brightness = 100
|
brightness = 100
|
||||||
self.RED_PWM.ChangeDutyCycle(round(red/255*100,2))
|
self.RED_PWM.ChangeDutyCycle(round(red/255*100,2))
|
||||||
self.GREEN_PWM.ChangeDutyCycle(round(green/255*100,2))
|
self.GREEN_PWM.ChangeDutyCycle(round(green/255*100,2))
|
||||||
self.BLUE_PWM.ChangeDutyCycle(round(blue/255*100,2))
|
self.BLUE_PWM.ChangeDutyCycle(round(blue/255*100,2))
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.RED_PWM.ChangeDutyCycle(0)
|
if not demo:
|
||||||
self.GREEN_PWM.ChangeDutyCycle(0)
|
self.RED_PWM.ChangeDutyCycle(0)
|
||||||
self.BLUE_PWM.ChangeDutyCycle(0)
|
self.GREEN_PWM.ChangeDutyCycle(0)
|
||||||
self.RED_PWM.stop()
|
self.BLUE_PWM.ChangeDutyCycle(0)
|
||||||
self.GREEN_PWM.stop()
|
self.RED_PWM.stop()
|
||||||
self.BLUE_PWM.stop()
|
self.GREEN_PWM.stop()
|
||||||
|
self.BLUE_PWM.stop()
|
0
clients/strip-rpi-udp/util/__init__.py
Normal file
0
clients/strip-rpi-udp/util/__init__.py
Normal file
Loading…
x
Reference in New Issue
Block a user