Convert to standard events with line arg

This commit is contained in:
John Lewin 2018-11-09 08:57:30 -08:00
parent 8c2f2314dd
commit f83fadd06b
12 changed files with 136 additions and 180 deletions

View file

@ -91,7 +91,7 @@ namespace MatterHackers.MatterControl.Library
// Ask for files and listen for response
gotBeginFileList = false;
printer.Connection.LineReceived.RegisterEvent(Printer_LineRead, ref unregisterEvents);
printer.Connection.LineReceived += Printer_LineRead;
printer.Connection.QueueLine("M21\r\nM20");
// Block and wait up to timeout for response
@ -108,13 +108,13 @@ namespace MatterHackers.MatterControl.Library
ApplicationController.Instance.Theme.InvertIcons));
}
private void Printer_LineRead(object sender, EventArgs e)
private void Printer_LineRead(object sender, string line)
{
if (e is StringEventArgs currentEvent)
if (line != null)
{
if (!currentEvent.Data.StartsWith("echo:"))
if (!line.StartsWith("echo:"))
{
switch (currentEvent.Data)
switch (line)
{
case "Begin file list":
gotBeginFileList = true;
@ -122,7 +122,7 @@ namespace MatterHackers.MatterControl.Library
break;
case "End file list":
printer.Connection.LineReceived.UnregisterEvent(Printer_LineRead, ref unregisterEvents);
printer.Connection.LineReceived -= Printer_LineRead;
// Release the Load WaitOne
autoResetEvent.Set();
@ -131,14 +131,14 @@ namespace MatterHackers.MatterControl.Library
default:
if (gotBeginFileList)
{
string sdCardFileExtension = currentEvent.Data.ToUpper();
string sdCardFileExtension = line.ToUpper();
bool validSdCardItem = sdCardFileExtension.Contains(".GCO") || sdCardFileExtension.Contains(".GCODE");
if (validSdCardItem)
{
this.Items.Add(new SDCardFileItem()
{
Name = currentEvent.Data
Name = line
});
}
}