Move temp processing into PrinterConnection
This commit is contained in:
parent
57c1b4c929
commit
afedb2555a
6 changed files with 139 additions and 91 deletions
|
|
@ -141,8 +141,6 @@ namespace MatterHackers.MatterControl.ActionBar
|
|||
this.goalTempIndicator.Text = $"{targetTemperature:0.#}";
|
||||
}
|
||||
|
||||
protected virtual void SetTargetTemperature(double targetTemp) { }
|
||||
|
||||
public override void OnLoad(EventArgs args)
|
||||
{
|
||||
this.EnableControls();
|
||||
|
|
|
|||
|
|
@ -62,6 +62,8 @@ namespace MatterHackers.MatterControl.ActionBar
|
|||
|
||||
// Register listeners
|
||||
printer.Connection.BedTemperatureRead += Connection_BedTemperatureRead;
|
||||
printer.Connection.BedTargetTemperatureChanged += this.Connection_BedTargetTemperatureChanged;
|
||||
|
||||
}
|
||||
|
||||
protected override int ActualTemperature => (int)printer.Connection.ActualBedTemperature;
|
||||
|
|
@ -96,15 +98,7 @@ namespace MatterHackers.MatterControl.ActionBar
|
|||
ToggleAction = (itemChecked) =>
|
||||
{
|
||||
var goalTemp = itemChecked ? printer.Settings.GetValue<double>(SettingsKey.bed_temperature) : 0;
|
||||
|
||||
if (itemChecked)
|
||||
{
|
||||
SetTargetTemperature(goalTemp);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetTargetTemperature(0);
|
||||
}
|
||||
printer.Connection.TargetBedTemperature = goalTemp;
|
||||
}
|
||||
},
|
||||
enforceGutter: false));
|
||||
|
|
@ -167,13 +161,6 @@ namespace MatterHackers.MatterControl.ActionBar
|
|||
var temp = printer.Settings.GetValue<double>(SettingsKey.bed_temperature);
|
||||
graph.GoalValue = temp;
|
||||
|
||||
// TODO: Why is this only when enabled? How does it get set to
|
||||
if (heatToggle.Checked)
|
||||
{
|
||||
// TODO: Why is a UI widget who is listening to model events driving this behavior? What when it's not loaded?
|
||||
SetTargetTemperature(temp);
|
||||
}
|
||||
|
||||
settingsRow.UpdateStyle();
|
||||
}
|
||||
}
|
||||
|
|
@ -187,44 +174,25 @@ namespace MatterHackers.MatterControl.ActionBar
|
|||
return widget;
|
||||
}
|
||||
|
||||
public override void OnDraw(Graphics2D graphics2D)
|
||||
{
|
||||
if (heatToggle != null)
|
||||
{
|
||||
heatToggle.Checked = printer.Connection.TargetBedTemperature != 0;
|
||||
}
|
||||
|
||||
base.OnDraw(graphics2D);
|
||||
}
|
||||
|
||||
public override void OnClosed(EventArgs e)
|
||||
{
|
||||
// Unregister listeners
|
||||
printer.Connection.BedTemperatureRead -= Connection_BedTemperatureRead;
|
||||
printer.Connection.BedTargetTemperatureChanged -= this.Connection_BedTargetTemperatureChanged;
|
||||
|
||||
UiThread.ClearInterval(runningInterval);
|
||||
|
||||
base.OnClosed(e);
|
||||
}
|
||||
|
||||
protected override void SetTargetTemperature(double targetTemp)
|
||||
{
|
||||
double goalTemp = (int)(targetTemp + .5);
|
||||
if (printer.Connection.Printing
|
||||
&& printer.Connection.DetailedPrintingState == DetailedPrintingState.HeatingBed
|
||||
&& goalTemp != printer.Connection.TargetBedTemperature)
|
||||
{
|
||||
string message = string.Format(waitingForBedToHeatMessage, printer.Connection.TargetBedTemperature, sliceSettingsNote);
|
||||
StyledMessageBox.ShowMessageBox(message, waitingForBedToHeatTitle);
|
||||
}
|
||||
else
|
||||
{
|
||||
printer.Connection.TargetBedTemperature = (int)(targetTemp + .5);
|
||||
}
|
||||
}
|
||||
|
||||
private void Connection_BedTemperatureRead(object s, EventArgs e)
|
||||
{
|
||||
DisplayCurrentTemperature();
|
||||
}
|
||||
|
||||
private void Connection_BedTargetTemperatureChanged(object sender, EventArgs e)
|
||||
{
|
||||
heatToggle.Checked = printer.Connection.TargetBedTemperature != 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -207,6 +207,7 @@ namespace MatterHackers.MatterControl.ActionBar
|
|||
|
||||
// Register listeners
|
||||
printer.Connection.HotendTemperatureRead += Connection_HotendTemperatureRead;
|
||||
printer.Connection.HotendTargetTemperatureChanged += this.Connection_HotendTargetTemperatureChanged;
|
||||
}
|
||||
|
||||
protected override int ActualTemperature => (int)printer.Connection.GetActualHotendTemperature(this.hotendIndex);
|
||||
|
|
@ -241,13 +242,13 @@ namespace MatterHackers.MatterControl.ActionBar
|
|||
menuTheme,
|
||||
new SettingsItem.ToggleSwitchConfig()
|
||||
{
|
||||
Checked = false,
|
||||
Checked = printer.Connection.GetTargetHotendTemperature(hotendIndex) > 0,
|
||||
ToggleAction = (itemChecked) =>
|
||||
{
|
||||
if (itemChecked)
|
||||
{
|
||||
// Set to goal temp
|
||||
SetTargetTemperature(printer.Settings.Helpers.ExtruderTargetTemperature(hotendIndex));
|
||||
printer.Connection.SetTargetHotendTemperature(hotendIndex, printer.Settings.Helpers.ExtruderTargetTemperature(hotendIndex));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -296,6 +297,14 @@ namespace MatterHackers.MatterControl.ActionBar
|
|||
var valueField = temperatureRow.Descendants<MHNumberEdit>().FirstOrDefault();
|
||||
valueField.Name = "Temperature Input";
|
||||
|
||||
valueField.ActuallNumberEdit.EditComplete += (s, e) =>
|
||||
{
|
||||
if (printer.Connection.GetTargetHotendTemperature(hotendIndex) > 0)
|
||||
{
|
||||
printer.Settings.SetValue(TemperatureKey, valueField.Value.ToString());
|
||||
}
|
||||
};
|
||||
|
||||
var settingsRow = temperatureRow.DescendantsAndSelf<SliceSettingsRow>().FirstOrDefault();
|
||||
|
||||
void Printer_SettingChanged(object s, StringEventArgs stringEvent)
|
||||
|
|
@ -316,17 +325,7 @@ namespace MatterHackers.MatterControl.ActionBar
|
|||
|
||||
if (stringEvent.Data == this.TemperatureKey)
|
||||
{
|
||||
var temp = printer.Settings.Helpers.ExtruderTargetTemperature(hotendIndex);
|
||||
|
||||
graph.GoalValue = temp;
|
||||
|
||||
// TODO: Why is this only when enabled?
|
||||
if (heatToggle.Checked)
|
||||
{
|
||||
// TODO: Why is a UI widget who is listening to model events driving this behavior? What when it's not loaded?
|
||||
SetTargetTemperature(temp);
|
||||
}
|
||||
|
||||
graph.GoalValue = printer.Settings.Helpers.ExtruderTargetTemperature(hotendIndex);
|
||||
settingsRow.UpdateStyle();
|
||||
}
|
||||
}
|
||||
|
|
@ -433,45 +432,25 @@ namespace MatterHackers.MatterControl.ActionBar
|
|||
return widget;
|
||||
}
|
||||
|
||||
public override void OnDraw(Graphics2D graphics2D)
|
||||
{
|
||||
if (heatToggle != null)
|
||||
{
|
||||
heatToggle.Checked = printer.Connection.GetTargetHotendTemperature(hotendIndex) != 0;
|
||||
}
|
||||
|
||||
base.OnDraw(graphics2D);
|
||||
}
|
||||
|
||||
public override void OnClosed(EventArgs e)
|
||||
{
|
||||
// Unregister listeners
|
||||
printer.Connection.HotendTemperatureRead -= Connection_HotendTemperatureRead;
|
||||
printer.Connection.HotendTargetTemperatureChanged -= this.Connection_HotendTargetTemperatureChanged;
|
||||
|
||||
UiThread.ClearInterval(runningInterval);
|
||||
|
||||
base.OnClosed(e);
|
||||
}
|
||||
|
||||
protected override void SetTargetTemperature(double targetTemp)
|
||||
{
|
||||
double goalTemp = (int)(targetTemp + .5);
|
||||
if (printer.Connection.Printing
|
||||
&& (printer.Connection.DetailedPrintingState == DetailedPrintingState.HeatingT0
|
||||
|| printer.Connection.DetailedPrintingState == DetailedPrintingState.HeatingT1)
|
||||
&& goalTemp != printer.Connection.GetTargetHotendTemperature(hotendIndex))
|
||||
{
|
||||
string message = string.Format(waitingForExtruderToHeatMessage, printer.Connection.GetTargetHotendTemperature(hotendIndex), sliceSettingsNote);
|
||||
StyledMessageBox.ShowMessageBox(message, "Waiting For Extruder To Heat".Localize());
|
||||
}
|
||||
else
|
||||
{
|
||||
printer.Connection.SetTargetHotendTemperature(hotendIndex, (int)(targetTemp + .5));
|
||||
}
|
||||
}
|
||||
|
||||
private void Connection_HotendTemperatureRead(object s, EventArgs e)
|
||||
{
|
||||
DisplayCurrentTemperature();
|
||||
}
|
||||
|
||||
private void Connection_HotendTargetTemperatureChanged(object sender, int extruderIndex)
|
||||
{
|
||||
heatToggle.Checked = printer.Connection.GetTargetHotendTemperature(extruderIndex) != 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -106,11 +106,52 @@ namespace MatterHackers.MatterControl
|
|||
}
|
||||
|
||||
public PrinterConfig(PrinterSettings settings)
|
||||
: this()
|
||||
{
|
||||
// TODO: Documentation should be added here to describe how this differs from EngineMappingMatterSlice and its MappedSettings
|
||||
replaceWithSettingsStrings = new MappedSetting[]
|
||||
{
|
||||
// Have a mapping so that MatterSlice while always use a setting that can be set. (the user cannot set first_layer_bedTemperature in MatterSlice)
|
||||
new AsPercentOfReferenceOrDirect(this, SettingsKey.first_layer_speed, SettingsKey.first_layer_speed, SettingsKey.infill_speed, 60),
|
||||
new AsPercentOfReferenceOrDirect(this, SettingsKey.external_perimeter_speed,"external_perimeter_speed", SettingsKey.perimeter_speed, 60),
|
||||
new AsPercentOfReferenceOrDirect(this, SettingsKey.raft_print_speed, "raft_print_speed", SettingsKey.infill_speed, 60),
|
||||
new MappedSetting(this, SettingsKey.bed_remove_part_temperature,SettingsKey.bed_remove_part_temperature),
|
||||
new MappedSetting(this, SettingsKey.bridge_fan_speed,"bridge_fan_speed"),
|
||||
new MappedSetting(this, SettingsKey.bridge_speed,"bridge_speed"),
|
||||
new MappedSetting(this, SettingsKey.air_gap_speed, "air_gap_speed"),
|
||||
new MappedSetting(this, SettingsKey.extruder_wipe_temperature,"extruder_wipe_temperature"),
|
||||
new MappedSetting(this, SettingsKey.filament_diameter,SettingsKey.filament_diameter),
|
||||
new ReplaceWithSetting(this, SettingsKey.first_layer_bed_temperature, SettingsKey.bed_temperature, SettingsKey.bed_temperature),
|
||||
new MappedSetting(this, SettingsKey.first_layer_temperature, SettingsKey.temperature),
|
||||
new MappedSetting(this, SettingsKey.max_fan_speed,"max_fan_speed"),
|
||||
new MappedSetting(this, SettingsKey.min_fan_speed,"min_fan_speed"),
|
||||
new MappedSetting(this, SettingsKey.retract_length,"retract_length"),
|
||||
new MappedSetting(this, SettingsKey.temperature,SettingsKey.temperature),
|
||||
new MappedSetting(this, SettingsKey.bed_temperature,SettingsKey.bed_temperature),
|
||||
new MappedSetting(this, SettingsKey.temperature1, SettingsKey.temperature1),
|
||||
new MappedSetting(this, SettingsKey.temperature2, SettingsKey.temperature2),
|
||||
new MappedSetting(this, SettingsKey.temperature3, SettingsKey.temperature3),
|
||||
new ScaledSingleNumber(this, SettingsKey.infill_speed, SettingsKey.infill_speed, 60),
|
||||
new ScaledSingleNumber(this, SettingsKey.min_print_speed, "min_print_speed", 60),
|
||||
new ScaledSingleNumber(this, SettingsKey.perimeter_speed,"perimeter_speed", 60),
|
||||
new ScaledSingleNumber(this, SettingsKey.retract_speed,"retract_speed", 60),
|
||||
new ScaledSingleNumber(this, SettingsKey.support_material_speed,"support_material_speed", 60),
|
||||
new ScaledSingleNumber(this, SettingsKey.travel_speed, "travel_speed", 60),
|
||||
new ScaledSingleNumber(this, SettingsKey.load_filament_speed, SettingsKey.load_filament_speed, 60),
|
||||
new MappedSetting(this, SettingsKey.trim_filament_markdown, SettingsKey.trim_filament_markdown),
|
||||
new MappedSetting(this, SettingsKey.insert_filament_markdown2, SettingsKey.insert_filament_markdown2),
|
||||
new MappedSetting(this, SettingsKey.insert_filament_1_markdown, SettingsKey.insert_filament_1_markdown),
|
||||
new MappedSetting(this, SettingsKey.running_clean_markdown2, SettingsKey.running_clean_markdown2),
|
||||
new MappedSetting(this, SettingsKey.running_clean_1_markdown, SettingsKey.running_clean_1_markdown),
|
||||
};
|
||||
|
||||
EngineMappingsMatterSlice = new EngineMappingsMatterSlice(this);
|
||||
|
||||
this.Bed = new BedConfig(ApplicationController.Instance.Library.PlatingHistory, this);
|
||||
this.ViewState = new PrinterViewState();
|
||||
|
||||
this.Settings = settings;
|
||||
this.Connection = new PrinterConnection(this);
|
||||
|
||||
// Register listeners
|
||||
this.Connection.TemporarilyHoldingTemp += ApplicationController.Instance.Connection_TemporarilyHoldingTemp;
|
||||
this.Connection.ErrorReported += ApplicationController.Instance.Connection_ErrorReported;
|
||||
|
|
@ -118,7 +159,6 @@ namespace MatterHackers.MatterControl
|
|||
this.Connection.CommunicationStateChanged += Connection_CommunicationStateChanged;
|
||||
this.Connection.PrintFinished += Connection_PrintFinished;
|
||||
|
||||
this.Settings = settings;
|
||||
this.Settings.SettingChanged += Printer_SettingChanged;
|
||||
|
||||
if (!string.IsNullOrEmpty(this.Settings.GetValue(SettingsKey.baud_rate)))
|
||||
|
|
|
|||
|
|
@ -117,6 +117,9 @@ namespace MatterHackers.MatterControl.PrinterCommunication
|
|||
|
||||
public event EventHandler HotendTemperatureRead;
|
||||
|
||||
public event EventHandler<int> HotendTargetTemperatureChanged;
|
||||
public event EventHandler BedTargetTemperatureChanged;
|
||||
|
||||
public event EventHandler FanSpeedSet;
|
||||
|
||||
public event EventHandler FirmwareVersionRead;
|
||||
|
|
@ -320,6 +323,61 @@ namespace MatterHackers.MatterControl.PrinterCommunication
|
|||
this.OnIdle();
|
||||
Thread.Sleep(10);
|
||||
});
|
||||
|
||||
printer.Settings.SettingChanged += (s, stringEvent) =>
|
||||
{
|
||||
var extruder = -1;
|
||||
switch (stringEvent.Data)
|
||||
{
|
||||
case SettingsKey.temperature:
|
||||
extruder = 0;
|
||||
break;
|
||||
case SettingsKey.temperature1:
|
||||
extruder = 1;
|
||||
break;
|
||||
case SettingsKey.temperature2:
|
||||
extruder = 2;
|
||||
break;
|
||||
case SettingsKey.temperature3:
|
||||
extruder = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
if (extruder > -1)
|
||||
{
|
||||
if (printer.Connection.Printing
|
||||
&& (printer.Connection.DetailedPrintingState == DetailedPrintingState.HeatingT0
|
||||
|| printer.Connection.DetailedPrintingState == DetailedPrintingState.HeatingT1))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
double goalTemp = printer.Connection.GetTargetHotendTemperature(extruder);
|
||||
if (goalTemp > 0)
|
||||
{
|
||||
var newGoal = printer.Settings.GetValue<double>(stringEvent.Data);
|
||||
printer.Connection.SetTargetHotendTemperature(extruder, newGoal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (stringEvent.Data == SettingsKey.bed_temperature)
|
||||
{
|
||||
if (printer.Connection.Printing
|
||||
&& printer.Connection.DetailedPrintingState == DetailedPrintingState.HeatingBed)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
double goalTemp = printer.Connection.TargetBedTemperature;
|
||||
if (goalTemp > 0)
|
||||
{
|
||||
var newGoal = printer.Settings.GetValue<double>(SettingsKey.bed_temperature);
|
||||
printer.Connection.TargetBedTemperature = newGoal;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -781,6 +839,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
|
|||
{
|
||||
QueueLine("M140 S{0}".FormatWith(_targetBedTemperature));
|
||||
}
|
||||
BedTargetTemperatureChanged?.Invoke(this, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -837,6 +896,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
|
|||
{
|
||||
// we set the private variable so that we don't get the callbacks called and get in a loop of setting the temp
|
||||
_targetBedTemperature = tempBeingSet;
|
||||
BedTargetTemperatureChanged?.Invoke(this, null);
|
||||
}
|
||||
}
|
||||
catch
|
||||
|
|
@ -1119,11 +1179,11 @@ You will then need to logout and log back in to the computer for the changes to
|
|||
double tempBeingSet = 0;
|
||||
if (GCodeFile.GetFirstNumberAfter("S", line, ref tempBeingSet))
|
||||
{
|
||||
double exturderIndex = 0;
|
||||
if (GCodeFile.GetFirstNumberAfter("T", line, ref exturderIndex))
|
||||
int extruderIndex = 0;
|
||||
if (GCodeFile.GetFirstNumberAfter("T", line, ref extruderIndex))
|
||||
{
|
||||
// we set the private variable so that we don't get the callbacks called and get in a loop of setting the temp
|
||||
int hotendIndex0Based = Math.Min((int)exturderIndex, MAX_EXTRUDERS - 1);
|
||||
int hotendIndex0Based = Math.Min(extruderIndex, MAX_EXTRUDERS - 1);
|
||||
targetHotendTemperature[hotendIndex0Based] = tempBeingSet;
|
||||
}
|
||||
else
|
||||
|
|
@ -1131,6 +1191,7 @@ You will then need to logout and log back in to the computer for the changes to
|
|||
// we set the private variable so that we don't get the callbacks called and get in a loop of setting the temp
|
||||
targetHotendTemperature[ActiveExtruderIndex] = tempBeingSet;
|
||||
}
|
||||
HotendTargetTemperatureChanged?.Invoke(this, extruderIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1875,6 +1936,7 @@ You will then need to logout and log back in to the computer for the changes to
|
|||
{
|
||||
QueueLine("M104 T{0} S{1}".FormatWith(hotendIndex0Based, targetHotendTemperature[hotendIndex0Based]));
|
||||
}
|
||||
HotendTargetTemperatureChanged?.Invoke(this, hotendIndex0Based);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -253,6 +253,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
|||
|
||||
// click the remove override and have it change to default temp
|
||||
testRunner.ClickByName("Restore temperature");
|
||||
testRunner.WaitFor(() => hipsGoalTemp == emulator.CurrentExtruder.TargetTemperature);
|
||||
Assert.AreEqual(hipsGoalTemp, (int)emulator.CurrentExtruder.TargetTemperature, "The printer should report the expected goal temp");
|
||||
|
||||
// type in 60 and have the heater turn on
|
||||
|
|
@ -282,7 +283,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
|||
testRunner.Type("{Enter}");
|
||||
testRunner.Delay();
|
||||
testRunner.ClickByName("Load Filament Button");
|
||||
testRunner.ClickByName("Next Button");
|
||||
testRunner.ClickByName("Load Filament");
|
||||
Assert.AreEqual(104, (int)emulator.CurrentExtruder.TargetTemperature);
|
||||
testRunner.Delay();
|
||||
testRunner.ClickByName("Cancel Wizard Button");
|
||||
|
|
@ -291,7 +292,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
|||
|
||||
testRunner.ClickByName("Hotend 0");
|
||||
testRunner.ClickByName("Load Filament Button");
|
||||
testRunner.ClickByName("Next Button");
|
||||
testRunner.ClickByName("Load Filament");
|
||||
testRunner.Delay();
|
||||
Assert.AreEqual(104, (int)emulator.CurrentExtruder.TargetTemperature);
|
||||
var systemWindow = testRunner.GetWidgetByName("Cancel Wizard Button", out SystemWindow containingWindow);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue