void handleConnectionError(DicePlus dpf) { if (dpf.Equals(currentlyConnectedDie)) { if (state == State.CONNECTING) { setState(State.DISCONNECTED); } currentlyConnectedDie = null; } if (connectedDice.Contains(dpf)) { connectedDice.Remove(dpf); } if (state == State.CONNECTED) { if (connectedDice.Count < maxDiceCount) { DicePlusAnimator.Instance.runDisconnectedAnimation(); setState(State.DISCONNECTED); } } else if (state != State.ROLLER) { OrbitingButtonsManager.Instance.showButtons(true); // triedDiceSet.Add(dpf); } }
public void onConnectionEstablished(DicePlus dpe) { if (dpe.Equals(currentlyConnectedDie)) { currentlyConnectedDie = null; } SoftwareVersion sv = dpe.getSoftwareVersion(); if ((sv.getMajor() > major) || (sv.getMajor() == major && sv.getMinor() >= minor)) { connectedDice.Add(dpe); if (connectedDice.Count >= maxDiceCount) { setState(State.CONNECTED); } else { setState(State.DISCONNECTED); } DicePlusAnimator.Instance.runConnectedAnimation(); dpe.subscribeRolls(); dpe.subscribeBatteryState(); dpe.registerListener(this); rssi = dpe.rssi; } else { setState(State.DISCONNECTED); DicePlusAnimator.Instance.runVersionMissmatchAnimation(false); dpe.disconnect(); } }
public override void onRoll(DicePlus dicePlus, long time, int duration, int face, int invalidityFlags, string errorMsg) { // Accepting only valid rolls. if(invalidityFlags == 0) { // RollResult.text = face.ToString(); } }
public void onConnectionFailed(DicePlus dpf, int errorCode, string excpMsg) { if (errorCode == DicePlusConnector.ERR_VERSION_MISSMATCH) { DicePlusAnimator.Instance.runVersionMissmatchAnimation(true); } handleConnectionError(dpf); }
public override void onRoll(DicePlus dicePlus, long time, int duration, int face, int invalidityFlags, string errorMsg) { // Accepting only valid rolls. if (invalidityFlags == 0) { // RollResult.text = face.ToString(); } }
public override void onOrientationReadout(DicePlus dicePlus, long time, Vector3 v, string errorMsg) { // X axis goes through 1 // Y axis goes through 5 // Z axis goes through 3 // transform.rotation = Quaternion.Euler(Vector3.zero); // transform.Rotate(v); currentOrientation = v; }
void IDicePlusConnectorListener.onConnectionEstablished(DicePlus dicePlus) { dicePlus.initializePStorageCommunication(); dicePlus.registerListener(this); dicePlus.subscribeOrientationReadouts(20); myDice = dicePlus; DiceConnected = true; }
private void checkConnection() { if (state == State.SEARCHING) { if (rssiSearchTimoutTime < Time.time && diceSet.Count > 0) { setState(State.DISCONNECTED); DicePlusConnector.Instance.stopScan(); } } if (state == State.DISCONNECTED) { if (diceSet.Count == 0) { if (scanningEnabled) { if (DicePlusConnector.Instance.startScan()) { rssiSearchTimoutTime = Time.time + findClosestTime; setState(State.SEARCHING); } else { OrbitingButtonsManager.Instance.showButtons(true); setState(State.DISCONNECTED); } } } else { int highestRssi = int.MinValue; DicePlus toBeConnected = null; foreach (DicePlus dp in diceSet) { if (dp.rssi > highestRssi) { highestRssi = dp.rssi; toBeConnected = dp; } } if (toBeConnected != null) { currentlyConnectedDie = toBeConnected; DicePlusConnector.Instance.connect(toBeConnected); setState(State.CONNECTING); diceSet.Remove(toBeConnected); } } } }
public void onNewDie(DicePlus ndp) { if ( !connectedDice.Contains(ndp)) { diceSet.Add(ndp); if (ndp.rssi >= rssi - 5) { setState(State.DISCONNECTED); DicePlusConnector.Instance.stopScan(); } } }
public override void onBatteryState(DicePlus dicePlus, DicePlusConnector.BatteryState batteryState, int percentage, bool low, string errorMsg) { if (percentage < battery && low) { if (state != State.CONNECTED) { DicePlusAnimator.Instance.runLowBatteryAnimation(); } else { StartCoroutine(DicePlusAnimator.Instance.lowBatteryCorutine()); } battery = percentage; } }
/// <summary> /// Subscribes to accelerometer readouts and configure sensor /// </summary> /// <param name='dicePlus'> /// the die to which to send command/request /// </param> /// <param name='readFrequency'> /// readout frequency (in Hz), values: 1 - 60 /// </param> /// <param name='readoutType'> /// a readout filter type /// </param> public void subscribeAccelerometerReadouts(DicePlus dicePlus, int readFrequency, AccelerometerReadoutType readoutType) { #if UNITY_EDITOR #elif UNITY_IPHONE ios_subscribeAndConfigureAccelerometerReadouts(dicePlus.address, readFrequency, (int)readoutType); #elif UNITY_ANDROID if (dmo != null) { dmo.Call("subscribeAndConfigureAccelerometerReadouts", new object [] {dicePlus.address, readFrequency, (int)readoutType}); } #endif }
/// <summary> /// Sends setMode packet to the given die /// </summary> /// <param name='dicePlus'> /// the die to which to send command/request /// </param> /// <param name='mode'> /// mode to set /// </param> public void setMode(DicePlus dicePlus, DieMode mode) { #if UNITY_EDITOR #elif UNITY_IPHONE ios_setMode(dicePlus.address, (int)mode); #elif UNITY_ANDROID if (dmo != null) { dmo.Call("setMode", new object [] {dicePlus.address, (int)mode}); } #endif }
/// <summary> /// Sends fade LED animation request /// </summary> /// <param name='dicePlus'> /// the die to which to send command/request /// </param> /// <param name='ledMask'> /// which LEDs to run animation on /// </param> /// <param name='priority'> /// animation with lower value overrides other, values: 0 - 255 /// </param> /// <param name='color'> /// color to be faded /// </param> /// <param name='fadeInOutTime'> /// time in ms LED is fading in/out, values: 0 - 65535 /// </param> /// <param name='pauseTime'> /// time in ms LED stays at full bright before fading out, values: 0 - 65535 /// </param> public void runFadeAnimation(DicePlus dicePlus, LedFace ledMask, int priority, Color color, int fadeInOutTime, int pauseTime) { #if UNITY_EDITOR #elif UNITY_IPHONE ios_runFadeAnimation(dicePlus.address, (int)ledMask, priority, (int)(color.r*255), (int)(color.g*255), (int)(color.b*255), fadeInOutTime, pauseTime); #elif UNITY_ANDROID if (dmo != null) { dmo.Call("runFadeAnimation", new object [] {dicePlus.address, (int)ledMask, priority, (int)(color.r*255), (int)(color.g*255), (int)(color.b*255), fadeInOutTime, pauseTime}); } #endif }
public virtual void onPStorageValueRead(DicePlus dicePlus, int handle, int intvalue) { }
public virtual void onAccelerometerReadout(DicePlus dicePlus, long time, Vector3 v, int type, string errorMsg) { }
/// <summary> /// Checks if the die is connected and authenticated /// </summary> /// <returns> /// true, if the die is authenticated; false otherwise. /// </returns> /// <param name='dicePlus'> /// the dice /// </param> public bool hasConnectionEstabilished(DicePlus dicePlus) { #if UNITY_EDITOR #elif UNITY_IPHONE return ios_connected(dicePlus.address); #elif UNITY_ANDROID if (dmo != null) { return dmo.Call<bool>("hasConnectionEstabilished", new object [] {dicePlus.address}); } #endif return false; }
/// <summary> /// Gets persistent storage record description for given handle /// </summary> /// <returns> /// persistent storage record description, null if handle was invalid /// </returns> /// <param name='dicePlus'> /// the die to which to send command/request /// </param> /// <param name='handle'> /// the handle to requested record /// </param> public PStorageRecordDescription getPStorageRecordDescription(DicePlus dicePlus, int handle) { string result = null; #if UNITY_EDITOR #elif UNITY_IPHONE result = ios_getPStorageRecordDescription(dicePlus.address, handle); #elif UNITY_ANDROID if (dmo != null) { result = dmo.Call<string>("getPStorageRecordDescription", new object [] {dicePlus.address, handle}); } #endif PStorageRecordDescription retVal; if (result == null || result.Equals("") || !PStorageRecordDescription.TryParse(result, out retVal)) { return null; } else { return retVal; } }
public void onConnectionLost(DicePlus dpl) { handleConnectionError(dpl); }
public virtual void onPowerMode(DicePlus dicePlus, long time, DicePlusConnector.PowerMode mode, string errorMsg) { }
public virtual void onPStorageOperationFailed(DicePlus dicePlus, string errorMsg) { }
public virtual void onPStorageCommunicationInitialized(DicePlus dicePlus, int count) { }
/// <summary> /// Subscribes to proximity readouts and configures sensor /// </summary> /// <param name='dicePlus'> /// the die to which to send command/request /// </param> /// <param name='freq'> /// readout frequency (in Hz), values: 1 - 10 /// </param> public void subscribeProximityReadouts(DicePlus dicePlus, int freq) { #if UNITY_EDITOR #elif UNITY_IPHONE ios_subscribeAndConfigureProximityReadouts(dicePlus.address, freq); #elif UNITY_ANDROID if (dmo != null) { dmo.Call("subscribeAndConfigureProximityReadouts", new object [] {dicePlus.address, freq}); } #endif }
public virtual void onReadoutFailed(DicePlus dicePlus, int dataSourceCode, string errorMsg) { }
public virtual void onPStorageValueRead(DicePlus dicePlus, int handle, String str) { }
public virtual void onSubscriptionChangeStatus(DicePlus dicePlus, DicePlusConnector.DataSource dataSourceCode, string errorMsg) { }
/// <summary> /// Gets the status. /// </summary> /// <returns> /// dies module status /// </returns> /// <param name='dicePlus'> /// the dice /// </param> public int? getStatus(DicePlus dicePlus) { string result = null; #if UNITY_EDITOR #elif UNITY_IPHONE result = ios_getStatus(dicePlus.address); #elif UNITY_ANDROID if (dmo != null) { result = dmo.Call<string>("getStatus", new object [] {dicePlus.address}); } #endif int retVal = new int(); if (result == null || result.Equals("") || !int.TryParse(result, out retVal)) { return null; } else { return retVal; } }
public virtual void onConnectionEstablished(DicePlus dicePlus) { }
/// <summary> /// Sends request to the given dice to get persistent storage record value /// </summary> /// <param name='dicePlus'> /// the die to which to send command/request /// </param> /// <param name='handle'> /// the handle to requested record /// </param> public void readPStorageValue(DicePlus dicePlus, int handle) { #if UNITY_EDITOR #elif UNITY_IPHONE ios_readPStorageValue(dicePlus.address, handle); #elif UNITY_ANDROID if (dmo != null) { dmo.Call("readPStorageValue", new object [] {dicePlus.address, handle}); } #endif }
public virtual void onNewDie(DicePlus dicePlus) { }
public virtual void onConnectionLost(DicePlus dicePlus) { }
public virtual void onPStorageValueRead(DicePlus dicePlus, int handle, Vector3 vector) { }
public virtual void onConnectionFailed(DicePlus dicePlus, int errorCode, string excpMsg) { }
public virtual void onDiceStatistics(DicePlus dicePlus, DiceStatistics diceStatistics, string errorMsg) { }
/// <summary> /// Sends blink LED animation request /// </summary> /// <param name='dicePlus'> /// the die to which to send command/request /// </param> /// <param name='ledMask'> /// which LEDs to run animation on /// </param> /// <param name='priority'> /// animation with lower value overrides other, values: 0 - 255 /// </param> /// <param name='color'> /// color to be blinked /// </param> /// <param name='ledOnPeriod'> /// time in ms LED is ON, values: 0 - 65535 /// </param> /// <param name='ledCyclePeriod'> /// time in ms one blink cycle lasts, values: 0 - 65535 /// </param> /// <param name='blinkNumber'> /// number of blinks, values: 0 - 255 /// </param> public void runBlinkAnimation(DicePlus dicePlus, LedFace ledMask, int priority, Color color, int ledOnPeriod, int ledCyclePeriod, int blinkNumber) { #if UNITY_EDITOR #elif UNITY_IPHONE ios_runBlinkAnimation(dicePlus.address, (int)ledMask, priority, (int)(color.r*255), (int)(color.g*255), (int)(color.b*255), ledOnPeriod, ledCyclePeriod, blinkNumber); #elif UNITY_ANDROID if (dmo != null) { dmo.Call("runBlinkAnimation", new object [] {dicePlus.address, (int)ledMask, priority, (int)(color.r*255), (int)(color.g*255), (int)(color.b*255), ledOnPeriod, ledCyclePeriod, blinkNumber}); } #endif }
/// <summary> /// Unsubscribes from battery state events /// </summary> /// <param name='dicePlus'> /// the die to which to send command/request /// </param> public void unsubscribeBatteryState(DicePlus dicePlus) { #if UNITY_EDITOR #elif UNITY_IPHONE ios_unsubscribeBatteryState(dicePlus.address); #elif UNITY_ANDROID if (dmo != null) { dmo.Call("unsubscribeBatteryState", new object [] {dicePlus.address}); } #endif }
/// <summary> /// Sends standard LED animation request /// </summary> /// <param name='dicePlus'> /// the die to which to send command/request /// </param> /// <param name='ledMask'> /// which LEDs to run animation on /// </param> /// <param name='priority'> /// animation with lower value overrides other, values: 0 - 255 /// </param> /// <param name='animation'> /// standard animation type /// </param> public void runStandardAnimation(DicePlus dicePlus, LedFace ledMask, int priority, DicePlusConnector.AnimationType animation) { #if UNITY_EDITOR #elif UNITY_IPHONE ios_runStandardAnimation(dicePlus.address, (int)ledMask, priority, (int)animation); #elif UNITY_ANDROID if (dmo != null) { dmo.Call("runStandardAnimation", new object [] {dicePlus.address, (int)ledMask, priority, (int)animation}); } #endif }
/// <summary> /// Sends request to the given dice to set persistent storage record value /// </summary> /// <param name='dicePlus'> /// the die to which to send command/request /// </param> /// <param name='handle'> /// the handle to requested record /// </param> /// <param name='x'> /// first vector value to be set /// </param> /// <param name='y'> /// second vector value to be set /// </param> /// <param name='z'> /// third vector value to be set /// </param> public void writePStorageValue(DicePlus dicePlus, int handle, int x, int y, int z) { #if UNITY_EDITOR #elif UNITY_IPHONE ios_writePStorageVecValue(dicePlus.address, handle, x, y, z); #elif UNITY_ANDROID if (dmo != null) { dmo.Call("writePStorageVecValue", new object [] {dicePlus.address, handle, x, y, z}); } #endif }
/// <summary> /// Sends sleep request to the given dice /// </summary> /// <param name='dicePlus'> /// the die to which to send command/request /// </param> public void sleep(DicePlus dicePlus) { #if UNITY_EDITOR #elif UNITY_IPHONE ios_sleep(dicePlus.address); #elif UNITY_ANDROID if (dmo != null) { dmo.Call("sleep", new object [] {dicePlus.address}); } #endif }
void onNewDie(string str) { string[] words = str.Split('#'); string addres = words[0]; DicePlus dicePlus; if (dice.ContainsKey(addres)) { dicePlus = dice[addres]; } else { dicePlus = new DicePlus(this, addres); dice.Add(addres, dicePlus); } dicePlus.rssi = int.Parse(words[1]); foreach (IDicePlusConnectorListener listener in listeners) { listener.onNewDie(dicePlus); } }
/// <summary> /// Subscribes to magnetometer readouts and configures sensor. /// </summary> /// <param name='dicePlus'> /// the die to which to send command/request /// </param> /// <param name='freq'> /// readout frequency (in Hz), values: 1 - 30 /// </param> /// <param name='type'> /// a readout type /// </param> public void subscribeMagnetometerReadouts(DicePlus dicePlus, int freq, MagnetometerReadoutType type) { #if UNITY_EDITOR #elif UNITY_IPHONE ios_subscribeAndConfigureMagnetometerReadouts(dicePlus.address, freq, (int)type); #elif UNITY_ANDROID if (dmo != null) { dmo.Call("subscribeAndConfigureMagnetometerReadouts", new object [] {dicePlus.address, freq, (int)type}); } #endif }
/// <summary> /// Sends the die statistics request to the given dice. /// </summary> /// <param name='dicePlus'> /// the die to which to send command/request /// </param> public void getDiceStatistics(DicePlus dicePlus) { #if UNITY_EDITOR #elif UNITY_IPHONE ios_getDiceStatistics(dicePlus.address); #elif UNITY_ANDROID if (dmo != null) { dmo.Call("getDiceStatistics", new object [] {dicePlus.address}); } #endif }
/// <summary> /// Subscribes to roll events /// </summary> /// <param name='dicePlus'> /// the die to which to send command/request /// </param> public void subscribeRolls(DicePlus dicePlus) { #if UNITY_EDITOR #elif UNITY_IPHONE ios_subscribeRolls(dicePlus.address); #elif UNITY_ANDROID if (dmo != null) { dmo.Call("subscribeRolls", new object [] {dicePlus.address}); } #endif }
public virtual void onPStorageReset(DicePlus dicePlus, string errorMsg) { }
/// <summary> /// Unsubscribes from touch/release state events /// </summary> /// <param name='dicePlus'> /// the die to which to send command/request /// </param> public void unsubscribeTouchReadouts(DicePlus dicePlus) { #if UNITY_EDITOR #elif UNITY_IPHONE ios_unsubscribeTouchReadouts(dicePlus.address); #elif UNITY_ANDROID if (dmo != null) { dmo.Call("unsubscribeTouchReadouts", new object [] {dicePlus.address}); } #endif }
public override void onLedState(DicePlus dicePlus, long time, DicePlusConnector.LedFace ledMask, long animationId, int type, string errorMsg) { }
/// <summary> /// Sends request to the given dice to set persistent storage record value /// </summary> /// <param name='dicePlus'> /// the die to which to send command/request /// </param> /// <param name='handle'> /// the handle to requested record /// </param> /// <param name='str'> /// string value to be set /// </param> public void writePStorageValue(DicePlus dicePlus, int handle, string str) { #if UNITY_EDITOR #elif UNITY_IPHONE ios_writePStorageStrValue(dicePlus.address, handle, str); #elif UNITY_ANDROID if (dmo != null) { dmo.Call("writePStorageStrValue", new object [] {dicePlus.address, handle, str}); } #endif }
public void onNewDie(DicePlus dicePlus) { // throw new System.NotImplementedException (); }
/// <summary> /// Disconnects specified dice. /// </summary> /// <param name='dicePlus'> /// the die to which to send command/request /// </param> public void disconnect(DicePlus dicePlus) { #if UNITY_EDITOR #elif UNITY_IPHONE ios_disconnect(dicePlus.address); #elif UNITY_ANDROID if (dmo != null) { dmo.Call("disconnect", new object [] {dicePlus.address}); } #endif }
public void onConnectionLost(DicePlus dicePlus) { dicePlus.unsubscribeOrientationReadouts(); }
/// <summary> /// Gets device model number /// </summary> /// <returns> /// device model model, null when die has not yet connected and authenticated connection. /// </returns> /// <param name='dicePlus'> /// the dice /// </param> public long? getModelNumber(DicePlus dicePlus) { string result = null; #if UNITY_EDITOR #elif UNITY_IPHONE result = ios_getModelNumber(dicePlus.address); #elif UNITY_ANDROID if (dmo != null) { result = dmo.Call<string>("getModelNumber", new object [] {dicePlus.address}); } #endif long retVal = new long(); if (result == null || result.Equals("") || !long.TryParse(result, out retVal)) { return null; } else { return retVal; } }
public void onConnectionEstablished(DicePlus dicePlus) { dicePlus.registerListener(this); dicePlus.subscribeOrientationReadouts(20); // dicePlus.subscribeLedState(); }
/// <summary> /// Gets software version. /// </summary> /// <returns> /// number representing software version, null when die has not yet connected and authenticated connection. /// </returns> /// <param name='dicePlus'> /// the dice /// </param> public SoftwareVersion getSoftwareVersion(DicePlus dicePlus) { string result = null; #if UNITY_EDITOR #elif UNITY_IPHONE result = ios_getSoftwareVersion(dicePlus.address); #elif UNITY_ANDROID if (dmo != null) { result = dmo.Call<string>("getSoftwareVersion", new object [] {dicePlus.address}); } #endif if (result == null || result.Equals("")) { return null; } else { return SoftwareVersion.Parse(result); } }
public void onConnectionFailed(DicePlus dicePlus, int errorCode, string excpMsg) { // throw new System.NotImplementedException (); }
/// <summary> /// Gets dice unique identifier /// </summary> /// <returns> /// unique identifier string, null when die has not yet connected and authenticated connection. /// </returns> /// <param name='dicePlus'> /// the die /// </param> public string getUID(DicePlus dicePlus) { string result = null; #if UNITY_EDITOR #elif UNITY_IPHONE result = ios_getUID(dicePlus.address); #elif UNITY_ANDROID if (dmo != null) { result = dmo.Call<string>("getUID", new object [] {dicePlus.address}); } #endif if (result == null || result.Equals("")) { return null; } else { return result; } }
/// <summary> /// Sends request to the given dice to initialize persistent storage communication /// </summary> /// <param name='dicePlus'> /// the die to which to send command/request /// </param> public void initializePStorageCommunication(DicePlus dicePlus) { #if UNITY_EDITOR #elif UNITY_IPHONE ios_initializePStorageCommunication(dicePlus.address); #elif UNITY_ANDROID if (dmo != null) { dmo.Call("initializePStorageCommunication", new object [] {dicePlus.address}); } #endif }
/// <summary> /// Sends request to the given dice to reset all persistent storage settings /// </summary> /// <param name='dicePlus'> /// the die to which to send command/request /// </param> public void resetPStorage(DicePlus dicePlus) { #if UNITY_EDITOR #elif UNITY_IPHONE ios_resetPStorage(dicePlus.address); #elif UNITY_ANDROID if (dmo != null) { dmo.Call("resetPStorage", new object [] {dicePlus.address}); } #endif }
public virtual void onSleepStatus(DicePlus dicePlus, string errorMsg) { }