Compare commits
3 commits
a6b2992cc2
...
6fa7277813
Author | SHA1 | Date | |
---|---|---|---|
|
6fa7277813 | ||
|
38caa62d40 | ||
|
8311416253 |
1 changed files with 35 additions and 25 deletions
|
@ -1,6 +1,7 @@
|
||||||
"""
|
"""
|
||||||
MS Teams controller using a Neokey 1x4 and a RP2040.
|
MS Teams controller using a Neokey 1x4 and a RP2040.
|
||||||
"""
|
"""
|
||||||
|
import logging
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
import asyncio
|
import asyncio
|
||||||
|
@ -8,7 +9,9 @@ from typing import Any
|
||||||
import serial_asyncio
|
import serial_asyncio
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from websockets.client import connect, WebSocketClientProtocol
|
from websockets.client import connect, WebSocketClientProtocol
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel, ValidationError
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Button(BaseModel):
|
class Button(BaseModel):
|
||||||
|
@ -18,10 +21,10 @@ class Button(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class BUTTONS:
|
class BUTTONS:
|
||||||
cam = Button(num=0, color_off=(0, 0, 10), color_on=(0, 0, 255))
|
cam = Button(num=0, color_off=(0, 0, 30), color_on=(0, 0, 255))
|
||||||
mic = Button(num=1, color_off=(10, 0, 0), color_on=(255, 0, 0))
|
mic = Button(num=1, color_off=(30, 0, 0), color_on=(255, 0, 0))
|
||||||
hand = Button(num=2, color_off=(10, 10, 0), color_on=(255, 192, 0))
|
hand = Button(num=2, color_off=(30, 10, 0), color_on=(255, 192, 0))
|
||||||
call = Button(num=3, color_off=(0, 10, 0), color_on=(255, 64, 0))
|
call = Button(num=3, color_off=(0, 30, 0), color_on=(255, 64, 0))
|
||||||
all = [cam, mic, hand, call]
|
all = [cam, mic, hand, call]
|
||||||
|
|
||||||
|
|
||||||
|
@ -240,9 +243,10 @@ class TeamsCtrl:
|
||||||
|
|
||||||
async def process_ws(self) -> None:
|
async def process_ws(self) -> None:
|
||||||
async for raw_msg in self.ws:
|
async for raw_msg in self.ws:
|
||||||
|
try:
|
||||||
msg = TeamsMsg.parse_raw(raw_msg)
|
msg = TeamsMsg.parse_raw(raw_msg)
|
||||||
if self.meeting_state != msg.meetingUpdate.meetingState:
|
if self.meeting_state != msg.meetingUpdate.meetingState:
|
||||||
print(
|
log.debug(
|
||||||
f"state changed:\n{self.meeting_state}\nto\n{msg.meetingUpdate.meetingState}"
|
f"state changed:\n{self.meeting_state}\nto\n{msg.meetingUpdate.meetingState}"
|
||||||
)
|
)
|
||||||
changes: dict[str, bool] = {}
|
changes: dict[str, bool] = {}
|
||||||
|
@ -259,18 +263,24 @@ class TeamsCtrl:
|
||||||
self.meeting_state = msg.meetingUpdate.meetingState
|
self.meeting_state = msg.meetingUpdate.meetingState
|
||||||
if next_state is not None:
|
if next_state is not None:
|
||||||
self.set_next_state(next_state=next_state)
|
self.set_next_state(next_state=next_state)
|
||||||
|
except ValidationError:
|
||||||
|
if isinstance(raw_msg, bytes):
|
||||||
|
m = raw_msg.decode("utf-8")
|
||||||
|
else:
|
||||||
|
m = raw_msg
|
||||||
|
log.info(f"got unknown meetingState: {m}")
|
||||||
|
|
||||||
async def process_statemachine(self) -> None:
|
async def process_statemachine(self) -> None:
|
||||||
while not self.loop.is_closed():
|
while not self.loop.is_closed():
|
||||||
await self.current_state.process()
|
await self.current_state.process()
|
||||||
|
|
||||||
def gather_all(self):
|
def gather_all(self) -> asyncio.Future[tuple[None, None, None]]:
|
||||||
return asyncio.gather(
|
return asyncio.gather(
|
||||||
self.process_serial(), self.process_ws(), self.process_statemachine()
|
self.process_serial(), self.process_ws(), self.process_statemachine()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def amain():
|
async def amain() -> None:
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
serial = await serial_asyncio.open_serial_connection(
|
serial = await serial_asyncio.open_serial_connection(
|
||||||
loop=loop, url=args.port, baudrate=115200
|
loop=loop, url=args.port, baudrate=115200
|
||||||
|
|
Loading…
Reference in a new issue