public void SetActiveDevice(DeviceInstance device, bool requestConfigs = true) { lock (_LockObject) { if (_ActiveOpenDevice != null) { if (!_ActiveOpenDevice.IsDisposed) { _ActiveOpenDevice.Dispose(); } _ActiveOpenDevice = null; _CurrentLedConfig = null; } _MessageQueue = new ConcurrentQueue <byte[]>(); _ActiveDevice = _CurrentDevices.FirstOrDefault(d => d.Instance == device); if (_ActiveDevice != null) { _Logger.Info("Connecting to device: {0} ...", _ActiveDevice); _ActiveOpenDevice = _ActiveDevice.Open(); _MessageQueue.Enqueue(CreateSimpleMessage(hid_pkt_req.HID_PKT_REQ_LED_COUNT)); _MessageQueue.Enqueue(CreateSimpleMessage(hid_pkt_req.HID_PKT_REQ_CONFIG_KEY_GET)); } } }
public MainPage() { InitializeComponent(); hmsMessaging = DependencyService.Get <IHMSMessaging>(); openDevice = DependencyService.Get <IOpenDevice>(); hmsPushEvent = DependencyService.Get <IHMSPushEvent>(); hmsPushEvent.Initialize(); hmsPushEvent.OnMessageReceived += OnMessageReceived; hmsPushEvent.OnInitialNotification += OnOpenedAppNotification; hmsPushEvent.OnMessageSent += OnMessageSent; hmsInstanceId = DependencyService.Get <IHMSInstanceId>(); hmsInstanceId.Initialize(); hmsInstanceId.OnNewToken += HMSInstanceIdOnNewToken; hmsInstanceId.OnTokenError += HMSInstanceIdOnTokenError; }