Skip to content

MoonLiveService

Source: MoonLiveService.h

MoonLiveService

class MoonLiveService
src/core/MoonLiveService.h:40

Inherits: MoonModule

A scripted SERVICE: the input twin of MoonLiveEffect, and the flexible half of this device's input story.

Why a script and not another module.ButtonService and InfraredService are lists of mappings, which is the right shape for "this pin drives that control" and the wrong one for anything with a condition in it. A list row cannot say "when the distance drops under 50 cm", cannot hold the edge state that stops it firing every tick, and cannot decide between two presets. A script can, and it is how a sensor nobody wrote a module for gets supported: with a datasheet and eight lines, rather than a firmware release.

The same relationship effects already have. A compiled effect and a scripted one are interchangeable; so are a compiled input service and a scripted one. ButtonService is the fast, shipped path for the buttons a board is built with, and this is the path for everything else. The engine is identical, so a script author already knows the language.

It runs on tick20ms, not on the render tick. A contact closes for tens of milliseconds and a sensor answers at its own rate, so the render rate would sample either thousands of times a second to learn the same thing. It also means a heavy script costs its own tick rather than stuttering the lights at the frame rate.

What it can reach.gpioRead / gpioWrite for the hardware, and setControl for the output, which writes the CONTROL SURFACE and nothing else. That is the same two-step model the mapping rows use: a script drives the surface, the surface drives everything. One path to a driver rather than two, and a script cannot rewrite a driver's pin list by naming it.

Not auto-wired. Factory-registered like the other services: added under Services, then pointed at a .mls file.

MoonLiveService card

Public Methods

virtual inline ModuleRole role() const override : Role for type identification (no RTTI needed).

virtual inline void defineControls() override : defineControls MUST be idempotent and pure: only controls_.clear() + controls_.addX().

virtual inline bool affectsPrepare(const char * controlName) const override : Naming a different script recompiles; a scripted control's value change must NOT, because it only updates an arena byte the running code reads next tick.

virtual inline void prepare() override : Tier-3 of the control-change split (see onControlChanged above): the module (re)allocates / recomputes whatever derived state it owns — an effect's heap, a Layer's mapping LUT, the Drivers output buffer.

virtual inline void tick20ms() override : The service moment: 50 Hz, where a press and a sensor reading both live.

virtual inline void release() override

inline void setScript(const char * name) : Point the module at a script.