Skip to content

Commit

Permalink
Wayland screen still fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sblantipodi committed Nov 20, 2023
1 parent 613b883 commit 84e4ed2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
27 changes: 21 additions & 6 deletions src/main/java/org/dpsoftware/FireflyLuciferin.java
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ private void connectToMqttServer() {
*
* @param stage main stage
*/
@SuppressWarnings("unused")
@SuppressWarnings("all")
private void scheduleBackgroundTasks(Stage stage) {
// Create a task that runs every 5 seconds, reconnect serial devices when needed
ScheduledExecutorService serialscheduledExecutorService = Executors.newScheduledThreadPool(1);
Expand All @@ -348,6 +348,19 @@ private void scheduleBackgroundTasks(Stage stage) {
}
};
serialscheduledExecutorService.scheduleAtFixedRate(framerateTask, 0, 5, TimeUnit.SECONDS);
// Wayland only, create a task that pings Glow Worm device every 2 seconds, this is needed because wayland stops sending
// updates to the device when the image on the screen is still.
if (NativeExecutor.isWayland()) {
ScheduledExecutorService waylandScheduledExecutorService = Executors.newScheduledThreadPool(1);
Runnable waylandTask = () -> {
if (MainSingleton.getInstance().RUNNING && MainSingleton.getInstance().FPS_PRODUCER == 0
&& MainSingleton.getInstance().lastLedColor != null && MainSingleton.getInstance().lastLedColor.length > 0) {
Collections.reverse(Arrays.asList(MainSingleton.getInstance().lastLedColor));
MainSingleton.getInstance().sharedQueue.offer(MainSingleton.getInstance().lastLedColor);
}
};
waylandScheduledExecutorService.scheduleAtFixedRate(waylandTask, 0, 200, TimeUnit.MILLISECONDS);
}
NativeExecutor.addShutdownHook();
if (!MainSingleton.getInstance().config.isMultiScreenSingleDevice() || CommonUtility.isSingleDeviceMainInstance()) {
powerSavingManager.addPowerSavingTask();
Expand Down Expand Up @@ -543,15 +556,17 @@ int sendChunck(int i, Color[] leds, int chunkNumber) {
*/
@SuppressWarnings("InfiniteLoopStatement")
void consume() throws InterruptedException, IOException {
boolean isWayland = NativeExecutor.isWayland();
while (true) {
Color[] num = MainSingleton.getInstance().sharedQueue.take();
Color[] colorArray = MainSingleton.getInstance().sharedQueue.take();
if (isWayland) MainSingleton.getInstance().lastLedColor = colorArray;
if (MainSingleton.getInstance().RUNNING) {
if (CommonUtility.isSingleDeviceMultiScreen()) {
if (num.length == NetworkSingleton.getInstance().totalLedNum) {
sendColors(num);
if (colorArray.length == NetworkSingleton.getInstance().totalLedNum) {
sendColors(colorArray);
}
} else if (num.length == MainSingleton.getInstance().ledNumber) {
sendColors(num);
} else if (colorArray.length == MainSingleton.getInstance().ledNumber) {
sendColors(colorArray);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/dpsoftware/MainSingleton.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class MainSingleton {
public boolean RUNNING = false;
// This queue orders elements FIFO. Producer offers some data, consumer throws data to the Serial port
public BlockingQueue<Color[]> sharedQueue;
public Color[] lastLedColor;
// Number of LEDs on the strip
public int ledNumber;
public int ledNumHighLowCount;
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/org/dpsoftware/grabber/GrabberManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,24 +260,29 @@ private static int getSuggestedFramerate() {
* @param notified don't alert user more than one time
*/
private void runBenchmark(AtomicInteger framerateAlert, AtomicBoolean notified) {
int benchIteration = Constants.NUMBER_OF_BENCHMARK_ITERATION;
// Wayland has a more swinging frame rate due to the fact that it doesn't capture an image if frame is still, give it some more room for error.
if (NativeExecutor.isWayland()) {
benchIteration = Constants.NUMBER_OF_BENCHMARK_ITERATION * 4;
}
if (!notified.get()) {
if ((MainSingleton.getInstance().FPS_PRODUCER > 0) && (framerateAlert.get() < Constants.NUMBER_OF_BENCHMARK_ITERATION)
if ((MainSingleton.getInstance().FPS_PRODUCER > 0) && (framerateAlert.get() < benchIteration)
&& (MainSingleton.getInstance().FPS_GW_CONSUMER < MainSingleton.getInstance().FPS_PRODUCER - Constants.BENCHMARK_ERROR_MARGIN)) {
framerateAlert.getAndIncrement();
} else {
framerateAlert.set(0);
}
int iterationNumber;
if (MainSingleton.getInstance().config.isMultiScreenSingleDevice()) {
iterationNumber = Constants.NUMBER_OF_BENCHMARK_ITERATION;
iterationNumber = benchIteration;
} else {
iterationNumber = Constants.NUMBER_OF_BENCHMARK_ITERATION / 2;
iterationNumber = benchIteration / 2;
}
if (MainSingleton.getInstance().FPS_GW_CONSUMER == 0 && framerateAlert.get() == iterationNumber && MainSingleton.getInstance().config.isFullFirmware()) {
log.info("Glow Worm Luciferin is not responding, restarting...");
NativeExecutor.restartNativeInstance();
}
if (framerateAlert.get() == Constants.NUMBER_OF_BENCHMARK_ITERATION && !notified.get() && MainSingleton.getInstance().FPS_GW_CONSUMER > 0) {
if (framerateAlert.get() == benchIteration && !notified.get() && MainSingleton.getInstance().FPS_GW_CONSUMER > 0) {
notified.set(true);
javafx.application.Platform.runLater(() -> {
int suggestedFramerate = getSuggestedFramerate();
Expand Down

0 comments on commit 84e4ed2

Please sign in to comment.