diff --git a/CNC Controls Probing/CNC Controls Probing/HeightMapControl.xaml b/CNC Controls Probing/CNC Controls Probing/HeightMapControl.xaml index d658e3b..d5a68c2 100644 --- a/CNC Controls Probing/CNC Controls Probing/HeightMapControl.xaml +++ b/CNC Controls Probing/CNC Controls Probing/HeightMapControl.xaml @@ -13,6 +13,7 @@ A rapid motion to X0Y0 will be performed before probing the height map starts.\nEnsure the initial Z-position is clear of any obstacles that might be encountered during probing. Probing failed Probing completed: Z min: {0}, Z max: {1}. + Probing point {0} of {1}... diff --git a/CNC Controls Probing/CNC Controls Probing/HeightMapControl.xaml.cs b/CNC Controls Probing/CNC Controls Probing/HeightMapControl.xaml.cs index c5bb828..001865b 100644 --- a/CNC Controls Probing/CNC Controls Probing/HeightMapControl.xaml.cs +++ b/CNC Controls Probing/CNC Controls Probing/HeightMapControl.xaml.cs @@ -1,7 +1,7 @@ /* * HeightMapControl.xaml.cs - part of CNC Probing library * - * v0.42 / 2023-03-22 / Io Engineering (Terje Io) + * v0.44 / 2023-10-01 / Io Engineering (Terje Io) * */ @@ -110,10 +110,15 @@ public void Start(bool preview = false) probing.HeightMap.GridSizeX = probing.HeightMap.Map.GridX; probing.HeightMap.GridSizeY = probing.HeightMap.Map.GridY; + int point = 0, points = probing.HeightMap.Map.SizeX * probing.HeightMap.Map.SizeX; + string pointOf = ((string)FindResource("ProbingPointOf")); + for (x = 0; x < probing.HeightMap.Map.SizeX; x++) { for (y = 0; y < probing.HeightMap.Map.SizeY; y++) { + probing.Program.AddMessage(string.Format(pointOf, ++point, points)); + if (probing.HeightMap.AddPause && (x > 0 || y > 0)) probing.Program.AddPause(); probing.Program.AddProbingAction(AxisFlags.Z, true); @@ -184,7 +189,7 @@ private void OnCompleted() // double z = probing.HeightMap.Map.InterpolateZ(0d, 0d); if (probing.HeightMap.SetToolOffset && - (ok = (probing.Positions[0].X == origin.X && probing.Positions[0].Y == origin.Y) || probing.Program.ProbeZ(0d, 0d))) + (ok = /* (probing.Positions[0].X == origin.X && probing.Positions[0].Y == origin.Y) || */ probing.Program.ProbeZ(0d, 0d))) { probing.HeightMap.Map.ZOffset = Z0 - probing.Positions[0].Z; // vs Z above, add check for allowed delta? diff --git a/CNC Controls Probing/CNC Controls Probing/LibStrings.xaml b/CNC Controls Probing/CNC Controls Probing/LibStrings.xaml index d9f1926..cf8be12 100644 --- a/CNC Controls Probing/CNC Controls Probing/LibStrings.xaml +++ b/CNC Controls Probing/CNC Controls Probing/LibStrings.xaml @@ -17,4 +17,5 @@ Illegal probe position, try again. Probe connection was not verified, continue anyway? Press [Start] again to start probing. + Probing @X0Y0... \ No newline at end of file diff --git a/CNC Controls Probing/CNC Controls Probing/ProbingView.xaml.cs b/CNC Controls Probing/CNC Controls Probing/ProbingView.xaml.cs index 8093195..3f21248 100644 --- a/CNC Controls Probing/CNC Controls Probing/ProbingView.xaml.cs +++ b/CNC Controls Probing/CNC Controls Probing/ProbingView.xaml.cs @@ -1,7 +1,7 @@ /* * ProbingView.xaml.cs - part of CNC Probing library * - * v0.43 / 2023-07-25 / Io Engineering (Terje Io) + * v0.44 / 2023-08-26 / Io Engineering (Terje Io) * */ @@ -324,18 +324,18 @@ public void Setup(UIViewModel model, AppConfig profile) private void mnu_Click(object sender, RoutedEventArgs e) { - switch ((string)((MenuItem)sender).Header) + switch ((string)((MenuItem)sender).Name) { - case "Add": + case "mnuAdd": cbxProfile.SelectedValue = profiles.Add(cbxProfile.Text, model); break; - case "Update": + case "mnuUpdate": if(model.Profile != null) profiles.Update(model.Profile.Id, cbxProfile.Text, model); break; - case "Delete": + case "mnuDelete": if (model.Profile != null && profiles.Delete(model.Profile.Id)) cbxProfile.SelectedValue = profiles.Profiles[0].Id; break; diff --git a/CNC Controls Probing/CNC Controls Probing/ProbingViewModel.cs b/CNC Controls Probing/CNC Controls Probing/ProbingViewModel.cs index 736dbc0..1b47d7b 100644 --- a/CNC Controls Probing/CNC Controls Probing/ProbingViewModel.cs +++ b/CNC Controls Probing/CNC Controls Probing/ProbingViewModel.cs @@ -1,7 +1,7 @@ /* * ProbingViewModel.cs - part of CNC Probing library * - * v0.43 / 2023-06-30 / Io Engineering (Terje Io) + * v0.44 / 2023-10-01 / Io Engineering (Terje Io) * */ @@ -171,9 +171,6 @@ public bool WaitForResponse(string command) { bool? res = null; - if (Grbl.ResponseLogVerbose) - Grbl.ResponseLog.Add(command); - var t = new Thread(() => { res = WaitFor.AckResponse( diff --git a/CNC Controls Probing/CNC Controls Probing/Program.cs b/CNC Controls Probing/CNC Controls Probing/Program.cs index f1ea971..ef25805 100644 --- a/CNC Controls Probing/CNC Controls Probing/Program.cs +++ b/CNC Controls Probing/CNC Controls Probing/Program.cs @@ -1,7 +1,7 @@ /* * Program.cs - part of CNC Probing library * - * v0.42 / 2023-03-22 / Io Engineering (Terje Io) + * v0.44 / 2023-10-01 / Io Engineering (Terje Io) * */ @@ -308,6 +308,11 @@ public void AddProbingAction(AxisFlags axis, bool negative) } } + public void AddMessage(string msg) + { + _program.Add("#" + msg); + } + public void AddSimulatedProbe(int p) { probing.IsSuccess = true; @@ -415,8 +420,7 @@ public bool Execute(bool go) if (response == "ok") { - step++; - if (step < _program.Count) + if (++step < _program.Count) { int i; //if ((i = _program[step].IndexOf('$')) > 0) @@ -426,6 +430,13 @@ public bool Execute(bool go) // double val = _positions[_positions.Count - 1].Values[i] + dbl.Parse(_program[step].Substring(i, 3)); // _program[step] = _program[step] + val.ToInvariantString(); //} + if (_program[step].StartsWith("#")) + { + Grbl.Message = _program[step].Substring(1); + if (++step == _program.Count) + break; + } + if (_program[step].StartsWith("!")) { isProbing = false; @@ -475,6 +486,7 @@ public bool ProbeZ(double x, double y) return false; probing.Program.AddRapid(string.Format("G90X{0}Y{0}", x.ToInvariantString(probing.Grbl.Format), y.ToInvariantString(probing.Grbl.Format))); + probing.Program.AddMessage(LibStrings.FindResource("ProbingAtX0Y0")); probing.Program.Add(string.Format("G91F{0}", probing.ProbeFeedRate.ToInvariantString())); probing.Program.AddProbingAction(AxisFlags.Z, true); diff --git a/CNC Controls/CNC Controls/AppConfig.cs b/CNC Controls/CNC Controls/AppConfig.cs index 1ec067b..063bd64 100644 --- a/CNC Controls/CNC Controls/AppConfig.cs +++ b/CNC Controls/CNC Controls/AppConfig.cs @@ -711,7 +711,7 @@ public RestartResult Restart () { if (MessageBox.Show(LibStrings.FindResource("MsgEStopExit"), "ioSender", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) return RestartResult.Close; - }; + } } else AttemptReset(); @@ -725,6 +725,17 @@ public RestartResult Restart () else Message = LibStrings.FindResource("MsgHome"); break; + + case 17: // Motor fault + if (!(GrblInfo.IsGrblHAL && model.Signals.Value.HasFlag(Signals.MotorFault))) + { + AttemptReset(); + if (!GrblInfo.IsLoaded) + model.ExecuteCommand(GrblConstants.CMD_UNLOCK); + } + break; + + } break; diff --git a/CNC Controls/CNC Controls/GCodeListControl.xaml b/CNC Controls/CNC Controls/GCodeListControl.xaml index 6528ee7..2d16b7d 100644 --- a/CNC Controls/CNC Controls/GCodeListControl.xaml +++ b/CNC Controls/CNC Controls/GCodeListControl.xaml @@ -8,11 +8,19 @@ d:DesignHeight="335" d:DesignWidth="400" Loaded="UserControl_Loaded"> + CanUserSortColumns="false" CanUserResizeRows="False" IsReadOnly="true" SelectionChanged="grdGCode_SelectionChanged" + DragEnter="grdGCode_Drag" DragOver="grdGCode_Drag" DragLeave="grdGCode_Drag" Drop="grdGCode_Drop"> + + + + + + + diff --git a/CNC Controls/CNC Controls/GCodeListControl.xaml.cs b/CNC Controls/CNC Controls/GCodeListControl.xaml.cs index e879fbf..af88e4b 100644 --- a/CNC Controls/CNC Controls/GCodeListControl.xaml.cs +++ b/CNC Controls/CNC Controls/GCodeListControl.xaml.cs @@ -1,18 +1,47 @@ -using CNC.Core; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +/* + * GcodeListControl.xaml.cs - part of CNC Controls library for Grbl + * + * v0.44 / 2023-10-07 / Io Engineering (Terje Io) + * + */ + +/* + +Copyright (c) 2020-2023, Io Engineering (Terje Io) +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +· Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + +· Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +· Neither the name of the copyright holder nor the names of its contributors may +be used to endorse or promote products derived from this software without +specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +using System.Data; using System.Windows; using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; +using System.Collections.Generic; +using CNC.Core; namespace CNC.Controls { @@ -22,12 +51,31 @@ namespace CNC.Controls public partial class GCodeListControl : UserControl { public ScrollViewer scroll = null; - + public GCodeListControl() { InitializeComponent(); + ctxMenu.DataContext = this; } + + #region Dependency properties + + public static readonly DependencyProperty SingleSelectedProperty = DependencyProperty.Register(nameof(SingleSelected), typeof(bool), typeof(GCodeListControl), new PropertyMetadata(false)); + public bool SingleSelected + { + get { return (bool)GetValue(SingleSelectedProperty); } + private set { SetValue(SingleSelectedProperty, value); } + } + + public static readonly DependencyProperty MultipleSelectedProperty = DependencyProperty.Register(nameof(MultipleSelected), typeof(bool), typeof(GCodeListControl), new PropertyMetadata(false)); + public bool MultipleSelected + { + get { return (bool)GetValue(MultipleSelectedProperty); } + private set { SetValue(MultipleSelectedProperty, value); } + } + #endregion + private void grdGCode_Drag(object sender, DragEventArgs e) { GCode.File.Drag(sender, e); @@ -59,5 +107,58 @@ private void GCodeListControl_PropertyChanged(object sender, System.ComponentMod break; } } + + void grdGCode_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + SingleSelected = grdGCode.SelectedItems.Count == 1 && (DataContext as GrblViewModel).StartFromBlock.CanExecute(grdGCode.SelectedIndex); + MultipleSelected = grdGCode.SelectedItems.Count >= 0 && (DataContext as GrblViewModel).StartFromBlock.CanExecute(grdGCode.SelectedIndex); + } + + private void StartHere_Click(object sender, RoutedEventArgs e) + { + if (grdGCode.SelectedItems.Count == 1 && + MessageBox.Show(string.Format(LibStrings.FindResource("VerifyStartFrom"), ((DataRowView)(grdGCode.SelectedItems[0])).Row["LineNum"]), + "ioSender", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes) + { + (DataContext as GrblViewModel).StartFromBlock.Execute(grdGCode.SelectedIndex); + } + } + + private void CopyMDI_Click(object sender, RoutedEventArgs e) + { + if (grdGCode.SelectedItems.Count == 1) + (DataContext as GrblViewModel).MDIText = (string)((DataRowView)(grdGCode.SelectedItems[0])).Row["Data"]; + } + + private void SendController_Click(object sender, RoutedEventArgs e) + { + if (grdGCode.SelectedItems.Count >= 1 && + MessageBox.Show(LibStrings.FindResource("VerifySendController"), "ioSender", + MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes) + { + var model = DataContext as GrblViewModel; + + if (model.GrblError != 0) + model.ExecuteCommand(""); + + List rows = new List(); + + for (int i = 0; i < grdGCode.SelectedItems.Count; i++) + rows.Add(((DataRowView)(grdGCode.SelectedItems[i])).Row); + + rows.Sort(new RowComparer()); + + foreach (DataRow row in rows) + model.ExecuteCommand((string)row["Data"]); + } + } + } + + internal class RowComparer : IComparer + { + public int Compare(DataRow a, DataRow b) + { + return (int)a["LineNum"] - (int)b["LineNum"]; + } } } diff --git a/CNC Controls/CNC Controls/GrblConfigView.xaml b/CNC Controls/CNC Controls/GrblConfigView.xaml index fe94054..5f500d6 100644 --- a/CNC Controls/CNC Controls/GrblConfigView.xaml +++ b/CNC Controls/CNC Controls/GrblConfigView.xaml @@ -17,6 +17,8 @@ Bummer...\nContinue loading? The file does not contain any settings. Restore settings from file + + +