|
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. | |
| bool LMBD_INLINE | is_bliping () const |
| return true if the output is in a blip state | |
| 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 | enforce_internal_brightness_limits () |
| Enforce the brightness limits, if getMaxBrightness 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 | 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 | 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, uint16_t start, uint16_t end, const BufferTy &shouldDisplay) |
| (indexable) Fill lamp with target color, from start to end. Apply a mask to display leds | |
| void LMBD_INLINE | fill (uint32_t color) |
| (indexable) Fill lamp with target color | |
| void LMBD_INLINE | fill (uint32_t color, const BufferTy &shouldDisplay) |
| (indexable) Fill lamp with target color, with a mask | |
| 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 | 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 | |
| physical::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 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 | |
Static Public Attributes | |
| 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 | |
Main interface between the user and the hardware of the lamp.
TODO: write recipes for best practices when doing Simple/CCT/Indexable
|
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 |
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, with a mask
See modes::colors::fromRGB() to set color
|
inline |
(indexable) Fill lamp with target color, from start to end
start and end color
|
inline |
(indexable) Fill lamp with target color, from start to end. Apply a mask to display leds
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 |
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
|
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 |
(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.