Addd a mechanism for the UI to get values from Freq, bandwidth, coding rate, spread factor widgets and send them to the RNode thread for processing.
the RNode thread gets the values and sends them to the radio. If the radio firmware accepts the values, a response is sent back. The response is then processed and the UI is updated. So, the true test of whether a value took, is the radio sending back a resonse and seeing the label on the UI change.pull/6/head
parent
ac9b643a7d
commit
4fc9fce834
|
|
@ -17,8 +17,7 @@ class SubmitEdit(urwid.Edit):
|
|||
return super().keypress(size, key)
|
||||
|
||||
def submitHandler(self, parentApp):
|
||||
parentApp.appendToOutputWidget(f"Widget {self.name} received {self.edit_text.strip()}")
|
||||
None
|
||||
parentApp.widgetChangeHandler(self.name, self.edit_text.strip())
|
||||
|
||||
class LoRaMonUIApp:
|
||||
def __init__(self, queue_from_radio, queue_to_radio):
|
||||
|
|
@ -126,7 +125,52 @@ class LoRaMonUIApp:
|
|||
|
||||
self.loop = urwid.MainLoop(self.view, unhandled_input=self.unhandledInputHandler)
|
||||
|
||||
self.loop.set_alarm_in(.1, self.alarmHandler)
|
||||
self.loop.set_alarm_in(.1, self.radioMessageHandler)
|
||||
|
||||
def sendParameterToRadio(self, type, value):
|
||||
if (self.queue_to_radio != None):
|
||||
msg = {
|
||||
"type": type,
|
||||
"value": value
|
||||
}
|
||||
self.queue_to_radio.put(msg)
|
||||
|
||||
def widgetChangeHandler(self, widgetName, value):
|
||||
def to_integer(s):
|
||||
try:
|
||||
return int(s)
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
#most values are integers, convert to int here
|
||||
valueInt = to_integer(value)
|
||||
|
||||
match(widgetName):
|
||||
case "frequency":
|
||||
#self.appendToOutputWidget(f"Widget {widgetName} received {value}")
|
||||
if valueInt != None:
|
||||
#we should do a check here for valid freq ranges..
|
||||
self.sendParameterToRadio(widgetName, valueInt)
|
||||
case "bandwidth":
|
||||
#self.appendToOutputWidget(f"Widget {widgetName} received {value}")
|
||||
if valueInt != None:
|
||||
#only support 125k and 250K values
|
||||
if valueInt == 125000 or valueInt == 250000:
|
||||
self.sendParameterToRadio(widgetName, valueInt)
|
||||
case "spread_factor":
|
||||
#self.appendToOutputWidget(f"Widget {widgetName} received {value}")
|
||||
if valueInt != None:
|
||||
#support spread factors 7 .. 12
|
||||
if valueInt >= 7 and valueInt <= 12:
|
||||
self.sendParameterToRadio(widgetName, valueInt)
|
||||
case "coding_rate":
|
||||
#self.appendToOutputWidget(f"Widget {widgetName} received {value}")
|
||||
if valueInt != None:
|
||||
#only support coding rages 5 .. 8
|
||||
if valueInt >= 5 and valueInt <= 8:
|
||||
self.sendParameterToRadio(widgetName, valueInt)
|
||||
case _:
|
||||
None
|
||||
|
||||
def appendToOutputWidget(self, line):
|
||||
self.output_widget.append(urwid.Text(line))
|
||||
|
|
@ -144,8 +188,11 @@ class LoRaMonUIApp:
|
|||
self.auto_scroll_flag = True
|
||||
self.auto_scroll_widget.set_label("AutoScroll: " + str(self.auto_scroll_flag))
|
||||
|
||||
def alarmHandler(self, loop, data):
|
||||
#print("\nalarmHandler running")
|
||||
#this routine is called periodicaly to service incoming events for the UI
|
||||
#currently, there is a message queue from the radio thread
|
||||
#that send messages to be shown
|
||||
def radioMessageHandler(self, loop, data):
|
||||
#print("\nradioMessageHandler running")
|
||||
# read up to 10 messages at a time
|
||||
num_messages = 10
|
||||
|
||||
|
|
@ -170,9 +217,8 @@ class LoRaMonUIApp:
|
|||
self.packets_received_widget.original_widget.set_text("Packets: " + str(msg["value"]))
|
||||
case _:
|
||||
None
|
||||
|
||||
|
||||
self.loop.set_alarm_in(.1, self.alarmHandler)
|
||||
#set the alarm again, so it calls the routing again
|
||||
self.loop.set_alarm_in(.1, self.radioMessageHandler)
|
||||
|
||||
def quitApp(self):
|
||||
raise urwid.ExitMainLoop()
|
||||
|
|
|
|||
|
|
@ -147,21 +147,27 @@ class RNode():
|
|||
def readFromUIApp(self):
|
||||
if self.queue_from_ui:
|
||||
if not self.queue_from_ui.empty():
|
||||
msg = self.queue_from_radio.get()
|
||||
msg = self.queue_from_ui.get()
|
||||
match msg['type']:
|
||||
case "frequency":
|
||||
print(f"UI is requesting frequency to change to {msg['value']}")
|
||||
None
|
||||
#print(f"UI is requesting frequency to change to {msg['value']}")
|
||||
self.frequency = msg['value']
|
||||
self.setFrequency()
|
||||
case "bandwidth":
|
||||
None
|
||||
#print(f"UI is requesting bandwidth to change to {msg['value']}")
|
||||
self.bandwidth = msg['value']
|
||||
self.setBandwidth()
|
||||
case "spread_factor":
|
||||
None
|
||||
#print(f"UI is requesting spread_factor to change to {msg['value']}")
|
||||
self.sf = msg['value']
|
||||
self.setSpreadingFactor()
|
||||
case "coding_rate":
|
||||
None
|
||||
#print(f"UI is requesting coding_rate to change to {msg['value']}")
|
||||
self.cr = msg['value']
|
||||
self.setCodingRate()
|
||||
case _:
|
||||
None
|
||||
|
||||
|
||||
def packetReadLoop(self):
|
||||
global number_of_packets_received_exit_code
|
||||
|
||||
|
|
@ -215,6 +221,7 @@ class RNode():
|
|||
number_of_packets_received_exit_code = 255
|
||||
else:
|
||||
number_of_packets_received_exit_code = self.number_of_packets_received
|
||||
self.updateIUApp("r_captured_packets", self.number_of_packets_received)
|
||||
case KISS.CMD_ROM_READ:
|
||||
self.eeprom = data_buffer
|
||||
case KISS.CMD_FREQUENCY:
|
||||
|
|
|
|||
Loading…
Reference in New Issue