Skip to content

Enhance setup documentation and refine idle mode functionality#257

Merged
Isaia26633 merged 6 commits into
mainfrom
DEV
May 15, 2026
Merged

Enhance setup documentation and refine idle mode functionality#257
Isaia26633 merged 6 commits into
mainfrom
DEV

Conversation

@Isaia26633

Copy link
Copy Markdown
Collaborator

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:

  • Added an idleTimeoutSeconds configuration to .env-template and formPixSim/.env-template to control how long the system waits with no API or Formbar socket activity before triggering idle bar animations. [1] [2]
  • Introduced middleware (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 both app.js and formPixSim/app.js. [1] [2] [3] [4] [5] [6] [7] [8]

Rave HSV→RGB refactor:

  • Removed the custom HSV-to-RGB conversion logic, lookup tables, and caching from controllers/raveControllers.js and replaced it with a shared hsvToRgb function imported from utils/hsv.js. This simplifies the code and centralizes color conversion logic. [1] [2] [3] [4]

Documentation cleanup:

  • Deleted documentaion/perf-github-issues.md, which contained now-obsolete performance and architecture issue tracking.

Idle timeout/activity detection

  • Added idleTimeoutSeconds environment variable to .env-template and formPixSim/.env-template to control idle animation timing. [1] [2]
  • Added recordApiActivity middleware and idle mode utilities to both app.js and formPixSim/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

  • Removed custom HSV-to-RGB conversion, lookup tables, and caching from controllers/raveControllers.js, now using a shared hsvToRgb from utils/hsv.js for all rave color calculations. [1] [2] [3] [4]

Documentation cleanup

  • Deleted documentaion/perf-github-issues.md as it is no longer needed.

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
Copilot AI review requested due to automatic review settings May 15, 2026 14:13
@Isaia26633 Isaia26633 merged commit 0c44a32 into main May 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 /api middleware 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 thread utils/idleMode.js
Comment on lines +124 to +128
* HTTP /api response finished: start a fresh idle countdown from now.
*/
function onHttpApiActivityEnd() {
scheduleNextIdleDeadline();
}
Comment thread utils/idleMode.js
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 thread utils/hsv.js
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 thread formPixSim/utils/hsv.js
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;
}
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.

2 participants