Skip to content

Commit

Permalink
rearranged and deleted some unnecessary components
Browse files Browse the repository at this point in the history
  • Loading branch information
milemihailov committed Mar 21, 2024
1 parent 3aa3bc4 commit 93c67e5
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 363 deletions.
5 changes: 0 additions & 5 deletions MachineControlHub/PrinterConnection/SerialConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public string PortName
catch (Exception ex)
{
Logger.LogError($"An error occurred while setting the PortName: {ex.Message}");
Logger.LogError(ex.StackTrace);
}
}
}
Expand All @@ -79,7 +78,6 @@ public int BaudRate
catch (Exception ex)
{
Logger.LogError($"An error occurred while setting the BaudRate: {ex.Message}");
Logger.LogError(ex.StackTrace);
}
}
}
Expand Down Expand Up @@ -120,7 +118,6 @@ public void Disconnect()
catch (Exception ex)
{
Logger.LogError($"Error closing serial port: {ex.Message}");
Logger.LogError(ex.StackTrace);
}

}
Expand All @@ -141,7 +138,6 @@ public void Write(string data)
catch (Exception ex)
{
Logger.LogError($"Error writing to serial port: {ex.Message}");
Logger.LogError(ex.StackTrace);
}
}

Expand All @@ -162,7 +158,6 @@ public string Read()
catch (Exception ex)
{
Logger.LogError($"Error reading from serial port: {ex.Message}");
Logger.LogError(ex.StackTrace);
return null;
}
}
Expand Down
36 changes: 36 additions & 0 deletions WebUIBlazor/Data/BedLevelingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using MachineControlHub.Motion;
using Microsoft.AspNetCore.Components;
using Plotly.Blazor;
using Plotly.Blazor.Traces;
using System.Globalization;
using WebUI.Pages;
using static MudBlazor.CategoryTypes;
Expand All @@ -13,6 +14,9 @@ public class BedLevelingService
public static BedLevelData bedData;
public string CSVData;
public Task<IList<ITrace>> meshData;
public bool _isInitialized { get; set; }



public BedLevelingService()
{
Expand All @@ -26,5 +30,37 @@ public void CalibrateBed()
string input = ConnectionServiceSerial.printerConnection.Read();
CSVData = bedData.GetGrid(input);
}

public async Task<IList<ITrace>> GetSurfaceData()
{
IList<ITrace> mapData = new List<ITrace>();

var csv = await Task.Run(() => CSVData
.Split("\n")
.Skip(1)
.Where(s => !string.IsNullOrWhiteSpace(s))
.Select(s => s.Split(",").ToList()).ToList());

var z = new List<decimal[]>();

foreach (var row in csv)
{
var currentValues = new List<decimal>();

for (var i = 1; i < row.Count; i++)
{
currentValues.Add(decimal.Parse(row[i], NumberStyles.Any, CultureInfo.InvariantCulture));
}

z.Add(currentValues.ToArray());
}

mapData.Add(new Surface
{
Z = z.Cast<object>().ToList()
});

return mapData;
}
}
}
10 changes: 5 additions & 5 deletions WebUIBlazor/Data/ControlPanelService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void AdjustAxis(MovePositions position, bool increment, ConnectionService
public void DisableSteppers()
{
// Send the command to disable the steppers to the printer
Data.ConnectionServiceSerial.printerConnection.Write(CommandMethods.BuildDisableSteppersCommand());
ConnectionServiceSerial.printerConnection.Write(CommandMethods.BuildDisableSteppersCommand());
}


Expand All @@ -86,7 +86,7 @@ public void DisableSteppers()
public void HomeAxisCommand(bool x = false, bool y = false, bool z = false)
{
// Send the command to turn off the fan to the printer
Data.ConnectionServiceSerial.printerConnection.Write(CommandMethods.BuildHomeAxesCommand(x, y, z));
ConnectionServiceSerial.printerConnection.Write(CommandMethods.BuildHomeAxesCommand(x, y, z));
}


Expand All @@ -111,7 +111,7 @@ public void SendGcodeViaTerminal(string command, ConnectionServiceSerial serial)
public void SetFanOff()
{
// Send the fan speed command to the printer
Data.ConnectionServiceSerial.printerConnection.Write(CommandMethods.BuildFanOffCommand());
ConnectionServiceSerial.printerConnection.Write(CommandMethods.BuildFanOffCommand());
}


Expand All @@ -122,7 +122,7 @@ public void SetFanOff()
public void SetFanSpeed(int value)
{
// Send the fan speed command to the printer
Data.ConnectionServiceSerial.printerConnection.Write(CommandMethods.BuildFanSpeedCommand(value));
ConnectionServiceSerial.printerConnection.Write(CommandMethods.BuildFanSpeedCommand(value));
}


Expand Down Expand Up @@ -154,11 +154,11 @@ public void UpdateParagraph(ConnectionServiceSerial serial)

public void ToggleValue()
{
SwitchValue = !SwitchValue;
if (SwitchValue)
fanSpeed = 255;
else
fanSpeed = 0;
SwitchValue = !SwitchValue;
}
}
}
104 changes: 55 additions & 49 deletions WebUIBlazor/Data/PrintingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Text.RegularExpressions;
using MudBlazor;
using WebUI.Pages;
using Microsoft.AspNetCore.Components;
using System;

namespace WebUI.Data
{
Expand All @@ -14,6 +16,8 @@ public class PrintingService
public PrintService printService;
public PrintJobHistory printJob;
public PrintProgress printProgress;
private readonly IDialogService _dialogService;
private readonly ISnackbar _snackbar;

public string printName;
public string estimatedTime;
Expand All @@ -25,18 +29,22 @@ public class PrintingService
public string fileToPrint = "";
public bool _processing = false;

public int hours;
public int minutes;
public int seconds;
public static List<double> hotendGraph = new List<double> { };
public static List<double> bedGraph = new List<double> { };
public ChartOptions Options = new ChartOptions();
public string[] XAxisLabels = { };
public int Index = -1;




public PrintingService()
public PrintingService(IDialogService dialogService, ISnackbar snackbar)
{
printService = new PrintService(ConnectionServiceSerial.printerConnection);
printJob = new PrintJobHistory(ConnectionServiceSerial.printerConnection);
printProgress = new PrintProgress();
_dialogService = dialogService;
_snackbar = snackbar;
_snackbar.Configuration.PositionClass = Defaults.Classes.Position.BottomLeft;
}

public void StartPrint(string fileName)
Expand All @@ -47,17 +55,24 @@ public void StartPrint(string fileName)
public void PausePrint()
{
ConnectionServiceSerial.printerConnection.Write(CommandMethods.BuildPauseSDPrintCommand());
_snackbar.Add("Print Paused", Severity.Info);
}

public void ResumePrint()
{
ConnectionServiceSerial.printerConnection.Write(CommandMethods.BuildStartSDPrintCommand());
_snackbar.Add($"<ul><li>Waiting for temperature</li><li>Print Resuming</li></ul>", Severity.Info);
}

public void StopPrint()
{
printService.AbortCurrentPrint();
_snackbar.Add("Print Stopped", Severity.Error);
}

public void ListSDFiles()
{
files = printService.ListSDFiles();

}

public void StartTimeOfPrint()
Expand Down Expand Up @@ -91,53 +106,44 @@ public void EstimatedPrintTime()
estimatedTime = match.Groups[1].Value;
}



public void Confirm(IDialogService dialogService)
public async Task ConfirmStartAsync()
{
var parameters = new DialogParameters<Dialog>
bool? result = await _dialogService.ShowMessageBox(
"Start Print",
"Do you want to start a print job?",
yesText: "Start!", cancelText: "Cancel");

if (result == true)
{
{ x => x.ContentText, "Start Print ?" },
{ x => x.ButtonText, "Yes" },
{ x => x.Color, Color.Success }
};
if (fileToPrint == "")
{
_snackbar.Add("No file selected", Severity.Error);
}
else
{
StartPrint(fileToPrint);
StartTimeOfPrint();
GetFileNameAndSize(fileToPrint);
_snackbar.Add($"<ul><li>Print Started</li> <li> File Printing: {fileToPrint} </li></ul>", Severity.Success);
}
}
}

IDialogReference dialogReference = dialogService.Show<Dialog>("Confirm", parameters);
public List<ChartSeries> Series = new List<ChartSeries>()
{
new ChartSeries() { Name = "Hotend", Data = hotendGraph.ToArray() },
new ChartSeries() { Name = "Bed", Data = bedGraph.ToArray() },
};

StartPrint(fileToPrint);
StartTimeOfPrint();
GetFileNameAndSize(fileToPrint);
}
public void UpdateGraphData()
{
var new_series = new List<ChartSeries>()
{
new ChartSeries() { Name = "Hotend", Data = hotendGraph.ToArray() },
new ChartSeries() { Name = "Bed", Data = bedGraph.ToArray() },
};
Series = new_series;

// private void StartClock()
// {
// hours = 0;
// minutes = 0;
// seconds = 0;

// timer = new System.Timers.Timer(1000);
// timer.Elapsed += (sender, e) => UpdateClock();
// timer.AutoReset = true;
// timer.Enabled = true;
// }

//private void UpdateClock()
//{
// seconds++;
// if (seconds == 60)
// {
// seconds = 0;
// minutes++;
// if (minutes == 2)
// {
// EstimatedPrintTime();
// }
// if (minutes == 60)
// {
// minutes = 0;
// hours++;
// }
// }
//}
}
}
}
Loading

0 comments on commit 93c67e5

Please sign in to comment.