コード例 #1
0
ファイル: EquipmentChooserVM.cs プロジェクト: daleghent/NINA
 private void OpenSetupDialog(object o)
 {
     if (SelectedDevice?.HasSetupDialog == true)
     {
         SelectedDevice.SetupDialog();
     }
 }
コード例 #2
0
 public MainWindowViewModel()
 {
     ConnectCommand = new DelegateCommand(conn);
     RCommand       = new DelegateCommand(() => SelectedDevice.TxUsb(Encoding.ASCII.GetBytes("r")));
     GCommand       = new DelegateCommand(() => SelectedDevice.TxQueue.Enqueue(Encoding.ASCII.GetBytes("g")));
     YCommand       = new DelegateCommand(() => SelectedDevice.TxQueue.Enqueue(Encoding.ASCII.GetBytes("y")));
 }
コード例 #3
0
ファイル: MainWindow.cs プロジェクト: sgmoore/KindleManager
        public async Task <bool> _SelectDevice(string driveLetter)
        {
            try
            {
                SelectedDevice = DevManager.OpenDevice(driveLetter);
            }
            catch (Exception e)
            {
                var errDlg = new Dialogs.Error("Unable to open Device", e.Message);
                await MaterialDesignThemes.Wpf.DialogHost.Show(errDlg);

                return(false);
            }

            if (SelectedDevice.Open())
            {
                var dlg = new Dialogs.YesNo("Device Setup", "It appears this is the first time you've used this device with KindleManager. A new configuration and database will be created.");
                await MaterialDesignThemes.Wpf.DialogHost.Show(dlg);

                if (dlg.DialogResult == false)
                {
                    SelectedDevice = null;
                    return(false);
                }

                await _EditDeviceSettings(true);

                _ScanDeviceLibrary();
            }

            CombinedLibrary.AddRemoteLibrary(SelectedDevice.Database.BOOKS);

            return(true);
        }
コード例 #4
0
        private void UpdateDeviceInfoCommand_Execute()
        {
            var newDevices = new List <IDevice>(DevicesFinder.FindAvailableDevices(DeviceCreatorsListBuilder.BuildDeviceCreatorsList()));

            if ((Settings.Instance.Device != null) && (Settings.Instance.Device.IsConnected))
            {
                newDevices.Add(Settings.Instance.Device);

                if (!CompareDevicesList(newDevices, Devices))
                {
                    Devices        = newDevices;
                    SelectedDevice = Settings.Instance.Device;
                }
            }
            else
            {
                var buf = SelectedDevice?.ToString();

                if (!CompareDevicesList(newDevices, Devices))
                {
                    Devices = newDevices;

                    if (!string.IsNullOrEmpty(buf))
                    {
                        SelectedDevice = Devices.FirstOrDefault(x => x.ToString() == buf);
                    }
                }
            }

            IsConnected = Settings.Instance.Device == null ? false : Settings.Instance.Device.IsConnected;
        }
コード例 #5
0
ファイル: MainWindow.cs プロジェクト: sgmoore/KindleManager
        public async void _ReorganizeDeviceLibrary()
        {
            var dlg = new Dialogs.YesNo("Reorganize Library", "All books in your Kindle's library will be moved and renamed according to your Kindle's settings. This may take some time depending on the size of your library.");
            await MaterialDesignThemes.Wpf.DialogHost.Show(dlg);

            if (dlg.DialogResult == false)
            {
                return;
            }

            var prgDlg = new Dialogs.Progress("Reorganizing Library", true);

            OpenBottomDrawer(prgDlg.Content);

            _ = Task.Run(() =>
            {
                try
                {
                    foreach (BookBase book in SelectedDevice.Reorganize())
                    {
                        prgDlg.Current = $"Processed {book.Title}";
                    }
                    prgDlg.Current = "Cleaning up...";
                    SelectedDevice.Clean();
                }
                catch (Exception e)
                {
                    prgDlg.ShowError(e);
                }
                finally
                {
                    prgDlg.Finish($"{SelectedDevice.Name} reorganized.");
                }
            });
        }
コード例 #6
0
ファイル: MainWindow.cs プロジェクト: sgmoore/KindleManager
        public async void _ScanDeviceLibrary()
        {
            var dlg = new Dialogs.YesNo("Rescan Library", "Your Kindle will be scanned for books which will then be organized and renamed according to your Kindle's settings.");
            await MaterialDesignThemes.Wpf.DialogHost.Show(dlg);

            if (dlg.DialogResult == false)
            {
                return;
            }

            var prgDlg = new Dialogs.Progress("Scanning Library", true);

            OpenBottomDrawer(prgDlg.Content);

            _ = Task.Run(() =>
            {
                try
                {
                    foreach (BookBase book in SelectedDevice.Rescan())
                    {
                        prgDlg.Current = $"Processed {book.Title}";
                    }
                }
                catch (Exception e)
                {
                    prgDlg.ShowError(e);
                }
                finally
                {
                    prgDlg.Finish($"{SelectedDevice.Name} library scan complete.");
                }
            });
        }
コード例 #7
0
        /// <summary>
        /// Connect to the device given host name
        /// </summary>
        /// <param name="deviceHostName">Raw host name of the device</param>
        /// <returns>True if connected successfully. Else False</returns>
        public async Task <bool> ConnectAsync(string deviceHostName)
        {
            if (_socket != null)
            {
                _socket.Dispose();
                _socket = null;
            }

            if (!_adapter.IsEnabled)
            {
                throw new Exception("Bluetooth is off. Please turn it on from settings.");
            }

            SelectedDevice = _adapter.BondedDevices.FirstOrDefault(d => d.Address == deviceHostName);

            if (SelectedDevice != null)
            {
                var uuids = SelectedDevice.GetUuids();
                if (uuids != null && uuids.Length > 0)
                {
                    return(await Task.Run <bool>(() =>
                    {
                        _socket = SelectedDevice.CreateRfcommSocketToServiceRecord(UUID.FromString(uuids[0].ToString()));
                        _socket.Connect();
                        return IsConnected;
                    }));
                }
            }

            return(IsConnected);
        }
コード例 #8
0
        /// <summary>
        /// Connect to the currently selected service
        /// </summary>
        public async void ConnectToSelectedDevice()
        {
            Debug.WriteLine("ConnectToSelectedDevice: Entering");
            StopEnumeration();
            Views.Busy.SetBusy(true, "Connecting to " + SelectedDevice.Name);

            Debug.WriteLine("ConnectToSelectedDevice: Trying to connect to " + SelectedDevice.Name);

            if (selectedDevice.IsConnected == true)
            {
                Debug.WriteLine("ConnectToSelectedDevice: Going to Device Service Page");
                Views.Busy.SetBusy(false);
                //GotoDeviceServicesPage();
                NavigationService.Navigate(typeof(Views.CharacteristicPage));
                Debug.WriteLine("ConnectToSelectedDevice: Exiting");
                return;
            }


            if (await SelectedDevice.Connect() == false)
            {
                Debug.WriteLine("ConnectToSelectedDevice: Something went wrong getting the BluetoothLEDevice");
                Views.Busy.SetBusy(false);
                SelectedDevice = null;
                NavigationService.Navigate(typeof(Views.Discover));
                return;
            }

            Debug.WriteLine("ConnectToSelectedDevice: Going to Device Service Page");
            Views.Busy.SetBusy(false);
            GotoDeviceServicesPage();
            Debug.WriteLine("ConnectToSelectedDevice: Exiting");
        }
コード例 #9
0
        private void OnSelection(object sender, SelectedItemChangedEventArgs e)
        {
            if (e.SelectedItem == null)
            {
                return;
            }

            ScanResults selectedScanResult = (ScanResults)e.SelectedItem;

            //DisplayAlert("Item Selected", selectedScanResult.GuiName, "Ok");
            ((ListView)sender).SelectedItem = null;
            selectedScanResult.IsRunning    = true;
            selectedScanResult.IsVisible    = true;

            System.Collections.Generic.List <Plugin.BLE.Abstractions.Contracts.IDevice> systemDevices =
                Plugin.BLE.CrossBluetoothLE.Current.Adapter.GetSystemConnectedOrPairedDevices();

            if ((selectedDevice == null) || (selectedScanResult.Name != selectedDevice.scanResult.Name))
            {
                selectedDevice = new SelectedDevice(selectedScanResult);
            }
            else if (systemDevices.Contains(selectedDevice.bledevice))
            {
                selectedDevice.SendDataToConnectedDevice();
            }
            else
            {
                selectedDevice = new SelectedDevice(selectedScanResult);
            }
        }
コード例 #10
0
 /// <summary>
 /// Factory method which returns IDataReceiver for selected device.
 /// </summary>
 /// <param name="dataReceiver">Selected device.</param>
 /// <returns>IDataReceiver for selected device.</returns>
 public IDataReceiver GetDataReceiver(SelectedDevice dataReceiver)
 {
     switch (dataReceiver)
     {
         case SelectedDevice.Battery:
         {
             return new BatteryDataReceiver(devicesManager.RoboteQ);
         }
         case SelectedDevice.Hokuyo:
         {
             return new HokuyoSensorDataReceiver(devicesManager.Hokuyo);
         }
         case SelectedDevice.Sharp:
         {
             return new SharpSensorsDataReceiver(devicesManager.Arduino);
         }
         case SelectedDevice.Mobot:
         {
             return new MobotSensorDataReceiver(devicesManager.Arduino);
         }
         case SelectedDevice.Encoder:
         {
             return new EncoderDataReceiver(devicesManager.RoboteQ);
         }
         case SelectedDevice.Temperature:
         {
             return new TemperatureDataReceiver(devicesManager.RoboteQ);
         }
         default:
         {
             Logger.Log(new ArgumentException("Wrong DataReceiver type"));
             return new NullDataReceiver();
         }
     }
 }
コード例 #11
0
 /// <summary> Connects the selected device. </summary>
 /// <returns> True if the connection succeeds. </returns>
 public bool Connect()
 {
     if (SelectedDevice.IsValidAddress())
     {
         IsConnected = true;
     }
     return(IsConnected);
 }
コード例 #12
0
 private void Device_MouseDoubleClick(object sender, MouseButtonEventArgs e)
 {
     if (SelectedDevice != null)
     {
         CurrentStep = SelectedDevice.StartsWith("Serial") ? Steps.WaitForDeviceConfirm : Steps.WaitForConnection;
         AdvanceStateMachine();
     }
 }
コード例 #13
0
ファイル: SnoopMain.cs プロジェクト: ming-hai/ACN
        void modeTool_Click(object sender, EventArgs e)
        {
            ToolStripDropDownItem item = sender as ToolStripDropDownItem;

            if (item != null)
            {
                SelectedDevice.SetMode((int)item.Tag);
            }
        }
コード例 #14
0
        public async Task RefreshDevices(bool connect = true, bool afterStartUp = false)
        {
            Devices = Config.Devices;
            var customIpAddresses = Devices.Where(d => d.IsCustom).Select(d => d.IpAddress);

            var pnpDevices = await Utils.GetPnpDevices(Config.DeviceSearchKey);

            var autoDevices     = pnpDevices.Where(p => !customIpAddresses.Contains(p.IpAddress)).Select(d => new LgDevice(d.Name, d.IpAddress, d.MacAddress, false)).ToList();
            var autoIpAddresses = pnpDevices.Select(d => d.IpAddress);

            Devices.RemoveAll(d => !d.IsCustom && !autoIpAddresses.Contains(d.IpAddress));

            var newAutoDevices = autoDevices.Where(ad => ad.IpAddress != null && !Devices.Any(d => d.IpAddress != null && d.IpAddress.Equals(ad.IpAddress)));

            Devices.AddRange(newAutoDevices);

            if (Devices.Any())
            {
                var preferredDevice = Devices.FirstOrDefault(x => x.MacAddress != null && x.MacAddress.Equals(Config.PreferredMacAddress)) ?? Devices[0];

                SelectedDevice = preferredDevice;
            }
            else
            {
                SelectedDevice = null;
            }

            if (afterStartUp && SelectedDevice == null && Config.PowerOnAfterStartup && !string.IsNullOrEmpty(Config.PreferredMacAddress))
            {
                Logger.Debug("No device has been found, trying to wake it first...");

                var tempDevice = new LgDevice("Test", string.Empty, Config.PreferredMacAddress);
                tempDevice.Wake();

                await Task.Delay(4000);
                await RefreshDevices();

                return;
            }

            foreach (var device in Devices)
            {
                device.PowerStateChangedEvent += LgDevice_PowerStateChangedEvent;
            }

            if (connect && SelectedDevice != null)
            {
                if (_allowPowerOn)
                {
                    WakeAfterStartupOrResume();
                }
                else
                {
                    var _ = SelectedDevice.Connect();
                }
            }
        }
コード例 #15
0
 private Emulator CreateEmulator()
 {
     if (SelectedDevice.IsDefault())
     {
         return(new Emulator());
     }
     return(new Emulator(SelectedDevice.ImageFile, SelectedDevice.ScreenPoint,
                         SelectedDevice.ScreenSize, SelectedOrientation, SelectedScale));
 }
コード例 #16
0
 private async void SendMessage()
 {
     await SelectedDevice.SendRequestAsync <ChatMessageRequest, ChatMessageResponse>(new ChatMessageRequest()
     {
         Message = Message
     }, new ResonanceRequestConfig()
     {
         LoggingMode = ResonanceMessageLoggingMode.Content
     });
 }
コード例 #17
0
 public async Task GetService()
 {
     if (adapter.ConnectedDevices.Count > 0)
     {
         if (SelectedDevice == null)
         {
             SelectedDevice = adapter.ConnectedDevices[0];
         }
         Service = await SelectedDevice.GetServiceAsync(new Guid(6166, 0, 4096, 128, 0, 0, 128, 95, 155, 52, 251));
     }
 }
コード例 #18
0
ファイル: SnoopMain.cs プロジェクト: ming-hai/ACN
        private void addressTool_Click(object sender, EventArgs e)
        {
            DmxAddressDialog addressDialog = new DmxAddressDialog();

            addressDialog.DmxAddress = SelectedDevice.DmxAddress;

            if (addressDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                SelectedDevice.SetDmxAddress(addressDialog.DmxAddress);
            }
        }
コード例 #19
0
 public MainWindowViewModel()
 {
     DemoMode = new DemoCommand()
     {
         Executer = () => SetDevice(new DemoSensiEdge())
     };
     FindMode = new DemoCommand()
     {
         Executer = () => { SetDevice(null); SelectedDevice.SetBluetoothAddress(ulong.MaxValue); }
     };
     SetDevice(null);
 }
コード例 #20
0
        public void Start()
        {
            // If no device selected, don't do anything
            if (SelectedDevice == null || !(Communicator is null))
            {
                return;
            }

            // Start scan
            Communicator = SelectedDevice.Open(0x10000, PacketDeviceOpenAttributes.Promiscuous, 1000);
            Communicator.ReceivePackets(-1, ProcessPacket); // Get packets indefinitely
        }
コード例 #21
0
        public void GetTemperatureDataReceiverTest()
        {
            //  Given
            DataReceiverFactory dataReceiverFactory = new DataReceiverFactory(devicesManager);
            SelectedDevice      dataReceiverType    = SelectedDevice.Temperature;

            //  When
            IDataReceiver dataReceiver = dataReceiverFactory.GetDataReceiver(dataReceiverType);

            //  Then
            Assert.IsTrue(dataReceiver is TemperatureDataReceiver);
        }
コード例 #22
0
        public void GetSharpSensorsDataReceiverTest()
        {
            //  Given
            DataReceiverFactory dataReceiverFactory = new DataReceiverFactory(devicesManager);
            SelectedDevice      dataReceiverType    = SelectedDevice.Sharp;

            //  When
            IDataReceiver dataReceiver = dataReceiverFactory.GetDataReceiver(dataReceiverType);

            //  Then
            Assert.IsTrue(dataReceiver is SharpSensorsDataReceiver);
        }
コード例 #23
0
        public void GetEncoderDataReceiverTest()
        {
            //  Given
            DataReceiverFactory dataReceiverFactory = new DataReceiverFactory(devicesManager);
            SelectedDevice      dataReceiverType    = SelectedDevice.Encoder;

            //  When
            IDataReceiver dataReceiver = dataReceiverFactory.GetDataReceiver(dataReceiverType);

            //  Then
            Assert.IsTrue(dataReceiver is EncoderDataReceiver);
        }
コード例 #24
0
        public void EncoderReceiveDataHasValidDeviceTypeTest()
        {
            //  Given
            EncoderDataReceiver ecoderDataReceiver   = new EncoderDataReceiver(roboteQ);
            SelectedDevice      expectedDataReceiver = SelectedDevice.Encoder;

            //  When
            SelectedDevice actualDataReceiver = ecoderDataReceiver.ReceiveData().SelectedDeviceType;

            //  Then
            Assert.AreEqual(expectedDataReceiver, actualDataReceiver);
        }
コード例 #25
0
        public void HokuyoSensorsReceiveDataHasValidDeviceTypeTest()
        {
            //  Given
            HokuyoSensorDataReceiver hokuyoSensorDataReceiver = new HokuyoSensorDataReceiver(hokuyo);
            SelectedDevice           expectedDataReceiver     = SelectedDevice.Hokuyo;

            //  When
            SelectedDevice actualDataReceiver = hokuyoSensorDataReceiver.ReceiveData().SelectedDeviceType;

            //  Then
            Assert.AreEqual(expectedDataReceiver, actualDataReceiver);
        }
コード例 #26
0
 private void conn()
 {
     if (SelectedDevice != null)
     {
         IsConnected   = SelectedDevice.OpenDevice();
         ConnectedText = IsConnected == true ? "Connected" : "Disconnected";
     }
     else
     {
         MessageBox.Show("Please choose device first");
     }
 }
コード例 #27
0
        public void SharpSensorsReceiveDataHasValidDeviceTypeTest()
        {
            //  Given
            SharpSensorsDataReceiver sharpSensorsDataReceiver = new SharpSensorsDataReceiver(arduino);
            SelectedDevice           expectedDataReceiver     = SelectedDevice.Sharp;

            //  When
            SelectedDevice actualDataReceiver = sharpSensorsDataReceiver.ReceiveData().SelectedDeviceType;

            //  Then
            Assert.AreEqual(expectedDataReceiver, actualDataReceiver);
        }
コード例 #28
0
        public void TemperatureReceiveDataHasValidDeviceTypeTest()
        {
            //  Given
            TemperatureDataReceiver temperatureDataReceiver = new TemperatureDataReceiver(roboteQ);
            SelectedDevice          expectedDataReceiver    = SelectedDevice.Temperature;

            //  When
            SelectedDevice actualDataReceiver = temperatureDataReceiver.ReceiveData().SelectedDeviceType;

            //  Then
            Assert.AreEqual(expectedDataReceiver, actualDataReceiver);
        }
コード例 #29
0
        private void HandleDeviceDeleted(IDeviceInfo deviceInfo)
        {
            if (SelectedDevice.Value == deviceInfo)
            {
                var noDevice = availableDevices.Single(x => x.Info == null);
                SelectedDevice.SetValue(noDevice);
            }

            var deviceViewModel = availableDevices.Single(x => x.Info == deviceInfo);

            availableDevices.Remove(deviceViewModel);
        }
コード例 #30
0
        public void BatteryReceiveDataHasValidDeviceTypeTest()
        {
            //  Given
            BatteryDataReceiver batteryDataReceiver  = new BatteryDataReceiver(roboteQ);
            SelectedDevice      expectedDataReceiver = SelectedDevice.Battery;

            //  When
            SelectedDevice actualDataReceiver = batteryDataReceiver.ReceiveData().SelectedDeviceType;

            //  Then
            Assert.AreEqual(expectedDataReceiver, actualDataReceiver);
        }
コード例 #31
0
        private void ReadConfigButton_Click(object sender, RoutedEventArgs e)
        {
            var result = SelectedDevice?.ReadConfig();

            if (result == true)
            {
                UpdateControls();
            }
            else if (result == false)
            {
                StatusWrite("Failed to get config. Unplug and reconnect.");
            }
        }
コード例 #32
0
        public EditDevice(SelectedDevice sd, ChannelManager cm)
        {
            InitializeComponent();

            this.cm = cm;
            this.sd = sd;

            // Initialize the fields with relevant information
            this.logicalIDText.Text = sd.logicalID.ToString();
            this.deviceTypeText.Text = sd.channelTypeString;
            this.deviceNameText.Text = sd.lc.Name;
            this.deviceDescText.Text = sd.lc.Description;

            this.availableHardwareChanCombo.Items.Clear();
            this.availableHardwareChanCombo.Items.Add(HardwareChannel.Unassigned);
            if (sd.lc.HardwareChannel!=null)
                this.availableHardwareChanCombo.Items.Add(sd.lc.HardwareChannel);

            // Fill the availableHardwareChanCombo with relevant items
            foreach (HardwareChannel hc in cm.knownHardwareChannels)
                if (hc.ChannelType == sd.channelType)
                    if (!Storage.settingsData.logicalChannelManager.AssignedHardwareChannels.Contains(hc))
                        this.availableHardwareChanCombo.Items.Add(hc);

            this.availableHardwareChanCombo.SelectedItem = sd.lc.HardwareChannel;

            togglingCheck.Checked = sd.lc.TogglingChannel;

            if (sd.channelType == HardwareChannel.HardwareConstants.ChannelTypes.analog)
            {
                checkBox1.Visible = true;
            }
            else
            {
                checkBox1.Visible = false;
            }

            if (sd.channelType == HardwareChannel.HardwareConstants.ChannelTypes.analog ||
                sd.channelType == HardwareChannel.HardwareConstants.ChannelTypes.digital)
            {
                togglingCheck.Visible = true;
            }
            else
            {
                togglingCheck.Visible = false;
            }

            checkBox1.Checked = sd.lc.AnalogChannelOutputNowUsesDwellWord;
        }