Skip to content

Commit

Permalink
Closes #162
Browse files Browse the repository at this point in the history
  • Loading branch information
sblantipodi committed Dec 9, 2023
1 parent dd0fb9f commit 993bb56
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/main/java/org/dpsoftware/managers/NetworkManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import javafx.application.Platform;
import javafx.scene.control.Alert;
import lombok.extern.slf4j.Slf4j;
import org.dpsoftware.LEDCoordinate;
Expand Down Expand Up @@ -489,13 +488,7 @@ private void manageAspectRatio(MqttMessage message) {
* @param message mqtt message
*/
private void manageSmoothing(MqttMessage message) {
if (MainSingleton.getInstance().RUNNING) {
Platform.runLater(() -> {
MainSingleton.getInstance().config.setFrameInsertion(LocalizedEnum.fromBaseStr(Enums.FrameInsertion.class, message.toString()).getBaseI18n());
MainSingleton.getInstance().guiManager.stopCapturingThreads(MainSingleton.getInstance().RUNNING);
CommonUtility.delaySeconds(() -> MainSingleton.getInstance().guiManager.startCapturingThreads(), 4);
});
}
PipelineManager.restartCapture(() -> MainSingleton.getInstance().config.setFrameInsertion(LocalizedEnum.fromBaseStr(Enums.FrameInsertion.class, message.toString()).getBaseI18n()));
}

/**
Expand Down Expand Up @@ -640,6 +633,7 @@ public void connectionLost(Throwable cause) {
subscribeToTopics();
connected = true;
log.info(Constants.MQTT_RECONNECTED);
PipelineManager.restartCapture(() -> log.info("Restarting upon disconnection."));
} catch (MqttException e) {
log.error(Constants.MQTT_DISCONNECTED);
}
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/org/dpsoftware/managers/PipelineManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
package org.dpsoftware.managers;

import javafx.application.Platform;
import javafx.scene.control.Alert;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -461,4 +462,20 @@ public void stopCapturePipeline() {
AudioSingleton.getInstance().AUDIO_BRIGHTNESS = 255;
MainSingleton.getInstance().config.setEffect(Enums.Effect.SOLID.getBaseI18n());
}

/**
* Callback used to restart the capture pipeline. It acceps a method as input.
*
* @param command callback to execute during the restart process
*/
public static void restartCapture(Runnable command) {
if (MainSingleton.getInstance().RUNNING) {
Platform.runLater(() -> {
command.run();
MainSingleton.getInstance().guiManager.stopCapturingThreads(MainSingleton.getInstance().RUNNING);
CommonUtility.delaySeconds(() -> MainSingleton.getInstance().guiManager.startCapturingThreads(), 4);
});
}
}

}

0 comments on commit 993bb56

Please sign in to comment.