Skip to content

Commit

Permalink
Display Connection Status (#104)
Browse files Browse the repository at this point in the history
* init

* working changes
  • Loading branch information
pdxlocations authored Feb 2, 2025
1 parent 9621bb0 commit a4a15e5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
3 changes: 2 additions & 1 deletion globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
selected_channel = 0
selected_message = 0
selected_node = 0
current_window = 0
current_window = 0
connected = False
2 changes: 2 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from utilities.arg_parser import setup_parser
from utilities.interfaces import initialize_interface
from ui.curses_ui import on_connection
from message_handlers.rx_handler import on_receive
from ui.curses_ui import main_ui, draw_splash
from utilities.utils import get_channels, get_node_list, get_nodeNum
Expand Down Expand Up @@ -47,6 +48,7 @@ def main(stdscr):
globals.channel_list = get_channels()
globals.node_list = get_node_list()
pub.subscribe(on_receive, 'meshtastic.receive')
pub.subscribe(on_connection, "meshtastic.connection")
init_nodedb()
load_messages_from_db()
logging.info("Starting main UI")
Expand Down
3 changes: 1 addition & 2 deletions message_handlers/rx_handler.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import logging
import time
from datetime import datetime
from utilities.utils import get_node_list
from ui.curses_ui import draw_packetlog_win, draw_node_list, draw_messages_window, draw_channel_list, add_notification
from db_handler import save_message_to_db, maybe_store_nodeinfo_in_db, get_name_from_database
import default_config as config
import globals


from datetime import datetime

def on_receive(packet, interface):

# Update packet log
Expand Down
30 changes: 29 additions & 1 deletion ui/curses_ui.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import curses
import textwrap
import logging
from pubsub import pub
from utilities.utils import get_channels, get_time_ago
from settings import settings_menu
from message_handlers.tx_handler import send_message, send_traceroute
Expand All @@ -9,6 +11,31 @@
import ui.dialog
import globals

def on_connection(interface, topic=pub.AUTO_TOPIC) -> None:
"""Callback invoked when we connect/disconnect from a radio."""
connection_status = topic.getName()

if connection_status == "meshtastic.connection.established":
globals.connected = True
elif connection_status == "meshtastic.connection.lost":
globals.connected = False

logging.info(f"Connection changed: {connection_status}")
draw_connection_indicator()

def draw_connection_indicator():
"""Draw a connection indicator (green dot if connected, red if disconnected) in the input window."""

height, width = entry_win.getmaxyx()

indicator_x = width - 3
indicator_y = 1

entry_win.addstr(indicator_y, indicator_x, "✔" if globals.connected else "✖", get_color("input", bold=True))
curses.curs_set(0)
entry_win.refresh()


def draw_node_details():
node = None
try:
Expand Down Expand Up @@ -447,7 +474,8 @@ def main_ui(stdscr):
handle_resize(stdscr, True)

while True:
draw_text_field(entry_win, f"Input: {input_text[-(stdscr.getmaxyx()[1] - 10):]}", get_color("input"))
draw_connection_indicator()
draw_text_field(entry_win, f"Input: {input_text[-(stdscr.getmaxyx()[1] - 12):]}", get_color("input"))

# Get user input from entry window
char = entry_win.get_wch()
Expand Down

0 comments on commit a4a15e5

Please sign in to comment.