attempt socket stuff
This commit is contained in:
parent
a4ad0da943
commit
0c9af2b968
5 changed files with 40 additions and 6 deletions
17
leds.py
17
leds.py
|
@ -10,7 +10,10 @@ from time import sleep
|
|||
import sys
|
||||
import lcd_manager
|
||||
import light_manager
|
||||
import pattern
|
||||
import logging
|
||||
import threading
|
||||
from socketengine import host
|
||||
|
||||
this = sys.modules[__name__]
|
||||
|
||||
|
@ -52,9 +55,23 @@ def displayon(lcd):
|
|||
lcd.display()
|
||||
|
||||
|
||||
def socket_loop():
|
||||
injected = False
|
||||
h = host('0.0.0.0', '29999')
|
||||
h.start()
|
||||
|
||||
while True:
|
||||
if not injected:
|
||||
this.lights.set_pattern(pattern.pat)
|
||||
data = h.getAll("pattern")
|
||||
if data is not None:
|
||||
pattern.parse(data)
|
||||
|
||||
|
||||
def loop():
|
||||
lcd = lcd_manager.Adafruit_CharLCD()
|
||||
lights = light_manager.LightStrip()
|
||||
this.lights = lights
|
||||
while True:
|
||||
logging.debug("loop")
|
||||
lights.tick()
|
||||
|
|
|
@ -2,10 +2,11 @@ from time import sleep
|
|||
import neopixel
|
||||
import board
|
||||
import logging
|
||||
import pattern
|
||||
|
||||
|
||||
def defaultPattern(n, t):
|
||||
return (((n + t) * 5) % 255, (t * 42) % 255, (t * 50) % 255)
|
||||
def defaultPattern(n, t, pv):
|
||||
return (0, 0, 0)
|
||||
|
||||
|
||||
class LightStrip:
|
||||
|
@ -26,17 +27,18 @@ class LightStrip:
|
|||
def set_light_level(self, level):
|
||||
self.np.brightness = level
|
||||
|
||||
def pattern(self, pattern_callback):
|
||||
def set_pattern(self, pattern_callback):
|
||||
self.pattern = pattern_callback
|
||||
|
||||
def get_next_pattern_tick(self):
|
||||
n = self.np.n
|
||||
np = self.np
|
||||
n = np.n
|
||||
t = self.cur_tick
|
||||
if not len(self.cur_pattern) >= n - 1:
|
||||
li = [(255, 255, 255)] * (n - len(self.cur_pattern))
|
||||
self.cur_pattern.extend(li)
|
||||
for i in range(n):
|
||||
self.cur_pattern[i] = self.pattern(i, t)
|
||||
self.cur_pattern[i] = self.pattern(i, t, np[i])
|
||||
self.cur_tick = t + 1
|
||||
|
||||
def tick(self):
|
||||
|
|
14
pattern.py
Normal file
14
pattern.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
this = sys.modules[__name__]
|
||||
|
||||
|
||||
def default(index, tick):
|
||||
return (((index + tick) * 5) % 255, (tick * 42) % 255, (tick * 50) % 255)
|
||||
|
||||
|
||||
def pat(index, tick, previous_values):
|
||||
return default(index, tick)
|
||||
|
||||
|
||||
def parse(str):
|
||||
this.encoded = str
|
||||
print(this.encoded)
|
|
@ -1,2 +1,3 @@
|
|||
rpi_ws281x==4.2.5
|
||||
adafruit-circuitpython-neopixel==6.0.0
|
||||
socket.engine==1.0.0
|
Loading…
Reference in a new issue