Pixels Plugin for Unity
Enable communications with Pixels dice using Bluetooth Low Energy.
Loading...
Searching...
No Matches
Systemic.Unity.Pixels.Pixel Class Referenceabstract

Represents a Pixel die. More...

Inheritance diagram for Systemic.Unity.Pixels.Pixel:

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).
 

Detailed Description

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.

Member Function Documentation

◆ AddMessageHandler()

void Systemic.Unity.Pixels.Pixel.AddMessageHandler ( MessageType  messageType,
MessageReceivedEventHandler  eventHandler 
)
protected

Add an event hander for the given message type.

Parameters
messageTypeThe type of message to subscribe to.
eventHandlerThe event handler to add.

◆ BlinkLEDsAsync()

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.

Parameters
colorThe desired color for the LEDs.
countThe number of blinks.
durationDuration of the animation in seconds.
onResultAn optional callback that is called when the operation completes successfully (true) or not (false) with an error message.
Returns
An enumerator meant to be run as a coroutine.

◆ CalibrateFace()

void Systemic.Unity.Pixels.Pixel.CalibrateFace ( int  face)

Sends a message to the Pixel to start face calibration.

Parameters
face

◆ DownloadBulkDataAsync()

IEnumerator Systemic.Unity.Pixels.Pixel.DownloadBulkDataAsync ( DataOperationResultCallback  onResult,
OperationProgressCallback  onProgress = null 
)

Asynchronously downloads the data from the Pixel flash memory.

Parameters
onResultA callback that is called when the operation completes, with the received data if successful or null and an error message on failure.
onProgressAn optional callback that is called as the operation progresses with the progress value being between 0 an 1.
Returns
An enumerator meant to be run as a coroutine.

◆ GetRollStateAsync()

IEnumerator Systemic.Unity.Pixels.Pixel.GetRollStateAsync ( OperationResultCallback  onResult = null)

Sends a message to the Pixel to update the instance rollState and currentFace properties.

Parameters
onResultAn optional callback that is called when the operation completes successfully (true) or not (false) with an error message.
Returns
An enumerator meant to be run as a coroutine.

◆ MessageReceivedEventHandler()

delegate void Systemic.Unity.Pixels.Pixel.MessageReceivedEventHandler ( IPixelMessage  message)
protected

Internal event handler for message notification.

Parameters
messageThe message object.

◆ NotifyMessageHandler()

void Systemic.Unity.Pixels.Pixel.NotifyMessageHandler ( IPixelMessage  message)
protected

Notify the event handlers for the given message, based on its type.

Parameters
messageThe message object.

◆ PlayAnimation()

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.

Parameters
animationIndexThe stored index of the animation to play.
remapFaceThe index of the face to remap the animation to.
loopWhether to loop the animation.

◆ PlayInstantAnimationAsync()

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.

Parameters
testAnimSetThe data set containing just one animation to play.
onResultAn optional callback that is called when the operation completes successfully (true) or not (false) with an error message.
onProgressAn optional callback that is called as the operation progresses with the progress value being between 0 an 1.
Returns
An enumerator meant to be run as a coroutine.

◆ PostMessage< T >()

void Systemic.Unity.Pixels.Pixel.PostMessage< T > ( message)
protected

Starts a coroutine that sends a message to the Pixel.

Template Parameters
TType of the message.
Parameters
messageThe message instance to send.
Type Constraints
T :IPixelMessage 

◆ RemoveMessageHandler()

void Systemic.Unity.Pixels.Pixel.RemoveMessageHandler ( MessageType  messageType,
MessageReceivedEventHandler  eventHandler 
)
protected

Remove an event hander for the given message type.

Parameters
messageTypeThe type of message to unsubscribe from.
eventHandlerThe event handler to remove.

◆ RenameAsync()

IEnumerator Systemic.Unity.Pixels.Pixel.RenameAsync ( string  name,
OperationResultCallback  onResult = null 
)

Sends a message to the Pixel to change its name.

Parameters
nameThe name to set.
onResultAn optional callback that is called when the operation completes successfully (true) or not (false) with an error message.
Returns
An enumerator meant to be run as a coroutine.

◆ ReportRssi()

void Systemic.Unity.Pixels.Pixel.ReportRssi ( bool  activate)

Sends a message to the Pixel to make it report the rssi value.

Parameters
activateWhether to turn RSSI reporting on or off.

◆ ReportTelemetry()

void Systemic.Unity.Pixels.Pixel.ReportTelemetry ( bool  activate)

Sends a message to the Pixel to turn telemetry on or off.

Parameters
activateWhether to turn telemetry reporting on or off.

◆ SendMessageAsync()

IOperationEnumerator Systemic.Unity.Pixels.Pixel.SendMessageAsync ( byte[]  bytes,
float  timeout = 0 
)
abstractprotected

Abstract method to send a message to the Pixel.

Parameters
bytes
timeout
Returns

◆ StopAnimation()

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.

Parameters
animationIndexThe stored index of the animation to stop playing.
remapFaceThe index of the face to remap the animation to.

◆ SubscribeToPlayAudioClipRequest()

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.

Parameters
playAudioClipCallbackThe callback to run, pass null to unsubscribe.

◆ SubscribeToUserNotifyRequest()

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.

Parameters
notifyUserCallbackThe callback to run, pass null to unsubscribe.

◆ UpdateInfoAsync()

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.

Parameters
onResultAn optional callback that is called when the operation completes successfully (true) or not (false) with an error message.
Returns
An enumerator meant to be run as a coroutine.

◆ UpdateTemperature()

void Systemic.Unity.Pixels.Pixel.UpdateTemperature ( OperationResultCallback  onResult = null)

Sends a message to the Pixel to update the mcuTemperature and batteryTemperature properties.

Parameters
onResult

◆ UploadBulkDataAsync()

IEnumerator Systemic.Unity.Pixels.Pixel.UploadBulkDataAsync ( byte[]  bytes,
OperationResultCallback  onResult = null,
OperationProgressCallback  onProgress = null 
)

Asynchronously uploads the given data to the Pixel flash memory.

Parameters
bytesThe data to upload.
onResultAn optional callback that is called when the operation completes successfully (true) or not (false) with an error message.
onProgressAn optional callback that is called as the operation progresses with the progress value being between 0 an 1.
Returns
An enumerator meant to be run as a coroutine.

◆ UploadDataSetAsync()

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.

Parameters
dataSetThe data set to upload.
onResultAn optional callback that is called when the operation completes successfully (true) or not (false) with an error message.
onProgressAn optional callback that is called as the operation progresses with the progress value being between 0 an 1.
Returns
An enumerator meant to be run as a coroutine.

Property Documentation

◆ availableFlashSize

uint Systemic.Unity.Pixels.Pixel.availableFlashSize
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.

◆ batteryLevel

int Systemic.Unity.Pixels.Pixel.batteryLevel
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.

◆ buildDateTime

System.DateTime Systemic.Unity.Pixels.Pixel.buildDateTime
get

Gets the Pixel firmware build data/time.

This value is the buildTimestamp converted to a DataTime value.

◆ buildTimestamp

uint Systemic.Unity.Pixels.Pixel.buildTimestamp
getprotected set

Gets the Pixel firmware build Unix timestamp.

This value is set when the Pixel is being scanned or when connected.

◆ colorway

PixelColorway Systemic.Unity.Pixels.Pixel.colorway = PixelColorway.Unknown
getprotected set

Gets the Pixel combination of design and color.

This value is set when the Pixel is being scanned or once when connected.

◆ currentFace

int Systemic.Unity.Pixels.Pixel.currentFace
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.

◆ currentFaceIndex

int Systemic.Unity.Pixels.Pixel.currentFaceIndex
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.

◆ dataSetHash

uint Systemic.Unity.Pixels.Pixel.dataSetHash
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.

◆ dieType

PixelDieType Systemic.Unity.Pixels.Pixel.dieType = PixelDieType.Unknown
getprotected set

Gets the die type of the Pixel.

This value is set when the Pixel is being scanned or once when connected.

◆ isCharging

bool Systemic.Unity.Pixels.Pixel.isCharging
get

Indicates whether or not the Pixel was last reported as charging.

This value is only set when UpdateBatteryLevelAsync(OperationResultCallback) is called while connected.

◆ ledCount

int Systemic.Unity.Pixels.Pixel.ledCount
getprotected set

Gets the number of LEDs for the Pixel.

This value is set when the Pixel is being scanned or once when connected.

◆ pixelId

uint Systemic.Unity.Pixels.Pixel.pixelId
getprotected set

Gets the Pixel unique device id.

This value is set when the Pixel is being scanned or when connected.

◆ rollState

PixelRollState Systemic.Unity.Pixels.Pixel.rollState = PixelRollState.Unknown
get

Gets the Pixel current roll state.

This value is set when the Pixel is being scanned or when connected.

◆ rssi

int Systemic.Unity.Pixels.Pixel.rssi
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.


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