C++ Pixels Library For Windows
Enable communications with Pixels dice using Bluetooth Low Energy.
Loading...
Searching...
No Matches
Systemic::Pixels::Pixel Class Reference

Represents a Pixels die. More...

#include <Pixel.h>

Inheritance diagram for Systemic::Pixels::Pixel:

Public Types

enum class  ConnectResult {
  Success , ConnectionFailed , Cancelled , IdentificationMismatch ,
  IdentificationTimeout , SubscriptionError
}
 List of possible Pixel connection results. More...
 
- Public Types inherited from Systemic::Pixels::PixelInfo
using Date = std::chrono::system_clock::time_point
 Type for a system Date.
 

Public Member Functions

virtual ~Pixel ()=default
 Default virtual destructor.
 
PixelStatus status () const
 Gets the last known connection status of the Pixel. More...
 
bool isReady () const
 Indicates whether the Pixel status is "ready". More...
 
virtual bluetooth_address_t systemId () const override
 Gets the unique id assigned by the OS to Pixel Bluetooth peripheral. More...
 
virtual bluetooth_address_t address () const override
 Gets the Bluetooth address of the Pixel. More...
 
virtual pixel_id_t pixelId () const override
 Gets the unique Pixel id of the die. More...
 
virtual const std::wstring & name () const override
 Gets the Pixel name. More...
 
virtual int ledCount () const override
 Gets the number of LEDs of the Pixel. More...
 
virtual PixelDesignAndColor designAndColor () const override
 Gets the design and color of the Pixel. More...
 
virtual Date firmwareDate () const override
 Gets the firmware build date of the Pixel. More...
 
virtual int rssi () const override
 Gets the last RSSI value measured by the Pixel. More...
 
virtual int batteryLevel () const override
 Gets the Pixel battery level (percentage). More...
 
virtual bool isCharging () const override
 Indicates whether the Pixel battery is charging or not. Set to 'true' if fully charged but still on charger. More...
 
virtual PixelRollState rollState () const override
 Gets the Pixel roll state. More...
 
virtual int currentFace () const override
 Gets the Pixel face value that is currently facing up. More...
 
std::future< ConnectResultconnectAsync ()
 Asynchronously tries to connect to the die. More...
 
void disconnect ()
 Immediately disconnects from the die.
 
std::future< bool > sendMessageAsync (Messages::MessageType type, bool withoutAck=false)
 Sends a message to the Pixel. More...
 
template<typename T , std::enable_if_t< std::is_base_of_v< Messages::PixelMessage, T >, int > = 0>
std::future< bool > sendMessageAsync (const T &message, bool withoutAck=false)
 Sends a message to the Pixel. More...
 
template<class Rep , class Period >
std::future< std::shared_ptr< const Messages::PixelMessage > > sendAndWaitForResponseAsync (Messages::MessageType type, Messages::MessageType responseType, std::chrono::duration< Rep, Period > timeout=std::chrono::seconds(5))
 Sends a message to the Pixel and wait for a specific reply. More...
 
std::future< std::shared_ptr< const Messages::PixelMessage > > sendAndWaitForResponseAsync (Messages::MessageType type, Messages::MessageType responseType)
 Sends a message to the Pixel and wait for a specific reply. More...
 
template<class Rep , class Period >
std::future< bool > reportRssiAsync (bool activate, std::chrono::duration< Rep, Period > minInterval)
 Requests the Pixel to regularly send its measured RSSI value. More...
 
std::future< bool > reportRssiAsync (bool activate=true)
 Requests the Pixel to regularly send its measured RSSI value. More...
 
std::future< bool > turnOffAsync ()
 Requests the Pixel to turn itself off. More...
 
template<class Rep , class Period >
std::future< bool > blinkAsync (std::chrono::duration< Rep, Period > duration, uint32_t rgbColor, int count=1, float fade=1)
 Requests the Pixel to blink. More...
 
- Public Member Functions inherited from Systemic::Pixels::PixelInfo
virtual bluetooth_address_t systemId () const =0
 Gets the unique id assigned by the OS to Pixel Bluetooth peripheral. More...
 
virtual bluetooth_address_t address () const =0
 Gets the Bluetooth address of the Pixel. More...
 
virtual pixel_id_t pixelId () const =0
 Gets the unique Pixel id of the die. More...
 
virtual const std::wstring & name () const =0
 Gets the Pixel name. More...
 
virtual int ledCount () const =0
 Gets the number of LEDs of the Pixel. More...
 
virtual PixelDesignAndColor designAndColor () const =0
 Gets the design and color of the Pixel. More...
 
virtual Date firmwareDate () const =0
 Gets the firmware build date of the Pixel. More...
 
virtual int rssi () const =0
 Gets the last RSSI value measured by the Pixel. More...
 
virtual int batteryLevel () const =0
 Gets the Pixel battery level (percentage). More...
 
virtual bool isCharging () const =0
 Indicates whether the Pixel battery is charging or not. Set to 'true' if fully charged but still on charger. More...
 
virtual PixelRollState rollState () const =0
 Gets the Pixel roll state. More...
 
virtual int currentFace () const =0
 Gets the Pixel face value that is currently facing up. More...
 
DieType dieType ()
 Gets die type of the Pixel. More...
 
int dieFaceCount ()
 Gets the number of faces of the Pixel. More...
 

Static Public Member Functions

static std::shared_ptr< Pixelcreate (bluetooth_address_t address, std::shared_ptr< PixelDelegate > delegate=nullptr)
 Initializes a new instance of Pixel for the device with the given Bluetooth address. More...
 
static std::shared_ptr< Pixelcreate (const ScannedPixel &scannedPixel, std::shared_ptr< PixelDelegate > delegate=nullptr)
 Initializes a new instance of Pixel for the device corresponding to the given scanned Pixel data. More...
 

Detailed Description

Represents a Pixels die.

The delegate object passed to the constructor is used to notify of events such as connection status changes or rolls.

Call the connectAsync() method to initiate a connection with the physical die.

This class is thread safe.

Member Enumeration Documentation

◆ ConnectResult

List of possible Pixel connection results.

Enumerator
Success 

Connection has succeeded.

ConnectionFailed 

Connection with the actual device failed.

Cancelled 

Connection was canceled (usually because of a call to Pixel.disconnect()).

IdentificationMismatch 

Connection failed because the die Pixel id is not the expected one.

IdentificationTimeout 

Connection failed because the die didn't identify itself in time.

SubscriptionError 

Connection failed because subscribing to the Bluetooth characteristic failed.

Member Function Documentation

◆ address()

virtual bluetooth_address_t Systemic::Pixels::Pixel::address ( ) const
overridevirtual

Gets the Bluetooth address of the Pixel.

Returns
The Bluetooth address of the Pixel.

Implements Systemic::Pixels::PixelInfo.

◆ batteryLevel()

virtual int Systemic::Pixels::Pixel::batteryLevel ( ) const
overridevirtual

Gets the Pixel battery level (percentage).

Returns
The Pixel battery level (percentage).

Implements Systemic::Pixels::PixelInfo.

◆ blinkAsync()

template<class Rep , class Period >
std::future< bool > Systemic::Pixels::Pixel::blinkAsync ( std::chrono::duration< Rep, Period >  duration,
uint32_t  rgbColor,
int  count = 1,
float  fade = 1 
)

Requests the Pixel to blink.

Template Parameters
RepDuration arithmetic type representing the number of ticks.
PeriodDuration type representing the tick period.
Parameters
durationTotal duration of the animation.
rgbColorBlink color.
countNumber of blinks.
fadeAmount of in and out fading, 0: sharp transition, 1: maximum fading.
Returns
A future with a boolean indicating whether the operation succeeded.

◆ connectAsync()

std::future< ConnectResult > Systemic::Pixels::Pixel::connectAsync ( )

Asynchronously tries to connect to the die.

Note
The request times out after 7 to 20s if device is not reachable.
Returns
A future with the result of the operation.

◆ create() [1/2]

static std::shared_ptr< Pixel > Systemic::Pixels::Pixel::create ( bluetooth_address_t  address,
std::shared_ptr< PixelDelegate delegate = nullptr 
)
static

Initializes a new instance of Pixel for the device with the given Bluetooth address.

Parameters
addressThe expected Bluetooth address of the Pixels die.
delegateThe object to receive event notifications from this instance.
Returns
A Pixel instance in a shared pointer.
Note
The delegate virtual methods should not block the thread and complete their operations quickly.

◆ create() [2/2]

static std::shared_ptr< Pixel > Systemic::Pixels::Pixel::create ( const ScannedPixel scannedPixel,
std::shared_ptr< PixelDelegate delegate = nullptr 
)
static

Initializes a new instance of Pixel for the device corresponding to the given scanned Pixel data.

Parameters
scannedPixelThe scanned Pixel data identifying the die.
delegateThe object to receive event notifications from this instance.
Returns
A Pixel instance in a shared pointer.
Note
The delegate virtual methods should not block the thread and complete their operations quickly.

◆ currentFace()

virtual int Systemic::Pixels::Pixel::currentFace ( ) const
overridevirtual

Gets the Pixel face value that is currently facing up.

Returns
The Pixel face value that is currently facing up.

Implements Systemic::Pixels::PixelInfo.

◆ designAndColor()

virtual PixelDesignAndColor Systemic::Pixels::Pixel::designAndColor ( ) const
overridevirtual

Gets the design and color of the Pixel.

Returns
The design and color of the Pixel.

Implements Systemic::Pixels::PixelInfo.

◆ firmwareDate()

virtual Date Systemic::Pixels::Pixel::firmwareDate ( ) const
overridevirtual

Gets the firmware build date of the Pixel.

Returns
The firmware build date of the Pixel.

Implements Systemic::Pixels::PixelInfo.

◆ isCharging()

virtual bool Systemic::Pixels::Pixel::isCharging ( ) const
overridevirtual

Indicates whether the Pixel battery is charging or not. Set to 'true' if fully charged but still on charger.

Returns
Whether the Pixel battery is charging or not.

Implements Systemic::Pixels::PixelInfo.

◆ isReady()

bool Systemic::Pixels::Pixel::isReady ( ) const

Indicates whether the Pixel status is "ready".

Returns
Whether the Pixel status is "ready".

◆ ledCount()

virtual int Systemic::Pixels::Pixel::ledCount ( ) const
overridevirtual

Gets the number of LEDs of the Pixel.

Returns
The number of LEDs of the Pixel.

Implements Systemic::Pixels::PixelInfo.

◆ name()

virtual const std::wstring & Systemic::Pixels::Pixel::name ( ) const
overridevirtual

Gets the Pixel name.

Returns
The Pixel name.

Implements Systemic::Pixels::PixelInfo.

◆ pixelId()

virtual pixel_id_t Systemic::Pixels::Pixel::pixelId ( ) const
overridevirtual

Gets the unique Pixel id of the die.

Returns
The unique Pixel id of the die.

Implements Systemic::Pixels::PixelInfo.

◆ reportRssiAsync() [1/2]

template<class Rep , class Period >
std::future< bool > Systemic::Pixels::Pixel::reportRssiAsync ( bool  activate,
std::chrono::duration< Rep, Period >  minInterval 
)

Requests the Pixel to regularly send its measured RSSI value.

Template Parameters
RepDuration arithmetic type representing the number of ticks.
PeriodDuration type representing the tick period.
Parameters
activateWhether to turn or turn off this feature.
minIntervalThe minimum time interval in seconds between two RSSI updates.
Returns
A future with a boolean indicating whether the operation succeeded.

◆ reportRssiAsync() [2/2]

std::future< bool > Systemic::Pixels::Pixel::reportRssiAsync ( bool  activate = true)

Requests the Pixel to regularly send its measured RSSI value.

Parameters
activateWhether to turn or turn off this feature.
Returns
A future with a boolean indicating whether the operation succeeded.

◆ rollState()

virtual PixelRollState Systemic::Pixels::Pixel::rollState ( ) const
overridevirtual

Gets the Pixel roll state.

Returns
The Pixel roll state.

Implements Systemic::Pixels::PixelInfo.

◆ rssi()

virtual int Systemic::Pixels::Pixel::rssi ( ) const
overridevirtual

Gets the last RSSI value measured by the Pixel.

Returns
The last RSSI value measured by the Pixel.

Implements Systemic::Pixels::PixelInfo.

◆ sendAndWaitForResponseAsync() [1/2]

std::future< std::shared_ptr< const Messages::PixelMessage > > Systemic::Pixels::Pixel::sendAndWaitForResponseAsync ( Messages::MessageType  type,
Messages::MessageType  responseType 
)

Sends a message to the Pixel and wait for a specific reply.

Parameters
typeType of message to send.
responseTypeType of the response to expect.
Returns
A message object or nullptr in a shared pointer.

◆ sendAndWaitForResponseAsync() [2/2]

template<class Rep , class Period >
std::future< std::shared_ptr< const Messages::PixelMessage > > Systemic::Pixels::Pixel::sendAndWaitForResponseAsync ( Messages::MessageType  type,
Messages::MessageType  responseType,
std::chrono::duration< Rep, Period >  timeout = std::chrono::seconds(5) 
)

Sends a message to the Pixel and wait for a specific reply.

Template Parameters
RepDuration arithmetic type representing the number of ticks.
PeriodDuration type representing the tick period.
Parameters
typeType of message to send.
responseTypeType of the response to expect.
timeoutTimeout before aborting waiting for the response.
Returns
A message object or nullptr in a shared pointer.

◆ sendMessageAsync() [1/2]

template<typename T , std::enable_if_t< std::is_base_of_v< Messages::PixelMessage, T >, int > = 0>
std::future< bool > Systemic::Pixels::Pixel::sendMessageAsync ( const T &  message,
bool  withoutAck = false 
)

Sends a message to the Pixel.

Template Parameters
TType of the message.
Parameters
messageMessage to send.
withoutAckWhether to request a confirmation that the message was received.
Returns
A future with a boolean indicating whether the operation succeeded.

◆ sendMessageAsync() [2/2]

std::future< bool > Systemic::Pixels::Pixel::sendMessageAsync ( Messages::MessageType  type,
bool  withoutAck = false 
)

Sends a message to the Pixel.

Parameters
typeType of message to send.
withoutAckWhether to request a confirmation that the message was received.
Returns
A future with a boolean indicating whether the operation succeeded.

◆ status()

PixelStatus Systemic::Pixels::Pixel::status ( ) const

Gets the last known connection status of the Pixel.

Returns
The last known connection status of the Pixel.

◆ systemId()

virtual bluetooth_address_t Systemic::Pixels::Pixel::systemId ( ) const
overridevirtual

Gets the unique id assigned by the OS to Pixel Bluetooth peripheral.

Note
This member exist only to keep similar interface than other implementations, the Bluetooth address is returned.
Returns
The unique id for the Pixel.

Implements Systemic::Pixels::PixelInfo.

◆ turnOffAsync()

std::future< bool > Systemic::Pixels::Pixel::turnOffAsync ( )

Requests the Pixel to turn itself off.

Returns
A future with a boolean indicating whether the operation succeeded.

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