string GetDeviceInstanceString(ControlScheme scheme, DeviceSlot deviceSlot) { int instance = 0; int totalInstances = 0; if (deviceSlot != null) { var deviceSlots = scheme.deviceSlots; for (int i = 0; i < deviceSlots.Count; i++) { var ds = deviceSlots[i]; if ((Type)deviceSlot.type == (Type)ds.type && deviceSlot.tagIndex == ds.tagIndex) { totalInstances++; if (deviceSlot == ds) { instance = totalInstances; } } } } if (totalInstances > 1) { return(string.Format("#{0}", instance)); } else { return(string.Empty); } }
private async Task <bool> SendCommand(DeviceSlot slot, byte[] data) { bool success = false; if (slot.IsEmpty) { return(success); } if (slot.ConnectedDevice.CommandCharacteristic == null) { _userDialogs.Alert(new AlertConfig { Message = $"Error: The session command function is not available for this device." }); } try { success = await slot.ConnectedDevice.CommandCharacteristic.WriteAsync(data); } catch (Exception e) { _log.Debug($"Error: Characteristic write cannot be completed. {e.Message}"); } return(success); }
public async Task <bool> DisconnectDevice(SensorDevice sensorDevice) { // Check if correct device reference was provided. if (sensorDevice == null) { return(false); } _isBusy = true; // Get type of device. DeviceType deviceType = sensorDevice.Type; // Clear connected device. DeviceSlot occupingSlot = _deviceSlotService.GetSlotWithDevice(sensorDevice); if (occupingSlot == null) { _isBusy = false; return(false); } foreach (var outputID in occupingSlot.OutputDataIDs) { OutputData.Remove(outputID); _sensorDataService.RemoveFromDataBuffer(outputID); } _deviceSlotService.EmptySlot(occupingSlot.Index); await _adapter.DisconnectDeviceAsync(sensorDevice.Device); _isBusy = false; return(true); }
void AddDevice() { ControlScheme scheme = m_ActionMapEditCopy.controlSchemes[selectedScheme]; var deviceSlot = new DeviceSlot() { key = GetNextDeviceKey() }; scheme.deviceSlots.Add(deviceSlot); }
public SlotViewModel(DeviceSlot slot, IDeviceSlotService deviceSlotService, IMvxLog log) { _bluetoothService = Mvx.Resolve <IBluetoothService>(); _deviceSlotService = deviceSlotService; _userDialogs = Mvx.Resolve <IUserDialogs>(); _log = log; _slot = slot; _deviceSlotService.DeviceAdded += SubscribeToUpdates; _deviceSlotService.DeviceWillBeRemoved += UnsubscribeToUpdates; _deviceSlotService.SessionInfoChanged += UpdateSessionStatus; _deviceSlotService.BatteryInfoChanged += UpdateBatteryStatus; }
public void OnDisconnected(SensorDevice sensorDevice, bool showMessage = false) { // Check if a valid sensor device model was referenced. if (sensorDevice == null) { return; } _isBusy = true; // Cleanup refrences for a device. if (sensorDevice.Type != DeviceType.None) { if (sensorDevice.Characteristics == null) { _isBusy = false; return; } // Cleanup data update listeners for characteristics. foreach (ICharacteristic characteristic in sensorDevice.Characteristics) { try { if (_dataTypeForCharacteristicUUID.ContainsKey(characteristic.Uuid)) { DataType dataType = _dataTypeForCharacteristicUUID[characteristic.Uuid]; DataType tempDataType = dataType; // Necessary temp conversion due to DataType clash in different chest and limb devices. if (dataType == DataType.temp) { if (sensorDevice.Type == DeviceType.Chest) { tempDataType = DataType.chest_temp; } else if (sensorDevice.Type == DeviceType.Limb) { tempDataType = DataType.foot_temp; } } if (!_dataTypeToOutputType.ContainsKey(tempDataType)) { continue; } foreach (var outputType in _dataTypeToOutputType[tempDataType]) { SubscribedCharacteristicsList.Remove(outputType); } } // Attempt to remove event handler. _characteristicEventAggregator.TryGetValue(characteristic, out EventHandler <CharacteristicUpdatedEventArgs> CharacteristicOnValueUpdated); characteristic.ValueUpdated -= CharacteristicOnValueUpdated; // Attempt to remove reference to the event handler. _characteristicEventAggregator.TryRemove(characteristic, out CharacteristicOnValueUpdated); } catch (Exception e) { _log.Debug("Characteristic unsubscription error: " + e.Message + characteristic.Name); } } //if (sensorDevice.InfoCharacteristic != null) //{ // sensorDevice.InfoCharacteristic.ValueUpdated -= _infoUpdateEventHandler; //} // Clear out the corresponding device slot for connected devices. DeviceSlot occupingSlot = _deviceSlotService.GetSlotWithDevice(sensorDevice); if (occupingSlot == null) { _isBusy = false; return; } foreach (var outputID in occupingSlot.OutputDataIDs) { OutputData.Remove(outputID); _sensorDataService.RemoveFromDataBuffer(outputID); } // StopSession(); _deviceSlotService.EmptySlot(occupingSlot.Index); _isBusy = false; } if (showMessage) { // If disconnection was unexpected. _log.Info($"Connection to {sensorDevice.Name} has been lost."); _userDialogs.Alert(new AlertConfig { Message = "Connection to " + sensorDevice.Name + " has been lost." }); } else { // If disconnection was made by user. _log.Info($"Device {sensorDevice.Name} has disconnected."); } }
public SlotEventArgs(DeviceSlot slot) : base() { Slot = slot; }
public List <DomainEntry> GetControlEntriesOfType(int domainId, Type controlType) { DeviceSlot slot = m_TrackedPoseDriver.deviceSlot; return(InputDeviceUtility.GetDeviceControlEntriesOfType(slot == null ? null : slot.type, typeof(PoseControl))); }