Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lampda::modes::hardware::LampTy Struct Reference

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
 

Detailed Description

Main interface between the user and the hardware of the lamp.

TODO: write recipes for best practices when doing Simple/CCT/Indexable

Member Function Documentation

◆ blip()

void LMBD_INLINE lampda::modes::hardware::LampTy::blip ( const uint32_t  duration)
inline

blip the power gate for set time

If LampTy::flavor is LampTypes::indexable then:

  • clear LED strip with black pixels Else
  • disable output power for a duration

◆ blur()

void LMBD_INLINE lampda::modes::hardware::LampTy::blur ( uint8_t  blurBy)
inline

Blur currently displayed content by blurBy units /!\ Only applied along the strip, not in 2D /!.

If LampTy::flavor is LampTypes::indexable then:

  • do not change brightness, only scale color of individual LEDs

Or else, for other flavors of lamp:

  • blue colors by blurBy floored at zero

◆ clear()

void LMBD_INLINE lampda::modes::hardware::LampTy::clear ( )
inline

Clear lamp to a clean state.

If LampTy::flavor is LampTypes::indexable then:

  • clear LED strip with black pixels

Or else, for interoperability:

  • does nothing

◆ copyBuffer()

template<uint8_t dstBufIdx, uint8_t srcBufIdx>
void LMBD_INLINE lampda::modes::hardware::LampTy::copyBuffer ( )
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.

◆ fadeToBlackBy()

void LMBD_INLINE lampda::modes::hardware::LampTy::fadeToBlackBy ( uint8_t  fadeBy)
inline

Fade currently displayed content by fadeBy units.

If LampTy::flavor is LampTypes::indexable then:

  • do not change brightness, only scale color of individual LEDs

Or else, for other flavors of lamp:

  • reduce brightness by fadeBy floored at zero

◆ fill() [1/6]

void LMBD_INLINE lampda::modes::hardware::LampTy::fill ( const colors::PaletteTy palette)
inline

(indexable) Fill lamp with target palette

◆ fill() [2/6]

void LMBD_INLINE lampda::modes::hardware::LampTy::fill ( const colors::PaletteTy palette,
uint16_t  start,
uint16_t  end 
)
inline

(indexable) Fill lamp with target palette, from start to end

◆ fill() [3/6]

void LMBD_INLINE lampda::modes::hardware::LampTy::fill ( uint32_t  color)
inline

(indexable) Fill lamp with target color

See modes::colors::fromRGB() to set color

◆ fill() [4/6]

void LMBD_INLINE lampda::modes::hardware::LampTy::fill ( uint32_t  color,
const BufferTy &  shouldDisplay 
)
inline

(indexable) Fill lamp with target color, with a mask

See modes::colors::fromRGB() to set color

◆ fill() [5/6]

void LMBD_INLINE lampda::modes::hardware::LampTy::fill ( uint32_t  color,
uint16_t  start,
uint16_t  end 
)
inline

(indexable) Fill lamp with target color, from start to end

◆ fill() [6/6]

void LMBD_INLINE lampda::modes::hardware::LampTy::fill ( uint32_t  color,
uint16_t  start,
uint16_t  end,
const BufferTy &  shouldDisplay 
)
inline

(indexable) Fill lamp with target color, from start to end. Apply a mask to display leds

◆ fillTempBuffer()

template<uint8_t bufIdx = 0, typename T >
void LMBD_INLINE lampda::modes::hardware::LampTy::fillTempBuffer ( const T &  value)
inline

Fill temporary buffer bufIdx with given value.

Equivalent to getTempBuffer().fill(value)

◆ fromStripIndexToXY()

static XYTy LMBD_INLINE lampda::modes::hardware::LampTy::fromStripIndexToXY ( uint16_t  N)
inlinestatic

(indexable) Given a LED index, return a corresponding X,Y value

Uses modes::strip_to_XY as implementation (both function are equivalent)

◆ fromXYtoStripIndex()

static uint16_t LMBD_INLINE lampda::modes::hardware::LampTy::fromXYtoStripIndex ( uint16_t  X,
uint16_t  Y 
)
inlinestatic

(indexable) Given X,Y coordinate, return a corresponding LED index

Uses modes::to_strip as implementation (both function are equivalent)

◆ getBrightness()

brightness_t LMBD_INLINE lampda::modes::hardware::LampTy::getBrightness ( const bool  readPreviousBrightness = false)
inline

Get brightness of the lamp.

If readPreviousBrightness is true, return the internally saved brightness state, used for user navigation of brightness.

◆ getColorsToBuffer()

template<uint8_t bufIdx = 0, bool forceFullRead = false>
void lampda::modes::hardware::LampTy::getColorsToBuffer ( )
inline

(indexable) Copy all current LEDs color to bufIdx temp. buffer

If forceFullRead is True, also copy skipped content.

◆ getTempBuffer()

template<uint8_t bufIdx = 0>
BufferTy &LMBD_INLINE lampda::modes::hardware::LampTy::getTempBuffer ( )
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.

◆ jumpBrightness()

void LMBD_INLINE lampda::modes::hardware::LampTy::jumpBrightness ( const brightness_t  brightness)
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)

◆ setBrightness()

void LMBD_INLINE lampda::modes::hardware::LampTy::setBrightness ( const brightness_t  newBrightness,
const bool  skipCallbacks = true,
const bool  skipUpdateBrightness = false,
const bool  updateSavedBrightess = false 
)
inline

Set brightness of the lamp.

Several behaviors:

  • by default, do not call user callbacks to avoid re-entry
  • by default, do call global brightness update handler (see brightness_handle.h)
  • by default, do NOT save brightness using "previous_brightness_update"
  • also set the brightness in underlying strip object, if necessary

Thus:

  • if skipCallbacks is false, do call user callbacks w/ re-entry risks
  • if skipUpdateBrightness is true, only set strip object brightness, or do nothing if LampTy::flavor is not LampTypes::indexable
  • if updateSavedBrightess 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

Warning
: this is actually heavy to run

◆ setColorsFromBuffer()

template<uint8_t bufIdx = 0>
void lampda::modes::hardware::LampTy::setColorsFromBuffer ( )
inline

(indexable) Display bufIdx temporary buffer as LED colors

This memcpy the selected buffer to the internal strip color buffer.

◆ setColorsFromMixedBuffers()

template<uint8_t dstBufIdx = 0, uint8_t srcBufIdx = 1>
void lampda::modes::hardware::LampTy::setColorsFromMixedBuffers ( float  phase)
inline

Mix two colors from a buffer.

Parameters
[in]phaseBetween 0 and 1, the gradient to apply

◆ setPixelColor()

void LMBD_INLINE lampda::modes::hardware::LampTy::setPixelColor ( uint16_t  n,
uint32_t  color 
)
inline

(indexable) Set the n-th LED color

See modes::fromRGB() to set color

◆ setPixelColorXY()

void LMBD_INLINE lampda::modes::hardware::LampTy::setPixelColorXY ( uint16_t  X,
uint16_t  Y,
uint32_t  color 
)
inline

(indexable) Set the X,Y-th LED color

See modes::fromRGB() to set color

◆ tempBrightness()

void LMBD_INLINE lampda::modes::hardware::LampTy::tempBrightness ( const brightness_t  brightness)
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)

◆ toLedCount()

template<typename T >
static constexpr LMBD_INLINE uint16_t lampda::modes::hardware::LampTy::toLedCount ( scale)
inlinestaticconstexpr

(indexable) Return a led count in 0-ledCount scaled by scale

Supports:

  • from float (0-1) to count (0-ledCount)
  • from uint8_t (0-255) to count (0-ledCount)

Member Data Documentation

◆ ledCount

constexpr uint16_t lampda::modes::hardware::LampTy::ledCount = _ledCount
staticconstexpr

(indexable) Count of indexable LEDs on the lamp

Equal to LED_COUNT if LampTypes::indexable or else 512

◆ maxHeight

constexpr uint16_t lampda::modes::hardware::LampTy::maxHeight = _height
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

◆ maxWidth

constexpr uint16_t lampda::modes::hardware::LampTy::maxWidth = _width
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

◆ nbBuffers

constexpr uint8_t lampda::modes::hardware::LampTy::nbBuffers = _nbBuffers
staticconstexpr

(indexable) Number of color buffers available for direct access

Equal to stripNbBuffers if LampTypes::indexable or else 2

◆ now

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.

◆ raw_frame_count

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.

◆ tick

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.


The documentation for this struct was generated from the following file: