Add baud to com port setup

issue: MatterHackers/MatterControl#4884
Add ability to set baud rate in manual connection window
This commit is contained in:
LarsBrubaker 2020-12-15 15:00:00 -08:00
parent c0374c92e5
commit c8bfef2085
4 changed files with 46 additions and 82 deletions

View file

@ -33,6 +33,7 @@ using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.SerialPortCommunication.FrostedSerial;
namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
@ -79,7 +80,6 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
printer.Connection.ConnectionFailed += Connection_CommunicationStateChanged;
printer.Connection.ConnectionSucceeded += Connection_CommunicationStateChanged;
printer.Settings.Helpers.SetComPort(GetSelectedSerialPort());
printer.Connection.Connect();
connectButton.Visible = false;
@ -140,8 +140,34 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
HAnchor = HAnchor.Stretch
};
var serialPortContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
CreateSerialPortControls(serialPortContainer, null);
var serialPortContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
{
HAnchor = HAnchor.Stretch
};
var settingsContext = new SettingsContext(printer, null, NamedSettingsLayers.All);
var menuTheme = ApplicationController.Instance.MenuTheme;
var tabIndex = 0;
var settingsToAdd = new[]
{
SettingsKey.com_port,
SettingsKey.baud_rate,
};
// turn off the port wizard button in this context
ComPortField.ShowPortWizardButton = false;
foreach (var key in settingsToAdd)
{
var settingsRow = SliceSettingsTabView.CreateItemRow(
PrinterSettings.SettingsData[key],
settingsContext,
printer,
menuTheme,
ref tabIndex);
serialPortContainer.AddChild(settingsRow);
}
ComPortField.ShowPortWizardButton = false;
var comPortMessageContainer = new FlowLayoutWidget
{
@ -202,71 +228,5 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
nextButton.Visible = false;
}
}
protected void CreateSerialPortControls(FlowLayoutWidget comPortContainer, string activePrinterSerialPort)
{
int portIndex = 0;
// Add a radio button for each filtered port
foreach (string portName in FrostedSerialPort.GetPortNames())
{
SerialPortIndexRadioButton comPortOption = CreateComPortOption(portName, activePrinterSerialPort == portName);
if (comPortOption.Checked)
{
printerComPortIsAvailable = true;
}
serialPortButtonsList.Add(comPortOption);
comPortContainer.AddChild(comPortOption);
portIndex++;
}
// Add a virtual entry for serial ports that were previously configured but are not currently connected
if (!printerComPortIsAvailable && activePrinterSerialPort != null)
{
SerialPortIndexRadioButton comPortOption = CreateComPortOption(activePrinterSerialPort, true);
comPortOption.Enabled = false;
comPortContainer.AddChild(comPortOption);
serialPortButtonsList.Add(comPortOption);
portIndex++;
}
// If there are still no com ports show a message to that effect
if (portIndex == 0)
{
var comPortOption = new TextWidget("No COM ports available".Localize())
{
Margin = new BorderDouble(3, 6, 5, 6),
TextColor = theme.TextColor
};
comPortContainer.AddChild(comPortOption);
}
}
private SerialPortIndexRadioButton CreateComPortOption(string portName, bool isActivePrinterPort)
{
return new SerialPortIndexRadioButton(portName, portName)
{
HAnchor = HAnchor.Left,
Margin = new BorderDouble(3, 3, 5, 3),
TextColor = theme.TextColor,
Checked = isActivePrinterPort
};
}
private string GetSelectedSerialPort()
{
foreach (SerialPortIndexRadioButton button in serialPortButtonsList)
{
if (button.Checked)
{
return button.PortValue;
}
}
throw new Exception("Could not find a selected button.".Localize());
}
}
}

View file

@ -52,6 +52,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
}
public new string Name { get; set; }
public static bool ShowPortWizardButton { get; set; } = true;
public override void Initialize(int tabIndex)
{
@ -103,18 +104,21 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
unregisterEvents?.Invoke(null, null);
};
var configureIcon = new IconButton(StaticData.Instance.LoadIcon("fa-cog_16.png", 16, 16, theme.InvertIcons), theme)
if (ShowPortWizardButton)
{
VAnchor = VAnchor.Center,
Margin = theme.ButtonSpacing,
ToolTipText = "Port Wizard".Localize()
};
configureIcon.Click += (s, e) =>
{
DialogWindow.Show(new SetupStepComPortOne(printer));
};
panel.AddChild(configureIcon);
var configureIcon = new IconButton(StaticData.Instance.LoadIcon("fa-cog_16.png", 16, 16, theme.InvertIcons), theme)
{
VAnchor = VAnchor.Center,
Margin = theme.ButtonSpacing,
ToolTipText = "Port Wizard".Localize()
};
configureIcon.Click += (s, e) =>
{
DialogWindow.Show(new SetupStepComPortOne(printer));
};
panel.AddChild(configureIcon);
}
panel.AddChild(dropdownList);

@ -1 +1 @@
Subproject commit 76cfdeaa803464bc15406805507773fd66a768ff
Subproject commit d52b44473d47b65d8be78e2f177fb940a65ff3a4

@ -1 +1 @@
Subproject commit de9c91f7986348b0b891c6614bf7af279e540cbc
Subproject commit db87d039f6736f57ccb672632afa376ab907bc06