From 1fa18d3ad9cdc18cc6157ef2d341a5365de72178 Mon Sep 17 00:00:00 2001 From: Nick Art Date: Tue, 14 Oct 2025 13:00:24 +0200 Subject: [PATCH] reworked am1, boot and config --- software/main/am1.py | 48 +++++++++++++++++++++++++++++++++- software/main/boot.py | 45 +++---------------------------- software/release/all/config.py | 2 +- 3 files changed, 51 insertions(+), 44 deletions(-) diff --git a/software/main/am1.py b/software/main/am1.py index f52d550..1c55793 100644 --- a/software/main/am1.py +++ b/software/main/am1.py @@ -1 +1,47 @@ -#am1.py functionality has been moved into boot.py \ No newline at end of file +import time +import gc +import machine +from machine import Pin, Timer + +print("running am1.py") + +lastPressed = 0 +message = "Boop!" +peer_mac = b'\xff\xff\xff\xff\xff\xff' + +try: + networking +except NameError: + from config import networking + +# Ping once at startup +networking.ping(peer_mac) + +# Button handler +def boop(pin): + global lastPressed + if (time.ticks_ms() - lastPressed > 1000): + lastPressed = time.ticks_ms() + networking.ping(peer_mac) + # networking.echo(peer_mac, message) + # networking.send(peer_mac, time.ticks_ms()) + print(f"{(time.ticks_ms() - networking.inittime)/1000:.3f} " + f"Networking Tool: Sent {message} to {peer_mac}") + # print(f"{(time.ticks_ms() - networking.inittime)/1000:.3f} Networking Tool RSSI: {networking.rssi()}") + +# Setup button interrupt +switch_select = Pin(9, Pin.IN, Pin.PULL_UP) +switch_select.irq(trigger=Pin.IRQ_FALLING, handler=boop) + +# Heartbeat called by timer +def heartbeat(timer): + print("") + boop(None) # safely call boop from timer + print(f"{(time.ticks_ms() - networking.inittime)/1000:.3f} " + f"Networking Tool Heartbeat: {gc.mem_free()} bytes") + print("") + gc.collect() + +# Periodic timer +timer = Timer(0) +timer.init(period=5000, mode=Timer.PERIODIC, callback=heartbeat) diff --git a/software/main/boot.py b/software/main/boot.py index b915ab4..bd1ddd1 100644 --- a/software/main/boot.py +++ b/software/main/boot.py @@ -38,9 +38,6 @@ config.networking = SSP_Networking(infmsg, dbgmsg, errmsg) networking = config.networking -peer_mac = b'\xff\xff\xff\xff\xff\xff' -global timer - print("{:.3f} Name: {}, ID: {}, Configuration: {}, Type: {}, Sta mac: {}, Sta channel: {}, Ap mac: {}, Ap channel: {}, Version: {}".format( (time.ticks_ms() - networking.inittime) / 1000, networking.config["name"], @@ -54,38 +51,6 @@ networking.config["version"] )) -def am1(): - lastPressed = 0 - - message = "Boop!" - - networking.ping(peer_mac) - - def boop(pin): - nonlocal lastPressed - if (time.ticks_ms() - lastPressed > 1000): - # lastPressed = time.ticks_ms() - networking.ping(peer_mac) - # networking.echo(peer_mac, message) - # networking.send(peer_mac, time.ticks_ms()) - print(f"{(time.ticks_ms() - networking.inittime) / 1000:.3f} Networking Tool: Sent {message} to {peer_mac}") - # print(f"{(time.ticks_ms() - networking.inittime) / 1000:.3f} Networking Tool: RSSI table: {networking.rssi()}") - - # Buttons - switch_select = Pin(9, Pin.IN, Pin.PULL_UP) - switch_select.irq(trigger=Pin.IRQ_FALLING, handler=boop) - - def heartbeat(timer): - print("") - boop(None) - print(f"{(time.ticks_ms() - networking.inittime) / 1000:.3f} Networking Tool Heartbeat: {gc.mem_free()} bytes") - print("") - gc.collect() - - timer = machine.Timer(0) - timer.init(period=5000, mode=machine.Timer.PERIODIC, callback=heartbeat) - - def deinit(): networking.cleanup() try: @@ -94,13 +59,9 @@ def deinit(): print(e) machine.reset() - try: - if configuration == "AM1": - am1() - else: - with open(module_name + ".py") as f: - code = f.read() - exec(code, {"networking": networking, "configuration": configuration, "__name__": "__main__"}) + with open(module_name + ".py") as f: + code = f.read() + exec(code, {"networking": networking, "configuration": configuration, "__name__": "__main__"}) except Exception as e: print(f"Error running {module_name}: {e}") diff --git a/software/release/all/config.py b/software/release/all/config.py index c4280d1..b09c938 100644 --- a/software/release/all/config.py +++ b/software/release/all/config.py @@ -79,6 +79,6 @@ "0x53": ["ACCEL", 1, "accelerometer"] } #key is i2c address: ["device name", Output (0) or Input (1), "Description"] sensor_dict = {"sensor": [0,4095], "potentiometer": [0,180], "select": [0,1], "up": [0,1], "down": [0,1], "button": [0,1], "sw1": [0,1], "sw2": [0,1], "sw3": [0,1], "sw4": [0,1]} -hive_config = {'hive': True, 'recipients': [b'd\xe83\x84\xd8\x18'], 'sender_sensor_list': [[b'd\xe83\x84\xd8\x18', 'None']], 'refreshrate': 200, 'mode': 'None'} +hive_config = {'hive': False, 'recipients': [], 'sender_sensor_list': [], 'refreshrate': 200, 'mode': 'None'} networking = None