private void SetMovesenseDeviceConnectState(string macID, string serial, bool isConnect) { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "SetMovesenseDeviceConnectState: " + macID + " (" + serial + "): " + (isConnect ? "connected" : "disconnected")); } #pragma warning restore CS0162 // NOTE: sometimes there is no onConnectionComplete-Callback and the library is trying to reconnect without success. // depends on which mobile android device is used. // take a look at https://bitbucket.org/suunto/movesense-docs/wiki/Mobile/Movesense%20compatible%20mobile%20devices.md // Fix: sometimes whiteboard reconnects a device if (!MovesenseDevice.ContainsMacID(macID) && isConnect) { MovesenseDevice movesenseDevice = new MovesenseDevice(macID, serial, -600, false, false, null); Debug.Log(TAG + "onConnectionComplete: " + serial + " added on reconnect"); MovesenseDevice.Add(movesenseDevice); } if (MovesenseDevice.SetConnectionState(macID, isConnect) || isConnect) { if (Event != null) { Event(null, new EventArgs(isConnect, macID, serial)); } } }
public LinearAccelerationPageViewModel() { // Command to start the subscription ToggleSubscribeSwitchCommand = new Xamarin.Forms.Command( async() => { if (IsSubscribeSwitchOn) { ConnectionStatusText = "Connecting..."; await MovesenseDevice.Connect(); ConnectionStatusText = "Subscribing..."; subscription = await CrossMovesense.Current.SubscribeAccelerometerAsync( MovesenseDevice.Name, (d) => { PlotData(d.Data.Timestamp, d.Data.AccData[0].X, d.Data.AccData[0].Y, d.Data.AccData[0].Z); }, 26); ConnectionStatusText = "Subscribed"; } else { // Unsubscribe subscription.Unsubscribe(); ConnectionStatusText = "Unsubscribed"; await MovesenseDevice.Disconnect(); ConnectionStatusText = "Disconnected"; } } , () => (MovesenseDevice != null) // Enable command only if we've got a device ); InitPlotModel(); }
public static void Subscribe(string Serial, string Subscriptionpath, int?Samplerate) { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "Subscribe: " + Serial + ", Subscriptionpath: " + Subscriptionpath + ", Samplerate: " + Samplerate); } #pragma warning restore CS0162 // check correct format if ((Subscriptionpath == SubscriptionPath.LinearAcceleration || Subscriptionpath == SubscriptionPath.AngularVelocity || Subscriptionpath == SubscriptionPath.MagneticField) && Samplerate == null) { Debug.LogError(TAG + "Subscribe, Samplerate missing"); return; } else if ((Subscriptionpath == SubscriptionPath.HeartRate || Subscriptionpath == SubscriptionPath.Temperature) && Samplerate != null) { Debug.LogWarning(TAG + "Subscribe, ignoring Samplerate"); Samplerate = null; return; } #if UNITY_ANDROID && !UNITY_EDITOR MovesenseDevice.AddSubscription(Serial, Subscriptionpath, new MovesenseDevice.SubscriptionSection(Samplerate, movesensePlugin.Call <AndroidJavaObject>("subscribe", URI_EVENTLISTENER, BuildContract(Serial, Subscriptionpath + Samplerate.ToString()), new NotificationCallback(Serial, Subscriptionpath)))); #elif UNITY_IOS && !UNITY_EDITOR SubscribeMDS(Serial, Subscriptionpath, Samplerate.ToString(), "{}", onNotification, onNotificationError); MovesenseDevice.AddSubscription(Serial, Subscriptionpath, new MovesenseDevice.SubscriptionSection(Samplerate)); #elif UNITY_STANDALONE_OSX || UNITY_EDITOR #endif }
// private void Awake() { // buttonOn = Resources.Load<Sprite>("Sprites/Button_On"); // buttonOff = Resources.Load<Sprite>("Sprites/Button_Off"); // } private void Start() { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "Start"); } #pragma warning restore CS0162 isButtonVisualizePressed = false; // refresh sensorlist RefreshScrollViewContentConnectedDevices(true); // refresh subscriptionlist RefreshPanelSubscription(0, null); // ButtonVisualize gets active, if any Subscription is active if (MovesenseDevice.isAnySubscribed(SubscriptionPath.AngularVelocity, SubscriptionPath.LinearAcceleration)) { buttonVisualize.gameObject.SetActive(true); } else { buttonVisualize.gameObject.SetActive(false); } // attach event MovesenseController.Event += OnMovesenseControllerCallbackEvent; }
private static void Scan() { if (IsScanning) { return; } #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "Scan"); } #pragma warning restore CS0162 IsIgnoringScanReport = false; IsScanning = true; MovesenseDevice.RemoveUnconnected(); if (Event != null) { Event(null, new EventArgs(EventType.REMOVE_UNCONNECTED, TAG + "Scan", null)); } #if UNITY_ANDROID && !UNITY_EDITOR scanPlugin.Call("Scan", uuidString); #elif UNITY_IOS && !UNITY_EDITOR Scan_iOS(uuidString); #elif UNITY_STANDALONE_OSX || UNITY_EDITOR #endif if (Event != null) { Event(null, new EventArgs(EventType.SYSTEM_SCANNING, TAG + "Scan", null)); } }
void OnMovesenseControllerCallbackEvent(object sender, MovesenseController.EventArgs e) { switch (e.Type) { case MovesenseController.EventType.CONNECTING: // a sensor is currently connecting #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "RefreshScrollViewContentScan: EventType.CONNECTING"); } #pragma warning restore CS0162 RefreshScrollViewContentScan(); break; case MovesenseController.EventType.CONNECTED: // a sensor is succesfully connected #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "RefreshScrollViewContentScan: EventType.CONNECTED"); } #pragma warning restore CS0162 RefreshScrollViewContentScan(); buttonSubscriptions.gameObject.SetActive(true); break; case MovesenseController.EventType.DISCONNECTED: // a sensor disconnected #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "RefreshScrollViewContentScan: EventType.DISCONNECTED"); } #pragma warning restore CS0162 RefreshScrollViewContentScan(); if (!MovesenseDevice.IsAnyConnectedOrConnecting()) { buttonSubscriptions.gameObject.SetActive(false); } break; case MovesenseController.EventType.RESPONSE: #pragma warning disable CS0162 if (!isLogging) { return; } for (int i = 0; i < e.OriginalEventArgs.Count; i++) { var ne = (ResponseCallback.EventArgs)e.OriginalEventArgs[i]; Debug.Log(TAG + "OnMovesenseControllerCallbackEvent: " + ne.Uri + ", method: " + ne.Method + ", data: " + ne.Data); } #pragma warning restore CS0162 break; } }
void OnMovesenseControllerCallbackEvent(object sender, MovesenseController.EventArgs e) { switch (e.Type) { case MovesenseController.EventType.NOTIFICATION: for (int i = 0; i < e.OriginalEventArgs.Count; i++) { var ne = (NotificationCallback.EventArgs)e.OriginalEventArgs[i]; UpdateTransform(MovesenseDevice.ContainsSerialAt(ne.Serial), ne); } break; } }
public static void Add(MovesenseDevice movesenseDevice) { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "Add: " + movesenseDevice.MacID + " (" + movesenseDevice.Serial + ")"); } #pragma warning restore CS0162 _movesenseDevices.Add(movesenseDevice); if (ShouldSortByRssi) { SortByRssi(); } // logMovesenseDevices(); }
public static void UnSubscribe(string Serial, string SubscriptionPath) { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "UnSubscribe: " + Serial + ", SubscriptionPath: " + SubscriptionPath); } #pragma warning restore CS0162 #if UNITY_ANDROID && !UNITY_EDITOR MovesenseDevice.GetSubscription(Serial, SubscriptionPath).Call("unsubscribe"); MovesenseDevice.RemoveSubscription(Serial, SubscriptionPath); #elif UNITY_IOS && !UNITY_EDITOR // Debug.Log(TAG + "GetSubscription: " + MovesenseDevice.GetSubscription(Serial, SubscriptionPath)); UnSubscribeMDS(Serial, MovesenseDevice.GetSubscription(Serial, SubscriptionPath)); MovesenseDevice.RemoveSubscription(Serial, SubscriptionPath); #elif UNITY_STANDALONE_OSX || UNITY_EDITOR #endif }
void OnMovesenseControllerCallbackEvent(object sender, MovesenseController.EventArgs e) { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "OnMovesenseControllerCallbackEvent, e.Type: " + e.Type); } #pragma warning restore CS0162 switch (e.Type) { case MovesenseController.EventType.NOTIFICATION: // got data from a sensor #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "OnMovesenseControllerCallbackEvent, case MovesenseController.EventType.NOTIFICATION"); } #pragma warning restore CS0162 for (int i = 0; i < e.OriginalEventArgs.Count; i++) { var ne = (NotificationCallback.EventArgs)e.OriginalEventArgs[i]; #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "OnMovesenseControllerCallbackEvent, e.OriginalEventArgs[" + i + "].Data: " + ne.Data); } #pragma warning restore CS0162 RefreshPanelSubscription(MovesenseDevice.ContainsSerialAt(ne.Serial), ne); } break; case MovesenseController.EventType.CONNECTED: // a sensor succesfully connected (in the background) RefreshScrollViewContentConnectedDevices(false); break; case MovesenseController.EventType.DISCONNECTED: // a sensor disconnected RefreshScrollViewContentConnectedDevices(true); RefreshPanelSubscription(0, null); break; } }
private void RefreshDeviceList() { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "RefreshDeviceList"); } #pragma warning restore CS0162 isIgnoringScanReport = true; MovesenseDevice.RemoveAllExcept(refresherList); if (Event != null) { Event(null, new EventArgs(EventType.REFRESH, TAG + "RefreshDeviceList", null)); } StopRefreshDeviceList(); isIgnoringScanReport = false; }
public static void Connect(string MacID) { // mds checks, if already connecting or connected if (!isInitialized) { Debug.LogError(TAG + "Connect: MovesenseController is not initialized. Did you forget to add MovesenseController object in the scene?"); return; } string serial = MovesenseDevice.GetSerial(MacID); #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "Connect: " + MacID + " (" + serial + ")"); } #pragma warning restore CS0162 MovesenseDevice.SetConnecting(MacID); #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "Connect, raising Connecting-event"); } #pragma warning restore CS0162 if (Event != null) { Event(null, new EventArgs(EventType.CONNECTING, TAG + "Connect", new List <System.EventArgs> { new ConnectCallback.EventArgs(false, MacID, serial) })); } #if UNITY_ANDROID && !UNITY_EDITOR movesensePlugin.Call("connect", MacID, new ConnectCallback()); #elif UNITY_IOS && !UNITY_EDITOR ConnectMDS(MacID); #elif UNITY_STANDALONE_OSX || UNITY_EDITOR #endif }
public static void Disconnect(string MacID) { // mds checks, if device is connected string serial = MovesenseDevice.GetSerial(MacID); #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "Disconnect: " + MacID + " (" + serial + ")"); } #pragma warning restore CS0162 #if UNITY_ANDROID && !UNITY_EDITOR movesensePlugin.Call("disconnect", MacID); #elif UNITY_IOS && !UNITY_EDITOR DisConnectMDS(MacID); if (MovesenseDevice.GetConnectingState(MacID)) { // connection has not been completed => there will be no callback if disconnect is called MovesenseDevice.SetConnectionState(MacID, false); #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "Disconnect, while connecting, raising Disconnect-event"); } #pragma warning restore CS0162 if (Event != null) { Event(null, new EventArgs(EventType.DISCONNECTED, TAG + "Disconnect", new List <System.EventArgs> { new ConnectCallback.EventArgs(false, MacID, serial) })); } } #elif UNITY_STANDALONE_OSX || UNITY_EDITOR #endif }
public void OnClickButtonSubscriptions() { if (isButtonSubscriptionsPressed) { isButtonSubscriptionsPressed = true; return; } #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "onClickButtonSubscriptions"); } #pragma warning restore CS0162 // detach events ScanController.Event -= OnScanControllerCallbackEvent; MovesenseController.Event -= OnMovesenseControllerCallbackEvent; ScanController.StopScan(); MovesenseDevice.RemoveUnconnected(); SceneManager.LoadScene(1); }
private void Update() { if (Event != null) // Feature in case you forgot to subscribe to the event, no data will be lost { connectLock.EnterUpgradeableReadLock(); try { if (connectEventArgs.Count > 0) { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "Update, raising CONNECT-event"); } #pragma warning restore CS0162 Event(null, new EventArgs(EventType.CONNECTED, TAG + "OnConnectCallbackEvent", connectEventArgs)); MovesenseDevice.RemoveUnconnected(); Subscribe(MovesenseDevice.Devices[0].Serial, SubscriptionPath.HeartRate, null); connectLock.EnterWriteLock(); try { connectEventArgs.Clear(); } finally { connectLock.ExitWriteLock(); } } } finally { connectLock.ExitUpgradeableReadLock(); } disConnectLock.EnterUpgradeableReadLock(); try { if (disConnectEventArgs.Count > 0) { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "Update, raising DISCONNECT-event"); } #pragma warning restore CS0162 Event(null, new EventArgs(EventType.DISCONNECTED, TAG + "OnConnectCallbackEvent", disConnectEventArgs)); disConnectLock.EnterWriteLock(); try { disConnectEventArgs.Clear(); } finally { disConnectLock.ExitWriteLock(); } } } finally { disConnectLock.ExitUpgradeableReadLock(); } notificationLock.EnterUpgradeableReadLock(); try { if (notificationCallbackEventArgs.Count > 0) { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "Update, raising NOTIFICATION-event"); } #pragma warning restore CS0162 Event(null, new EventArgs(EventType.NOTIFICATION, TAG + "OnNotificationCallbackEvent", notificationCallbackEventArgs)); notificationLock.EnterWriteLock(); try { notificationCallbackEventArgs.Clear(); } finally { notificationLock.ExitWriteLock(); } } } finally { notificationLock.ExitUpgradeableReadLock(); } responseLock.EnterUpgradeableReadLock(); try { if (responseEventArgs.Count > 0) { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "Update, raising RESPONSE-event"); } #pragma warning restore CS0162 Event(null, new EventArgs(EventType.RESPONSE, TAG + "OnResponseCallbackEvent", responseEventArgs)); responseLock.EnterWriteLock(); try { responseEventArgs.Clear(); } finally { responseLock.ExitWriteLock(); } } } finally { responseLock.ExitUpgradeableReadLock(); } } }
void RefreshScrollViewContentScan() { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "RefreshScrollViewContentScan"); } #pragma warning restore CS0162 int scannedDevices = MovesenseDevice.Devices.Count; int scanElementsCount = ScanElements.Count; if (scanElementsCount < scannedDevices) { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "RefreshScrollViewContentScan, add clones"); } #pragma warning restore CS0162 for (int i = scanElementsCount; i < scannedDevices; i++) { GameObject ScanElementClone = Instantiate(ScanElement, scrollViewContentScan) as GameObject; // Positioning RectTransform ScanElementRect = ScanElementClone.GetComponent <RectTransform>(); if (scanElementHeight == 0) { scanElementHeight = ScanElementRect.sizeDelta.y; } // change position ScanElementRect.anchoredPosition = new Vector2(0, -scanElementHeight / 2 - (i * scanElementHeight)); ScanElements.Add(ScanElementClone); } scrollViewContentScan.sizeDelta = new Vector2(0, scanElementHeight * scannedDevices); } else if (scanElementsCount > scannedDevices) { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "RefreshScrollViewContentScan, destroy clones"); } #pragma warning restore CS0162 for (int i = scanElementsCount - 1; i > scannedDevices - 1; i--) { Destroy(ScanElements[i]); ScanElements.RemoveAt(i); } scrollViewContentScan.sizeDelta = new Vector2(0, scanElementHeight * scannedDevices); } // Debug.Log(TAG + "RefreshScrollViewContentScan, assign properties"); for (int i = 0; i < scannedDevices; i++) { MovesenseDevice device = null; try { device = MovesenseDevice.Devices[i]; } catch { Debug.LogWarning(TAG + "RefreshScrollViewContentScan, Device is currently not available"); continue; } // change texts string rssi; if (device.Rssi <= -500) { rssi = "~"; } else { rssi = device.Rssi.ToString(); } // define connectionColor Color32 fontColor; if (device.IsConnecting) { fontColor = Color.yellow; } else if (device.IsConnected) { fontColor = Color.green; } else { fontColor = Color.red; } TMP_Text[] scanElementTexts = ScanElements[i].GetComponentsInChildren <TMP_Text>(); foreach (var text in scanElementTexts) { if (isColorizedScan) { text.color = fontColor; } if (text.name == "Text Serial") { text.text = device.Serial; } else if (text.name == "Text MacID") { text.text = device.MacID; } else if (text.name == "Text Rssi") { text.text = rssi + "db"; } else if (text.name == "Text Status") { if (device.IsConnecting) { text.text = "connecting"; } else { text.text = device.IsConnected ? "Connected" : "Disconnected"; } } } // change OnClickButtonConnect-methodparameters Button scanElementButton = ScanElements[i].GetComponentInChildren <Button>(); scanElementButton.onClick.RemoveAllListeners(); System.Func <string, string, bool, bool, UnityEngine.Events.UnityAction> actionBuilder = (macID, serial, connecting, connected) => () => OnClickButtonConnect(macID, serial, connecting, connected); UnityEngine.Events.UnityAction action1 = actionBuilder(device.MacID, device.Serial, device.IsConnecting, device.IsConnected); scanElementButton.onClick.AddListener(action1); } if (MovesenseDevice.NumberOfConnectedDevices() > 0) { buttonSubscriptions.gameObject.SetActive(true); } }
private void RefreshVisualizationDevices() { // get subcribed sensors int subscriptedDevices = 0; foreach (var item in MovesenseDevice.Devices) { if (MovesenseDevice.GetAllSubscriptionPaths(item.Serial) != null) { subscriptedDevices++; } } int visualizationDevicesCount = visualizationDevices.Count; if (visualizationDevicesCount < subscriptedDevices) { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "RefreshVisualizationDevices, add clones"); } #pragma warning restore CS0162 for (int i = visualizationDevicesCount; i < MovesenseDevice.Devices.Count; i++) { // needed to keep index consistent with connected Devices (unconnected have been removed) if (MovesenseDevice.GetAllSubscriptionPaths(MovesenseDevice.Devices[i].Serial) == null) { visualizationDevices.Add(new VisualizationDevice(null, false, null, null, null, null, null, null, null)); Debug.LogWarning(TAG + "RefreshVisualizationDevices, no Subscriptions available for " + MovesenseDevice.Devices[i].Serial); continue; } GameObject movesenseSensorClone = Instantiate(MovesenseSensor) as GameObject; // DeviceSerial TMP_Text serial = movesenseSensorClone.GetComponentInChildren <TMP_Text>(); serial.text = MovesenseDevice.Devices[i].Serial; Transform cylinderUpDown = null; Transform coneUpDown = null; Transform cylinderForthBack = null; Transform coneForthBack = null; Transform cylinderLeftRight = null; Transform coneLeftRight = null; for (int j = 0; j < movesenseSensorClone.transform.childCount; j++) { if (movesenseSensorClone.transform.GetChild(j).name == "CylinderUpDown") { cylinderUpDown = movesenseSensorClone.transform.GetChild(j); } else if (movesenseSensorClone.transform.GetChild(j).name == "ConeUpDown") { coneUpDown = movesenseSensorClone.transform.GetChild(j); } else if (movesenseSensorClone.transform.GetChild(j).name == "CylinderForthBack") { cylinderForthBack = movesenseSensorClone.transform.GetChild(j); } else if (movesenseSensorClone.transform.GetChild(j).name == "ConeForthBack") { coneForthBack = movesenseSensorClone.transform.GetChild(j); } else if (movesenseSensorClone.transform.GetChild(j).name == "CylinderLeftRight") { cylinderLeftRight = movesenseSensorClone.transform.GetChild(j); } else if (movesenseSensorClone.transform.GetChild(j).name == "ConeLeftRight") { coneLeftRight = movesenseSensorClone.transform.GetChild(j); } } Transform movesenseSensorTransform = movesenseSensorClone.GetComponent <Transform>(); visualizationDevices.Add(new VisualizationDevice(movesenseSensorClone, true, movesenseSensorTransform, cylinderUpDown, coneUpDown, cylinderForthBack, coneForthBack, cylinderLeftRight, coneLeftRight)); } } else if (visualizationDevicesCount > subscriptedDevices) { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "RefreshVisualizationDevices, destroy clones"); } #pragma warning restore CS0162 for (int i = visualizationDevicesCount - 1; i > subscriptedDevices - 1; i--) { Destroy(visualizationDevices[i].Clone); visualizationDevices.RemoveAt(i); } } // Positioning int devicesWithSubscription = 0; for (int i = 0; i < MovesenseDevice.Devices.Count; i++) { if (MovesenseDevice.GetAllSubscriptionPaths(MovesenseDevice.Devices[i].Serial) != null) { visualizationDevices[i].MovesenseSensorTransform.localPosition = devicePositions[subscriptedDevices - 1][devicesWithSubscription]; devicesWithSubscription++; } } }
void RefreshScrollViewContentConnectedDevices(bool isInit) { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "RefreshScrollViewContentConnectedDevices"); } #pragma warning restore CS0162 int connectedDevices = MovesenseDevice.NumberOfConnectedDevices(); int connectedElementsCount = connectedElements.Count; if (connectedElementsCount < connectedDevices) { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "RefreshScrollViewContentConnectedDevices, add clones"); } #pragma warning restore CS0162 for (int i = connectedElementsCount; i < connectedDevices; i++) { GameObject connectedElementClone = Instantiate(ConnectedElement, contentConnected) as GameObject; // Positioning RectTransform connectedElementRect = connectedElementClone.GetComponent <RectTransform>(); if (connectedElementHeight == 0) { connectedElementHeight = connectedElementRect.sizeDelta.y; } // change position connectedElementRect.anchoredPosition = new Vector2(0, -connectedElementHeight / 2 - (i * connectedElementHeight)); connectedElements.Add(connectedElementClone); } contentConnected.sizeDelta = new Vector2(0, connectedElementHeight * connectedDevices); if (isInit) { foreach (var item in connectedElements[0].GetComponentInChildren <Button>().GetComponentsInChildren <Image>()) { if (item.name == "Image Background") { item.color = colorHighlited; break; } } connectedElementHighlitedIndex = 0; } } else if (connectedElementsCount > connectedDevices) { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "RefreshScrollViewContentConnectedDevices, destroy clones"); } #pragma warning restore CS0162 for (int i = connectedElementsCount - 1; i > connectedDevices - 1; i--) { Destroy(connectedElements[i]); connectedElements.RemoveAt(i); } contentConnected.sizeDelta = new Vector2(0, connectedElementHeight * connectedDevices); } for (int i = 0; i < connectedDevices; i++) { // change texts TMP_Text[] connectedElementTexts = connectedElements[i].GetComponentsInChildren <TMP_Text>(); foreach (var text in connectedElementTexts) { if (text.name == "Text Serial") { text.text = MovesenseDevice.Devices[i].Serial; } else if (text.name == "Text MacID") { text.text = MovesenseDevice.Devices[i].MacID; } } // Highlight Button btn = connectedElements[i].GetComponentInChildren <Button>(); btn.onClick.RemoveAllListeners(); System.Func <int, UnityEngine.Events.UnityAction> actionBuilder = (connectedElementIndex) => () => OnClickButtonConnectElement(connectedElementIndex); UnityEngine.Events.UnityAction action1 = actionBuilder(i); btn.onClick.AddListener(action1); } }
public void OnClickButtonSubscribe(int index) { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "OnClickButtonSubscribe, Button: " + buttonsSubscription[index].name); } #pragma warning restore CS0162 // Toggle state bool isOn = (buttonsSubscription[index].image.sprite.name.Split('_')[1] == "On") ? true : false; buttonsSubscription[index].image.sprite = isOn?buttonOff:buttonOn; isOn = !isOn; string serial = MovesenseDevice.Devices[connectedElementHighlitedIndex].Serial; string subscriptionPath = null; int? sampleRate = null; string subscriptionChar = null; // only for logging switch (index) { case 0: subscriptionPath = SubscriptionPath.LinearAcceleration; sampleRate = SampleRate.slowest; subscriptionChar = "LinearAcceleration"; break; case 1: subscriptionPath = SubscriptionPath.AngularVelocity; sampleRate = SampleRate.slowest; subscriptionChar = "AngularVelocity"; break; case 2: subscriptionPath = SubscriptionPath.MagneticField; sampleRate = SampleRate.slowest; subscriptionChar = "MagneticField"; break; case 3: subscriptionPath = SubscriptionPath.HeartRate; subscriptionChar = "HeartRate"; break; case 4: subscriptionPath = SubscriptionPath.Temperature; subscriptionChar = "Temperature"; break; } #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "onClickButtonSubscribe, " + (isOn ? "" : "un") + "subscribe " + subscriptionChar + " for " + serial); } #pragma warning restore CS0162 if (isOn) { MovesenseController.Subscribe(serial, subscriptionPath, sampleRate); } else { MovesenseController.UnSubscribe(serial, subscriptionPath); // clear values Invoke("RefreshPanelSubscriptionDelayed", 0.2F); } // ButtonVisualize gets active, if any Subscription is active if (MovesenseDevice.isAnySubscribed(SubscriptionPath.AngularVelocity, SubscriptionPath.LinearAcceleration)) { buttonVisualize.gameObject.SetActive(true); } else { buttonVisualize.gameObject.SetActive(false); } }
public void ReportScan(string Device) { #endif if (IsIgnoringScanReport) { return; } #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "ReportScan: " + Device); } #pragma warning restore CS0162 StartRefreshDeviceList(); //Structure from native connect:[MacAdress or Identifier],[Name from AdvertisementData],[rssi] string[] splitString = Device.Split(','); string s_rssi = splitString[2]; int i_rssi = int.Parse(s_rssi); string serial = splitString[1].Split(' ')[1]; string macID = splitString[0]; if (MovesenseDevice.GetConnectingState(macID)) { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + macID + " is connecting, cancel further processing"); } #pragma warning restore CS0162 return; } if (!RefresherList.Contains(macID)) { RefresherList.Add(macID); } if (MovesenseDevice.ContainsMacID(macID)) { if (MovesenseDevice.GetRssi(macID) != i_rssi && !IsRefreshingRssiBlocked) { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + macID + " (" + serial + ") already scanned, refreshing rssi"); } #pragma warning restore CS0162 MovesenseDevice.RefreshRssi(macID, i_rssi); if (Event != null) { Event(null, new EventArgs(EventType.RSSI, TAG + "ReportScan", macID)); } } else { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + macID + " (" + serial + ") already scanned, " + (IsRefreshingRssiBlocked ? "refreshRssi blocked" : "same rssi") + ", cancel further processing"); } #pragma warning restore CS0162 return; } } else { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + macID + " (" + serial + ") is new"); } #pragma warning restore CS0162 MovesenseDevice movesenseDevice = new MovesenseDevice(macID, serial, i_rssi, false, false, null); MovesenseDevice.Add(movesenseDevice); if (Event != null) { Event(null, new EventArgs(EventType.NEW_DEVICE, TAG + "ReportScan", macID)); } } StartRssiRefreshBlocker(); }
void RefreshPanelSubscription(int connectedElementIndex, NotificationCallback.EventArgs e) { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "RefreshPanelSubscription, connectedElementIndex: " + connectedElementIndex + ", e.Data: " + (e == null?"e == null!":e.Data)); } #pragma warning restore CS0162 if (e == null) // @Start or on DisconnectEvent or if another Sensor is selected { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "RefreshPanelSubscription, refreshing Sensorlist"); } #pragma warning restore CS0162 // check subscriptionTypes per serial in MovesenseDevice if (MovesenseDevice.Devices.Count == 0) { Debug.LogError(TAG + "RefreshPanelSubscription, MovesenseDevice.Devices.Count == 0"); return; } Dictionary <string, int?> subscriptionTypes = new Dictionary <string, int?>(); if (MovesenseDevice.GetAllSubscriptionPaths(MovesenseDevice.Devices[connectedElementIndex].Serial) != null) { subscriptionTypes = new Dictionary <string, int?>(MovesenseDevice.GetAllSubscriptionPaths(MovesenseDevice.Devices[connectedElementIndex].Serial)); } if (subscriptionTypes.ContainsKey(SubscriptionPath.LinearAcceleration)) { buttonsSubscription[0].image.sprite = buttonOn; // Example for getting samplerate: // Debug.Log("SampleRate: " + subscriptionTypes[SubscriptionPath.LinearAcceleration]); TextLinAcc[0].text = "..."; TextLinAcc[1].text = "..."; TextLinAcc[2].text = "..."; } else { buttonsSubscription[0].image.sprite = buttonOff; TextLinAcc[0].text = "--"; TextLinAcc[1].text = "--"; TextLinAcc[2].text = "--"; } if (subscriptionTypes.ContainsKey(SubscriptionPath.AngularVelocity)) { buttonsSubscription[1].image.sprite = buttonOn; TextGyro[0].text = "..."; TextGyro[1].text = "..."; TextGyro[2].text = "..."; } else { buttonsSubscription[1].image.sprite = buttonOff; TextGyro[0].text = "--"; TextGyro[1].text = "--"; TextGyro[2].text = "--"; } if (subscriptionTypes.ContainsKey(SubscriptionPath.MagneticField)) { buttonsSubscription[2].image.sprite = buttonOn; TextMagnField[0].text = "..."; TextMagnField[1].text = "..."; TextMagnField[2].text = "..."; } else { buttonsSubscription[2].image.sprite = buttonOff; TextMagnField[0].text = "--"; TextMagnField[1].text = "--"; TextMagnField[2].text = "--"; } if (subscriptionTypes.ContainsKey(SubscriptionPath.HeartRate)) { buttonsSubscription[3].image.sprite = buttonOn; TextHeartrate.text = "..."; TextRrData.text = "..."; } else { buttonsSubscription[3].image.sprite = buttonOff; TextHeartrate.text = "--"; TextRrData.text = "--"; } Pulsing.ObjectTransform.IsPulsing = false; if (subscriptionTypes.ContainsKey(SubscriptionPath.Temperature)) { buttonsSubscription[4].image.sprite = buttonOn; TextTemp.text = "..."; } else { buttonsSubscription[4].image.sprite = buttonOff; TextTemp.text = "--"; } } else { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "RefreshPanelSubscription, refreshing Subscriptionlist"); } #pragma warning restore CS0162 // only highlighted Sensordata will be updated if (connectedElementIndex != connectedElementHighlitedIndex) { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "Values for " + MovesenseDevice.Devices[connectedElementIndex].Serial + " do not match displayed " + MovesenseDevice.Devices[connectedElementHighlitedIndex].Serial); } #pragma warning restore CS0162 return; } if (e.Subscriptionpath == SubscriptionPath.LinearAcceleration) { var notificationFieldArgs = (NotificationCallback.FieldArgs)e; #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "updating LinearAcceleration texts"); } #pragma warning restore CS0162 TextLinAcc[0].text = notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].x.ToString("F6"); TextLinAcc[1].text = notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].y.ToString("F6"); TextLinAcc[2].text = notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].z.ToString("F6"); } else if (e.Subscriptionpath == SubscriptionPath.AngularVelocity) { var notificationFieldArgs = (NotificationCallback.FieldArgs)e; #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "updating Gyroscope texts"); } #pragma warning restore CS0162 TextGyro[0].text = notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].x.ToString("F6"); TextGyro[1].text = notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].y.ToString("F6"); TextGyro[2].text = notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].z.ToString("F6"); } else if (e.Subscriptionpath == SubscriptionPath.MagneticField) { var notificationFieldArgs = (NotificationCallback.FieldArgs)e; #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "updating Magnetic texts"); } #pragma warning restore CS0162 TextMagnField[0].text = notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].x.ToString("F6"); TextMagnField[1].text = notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].y.ToString("F6"); TextMagnField[2].text = notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].z.ToString("F6"); } else if (e.Subscriptionpath == SubscriptionPath.HeartRate) { var notificationHeartRateArgs = (NotificationCallback.HeartRateArgs)e; TextHeartrate.text = notificationHeartRateArgs.Pulse.ToString("F0"); TextRrData.text = notificationHeartRateArgs.RrData[notificationHeartRateArgs.RrData.Length - 1].ToString("F0"); Pulsing.ObjectTransform.BPM = (int)notificationHeartRateArgs.Pulse; Pulsing.ObjectTransform.IsPulsing = true; } else if (e.Subscriptionpath == SubscriptionPath.Temperature) { var notificationTemperatureArgs = (NotificationCallback.TemperatureArgs)e; TextTemp.text = (notificationTemperatureArgs.Temperature - 273.15).ToString("F1"); } } }