mirror of
https://github.com/tcsenpai/emesh.git
synced 2025-06-07 02:35:20 +00:00
fixed imports on key + added loader
This commit is contained in:
parent
545af545bc
commit
c4d2d7c317
@ -4,7 +4,7 @@ from pubsub import pub
|
|||||||
import time
|
import time
|
||||||
# Helpers
|
# Helpers
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
import keys
|
import libs.keys as keys
|
||||||
import json
|
import json
|
||||||
|
|
||||||
serial_port = None
|
serial_port = None
|
||||||
@ -95,11 +95,15 @@ def connect(serialPort=None):
|
|||||||
keys.ensure()
|
keys.ensure()
|
||||||
# Connecting to the radio
|
# Connecting to the radio
|
||||||
serial_port = serialPort
|
serial_port = serialPort
|
||||||
|
try:
|
||||||
pub.subscribe(onReceive, "meshtastic.receive")
|
pub.subscribe(onReceive, "meshtastic.receive")
|
||||||
pub.subscribe(onConnection, "meshtastic.connection.established")
|
pub.subscribe(onConnection, "meshtastic.connection.established")
|
||||||
interface = meshtastic.serial_interface.SerialInterface(serial_port)
|
interface = meshtastic.serial_interface.SerialInterface(serial_port)
|
||||||
print("[INITIALIZATION] Connection to radio established")
|
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():
|
def listSerials():
|
||||||
# TODO
|
# TODO
|
||||||
|
30
libs/loading.py
Normal file
30
libs/loading.py
Normal 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
13
term.py
@ -3,6 +3,7 @@ import builtins as __builtin__
|
|||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
import libs.loading as loading
|
||||||
|
|
||||||
# SECTION GUI Variables
|
# SECTION GUI Variables
|
||||||
outputs = ""
|
outputs = ""
|
||||||
@ -28,7 +29,12 @@ def print(*args, **kwargs):
|
|||||||
def init():
|
def init():
|
||||||
print("[SYSTEM] Starting EMesh...")
|
print("[SYSTEM] Starting EMesh...")
|
||||||
vars = preparse()
|
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")
|
print("[LOADER] Initialized")
|
||||||
|
|
||||||
|
|
||||||
@ -53,6 +59,7 @@ def main():
|
|||||||
print("[MAIN CYCLE] Starting watchdog...")
|
print("[MAIN CYCLE] Starting watchdog...")
|
||||||
was_connected = False
|
was_connected = False
|
||||||
cooldownHeader = False
|
cooldownHeader = False
|
||||||
|
loading.start("[ eMesh Main Cycle is Running ")
|
||||||
while not ((os.getenv("FORCE_QUIT") == "True") or forceQuit):
|
while not ((os.getenv("FORCE_QUIT") == "True") or forceQuit):
|
||||||
# This is just a way to check if we need to notify the gui
|
# This is just a way to check if we need to notify the gui
|
||||||
are_connected = emesh.connected
|
are_connected = emesh.connected
|
||||||
@ -95,7 +102,9 @@ def main():
|
|||||||
# print("[MAIN CYCLE] Sleeping for " + os.getenv('SLEEP_INTERVAL') + " seconds")
|
# print("[MAIN CYCLE] Sleeping for " + os.getenv('SLEEP_INTERVAL') + " seconds")
|
||||||
time.sleep(int(os.getenv("SLEEP_INTERVAL")))
|
time.sleep(int(os.getenv("SLEEP_INTERVAL")))
|
||||||
# print("[MAIN CYCLE] Sleeping complete. Proceeding to the next cycle...")
|
# 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.")
|
print("[SYSTEM] Ready to start.")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user