blink1-lib  1.0.0
blink1_lib::Blink1Device Class Reference

#include <Blink1Device.hpp>

Collaboration diagram for blink1_lib::Blink1Device:

Public Types

enum  STRING_INIT_TYPE { STRING_INIT_TYPE::PATH, STRING_INIT_TYPE::SERIAL }
 

Public Member Functions

 Blink1Device () noexcept
 
 Blink1Device (const std::uint32_t id) noexcept
 
 Blink1Device (const std::string &stringInitializer, const STRING_INIT_TYPE initType) noexcept
 
 Blink1Device (const char *stringInitializer, const STRING_INIT_TYPE initType) noexcept
 
 Blink1Device (const Blink1Device &other)=delete
 
Blink1Deviceoperator= (const Blink1Device &other)=delete
 
 ~Blink1Device ()
 
bool good () const noexcept
 
 operator bool () const noexcept
 
std::optional< int > getVersion () const noexcept
 
bool fadeToRGB (const std::uint16_t fadeMillis, const RGB &rgb) noexcept
 
bool fadeToRGBN (const std::uint16_t fadeMillis, const RGBN &rgbn) noexcept
 
bool setRGB (const RGB &rgb) noexcept
 
bool setRGBN (const RGBN &rgbn) noexcept
 
std::optional< PatternLinereadRGBWithFade (const std::uint8_t ledn) const noexcept
 
std::optional< RGBreadRGB (const std::uint8_t ledn) const noexcept
 
bool play (const std::uint8_t pos) noexcept
 
bool playLoop (const std::uint8_t startpos, const std::uint8_t endpos, const std::uint8_t count) noexcept
 
bool stop () noexcept
 
std::optional< PlayStatereadPlayState () const noexcept
 
bool writePatternLine (const PatternLine &line, const std::uint8_t pos) noexcept
 
bool writePatternLineN (const PatternLineN &line, const std::uint8_t pos) noexcept
 
std::optional< PatternLinereadPatternLine (const std::uint8_t pos) const noexcept
 
std::optional< PatternLineNreadPatternLineN (const std::uint8_t pos) const noexcept
 
bool savePattern () noexcept
 
std::optional< int > getCacheIndex () const noexcept
 
std::optional< int > clearCache () noexcept
 
std::optional< std::string_view > getSerial () const noexcept
 
std::optional< bool > isMk2 () const noexcept
 
void setBlocking (bool blocking) noexcept
 
void setBlocking () noexcept
 
void setNonBlocking () noexcept
 
bool isBlocking () const noexcept
 

Static Public Member Functions

static void enableDegamma () noexcept
 
static void disableDegamma () noexcept
 
static int vid () noexcept
 
static int pid () noexcept
 

Public Attributes

RGB clearColor {0, 0, 0}
 
bool clearOnExit {false}
 

Detailed Description

A wrapper around the blink1 C library used to control blink1 devices

Member Enumeration Documentation

◆ STRING_INIT_TYPE

Defines how to interpret the string initializer passed into the constructors that take strings

Enumerator
PATH 

Interpret the initializer as a path to the device

SERIAL 

Interpret the initializer as a serial ID

Constructor & Destructor Documentation

◆ Blink1Device() [1/4]

blink1_lib::Blink1Device::Blink1Device ( )
noexcept

Default constructor

◆ Blink1Device() [2/4]

blink1_lib::Blink1Device::Blink1Device ( const std::uint32_t  id)
explicitnoexcept
Parameters
idThe ID of the device to initialize

◆ Blink1Device() [3/4]

blink1_lib::Blink1Device::Blink1Device ( const std::string &  stringInitializer,
const STRING_INIT_TYPE  initType 
)
noexcept
Parameters
stringInitializerString to select the device to initialize
initTypeHow to interpret the the string

◆ Blink1Device() [4/4]

blink1_lib::Blink1Device::Blink1Device ( const char *  stringInitializer,
const STRING_INIT_TYPE  initType 
)
noexcept
Parameters
stringInitializerString to select the device to initialize
initTypeHow to interpret the the string

◆ ~Blink1Device()

blink1_lib::Blink1Device::~Blink1Device ( )

Destructor.

Member Function Documentation

◆ clearCache()

std::optional<int> blink1_lib::Blink1Device::clearCache ( )
noexcept

Clear blink1 device cache for this device

Returns
The cache index that was cleared if anything was cleared, std::nullopt otherwise

◆ disableDegamma()

static void blink1_lib::Blink1Device::disableDegamma ( )
staticnoexcept

Disable the blink1-lib gamma curve

Note
Docs say it should probably always be disabled

◆ enableDegamma()

static void blink1_lib::Blink1Device::enableDegamma ( )
staticnoexcept

Enables the blink1-lib gamma curve

Note
Docs say it should probably always be disabled

◆ fadeToRGB()

bool blink1_lib::Blink1Device::fadeToRGB ( const std::uint16_t  fadeMillis,
const RGB rgb 
)
noexcept

Fades the device to another color over time. If this device has multiple LEDs, all LEDs will fade to that color.

By default this function is non-blocking to allow for processing while the fade is occurring. This behavior can be changed with setBlocking(bool).

Parameters
fadeMillisThe amount of time in milliseconds for the fade to last
rgbRGB color to fade to
Returns
true if the command was successfully sent to the device, false otherwise
See also
setBlocking(bool)
setBlocking()
setNonBlocking()

◆ fadeToRGBN()

bool blink1_lib::Blink1Device::fadeToRGBN ( const std::uint16_t  fadeMillis,
const RGBN rgbn 
)
noexcept

Fades the device to another color over time. Only fades the LED specified in the RGBN value.

By default this function is non-blocking to allow for processing while the fade is occurring. This behavior can be changed with setBlocking(bool).

Parameters
fadeMillisThe amount of time in milliseconds for the fade to last
rgbnRGB color to fade to along with which LED on the device to fade to
Returns
true if the command was successfully sent to the device, false otherwise
See also
setBlocking(bool)
setBlocking()
setNonBlocking()

◆ getCacheIndex()

std::optional<int> blink1_lib::Blink1Device::getCacheIndex ( ) const
noexcept

Returns the cache index for this device

Returns
The cache index if it was found, std::nullopt otherwise

◆ getSerial()

std::optional<std::string_view> blink1_lib::Blink1Device::getSerial ( ) const
noexcept

Gets serial ID for this device

Returns
8-hexdigit serial number string if device is good, std::nullopt otherwise

◆ getVersion()

std::optional<int> blink1_lib::Blink1Device::getVersion ( ) const
noexcept

Gets the version of the device that is connected. Returns std::nullopt if good() returns false

Returns
The version of the device

◆ good()

bool blink1_lib::Blink1Device::good ( ) const
noexcept

Returns whether or not the device is successfully connected

Returns
true if the device is connected and ready, false otherwise

◆ isBlocking()

bool blink1_lib::Blink1Device::isBlocking ( ) const
noexcept

Returns whether the device is in blocking mode.

Returns
Whether blocking mode is set.
See also
setBlocking(bool)

◆ isMk2()

std::optional<bool> blink1_lib::Blink1Device::isMk2 ( ) const
noexcept

Returns whether the device is a MK2 device

Returns
Whether the device is a MK2 device if the device is good, std::nullopt otherwise

◆ operator bool()

blink1_lib::Blink1Device::operator bool ( ) const
explicitnoexcept

Returns the same thing as good()

Returns
Whatever good() returns
See also
good()

◆ pid()

static int blink1_lib::Blink1Device::pid ( )
staticnoexcept

Product ID for blink1 devices

◆ play()

bool blink1_lib::Blink1Device::play ( const std::uint8_t  pos)
noexcept

Plays a programmed pattern on the device

Parameters
posPosition to start playing from
See also
writePatternLine(const PatternLine&, const std::uint8_t)
writePatternLineN(const PatternLineN&, const std::uint8_t)
Returns
true if the command was successfully sent to the device, false otherwise

◆ playLoop()

bool blink1_lib::Blink1Device::playLoop ( const std::uint8_t  startpos,
const std::uint8_t  endpos,
const std::uint8_t  count 
)
noexcept

Plays a stored pattern on a loop

Parameters
startposStart position for the loop
endposEnd position for the loop
countNumber of times to repeat (0 to repeat forever)
Returns
true if the command was successfully sent to the device, false otherwise

◆ readPatternLine()

std::optional<PatternLine> blink1_lib::Blink1Device::readPatternLine ( const std::uint8_t  pos) const
noexcept

Reads the pattern line stored at the given position

Note
The documentation doesn't say whether this reads from volatile or non-volatile memory, but I'd assume is the volatile memory
Parameters
posThe position to read
Returns
The PatternLine if it could be read successfully, std::nullopt otherwise

◆ readPatternLineN()

std::optional<PatternLineN> blink1_lib::Blink1Device::readPatternLineN ( const std::uint8_t  pos) const
noexcept

Reads the pattern line stored at the given position

Note
The documentation doesn't say whether this reads from volatile or non-volatile memory, but I'd assume is the volatile memory
Parameters
posThe position to read
Returns
The PatternLineN if it could be read successfully, std::nullopt otherwise

◆ readPlayState()

std::optional<PlayState> blink1_lib::Blink1Device::readPlayState ( ) const
noexcept

Reads the current PlayState of the device

Returns
The PlayState if it could be read, std::nullopt otherwise

◆ readRGB()

std::optional<RGB> blink1_lib::Blink1Device::readRGB ( const std::uint8_t  ledn) const
noexcept

Reads the RGB value of the given LED

Note
The underlying function takes in fadeMillis as a parameter, but it's not documented at all. This makes me think the function might return the target RGB value rather than the current value, but the docs say current, so I'm really not sure
Parameters
lednThe index of the LED to read
Returns
The RGB value if it was read successfully, std::nullopt otherwise

◆ readRGBWithFade()

std::optional<PatternLine> blink1_lib::Blink1Device::readRGBWithFade ( const std::uint8_t  ledn) const
noexcept

Reads the RGB value of the given LED & the fade time

Note
The underlying function takes in fadeMillis as a parameter, but it's not documented at all. This makes me think the function might return the target RGB value rather than the current value, but the docs say current, so I'm really not sure
Parameters
lednThe index of the LED to read
Returns
A PatternLine (an RGB plus a fade time) if the value could be read successfully, std::nullopt otherwise

◆ savePattern()

bool blink1_lib::Blink1Device::savePattern ( )
noexcept

Saves the pattern in volatile memory into the non-volatile storage

Note
Based on the documentation, this probably will always return a failure due to the function call timing out before it is actually able to save to the flash
Returns
true if it was saved successfully, false otherwise

◆ setBlocking() [1/2]

void blink1_lib::Blink1Device::setBlocking ( )
noexcept

Sets the device to be in blocking mode.

See also
setBlocking(bool)

◆ setBlocking() [2/2]

void blink1_lib::Blink1Device::setBlocking ( bool  blocking)
noexcept

Sets the blocking mode for this device (technically just for this library for this device, as the underlying C library does not have a blocking mode).

When in blocking mode, fade commands will not return until the fade time is up. If blocking mode is disabled, the fade commands will return immediately. By default, all functions are non-blocking.

Parameters
blockingWhether or not to be in blocking mode
See also
fadeToRGB()
fadeToRGBN()

◆ setNonBlocking()

void blink1_lib::Blink1Device::setNonBlocking ( )
noexcept

Sets the device to be in non-blocking mode.

See also
setBlocking(bool)

◆ setRGB()

bool blink1_lib::Blink1Device::setRGB ( const RGB rgb)
noexcept

Sets the color of all LEDs on the device. The same as calling fadeToRGB(const std::uint16_t, const RGB&) with fadeMillis set to 0.

Parameters
rgbThe color to set
Returns
true if the command was successfully sent to the device, false otherwise

◆ setRGBN()

bool blink1_lib::Blink1Device::setRGBN ( const RGBN rgbn)
noexcept

Sets the color of the specified on the device. The same as calling fadeToRGBN(const std::uint16_t, const RGBN&) with fadeMillis set to 0.

Parameters
rgbnThe color to set along with which LED to set it on
Returns
true if the command was successfully sent to the device, false otherwise

◆ stop()

bool blink1_lib::Blink1Device::stop ( )
noexcept

Stop playing the pattern that was playing

Returns
true if the command was successfully sent to the device, false otherwise

◆ vid()

static int blink1_lib::Blink1Device::vid ( )
staticnoexcept

Vendor ID for blink1 devices

◆ writePatternLine()

bool blink1_lib::Blink1Device::writePatternLine ( const PatternLine line,
const std::uint8_t  pos 
)
noexcept

Writes a PatternLine to the device at the specified position

Note
On mk2 devices, this saves the pattern to volatile memory. Call savePattern() to save the pattern in volatile memory into non-volatile memory
Parameters
lineThe line to write
posThe position to write the line to - a number from 0 to max_patt (no documentation on what the value is)
See also
savePattern()
Returns
true if the command was sent successfully to the device, false otherwise

◆ writePatternLineN()

bool blink1_lib::Blink1Device::writePatternLineN ( const PatternLineN line,
const std::uint8_t  pos 
)
noexcept

Writes a PatternLineN to the device at the specified position

Note
On mk2 devices, this saves the pattern to volatile memory. Call savePattern() to save the pattern in volatile memory into non-volatile memory
Parameters
lineThe line to write
posThe position to write the line to - a number from 0 to max_patt (no documentation on what the value is)
See also
savePattern()
Returns
true if the command was sent successfully to the device, false otherwise

Member Data Documentation

◆ clearColor

RGB blink1_lib::Blink1Device::clearColor {0, 0, 0}

Color to clear to if Blink1Device::clearOnExit is set to true. Defaults to black/off.

◆ clearOnExit

bool blink1_lib::Blink1Device::clearOnExit {false}

Set to true to clear the LEDs when the destructor is called. The clear color can be changed with Blink1Device::clearColor.


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