Skip to content

Commit

Permalink
small code update
Browse files Browse the repository at this point in the history
  • Loading branch information
NicK4rT committed Dec 19, 2024
1 parent 624145a commit 4b32628
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 137 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified software/.DS_Store
Binary file not shown.
Binary file modified software/main/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion software/main/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 29 additions & 18 deletions software/main/boot.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from machine import Pin
import machine
from config import config

import time
import gc

gc.collect()
Expand All @@ -22,20 +22,17 @@

# Network
infmsg = True
dbgmsg = True
dbgmsg = False
errmsg = True
global timer
peer_mac = b'\xff\xff\xff\xff\xff\xff'
configuration = config["configuration"]
hive = config["hive"]
if configuration == "AM1":
infmsg = True

networking = SSP_Networking(infmsg, dbgmsg, errmsg)

peer_mac = b'\xff\xff\xff\xff\xff\xff'

import time

global timer

print("{:.3f} Name: {}, ID: {}, Configuration: {}, Sta mac: {}, Ap mac: {}, Version: {}".format(
(time.ticks_ms() - networking.inittime) / 1000,
networking.config["name"],
Expand All @@ -46,9 +43,8 @@
networking.config["version"]
))

if configuration == "AM1":
def idle():
lastPressed = 0

message = "Boop!"

def boop(pin):
Expand All @@ -66,23 +62,38 @@ def boop(pin):
switch_select = Pin(9, Pin.IN, Pin.PULL_UP)
switch_select.irq(trigger=Pin.IRQ_FALLING, handler=boop)


def heartbeat(timer):
print("")
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()
def run_config_module(module_name):
try:
timer.deinit()
with open(module_name + ".py") as f:
code = f.read()
exec(code)
except Exception as e:
print(e)
machine.reset()
print(f"Error running {module_name}: {e}")

# cases for different configurations
if not hive:
if configuration == "AM1":
print("am1")
idle()
elif configuration == "SM3":
print("sm3")
run_config_module("sm3")
elif configuration == "SL1":
print("sl1")
run_config_module("sl1")
else:
print("idle")
idle()
else:
run_config_module("hm1")
# insert code here to run in case of hive motor!

2 changes: 2 additions & 0 deletions software/main/hm1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@


112 changes: 0 additions & 112 deletions software/main/main.py

This file was deleted.

8 changes: 5 additions & 3 deletions software/release/README.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ A short description of the directories can be found below.
| name | description | contribution |
|--------------|-----------------------------------------|--------------|
| release/config.py | Smart Module Configuration File | Nick |
| main/main.py | Smart Module Main.py | Nick |
| main/boot.py | Smart Module boot.py | Nick |
| main/main.py | Smart Module main.py | Nick |
| main/hm1.py | Smart hive program | Nick |
| main/sl1.py | Smart light module main program | Milan |
| main/sm3.py | Smart motor module main program | Milan |
| networking/networking.py | This is the main networking code that builds on ESP-NOW. There are many prepared functionalities (and some more that I am working on), such as long message support, sending of various variable types (bytes, bytearray, dicts, lists, int, float, char, string), as well as different types of messages such as ping, echo and more. There are also various features in place to make the networking more robust. | Nick |
| networking/ssp_networking.py | This is the ssp networking module. It needs config.py to function. | Nick |
| libraries/adxl345.py | Support for the built in accelerometer https://github.com/DFRobot/micropython-dflib/blob/master/ADXL345/user_lib/ADXL345.py | Milan |
Expand All @@ -45,7 +49,5 @@ A short description of the directories can be found below.
| libraries/sensors.py | Sensor support for the smart motor module | Milan |
| libraries/servo.py | Servo support for the smart motor module | Milan |
| libraries/smartlight.py | Smart light support for smart light module | Milan |
| main/sl1.py | Smart light module main program | Milan |
| main/sm3.py | Smart motor module main program | Milan |
| libraries/ssd1306.py | Support for the built in OLED screen https://github.com/stlehmann/micropython-ssd1306/blob/master/ssd1306.py | Milan |
| libraries/variableLED.py | Library that powers the variable LED grid | Sophie |
7 changes: 4 additions & 3 deletions software/release/config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
config = {
"name": "Nickname",
"configuration": "AM1",
"hive": False,
"id": None,
"version": None
}
version = {'adxl345.py': 3,
'ssp_networking.py': 1,
'ssp_networking.py': 1,
'files.py': 2,
'icons.py': 2,
'prefs.py': 2,
Expand All @@ -15,8 +16,8 @@
'sm3.py': 1,
'sl1.py': 1,
'smartlight.py': 1,
'networking.py': 3,
'main.py': 1,
'networking.py': 3,
'main.py': 1,
'boot.py': 0
}
mysecrets = {"SSID": "Tufts_Robot", "key": ""}
Expand Down

0 comments on commit 4b32628

Please sign in to comment.