Skip to content

Wizard serial port detect - #656

Draft
AARP41298 wants to merge 2 commits into
psieg:masterfrom
AARP41298:wizard-serial-port-detect
Draft

AARP41298 wants to merge 2 commits into
psieg:masterfrom
AARP41298:wizard-serial-port-detect

Conversation

@AARP41298

@AARP41298 AARP41298 commented Nov 28, 2026 •

Copy link
Copy Markdown

Every time i disconnect the LED strip the COM changes (even if i try to connect it to the same USB port) and i need to run the wizard again to configure it.
Also, i have to manually look in device manager wich port is now using so i can manually type it.

image image

Not tested with real hardware yet.

AARP41298 and others added 2 commits November 28, 2026 01:20
Replace the serial port text field with an editable combo box listing the
ports reported by QSerialPortInfo, labelled with their description (e.g.
"COM5 - USB-SERIAL CH340"), plus a Refresh button to rescan.

USB serial adapters are listed first and pre-selected when the configured
port is missing (e.g. the device was re-plugged and got a new number) or is
just the built-in default. A configured port that is present stays
selected, and a port name can still be typed manually. The wizard field
still stores only the port name.

Also guard QTEST_DISABLE_KEYPAD_NAVIGATION in the test runner, since it was
removed in Qt 6.12.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adalight/Ardulight users previously had to rerun the whole wizard (or edit
main.conf and restart) whenever the device's COM port changed. Add a
"Serial device" group to the Device tab, shown for serial devices, with the
detected-port combo box, a Refresh button and the baud rate.

Changes apply live: the Settings change signals now reach LedDeviceManager,
which pushes the new port/baud rate to the cached serial device instances
(they only got them at construction) and reconnects. Back-to-back changes
are coalesced into one reconnect; while sleeping, the new settings are used
on wake-up.

The port listing is moved into SerialPortComboHelper and shared with the
wizard's device configuration page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@psieg

psieg commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

Constantly having to rerun the wizard doesn't seem WAI. Is this an issue with your device firmware, rather than the host software? I haven't heard of this COM switching behavior before.

The changes in the wizard make sense to me, though AI review has a few comments. Putting these settings in the device page too breaks the separation of concerns and is incomplete. Could you separate the two changes please?

@psieg psieg closed this Nov 29, 2026
@psieg psieg reopened this Nov 29, 2026

@psieg psieg left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are the review comments on the wizard / serial-port helper changes (applicable whether you keep SerialPortComboHelper for the wizard or inline it back into ConfigureDevicePage).

Made with AI

Comment on lines +66 to +70
comboBox->addItem(label, port.portName());
comboBox->setItemData(idx, tooltip.join(QLatin1Char('\n')), Qt::ToolTipRole);

if (preferredIdx < 0 && port.portName().compare(preferredPort, Qt::CaseInsensitive) == 0)
preferredIdx = idx;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Linux and macOS, QSerialPortInfo::portName() returns the bare device name without /dev/ (e.g. "ttyUSB0", "ttyACM0", "cu.usbserial-..."), whereas port.systemLocation() is "/dev/ttyUSB0". However, SERIAL_PORT_DEFAULT on Unix is "/dev/ttyUSB0" (SettingsDefaults.hpp) and existing main.conf files / manual entries typically store /dev/... paths.

Because populate() and selectPortName() (line 101) only store and compare port.portName(), any configured /dev/... path on Linux/macOS will fail to match (preferredIdx == -1), causing populate() to treat the configured port as disconnected and silently fall back to firstUsbIdx (which may be a different USB serial device).

Please match preferredPort / portName against both port.portName() and port.systemLocation(), and consider storing port.systemLocation() on Unix (or normalizing /dev/ prefixes consistently) so existing Unix configs keep matching.

Comment on lines +88 to +97
QString selectedPortName(const QComboBox *comboBox)
{
const QString text = comboBox->currentText().trimmed();
// A detected port is shown as "COM5 - USB-SERIAL CH340"; its port name is in the item data.
// Anything else was typed by hand and is used as-is.
const int idx = comboBox->findText(text);
if (idx >= 0)
return comboBox->itemData(idx).toString();
return text;
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the combo box is editable and items use "COM5 - USB-SERIAL CH340" as their Qt::DisplayRole text, Qt populates the QLineEdit with the full "port - description" label. If a user edits the port name in place (e.g. changing 5 to 6 so the text becomes "COM6 - USB-SERIAL CH340"), comboBox->findText(text) returns -1 and selectedPortName() returns the entire "COM6 - USB-SERIAL CH340" string as the port name, which QSerialPort cannot open.

Either put only the bare port name into the QLineEdit when an item is selected (rendering descriptions in the popup via a delegate/model or separate hint) or otherwise avoid treating an edited "<port> - <description>" label as a literal port name.

Comment on lines +33 to +36
void populate(QComboBox *comboBox, const QString &preferredPort, const bool preferredIsDefault)
{
QList<QSerialPortInfo> ports = QSerialPortInfo::availablePorts();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider extracting an overload that accepts a list of lightweight port-info structs (instead of calling QSerialPortInfo::availablePorts() directly) and adding unit tests in Software/tests/ covering the sorting, fallback selection, and Windows (COMx) vs. Unix (/dev/tty*) path matching.

ui->cbBaudRate->setCurrentText(QString::number(currentBaudRate));
if (!currentSerialPort.isEmpty())
ui->leSerialPortName->setText(currentSerialPort);
populateSerialPorts(currentSerialPort, currentSerialPort == QStringLiteral(SERIAL_PORT_DEFAULT));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Linux, SERIAL_PORT_DEFAULT is "/dev/ttyUSB0", which is a real and very common USB serial adapter path (unlike COM1 on Windows, which is usually a motherboard RS-232 port). Passing currentSerialPort == SERIAL_PORT_DEFAULT as preferredIsDefault means that if a Linux user explicitly saved /dev/ttyUSB0 in a previous wizard run and also has /dev/ttyACM0 plugged in (ttyACM0 sorts before ttyUSB0), reopening the wizard will discard their configured /dev/ttyUSB0 and select ttyACM0.

preferredIsDefault should only be true when the selected serial device hasn't actually been configured yet (e.g. !_isInitFromSettings, or the serial port setting has never been saved for that device type).

Comment on lines +76 to +92
<widget class="QComboBox" name="cbSerialPortName">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable">
<bool>true</bool>
</property>
<property name="insertPolicy">
<enum>QComboBox::NoInsert</enum>
</property>
<property name="toolTip">
<string>Detected serial ports. You can also type a port name manually.</string>
</property>
</widget>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QComboBox defaults to QComboBox::AdjustToContents, so long OS port descriptions (e.g. "COM12 - Standard Serial over Bluetooth link (Microsoft Corporation)") can expand cbSerialPortName's sizeHint and stretch the 400px wizard page. Setting sizeAdjustPolicy to QComboBox::AdjustToMinimumContentsLengthWithIcon (with a reasonable minimumContentsLength) keeps the combo box constrained to the layout while preserving full labels in the popup.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants