Pixels Plugin for Unity
Enable communications with Pixels dice using Bluetooth Low Energy.
|
Represents a Pixel die. More...
Classes | |
interface | IOperationEnumerator |
Interface for an enumerator handling an asynchronous operation with a Pixel. More... | |
class | SendMessageAndProcessResponseEnumerator |
Enumerator that first sends a message to a Pixel, then waits for a message of the given type as the response and pass it to a user callback. More... | |
class | SendMessageAndProcessResponseWithValueEnumerator |
Enumerator that first sends a message to a Pixel, then waits for a message of the given type as the response and pass it to a user callback. The value returned by the callback is stored in the Value property. More... | |
class | SendMessageAndWaitForResponseEnumerator |
Enumerator that first sends a message to a Pixel and then waits for a message of the given type as the response. More... | |
class | WaitForMessageEnumerator |
Enumerator that waits until the Pixel receives a message of the given type. More... | |
Public Member Functions | |
void | SubscribeToUserNotifyRequest (NotifyUserCallback notifyUserCallback) |
Subscribe to requests send by the Pixel to notify user. | |
void | SubscribeToPlayAudioClipRequest (PlayAudioClipCallback playAudioClipCallback) |
Subscribes to requests send by the Pixel to play an audio clip. | |
IEnumerator | UploadBulkDataAsync (byte[] bytes, OperationResultCallback onResult=null, OperationProgressCallback onProgress=null) |
Asynchronously uploads the given data to the Pixel flash memory. | |
IEnumerator | DownloadBulkDataAsync (DataOperationResultCallback onResult, OperationProgressCallback onProgress=null) |
Asynchronously downloads the data from the Pixel flash memory. | |
IEnumerator | UploadDataSetAsync (DataSet dataSet, OperationResultCallback onResult=null, OperationProgressCallback onProgress=null) |
Asynchronously uploads the given data set of animations to the Pixel flash memory. | |
IEnumerator | PlayInstantAnimationAsync (DataSet testAnimSet, OperationResultCallback onResult=null, OperationProgressCallback onProgress=null) |
Asynchronously plays the (single) LEDs animation included in the given data set. | |
void | PlayAnimation (int animationIndex, int remapFace=0, bool loop=false) |
Sends a message to the Pixel to play the animation stored at the given index with face optional remapping and looping. | |
void | StopAnimation (int animationIndex, int remapFace=0) |
Sends a message to the Pixel to stop playing the animation stored on the Pixel at the given index with face remapping. | |
IEnumerator | GetRollStateAsync (OperationResultCallback onResult=null) |
Sends a message to the Pixel to update the instance rollState and currentFace properties. | |
IEnumerator | UpdateInfoAsync (OperationResultCallback onResult=null) |
Sends a message to the Pixel to update the instance information. | |
void | ReportTelemetry (bool activate) |
Sends a message to the Pixel to turn telemetry on or off. | |
void | ReportRssi (bool activate) |
Sends a message to the Pixel to make it report the rssi value. | |
void | UpdateTemperature (OperationResultCallback onResult=null) |
Sends a message to the Pixel to update the mcuTemperature and batteryTemperature properties. | |
IEnumerator | RenameAsync (string name, OperationResultCallback onResult=null) |
Sends a message to the Pixel to change its name. | |
IEnumerator | BlinkLEDsAsync (Color color, int count=1, float duration=1, float fade=0.5f, OperationResultCallback onResult=null) |
Sends a message to the Pixel to make its LEDs blink a given number of time. | |
void | StartCalibration () |
Sends a message to the Pixel to start die calibration. | |
void | CalibrateFace (int face) |
Sends a message to the Pixel to start face calibration. | |
void | SetStandardMode () |
Sends a message to the Pixel to set it to standard mode (the default which plays animations based on roll events). | |
void | SetLEDAnimatorMode () |
Sends a message to the Pixel to set it to LED animator mode. | |
void | ResetParameters () |
Sends a message to the Pixel to reset its parameters. | |
Public Attributes | |
ConnectionStateChangedEventHandler | ConnectionStateChanged |
Event raised when the Pixel connection state changes. | |
ErrorRaisedEventHandler | ErrorEncountered |
Event raised when communications with the Pixel encountered an error. | |
AppearanceChangedEventHandler | AppearanceChanged |
Event raised when the Pixel appearance setting is changed. | |
RollStateChangedEventHandler | RollStateChanged |
Event raised when the Pixel roll state changes. | |
BatteryLevelChangedEventHandler | BatteryLevelChanged |
Event raised when the battery level reported by the Pixel changes. | |
TemperatureChangedEventHandler | TemperatureChanged |
Event raised when the temperature reported by the Pixel changes. | |
Static Public Attributes | |
const float | AckMessageTimeout = 5 |
The timeout in seconds for waiting the response of a message send to a Pixel. | |
Protected Member Functions | |
delegate void | MessageReceivedEventHandler (IPixelMessage message) |
Internal event handler for message notification. | |
IOperationEnumerator | SendMessageAsync (byte[] bytes, float timeout=0) |
Abstract method to send a message to the Pixel. | |
void | EnsureRunningOnMainThread () |
Helper to method to check if we are running on the main thread. Throws an exception if running on another thread. | |
void | AddMessageHandler (MessageType messageType, MessageReceivedEventHandler eventHandler) |
Add an event hander for the given message type. | |
void | RemoveMessageHandler (MessageType messageType, MessageReceivedEventHandler eventHandler) |
Remove an event hander for the given message type. | |
void | NotifyMessageHandler (IPixelMessage message) |
Notify the event handlers for the given message, based on its type. | |
void | PostMessage< T > (T message) |
Starts a coroutine that sends a message to the Pixel. | |
virtual void | RegisterDefaultMessageHandlers () |
Register the default message handlers, called once during instance initialization. | |
void | NotifyRollState (PixelRollState state, byte faceIndex) |
void | NotifyBatteryLevel (int level, PixelBatteryState state) |
void | NotifyBatteryLevel (int level, bool charging) |
void | NotifyRssi (int newRssi) |
void | NotifyTemperature (int newMcuTempTimes100, int newBatteryTempTimes100) |
virtual void | OnDestroy () |
Properties | |
PixelConnectionState | connectionState [get, protected set] |
Gets the connection state to the Pixel. | |
bool | isAvailable [get] |
Indicates whether the connection state is set to available, meaning the Pixel can be connected to. | |
bool | isReady [get] |
Indicates whether the connection state is set to ready, meaning the Pixel is connected and ready to communicate. | |
PixelError | lastError [get, protected set] |
Get the last error that happened during communications with the Pixel. | |
string | systemId [get, protected set] |
Gets the unique system id assigned to the Pixel. This value is platform specific and may change over long periods of time. | |
uint | pixelId [get, protected set] |
Gets the Pixel unique device id. | |
int | ledCount [get, protected set] |
Gets the number of LEDs for the Pixel. | |
PixelColorway | colorway = PixelColorway.Unknown [get, protected set] |
Gets the Pixel combination of design and color. | |
PixelDieType | dieType = PixelDieType.Unknown [get, protected set] |
Gets the die type of the Pixel. | |
int | dieFaceCount [get] |
Gets the number of faces of the Pixel. | |
uint | buildTimestamp [get, protected set] |
Gets the Pixel firmware build Unix timestamp. | |
System.DateTime | buildDateTime [get] |
Gets the Pixel firmware build data/time. | |
uint | dataSetHash [get, protected set] |
Get the hash value of the animation data loaded on the Pixel. | |
uint | availableFlashSize [get, protected set] |
Get the size of memory that can be used to store animation data on the Pixel. | |
PixelRollState | rollState = PixelRollState.Unknown [get] |
Gets the Pixel current roll state. | |
int | currentFace [get] |
Gets Pixel the current face that is up. | |
int | currentFaceIndex [get] |
Gets the 0-based index of the die face that is currently facing up. | |
int | batteryLevel [get] |
Gets the Pixel last read battery level in percent. | |
bool | isCharging [get] |
Indicates whether or not the Pixel was last reported as charging. | |
int | rssi [get] |
Gets the Pixel last read Received Signal Strength Indicator (RSSI) value. | |
float | mcuTemperature [get] |
Pixel micro-controller temperature in degree Celsius. | |
float | batteryTemperature [get] |
Pixel battery temperature in degree Celsius. | |
RssiChangedEventHandler | RssiChanged |
Event raised when the RSSI value reported by the Pixel changes. | |
TelemetryEventHandler | TelemetryReceived |
Event raised when telemetry data is received. | |
string | SafeName [get] |
Use this property to access the Pixel name without having to first check if the object is considered destroyed by Unity (to avoid generating an error). | |
Represents a Pixel die.
This class offers access to many settings and features of a Pixel. This abstract class does not implement a specific communication protocol with the dice, leaving the door open to have multiple implementations including a virtual die. Currently only Bluetooth communications are supported, see DiceBag to connect to and communicate with Bluetooth Low Energy Pixel dice.
The Pixel name is given by the parent class MonoBehaviour name property.
|
protected |
Add an event hander for the given message type.
messageType | The type of message to subscribe to. |
eventHandler | The event handler to add. |
IEnumerator Systemic.Unity.Pixels.Pixel.BlinkLEDsAsync | ( | Color | color, |
int | count = 1 , |
||
float | duration = 1 , |
||
float | fade = 0::5f , |
||
OperationResultCallback | onResult = null |
||
) |
Sends a message to the Pixel to make its LEDs blink a given number of time.
color | The desired color for the LEDs. |
count | The number of blinks. |
duration | Duration of the animation in seconds. |
onResult | An optional callback that is called when the operation completes successfully (true) or not (false) with an error message. |
void Systemic.Unity.Pixels.Pixel.CalibrateFace | ( | int | face | ) |
Sends a message to the Pixel to start face calibration.
face |
IEnumerator Systemic.Unity.Pixels.Pixel.DownloadBulkDataAsync | ( | DataOperationResultCallback | onResult, |
OperationProgressCallback | onProgress = null |
||
) |
Asynchronously downloads the data from the Pixel flash memory.
onResult | A callback that is called when the operation completes, with the received data if successful or null and an error message on failure. |
onProgress | An optional callback that is called as the operation progresses with the progress value being between 0 an 1. |
IEnumerator Systemic.Unity.Pixels.Pixel.GetRollStateAsync | ( | OperationResultCallback | onResult = null | ) |
Sends a message to the Pixel to update the instance rollState and currentFace properties.
onResult | An optional callback that is called when the operation completes successfully (true) or not (false) with an error message. |
|
protected |
Internal event handler for message notification.
message | The message object. |
|
protected |
Notify the event handlers for the given message, based on its type.
message | The message object. |
void Systemic.Unity.Pixels.Pixel.PlayAnimation | ( | int | animationIndex, |
int | remapFace = 0 , |
||
bool | loop = false |
||
) |
Sends a message to the Pixel to play the animation stored at the given index with face optional remapping and looping.
animationIndex | The stored index of the animation to play. |
remapFace | The index of the face to remap the animation to. |
loop | Whether to loop the animation. |
IEnumerator Systemic.Unity.Pixels.Pixel.PlayInstantAnimationAsync | ( | DataSet | testAnimSet, |
OperationResultCallback | onResult = null , |
||
OperationProgressCallback | onProgress = null |
||
) |
Asynchronously plays the (single) LEDs animation included in the given data set.
testAnimSet | The data set containing just one animation to play. |
onResult | An optional callback that is called when the operation completes successfully (true) or not (false) with an error message. |
onProgress | An optional callback that is called as the operation progresses with the progress value being between 0 an 1. |
|
protected |
Starts a coroutine that sends a message to the Pixel.
T | Type of the message. |
message | The message instance to send. |
T | : | IPixelMessage |
|
protected |
Remove an event hander for the given message type.
messageType | The type of message to unsubscribe from. |
eventHandler | The event handler to remove. |
IEnumerator Systemic.Unity.Pixels.Pixel.RenameAsync | ( | string | name, |
OperationResultCallback | onResult = null |
||
) |
Sends a message to the Pixel to change its name.
name | The name to set. |
onResult | An optional callback that is called when the operation completes successfully (true) or not (false) with an error message. |
void Systemic.Unity.Pixels.Pixel.ReportRssi | ( | bool | activate | ) |
Sends a message to the Pixel to make it report the rssi value.
activate | Whether to turn RSSI reporting on or off. |
void Systemic.Unity.Pixels.Pixel.ReportTelemetry | ( | bool | activate | ) |
Sends a message to the Pixel to turn telemetry on or off.
activate | Whether to turn telemetry reporting on or off. |
|
abstractprotected |
Abstract method to send a message to the Pixel.
bytes | |
timeout |
void Systemic.Unity.Pixels.Pixel.StopAnimation | ( | int | animationIndex, |
int | remapFace = 0 |
||
) |
Sends a message to the Pixel to stop playing the animation stored on the Pixel at the given index with face remapping.
animationIndex | The stored index of the animation to stop playing. |
remapFace | The index of the face to remap the animation to. |
void Systemic.Unity.Pixels.Pixel.SubscribeToPlayAudioClipRequest | ( | PlayAudioClipCallback | playAudioClipCallback | ) |
Subscribes to requests send by the Pixel to play an audio clip.
Replaces the callback passed in a previous call to this method.
playAudioClipCallback | The callback to run, pass null to unsubscribe. |
void Systemic.Unity.Pixels.Pixel.SubscribeToUserNotifyRequest | ( | NotifyUserCallback | notifyUserCallback | ) |
Subscribe to requests send by the Pixel to notify user.
Replaces the callback passed in a previous call to this method.
notifyUserCallback | The callback to run, pass null to unsubscribe. |
IEnumerator Systemic.Unity.Pixels.Pixel.UpdateInfoAsync | ( | OperationResultCallback | onResult = null | ) |
Sends a message to the Pixel to update the instance information.
On success, this will update the ledCount, designAndColor, dataSetHash, availableFlashSize and firmwareVersion properties and raise the AppearanceChanged event if the face out or design and color have changed.
onResult | An optional callback that is called when the operation completes successfully (true) or not (false) with an error message. |
void Systemic.Unity.Pixels.Pixel.UpdateTemperature | ( | OperationResultCallback | onResult = null | ) |
Sends a message to the Pixel to update the mcuTemperature and batteryTemperature properties.
onResult |
IEnumerator Systemic.Unity.Pixels.Pixel.UploadBulkDataAsync | ( | byte[] | bytes, |
OperationResultCallback | onResult = null , |
||
OperationProgressCallback | onProgress = null |
||
) |
Asynchronously uploads the given data to the Pixel flash memory.
bytes | The data to upload. |
onResult | An optional callback that is called when the operation completes successfully (true) or not (false) with an error message. |
onProgress | An optional callback that is called as the operation progresses with the progress value being between 0 an 1. |
IEnumerator Systemic.Unity.Pixels.Pixel.UploadDataSetAsync | ( | DataSet | dataSet, |
OperationResultCallback | onResult = null , |
||
OperationProgressCallback | onProgress = null |
||
) |
Asynchronously uploads the given data set of animations to the Pixel flash memory.
dataSet | The data set to upload. |
onResult | An optional callback that is called when the operation completes successfully (true) or not (false) with an error message. |
onProgress | An optional callback that is called as the operation progresses with the progress value being between 0 an 1. |
|
getprotected set |
Get the size of memory that can be used to store animation data on the Pixel.
This value is set once when the Pixel is being connected.
|
get |
Gets the Pixel last read battery level in percent.
This value is set when the Pixel is being scanned and UpdateBatteryLevelAsync(OperationResultCallback) is called while connected.
|
get |
Gets the Pixel firmware build data/time.
This value is the buildTimestamp converted to a DataTime value.
|
getprotected set |
Gets the Pixel firmware build Unix timestamp.
This value is set when the Pixel is being scanned or when connected.
|
getprotected set |
Gets the Pixel combination of design and color.
This value is set when the Pixel is being scanned or once when connected.
|
get |
Gets Pixel the current face that is up.
Fudge die returns +1, 0 and -1. This value is set when the Pixel is being scanned or when connected.
|
get |
Gets the 0-based index of the die face that is currently facing up.
This value is set when the Pixel is being scanned or when connected.
|
getprotected set |
Get the hash value of the animation data loaded on the Pixel.
This value is set once when the Pixel is being connected.
|
getprotected set |
Gets the die type of the Pixel.
This value is set when the Pixel is being scanned or once when connected.
|
get |
Indicates whether or not the Pixel was last reported as charging.
This value is only set when UpdateBatteryLevelAsync(OperationResultCallback) is called while connected.
|
getprotected set |
Gets the number of LEDs for the Pixel.
This value is set when the Pixel is being scanned or once when connected.
|
getprotected set |
Gets the Pixel unique device id.
This value is set when the Pixel is being scanned or when connected.
|
get |
Gets the Pixel current roll state.
This value is set when the Pixel is being scanned or when connected.
|
get |
Gets the Pixel last read Received Signal Strength Indicator (RSSI) value.
This value is set when the Pixel is being scanned or when UpdateRssiAsync(OperationResultCallback) is called while connected.