Remove ActiveSliceSettings.Instance

- Issue MatterHackers/MCCentral#4243
This commit is contained in:
John Lewin 2018-10-05 09:24:57 -07:00
parent d8a5100639
commit 6dbae7668b
32 changed files with 153 additions and 135 deletions

View file

@ -79,8 +79,9 @@ namespace MatterHackers.MatterControl.Plugins.X3GDriver
StreamReader inputFile = new StreamReader(result.Stream);
FileStream binaryFileStream = new FileStream(outputPath, FileMode.OpenOrCreate);
BinaryWriter outputFile = new BinaryWriter(binaryFileStream);
X3GPrinterDetails printerDetails = new X3GPrinterDetails();
X3GWriter x3gConverter = new X3GWriter(printerDetails);
var x3gConverter = new X3GWriter(new X3GPrinterDetails(), ApplicationController.Instance.ActivePrinter);
List<byte[]> x3gLines = new List<byte[]>();
byte[] emptyByteArray = { 0 };
string line;

View file

@ -16,13 +16,15 @@ namespace MatterHackers.MatterControl.Plugins.X3GDriver
*******************************************************/
public class X3GReader
{
private PrinterConfig printer;
private X3GPrinterDetails printerDetails;
private X3GPacketAnalyzer analyzer;
public X3GReader(X3GPrinterDetails PtrDetails)
public X3GReader(X3GPrinterDetails PtrDetails, PrinterConfig printer)
{
this.printer = printer;
this.printerDetails = PtrDetails;
analyzer = new X3GPacketAnalyzer(PtrDetails);
analyzer = new X3GPacketAnalyzer(PtrDetails, printer);
}
public string translate(byte[] x3gResponse, string relatedGCommand, out bool commandOK)
@ -34,27 +36,20 @@ namespace MatterHackers.MatterControl.Plugins.X3GDriver
private class X3GPacketAnalyzer
{
private byte[] response;
private PrinterConfig printer;
private X3GCrc crc;
private string gCommandForResponse; //Figure out better name. this is the gCommand that was sent to the printer that caused this response
private X3GPrinterDetails printerDetails; //used to get location information and other needed response data
private StringBuilder temperatureResponseStrBuilder; //Saves extruder temp when we have a heated bed to send back temps together
public X3GPacketAnalyzer(X3GPrinterDetails PtrDetails)
public X3GPacketAnalyzer(X3GPrinterDetails PtrDetails, PrinterConfig printer)
{
this.printer = printer;
crc = new X3GCrc();
printerDetails = PtrDetails;
temperatureResponseStrBuilder = new StringBuilder();
}
public X3GPacketAnalyzer(byte[] x3gResponse, string relatedGCommand, X3GPrinterDetails PtrDetails)
{
response = x3gResponse;
crc = new X3GCrc();
gCommandForResponse = relatedGCommand;
printerDetails = PtrDetails;
temperatureResponseStrBuilder = new StringBuilder();
}
public string analyze(byte[] x3gResponse, string relatedGcommand, out bool commandOK)
{
response = x3gResponse;
@ -159,7 +154,7 @@ namespace MatterHackers.MatterControl.Plugins.X3GDriver
if (printerDetails.teperatureResponseCount == 1)
{
if (ActiveSliceSettings.Instance.GetValue<int>(SettingsKey.extruder_count) > 1)
if (printer.Settings.GetValue<int>(SettingsKey.extruder_count) > 1)
{
temperatureResponseStrBuilder.Append(String.Format(" T0:{0}", temperature));
}
@ -168,7 +163,7 @@ namespace MatterHackers.MatterControl.Plugins.X3GDriver
temperatureResponseStrBuilder.Append(String.Format(" T:{0}", temperature));
}
}
else if (printerDetails.teperatureResponseCount == 2 && ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.has_heated_bed))
else if (printerDetails.teperatureResponseCount == 2 && printer.Settings.GetValue<bool>(SettingsKey.has_heated_bed))
{
temperatureResponseStrBuilder.Append(String.Format(" B:{0}", temperature));
}

View file

@ -9,7 +9,7 @@ namespace MatterHackers.MatterControl.Plugins.X3GDriver
public override IFrostedSerialPort Create(string serialPortName)
{
return new X3GSerialPortWrapper(serialPortName);
return new X3GSerialPortWrapper(serialPortName, ApplicationController.Instance.ActivePrinter);
}
}
}

View file

@ -33,12 +33,12 @@ namespace MatterHackers.Plugins.X3GDriver
private bool waitForResponse;
private bool dtrEnable;
public X3GSerialPortWrapper(string serialPortName)
public X3GSerialPortWrapper(string serialPortName, PrinterConfig printer)
{
port = FrostedSerialPortFactory.GetAppropriateFactory("raw").Create(serialPortName);
printerDetails = new X3GPrinterDetails();
writer = new X3GWriter(printerDetails);
reader = new X3GReader(printerDetails);
writer = new X3GWriter(printerDetails, printer);
reader = new X3GReader(printerDetails, printer);
timeSinceLastCommandSent = new Stopwatch();
timeSinceLastOK = new Stopwatch();
sentCommandQueue = new Queue<string>();

View file

@ -11,6 +11,7 @@ namespace MatterHackers.MatterControl.Plugins.X3GDriver
{
public class X3GWriter
{
private PrinterConfig printer;
private X3GPrinterDetails printerDetails;
private Queue<byte[]> overFlowPackets;
@ -30,8 +31,9 @@ namespace MatterHackers.MatterControl.Plugins.X3GDriver
lineNumber = 0;
}
public X3GWriter(X3GPrinterDetails printerInfo)
public X3GWriter(X3GPrinterDetails printerInfo, PrinterConfig printer)
{
this.printer = printer;
printerDetails = printerInfo;
overFlowPackets = new Queue<byte[]>();
feedrate = 3200;
@ -116,7 +118,7 @@ namespace MatterHackers.MatterControl.Plugins.X3GDriver
convertedMessage = binaryPacket.getX3GPacket();
printerDetails.requiredTemperatureResponseCount = 1;
if (ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.has_heated_bed))//if it has a bed get the bed temp
if (printer.Settings.GetValue<bool>(SettingsKey.has_heated_bed))//if it has a bed get the bed temp
{
binaryPacket = new X3GPacketFactory(10);
binaryPacket.addByte(0);
@ -125,7 +127,7 @@ namespace MatterHackers.MatterControl.Plugins.X3GDriver
overFlowPackets.Enqueue(binaryPacket.getX3GPacket());
}
if (ActiveSliceSettings.Instance.GetValue<int>(SettingsKey.extruder_count) > 1)
if (printer.Settings.GetValue<int>(SettingsKey.extruder_count) > 1)
{
binaryPacket = new X3GPacketFactory(10);
binaryPacket.addByte(1);
@ -275,7 +277,7 @@ namespace MatterHackers.MatterControl.Plugins.X3GDriver
printerDetails.heatingLockout = true;
break;
case 134://wait for build platform temp Makerbot M134
if (ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.has_heated_bed))
if (printer.Settings.GetValue<bool>(SettingsKey.has_heated_bed))
{
binaryPacket = new X3GPacketFactory(136);
@ -303,7 +305,7 @@ namespace MatterHackers.MatterControl.Plugins.X3GDriver
convertedMessage = binaryPacket.getX3GPacket();
break;
case 140://Set Bed temp M140
if (ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.has_heated_bed))
if (printer.Settings.GetValue<bool>(SettingsKey.has_heated_bed))
{
int temperature = (int)getParameterValue(commands, 'S');
binaryPacket = new X3GPacketFactory(136);
@ -322,7 +324,7 @@ namespace MatterHackers.MatterControl.Plugins.X3GDriver
break;
case 190://Wait for bed to reach target temp M190
if (ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.has_heated_bed))
if (printer.Settings.GetValue<bool>(SettingsKey.has_heated_bed))
{
int temperature = (int)getParameterValue(commands, 'S');
binaryPacket = new X3GPacketFactory(136);