java.lang.Object
pl.polsl.rtsa.controller.MainController
Main JavaFX controller for the JSignalAnalysis UI.
Manages all user interactions (connect, start/stop, zoom, trigger, freeze),
drives the 30 FPS render loop via AnimationTimer, and bridges
the SignalAnalyzerApi backend with the canvas-based oscilloscope
and FFT views.
Render Pipeline:
- Backend delivers
SignalDatavia callback (background thread) - Data is posted to the FX thread with
Platform.runLater() - AnimationTimer picks it up at ~30 FPS and redraws both canvases
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate javafx.animation.AnimationTimerprivate final SignalAnalyzerApiprivate javafx.scene.control.CheckBoxprivate final Autoscalerprivate javafx.scene.control.Buttonprivate javafx.scene.control.Labelprivate booleanprivate doubleprivate doubleprivate javafx.scene.control.Labelprivate javafx.scene.canvas.Canvasprivate javafx.scene.control.CheckBoxprivate javafx.scene.layout.Paneprivate final FFTDomainRenprivate javafx.scene.layout.VBoxprivate javafx.scene.control.Sliderprivate javafx.scene.control.Labelprivate javafx.scene.control.Sliderprivate javafx.scene.control.Labelprivate static final longprivate javafx.scene.control.CheckBoxprivate javafx.scene.control.CheckBoxprivate booleanprivate longprivate SignalDataprivate doubleprivate booleanprivate booleanprivate javafx.scene.canvas.Canvasprivate javafx.scene.layout.VBoxprivate javafx.scene.control.ComboBox<String> private javafx.scene.control.ComboBox<String> private javafx.scene.layout.Paneprivate final TimeDomainRenprivate javafx.scene.layout.VBoxprivate javafx.scene.control.Sliderprivate javafx.scene.control.Labelprivate javafx.scene.control.Sliderprivate javafx.scene.control.Labelprivate javafx.scene.control.ToggleButtonprivate javafx.scene.control.CheckBoxprivate javafx.scene.control.Sliderprivate javafx.scene.control.Labelprivate booleanWhether the trigger slider range has been initialised from autoscale data.private javafx.scene.control.Labelprivate javafx.scene.control.Labelprivate javafx.scene.control.Labelprivate doubleprivate doubleprivate javafx.scene.control.Label -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidRecomputes voltage and magnitude ranges from the current signal data when the autoscale checkbox is selected.(package private) voidchangeSamplingFreq(javafx.event.ActionEvent event) Handles sample-rate combo box changes — sends the appropriate rate command to the hardware.private voiddrawAll(SignalData data) Draws the time-domain and (optionally) FFT canvases for the given data.(package private) voidFFTVisualization(javafx.event.ActionEvent event) Toggles the FFT spectrum panel visibility based on the FFT checkbox state.(package private) voidhandleConnect(javafx.event.ActionEvent event) Handles the “Connect” button press — attempts to connect to the serial port selected inportComboBox.(package private) voidhandleStart(javafx.event.ActionEvent event) Handles the Start/Stop toggle button — starts or stops data acquisition and updates the button label accordingly.private voidhookCanvasToPane(javafx.scene.canvas.Canvas canvas, javafx.scene.layout.Pane container) Binds aCanvassize to its parentPaneso the canvas resizes automatically when the window layout changes.voidFXML initialisation hook — called automatically after all @FXML fields have been injected.private voidonConnectionChange(ConnectionStatus status) API connection-state callback — updates the status label colour and text.private voidAPI error callback — displays the error message in the status label.private voidonSignalData(SignalData data) API data callback — stores the latest signal data for the next render frame unless the display is frozen.private voidRenders a single frame — invoked from theAnimationTimer.voidshutdown()Shuts down the render loop and the backend API.private voidCreates and starts theAnimationTimerthat drives the render loop at approximately 30 FPS.private voidupdateLabels(SignalData data) Refreshes the on-screen statistics labels (Vmax, Vmin, RMS, f0) from the given signal data.private voidupdateTriggerSliderRange(double vMin, double vMax) Updates the trigger-level slider's min/max to match the current autoscaled voltage range.
-
Field Details
-
api
-
timeRenderer
-
fftRenderer
-
autoscaler
-
voltageMin
private double voltageMin -
voltageMax
private double voltageMax -
magnitudeMax
private double magnitudeMax -
lastSignalData
-
newDataAvailable
private volatile boolean newDataAvailable -
isRunning
private boolean isRunning -
needsRedraw
private boolean needsRedraw -
cursorX
private double cursorX -
cursorY
private double cursorY -
cursorActive
private boolean cursorActive -
animationTimer
private javafx.animation.AnimationTimer animationTimer -
lastFrameTime
private long lastFrameTime -
FRAME_INTERVAL
private static final long FRAME_INTERVAL- See Also:
-
oscilloscopeCanvas
private javafx.scene.canvas.Canvas oscilloscopeCanvas -
fftCanvas
private javafx.scene.canvas.Canvas fftCanvas -
timeContainer
private javafx.scene.layout.Pane timeContainer -
fftContainer
private javafx.scene.layout.Pane fftContainer -
timeSection
private javafx.scene.layout.VBox timeSection -
fftSection
private javafx.scene.layout.VBox fftSection -
plotArea
private javafx.scene.layout.VBox plotArea -
timeZoomX
private javafx.scene.control.Slider timeZoomX -
timeZoomY
private javafx.scene.control.Slider timeZoomY -
fftZoomX
private javafx.scene.control.Slider fftZoomX -
fftZoomY
private javafx.scene.control.Slider fftZoomY -
timeZoomXLabel
private javafx.scene.control.Label timeZoomXLabel -
timeZoomYLabel
private javafx.scene.control.Label timeZoomYLabel -
fftZoomXLabel
private javafx.scene.control.Label fftZoomXLabel -
fftZoomYLabel
private javafx.scene.control.Label fftZoomYLabel -
portComboBox
-
samplingFreq
-
connectButton
private javafx.scene.control.Button connectButton -
connectionStatus
private javafx.scene.control.Label connectionStatus -
toggleButtonStart
private javafx.scene.control.ToggleButton toggleButtonStart -
Vrms
private javafx.scene.control.Label Vrms -
Vmax
private javafx.scene.control.Label Vmax -
Vmin
private javafx.scene.control.Label Vmin -
dominantFreqLabel
private javafx.scene.control.Label dominantFreqLabel -
FFTCheck
private javafx.scene.control.CheckBox FFTCheck -
FreezeCheck
private javafx.scene.control.CheckBox FreezeCheck -
autoCheck
private javafx.scene.control.CheckBox autoCheck -
gridCheck
private javafx.scene.control.CheckBox gridCheck -
triggerCheck
private javafx.scene.control.CheckBox triggerCheck -
triggerLevel
private javafx.scene.control.Slider triggerLevel -
triggerLevelLabel
private javafx.scene.control.Label triggerLevelLabel -
triggerStatusLabel
private javafx.scene.control.Label triggerStatusLabel -
triggerRangeInitialized
private boolean triggerRangeInitializedWhether the trigger slider range has been initialised from autoscale data.
-
-
Constructor Details
-
MainController
public MainController()
-
-
Method Details
-
initialize
public void initialize()FXML initialisation hook — called automatically after all @FXML fields have been injected.Wires canvas resize listeners, zoom/trigger slider listeners, populates the port and sample-rate combo boxes, registers API callbacks, and starts the render loop.
-
hookCanvasToPane
private void hookCanvasToPane(javafx.scene.canvas.Canvas canvas, javafx.scene.layout.Pane container) Binds aCanvassize to its parentPaneso the canvas resizes automatically when the window layout changes.- Parameters:
canvas- the canvas to resizecontainer- the parent pane whose dimensions drive the canvas size
-
handleConnect
void handleConnect(javafx.event.ActionEvent event) Handles the “Connect” button press — attempts to connect to the serial port selected inportComboBox.- Parameters:
event- the originating action event
-
handleStart
void handleStart(javafx.event.ActionEvent event) Handles the Start/Stop toggle button — starts or stops data acquisition and updates the button label accordingly.- Parameters:
event- the originating action event
-
changeSamplingFreq
void changeSamplingFreq(javafx.event.ActionEvent event) Handles sample-rate combo box changes — sends the appropriate rate command to the hardware.- Parameters:
event- the originating action event
-
FFTVisualization
void FFTVisualization(javafx.event.ActionEvent event) Toggles the FFT spectrum panel visibility based on the FFT checkbox state.- Parameters:
event- the originating action event
-
autoscaling
void autoscaling()Recomputes voltage and magnitude ranges from the current signal data when the autoscale checkbox is selected. -
onSignalData
API data callback — stores the latest signal data for the next render frame unless the display is frozen.- Parameters:
data- the new signal data received from the backend
-
onError
API error callback — displays the error message in the status label.- Parameters:
message- the error description
-
onConnectionChange
API connection-state callback — updates the status label colour and text.- Parameters:
status- the new connection status
-
startRenderLoop
private void startRenderLoop()Creates and starts theAnimationTimerthat drives the render loop at approximately 30 FPS. -
renderFrame
private void renderFrame()Renders a single frame — invoked from theAnimationTimer.Handles empty-canvas drawing, frozen/stopped states, autoscaling, label updates, and delegates to
drawAll(SignalData). -
drawAll
Draws the time-domain and (optionally) FFT canvases for the given data.Applies zoom, trigger detection, window slicing, and delegates to
TimeDomainRenandFFTDomainRen.- Parameters:
data- the signal data to render
-
updateTriggerSliderRange
private void updateTriggerSliderRange(double vMin, double vMax) Updates the trigger-level slider's min/max to match the current autoscaled voltage range.- Parameters:
vMin- the current minimum voltagevMax- the current maximum voltage
-
updateLabels
Refreshes the on-screen statistics labels (Vmax, Vmin, RMS, f0) from the given signal data.- Parameters:
data- the signal data whose statistics to display
-
shutdown
public void shutdown()Shuts down the render loop and the backend API. Called fromApp.stop()during application exit.
-