Enhance setup documentation and refine idle mode functionality#257
Merged
Conversation
Updating Dev from Main
added new setup doc
Add idleTimeoutSeconds (preferred) to env templates and parsing logic, with fallback to idleTimeoutMs; warn on sub-second configs. Centralize idle deadline and animation handles on shared state (idleDeadlineTimer, idleAnimationInterval, idleAnimContext) to avoid stale timers. Change idleMode to expose onHttpApiActivityStart/onHttpApiActivityEnd, stop competing animations, and prevent duplicate socket handlers. Update recordApiActivity middleware to run earlier / be mounted under /api, detect requests via originalUrl, and hook into res.finish/close so the idle countdown restarts only after responses complete.
Enhance idle mode with timers, API hooks, and configuration updates
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds an idle-mode system that triggers an LED “idle” animation after a period of no HTTP /api or Formbar Socket.IO activity, and centralizes HSV→RGB conversion into a shared utility used by rave/idle animations. It also removes now-obsolete performance/architecture tracking documentation.
Changes:
- Added idle timeout configuration (
idleTimeoutSeconds) and state bookkeeping for idle timers/animation context. - Introduced idle activity tracking via new
/apimiddleware and Socket.IO “any event” activity bumping, plus a new idle bar animation loop. - Refactored rave HSV→RGB conversion to use a shared
utils/hsv.js(and removed old doc files).
Reviewed changes
Copilot reviewed 18 out of 19 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
utils/idleMode.js |
New idle animation + idle deadline scheduling + activity bump/reset logic. |
middleware/recordApiActivity.js |
New middleware to bump/reset idle timer on /api traffic. |
state.js |
Adds idle timeout parsing + idle timers/animation context fields on state/config. |
utils/hsv.js |
Shared HSV→RGB conversion (used by rave + idle). |
controllers/raveControllers.js |
Replaces local HSV→RGB implementation with shared utils/hsv. |
app.js |
Wires idle tracking middleware early + initializes idle mode + hooks socket activity bumping. |
.env-template |
Adds idleTimeoutSeconds documentation/default. |
documentaion/perf-github-issues.md |
Deleted obsolete performance issue-tracking doc. |
documentaion/inefficiencies.md |
Deleted obsolete inefficiency audit doc. |
formPixSim/utils/idleMode.js |
Simulator mirror of idle mode implementation. |
formPixSim/middleware/recordApiActivity.js |
Simulator mirror of /api activity middleware. |
formPixSim/state.js |
Simulator mirror of idle timeout parsing + state fields. |
formPixSim/utils/hsv.js |
Simulator mirror of shared HSV→RGB utility. |
formPixSim/controllers/raveControllers.js |
Simulator rave controller updated to use shared HSV→RGB utility. |
formPixSim/app.js |
Simulator wiring for idle init + /api activity middleware + socket activity bumping. |
formPixSim/.env-template |
Simulator env template updated with idleTimeoutSeconds. |
formPixSim/documentaion/perf-github-issues.md |
Deleted simulator obsolete performance doc. |
formPixSim/documentaion/inefficiencies.md |
Deleted simulator obsolete inefficiency doc. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+124
to
+128
| * HTTP /api response finished: start a fresh idle countdown from now. | ||
| */ | ||
| function onHttpApiActivityEnd() { | ||
| scheduleNextIdleDeadline(); | ||
| } |
Comment on lines
+88
to
+90
| if (progressModule.currentProgressInterval) { | ||
| clearInterval(progressModule.currentProgressInterval); | ||
| progressModule.currentProgressInterval = null; |
Comment on lines
+112
to
+127
| * The deadline is started again in {@link onHttpApiActivityEnd} when the response finishes. | ||
| */ | ||
| function onHttpApiActivityStart() { | ||
| const state = require('../state'); | ||
| if (state.idleDeadlineTimer) { | ||
| clearTimeout(state.idleDeadlineTimer); | ||
| state.idleDeadlineTimer = null; | ||
| } | ||
| exitIdleIfActive(); | ||
| } | ||
|
|
||
| /** | ||
| * HTTP /api response finished: start a fresh idle countdown from now. | ||
| */ | ||
| function onHttpApiActivityEnd() { | ||
| scheduleNextIdleDeadline(); |
Comment on lines
+88
to
+90
| if (progressModule.currentProgressInterval) { | ||
| clearInterval(progressModule.currentProgressInterval); | ||
| progressModule.currentProgressInterval = null; |
Comment on lines
+11
to
+30
| function hsvToRgbInternal(h, s, v) { | ||
| const c = v * s; | ||
| const x = c * (1 - Math.abs(((h / 60) % 2) - 1)); | ||
| const m = v - c; | ||
|
|
||
| let r = 0; let g = 0; let b = 0; | ||
|
|
||
| if (h >= 0 && h < 60) { | ||
| r = c; g = x; b = 0; | ||
| } else if (h >= 60 && h < 120) { | ||
| r = x; g = c; b = 0; | ||
| } else if (h >= 120 && h < 180) { | ||
| r = 0; g = c; b = x; | ||
| } else if (h >= 180 && h < 240) { | ||
| r = 0; g = x; b = c; | ||
| } else if (h >= 240 && h < 300) { | ||
| r = x; g = 0; b = c; | ||
| } else if (h >= 300 && h < 360) { | ||
| r = c; g = 0; b = x; | ||
| } |
Comment on lines
+11
to
+30
| function hsvToRgbInternal(h, s, v) { | ||
| const c = v * s; | ||
| const x = c * (1 - Math.abs(((h / 60) % 2) - 1)); | ||
| const m = v - c; | ||
|
|
||
| let r = 0; let g = 0; let b = 0; | ||
|
|
||
| if (h >= 0 && h < 60) { | ||
| r = c; g = x; b = 0; | ||
| } else if (h >= 60 && h < 120) { | ||
| r = x; g = c; b = 0; | ||
| } else if (h >= 120 && h < 180) { | ||
| r = 0; g = c; b = x; | ||
| } else if (h >= 180 && h < 240) { | ||
| r = 0; g = x; b = c; | ||
| } else if (h >= 240 && h < 300) { | ||
| r = x; g = 0; b = c; | ||
| } else if (h >= 300 && h < 360) { | ||
| r = c; g = 0; b = x; | ||
| } |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces two main sets of changes: (1) the addition of an idle timeout/idle animation system based on API and socket activity, and (2) a significant refactor of the HSV-to-RGB color conversion logic for rave animations. Additionally, it removes an old performance/architecture issues documentation file that is now obsolete.
Idle timeout and activity tracking:
idleTimeoutSecondsconfiguration to.env-templateandformPixSim/.env-templateto control how long the system waits with no API or Formbar socket activity before triggering idle bar animations. [1] [2]recordApiActivity) and utility functions (initIdleMode,registerFormbarSocketIdleReset) to monitor API and socket activity, resetting the idle timer as needed. These are initialized early in the middleware stack and on socket connection in bothapp.jsandformPixSim/app.js. [1] [2] [3] [4] [5] [6] [7] [8]Rave HSV→RGB refactor:
controllers/raveControllers.jsand replaced it with a sharedhsvToRgbfunction imported fromutils/hsv.js. This simplifies the code and centralizes color conversion logic. [1] [2] [3] [4]Documentation cleanup:
documentaion/perf-github-issues.md, which contained now-obsolete performance and architecture issue tracking.Idle timeout/activity detection
idleTimeoutSecondsenvironment variable to.env-templateandformPixSim/.env-templateto control idle animation timing. [1] [2]recordApiActivitymiddleware and idle mode utilities to bothapp.jsandformPixSim/app.js, ensuring idle reset is triggered by both API and Formbar socket activity. [1] [2] [3] [4] [5] [6] [7] [8]Rave HSV→RGB logic refactor
controllers/raveControllers.js, now using a sharedhsvToRgbfromutils/hsv.jsfor all rave color calculations. [1] [2] [3] [4]Documentation cleanup
documentaion/perf-github-issues.mdas it is no longer needed.