diff options
Diffstat (limited to 'confui/mainwindow.cpp')
-rw-r--r-- | confui/mainwindow.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/confui/mainwindow.cpp b/confui/mainwindow.cpp index 8dcf077..b0a1857 100644 --- a/confui/mainwindow.cpp +++ b/confui/mainwindow.cpp @@ -49,11 +49,20 @@ void CDMainWindow::update() { QAction *menu_options_add_automation = menu_options->addAction("add automation"); connect(menu_options_add_automation, &QAction::triggered, this, &CDMainWindow::menu_add_automation); - QMenu *menu_options_serialport = menu_options->addMenu("serial port (FIXME)"); + QString serial_port_menu_label = "serial port"; + string port_name = g_cd_serial->get_port(); + if (port_name.size() > 0) { + serial_port_menu_label.append(" ("); + serial_port_menu_label.append(QString::fromStdString(port_name)); + serial_port_menu_label.append(")"); + } + QMenu *menu_options_serialport = menu_options->addMenu(serial_port_menu_label); vector<string> ports = CDSerialConnector::get_ports(); - for (string port : ports) - menu_options_serialport->addAction(QString::fromStdString(port)); + for (string port : ports) { + QAction* menu_port = menu_options_serialport->addAction(QString::fromStdString(port)); + connect(menu_port, &QAction::triggered, this, [this, port](){ menu_set_serial_port(port); }); + } } void CDMainWindow::menu_refresh() { update(); } @@ -62,3 +71,9 @@ void CDMainWindow::menu_add_automation() { g_cd_mesh_connector->create_link(); update(); } + +void CDMainWindow::menu_set_serial_port(string new_port) { + g_cd_serial->disconnect(); + g_cd_serial->connect(new_port); + update(); +} |