FreeDATA/modem/event_manager.py

30 lines
798 B
Python
Raw Normal View History

import json
2023-11-30 07:44:18 +00:00
import structlog
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
def broadcast(self, data):
2023-11-30 07:44:18 +00:00
self.log.debug(f"Broadcasting event: {data}")
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):
self.broadcast({"buffer-overflow": str(data)})
2023-11-20 08:00:07 +00:00
def send_custom_event(self, **event_data):
self.broadcast(event_data)