Skip to content

Flush LED switch-off synchronously during application exit and OS shutdown (#206) - #666

Open
psieg wants to merge 2 commits into
masterfrom
fix/206-shutdown-flush-leds
Open

psieg wants to merge 2 commits into
masterfrom
fix/206-shutdown-flush-leds

Conversation

@psieg

@psieg psieg commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Fixes #206

Problem

During manual exit and OS shutdown/session termination, LEDs could remain lit because:

  1. SettingsWindow::quit(), LightpackApplication::onSessionChange(SystemSession::Status::Ending), and commitData() posted switchOffLeds() asynchronously via Qt::QueuedConnection and called QApplication::processEvents(), which returns immediately on the main thread without waiting for m_ledDeviceManagerThread or m_ledDeviceThread to finish writing the off frame.
  2. onSessionChange(Ending) and commitData() did not stop GrabManager, MoodLampManager, and SoundManager before shutting off LEDs, allowing color frames to keep racing into the queue.
  3. LightpackApplication::commitData(QSessionManager &) was still declared as a Qt 4 virtual override rather than connected to QGuiApplication::commitDataRequest.
  4. LedDeviceAdalight::switchOffLeds() and LedDeviceArdulight::switchOffLeds() called writeBuffer(m_writeBuffer) with force = false (which could skip the turn-off frame when bytesToWrite() > 0) and returned before draining the serial port buffer via waitForBytesWritten().

Changes

  • LedDeviceManager: Added Q_INVOKABLE void switchOffLedsSync(int timeoutMs = 1000) which sets Backlight::StatusOff, drops queued SetColors, enqueues/sends OffLeds, and runs a bounded local QEventLoop until OffLeds completes or command state resets/times out.
  • LedDeviceAdalight / LedDeviceArdulight: Forced writing the off frame in switchOffLeds() (writeBuffer(m_writeBuffer, true)) and flushed bytesToWrite() via waitForBytesWritten() within a 250 ms budget before acknowledging completion.
  • LightpackApplication / SettingsWindow: Added LightpackApplication::prepareForShutdown() to stop frame generators (GrabManager, MoodLampManager, SoundManagerBase) and invoke LedDeviceManager::switchOffLedsSync(1000) via Qt::BlockingQueuedConnection when isKeepLightsOnAfterExit() is false; connected QGuiApplication::commitDataRequest to commitData(); routed onSessionChange(Ending), commitData(), SettingsWindow::quit(), trayless closeEvent(), and quitForWizard through prepareForShutdown().
  • Tests (LedDeviceManagerTest): Added testSwitchOffLedsSyncFlushesWithInFlightSetColors and testSwitchOffLedsSyncBoundedTimeoutWhenStalled, plus closed-port switchOffLeds() ack checks on LedDeviceAdalight and LedDeviceArdulight.

Verification

  • Built Prismatik and LightpackTests with qmake6 -r && make -j2.
  • Ran QT_QPA_PLATFORM=offscreen ./bin/LightpackTests — all 8 test suites passed (0 failed).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LEDs stay on when shutting down the PC

1 participant