DriverBase
Source:
DriverBase.h
DriverBase¶
src/light/drivers/DriverBase.h:40Inherits:
MoonModule
Base class for one driver — a consumer that reads the shared source buffer and emits it to a destination (a physical LED output, a network sink, or the preview).
A driver optionally reads dimensions from an active Layer, optionally applies the shared output correction, and optionally restricts its output to a contiguous window of the source buffer (see addWindowControls). It plays the same zero-state role for drivers that EffectBase does for effects.
Public Methods¶
virtual inline ModuleRole role() const override
: A driver must not be destroyed while its container's worker thread might still tick it — that is a vptr race (the destructor rewrites the vtable while the worker calls through it).
virtual void setSourceBuffer(Buffer * buf)
virtual inline void defineControls() final
: Template method: every driver card leads with the per-driver output correction (localBrightness / lightPreset / whiteMode / Custom offsets), added once here in the base so no driver re-implements the placement (the No-duplication rule) — then the driver's own controls via [defineDriverControls()].
virtual inline void defineDriverControls()
: A driver's own controls (its pins, protocol, IP, window, …), added AFTER the correction block.
virtual inline bool hasCorrectionControls() const
: Whether this driver exposes the per-driver correction controls.
inline void setLayer(Layer * layer)
: Set the active Layer this driver reads dimensions from.
inline uint16_t windowStart() const
: First light of the configured window.
inline uint16_t windowCount() const
: Number of lights in the configured window (0 = to end of buffer).
inline void setWindow(uint16_t start, uint16_t count)
: Set the window directly (the UI sets it via the start/count controls; this is for code-wiring a driver's slice and for tests).
inline nrOfLightsType resolveWindowLenForTest(nrOfLightsType bufN) const
: Resolve the window against a buffer of bufN lights → its length (0 if it starts past the end).
inline Layer * layer() const
: The active Layer this driver reads dimensions from — null when no Layer is wired (such as after the last Layer was deleted).
inline void rebuildCorrection(uint8_t globalBrightness)
: Rebuild this driver's own output correction, baking the global brightness the Drivers container passes together with this driver's local brightness into one LUT (global × local, both 0..255).
virtual inline void onControlChanged(constchar * name) override
: Base onControlChanged: rebuild this driver's correction when one of ITS correction controls (order/white/brightness/Custom offsets) changed, reusing the last global brightness the container pushed.
virtual inline void onCorrectionChanged()
: Notified when this driver's Correction outChannels may have changed (a lightPreset switch RGB↔RGBW, or a Custom channel-count edit).
virtual inline void release() override
: Clear every shared status string on release — fail buffer, config error, and config warning — so a stopped driver leaves nothing behind (frees the owned failBuf_; retracts the warning the same "clear only MY status" way as the error), then chain to MoonModule::release() so any ScratchBuffer the driver holds frees on disable and children recurse.
inline Correction & correctionForTest()
: Test-only: the driver's own Correction, mutable so a test can set a wiring directly (via the mm::test::rebuildFromPreset helper, or rebuild(255, roles, n)) instead of going through the container.