Skip to content

Commit

Permalink
Release 2.0.36
Browse files Browse the repository at this point in the history
  • Loading branch information
terjeio committed Jan 27, 2022
1 parent 42149d3 commit fe01ffa
Show file tree
Hide file tree
Showing 70 changed files with 838 additions and 971 deletions.
27 changes: 20 additions & 7 deletions CNC Controls Probing/CNC Controls Probing/GCodeTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using RP.Math;
using System;
using System.Collections.Generic;
using System.Linq;

namespace CNC.Controls.Probing
{
Expand Down Expand Up @@ -56,9 +57,10 @@ public void ApplyHeightMap(ProbingViewModel model)
{
var motion = token as GCLinearMotion;

var m = new Line();
var m = new Line(motion.AxisFlags);
m.Start = pos;
m.End = pos = ToAbsolute(pos, motion.Values, distanceMode == DistanceMode.Incremental);
m.Rapid = token.Command == Commands.G0;

foreach (Motion subMotion in m.Split(segmentLength))
{
Expand Down Expand Up @@ -188,11 +190,22 @@ public Vector3 Delta
}
class Line : Motion
{
public bool Rapid;
public bool Rapid = false;
// PositionValid[i] is true if the corresponding coordinate of the end position was defined in the file.
// eg. for a file with "G0 Z15" as the first line, X and Y would still be false
public bool[] PositionValid = new bool[] { false, false, false };

public Line()
{
}

public Line(AxisFlags axisFlags)
{
PositionValid[0] = axisFlags.HasFlag(AxisFlags.X);
PositionValid[1] = axisFlags.HasFlag(AxisFlags.Y);
PositionValid[2] = axisFlags.HasFlag(AxisFlags.Z);
}

public override double Length
{
get
Expand All @@ -208,11 +221,11 @@ public override Vector3 Interpolate(double ratio)

public override IEnumerable<Motion> Split(double length)
{
//if (Rapid || PositionValid.Any(isValid => !isValid)) //don't split up rapid or not fully defined motions
//{
// yield return this;
// yield break;
//}
if (Rapid /* || PositionValid.Any(isValid => !isValid)*/) //don't split up rapid or not fully defined motions
{
yield return this;
yield break;
}

int divisions = (int)Math.Ceiling(Length / length);

Expand Down
1 change: 1 addition & 0 deletions CNC Controls Probing/CNC Controls Probing/HeightMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Changes by Terje Io for GCode Sender
2020-09-20 : Added constructor for separate X and Y grid sizes
2022-01-23 : Added check for rapid motions and motion validity
*/

Expand Down
7 changes: 4 additions & 3 deletions CNC Controls Probing/CNC Controls Probing/Program.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* Program.cs - part of CNC Probing library
*
* v0.36 / 2021-11-29 / Io Engineering (Terje Io)
* v0.36 / 2022-01-09 / Io Engineering (Terje Io)
*
*/

/*
Copyright (c) 2020, Io Engineering (Terje Io)
Copyright (c) 2020-2022, Io Engineering (Terje Io)
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -466,7 +466,8 @@ public bool Execute(bool go)

private void ResponseReceived(string response)
{
cmd_response = response;
if(cmd_response != "cancel")
cmd_response = response;
}

public override string ToString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Io Engineering")]
[assembly: AssemblyProduct("ioSender")]
[assembly: AssemblyCopyright("Copyright © 2021 Io Engineering")]
[assembly: AssemblyCopyright("Copyright © 2022 Io Engineering")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
Expand Down
217 changes: 215 additions & 2 deletions CNC Controls/CNC Controls/AppConfig.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* AppConfig.cs - part of CNC Controls library
*
* v0.36 / 2021-12-25 / Io Engineering (Terje Io)
* v0.36 / 2022-01-23 / Io Engineering (Terje Io)
*
*/

/*
Copyright (c) 2019-2021, Io Engineering (Terje Io)
Copyright (c) 2019-2022, Io Engineering (Terje Io)
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -544,4 +544,217 @@ private string GetArg(string[] args, int i)
return i < args.GetLength(0) ? args[i] : null;
}
}

public class Controller
{
GrblViewModel model;

public enum RestartResult
{
Ok = 0,
NoResponse,
Close,
Exit
}

public Controller (GrblViewModel model)
{
this.model = model;
}

public bool ResetPending { get; private set; } = false;
public string Message { get; private set; }

public RestartResult Restart ()
{
Message = model.Message;
model.Message = string.Format(LibStrings.FindResource("MsgWaiting"), AppConfig.Settings.Base.PortParams);

string response = GrblInfo.Startup(model);

if (response.StartsWith("<"))
{
if (model.GrblState.State != GrblStates.Unknown)
{

switch (model.GrblState.State)
{
case GrblStates.Alarm:

model.Poller.SetState(AppConfig.Settings.Base.PollInterval);

switch (model.GrblState.Substate)
{
case 1: // Hard limits
if (!GrblInfo.IsLoaded)
{
if (model.LimitTriggered)
{
MessageBox.Show(string.Format(LibStrings.FindResource("MsgNoCommAlarm"), model.GrblState.Substate.ToString()), "ioSender");
if (AttemptReset())
model.ExecuteCommand(GrblConstants.CMD_UNLOCK);
else
{
MessageBox.Show(LibStrings.FindResource("MsgResetFailed"), "ioSender");
return RestartResult.Close;
}
}
else if (AttemptReset())
model.ExecuteCommand(GrblConstants.CMD_UNLOCK);
}
else
response = string.Empty;
break;

case 2: // Soft limits
if (!GrblInfo.IsLoaded)
{
MessageBox.Show(string.Format(LibStrings.FindResource("MsgNoCommAlarm"), model.GrblState.Substate.ToString()), "ioSender");
if (AttemptReset())
model.ExecuteCommand(GrblConstants.CMD_UNLOCK);
else
{
MessageBox.Show(LibStrings.FindResource("MsgResetFailed"), "ioSender");
return RestartResult.Close;
}
}
else
response = string.Empty;
break;

case 10: // EStop
if (GrblInfo.IsGrblHAL && model.Signals.Value.HasFlag(Signals.EStop))
{
MessageBox.Show(LibStrings.FindResource("MsgEStop"), "ioSender", MessageBoxButton.OK, MessageBoxImage.Warning);
while (!AttemptReset() && model.GrblState.State == GrblStates.Alarm)
{
if (MessageBox.Show(LibStrings.FindResource("MsgEStopExit"), "ioSender", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
return RestartResult.Close;
};
}
else
AttemptReset();
if (!GrblInfo.IsLoaded)
model.ExecuteCommand(GrblConstants.CMD_UNLOCK);
break;

case 11: // Homing required
if (GrblInfo.IsLoaded)
response = string.Empty;
else
Message = LibStrings.FindResource("MsgHome");
break;
}
break;

case GrblStates.Tool:
Comms.com.WriteByte(GrblConstants.CMD_STOP);
break;

case GrblStates.Door:
if (!GrblInfo.IsLoaded)
{
if (MessageBox.Show(LibStrings.FindResource("MsgDoorOpen"), "ioSender", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
return RestartResult.Close;
else
{
bool exit = false;
do
{
Comms.com.PurgeQueue();

bool? res = null;
CancellationToken cancellationToken = new CancellationToken();

new Thread(() =>
{
res = WaitFor.SingleEvent<string>(
cancellationToken,
s => TrapReset(s),
a => model.OnGrblReset += a,
a => model.OnGrblReset -= a,
200, () => Comms.com.WriteByte(GrblConstants.CMD_STATUS_REPORT));
}).Start();

while (res == null)
EventUtils.DoEvents();

if (!(exit = !model.Signals.Value.HasFlag(Signals.SafetyDoor)))
{
if (MessageBox.Show(LibStrings.FindResource("MsgDoorExit"), "ioSender", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
{
exit = true;
return RestartResult.Close;
}
}
} while (!exit);
}
}
else
{
MessageBox.Show(LibStrings.FindResource("MsgDoorPersist"), "ioSender", MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
response = string.Empty;
}
break;

case GrblStates.Hold:
case GrblStates.Sleep:
if (MessageBox.Show(string.Format(LibStrings.FindResource("MsgNoComm"), model.GrblState.State.ToString()),
"ioSender", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
return RestartResult.Close;
else if (!AttemptReset())
{
MessageBox.Show(LibStrings.FindResource("MsgResetExit"), "ioSender");
return RestartResult.Close;
}
break;

case GrblStates.Idle:
if (response.Contains("|SD:Pending"))
AttemptReset();
break;
}
}
}
else
{
MessageBox.Show(response == string.Empty
? "No respone received from controller, exiting."
: string.Format("Unexpected response received from controller: \"{0}\", exiting.", response),
"ioSender", MessageBoxButton.OK, MessageBoxImage.Stop);
return RestartResult.Exit;
}

return response == string.Empty ? RestartResult.NoResponse : RestartResult.Ok;
}

private void TrapReset(string rws)
{
ResetPending = false;
}

private bool AttemptReset()
{
ResetPending = true;
Comms.com.PurgeQueue();

bool? res = null;
CancellationToken cancellationToken = new CancellationToken();

new Thread(() =>
{
res = WaitFor.SingleEvent<string>(
cancellationToken,
s => TrapReset(s),
a => model.OnGrblReset += a,
a => model.OnGrblReset -= a,
AppConfig.Settings.Base.ResetDelay, () => Comms.com.WriteByte(GrblConstants.CMD_RESET));
}).Start();

while (res == null)
EventUtils.DoEvents();

return !ResetPending;
}
}
}
4 changes: 2 additions & 2 deletions CNC Controls/CNC Controls/JobControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* JobControl.xaml.cs - part of CNC Controls library for Grbl
*
* v0.36 / 2021-12-25 / Io Engineering (Terje Io)
* v0.36 / 2021-12-27 / Io Engineering (Terje Io)
*
*/

Expand Down Expand Up @@ -383,7 +383,7 @@ private bool FnKeyHandler(Key key)
{
int id = int.Parse(key.ToString().Substring(1));
var macro = AppConfig.Settings.Macros.FirstOrDefault(o => o.Id == id);
if (macro != null && MessageBox.Show(string.Format("Run {0} macro?", macro.Name), "Run macro", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
if (macro != null && (!macro.ConfirmOnExecute || MessageBox.Show(string.Format("Run {0} macro?", macro.Name), "Run macro", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes))
{
model.ExecuteCommand(macro.Code);
return true;
Expand Down
Loading

0 comments on commit fe01ffa

Please sign in to comment.