tidy up, split into server/client
This commit is contained in:
@@ -1,98 +0,0 @@
|
||||
try:
|
||||
import RPi.GPIO as GPIO
|
||||
except ImportError:
|
||||
import rgbUtils.fakeGPIO as GPIO
|
||||
from rgbUtils.debug import debug
|
||||
class RGBStrip:
|
||||
STRIP_NAME = None
|
||||
|
||||
issetup = False
|
||||
|
||||
effectClassInstance = None
|
||||
|
||||
# GPIO PWM Frequenz
|
||||
hertz = 100
|
||||
|
||||
RED_PIN = None
|
||||
GREEN_PIN = None
|
||||
BLUE_PIN = None
|
||||
|
||||
RED_PWM = None
|
||||
GREEN_PWM = None
|
||||
BLUE_PWM = None
|
||||
|
||||
|
||||
def __init__(self,STRIP_NAME,RED_PIN,GREEN_PIN,BLUE_PIN):
|
||||
self.STRIP_NAME = STRIP_NAME
|
||||
self.RED_PIN = RED_PIN
|
||||
self.GREEN_PIN = GREEN_PIN
|
||||
self.BLUE_PIN = BLUE_PIN
|
||||
|
||||
def init(self):
|
||||
if not self.issetup:
|
||||
debug("setting up")
|
||||
# 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)
|
||||
|
||||
self.issetup = True
|
||||
|
||||
def RGB(self,red,green,blue,brightness = 100):
|
||||
|
||||
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 = red
|
||||
self.green = green
|
||||
self.blue = blue
|
||||
self.RED_PWM.ChangeDutyCycle(round((red/255*100)/100*brightness,2))
|
||||
self.GREEN_PWM.ChangeDutyCycle(round((green/255*100)/100*brightness,2))
|
||||
self.BLUE_PWM.ChangeDutyCycle(round((blue/255*100)/100*brightness,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()
|
||||
|
||||
|
||||
|
||||
# I have to be sure that a rgbStip is only used by one Effect at once, so i save the current running Effect Class Object
|
||||
# in the rgbStip object.
|
||||
def setEffectClassInstance(self,effectClass):
|
||||
debug("RGBStrip "+ self.STRIP_NAME + " Effect is now " + str(effectClass))
|
||||
self.effectClassInstance = effectClass
|
||||
|
||||
def getEffectClassInstance(self):
|
||||
return self.effectClassInstance
|
||||
|
||||
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
# The Master Strip that can be used as multiple RGBStrips or later as one for Special Effects
|
||||
# see https://github.com/mdaffin/PyNeoPixel for arduino ino
|
||||
|
||||
import struct
|
||||
import serial
|
||||
import time
|
||||
|
||||
|
||||
class WS2812MasterStrip:
|
||||
|
||||
def __init__(self,port,LED_COUNT):
|
||||
|
||||
#serial connection
|
||||
self.port = port
|
||||
self.ser = serial.Serial(self.port, 115200, timeout=1)
|
||||
self.command_count = 0
|
||||
|
||||
self.LED_COUNT = LED_COUNT
|
||||
|
||||
self.lock = False
|
||||
|
||||
self.setPixelColorRange(1,LED_COUNT, 0, 0, 0)
|
||||
|
||||
def setPixelColorRange(self, pixelstart, pixelstop, red, green, blue):
|
||||
# locking while sending serial data, because multiple threads
|
||||
# could try to send data at the same time
|
||||
while self.lock:
|
||||
#time.sleep(0.001)
|
||||
return
|
||||
self.lock = True
|
||||
|
||||
for pixel in [pixelstart,pixelstop]:
|
||||
if pixelstart > self.LED_COUNT:
|
||||
print("WS2812MasterStrip@"+self.port+" Strip is only "+self.LED_COUNT+" pixels long")
|
||||
return
|
||||
pixelstart = pixelstart - 1
|
||||
pixelstop = pixelstop - 1
|
||||
message = struct.pack('>BBBHHBBB', ord(':'), self.command_count, ord('r'), pixelstart, pixelstop, red, green, blue)
|
||||
self.command_count += 1
|
||||
if self.command_count >=255:
|
||||
self.command_count = 0
|
||||
#print(message)
|
||||
self.ser.write(message)
|
||||
response = self.ser.readline()
|
||||
self.lock = False
|
||||
#print(response)
|
||||
@@ -1,61 +0,0 @@
|
||||
from rgbUtils.debug import debug
|
||||
from rgbUtils.RGBStrip import RGBStrip
|
||||
|
||||
# The WS2812Strip must have the same behavior as the 12v rgb strip,
|
||||
# plus some extras for these type of strips only.
|
||||
# A WS1812 Strip can be initialised as multiple RGB Strips by defining
|
||||
# the start and the end led's. lets's see how that goes
|
||||
class WS2812Strip(RGBStrip):
|
||||
STRIP_NAME = None
|
||||
|
||||
master = None
|
||||
FIRST_LED = None
|
||||
LAST_LED = None
|
||||
|
||||
def __init__(self,STRIP_NAME,FIRST_LED,LAST_LED,WS2812B_MASTER_STRIP):
|
||||
self.STRIP_NAME = STRIP_NAME
|
||||
self.master = WS2812B_MASTER_STRIP
|
||||
self.FIRST_LED = FIRST_LED
|
||||
self.LAST_LED = LAST_LED
|
||||
|
||||
# init the WS2812 part. since the master sets all pixel to 0 in init,
|
||||
# we have nothing to do here.
|
||||
def init(self):
|
||||
if not self.issetup:
|
||||
debug("setting up")
|
||||
self.issetup = True
|
||||
|
||||
def RGB(self,red,green,blue,brightness = 100):
|
||||
|
||||
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
|
||||
green = 255
|
||||
|
||||
if(brightness < 0):
|
||||
brightness = 0
|
||||
if(brightness > 255):
|
||||
brightness = 100
|
||||
|
||||
self.red = red
|
||||
self.green = green
|
||||
self.blue = blue
|
||||
self.master.setPixelColorRange(self.FIRST_LED,self.LAST_LED, int(round(red/100*brightness)), int(round(green/100*brightness)), int(round(blue/100*brightness)))
|
||||
|
||||
|
||||
def stop(self):
|
||||
self.master.setPixelColorRange(self.FIRST_LED,self.LAST_LED, 0, 0,0)
|
||||
|
||||
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Fake RPi.GPIO package
|
||||
'''
|
||||
#______________________________________________________________________
|
||||
# imports
|
||||
|
||||
#______________________________________________________________________
|
||||
# globals
|
||||
BCM = 'BCM'
|
||||
BOARD = 'BOARD'
|
||||
|
||||
OUT = 'OUT'
|
||||
IN = 'IN'
|
||||
|
||||
LOW = 'LOW'
|
||||
HIGH = 'HIGH'
|
||||
|
||||
FALLING = 'FALLING'
|
||||
RISING = 'RISING'
|
||||
|
||||
PUD_UP = 'PUD_UP'
|
||||
PUD_DOWN = 'PUD_DOWN'
|
||||
|
||||
RPI_INFO = {'INFO': 'Fake GPIO, ¬¬', 'P1_REVISION': 'Fake GPIO, ¬¬'}
|
||||
|
||||
VERSION = '0.2.0a0'
|
||||
|
||||
#______________________________________________________________________
|
||||
# VERBOSE
|
||||
VERBOSE = False
|
||||
|
||||
#______________________________________________________________________
|
||||
# functions wrapper/ base fucntion
|
||||
def print_data(func):
|
||||
def verbose(*args, **kwargs):
|
||||
if VERBOSE:
|
||||
print(func.__name__, args, kwargs)
|
||||
return verbose
|
||||
|
||||
#______________________________________________________________________
|
||||
# PWM class
|
||||
class PWM(object):
|
||||
|
||||
@print_data
|
||||
def __init__(self, channel, frequency):
|
||||
self.channel = channel
|
||||
self.frequency = frequency
|
||||
self.dc = 0
|
||||
|
||||
@print_data
|
||||
def start(self, dc):
|
||||
pass
|
||||
|
||||
@print_data
|
||||
def ChangeFrequency(self, freq):
|
||||
self.frequency = freq
|
||||
|
||||
@print_data
|
||||
def ChangeDutyCycle(self, dc):
|
||||
self.dc = dc
|
||||
|
||||
@print_data
|
||||
def stop(self):
|
||||
pass
|
||||
|
||||
#______________________________________________________________________
|
||||
# functions
|
||||
|
||||
@print_data
|
||||
def setmode(*args, **kwargs):
|
||||
pass
|
||||
|
||||
@print_data
|
||||
def setup(*args, **kwargs):
|
||||
pass
|
||||
|
||||
@print_data
|
||||
def output(*args, **kwargs):
|
||||
pass
|
||||
|
||||
@print_data
|
||||
def input(*args, **kwargs):
|
||||
pass
|
||||
|
||||
@print_data
|
||||
def cleanup(*args, **kwargs):
|
||||
pass
|
||||
|
||||
@print_data
|
||||
def wait_for_edge(*args, **kwargs):
|
||||
pass
|
||||
|
||||
@print_data
|
||||
def event_detected(*args, **kwargs):
|
||||
pass
|
||||
|
||||
@print_data
|
||||
def add_event_detect(*args, **kwargs):
|
||||
pass
|
||||
|
||||
@print_data
|
||||
def add_event_callback(*args, **kwargs):
|
||||
pass
|
||||
|
||||
@print_data
|
||||
def remove_event_detect(*args, **kwargs):
|
||||
pass
|
||||
|
||||
@print_data
|
||||
def setwarnings(*args, **kwargs):
|
||||
pass
|
||||
@@ -39,7 +39,7 @@ class rgbStripController(threading.Thread):
|
||||
# remove onRGBStripRegisteredHandler
|
||||
def removeOnRGBStripRegisteredHandler(self, function):
|
||||
self.onRGBStripRegisteredHandler.remove(function)
|
||||
|
||||
|
||||
# inform all onRGBStripUnRegisteredHandder about the removed RGBStrip
|
||||
def noticeRGBStripUnRegisteredHandler(self,rgbStrip):
|
||||
for hander in self.onRGBStripUnRegisteredHandler:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user