split code up into modules and add pubsub and timers
This commit is contained in:
parent
05c470197f
commit
001f99db7c
7 changed files with 228 additions and 137 deletions
16
CIRCUITPY/weather_station/pubsub.py
Executable file
16
CIRCUITPY/weather_station/pubsub.py
Executable file
|
|
@ -0,0 +1,16 @@
|
|||
class PubSub:
|
||||
def __init__(self):
|
||||
self.cbs = {}
|
||||
def _check_msg_type(self, msg_type):
|
||||
if msg_type not in self.cbs:
|
||||
self.cbs[msg_type] = []
|
||||
|
||||
def subscribe(self, msg_type, cb):
|
||||
self._check_msg_type(msg_type)
|
||||
self.cbs[msg_type].append(cb)
|
||||
|
||||
def publish(self, msg_type, body):
|
||||
self._check_msg_type(msg_type)
|
||||
print(f"publishing msg {msg_type}")
|
||||
for cb in self.cbs[msg_type]:
|
||||
cb(body)
|
||||
Loading…
Add table
Add a link
Reference in a new issue