Skip to content

[DO NOT MERGE] kurt/helios-RAII-wasm#151

Open
livingkurt wants to merge 38 commits intomasterfrom
feature/helios-instance
Open

[DO NOT MERGE] kurt/helios-RAII-wasm#151
livingkurt wants to merge 38 commits intomasterfrom
feature/helios-instance

Conversation

@livingkurt
Copy link
Copy Markdown
Collaborator

This PR adds the HeliosInstance class to enable multiple independent WASM engine instances on the same page.

Changes

  • HeliosInstance.h/cpp: New class with per-instance pattern/colorset/state (not static/global)
  • HeliosLib.cpp: WASM bindings for HeliosInstance class
  • Makefile: Include new source files

Why

The current Helios class uses all static members, making it impossible to have multiple independent mode previews on the same page (like a grid of mode cards). Each preview would share the same pattern/colorset state.

Usage

const lib = await HeliosLib();
const instance1 = new lib.HeliosInstance();
const instance2 = new lib.HeliosInstance();
instance1.init();
instance2.init();
// Each instance has independent pattern/colorset/tick

This enables the Glow-LEDs mode grid to show live previews for all modes simultaneously.

Herc added 2 commits February 20, 2026 17:26
- Remove Helios.h include from HeliosInstance.h (circular include)
- Fix getCurColor() to not be const (accesses static Led)
- Remove cur_pattern from WASM bindings (caused embind template errors)
- Keep only needed methods: init, tick, getCurColor, setColorset, setArgs, setMode
@livingkurt livingkurt force-pushed the feature/helios-instance branch from 47e3e00 to 80f27a1 Compare February 20, 2026 17:53
Herc and others added 6 commits February 20, 2026 17:57
- Add static create() method to HeliosInstance
- Export createHeliosInstance() function from WASM
- Update JS to use factory function instead of constructor
- Include TimeControl.h to manage timing for patterns.
- Call Time::tickClock() in the tick() method to ensure pattern timers function correctly.
@livingkurt livingkurt changed the title Add HeliosInstance class for multiple independent engine instances kurt/helos-instance Feb 20, 2026
Convert Helios controller and core services (pattern runtime, storage, LED, time, and button) to instance-owned state, preserve ISR bridge compatibility, and isolate WASM bindings/build to instance-only APIs.
Introduce HeliosCallbacks and wire button, LED, time, and storage hookpoints through Helios/HeliosLib, with WASM-exposed callback registration APIs for event-driven host integration.
Allow NUM_COLOR_SLOTS override from config and set a safe WASM slot cap so randomizer can vary from 1..N without being hard-limited to 6.
@livingkurt livingkurt changed the title kurt/helos-instance [DO NOT MERGE] kurt/helios-RAII-wasm Feb 22, 2026
…ntime API.

This updates Helios core ownership wiring to use Helios-scoped dependencies, removes legacy static runtime bridges, and consolidates WASM preview/randomizer behavior onto HeliosLib while preserving existing frontend behavior.
This removes remaining non-conforming helper/globals and inheritance layers, deletes obsolete HeliosInstance/HeliosPattern* files, and keeps engine/runtime access consistently instance-based through Helios references.
…te LED color setting to only occur when the color is marked as dirty, improving efficiency. Initialize and reset color dirty state in Pattern class.
Comment thread Helios/Button.cpp Outdated
Comment thread Helios/Button.cpp Outdated
#ifdef HELIOS_EMBEDDED
#ifdef HELIOS_ARDUINO
return digitalRead(3) == HIGH;
defaultState = digitalRead(3) == HIGH;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is changing the code, dont change the code.

Do not create new variables or logic.

This should work exactly the same as it did before.

Adding the ifdef to call the callback a few lines down is correct, but adding defaultState is not, get rid of it.

Comment thread Helios/Button.cpp Outdated
return m_pinState;
defaultState = m_pinState;
#endif
return m_helios.callbacks().checkPinHook(BUTTON_PIN, defaultState);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This should be inside a ifdef helios_lib it only builds on desktop.

The whole callbacks thing should all be inside ifdef helios lib. Callbacks dont exist if you built this branch for embedded

Comment thread Helios/Button.cpp
Comment thread Helios/Button.cpp Outdated
Comment thread Helios/Button.h Outdated
Comment thread Helios/Button.h Outdated
#include <queue>
#endif

class Time;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Forward decls should not be necessary, delete.

If they are necessary its because something is done wrong.

Shouldn't have references to time or whatever here in the header, and where they are used in the cpp file the appropriate header would just be included.

So ya delete these forward decls

Comment thread Helios/Button.h
Comment thread Helios/HeliosConfig.h
// The number of slots in a colorset
// The number of slots in a colorset.
// Firmware default remains 6, but WASM can override via compiler define.
#ifndef NUM_COLOR_SLOTS
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Smart

Comment thread Helios/Led.cpp

#include "Led.h"

#include "TimeControl.h"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Your still using m_helios.time()

You still should include this, the only reason it works without this include is because another header indirectly included it.

Restore this, unnecessary deletion

livingkurt and others added 2 commits February 27, 2026 21:34
…d duration calculations. Introduce external Helios reference in ISR for wakeup functionality. Update Button header guard for consistency.
@Unreal-Dan Unreal-Dan force-pushed the feature/helios-instance branch from 893f278 to 1836cf5 Compare March 3, 2026 08:57
Unreal-Dan and others added 11 commits March 4, 2026 23:40
…M build

- Add fade_dur param to PatternArgs (Pattern.h/cpp)
- Add isFade() method and tickFade() logic to Pattern
- Add PATTERN_FADE, PATTERN_MORPH_FADE, PATTERN_GLITCH_FADE to Patterns.h/cpp
- Update HeliosLib WASM bindings for new fade_dur param and pattern IDs
- Fix pre-existing WASM build errors: Pattern pointer initialization with
  Helios ref, checkPinHook signature mismatch, missing restart/tick/getCurColor

Made-with: Cursor
tickClock() busy-waits up to 1ms per tick to enforce TICKRATE=1000.
When multiple WASM engines run in parallel (fingerroll/multi-light preview),
this blocks the browser main thread causing severe lag. JS rAF controls
timing for WASM, so the timestep serves no purpose and must be disabled.

Made-with: Cursor
Backport cleanup from master (#152): replace #pragma once in Button.h
and add missing include guard to Helios.h with standard #ifndef guards.
This reduces the diff against master for the RAII PR review.

Made-with: Cursor
Comment thread HeliosCLI/Makefile
# generic clean target
clean:
@$(RM) $(DFILES) $(OBJS) $(TARGETS) $(TESTS)
@$(RM) ../Helios/*.o ../Helios/*.d ../Helios/*.avr.o ../Helios/*.avr.d
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

do we want this in main/helios/aeos?

Comment thread HeliosEmbedded/Makefile

clean:
rm -f $(OBJS) $(TARGET).elf $(TARGET).hex $(DFILES) $(TARGET).bin $(TARGET).eep $(TARGET).lst $(TARGET).map
rm -f ../Helios/*.o ../Helios/*.d ../Helios/*.avr.o ../Helios/*.avr.d
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same here, do we want this in main/helios/aeos?

Comment thread HeliosLib/Makefile Outdated

ifdef WASM
DEFINES += -D WASM
DEFINES += -D NUM_COLOR_SLOTS=80
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

what the heck is NUM_COLOR_SLOTS for O.o

Comment thread HeliosLib/Makefile
# generic clean target
clean:
@$(RM) $(DFILES) $(OBJS) $(TARGETS) $(TESTS) HeliosLib.js HeliosLib.wasm
@$(RM) ../Helios/*.o ../Helios/*.d ../Helios/*.avr.o ../Helios/*.avr.d
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same here, do we want this in main?

- Fix Pattern::crc32() to hash only m_args and m_colorset directly,
  skipping the m_helios reference (a pointer with non-deterministic
  address that made the randomizer seed change each run)
- Restore helios.wakeup() in HELIOS_EMBEDDED ISR(PCINT0_vect) using
  the global Helios instance per Daniel's review feedback
- Re-record 22 integration tests whose golden output changed due to
  the new PATTERN_FADE/MORPH_FADE/GLITCH_FADE pattern IDs shifting
  the PATTERN_COUNT used by the randomizer

Made-with: Cursor
- Add comment to HeliosLib/Makefile explaining NUM_COLOR_SLOTS=80:
  overrides the embedded default of 6 so the WASM web editor supports
  up to 80 colors per mode (no flash constraints in browser)
- Remove stale comment "this was used before..." from HeliosLib/Makefile
  (LDFLAGS line is still needed)
- Add comments to all three clean targets noting they are candidates
  to backport to master/aeos (intentional full-repo clean behavior)

Made-with: Cursor
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