private void OpenSetupDialog(object o) { if (SelectedDevice?.HasSetupDialog == true) { SelectedDevice.SetupDialog(); } }
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"))); }
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); }
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; }
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."); } }); }
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."); } }); }
/// <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); }
/// <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"); }
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); } }
/// <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(); } } }
/// <summary> Connects the selected device. </summary> /// <returns> True if the connection succeeds. </returns> public bool Connect() { if (SelectedDevice.IsValidAddress()) { IsConnected = true; } return(IsConnected); }
private void Device_MouseDoubleClick(object sender, MouseButtonEventArgs e) { if (SelectedDevice != null) { CurrentStep = SelectedDevice.StartsWith("Serial") ? Steps.WaitForDeviceConfirm : Steps.WaitForConnection; AdvanceStateMachine(); } }
void modeTool_Click(object sender, EventArgs e) { ToolStripDropDownItem item = sender as ToolStripDropDownItem; if (item != null) { SelectedDevice.SetMode((int)item.Tag); } }
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(); } } }
private Emulator CreateEmulator() { if (SelectedDevice.IsDefault()) { return(new Emulator()); } return(new Emulator(SelectedDevice.ImageFile, SelectedDevice.ScreenPoint, SelectedDevice.ScreenSize, SelectedOrientation, SelectedScale)); }
private async void SendMessage() { await SelectedDevice.SendRequestAsync <ChatMessageRequest, ChatMessageResponse>(new ChatMessageRequest() { Message = Message }, new ResonanceRequestConfig() { LoggingMode = ResonanceMessageLoggingMode.Content }); }
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)); } }
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); } }
public MainWindowViewModel() { DemoMode = new DemoCommand() { Executer = () => SetDevice(new DemoSensiEdge()) }; FindMode = new DemoCommand() { Executer = () => { SetDevice(null); SelectedDevice.SetBluetoothAddress(ulong.MaxValue); } }; SetDevice(null); }
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 }
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); }
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); }
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); }
public void EncoderReceiveDataHasValidDeviceTypeTest() { // Given EncoderDataReceiver ecoderDataReceiver = new EncoderDataReceiver(roboteQ); SelectedDevice expectedDataReceiver = SelectedDevice.Encoder; // When SelectedDevice actualDataReceiver = ecoderDataReceiver.ReceiveData().SelectedDeviceType; // Then Assert.AreEqual(expectedDataReceiver, actualDataReceiver); }
public void HokuyoSensorsReceiveDataHasValidDeviceTypeTest() { // Given HokuyoSensorDataReceiver hokuyoSensorDataReceiver = new HokuyoSensorDataReceiver(hokuyo); SelectedDevice expectedDataReceiver = SelectedDevice.Hokuyo; // When SelectedDevice actualDataReceiver = hokuyoSensorDataReceiver.ReceiveData().SelectedDeviceType; // Then Assert.AreEqual(expectedDataReceiver, actualDataReceiver); }
private void conn() { if (SelectedDevice != null) { IsConnected = SelectedDevice.OpenDevice(); ConnectedText = IsConnected == true ? "Connected" : "Disconnected"; } else { MessageBox.Show("Please choose device first"); } }
public void SharpSensorsReceiveDataHasValidDeviceTypeTest() { // Given SharpSensorsDataReceiver sharpSensorsDataReceiver = new SharpSensorsDataReceiver(arduino); SelectedDevice expectedDataReceiver = SelectedDevice.Sharp; // When SelectedDevice actualDataReceiver = sharpSensorsDataReceiver.ReceiveData().SelectedDeviceType; // Then Assert.AreEqual(expectedDataReceiver, actualDataReceiver); }
public void TemperatureReceiveDataHasValidDeviceTypeTest() { // Given TemperatureDataReceiver temperatureDataReceiver = new TemperatureDataReceiver(roboteQ); SelectedDevice expectedDataReceiver = SelectedDevice.Temperature; // When SelectedDevice actualDataReceiver = temperatureDataReceiver.ReceiveData().SelectedDeviceType; // Then Assert.AreEqual(expectedDataReceiver, actualDataReceiver); }
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); }
public void BatteryReceiveDataHasValidDeviceTypeTest() { // Given BatteryDataReceiver batteryDataReceiver = new BatteryDataReceiver(roboteQ); SelectedDevice expectedDataReceiver = SelectedDevice.Battery; // When SelectedDevice actualDataReceiver = batteryDataReceiver.ReceiveData().SelectedDeviceType; // Then Assert.AreEqual(expectedDataReceiver, actualDataReceiver); }
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."); } }
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; }