|
C++ Pixels Library For Windows
Enable communications with Pixels dice using Bluetooth Low Energy.
|
Represents a Pixels die. More...
#include <Pixel.h>
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< ConnectResult > | connectAsync () |
| 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< Pixel > | create (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< Pixel > | create (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... | |
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.
|
strong |
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. |
|
overridevirtual |
Gets the Bluetooth address of the Pixel.
Implements Systemic::Pixels::PixelInfo.
|
overridevirtual |
Gets the Pixel battery level (percentage).
Implements Systemic::Pixels::PixelInfo.
| 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.
| Rep | Duration arithmetic type representing the number of ticks. |
| Period | Duration type representing the tick period. |
| duration | Total duration of the animation. |
| rgbColor | Blink color. |
| count | Number of blinks. |
| fade | Amount of in and out fading, 0: sharp transition, 1: maximum fading. |
| std::future< ConnectResult > Systemic::Pixels::Pixel::connectAsync | ( | ) |
Asynchronously tries to connect to the die.
|
static |
Initializes a new instance of Pixel for the device with the given Bluetooth address.
| address | The expected Bluetooth address of the Pixels die. |
| delegate | The object to receive event notifications from this instance. |
|
static |
Initializes a new instance of Pixel for the device corresponding to the given scanned Pixel data.
| scannedPixel | The scanned Pixel data identifying the die. |
| delegate | The object to receive event notifications from this instance. |
|
overridevirtual |
Gets the Pixel face value that is currently facing up.
Implements Systemic::Pixels::PixelInfo.
|
overridevirtual |
Gets the design and color of the Pixel.
Implements Systemic::Pixels::PixelInfo.
|
overridevirtual |
Gets the firmware build date of the Pixel.
Implements Systemic::Pixels::PixelInfo.
|
overridevirtual |
Indicates whether the Pixel battery is charging or not. Set to 'true' if fully charged but still on charger.
Implements Systemic::Pixels::PixelInfo.
| bool Systemic::Pixels::Pixel::isReady | ( | ) | const |
|
overridevirtual |
Gets the number of LEDs of the Pixel.
Implements Systemic::Pixels::PixelInfo.
|
overridevirtual |
|
overridevirtual |
Gets the unique Pixel id of the die.
Implements Systemic::Pixels::PixelInfo.
| 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.
| Rep | Duration arithmetic type representing the number of ticks. |
| Period | Duration type representing the tick period. |
| activate | Whether to turn or turn off this feature. |
| minInterval | The minimum time interval in seconds between two RSSI updates. |
| std::future< bool > Systemic::Pixels::Pixel::reportRssiAsync | ( | bool | activate = true | ) |
Requests the Pixel to regularly send its measured RSSI value.
| activate | Whether to turn or turn off this feature. |
|
overridevirtual |
|
overridevirtual |
Gets the last RSSI value measured by the Pixel.
Implements Systemic::Pixels::PixelInfo.
| 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.
| type | Type of message to send. |
| responseType | Type of the response to expect. |
| 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.
| Rep | Duration arithmetic type representing the number of ticks. |
| Period | Duration type representing the tick period. |
| type | Type of message to send. |
| responseType | Type of the response to expect. |
| timeout | Timeout before aborting waiting for the response. |
| std::future< bool > Systemic::Pixels::Pixel::sendMessageAsync | ( | const T & | message, |
| bool | withoutAck = false |
||
| ) |
Sends a message to the Pixel.
| T | Type of the message. |
| message | Message to send. |
| withoutAck | Whether to request a confirmation that the message was received. |
| std::future< bool > Systemic::Pixels::Pixel::sendMessageAsync | ( | Messages::MessageType | type, |
| bool | withoutAck = false |
||
| ) |
Sends a message to the Pixel.
| type | Type of message to send. |
| withoutAck | Whether to request a confirmation that the message was received. |
| PixelStatus Systemic::Pixels::Pixel::status | ( | ) | const |
|
overridevirtual |
Gets the unique id assigned by the OS to Pixel Bluetooth peripheral.
Implements Systemic::Pixels::PixelInfo.
| std::future< bool > Systemic::Pixels::Pixel::turnOffAsync | ( | ) |
Requests the Pixel to turn itself off.