private async void DiscoverDevices()
        {
            var accessStatus = await RemoteSystem.RequestAccessAsync();

            if (accessStatus == RemoteSystemAccessStatus.Allowed)
            {
                _remoteSystemWatcher = RemoteSystem.CreateWatcher();

                //Add RemoteSystem to DeviceList (on the UI Thread)
                _remoteSystemWatcher.RemoteSystemAdded += async(sender, args) =>
                                                          await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => DeviceList.Add(args.RemoteSystem));

                //Remove RemoteSystem from DeviceList (on the UI Thread)
                _remoteSystemWatcher.RemoteSystemRemoved += async(sender, args) =>
                                                            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => DeviceList.Remove(DeviceList.FirstOrDefault(system => system.Id == args.RemoteSystemId)));

                //Update RemoteSystem on DeviceList (on the UI Thread)
                _remoteSystemWatcher.RemoteSystemUpdated += async(sender, args) =>
                                                            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    DeviceList.Remove(DeviceList.FirstOrDefault(system => system.Id == args.RemoteSystem.Id));
                    DeviceList.Add(args.RemoteSystem);
                });

                _remoteSystemWatcher.Start();
            }
        }
        /// <summary>
        /// Get additional details on a specific device.
        /// If a DeviceList is present this list is also updated with the additional details.
        /// </summary>
        /// <param name="monitorId">Monitor ID that the device is registered on</param>
        /// <param name="deviceId">Device ID to get additional details for</param>
        /// <returns>Device Details for the specified device.</returns>
        public async Task <DeviceDetails> GetDeviceDetails(int monitorId, string deviceId)
        {
            using (var httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Config["accesstoken"]);

                var callData = $"{apiAddress}/app/monitors/{monitorId}/devices/{deviceId}";

                var response = await httpClient.GetAsync(callData);

                await CheckResponseStatus(response, httpClient, callData);

                var json = await response.Content.ReadAsStringAsync();

                var deviceDetails = JsonConvert.DeserializeObject <DeviceDetails>(json);

                if (DeviceList == null || DeviceList.Count <= 0)
                {
                    return(deviceDetails);
                }

                var device = DeviceList.FirstOrDefault(x => x.Id == deviceId);
                if (device == null)
                {
                    return(deviceDetails);
                }

                var pos = DeviceList.FindIndex(x => x.Id == deviceId);
                DeviceList.RemoveAt(pos);
                device = deviceDetails.Device;
                DeviceList.Insert(pos, device);

                return(deviceDetails);
            }
        }
Example #3
0
        public override void ChangeLastIncome(string deviceId)
        {
            var device = DeviceList?.FirstOrDefault(m => m.DeviceId == deviceId);

            if (device == null)
            {
                return;
            }
            device.LastInCome = DateTime.Now;
        }
Example #4
0
        public bool Initialize()
        {
            IDeviceList list = new DeviceList();
              list.Scan();
              this.logger.Debug("Found {0} devices", list.Count());

              this.device = list.FirstOrDefault();
              this.logger.Debug("Selected device: {0}", (this.device as Device)?.DevicePath ?? "None");

              return this.device != null;
        }
Example #5
0
        /// <summary>
        /// Scan result event
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event args including device information</param>
        private void Ble_DeviceDiscoveredEvent(object sender, DeviceInfoEventArgs e)
        {
            DeviceInfo device = e.Device;

            // Add if not already on the list
            if (DeviceList.FirstOrDefault(d => d.DeviceId == device.DeviceId) == null)
            {
                DeviceList.Add(device);
                AdaptorState += Environment.NewLine + string.Format("Device found: {0} [{1}]", e.Device.Name, MacAddressUtils.MacAddressAsString(e.Device.DeviceId, true));
            }
        }
Example #6
0
        internal void UpdateNotInitializedFirstEgsDeviceOnSomeDeviceConnected()
        {
            // TODO: MUSTDO: Test with connecting and re-connecting USB connector, because various problems can occur here.
            try
            {
                // At first it checks HID connection.
                MessageReceivingForm.SetupDi.Update();
                foreach (var device in DeviceList)
                {
                    device.UpdateHidDeviceConnectionStatus();
                }

                // And then it checks camera connection.
                var cameras = GetCameraInterfaceInformationList();
                Debug.WriteLine("cameras.Count: " + cameras.Count);
                foreach (var camera in cameras)
                {
                    var matchedDeviceExists = DeviceList.Any(e => e.CameraViewImageSourceBitmapCapture.VideoCaptureDeviceIndex == camera.Index);
                    if (matchedDeviceExists)
                    {
                        continue;
                    }
                    var notInitializedFirstEgsDevice = DeviceList.FirstOrDefault(e => (e.CameraViewImageSourceBitmapCapture.VideoCaptureDeviceIndex.HasValue == false));
                    if (notInitializedFirstEgsDevice == null)
                    {
                        return;
                    }

                    Trace.Assert(notInitializedFirstEgsDevice.Settings != null);

                    // TODO: MUSTDO: get root device's serial number;
                    notInitializedFirstEgsDevice.CameraViewImageSourceBitmapCapture.VideoCaptureDeviceIndex      = camera.Index;
                    notInitializedFirstEgsDevice.CameraViewImageSourceBitmapCapture.VideoCaptureDeviceName       = camera.Description;
                    notInitializedFirstEgsDevice.CameraViewImageSourceBitmapCapture.VideoCaptureDeviceDevicePath = camera.DevicePath;
                    notInitializedFirstEgsDevice.TrySetIsCameraDeviceConnectedToTrue();
                    Debug.WriteLine("notInitializedFirstEgsDevice.IsConnected: " + notInitializedFirstEgsDevice.IsConnected);
                }
            }
            catch (EgsHostApplicationIsClosingException)
            {
                // NOTE: The exception occurs from inside of Timer, so the application thread cannot catch it.  EgsDevicesManager.Dispose() is called and then the application exit in the event handler of EgsDevicesManager.Disposing.
                System.Windows.Forms.MessageBox.Show(Resources.CommonStrings_ApplicationWillExit, ApplicationCommonSettings.HostApplicationName, System.Windows.Forms.MessageBoxButtons.OK);
                // NOTE! EgsHostAppBaseComponents should save Settings before disposing this object!
                this.Dispose();
            }
            catch (Exception ex)
            {
                if (ApplicationCommonSettings.IsDebugging)
                {
                    Debugger.Break();
                }
                Debug.WriteLine(ex.Message);
            }
        }
Example #7
0
        public bool Initialize()
        {
            IDeviceList list = new DeviceList();

            list.Scan();
            this.logger.Debug("Found {0} devices", list.Count());

            this.device = list.FirstOrDefault();
            this.logger.Debug("Selected device: {0}", (this.device as Device)?.DevicePath ?? "None");

            return(this.device != null);
        }
 /// <summary>
 /// If a DeviceList is present this list is also updated with the additional details.
 /// </summary>
 /// <param name="deviceId">Device ID of the device</param>
 /// <param name="deviceDetails">Device Details for the specified device.</param>
 private void UpdateDeviceList(string deviceId, DeviceDetails deviceDetails)
 {
     if (DeviceList != null && DeviceList.Count > 0)
     {
         var device = DeviceList.FirstOrDefault(x => x.Id == deviceId);
         if (device != null)
         {
             var pos = DeviceList.FindIndex(x => x.Id == deviceId);
             DeviceList.RemoveAt(pos);
             device = deviceDetails.Device;
             DeviceList.Insert(pos, device);
         }
     }
 }
Example #9
0
        private void OKExecute(Window win)
        {
            if (win != null)
            {
                win.DialogResult = true;
                var selNode = DeviceList.FirstOrDefault(a => a.IsChecked);
                if (selNode != null)
                {
                    if (selNode.ViewType == Module.ViewType.Portait)
                    {
                        if (selNode.Type == DeviceType.PCWeb || selNode.Type == DeviceType.Tablet)
                        {
                            Swap(selNode);
                        }
                    }
                    else
                    {
                        if (selNode.Type == DeviceType.Mobile || selNode.Type == DeviceType.Watch)
                        {
                            Swap(selNode);
                        }
                    }
                }

                //UserSetting is checked
                //if user input a name, add it as a new device, else as usersetting
                //Current UserSetting will be added as another device, and add default userSetting again.
                if (UserSetting.IsChecked)
                {
                    if (!string.IsNullOrEmpty(_name))
                    {
                        var device = _document.DeviceSet.CreateDevice(_name);
                        device.IsChecked = true;
                        device.Width     = _width;
                        device.Height    = _height;
                        DeviceList.Insert(DeviceList.Count() - 2, new DeviceNode(device));
                        UserSetting.IsChecked = false;
                    }
                    else
                    {
                        UserSetting.Width  = _width;
                        UserSetting.Height = _height;
                    }
                }
                win.Close();
            }
        }
Example #10
0
        private async Task ConnectLuxafor()
        {
            if (_luxaforDevice != null)
            {
                _luxaforDevice.Dispose();
            }

            _luxaforDevices.Scan();
            _luxaforDevice = _luxaforDevices.FirstOrDefault();

            if (_luxaforDevice != null)
            {
                await _luxaforDevice?.SetColor(LedTarget.All, new LuxaforSharp.Color(0, 0, 0));

                await _luxaforDevice.Wave(WaveType.OverlappingShort, new LuxaforSharp.Color(255, 255, 255), 5, 2);
            }
        }
Example #11
0
        public override void AddDeviceId(string deviceId, string deviceName)
        {
            var device = DeviceList?.FirstOrDefault(m => m.DeviceId == deviceId);

            if (device != null)
            {
                device.DeviceName = deviceName;
                return;
            }
            device = new DeviceInfo()
            {
                AddDate    = DateTime.Now,
                DeviceId   = deviceId,
                DeviceName = deviceName,
                LastInCome = DateTime.Now,
            };
            if (DeviceList == null)
            {
                DeviceList = new List <DeviceInfo>();
            }
            DeviceList.Add(device);
        }
        private static void GpioCardObject_NotifyGpioEvent(string arg)
        {
            /* if (_LastDrawerOpened != 0)
             * {
             *   if (GpioCardObject.InStatus[_LastDrawerOpened] == 0)
             *   {
             *       _LastDrawerClosed = _LastDrawerOpened;
             *       _LastDrawerOpened = 0;
             *       FireEvent(DrawerClosed, DeviceList.FirstOrDefault(x => x.Value == _LastDrawerClosed).Key, _LastDrawerClosed);
             *       return;
             *   }
             * }
             *
             * for (int loop = 1; loop <= NbDrawer; loop++)
             * {
             *   if (GpioCardObject.InStatus[loop] == 1)
             *   {
             *       if (_LastDrawerOpened != loop)
             *       {
             *           _LastDrawerOpened = loop;
             *           _LastDrawerClosed = 0;
             *           FireEvent(DrawerOpened, DeviceList.FirstOrDefault(x => x.Value == _LastDrawerOpened).Key, _LastDrawerOpened);
             *       }
             *       break;
             *   }
             * }*/

            for (int loop = 1; loop <= NbDrawer; loop++)
            {
                if (GpioCardObject.InStatus[loop] != GpioCardObject.PreviousInStatus[loop])
                {
                    if ((GpioCardObject.InStatus[loop] == 0) && (GpioCardObject.PreviousInStatus[loop] == 1))
                    {
                        FireEvent(DrawerClosed, DeviceList.FirstOrDefault(x => x.Value == loop).Key, loop);
                    }
                }
            }

            for (int loop = 1; loop <= NbDrawer; loop++)
            {
                if ((GpioCardObject.InStatus[loop] == 1) && (GpioCardObject.PreviousInStatus[loop] == 0))
                {
                    FireEvent(DrawerOpened, DeviceList.FirstOrDefault(x => x.Value == loop).Key, loop);
                }
            }

            if (GpioCardObject.PreviousInStatus[8] == -1)
            {
                if (GpioCardObject.InStatus[8] == 1)
                {
                    isWallLocked = true;
                }
                else
                {
                    isWallLocked = false;
                }
            }

            if ((GpioCardObject.InStatus[8] == 1) && (GpioCardObject.PreviousInStatus[8] == 0))
            {
                isWallLocked = false;
                FireEvent(WallUnLocked, "0", 0);
            }
            if ((GpioCardObject.InStatus[8] == 0) && (GpioCardObject.PreviousInStatus[8] == 1))
            {
                isWallLocked = true;
                FireEvent(WallLocked, "0", 0);
            }
        }
Example #13
0
        public override bool CheckDevice(string deviceId)
        {
            var device = DeviceList?.FirstOrDefault(m => m.DeviceId == deviceId);

            return((device != null) ? true : false);
        }