Skip to content

Commit dbc2ede

Browse files
committed
Show the device name in port list
For WARDuino on Zephyr it should show "WARDuino Microcontroller"
1 parent c10988a commit dbc2ede

1 file changed

Lines changed: 32 additions & 6 deletions

File tree

src/main/kotlin/be/ugent/topl/mio/ui/StartScreen.kt

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ import java.io.FileWriter
1515
import java.io.IOException
1616
import java.util.*
1717
import javax.swing.*
18+
import javax.swing.event.PopupMenuEvent
19+
import javax.swing.event.PopupMenuListener
20+
21+
data class PortElement(val portPath: String, val portInfo: String) {
22+
override fun toString(): String {
23+
if (portInfo == "Unknown")
24+
return portPath
25+
return "$portInfo ($portPath)"
26+
}
27+
}
1828

1929
open class StartScreen(config: DebuggerConfig) : AboutScreen(config) {
2030
init {
@@ -23,25 +33,41 @@ open class StartScreen(config: DebuggerConfig) : AboutScreen(config) {
2333
}
2434

2535
override fun addOptions(mainPanel: JPanel) {
26-
val portComboBox = JComboBox<String>().apply {
36+
val portComboBox = JComboBox<PortElement>().apply {
37+
prototypeDisplayValue = PortElement("", " ")
2738
setAlignmentX(CENTER_ALIGNMENT)
28-
maximumSize = Dimension(250, 500)
39+
maximumSize = Dimension(Integer.MAX_VALUE, 500)
2940
for (port in SerialPort.getCommPorts()) {
30-
addItem(port.systemPortPath)
41+
addItem(PortElement(port.systemPortPath, port.portDescription))
3142
}
3243
if (config.port != null) {
3344
selectedItem = config.port
3445
}
46+
addPopupMenuListener(object : PopupMenuListener {
47+
override fun popupMenuWillBecomeVisible(e: PopupMenuEvent?) {
48+
val currentItem = selectedItem as PortElement
49+
removeAllItems()
50+
for (port in SerialPort.getCommPorts()) {
51+
addItem(PortElement(port.systemPortPath, port.portDescription))
52+
}
53+
selectedItem = currentItem
54+
}
55+
56+
override fun popupMenuWillBecomeInvisible(e: PopupMenuEvent?) {}
57+
58+
override fun popupMenuCanceled(e: PopupMenuEvent?) {}
59+
})
3560
}
3661
val portBox = Box.createHorizontalBox()
3762
portBox.border = BorderFactory.createEmptyBorder(10, 20, 0, 20)
63+
portBox.add(JLabel("Port: "))
3864
portBox.add(portComboBox)
3965
portBox.add(JButton(FlatSVGIcon(javaClass.getResource("/refresh.svg"))).apply {
4066
addActionListener {
41-
val currentItem = portComboBox.selectedItem as String
67+
val currentItem = portComboBox.selectedItem as PortElement
4268
portComboBox.removeAllItems()
4369
for (port in SerialPort.getCommPorts()) {
44-
portComboBox.addItem(port.systemPortPath) // TODO: We can use the device name CONFIG_USB_DEVICE_PRODUCT
70+
portComboBox.addItem(PortElement(port.systemPortPath, port.portDescription))
4571
}
4672
portComboBox.selectedItem = currentItem
4773
}
@@ -67,7 +93,7 @@ open class StartScreen(config: DebuggerConfig) : AboutScreen(config) {
6793
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
6894
recentProperties.setProperty("lastDir", chooser.selectedFile.parent)
6995
recentProperties.store(FileWriter(recentConfig), null)
70-
if(!startDebugger(chooser.selectedFile, emulatorCheckbox.isSelected, portComboBox.selectedItem as String?)) {
96+
if(!startDebugger(chooser.selectedFile, emulatorCheckbox.isSelected, (portComboBox.selectedItem as PortElement).portPath)) {
7197
return@addActionListener
7298
}
7399
isVisible = false

0 commit comments

Comments
 (0)