|
Lamp-Da 0.1
A compact lantern project
|
Main interface between the user and the hardware of the lamp. More...
#include <lamp_type.hpp>
Classes | |
| struct | LampConfig |
| Store a display config. More... | |
Public Member Functions | |
| void LMBD_INLINE | clear () |
| Clear lamp to a clean state. | |
| void LMBD_INLINE | blip (const uint32_t duration) |
| blip the power gate for set time | |
| void LMBD_INLINE | cancel_blip () const |
| Cancel the ongoing blip, if any. | |
| void LMBD_INLINE | end_blackout () const |
| Stop the strip blackout of a blip (indexable only, no-op otherwise) | |
| bool LMBD_INLINE | is_bliping () const |
| return true if the output is in a blip state | |
| void LMBD_INLINE | set_steps_mask (uint8_t newValue) |
| Set the value of the half step mask, from 0 to maxMaskStep. | |
| void LMBD_INLINE | cancel_step_mask () |
| Diasble the step mask. | |
| void LMBD_INLINE | setBrightness (const brightness_t newBrightness, const bool skipCallbacks=true, const bool skipUpdateBrightness=false, const bool updateSavedBrightess=false) |
| Set brightness of the lamp. | |
| void | align_internal_to_system_brightness () |
| Special call to update the internal brightness values to the system brightness. | |
| void | align_internal_to_system_brightness (const brightness_t systemBrightness) |
| Update the internal brightness values to a new system brightness. | |
| void | enforce_internal_brightness_limits () |
| Follow the system brightness and enforce its limits, if they changed. Will call setBrightness. | |
| brightness_t LMBD_INLINE | getMaxBrightness () const |
| Return the actual allowed maximum brightness. | |
| void LMBD_INLINE | tempBrightness (const brightness_t brightness) |
| Temporarily set brightness, without affecting brightness navigation. | |
| void LMBD_INLINE | jumpBrightness (const brightness_t brightness) |
| Jump to brightness, affecting the next brightness navigation. | |
| brightness_t LMBD_INLINE | getBrightness (const bool readPreviousBrightness=false) |
| Get brightness of the lamp. | |
| brightness_t LMBD_INLINE | getSavedBrightness () |
Alias for getBrightness(true) | |
| void LMBD_INLINE | restoreBrightness () |
| Reset brightness to internal saved brightness, skip callbacks. | |
| void LMBD_INLINE | restoreBrightnessNow () |
| Same as restoreBrightness(), but ignores the brightness update rate limit. | |
| void LMBD_INLINE | fadeToBlackBy (uint8_t fadeBy) |
Fade currently displayed content by fadeBy units. | |
| void LMBD_INLINE | blur (uint8_t blurBy) |
Blur currently displayed content by blurBy units /!\ Only applied along the strip, not in 2D /!. | |
| void LMBD_INLINE | apply_low_brightness_mask () |
| Apply the optional low level brightnes dithering. | |
| void LMBD_INLINE | fill (uint32_t color, uint16_t start, uint16_t end) |
| (indexable) Fill lamp with target color, from start to end | |
| void LMBD_INLINE | fill (uint32_t color) |
| (indexable) Fill lamp with target color | |
| void LMBD_INLINE | fill (const colors::PaletteTy &palette, uint16_t start, uint16_t end) |
| (indexable) Fill lamp with target palette, from start to end | |
| void LMBD_INLINE | fill (const colors::PaletteTy &palette) |
| (indexable) Fill lamp with target palette | |
| void LMBD_INLINE | mask_led_at_index (const size_t n, const bool shouldMask) |
| Mark a led to be masked at the next show. | |
| void LMBD_INLINE | mask_led_at_XY (uint16_t X, uint16_t Y, const bool shouldMask) |
| void LMBD_INLINE | setPixelColor (uint16_t n, uint32_t color) |
| (indexable) Set the n-th LED color | |
| uint32_t LMBD_INLINE | getPixelColor (uint16_t n) |
| (indexable) Get the n-th LED color | |
| void LMBD_INLINE | setPixelColorXY (uint16_t X, uint16_t Y, uint32_t color) |
| (indexable) Set the X,Y-th LED color | |
| template<uint8_t bufIdx = 0> | |
| BufferTy &LMBD_INLINE | getTempBuffer () |
Get a reference to the bufIdx temporary buffer. | |
| template<uint8_t dstBufIdx, uint8_t srcBufIdx> | |
| void LMBD_INLINE | copyBuffer () |
Copy a source buffer at srcBufIdx to another buffer at dstBufIdx. | |
| template<uint8_t bufIdx = 0, typename T > | |
| void LMBD_INLINE | fillTempBuffer (const T &value) |
Fill temporary buffer bufIdx with given value. | |
| template<uint8_t bufIdx = 0> | |
| void | setColorsFromBuffer () |
(indexable) Display bufIdx temporary buffer as LED colors | |
| template<uint8_t dstBufIdx = 0, uint8_t srcBufIdx = 1> | |
| void | setColorsFromMixedBuffers (float phase) |
| Mix two colors from a buffer. | |
| template<uint8_t bufIdx = 0> | |
| void | setColorsFromBufferReversed (bool skipLastLine) |
(indexable) Display bufIdx temporary buffer, but reversed | |
| template<uint8_t bufIdx = 0, bool forceFullRead = false> | |
| void | getColorsToBuffer () |
(indexable) Copy all current LEDs color to bufIdx temp. buffer | |
| component::microphone::SoundStruct &LMBD_INLINE | get_sound_struct () |
| Return the an object containing sound analysis data. | |
Static Public Member Functions | |
| template<typename T > | |
| static constexpr LMBD_INLINE uint16_t | toLedCount (T scale) |
(indexable) Return a led count in 0-ledCount scaled by scale | |
| static uint16_t LMBD_INLINE | fromXYtoStripIndex (uint16_t X, uint16_t Y) |
| (indexable) Given X,Y coordinate, return a corresponding LED index | |
| static XYTy LMBD_INLINE | fromStripIndexToXY (uint16_t N) |
| (indexable) Given a LED index, return a corresponding X,Y value | |
Public Attributes | |
| LampConfig | config |
| store a display configuration | |
| volatile brightness_t | saved_brightness |
| Define a localy consistant saved brightness. Should be similar. | |
| volatile brightness_t | temporary_brightness |
| Define a localy consistant temporary brightness. | |
| volatile brightness_t | last_system_brightness |
| Value of the system brightness when the local saved brightness last followed it. | |
| volatile const uint32_t | now |
| (physical) The "now" on milliseconds, updated just before loop. | |
| volatile const uint32_t | tick |
| (physical) Tick number, ever-increasing every frameDurationMs | |
| volatile const uint32_t | raw_frame_count |
| (physical) Raw frame count, incremented at an undefined rate | |
| volatile const uint8_t | currentMaskStep = 0 |
| If true, only a proportion of the leds will be available to control If 1, all leds are available, goes up to maxMaskStep. | |
| volatile bool | forceDisableLedDitherMask = false |
| set to true to lock led mask brightness control | |
Static Public Attributes | |
| static constexpr helixmask::Params | helixMaskParameters = {} |
| static constexpr LampTypes | flavor = lampType |
| Which lamp flavor is currently used by the implementation? | |
| static constexpr uint32_t | frameDurationMs = MAIN_LOOP_UPDATE_PERIOD_MS |
| Hardward try to call .loop() every frameDurationMs (12ms for 83.3fps) | |
| static constexpr uint32_t | brightnessDurationMs = frameDurationMs * 2 |
| Limit mode-requested brightness changes to one every few frames. | |
| static constexpr uint16_t | ledCount = _ledCount |
| (indexable) Count of indexable LEDs on the lamp | |
| static constexpr uint16_t | maxWidth = _width |
| (indexable) Width of "pixel space" w/ lamp taken as a LED matrix | |
| static constexpr float | maxWidthFloat = _fwidth |
Width as a precise floating point number, equal to stripXCoordinates. | |
| static constexpr uint16_t | maxOverflowWidth = maxWidth + 1 |
| Larger width, taken as the absolute maximum X coordinate on all rows. | |
| static constexpr uint16_t | maxHeight = _height |
| (indexable) Height of "pixel space" w/ lamp taken as a LED matrix | |
| static constexpr float | maxHeightFloat = _fheight |
Height as a precise floating point number, equal to stripYCoordinates. | |
| static constexpr uint16_t | maxOverflowHeight = maxHeight + 1 |
| Larger height, taken as the absolute maximum Y coordinate, overflowing. | |
| static constexpr float | _invShiftResidue = shiftPeriod * (_fwidth - floor(_fwidth - 0.0001)) |
| (while shifting every shiftPeriod, we have a residue accumulating) | |
| static constexpr float | lampBodyRadius_mm = _lampBodyRadius_mm |
| real radius of the lamp body | |
| static constexpr float | ledStripWidth_mm = _ledStripWidth_mm |
| real size of the led strip in use | |
| static constexpr float | ledStripLength_mm = _ledStripLength_mm |
| Copy the led strip lenght. | |
| static constexpr float | ledByMeter = _ledByMeter |
| number of led per meters of strip used | |
| static constexpr float | ledSize_mm = 1000.0f / ledByMeter |
| Number of leds per one turn of led strip. | |
| static constexpr float | lampBodyCircumpherence_mm = c_TWO_PI * lampBodyRadius_mm |
| Computation of the lamp body circumpherence. | |
| static constexpr float | ledPerTurns = lampBodyCircumpherence_mm / ledSize_mm |
| Computation of the led count per turns. | |
| static constexpr float | lampHeight_mm = ledStripWidth_mm * ledCount / ledPerTurns |
| Computation of the lamp height. | |
| static constexpr uint8_t | nbBuffers = _nbBuffers |
| (indexable) Number of color buffers available for direct access | |
| static constexpr uint8_t | maxMaskStep = helixMaskParameters.max_level |
| static constexpr brightness_t | ledMasking_brightnessThreshold |
| below this, the system will enable the led masking | |
Main interface between the user and the hardware of the lamp.
|
inline |
Update the internal brightness values to a new system brightness.
Used by the system brightness callback: the system saves the brightness after this callback, so logic::brightness::get_scaled_saved_brightness() still holds the previous level at this point.
|
inline |
Apply the optional low level brightnes dithering.
public API (indexable-only)
|
inline |
blip the power gate for set time
If LampTy::flavor is LampTypes::indexable then:
|
inline |
Blur currently displayed content by blurBy units /!\ Only applied along the strip, not in 2D /!.
If LampTy::flavor is LampTypes::indexable then:
Or else, for other flavors of lamp:
blurBy floored at zero
|
inline |
Clear lamp to a clean state.
If LampTy::flavor is LampTypes::indexable then:
Or else, for interoperability:
|
inline |
Copy a source buffer at srcBufIdx to another buffer at dstBufIdx.
These buffers can be used for computations by the active mode, but their content may be erased if the mode is reset or if used elsewhere in code.
|
inline |
Follow the system brightness and enforce its limits, if they changed. Will call setBrightness.
A mode may have moved the saved brightness below the system one (see jumpBrightness). To keep this offset without a visible jump, a rise is added to the saved brightness, and a fall only limits it. A temporary brightness set by a mode is left to this mode, unless it is above the limit: writing to it would show as a flash until the next frame of the mode.
|
inline |
Fade currently displayed content by fadeBy units.
If LampTy::flavor is LampTypes::indexable then:
Or else, for other flavors of lamp:
fadeBy floored at zero
|
inline |
(indexable) Fill lamp with target palette
palette
|
inline |
(indexable) Fill lamp with target palette, from start to end
start and end palette
|
inline |
(indexable) Fill lamp with target color
See modes::colors::fromRGB() to set color
|
inline |
(indexable) Fill lamp with target color, from start to end
start and end color
|
inline |
Fill temporary buffer bufIdx with given value.
Equivalent to getTempBuffer().fill(value)
|
inlinestatic |
(indexable) Given a LED index, return a corresponding X,Y value
Uses modes::strip_to_XY as implementation (both function are equivalent)
|
inlinestatic |
(indexable) Given X,Y coordinate, return a corresponding LED index
Uses modes::to_strip as implementation (both function are equivalent)
|
inline |
Get brightness of the lamp.
If readPreviousBrightness is true, return the internally saved brightness state, used for user navigation of brightness.
|
inline |
(indexable) Copy all current LEDs color to bufIdx temp. buffer
If forceFullRead is True, also copy skipped content.
|
inline |
Get a reference to the bufIdx temporary buffer.
These buffers can be used for computations by the active mode, but their content may be erased if the mode is reset or if used elsewhere in code.
|
inline |
Jump to brightness, affecting the next brightness navigation.
Skip callbacks.
Set brightness, affecting internal brightness navigation state, which imply that next time an user increases / lowers brightness, it starts again from the provided brightness.
Equivalent to setBrightness(true, false, true)
|
inline |
Mark a led to be masked at the next show.
| [in] | n | Index of the led to disable |
| [in] | shouldMask | If true, the led wont be displayed |
|
inline |
Same as restoreBrightness(), but ignores the brightness update rate limit.
For the callers that will not try again: a rate limited update would leave the system on the temporary brightness
|
inline |
Set brightness of the lamp.
Several behaviors:
Thus:
skipCallbacks is false, do call user callbacks w/ re-entry risksskipUpdateBrightness is true, only set strip object brightness, or do nothing if LampTy::flavor is not LampTypes::indexableupdateSavedBrightess is true, save brightness and next time user navigate brightness, use it as starting point (see tempBrightness)Note that calls to logic::brightness::update_brightness are throttled to once in every 50ms to avoid freezing user brightness navigation.
Note that skipUpdateBrightness implies skipCallbacks implicitly
|
inline |
(indexable) Display bufIdx temporary buffer as LED colors
This memcpy the selected buffer to the internal strip color buffer.
|
inline |
Mix two colors from a buffer.
| [in] | phase | Between 0 and 1, the gradient to apply |
|
inline |
(indexable) Set the n-th LED color
See modes::fromRGB() to set color
| [in] | forceSet | Force set the pixel color, ignoring all check and masks rules |
|
inline |
(indexable) Set the X,Y-th LED color
See modes::fromRGB() to set color
|
inline |
Temporarily set brightness, without affecting brightness navigation.
Skip callbacks.
Set brightness, without affecting internal brightness navigation state, which imply that next time an user increases / lowers brightness, it starts again from another internal "previously saved" brightness.
Equivalent to setBrightness(true, false, false)
|
inlinestaticconstexpr |
(indexable) Return a led count in 0-ledCount scaled by scale
Supports:
|
staticconstexpr |
(indexable) Count of indexable LEDs on the lamp
Equal to LED_COUNT if LampTypes::indexable or else 512
|
staticconstexpr |
below this, the system will enable the led masking
|
staticconstexpr |
(indexable) Height of "pixel space" w/ lamp taken as a LED matrix
This height equals the largest Y coordinate for which a full maxWidth row can be displayed, the last row at coordinate maxOverflowHeight being likely to be truncated depending on the exact diameter of the lamp and density of the LED strip.
The largest LED matrix fully displayed on the lamp taken as an XY screen display is thus of width maxWidth and height maxHeight leaving out some "outside" of the default display size.
Equal to stripYCoordinates (floor) if LampTypes::indexable or else 22
|
staticconstexpr |
(indexable) Width of "pixel space" w/ lamp taken as a LED matrix
This width equals the smallest maximal X coordinate for which all rows are fully displayed on the lamp taken as an "XY-display" LED matrix.
All rows are of length of at least maxWidth but some will be of length maxOverflowWidth depending on the exact diameter of the lamp and density of the LED strip.
Equal to stripXCoordinates (floor) if LampTypes::indexable or else 23
|
staticconstexpr |
(indexable) Number of color buffers available for direct access
Equal to stripNbBuffers if LampTypes::indexable or else 2
| volatile const uint32_t lampda::modes::hardware::LampTy::now |
(physical) The "now" on milliseconds, updated just before loop.
This value is get_time_ms() called once and used as basis for tick and may wrap around every three weeks of functioning.
| volatile const uint32_t lampda::modes::hardware::LampTy::raw_frame_count |
(physical) Raw frame count, incremented at an undefined rate
This value increments everytime the loop method is called, and its rate may vary depending on hardware and load. If used to build animations, this may cause stutters or visible slowdowns during loads.
| volatile const uint32_t lampda::modes::hardware::LampTy::tick |
(physical) Tick number, ever-increasing every frameDurationMs
This value increments 83.3 times per second and is updated once per loop.
It is based on the internal board clock, that counter is time-based and best used to build animations, but intermediary values may be skipped.