public void LoadPortList() { // POSIX specific List <string> ports; if ((Environment.OSVersion.Platform == PlatformID.Unix) || (Environment.OSVersion.Platform == PlatformID.MacOSX)) { try { if (Directory.Exists(@"/dev/serial/by-id")) { // probably is unix var psi = new Process(); psi.StartInfo.WindowStyle = ProcessWindowStyle.Normal; psi.EnableRaisingEvents = false; psi.StartInfo.UseShellExecute = false; psi.StartInfo.RedirectStandardOutput = true; psi.StartInfo.FileName = @"sh"; psi.StartInfo.Arguments = @"-c 'for s in /dev/serial/by-path/*; do readlink -f $s; done'"; psi.Start(); psi.WaitForExit(); ports = psi.StandardOutput.ReadToEnd().Split('\n').ToList(); ports.RemoveAt(ports.Count - 1); } else { // probably is mac var psi = new Process(); psi.StartInfo.WindowStyle = ProcessWindowStyle.Normal; psi.EnableRaisingEvents = false; psi.StartInfo.UseShellExecute = false; psi.StartInfo.RedirectStandardOutput = true; psi.StartInfo.FileName = @"sh"; psi.StartInfo.Arguments = @"-c 'ls /dev/tty.*'"; psi.Start(); psi.WaitForExit(); ports = psi.StandardOutput.ReadToEnd().Split('\n').ToList(); ports.RemoveAt(ports.Count - 1); } } catch (Exception) { ports = SerialPort.GetPortNames().ToList(); } } else { ports = SerialPort.GetPortNames().ToList(); } var dialog = new FmSelectTextDialog(ports, ports, "Select your port"); dialog.ShowModal(); if (dialog.OutputIndex >= 0) { this.BtnSelectPort.Text = "Port: " + dialog.OutputKeys[dialog.OutputIndex]; } }
private void BtnPortsClicked() { Ports = GetPorts(); var dialog = new FmSelectTextDialog(Ports, Ports, "Select your port"); dialog.ShowModal(); if (dialog.OutputIndex >= 0) { this.LSelectedPort.Text = "Port: " + dialog.OutputKeys[dialog.OutputIndex]; SelectedPort = dialog.OutputKeys[dialog.OutputIndex]; } }
private void SelectDevice() { var lst = Directory.GetFiles(Path.Combine(MdPersistentData.ConfigPath, MdConstant.D_KEYBOARD), "*" + MdConstant.E_KEYBOARD).ToList(); var fm = new FmSelectTextDialog(lst, lst.Select(ele => Path.GetFileNameWithoutExtension(ele)).ToList(), "Select a device"); fm.ShowModal(); var outputInd = fm.OutputIndex; if (outputInd >= 0) { var kb = MdCore.Deserialize <ClKeyboard>(fm.OutputValues[outputInd]); MdSessionData.CurrentKeyboardType = kb; MdSessionData.CurrentLayout = kb.GenerateLayout(); var ucl = new UCKeyboard(MdSessionData.CurrentKeyboardType, MdSessionData.CurrentLayout); MdSessionData.CurrentKeyboardUI = ucl; this.PnMain.Content = ucl; this.BtnSelectDevice.Text = "Device: " + kb.Name; } }
private void OpenMacroMenu() { var lst = new List <string> { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }; var fm = new FmSelectTextDialog(lst, lst.Select(ele => "macro" + ele).ToList(), "Select a macro key to edit"); fm.ShowModal(); var outputInd = fm.OutputIndex; if (outputInd >= 0) { if (!MdSessionData.OpenedMacroEdit) { if (MdSessionData.CurrentLayout.KeyDatas.Count == 0) { MessageBox.Show("Error: You must first select a device"); } else { MdSessionData.OpenedMacroEdit = true; var lay = MdSessionData.CurrentLayout; var dataCont = new ClMacroDataContainer(); var hasData = false; foreach (var ele in lay.AddonDatas) { if (ele.GetType() == ClMacroDataContainer.DATA_TYPE) { hasData = true; dataCont = ele as ClMacroDataContainer; } } if (!hasData) { lay.AddonDatas.Add(dataCont); } var data = new ClMacroData(); data.Index = outputInd; hasData = false; if (dataCont != null) { foreach (var ele in dataCont.MacroKeys) { if (ele.Index == outputInd) { hasData = true; data = ele; } } if (!hasData) { dataCont.MacroKeys.Add(data); } } var mdialog = new FmMacroEdit(new ClMacroData(data)); mdialog.Show(); } } else { MessageBox.Show("Error: Macro editor already opened"); } } }