diff --git a/MAVProxy/mavproxy.py b/MAVProxy/mavproxy.py index 836dd91b8b..7dff43a88e 100644 --- a/MAVProxy/mavproxy.py +++ b/MAVProxy/mavproxy.py @@ -72,6 +72,7 @@ #The MAVLink version being used (None, "1.0", "2.0") mavversion = None +mpstate = None class MPStatus(object): '''hold status information about the mavproxy''' @@ -1326,8 +1327,8 @@ def set_mav_version(mav10, mav20, autoProtocol, mavversionArg): mpstate.command_map = command_map mpstate.continue_mode = opts.continue_mode # queues for logging - mpstate.logqueue = Queue.Queue() - mpstate.logqueue_raw = Queue.Queue() + mpstate.logqueue = multiproc.Queue() + mpstate.logqueue_raw = multiproc.Queue() if opts.speech: @@ -1425,7 +1426,7 @@ def quit_handler(signum = None, frame = None): heartbeat_period = mavutil.periodic_event(1) heartbeat_check_period = mavutil.periodic_event(0.33) - mpstate.input_queue = Queue.Queue() + mpstate.input_queue = multiproc.Queue() mpstate.input_count = 0 mpstate.empty_input_count = 0 if opts.setup: diff --git a/MAVProxy/modules/lib/live_graph.py b/MAVProxy/modules/lib/live_graph.py index 2724006119..dcf9644167 100755 --- a/MAVProxy/modules/lib/live_graph.py +++ b/MAVProxy/modules/lib/live_graph.py @@ -26,8 +26,10 @@ def __init__(self, timespan=20.0, tickresolution=0.2, colors=[ 'red', 'green', 'blue', 'orange', 'olive', 'cyan', 'magenta', 'brown', - 'violet', 'purple', 'grey', 'black']): + 'violet', 'purple', 'grey', 'black'], + labels=None): self.fields = fields + self.labels = labels self.colors = colors self.title = title self.timespan = timespan @@ -79,10 +81,11 @@ def is_alive(self): import time, math import live_graph livegraph = live_graph.LiveGraph(['sin(t)', 'cos(t)', 'sin(t+1)', - 'cos(t+1)', 'sin(t+2)', 'cos(t+2)', - 'cos(t+1)', 'sin(t+2)', 'cos(t+2)', 'x'], - timespan=30, - title='Graph Test') + 'cos(t+1)', 'sin(t+2)', 'cos(t+2)', + 'cos(t+1)', 'sin(t+2)', 'cos(t+2)', 'x'], + timespan=30, + title='Graph Test', + labels=['a','b','c','d']) while livegraph.is_alive(): t = time.time() livegraph.add_values([math.sin(t), math.cos(t), diff --git a/MAVProxy/modules/lib/live_graph_ui.py b/MAVProxy/modules/lib/live_graph_ui.py index b659285e9a..88997ae52d 100644 --- a/MAVProxy/modules/lib/live_graph_ui.py +++ b/MAVProxy/modules/lib/live_graph_ui.py @@ -84,12 +84,19 @@ def init_plot(self): max_y = min_y = 0 else: max_y = min_y = self.data[0][0] + num_labels = 0 if not self.state.labels else len(self.state.labels) + labels = [] for i in range(len(self.data)): + if i < num_labels and self.state.labels[i] is not None: + label = self.state.labels[i] + else: + label = self.state.fields[i] + labels.append(label) p = self.axes.plot( self.data[i], linewidth=1, color=self.state.colors[i], - label=self.state.fields[i], + label=label )[0] self.plot_data.append(p) if len(self.data[i]) != 0: @@ -101,7 +108,7 @@ def init_plot(self): self.axes.set_xbound(lower=self.xdata[0], upper=0) if min_y == max_y: self.axes.set_ybound(min_y, max_y+0.1) - self.axes.legend(self.state.fields, loc='upper left', bbox_to_anchor=(0, 1.1)) + self.axes.legend(labels, loc='upper left', bbox_to_anchor=(0, 1.1)) def draw_plot(self): """ Redraws the plot diff --git a/MAVProxy/modules/lib/mp_menu.py b/MAVProxy/modules/lib/mp_menu.py index 1a7029508b..ac2bbe36d3 100644 --- a/MAVProxy/modules/lib/mp_menu.py +++ b/MAVProxy/modules/lib/mp_menu.py @@ -351,6 +351,26 @@ def call(self): return None return dlg.GetValue() +class MPMenuConfirmDialog(object): + '''used to create a confirmation dialog''' + def __init__(self, title='Confirmation', message='', callback=None, args=None): + self.title = title + self.message = message + self.callback = callback + self.args = args + t = multiproc.Process(target=self.thread) + t.start() + + def thread(self): + mp_util.child_close_fds() + from MAVProxy.modules.lib import wx_processguard + from MAVProxy.modules.lib.wx_loader import wx + app = wx.App(False) + dlg = wx.MessageDialog(None, self.title, self.message, wx.YES|wx.NO) + ret = dlg.ShowModal() + if ret == wx.ID_YES and self.callback is not None: + self.callback(self.args) + class MPMenuChildMessageDialog(object): '''used to create a message dialog in a child process''' def __init__(self, title='Information', message='', font_size=18): diff --git a/MAVProxy/modules/mavproxy_console.py b/MAVProxy/modules/mavproxy_console.py index 53a967a63c..d348931d9a 100644 --- a/MAVProxy/modules/mavproxy_console.py +++ b/MAVProxy/modules/mavproxy_console.py @@ -134,7 +134,7 @@ def cmd_menu_add(self, args): if len(args) < 2: print("Usage: console menu add MenuPath command") return - menupath = args[0].split(':') + menupath = args[0].strip('"').split(':') name = menupath[-1] cmd = '# ' + ' '.join(args[1:]) self.menu.add_to_submenu(menupath[:-1], MPMenuItem(name, name, cmd)) diff --git a/MAVProxy/modules/mavproxy_graph.py b/MAVProxy/modules/mavproxy_graph.py index ad621a88dd..403205acc2 100644 --- a/MAVProxy/modules/mavproxy_graph.py +++ b/MAVProxy/modules/mavproxy_graph.py @@ -114,12 +114,24 @@ def __init__(self, state, fields): print("Adding graph: %s" % self.fields) fields = [ self.pretty_print_fieldname(x) for x in fields ] + labels = [] + for i in range(len(fields)): + f = fields[i] + f1 = f.find("<") + f2 = f.find(">") + if f1 > 0 and f2 > f1: + labels.append(f[f1+1:f2]) + fields[i] = f[:f1] + else: + labels.append(None) + self.fields = fields[:] self.values = [None] * len(self.fields) self.livegraph = live_graph.LiveGraph(fields, timespan=state.timespan, tickresolution=state.tickresolution, - title=self.fields[0]) + title=fields[0] if labels[0] is None else labels[0], + labels=labels) def pretty_print_fieldname(self, fieldname): if fieldname in self.state.legend: diff --git a/MAVProxy/modules/mavproxy_mode.py b/MAVProxy/modules/mavproxy_mode.py index 38eed53e09..234aae0904 100644 --- a/MAVProxy/modules/mavproxy_mode.py +++ b/MAVProxy/modules/mavproxy_mode.py @@ -5,12 +5,14 @@ from pymavlink import mavutil from MAVProxy.modules.lib import mp_module +from MAVProxy.modules.lib import mp_util class ModeModule(mp_module.MPModule): def __init__(self, mpstate): super(ModeModule, self).__init__(mpstate, "mode", public=True) self.add_command('mode', self.cmd_mode, "mode change", self.available_modes()) self.add_command('guided', self.cmd_guided, "fly to a clicked location on map") + self.add_command('confirm', self.cmd_confirm, "confirm a command") def cmd_mode(self, args): '''set arbitrary mode''' @@ -31,6 +33,19 @@ def cmd_mode(self, args): modenum = mode_mapping[mode] self.master.set_mode(modenum) + def cmd_confirm(self, args): + '''confirm a command''' + if len(args) < 2: + print('Usage: confirm "Question to display" command ') + return + question = args[0].strip('"') + command = ' '.join(args[1:]) + if not mp_util.has_wxpython: + print("No UI available for confirm") + return + from MAVProxy.modules.lib import mp_menu + mp_menu.MPMenuConfirmDialog(question, callback=self.mpstate.functions.process_stdin, args=command) + def available_modes(self): if self.master is None: print('No mode mapping available')