From 96a8b2e76cb742b7b073e5cae1844a36bcbc977b Mon Sep 17 00:00:00 2001 From: Bob Jacobsen Date: Fri, 21 Mar 2025 15:16:16 -0400 Subject: [PATCH 1/3] add sensor popup --- src/org/openlcb/swing/EventIdTextField.java | 95 ++++++++++++++++----- 1 file changed, 75 insertions(+), 20 deletions(-) diff --git a/src/org/openlcb/swing/EventIdTextField.java b/src/org/openlcb/swing/EventIdTextField.java index 2be7c790..81fa74fe 100644 --- a/src/org/openlcb/swing/EventIdTextField.java +++ b/src/org/openlcb/swing/EventIdTextField.java @@ -145,20 +145,7 @@ public void actionPerformed(ActionEvent e) { } } }); - - // create a submenu for well-known events - popup.add(makeWellKnownEventMenu(textfield)); - - // Add the time events - popup.add( makeClockEventMenuItem(textfield)); - - // Add the accessory decoder events - popup.add(makeDccAccessoryEventMenuItem(textfield)); - - // popup.add("Extended DCC accessory decoder events ..."); - // popup.add("DCC turnout feedback events ..."); - // popup.add("DCC system sensor feedback events ..."); - + return popup; } @@ -179,6 +166,21 @@ public static JMenu makeWellKnownEventMenu(JTextComponent textfield) { wkeMenu.add(new EventIdInserter( "Stop Default Fast Clock", "01.01.00.00.01.00.F0.01", textfield)); + // Add the time events + wkeMenu.add( makeClockEventMenuItem(textfield)); + + // Add the accessory decoder events + wkeMenu.add(makeDccAccessoryEventMenuItem(textfield)); + + // Add the sensor events + wkeMenu.add(makeDccSensorEventMenuItem(textfield)); + + // wkeMenu.add("Extended DCC accessory decoder events ..."); + // wkeMenu.add("DCC turnout feedback events ..."); + + // create a submenu for well-known events + wkeMenu.add(makeWellKnownEventMenu(textfield)); + return wkeMenu; } @@ -232,7 +234,7 @@ public static JMenuItem makeDccAccessoryEventMenuItem(JTextComponent textfield) @Override public void actionPerformed(ActionEvent e) { JDialog dialog = new JDialog(); - dialog.setTitle("Select DCC Accessory Decoder"); + dialog.setTitle("Select DCC Accessory Decoder Address"); JPanel innerPanel = new JPanel(new FlowLayout()); @@ -254,11 +256,11 @@ public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) { int from = Integer.parseInt(number.getText().trim()); - // See JMRI OlcnAddress line 89 for Event ID coding - int DD = (from-1) & 0x3; - int aaaaaa = (( (from-1) >> 2)+1 ) & 0x3F; - int AAA = ( (from) >> 8) & 0x7; - long event = 0x0101020000FF0000L | (AAA << 9) | (aaaaaa << 3) | (DD << 1); + // See JMRI OlcnAddress line 111 for Event ID coding + if (from >= 2045) from = from-2045; + else from = from + 3; + long event = 0x0101020000FF0000L | (from<<1); + event |= onOffBox.getSelectedIndex(); EventID id = new EventID(String.format("%016X", event)); @@ -278,6 +280,59 @@ public void actionPerformed(ActionEvent e) { return menuItem; } + public static JMenuItem makeDccSensorEventMenuItem(JTextComponent textfield) { + JMenuItem menuItem = new JMenuItem("Insert DCC sensor events ..."); + menuItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JDialog dialog = new JDialog(); + dialog.setTitle("Select DCC Sensor Address"); + + JPanel innerPanel = new JPanel(new FlowLayout()); + + JTextField number = new JTextField(12); + number.setText("1"); + innerPanel.add(number); + + JComboBox onOffBox = new JComboBox( + new String[]{ + "Inactive/Off", + "Active/On" + }); + innerPanel.add(onOffBox); + + JButton setButton = new JButton("Set"); + innerPanel.add(setButton); + setButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + int from = Integer.parseInt(number.getText().trim()); + + // See JMRI OlcnAddress line 126 for Event ID coding + from = 0xFFF & (from - 1); // 1 based name to 0 based network, 12 bit value + + long eventActive = 0x0101020000FB0000L | from; // active/on + long eventInactive = 0x0101020000FA0000L | from; // inactive/off + + long event = onOffBox.getSelectedIndex() == 0 ? eventInactive : eventActive; + + EventID id = new EventID(String.format("%016X", event)); + textfield.setText(id.toShortString()); + dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING)); + } + }); + + dialog.add(innerPanel); + dialog.setModal(true); + dialog.pack(); + dialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + + dialog.setVisible(true); + } + }); + return menuItem; + } + private static class EventIdInserter extends JMenuItem { public EventIdInserter(String name, String value, JTextComponent target) { super(name); From f3790e4b6c2c343f38199fdcdfe143c6ed09d400 Mon Sep 17 00:00:00 2001 From: Bob Jacobsen Date: Sun, 23 Mar 2025 14:21:38 -0400 Subject: [PATCH 2/3] Better output format --- src/org/openlcb/DatagramMessage.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/org/openlcb/DatagramMessage.java b/src/org/openlcb/DatagramMessage.java index a4c101d5..ea969f54 100644 --- a/src/org/openlcb/DatagramMessage.java +++ b/src/org/openlcb/DatagramMessage.java @@ -91,11 +91,7 @@ public String toString() { int n = getData().length; value.append("("+n+") "); boolean first = true; - for (int i = 0; i Date: Sun, 23 Mar 2025 14:21:56 -0400 Subject: [PATCH 3/3] Reorganize popup, add sensors --- src/org/openlcb/swing/EventIdTextField.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/org/openlcb/swing/EventIdTextField.java b/src/org/openlcb/swing/EventIdTextField.java index 81fa74fe..56b35ef3 100644 --- a/src/org/openlcb/swing/EventIdTextField.java +++ b/src/org/openlcb/swing/EventIdTextField.java @@ -146,6 +146,9 @@ public void actionPerformed(ActionEvent e) { } }); + // create a submenu for well-known events + popup.add(makeWellKnownEventMenu(textfield)); + return popup; } @@ -178,9 +181,6 @@ public static JMenu makeWellKnownEventMenu(JTextComponent textfield) { // wkeMenu.add("Extended DCC accessory decoder events ..."); // wkeMenu.add("DCC turnout feedback events ..."); - // create a submenu for well-known events - wkeMenu.add(makeWellKnownEventMenu(textfield)); - return wkeMenu; }