fixed imports on key + added loader

This commit is contained in:
tcsenpai 2024-03-31 15:19:21 +02:00
parent 545af545bc
commit c4d2d7c317
3 changed files with 51 additions and 8 deletions

View File

@ -4,7 +4,7 @@ from pubsub import pub
import time
# Helpers
from hashlib import sha256
import keys
import libs.keys as keys
import json
serial_port = None
@ -95,11 +95,15 @@ def connect(serialPort=None):
keys.ensure()
# Connecting to the radio
serial_port = serialPort
pub.subscribe(onReceive, "meshtastic.receive")
pub.subscribe(onConnection, "meshtastic.connection.established")
interface = meshtastic.serial_interface.SerialInterface(serial_port)
print("[INITIALIZATION] Connection to radio established")
try:
pub.subscribe(onReceive, "meshtastic.receive")
pub.subscribe(onConnection, "meshtastic.connection.established")
interface = meshtastic.serial_interface.SerialInterface(serial_port)
print("[INITIALIZATION] Connection to radio established")
except Exception as e:
print("[INITIALIZATION] Could not connect to radio")
print("[INITIALIZATION] " + str(e))
return False
def listSerials():
# TODO

30
libs/loading.py Normal file
View File

@ -0,0 +1,30 @@
import itertools
import threading
import time
import sys
done = True
message = ""
#here is the animation
def animate():
global done
global message
for c in itertools.cycle(['|', '/', '-', '\\']):
if done:
break
sys.stdout.write('\r' + message + ' ' + c)
sys.stdout.flush()
time.sleep(0.1)
sys.stdout.write('\rDone! \n')
def start(msg="loading..."):
global done
global message
done = False
message = msg
t = threading.Thread(target=animate)
t.start()
def stop():
global done
done = True

13
term.py
View File

@ -3,6 +3,7 @@ import builtins as __builtin__
import time
import os
from dotenv import load_dotenv
import libs.loading as loading
# SECTION GUI Variables
outputs = ""
@ -28,7 +29,12 @@ def print(*args, **kwargs):
def init():
print("[SYSTEM] Starting EMesh...")
vars = preparse()
emesh.connect(vars["port"])
loading.start("Initializing EMesh...")
if not emesh.connect(vars["port"]):
print("[SYSTEM] Could not connect to the device. Exiting...")
loading.stop()
exit()
loading.stop()
print("[LOADER] Initialized")
@ -53,6 +59,7 @@ def main():
print("[MAIN CYCLE] Starting watchdog...")
was_connected = False
cooldownHeader = False
loading.start("[ eMesh Main Cycle is Running ")
while not ((os.getenv("FORCE_QUIT") == "True") or forceQuit):
# This is just a way to check if we need to notify the gui
are_connected = emesh.connected
@ -95,7 +102,9 @@ def main():
# print("[MAIN CYCLE] Sleeping for " + os.getenv('SLEEP_INTERVAL') + " seconds")
time.sleep(int(os.getenv("SLEEP_INTERVAL")))
# print("[MAIN CYCLE] Sleeping complete. Proceeding to the next cycle...")
print("[MAIN CYCLE] Exiting main cycle...")
print("[SYSTEM] Exiting...")
loading.stop()
print("[SYSTEM] Ready to start.")