-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Export tab has changed name to Capture and works - Capture tab allows to capture data to file in such format such we want - choice: hex or decimal, is still to fix
- Loading branch information
Showing
13 changed files
with
420 additions
and
129 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
package mainwindow; | ||
|
||
import application.Main; | ||
import classes.Frame; | ||
import javafx.application.Platform; | ||
import javafx.fxml.Initializable; | ||
import javafx.scene.control.*; | ||
import javafx.stage.FileChooser; | ||
import port.PortReader; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.PrintWriter; | ||
import java.net.URL; | ||
import java.util.ArrayList; | ||
import java.util.ResourceBundle; | ||
|
||
public class CaptureController implements Initializable | ||
{ | ||
public TextField filePathTextField; | ||
|
||
public Button chooseFileButton; | ||
public Button startOverwriteButton; | ||
public Button startAppendButton; | ||
public Button stopButton; | ||
|
||
public RadioButton asHexRadioButton; | ||
public RadioButton asDecimalRadioButton; | ||
|
||
public CheckBox channel1CheckBox; | ||
public CheckBox channel2CheckBox; | ||
public CheckBox channel3CheckBox; | ||
public CheckBox channel4CheckBox; | ||
public CheckBox channel5CheckBox; | ||
public CheckBox channel6CheckBox; | ||
public CheckBox channel7CheckBox; | ||
public CheckBox channel8CheckBox; | ||
|
||
private ArrayList<CheckBox> channelCheckBoxes; | ||
|
||
private volatile boolean isActiveExport; | ||
|
||
private File file; | ||
|
||
@Override | ||
public void initialize(URL location, ResourceBundle resources) | ||
{ | ||
channelCheckBoxes = new ArrayList<>(); | ||
|
||
channelCheckBoxes.add(channel1CheckBox); | ||
channelCheckBoxes.add(channel2CheckBox); | ||
channelCheckBoxes.add(channel3CheckBox); | ||
channelCheckBoxes.add(channel4CheckBox); | ||
channelCheckBoxes.add(channel5CheckBox); | ||
channelCheckBoxes.add(channel6CheckBox); | ||
channelCheckBoxes.add(channel7CheckBox); | ||
channelCheckBoxes.add(channel8CheckBox); | ||
} | ||
|
||
public void chooseFileClick() | ||
{ | ||
FileChooser fileChooser = new FileChooser(); | ||
|
||
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("TXT files (*.txt)", "*.txt"); | ||
fileChooser.getExtensionFilters().add(extFilter); | ||
fileChooser.setTitle("Save as"); | ||
file = fileChooser.showSaveDialog(Main.getPrimaryStage()); | ||
|
||
if(null != file) | ||
{ | ||
filePathTextField.setText(file.getPath()); | ||
} | ||
} | ||
|
||
public void startOverwriteClick() | ||
{ | ||
file = new File(filePathTextField.getText()); | ||
|
||
if(file.exists()) | ||
{ | ||
if(PortReader.getInstance().isOpen()) | ||
{ | ||
PortReader.getInstance().setExportBufferEnabled(true); | ||
isActiveExport = true; | ||
|
||
stopButton.setDisable(false); | ||
//startAppendButton.setDisable(true); | ||
startOverwriteButton.setDisable(true); | ||
|
||
new Thread(() -> | ||
{ | ||
int i; | ||
|
||
boolean checks[] = new boolean[8]; | ||
|
||
try | ||
{ | ||
PrintWriter printWriter = new PrintWriter(file); | ||
|
||
while (isActiveExport) | ||
{ | ||
if (!PortReader.getInstance().getExportFrameBuffer().isEmpty()) | ||
{ | ||
Frame frame = PortReader.getInstance().getExportFrameBuffer().take(); | ||
|
||
for(i = 0; i < frame.getNumberOfChannels(); i++) | ||
{ | ||
int finalI = i; | ||
Platform.runLater(() -> channelCheckBoxes.get(finalI).setDisable(false)); | ||
} | ||
|
||
for(i = frame.getNumberOfChannels(); i < 8; i++) | ||
{ | ||
int finalI = i; | ||
Platform.runLater(() -> channelCheckBoxes.get(finalI).setDisable(true)); | ||
} | ||
|
||
for(i = 0; i < 8; i++) | ||
{ | ||
checks[i] = channelCheckBoxes.get(i).isSelected(); | ||
} | ||
|
||
printWriter.println(frame.toString(checks)); | ||
} | ||
} | ||
|
||
printWriter.close(); | ||
} | ||
catch (FileNotFoundException | InterruptedException e) | ||
{ | ||
e.printStackTrace(); | ||
} | ||
|
||
}).start(); | ||
|
||
} | ||
else | ||
{ | ||
showInformationAlert("Port must be open to capture!"); | ||
} | ||
} | ||
else | ||
{ | ||
showErrorAlert("Podana ścieżka jest niepoprawna!"); | ||
} | ||
} | ||
|
||
public void startAppendClick() | ||
{ | ||
if(PortReader.getInstance().isOpen()) | ||
{ | ||
PortReader.getInstance().setExportBufferEnabled(true); | ||
isActiveExport = true; | ||
|
||
stopButton.setDisable(false); | ||
startAppendButton.setDisable(true); | ||
startOverwriteButton.setDisable(true); | ||
|
||
} | ||
else | ||
{ | ||
showInformationAlert("Port must be open to capture!"); | ||
} | ||
} | ||
|
||
public void stopClick() | ||
{ | ||
PortReader.getInstance().setExportBufferEnabled(false); | ||
isActiveExport = false; | ||
|
||
stopButton.setDisable(true); | ||
//startAppendButton.setDisable(false); | ||
startOverwriteButton.setDisable(false); | ||
|
||
for(int i = 0; i < 8; i++) | ||
{ | ||
int finalI = i; | ||
Platform.runLater(() -> channelCheckBoxes.get(finalI).setDisable(false)); | ||
} | ||
|
||
} | ||
|
||
private void showInformationAlert(String information) | ||
{ | ||
Alert alert = new Alert(Alert.AlertType.INFORMATION); | ||
|
||
alert.setTitle("Real Time Serial Plotter"); | ||
alert.setHeaderText(null); | ||
alert.setContentText(information); | ||
alert.showAndWait(); | ||
} | ||
|
||
private void showErrorAlert(String error) | ||
{ | ||
Alert alert = new Alert(Alert.AlertType.ERROR); | ||
|
||
alert.setTitle("Real Time Serial Plotter"); | ||
alert.setHeaderText(null); | ||
alert.setContentText(error); | ||
alert.showAndWait(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import java.lang.*?> | ||
<?import javafx.scene.text.*?> | ||
<?import javafx.geometry.*?> | ||
<?import javafx.scene.control.*?> | ||
<?import javafx.scene.layout.*?> | ||
|
||
<GridPane prefHeight="288.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mainwindow.CaptureController"> | ||
<columnConstraints> | ||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="498.0" minWidth="10.0" prefWidth="473.0" /> | ||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="498.0" minWidth="10.0" prefWidth="25.0" /> | ||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="337.0" minWidth="10.0" prefWidth="109.0" /> | ||
</columnConstraints> | ||
<rowConstraints> | ||
<RowConstraints maxHeight="182.0" minHeight="0.0" prefHeight="22.0" /> | ||
<RowConstraints maxHeight="245.0" minHeight="0.0" prefHeight="245.0" /> | ||
<RowConstraints maxHeight="201.0" minHeight="10.0" prefHeight="21.0" vgrow="SOMETIMES" /> | ||
</rowConstraints> | ||
<padding> | ||
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> | ||
</padding> | ||
<children> | ||
<VBox prefHeight="168.0" prefWidth="412.0" spacing="10.0" GridPane.rowIndex="1"> | ||
<padding> | ||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" /> | ||
</padding> | ||
<children> | ||
<HBox prefHeight="0.0" prefWidth="410.0"> | ||
<children> | ||
<Label alignment="CENTER" prefHeight="23.0" prefWidth="21.0" text="File:"> | ||
<font> | ||
<Font size="11.0" /> | ||
</font> | ||
</Label> | ||
<TextField fx:id="filePathTextField" focusTraversable="false" minHeight="20.0" prefHeight="10.0" prefWidth="268.0" text="C:\captureOfData.txt"> | ||
<HBox.margin> | ||
<Insets left="5.0" right="5.0" /> | ||
</HBox.margin> | ||
</TextField> | ||
<Button fx:id="chooseFileButton" focusTraversable="false" minHeight="20.0" mnemonicParsing="false" onAction="#chooseFileClick" prefHeight="22.0" prefWidth="24.0" text="..." /> | ||
</children> | ||
</HBox> | ||
<HBox prefHeight="24.0" prefWidth="464.0"> | ||
<VBox.margin> | ||
<Insets /> | ||
</VBox.margin> | ||
<opaqueInsets> | ||
<Insets /> | ||
</opaqueInsets> | ||
<children> | ||
<Button fx:id="startOverwriteButton" focusTraversable="false" minHeight="20.0" mnemonicParsing="false" onAction="#startOverwriteClick" prefHeight="24.0" prefWidth="105.0" text="Start: Overwrite"> | ||
<font> | ||
<Font size="11.0" /> | ||
</font> | ||
<HBox.margin> | ||
<Insets right="5.0" /> | ||
</HBox.margin> | ||
</Button> | ||
<Button fx:id="startAppendButton" disable="true" focusTraversable="false" minHeight="20.0" mnemonicParsing="false" onAction="#startAppendClick" prefHeight="24.0" prefWidth="89.0" text="Start: Append"> | ||
<HBox.margin> | ||
<Insets left="5.0" right="5.0" /> | ||
</HBox.margin> | ||
<font> | ||
<Font size="11.0" /> | ||
</font> | ||
</Button> | ||
<Button fx:id="stopButton" disable="true" mnemonicParsing="false" onAction="#stopClick" text="Stop"> | ||
<HBox.margin> | ||
<Insets left="5.0" /> | ||
</HBox.margin> | ||
</Button> | ||
</children> | ||
</HBox> | ||
<RadioButton fx:id="asHexRadioButton" focusTraversable="false" mnemonicParsing="false" text="as hex"> | ||
<font> | ||
<Font size="11.0" /> | ||
</font> | ||
</RadioButton> | ||
<RadioButton fx:id="asDecimalRadioButton" focusTraversable="false" mnemonicParsing="false" text="as decimal"> | ||
<font> | ||
<Font size="11.0" /> | ||
</font> | ||
</RadioButton> | ||
</children> | ||
</VBox> | ||
<VBox maxWidth="306.0" prefHeight="275.0" prefWidth="306.0" spacing="5.0" GridPane.columnIndex="2" GridPane.rowIndex="1"> | ||
<children> | ||
<Label alignment="CENTER" prefHeight="15.0" prefWidth="92.0" text="Choose channels:" textAlignment="CENTER" /> | ||
<Separator prefWidth="200.0" /> | ||
<CheckBox fx:id="channel1CheckBox" focusTraversable="false" mnemonicParsing="false" text="Channel 1" /> | ||
<CheckBox fx:id="channel2CheckBox" focusTraversable="false" mnemonicParsing="false" text="Channel 2" /> | ||
<CheckBox fx:id="channel3CheckBox" focusTraversable="false" layoutX="10.0" layoutY="68.0" mnemonicParsing="false" text="Channel 3" /> | ||
<CheckBox fx:id="channel4CheckBox" focusTraversable="false" layoutX="10.0" layoutY="85.0" mnemonicParsing="false" text="Channel 4" /> | ||
<CheckBox fx:id="channel5CheckBox" focusTraversable="false" layoutX="10.0" layoutY="51.0" mnemonicParsing="false" text="Channel 5" /> | ||
<CheckBox fx:id="channel6CheckBox" focusTraversable="false" layoutX="10.0" layoutY="119.0" mnemonicParsing="false" text="Channel 6" /> | ||
<CheckBox fx:id="channel7CheckBox" focusTraversable="false" layoutX="10.0" layoutY="68.0" mnemonicParsing="false" text="Channel 7" /> | ||
<CheckBox fx:id="channel8CheckBox" focusTraversable="false" layoutX="10.0" layoutY="153.0" mnemonicParsing="false" text="Channel 8" /> | ||
</children> | ||
</VBox> | ||
<Label prefHeight="41.0" prefWidth="174.0" text="Capture" textAlignment="CENTER"> | ||
<font> | ||
<Font name="System Bold" size="18.0" /> | ||
</font> | ||
</Label> | ||
<Separator orientation="VERTICAL" prefHeight="245.0" prefWidth="139.0" GridPane.columnIndex="1" GridPane.rowIndex="1" /> | ||
</children> | ||
</GridPane> |
Oops, something went wrong.