Restructure LightbarServer; implement LightbarController
This commit is contained in:
parent
144e7d556f
commit
722abc3056
8 changed files with 76 additions and 39 deletions
48
src/main.py
48
src/main.py
|
|
@ -1,38 +1,18 @@
|
|||
from machine import Pin
|
||||
from neopixel import NeoPixel
|
||||
import uasyncio
|
||||
from lightbar.lightbar_controller import LightbarController
|
||||
from lightbar.lightbar_server import LightbarServer
|
||||
|
||||
from lightbar.app import Lightbar
|
||||
try:
|
||||
import lightbar_cfg
|
||||
except Exception as e:
|
||||
print('[main] Could not import lightbar_cfg.py: {}'.format(str(e)))
|
||||
raise e
|
||||
|
||||
# TODO: Move this to config file
|
||||
NEOPIXEL_COUNT = 28
|
||||
print('[main] Starting lightbar controller')
|
||||
lightbar_controller = LightbarController(neopixel_count=lightbar_cfg.NEOPIXEL_COUNT)
|
||||
lightbar_controller.start()
|
||||
|
||||
print('[main] Starting lightbar HTTP server')
|
||||
api_server = LightbarServer()
|
||||
api_server.run(port=lightbar_cfg.SERVER_PORT, debug=lightbar_cfg.SERVER_DEBUG)
|
||||
|
||||
# TODO: Move this into a LightbarController class
|
||||
async def run_neopixels():
|
||||
print('[main/run_neopixels] Turning on Neopixels')
|
||||
np = NeoPixel(Pin(26), NEOPIXEL_COUNT)
|
||||
np.fill((0, 0, 0))
|
||||
np.write()
|
||||
|
||||
color_set = [
|
||||
(255, 0, 0),
|
||||
(255, 255, 0),
|
||||
(0, 255, 0),
|
||||
(0, 255, 255),
|
||||
(0, 0, 255),
|
||||
(255, 0, 255),
|
||||
]
|
||||
|
||||
while True:
|
||||
for i in range(NEOPIXEL_COUNT):
|
||||
np[i] = color_set[i % len(color_set)]
|
||||
np.write()
|
||||
|
||||
await uasyncio.sleep(0.5)
|
||||
|
||||
uasyncio.create_task(run_neopixels())
|
||||
|
||||
print('[main] Starting lightbar HTTP server...')
|
||||
api_server = Lightbar()
|
||||
api_server.run(port=80, debug=True)
|
||||
print('[main] HTTP server shut down! End of main')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue