/** * <summary>The device connection state changed, it is received here as a json</summary> * * <param name="state">Current connection state.</param> */ public void onConnectionStateChanged(string state) { try { // Convert json object to an object format. DeviceState s = JsonUtility.FromJson <DeviceState>(state); // Check if the callback was previously initialized. if (OnDeviceConnectionChange != null) { currState = (DeviceState.States)s.state; OnDeviceConnectionChange(s.identifier, (DeviceState.States)s.state); // Disconnect device is the acquisition stops. if (currState.Equals(DeviceState.States.ACQUISITION_STOPPING)) { // Disconnect device. androidSensorsClass.Call("disconnect", identifier); } } } catch (Exception e) { Debug.Log(e.Message); } }
public static bool IsConnectedState(this DeviceState.States state) { switch (state) { case DeviceState.States.CONNECTED: case DeviceState.States.ONLINE: case DeviceState.States.ONNET: case DeviceState.States.SYNCING: return(true); } return(false); }
/** * <summary>Callback invoked every time the connection state changes.</summary> * <param name="device">Device identifier to which the current state is linked.</param> * <param name="state">New state currently being communicated.</param> */ void OnDeviceConnection(string device, DeviceState.States state) { // Check if a PLUX device is currently connected. sensorsConnectedProperty.Value = DeviceController.Instance.IsSensorConnected(); string message = ""; switch (state) { case DeviceState.States.LISTEN: message = "listening"; break; case DeviceState.States.CONNECTING: message = "connecting"; break; case DeviceState.States.CONNECTED: message = "connected"; break; case DeviceState.States.ACQUISITION_TRYING: message = "starting"; break; case DeviceState.States.ACQUISITION_OK: message = "in acquisition"; break; case DeviceState.States.ACQUISITION_STOPPING: message = "stopping"; break; case DeviceState.States.DISCONNECTED: message = "disconnected"; break; default: message = "no connection"; break; } // Update GUI informative text regarding the connection state. statusTextProperty.Value = message; }