2023-11-08 16:46:15 +00:00
|
|
|
import json
|
2023-11-30 07:44:18 +00:00
|
|
|
import structlog
|
2023-11-08 16:46:15 +00:00
|
|
|
|
|
|
|
class EventManager:
|
|
|
|
|
|
|
|
def __init__(self, queues):
|
|
|
|
self.queues = queues
|
2023-11-30 07:44:18 +00:00
|
|
|
self.log = structlog.get_logger('Event Manager')
|
2023-11-30 21:50:10 +00:00
|
|
|
self.lastpttstate = False
|
2023-11-08 16:46:15 +00:00
|
|
|
|
|
|
|
def broadcast(self, data):
|
2023-11-30 07:44:18 +00:00
|
|
|
self.log.debug(f"Broadcasting event: {data}")
|
2023-11-08 16:46:15 +00:00
|
|
|
for q in self.queues:
|
|
|
|
q.put(data)
|
|
|
|
|
|
|
|
def send_ptt_change(self, on:bool = False):
|
2023-11-30 21:50:10 +00:00
|
|
|
if (on == self.lastpttstate):
|
|
|
|
return
|
|
|
|
self.lastpttstate= on
|
|
|
|
self.broadcast({"ptt": bool(on)})
|
2023-11-12 22:22:53 +00:00
|
|
|
|
|
|
|
def send_scatter_change(self, data):
|
2023-12-01 02:12:04 +00:00
|
|
|
self.broadcast({"scatter": json.dumps(data)})
|
2023-11-13 17:11:55 +00:00
|
|
|
|
|
|
|
def send_buffer_overflow(self, data):
|
2023-11-26 11:45:51 +00:00
|
|
|
self.broadcast({"buffer-overflow": str(data)})
|
2023-11-20 08:00:07 +00:00
|
|
|
|
2023-11-26 11:45:51 +00:00
|
|
|
def send_custom_event(self, **event_data):
|
|
|
|
self.broadcast(event_data)
|