Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/org/openlcb/DatagramMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,7 @@ public String toString() {
int n = getData().length;
value.append("("+n+") ");
boolean first = true;
for (int i = 0; i<n; i++) {
if (!first) value.append(".");
value.append(Integer.toHexString((int)(data[i]&0xFF)).toUpperCase());
first = false;
}
value.append(Utilities.toHexDotsString(data));
return new String(value);
}
}
89 changes: 72 additions & 17 deletions src/org/openlcb/swing/EventIdTextField.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,10 @@ 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;
}

Expand All @@ -179,6 +169,18 @@ 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 ...");

return wkeMenu;
}

Expand Down Expand Up @@ -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());

Expand All @@ -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));
Expand All @@ -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<String> onOffBox = new JComboBox<String>(
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);
Expand Down