public void AddAvailableMotionControllers() { int count = PsMoveApi.count_connected(); for(int i = 0; i < count; i++) { IMotionControllerService mcs = new MotionControllerService(); MotionControllerModel mc = mcs.Initialize(i); mc.Name = "MC " + i; new MotionControllerViewModel(mc, mcs); } Refresh(); }
public void DoRefresh() { ObservableCollection<MotionControllerModel> existingControllers = new ObservableCollection<MotionControllerModel>(); AvailableMotionControllers.Clear(); NewMotionController = new MotionControllerModel(); NewMotionController.Name = null; NewControllersDetected = false; int connectedCount = PsMoveApi.count_connected(); if(connectedCount > 0) { foreach (MotionControllerViewModel mcvw in SimpleIoc.Default.GetAllCreatedInstances<MotionControllerViewModel>()) { existingControllers.Add(mcvw.MotionController); } MotionControllerService motionControllerService = new MotionControllerService(); for (int i = 0; i < connectedCount; i++) { MotionControllerModel tmp = motionControllerService.Initialize(i); if(existingControllers.Count > 0) { bool duplicate = false; foreach (MotionControllerModel mcw in existingControllers) { if (tmp.ConnectStatus == PSMoveConnectStatus.OK) { if (tmp.Serial.Equals(mcw.Serial)) { duplicate = true; break; } } } // end foreach if (!duplicate) AvailableMotionControllers.Add(tmp); } else { if (tmp.ConnectStatus == PSMoveConnectStatus.OK) { AvailableMotionControllers.Add(tmp); } } } // end for } if (AvailableMotionControllers.Count > 0) NewControllersDetected = true; } // DoRefresh