Skip to content

Commit

Permalink
wokring on more displays
Browse files Browse the repository at this point in the history
  • Loading branch information
tomtzook committed Jul 4, 2023
1 parent 9a9959c commit 0440769
Show file tree
Hide file tree
Showing 12 changed files with 396 additions and 19 deletions.
23 changes: 20 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,26 @@ plugins {
id 'org.openjfx.javafxplugin' version '0.0.9'
}

def SUPPORTED_ARCHES = ['windowsx86-64', 'linuxx86-64']

sourceCompatibility = JavaVersion.VERSION_11

repositories {
mavenCentral()
mavenLocal()

maven {
url('https://frcmaven.wpi.edu/artifactory/release')
}
}

dependencies {
implementation group: 'com.flash3388.flashlib', name: 'flashlib.core.robot', version: '3.2.0-beta.1'
implementation group: 'com.flash3388.flashlib', name: 'flashlib.hid.sdl2', version: '3.2.0-beta.1'
implementation group: 'com.flash3388.flashlib', name: 'flashlib.core.robot', version: FLASHLIB_VERSION
implementation group: 'com.flash3388.flashlib', name: 'flashlib.net.robolink', version: FLASHLIB_VERSION
implementation group: 'com.flash3388.flashlib', name: 'flashlib.vision.core', version: FLASHLIB_VERSION

implementation group: 'com.flash3388.flashlib', name: 'flashlib.core.hid', version: FLASHLIB_VERSION
implementation group: 'com.flash3388.flashlib', name: 'flashlib.hid.sdl2', version: FLASHLIB_VERSION
implementation group: 'com.github.tomtzook', name: 'jsdl2-jni', version: '0.1.0', classifier: 'linux-amd64'

implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
Expand All @@ -25,6 +35,13 @@ dependencies {
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.7'
implementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.7'

implementation group: 'edu.wpi.first.wpiutil', name: 'wpiutil-java', version: "$WPILIB_VERSION"
implementation group: 'edu.wpi.first.ntcore', name: 'ntcore-java', version: "$WPILIB_VERSION"
SUPPORTED_ARCHES.forEach({
implementation group: 'edu.wpi.first.wpiutil', name: 'wpiutil-jni', version: "$WPILIB_VERSION", classifier: "$it"
implementation group: 'edu.wpi.first.ntcore', name: 'ntcore-jni', version: "$WPILIB_VERSION", classifier: "$it"
})

testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.4.2'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.4.2'
testImplementation group: 'org.junit.platform', name: 'junit-platform-runner', version: '1.2.0'
Expand All @@ -49,7 +66,7 @@ jar {

javafx {
version = '11'
modules = [ 'javafx.controls' ]
modules = [ 'javafx.controls', 'javafx.media', 'javafx.swing' ]
//use to do cross platform
//configuration = 'compileOnly'
}
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@

FLASHLIB_VERSION=3.2.0-beta.6
WPILIB_VERSION=2022.4.1
25 changes: 21 additions & 4 deletions src/main/java/com/flash3388/flashlib/viewerfx/gui/MainWindow.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.flash3388.flashlib.viewerfx.gui;

import com.castle.exceptions.ServiceException;
import com.castle.util.closeables.Closeables;
import com.flash3388.flashlib.viewerfx.gui.views.ConfigView;
import com.flash3388.flashlib.viewerfx.gui.views.NtSchedulerView;
import com.flash3388.flashlib.viewerfx.gui.views.StreamView;
import com.flash3388.flashlib.viewerfx.services.FlashLibServices;
import com.flash3388.flashlib.viewerfx.gui.views.AbstractView;
import com.flash3388.flashlib.viewerfx.gui.views.RobotControlView;
import com.flash3388.flashlib.viewerfx.gui.views.JoystickView;
import com.flash3388.flashlib.viewerfx.gui.views.ObsrView;
import edu.wpi.first.networktables.NetworkTableInstance;
import javafx.application.Platform;
import javafx.geometry.Side;
import javafx.scene.Scene;
Expand All @@ -17,7 +21,7 @@

import java.util.concurrent.atomic.AtomicReference;

public class MainWindow implements AutoCloseable {
public class MainWindow extends AbstractView {

private final double mWidth;
private final double mHeight;
Expand All @@ -29,6 +33,8 @@ public class MainWindow implements AutoCloseable {
private final RobotControlView mRobotControlView;
private final JoystickView mJoystickView;
private final ConfigView mConfigView;
private final StreamView mStreamView;
private final NtSchedulerView mNtSchedulerView;

private final AtomicReference<AbstractView> mSelectedView;

Expand All @@ -42,6 +48,8 @@ public MainWindow(Stage owner, double width, double height, FlashLibServices ser
mRobotControlView = new RobotControlView(services.getHfcsService(), services.getClock());
mJoystickView = new JoystickView(services.getHfcsService());
mConfigView = new ConfigView(services);
mStreamView = new StreamView();
mNtSchedulerView = new NtSchedulerView(services.getNtInstance());

mSelectedView = new AtomicReference<>();
}
Expand All @@ -63,8 +71,16 @@ public Scene createScene() {
configTab.setContent(mConfigView);
configTab.setClosable(false);

Tab streamTab = new Tab("Streams");
streamTab.setContent(mStreamView);
streamTab.setClosable(false);

Tab ntSchedulerView = new Tab("NT Scheduler");
ntSchedulerView.setContent(mNtSchedulerView);
ntSchedulerView.setClosable(false);

TabPane tabPane = new TabPane();
tabPane.getTabs().addAll(obsrTab, instancesTab, joysticksTab, configTab);
tabPane.getTabs().addAll(obsrTab, instancesTab, joysticksTab, configTab, streamTab, ntSchedulerView);
tabPane.setSide(Side.LEFT);
tabPane.getSelectionModel().selectedItemProperty().addListener((obs, o, n)-> {
mSelectedView.set((AbstractView) n.getContent());
Expand All @@ -85,7 +101,8 @@ public void updateView() {
}

@Override
public void close() throws Exception {
mJoystickView.close();
public void close() {
Closeables.silentClose(mJoystickView);
Closeables.silentClose(mStreamView);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import javafx.scene.layout.BorderPane;

public abstract class AbstractView extends BorderPane {
public abstract class AbstractView extends BorderPane implements AutoCloseable {

public abstract void updateView();
public abstract void close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import com.castle.concurrent.service.TerminalService;
import com.castle.exceptions.ServiceException;
import com.flash3388.flashlib.hid.data.HidData;
import com.flash3388.flashlib.hid.data.RawHidData;
import com.flash3388.flashlib.hid.sdl2.hfcs.Sdl2HfcsHid;
import com.flash3388.flashlib.net.hfcs.HfcsRegistry;
import com.flash3388.flashlib.robot.hfcs.hid.HfcsHid;
import com.flash3388.flashlib.robot.hfcs.hid.HidData;
import com.flash3388.flashlib.robot.hfcs.hid.RawHidData;
import com.flash3388.flashlib.time.Time;
import com.flash3388.flashlib.viewerfx.gui.controls.AxisIndicator;
import com.flash3388.flashlib.viewerfx.gui.controls.BooleanIndicator;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package com.flash3388.flashlib.viewerfx.gui.views;

import edu.wpi.first.networktables.EntryListenerFlags;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.networktables.NetworkTableInstance;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.VBox;

import java.io.Closeable;
import java.io.IOException;

public class NtSchedulerView extends AbstractView {

public NtSchedulerView(NetworkTableInstance ntInstance) {
ListView<InstanceNode> instancesList = new ListView<>();
instancesList.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
instancesList.getSelectionModel().selectedItemProperty().addListener((obs, o, n)-> {
setCenter(n.getDataPane());
});

NetworkTable instancesTable = ntInstance.getTable("FlashLib").getSubTable("instances");
instancesTable.addSubTableListener((parent, name, table) -> {
instancesList.getItems().add(new InstanceNode(table, name));
}, false);

VBox leftPane = new VBox();
leftPane.setAlignment(Pos.CENTER_LEFT);
leftPane.setPadding(new Insets(5));
leftPane.setSpacing(5);
leftPane.getChildren().addAll(instancesList);
setLeft(leftPane);
}

@Override
public void updateView() {

}

@Override
public void close() {

}

private static class InstanceNode {

private final NetworkTable mTable;
private final NetworkTable mSchedulerTable;
private final String mName;

private final Node mDataPane;

InstanceNode(NetworkTable table, String name) {
mTable = table;
mSchedulerTable = table.getSubTable("FlashLib").getSubTable("Scheduler");
mName = name;

ScrollPane scrollPane = new ScrollPane();
FlowPane dataPane = new FlowPane();
scrollPane.setContent(dataPane);
mDataPane = scrollPane;

mSchedulerTable.addSubTableListener((parent, subName, subTable) -> {
dataPane.getChildren().add(new ActionNode(subTable));
}, false);
}

public Node getDataPane() {
return mDataPane;
}

@Override
public String toString() {
return mName;
}
}

private static class ActionNode extends BorderPane implements Closeable {

private ActionNode(NetworkTable table) {
NetworkTableEntry nameEntry = table.getEntry("name");
NetworkTableEntry classEntry = table.getEntry("class");
NetworkTableEntry timeoutEntry = table.getEntry("timeout");
NetworkTableEntry requirementsEntry = table.getEntry("requirements");

NetworkTableEntry statusEntry = table.getEntry("status");
NetworkTableEntry phaseEntry = table.getEntry("phase");

VBox topPane = new VBox();
topPane.setAlignment(Pos.TOP_LEFT);
topPane.setPadding(new Insets(5));
topPane.setSpacing(5);
topPane.getChildren().addAll(
new Label(nameEntry.getString("")),
new Label(classEntry.getString("")));
setTop(topPane);

ListView<String> requirementsList = new ListView<>();
String requirementsString = requirementsEntry.getString("[]");
requirementsString = requirementsString.substring(1, requirementsString.length() - 1);
requirementsList.getItems().addAll(requirementsString.split(","));
requirementsList.setPlaceholder(new Label("No Requirements"));

VBox leftPane = new VBox();
leftPane.setAlignment(Pos.TOP_LEFT);
leftPane.setPadding(new Insets(5));
leftPane.setSpacing(5);
leftPane.setPrefSize(150, 100);
leftPane.getChildren().addAll(requirementsList);
setLeft(leftPane);

Label phaseLabel = new Label();
phaseLabel.setText(phaseEntry.getString(""));
phaseEntry.addListener((notification)-> {
phaseLabel.setText(notification.value.getString());
}, EntryListenerFlags.kUpdate);

Label statusLabel = new Label();
statusLabel.setText(statusEntry.getString(""));
statusEntry.addListener((notification)-> {
statusLabel.setText(notification.value.getString());
}, EntryListenerFlags.kUpdate);

VBox centerPane = new VBox();
centerPane.setAlignment(Pos.CENTER_LEFT);
centerPane.setPadding(new Insets(5));
centerPane.setSpacing(5);
centerPane.getChildren().addAll(phaseLabel, statusLabel);
setCenter(centerPane);
}

@Override
public void close() throws IOException {

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public class RobotControlView extends AbstractView {

private static final Time PING_INTERVAL = Time.seconds(5);
private static final Time CONTROL_INTERVAL = Time.seconds(1);
private static final Time CONTROL_INTERVAL = Time.milliseconds(200);

private final Clock mClock;
private final Map<InstanceId, InstanceNode> mNodes;
Expand Down
Loading

0 comments on commit 0440769

Please sign in to comment.