Skip to content

Commit baa078f

Browse files
Merge pull request #119
Add color check feature
2 parents d783932 + 874c33b commit baa078f

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/main/java/org/emrick/project/MediaEditorGUI.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,8 @@ private void createAndShowGUI() {
908908
hardwareMenu.addSeparator();
909909
JMenuItem modifyBoardItem = new JMenuItem("Modify Board");
910910
hardwareMenu.add(modifyBoardItem);
911+
JMenuItem checkColor = new JMenuItem("Check Color");
912+
hardwareMenu.add(checkColor);
911913

912914
verifyShowItem.addActionListener(e -> {
913915
SerialTransmitter st = comPortPrompt("Transmitter");
@@ -993,6 +995,25 @@ private void createAndShowGUI() {
993995
}
994996
});
995997

998+
checkColor.addActionListener(e -> {
999+
SerialTransmitter st = comPortPrompt("Receiver");
1000+
if (!st.getType().equals("Receiver")) return;
1001+
1002+
JLabel idLabel = new JLabel("Enter LED strip label to test color at current time");
1003+
JTextField idField = new JTextField();
1004+
1005+
Object[] inputs = {idLabel, idField};
1006+
int option = JOptionPane.showConfirmDialog(frame, inputs, "Enter LED Strip label", JOptionPane.OK_CANCEL_OPTION);
1007+
if (option == JOptionPane.OK_OPTION) {
1008+
LEDStrip l = footballFieldPanel.drill.ledStrips.stream().filter(led -> led.getLabel().equalsIgnoreCase(idField.getText())).findFirst().orElse(null);
1009+
if (l != null) {
1010+
Color c = footballFieldPanel.calculateColor(effectManager.getEffect(l, (long)(scrubBarGUI.getTime() * 1000)));
1011+
System.out.println(c);
1012+
st.writeColorCheck(c);
1013+
}
1014+
}
1015+
});
1016+
9961017
// Help menu
9971018
JMenu helpMenu = new JMenu("Help");
9981019
menuBar.add(helpMenu);

src/main/java/org/emrick/project/SerialTransmitter.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,30 @@ public void writeLEDCount(String ledCount) {
110110
sp.closePort();
111111
}
112112

113+
public void writeColorCheck(Color color) {
114+
String query = "c" + color.getRed() + "\n" + color.getGreen() + "\n" + color.getBlue() + "\n";
115+
sp.setDTR();
116+
sp.setRTS();
117+
if (!sp.openPort()) {
118+
System.out.println("Port is busy");
119+
return;
120+
}
121+
sp.closePort();
122+
sp.clearDTR();
123+
sp.clearRTS();
124+
sp.openPort();
125+
sp.flushIOBuffers();
126+
try {
127+
Thread.sleep(1000);
128+
} catch (InterruptedException e) {
129+
e.printStackTrace();
130+
}
131+
byte[] out = query.getBytes();
132+
sp.writeBytes(out, query.length());
133+
sp.flushIOBuffers();
134+
sp.closePort();
135+
}
136+
113137
public String getBoardType(String port) {
114138
SerialPort[] allPorts = SerialPort.getCommPorts();
115139
SerialPort s = null;

0 commit comments

Comments
 (0)