|
|
@ -29,7 +29,6 @@ CONFIG = load_config()
|
|
|
|
LED_COUNT = 60 # Number of LED pixels.
|
|
|
|
LED_COUNT = 60 # Number of LED pixels.
|
|
|
|
LED_PIN = board.D18 # GPIO pin connected to the pixels (must support PWM!).
|
|
|
|
LED_PIN = board.D18 # GPIO pin connected to the pixels (must support PWM!).
|
|
|
|
LED_PIXEL_ORDER = neopixel.GRB # Strip type and colour ordering
|
|
|
|
LED_PIXEL_ORDER = neopixel.GRB # Strip type and colour ordering
|
|
|
|
LED_BRIGHTNESS = 0.05
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Zahl stellt den Wert in Minuten dar, wie lange kein Gerät erreichbar sein darf dass die Uhr "abgeschalten" wird
|
|
|
|
# Zahl stellt den Wert in Minuten dar, wie lange kein Gerät erreichbar sein darf dass die Uhr "abgeschalten" wird
|
|
|
|
ABSCHALTWERT = 4
|
|
|
|
ABSCHALTWERT = 4
|
|
|
@ -51,13 +50,20 @@ stdliste = [std0, std1, std2, std3, std4, std5, std6, std7, std8, std9, std10, s
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Uhr:
|
|
|
|
class Uhr:
|
|
|
|
def __init__(self, pixels):
|
|
|
|
def __init__(self, pixels, mode):
|
|
|
|
self.helligkeit = pixels.brightness
|
|
|
|
self.helligkeit = pixels.brightness
|
|
|
|
self.pixels = pixels
|
|
|
|
self.pixels = pixels
|
|
|
|
|
|
|
|
self.helligkeit_geaendert = None
|
|
|
|
|
|
|
|
self.mode = mode
|
|
|
|
|
|
|
|
self._rgb_leer = None
|
|
|
|
|
|
|
|
self._rgb_sekunde = None
|
|
|
|
|
|
|
|
self._rgb_minute = None
|
|
|
|
|
|
|
|
self._rgb_stunde = None
|
|
|
|
|
|
|
|
|
|
|
|
def set_helligkeit(self, helligkeit):
|
|
|
|
def set_helligkeit(self, helligkeit):
|
|
|
|
self.helligkeit = helligkeit
|
|
|
|
self.helligkeit = helligkeit
|
|
|
|
self.pixels.brightness = self.helligkeit
|
|
|
|
self.pixels.brightness = self.helligkeit
|
|
|
|
|
|
|
|
self.helligkeit_geaendert = datetime.datetime.now()
|
|
|
|
|
|
|
|
|
|
|
|
def helligkeit_erhoehen(self):
|
|
|
|
def helligkeit_erhoehen(self):
|
|
|
|
self.helligkeit += 0.05
|
|
|
|
self.helligkeit += 0.05
|
|
|
@ -71,6 +77,18 @@ class Uhr:
|
|
|
|
self.helligkeit = 1
|
|
|
|
self.helligkeit = 1
|
|
|
|
self.set_helligkeit(self.helligkeit)
|
|
|
|
self.set_helligkeit(self.helligkeit)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def rgb_farben_lesen(self):
|
|
|
|
|
|
|
|
self._rgb_leer = CONFIG["mode"][self.mode]["leer"]
|
|
|
|
|
|
|
|
self._rgb_sekunde = CONFIG["mode"][self.mode]["sekunde"]
|
|
|
|
|
|
|
|
self._rgb_minute = CONFIG["mode"][self.mode]["minute"]
|
|
|
|
|
|
|
|
self._rgb_stunde = CONFIG["mode"][self.mode]["stunde"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rgbconf = {"rgb_leer": self._rgb_leer, "rgb_s": self._rgb_sekunde, "rgb_min": self._rgb_minute,
|
|
|
|
|
|
|
|
"rgb_std": self._rgb_stunde}
|
|
|
|
|
|
|
|
print("In der Klasse:")
|
|
|
|
|
|
|
|
print(rgbconf)
|
|
|
|
|
|
|
|
return rgbconf
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# GPIO
|
|
|
|
# GPIO
|
|
|
|
I_MODE_TASTER = gpiozero.Button(3)
|
|
|
|
I_MODE_TASTER = gpiozero.Button(3)
|
|
|
@ -78,17 +96,10 @@ I_PLUS_TASTER = gpiozero.Button(4)
|
|
|
|
I_MINUS_TASTER = gpiozero.Button(17)
|
|
|
|
I_MINUS_TASTER = gpiozero.Button(17)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # # # # # # # # #
|
|
|
|
def config_schreiben(pfad=SKRIPTPFAD):
|
|
|
|
# Funktionen
|
|
|
|
configfile = os.path.join(pfad, "uhr_cfg.toml")
|
|
|
|
# # # # # # # # # #
|
|
|
|
with open(configfile, "w") as conffile:
|
|
|
|
# Farbkonfiguration
|
|
|
|
conffile.write(toml.dumps(CONFIG))
|
|
|
|
def rgb_standard():
|
|
|
|
|
|
|
|
rgb_leer = [0, 0, 0]
|
|
|
|
|
|
|
|
rgb_s = [0, 180, 0]
|
|
|
|
|
|
|
|
rgb_min = [32, 178, 170]
|
|
|
|
|
|
|
|
rgb_std = [255, 0, 255]
|
|
|
|
|
|
|
|
rgbconf = {"rgb_leer": rgb_leer, "rgb_s": rgb_s, "rgb_min": rgb_min, "rgb_std": rgb_std}
|
|
|
|
|
|
|
|
return rgbconf
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def alle_led(r, g, b, pixels):
|
|
|
|
def alle_led(r, g, b, pixels):
|
|
|
@ -153,7 +164,7 @@ def shutdown():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Threads
|
|
|
|
# Threads
|
|
|
|
def check_anwesenheit(uhr):
|
|
|
|
def check_anwesenheit(uhr, pixels):
|
|
|
|
"""Funktion, welche als eigener Thread laeuft, um selbststaendig in einem gewissenen Intervall
|
|
|
|
"""Funktion, welche als eigener Thread laeuft, um selbststaendig in einem gewissenen Intervall
|
|
|
|
alle Geraete in der Toml Liste zu pingen
|
|
|
|
alle Geraete in der Toml Liste zu pingen
|
|
|
|
arg: Objekt des neopixel LED Ringes
|
|
|
|
arg: Objekt des neopixel LED Ringes
|
|
|
@ -178,7 +189,7 @@ def check_anwesenheit(uhr):
|
|
|
|
"""pingt die IP 3x an
|
|
|
|
"""pingt die IP 3x an
|
|
|
|
return (0 | !0) 0 wenn erreichbar
|
|
|
|
return (0 | !0) 0 wenn erreichbar
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
befehl = "/usr/bin/arping -c 3 -w 10 -b -f -I {interface} {ip}".format(interface=interface, ip=ip)
|
|
|
|
befehl = "/usr/bin/arping -q -c 3 -w 10 -b -f -I {interface} {ip}".format(interface=interface, ip=ip)
|
|
|
|
cmd = shlex.split(befehl)
|
|
|
|
cmd = shlex.split(befehl)
|
|
|
|
return subprocess.call(cmd)
|
|
|
|
return subprocess.call(cmd)
|
|
|
|
|
|
|
|
|
|
|
@ -219,10 +230,10 @@ def check_anwesenheit(uhr):
|
|
|
|
if len(status_anwesend_liste) > ABSCHALTWERT:
|
|
|
|
if len(status_anwesend_liste) > ABSCHALTWERT:
|
|
|
|
helligkeit = 0
|
|
|
|
helligkeit = 0
|
|
|
|
if status["dimmen"]:
|
|
|
|
if status["dimmen"]:
|
|
|
|
helligkeit = uhr.helligkeit * 0.5
|
|
|
|
helligkeit = 0.03
|
|
|
|
if now.hour < 5 and not status["dimmen"]:
|
|
|
|
if now.hour < 5 and not status["dimmen"]:
|
|
|
|
helligkeit = 0
|
|
|
|
helligkeit = 0
|
|
|
|
uhr.set_helligkeit(helligkeit)
|
|
|
|
pixels.brightness = helligkeit
|
|
|
|
last = datetime.datetime.now()
|
|
|
|
last = datetime.datetime.now()
|
|
|
|
delta = now - last
|
|
|
|
delta = now - last
|
|
|
|
time.sleep(30)
|
|
|
|
time.sleep(30)
|
|
|
@ -231,12 +242,15 @@ def check_anwesenheit(uhr):
|
|
|
|
def main():
|
|
|
|
def main():
|
|
|
|
lastsecond = None
|
|
|
|
lastsecond = None
|
|
|
|
led_gesetzt = 0
|
|
|
|
led_gesetzt = 0
|
|
|
|
rgbconf = rgb_standard()
|
|
|
|
|
|
|
|
pixels = neopixel.NeoPixel(LED_PIN, LED_COUNT, brightness=LED_BRIGHTNESS,
|
|
|
|
pixels = neopixel.NeoPixel(LED_PIN, LED_COUNT, brightness=CONFIG["led_helligkeit"],
|
|
|
|
auto_write=False, pixel_order=LED_PIXEL_ORDER)
|
|
|
|
auto_write=False, pixel_order=LED_PIXEL_ORDER)
|
|
|
|
uhr = Uhr(pixels)
|
|
|
|
uhr = Uhr(pixels, CONFIG["mode_nummer"])
|
|
|
|
thread_check_wlan = threading.Thread(target=check_anwesenheit, args=(uhr,))
|
|
|
|
thread_check_wlan = threading.Thread(target=check_anwesenheit, args=(uhr, pixels))
|
|
|
|
thread_check_wlan.start()
|
|
|
|
thread_check_wlan.start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rgbconf = uhr.rgb_farben_lesen()
|
|
|
|
|
|
|
|
print(rgbconf)
|
|
|
|
alle_led(rgbconf["rgb_leer"][0], rgbconf["rgb_leer"][1], rgbconf["rgb_leer"][2], pixels)
|
|
|
|
alle_led(rgbconf["rgb_leer"][0], rgbconf["rgb_leer"][1], rgbconf["rgb_leer"][2], pixels)
|
|
|
|
|
|
|
|
|
|
|
|
I_PLUS_TASTER.when_pressed = uhr.helligkeit_erhoehen
|
|
|
|
I_PLUS_TASTER.when_pressed = uhr.helligkeit_erhoehen
|
|
|
@ -244,10 +258,16 @@ def main():
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
while True:
|
|
|
|
while True:
|
|
|
|
rgbconf = rgb_standard()
|
|
|
|
rgbconf = uhr.rgb_farben_lesen()
|
|
|
|
|
|
|
|
print(rgbconf)
|
|
|
|
now = datetime.datetime.now()
|
|
|
|
now = datetime.datetime.now()
|
|
|
|
if lastsecond != now.second:
|
|
|
|
if lastsecond != now.second:
|
|
|
|
lastsecond, led_gesetzt = led_calc(now, stdliste, rgbconf, led_gesetzt, pixels)
|
|
|
|
lastsecond, led_gesetzt = led_calc(now, stdliste, rgbconf, led_gesetzt, pixels)
|
|
|
|
|
|
|
|
if uhr.helligkeit_geaendert is not None:
|
|
|
|
|
|
|
|
if (datetime.datetime.now() - uhr.helligkeit_geaendert) > datetime.timedelta(seconds=30):
|
|
|
|
|
|
|
|
CONFIG["led_helligkeit"] = uhr.helligkeit
|
|
|
|
|
|
|
|
config_schreiben()
|
|
|
|
|
|
|
|
uhr.helligkeit_geaendert = None
|
|
|
|
time.sleep(0.2)
|
|
|
|
time.sleep(0.2)
|
|
|
|
finally:
|
|
|
|
finally:
|
|
|
|
pixels.brightness = 0
|
|
|
|
pixels.brightness = 0
|
|
|
|