Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User defined events #61

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions src/main/java/uorocketry/basestation/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public Main() {

private void setupData() {
dataProcessor = new DataProcessor(config, window.dataTables);
window.userEventPanel.setDataPointHolder(dataProcessor.getDataPointHolder());

currentDataIndexes = new ArrayList<>(config.getDataSourceCount());
minDataIndexes = new ArrayList<>(config.getDataSourceCount());
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/uorocketry/basestation/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
import uorocketry.basestation.connections.DeviceConnectionHolder;
import uorocketry.basestation.connections.DataReceiver;
import uorocketry.basestation.control.StateButton;
import uorocketry.basestation.control.UserEventPanel;
import uorocketry.basestation.data.DataTableCellRenderer;
import uorocketry.basestation.data.RssiProcessor;
import uorocketry.basestation.panel.Chart;
import uorocketry.basestation.panel.DataChart;
import uorocketry.basestation.panel.TableHolder;

public class Window extends JFrame {
Expand Down Expand Up @@ -77,6 +77,7 @@ public class Window extends JFrame {
List<JSlider> maxSliders = new ArrayList<JSlider>(2);
List<JSlider> minSliders = new ArrayList<JSlider>(2);
public JTabbedPane sliderTabs;
UserEventPanel userEventPanel;
JButton clearDataButton;
JButton refreshComSelectorButton;
JButton hideComSelectorButton;
Expand Down Expand Up @@ -232,7 +233,10 @@ public Window(Main main, Config config) {

eastSliderButtons = new JPanel();
sliderButtons.add(eastSliderButtons, BorderLayout.EAST);


userEventPanel = new UserEventPanel(config);
eastSliderButtons.add(userEventPanel.getPanel());

clearDataButton = new JButton("Clear Data");
eastSliderButtons.add(clearDataButton);

Expand Down
69 changes: 69 additions & 0 deletions src/main/java/uorocketry/basestation/control/UserEventPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package uorocketry.basestation.control;

import uorocketry.basestation.config.Config;
import uorocketry.basestation.data.DataHolder;
import uorocketry.basestation.data.DataPointHolder;
import uorocketry.basestation.data.UserEvent;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class UserEventPanel implements ActionListener {
private JPanel panel;
private JButton recordEventButton;

private List<UserEvent> events = new ArrayList<>();

private Config mainConfig;
private DataPointHolder dataPointHolder;

public UserEventPanel(Config mainConfig) {
this.mainConfig = mainConfig;
panel = new JPanel();

recordEventButton = new JButton(getButtonTitle(0));
recordEventButton.addActionListener(this);
panel.add(recordEventButton);
}

public JPanel getPanel() {
return panel;
}

@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == recordEventButton) {
List<List<DataHolder>> allData = dataPointHolder.getAllReceivedData();
long[] datasetsTimestamp = new long[allData.size()];
for (int i = 0; i < allData.size(); i++) {
Integer timestampIndex = mainConfig.getDataSet(i).getIndex("timestamp");
List<DataHolder> dataHolders = allData.get(i);
if (timestampIndex != null && dataHolders != null && dataHolders.size() > 0) {
DataHolder currentData = dataHolders.get(dataHolders.size() - 1);
datasetsTimestamp[i] = currentData != null ?
Optional.ofNullable(currentData.data[timestampIndex].getLongValue()).orElse(-1L)
: -1L;
} else {
datasetsTimestamp[i] = -1;
}
}

events.add(new UserEvent("", events.size(), System.currentTimeMillis(), datasetsTimestamp));
recordEventButton.setText(getButtonTitle(events.size()));

System.out.println(events.size() + "\t" + System.currentTimeMillis() + "\t" + datasetsTimestamp);
}
}

private String getButtonTitle(int index) {
return "Record Event (" + index + ")";
}

public void setDataPointHolder(DataPointHolder dataPointHolder) {
this.dataPointHolder = dataPointHolder;
}
}
31 changes: 31 additions & 0 deletions src/main/java/uorocketry/basestation/data/UserEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package uorocketry.basestation.data;

public class UserEvent {
private String name;
private int index;
private long epochTime;
private long[] datasetTime;

public UserEvent(String name, int index, long epochTime, long[] datasetTime) {
this.name = name;
this.index = index;
this.epochTime = epochTime;
this.datasetTime = datasetTime;
}

public String getName() {
return name;
}

public int getIndex() {
return index;
}

public long getEpochTime() {
return epochTime;
}

public long[] getDatasetTime() {
return datasetTime;
}
}