Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion software/main/am1.py
Original file line number Diff line number Diff line change
@@ -1 +1,47 @@
#am1.py functionality has been moved into boot.py
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)
45 changes: 3 additions & 42 deletions software/main/boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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:
Expand All @@ -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}")
2 changes: 1 addition & 1 deletion software/release/all/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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