start settings

This commit is contained in:
pdxlocations
2024-04-02 11:24:40 -07:00
parent 24d9bdec9b
commit a1c0a38327
2 changed files with 70 additions and 4 deletions

View File

@@ -12,6 +12,8 @@ from pubsub import pub
from meshtastic import config_pb2, BROADCAST_NUM
import textwrap # Import the textwrap module
from settings import settings
# Initialize Meshtastic interface
interface = meshtastic.serial_interface.SerialInterface()
# interface = meshtastic.tcp_interface.TCPInterface(hostname='192.168.xx.xx')
@@ -299,6 +301,8 @@ def select_nodes(direction):
draw_node_list()
def main(stdscr):
global messages_win, nodes_win, channel_win, function_win, selected_node, selected_channel, direct_message
@@ -325,7 +329,7 @@ def main(stdscr):
nodes_win = curses.newwin(height - 6, nodes_width, 3, channel_width + messages_width)
function_win = curses.newwin(3, width, height - 3, 0)
draw_text_field(function_win, f"↑↓ = Switch Channels ← → = Channels/Nodes ENTER = Send Message / Select DM Node ESC = Quit")
draw_text_field(function_win, f"↑↓ = Switch Channels ← → = Channels/Nodes ENTER = Send / Select DM ESC = Quit ` = Settings")
# Enable scrolling for messages and nodes windows
messages_win.scrollok(True)
@@ -423,13 +427,18 @@ def main(stdscr):
elif char == curses.KEY_BACKSPACE or char == 127:
input_text = input_text[:-1]
elif char == 96:
curses.curs_set(0) # Hide cursor
settings(stdscr, interface)
curses.curs_set(1) # Show cursor again
else:
# Append typed character to input text
input_text += chr(char)
# draw_debug(char)
pub.subscribe(on_receive, 'meshtastic.receive')
if __name__ == "__main__":
curses.wrapper(main)
curses.wrapper(main)

57
settings.py Normal file
View File

@@ -0,0 +1,57 @@
import curses
def settings(stdscr, interface):
popup_height = 10
popup_width = 30
y_start = (curses.LINES - popup_height) // 2
x_start = (curses.COLS - popup_width) // 2
popup_win = curses.newwin(popup_height, popup_width, y_start, x_start)
popup_win.border()
popup_win.addstr(1, 1, "Select an option:")
options = ["Reboot", "Reset NodeDB", "Shutdown", "Factory Reset"]
for i, option in enumerate(options, start=1):
popup_win.addstr(i + 1, 2, f"{i}. {option}")
popup_win.addstr(i + 2, 2, f"ESC: Exit Menu")
popup_win.refresh()
while True:
char = popup_win.getch()
if char == 27:
break
# Handle the selected option
elif char in [ord('1'), ord('2'), ord('3'), ord('4')]:
selected_option = chr(char)
if selected_option == '1':
settings_reboot(interface)
elif selected_option == '2':
settings_reset_nodedb(interface)
elif selected_option == '3':
settings_shutdown(interface)
elif selected_option == '4':
settings_factory_reset(interface)
break
# Close the popup window
popup_win.clear()
popup_win.refresh()
del popup_win # Delete the window object to free up memory
def settings_reboot(interface):
interface.getNode('^local').reboot()
def settings_reset_nodedb(interface):
interface.getNode('^local').resetNodeDb()
def settings_shutdown(interface):
interface.getNode('^local').shutdown()
def settings_factory_reset(interface):
interface.getNode('^local').factory_reset()
# ourNode = interface.getNode('^local')
# ourNode.localConfig.lora.modem_preset = 'LONG_FAST'
# ourNode.writeConfig("lora")