libblinkstick
A library for the blinkstick LED controller
Loading...
Searching...
No Matches
libblinkstick.h File Reference

Header for libBlinkStick. More...

#include <hidapi.h>
#include <stdbool.h>

Go to the source code of this file.

Classes

struct  blinkstick_device
 A blinkstick_device holds a pointer to the hid device and is used when setting colors, modes, or turning the device off. More...
 
struct  blinkstick_color
 

Typedefs

typedef struct blinkstick_device blinkstick_device
 A blinkstick_device holds a pointer to the hid device and is used when setting colors, modes, or turning the device off.
 
typedef struct blinkstick_color blinkstick_color
 

Enumerations

enum  blinkstick_mode { unknown =-1 , normal =0 , inverse =1 , smart_pixel =2 }
 Possible blink stick modes (only valid for Blinkstick Pro).
 

Functions

BLINKSTICK_API blinkstick_device ** blinkstick_find_many (const int count)
 Given a count will return a pointer array of blinkstick devices. This will abort if the number found is less than the given count.
 
BLINKSTICK_API blinkstick_deviceblinkstick_find ()
 Find the first blinkstick device on the bus registered with HID.
 
BLINKSTICK_API bool blinkstick_set_color (blinkstick_device *blinkstick, const int channel, const int index, const int red, const int green, const int blue)
 Sets the LED at the given index and channel to the specified color for the provided device.
 
BLINKSTICK_API blinkstick_colorblinkstick_get_color (struct blinkstick_device *blinkstick, const int index)
 Reads the color from the blinkstick at a given index.
 
BLINKSTICK_API bool blinkstick_set_mode (blinkstick_device *blinkstick, enum blinkstick_mode mode)
 Set the mode of the blinkstick.
 
BLINKSTICK_API enum blinkstick_mode blinkstick_get_mode (blinkstick_device *blinkstick)
 Read the mode currently set on the blinkstick.
 
BLINKSTICK_API bool blinkstick_off (blinkstick_device *blinkstick, const int channel, const int index)
 Turns off the led at the specified index for the provided device. This is the same as using set_color with the RGB value (0, 0, 0)
 
BLINKSTICK_API void blinkstick_debug ()
 Turns on debug logging.
 
BLINKSTICK_API void blinkstick_destroy (blinkstick_device *device)
 Frees the given blinkstick device.
 

Detailed Description

Header for libBlinkStick.

libBlinkStick is meant to to be a simple library for talking to a blinkstick. The BlinkStick Square, BlinkStick v1.1, and the BlinkStick Pro are officially supported and it's likely that other devices work as well.

libBlinkStick depends on hidapi for interacting with the USB devices, but otherwise has no other dependencies.

Included are functions to turn on and off any of the LEDs and change their color via an rgb color. Multiple devices are supported.

Typedef Documentation

◆ blinkstick_device

typedef struct blinkstick_device blinkstick_device

A blinkstick_device holds a pointer to the hid device and is used when setting colors, modes, or turning the device off.

Construct this device by using blinkstick_find and free it with blinkstick_destroy. Example:

blinkstick_device* device = blinkstick_find();
// destroy
blinkstick_destroy(device);
A blinkstick_device holds a pointer to the hid device and is used when setting colors,...
Definition libblinkstick.h:54

Function Documentation

◆ blinkstick_destroy()

BLINKSTICK_API void blinkstick_destroy ( blinkstick_device * device)

Frees the given blinkstick device.

Parameters
devicethe device to free.

◆ blinkstick_find()

BLINKSTICK_API blinkstick_device * blinkstick_find ( )

Find the first blinkstick device on the bus registered with HID.

Note the caller is responsible for deleting the instance of the blinkstick_device using blinkstick_destroy.

Returns
pointer to a blinkstick_device.

◆ blinkstick_find_many()

BLINKSTICK_API blinkstick_device ** blinkstick_find_many ( const int count)

Given a count will return a pointer array of blinkstick devices. This will abort if the number found is less than the given count.

Parameters
countthe number of blinkstick devices to find.
Returns
an array of blinkstick device pointers.

◆ blinkstick_get_color()

BLINKSTICK_API blinkstick_color * blinkstick_get_color ( struct blinkstick_device * blinkstick,
const int index )

Reads the color from the blinkstick at a given index.

Parameters
blinkstickpointer to the blinckstick_device to read from.
indexthe index of the LED to read from.
Returns
pointer to a blinkstick_color struct containing the read color.

◆ blinkstick_get_mode()

BLINKSTICK_API enum blinkstick_mode blinkstick_get_mode ( blinkstick_device * blinkstick)

Read the mode currently set on the blinkstick.

Parameters
blinkstickpointer to the blinkstick device.
Returns
the current mode.

◆ blinkstick_set_color()

BLINKSTICK_API bool blinkstick_set_color ( blinkstick_device * blinkstick,
const int channel,
const int index,
const int red,
const int green,
const int blue )

Sets the LED at the given index and channel to the specified color for the provided device.

Parameters
blinkstickpointer to the blinkstick_device to modify.
channelthe channel to set the LED color on.
indexwhich LED to set the color of.
redthe red component of the new color.
greenthe green component of the new color.
bluethe blue component of the new color.

◆ blinkstick_set_mode()

BLINKSTICK_API bool blinkstick_set_mode ( blinkstick_device * blinkstick,
enum blinkstick_mode mode )

Set the mode of the blinkstick.

Possible modes are "normal" (non-inverse LED control), "inverse" (LED values are inverted) and "smart" (LEDs are WS2812 smart LEDs). Note that you'll need to implement a delay after setting the mode before setting the color on the blinkstick device.