Added serial port hardware config

This commit is contained in:
Mark Qvist 2022-10-15 10:35:40 +02:00
parent f9d6185064
commit 712a099c8b
2 changed files with 212 additions and 2 deletions

View File

@ -1537,7 +1537,109 @@ class SidebandApp(MDApp):
self.sideband.setstate("app.displaying", self.root.ids.screen_manager.current)
def hardware_serial_init(self, sender=None):
pass
if not self.hardware_serial_ready:
def save_connectivity(sender=None, event=None):
if self.hardware_serial_validate():
self.hardware_serial_save()
def focus_save(sender=None, event=None):
if sender != None:
if not sender.focus:
save_connectivity(sender=sender)
if self.sideband.config["hw_serial_baudrate"] != None:
t_b = str(self.sideband.config["hw_serial_baudrate"])
else:
t_b = ""
if self.sideband.config["hw_serial_databits"] != None:
t_db = str(self.sideband.config["hw_serial_databits"])
else:
t_db = ""
if self.sideband.config["hw_serial_parity"] != None:
t_p = str(self.sideband.config["hw_serial_parity"])
else:
t_p = ""
if self.sideband.config["hw_serial_stopbits"] != None:
t_sb = str(self.sideband.config["hw_serial_stopbits"])
else:
t_sb = ""
self.root.ids.hardware_serial_baudrate.text = t_b
self.root.ids.hardware_serial_databits.text = t_db
self.root.ids.hardware_serial_parity.text = t_p
self.root.ids.hardware_serial_stopbits.text = t_sb
self.root.ids.hardware_serial_baudrate.bind(focus=focus_save)
self.root.ids.hardware_serial_databits.bind(focus=focus_save)
self.root.ids.hardware_serial_parity.bind(focus=focus_save)
self.root.ids.hardware_serial_stopbits.bind(focus=focus_save)
self.root.ids.hardware_serial_baudrate.bind(on_text_validate=save_connectivity)
self.root.ids.hardware_serial_databits.bind(on_text_validate=save_connectivity)
self.root.ids.hardware_serial_parity.bind(on_text_validate=save_connectivity)
self.root.ids.hardware_serial_stopbits.bind(on_text_validate=save_connectivity)
def hardware_serial_validate(self, sender=None):
valid = True
try:
val = int(self.root.ids.hardware_serial_baudrate.text)
if not val > 0:
raise ValueError("Invalid baudrate")
self.root.ids.hardware_serial_baudrate.error = False
self.root.ids.hardware_serial_baudrate.text = str(val)
except:
self.root.ids.hardware_serial_baudrate.error = True
valid = False
try:
val = int(self.root.ids.hardware_serial_databits.text)
if not val > 0:
raise ValueError("Invalid databits")
self.root.ids.hardware_serial_databits.error = False
self.root.ids.hardware_serial_databits.text = str(val)
except:
self.root.ids.hardware_serial_databits.error = True
valid = False
try:
val = int(self.root.ids.hardware_serial_stopbits.text)
if not val > 0:
raise ValueError("Invalid stopbits")
self.root.ids.hardware_serial_stopbits.error = False
self.root.ids.hardware_serial_stopbits.text = str(val)
except:
self.root.ids.hardware_serial_stopbits.error = True
valid = False
try:
val = self.root.ids.hardware_serial_parity.text
nval = val.lower()
if nval in ["e", "ev", "eve", "even"]:
val = "even"
if nval in ["o", "od", "odd"]:
val = "odd"
if nval in ["n", "no", "non", "none", "not", "null", "off"]:
val = "none"
if not val in ["even", "odd", "none"]:
raise ValueError("Invalid parity")
self.root.ids.hardware_serial_parity.error = False
self.root.ids.hardware_serial_parity.text = str(val)
except:
self.root.ids.hardware_serial_parity.error = True
valid = False
return valid
def hardware_serial_save(self):
self.sideband.config["hw_serial_baudrate"] = int(self.root.ids.hardware_serial_baudrate.text)
self.sideband.config["hw_serial_databits"] = int(self.root.ids.hardware_serial_databits.text)
self.sideband.config["hw_serial_parity"] = self.root.ids.hardware_serial_parity.text
self.sideband.config["hw_serial_stopbits"] = int(self.root.ids.hardware_serial_stopbits.text)
self.sideband.save_configuration()
### Announce Stream screen
######################################

View File

@ -1139,7 +1139,7 @@ MDNavigationLayout:
font_size: dp(16)
size_hint: [1.0, None]
on_release: root.ids.screen_manager.app.hardware_serial_action(self)
disabled: True
disabled: False
MDScreen:
name: "hardware_rnode_screen"
@ -1285,6 +1285,114 @@ MDNavigationLayout:
text: ""
font_size: dp(24)
MDScreen:
name: "hardware_serial_screen"
BoxLayout:
orientation: "vertical"
MDTopAppBar:
title: "Serial Port"
anchor_title: "left"
elevation: 2
left_action_items:
[['menu', lambda x: nav_drawer.set_state("open")]]
right_action_items:
[
['close', lambda x: root.ids.screen_manager.app.close_sub_hardware_action(self)],
]
ScrollView:
id: hardware_serial_scrollview
MDBoxLayout:
orientation: "vertical"
spacing: "8dp"
size_hint_y: None
height: self.minimum_height
padding: [dp(28), dp(48), dp(28), dp(16)]
MDLabel:
text: "Serial Hardware Parameters\\n"
font_style: "H6"
MDLabel:
id: hardware_serial_info
markup: True
text: "To communicate using a serial port, you will need to specify the following parameters. If communicating directly to another Reticulum instance over serial, the parameters must match the other device. If you are using a serial-connected device to pass on data to other Reticulum instances, it must be pass data transparently to the desired endpoints.\\n"
size_hint_y: None
text_size: self.width, None
height: self.texture_size[1]
# MDBoxLayout:
# orientation: "horizontal"
# spacing: "24dp"
# size_hint_y: None
# height: self.minimum_height
# padding: [dp(0), dp(0), dp(0), dp(35)]
# MDRectangleFlatIconButton:
# id: serial_mote_export
# icon: "upload"
# text: "Export"
# padding: [dp(0), dp(14), dp(0), dp(14)]
# icon_size: dp(24)
# font_size: dp(16)
# size_hint: [1.0, None]
# on_release: root.ids.screen_manager.app.hardware_serial_export(self)
# MDRectangleFlatIconButton:
# id: serial_mote_import
# icon: "download"
# text: "Import"
# padding: [dp(0), dp(14), dp(0), dp(14)]
# icon_size: dp(24)
# font_size: dp(16)
# size_hint: [1.0, None]
# on_release: root.ids.screen_manager.app.hardware_serial_import(self)
MDLabel:
text: "Port Options"
font_style: "H6"
MDBoxLayout:
orientation: "horizontal"
spacing: "24dp"
size_hint_y: None
height: self.minimum_height
# padding: [dp(0), dp(0), dp(0), dp(35)]
MDTextField:
id: hardware_serial_baudrate
hint_text: "Baud Rate"
text: ""
font_size: dp(24)
MDBoxLayout:
orientation: "horizontal"
spacing: "24dp"
size_hint_y: None
height: self.minimum_height
padding: [dp(0), dp(0), dp(0), dp(24)]
MDTextField:
id: hardware_serial_databits
hint_text: "Data Bits"
text: ""
font_size: dp(24)
MDTextField:
id: hardware_serial_parity
hint_text: "Parity"
text: ""
font_size: dp(24)
MDTextField:
id: hardware_serial_stopbits
hint_text: "Stop Bits"
text: ""
font_size: dp(24)
MDNavigationDrawer:
id: nav_drawer