Additional comments

master
Jamie Munro 2 years ago
parent 37bd7257d3
commit 02d7e5f264
  1. 2
      controller.py
  2. 4
      controller.py.bak
  3. 2
      receiver.py
  4. 34
      receiver.py.bak

@ -1,3 +1,5 @@
#2022 Jamie Munro
from microbit import *
import radio

@ -55,7 +55,7 @@ def loop():
global bombAnimationStep
global lastBombStep
#gather sensor data
if conf["a"]: a = button_a.is_pressed()
if conf["b"]: b = button_b.is_pressed()
if conf["logo"]: logo = pin_logo.is_touched()
@ -73,6 +73,7 @@ def loop():
if conf["time"]: time = running_time()
#format into message
msg = ""
msg += CONTROL_CHAR
if conf["a"]: msg += "a" + str(int(a))
@ -83,6 +84,7 @@ def loop():
if conf["light"]: msg += 'l{:3d}'.format(light)
if conf["heading"]: msg += 'h{:3d}'.format(heading)
#broadcast message via radio or serial depending on mode
if MODE:
radio.send(msg)
else:

@ -1,3 +1,5 @@
#2022 Jamie Munro
from microbit import *
import radio

@ -0,0 +1,34 @@
from microbit import *
import radio
CONTROL_CHAR = "*"
RADIO_GROUP = 222
RADIO_CHANNEL = 5
RADIO_LENGTH = 36
MSG_LENGTH = RADIO_LENGTH - 3
DELAY = 0
def setup():
print("Starting...")
print("Turning radio on...")
radio.on()
radio.config(group=RADIO_GROUP, channel=RADIO_CHANNEL, length=RADIO_LENGTH)
while True:
loop()
sleep(DELAY)
def loop():
#get message from buffer
incoming = radio.receive()
#perform a bunch of sanity checks to insure this is a valid message
#TODO: investigate performance impact of sanity checks, maybe this should be done at app level
#TODO: investigate performance speed up of direct byte encoding instead of string manipulation
if incoming != None and incoming[0] == CONTROL_CHAR and len(incoming) == MSG_LENGTH:
print(incoming)
setup()
Loading…
Cancel
Save