Skip to content

Commit

Permalink
hotkeys for overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
arkypita committed Jun 12, 2018
1 parent 89d04ee commit 4b4c910
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 94 deletions.
2 changes: 1 addition & 1 deletion LaserGRBL/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// È possibile specificare tutti i valori oppure impostare valori predefiniti per i numeri relativi alla revisione e alla build
// utilizzando l'asterisco (*) come descritto di seguito:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion ("2.8.47")]
[assembly: AssemblyVersion ("2.8.48")]
[assembly: NeutralResourcesLanguageAttribute("en")]
86 changes: 57 additions & 29 deletions LaserGRBL/GrblCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,13 @@ public object Clone()
private int mCurF;
private int mCurS;

private int mCurOvFeed;
private int mCurOvLinear;
private int mCurOvRapids;
private int mCurOvSpindle;
private int mCurOvPower;

private int mTarOvFeed;
private int mTarOvLinear;
private int mTarOvRapids;
private int mTarOvSpindle;
private int mTarOvPower;

private decimal mLoopCount = 1;

Expand Down Expand Up @@ -265,8 +265,8 @@ public GrblCore(System.Windows.Forms.Control syncroObject)
mSentPtr = mSent;
mQueuePtr = mQueue;

mCurOvFeed = mCurOvRapids = mCurOvSpindle = 100;
mTarOvFeed = mTarOvRapids = mTarOvSpindle = 100;
mCurOvLinear = mCurOvRapids = mCurOvPower = 100;
mTarOvLinear = mTarOvRapids = mTarOvPower = 100;

if (!Settings.ExistObject("Hotkey Setup")) Settings.SetObject("Hotkey Setup", new HotKeysManager());
mHotKeyManager = (HotKeysManager)Settings.GetObject("Hotkey Setup", null);
Expand All @@ -278,6 +278,34 @@ public GrblCore(System.Windows.Forms.Control syncroObject)
CSVD.LoadAppropriateSettings(GrblVersion); //load setting for last known version
}

internal void HotKeyOverride(HotKeysManager.HotKey.Actions action)
{

switch (action)
{
case HotKeysManager.HotKey.Actions.OverridePowerDefault:
mTarOvPower = 100; break;
case HotKeysManager.HotKey.Actions.OverridePowerUp:
mTarOvPower = Math.Min(mTarOvPower + 1, 200); break;
case HotKeysManager.HotKey.Actions.OverridePowerDown:
mTarOvPower = Math.Max(mTarOvPower - 1, 10); break;
case HotKeysManager.HotKey.Actions.OverrideLinearDefault:
mTarOvLinear = 100; break;
case HotKeysManager.HotKey.Actions.OverrideLinearUp:
mTarOvLinear = Math.Min(mTarOvLinear + 1, 200); break;
case HotKeysManager.HotKey.Actions.OverrideLinearDown:
mTarOvLinear = Math.Max(mTarOvLinear - 1, 10); break;
case HotKeysManager.HotKey.Actions.OverrideRapidDefault:
mTarOvRapids = 100; break;
case HotKeysManager.HotKey.Actions.OverrideRapidUp:
mTarOvRapids = Math.Min(mTarOvRapids * 2, 100); break;
case HotKeysManager.HotKey.Actions.OverrideRapidDown:
mTarOvRapids = Math.Max(mTarOvRapids / 2, 25); break;
default:
break;
}
}

public GrblConf Configuration
{
get { return (GrblConf)Settings.GetObject("Grbl Configuration", new GrblConf()); }
Expand Down Expand Up @@ -869,8 +897,8 @@ private void InternalReset(bool grbl)
ClearQueue(true);
mBuffer = 0;
mTP.JobEnd();
mCurOvFeed = mCurOvRapids = mCurOvSpindle = 100;
mTarOvFeed = mTarOvRapids = mTarOvSpindle = 100;
mCurOvLinear = mCurOvRapids = mCurOvPower = 100;
mTarOvLinear = mTarOvRapids = mTarOvPower = 100;

if (grbl)
SendImmediate(24);
Expand Down Expand Up @@ -1230,8 +1258,8 @@ private void OnStartupMessage() //resetta tutto, così funziona anche nel caso d
ClearQueue(false);
mBuffer = 0;
mTP.JobEnd();
mCurOvFeed = mCurOvRapids = mCurOvSpindle = 100;
mTarOvFeed = mTarOvRapids = mTarOvSpindle = 100;
mCurOvLinear = mCurOvRapids = mCurOvPower = 100;
mTarOvLinear = mTarOvRapids = mTarOvPower = 100;
}
RiseOverrideChanged();
}
Expand Down Expand Up @@ -1466,26 +1494,26 @@ private bool HasIncomingData()

public void ManageOverrides()
{
if (mTarOvFeed == 100 && mCurOvFeed != 100) //devo fare un reset
if (mTarOvLinear == 100 && mCurOvLinear != 100) //devo fare un reset
SendImmediate(144);
else if (mTarOvFeed - mCurOvFeed >= 10) //devo fare un bigstep +
else if (mTarOvLinear - mCurOvLinear >= 10) //devo fare un bigstep +
SendImmediate(145);
else if (mCurOvFeed - mTarOvFeed >= 10) //devo fare un bigstep -
else if (mCurOvLinear - mTarOvLinear >= 10) //devo fare un bigstep -
SendImmediate(146);
else if (mTarOvFeed - mCurOvFeed >= 1) //devo fare uno smallstep +
else if (mTarOvLinear - mCurOvLinear >= 1) //devo fare uno smallstep +
SendImmediate(147);
else if (mCurOvFeed - mTarOvFeed >= 1) //devo fare uno smallstep -
else if (mCurOvLinear - mTarOvLinear >= 1) //devo fare uno smallstep -
SendImmediate(148);

if (mTarOvSpindle == 100 && mCurOvSpindle != 100) //devo fare un reset
if (mTarOvPower == 100 && mCurOvPower != 100) //devo fare un reset
SendImmediate(153);
else if (mTarOvSpindle - mCurOvSpindle >= 10) //devo fare un bigstep +
else if (mTarOvPower - mCurOvPower >= 10) //devo fare un bigstep +
SendImmediate(154);
else if (mCurOvSpindle - mTarOvSpindle >= 10) //devo fare un bigstep -
else if (mCurOvPower - mTarOvPower >= 10) //devo fare un bigstep -
SendImmediate(155);
else if (mTarOvSpindle - mCurOvSpindle >= 1) //devo fare uno smallstep +
else if (mTarOvPower - mCurOvPower >= 1) //devo fare uno smallstep +
SendImmediate(156);
else if (mCurOvSpindle - mTarOvSpindle >= 1) //devo fare uno smallstep -
else if (mCurOvPower - mTarOvPower >= 1) //devo fare uno smallstep -
SendImmediate(157);

if (mTarOvRapids == 100 && mCurOvRapids != 100)
Expand All @@ -1511,28 +1539,28 @@ private void ParseOverrides(string data)

private void ChangeOverrides(int feed, int rapids, int spindle)
{
bool notify = (feed != mCurOvFeed || rapids != mCurOvRapids || spindle != mCurOvSpindle);
mCurOvFeed = feed;
bool notify = (feed != mCurOvLinear || rapids != mCurOvRapids || spindle != mCurOvPower);
mCurOvLinear = feed;
mCurOvRapids = rapids;
mCurOvSpindle = spindle;
mCurOvPower = spindle;

if (notify)
RiseOverrideChanged();
}

public int OverrideG1
{ get { return mCurOvFeed; } }
{ get { return mCurOvLinear; } }

public int OverrideG0
{ get { return mCurOvRapids; } }

public int OverrideS
{ get { return mCurOvSpindle; } }
{ get { return mCurOvPower; } }

public int TOverrideG1
{
get { return mTarOvFeed; }
set { mTarOvFeed = value; }
get { return mTarOvLinear; }
set { mTarOvLinear = value; }
}

public int TOverrideG0
Expand All @@ -1543,8 +1571,8 @@ public int TOverrideG0

public int TOverrideS
{
get { return mTarOvSpindle; }
set { mTarOvSpindle = value; }
get { return mTarOvPower; }
set { mTarOvPower = value; }
}

private void ParseMachineStatus(string data)
Expand Down
131 changes: 91 additions & 40 deletions LaserGRBL/HotKeysManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ public class HotKey : ICloneable
public enum Actions
{
ConnectDisconnect = 10, Connect = 11, Disconnect = 12,
OpenFile = 20, ReopenLastFile = 21, SaveFile = 22, ExecuteFile = 23,
OpenFile = 20, ReopenLastFile = 21, SaveFile = 22, ExecuteFile = 23, AbortFile = 24,
HelpOnline = 30,
Reset = 100, Homing = 101, Unlock = 102, PauseJob = 103, ResumeJob = 104, SetNewZero = 105,
JogHome = 1000, JogN = 1001, JogNE = 1002, JogE = 1003, JogSE = 1004, JogS = 1005, JogSW = 1006, JogW = 1007, JogNW = 1008,
OverridePowerDefault = 1100, OverridePowerUp = 1101, OverridePowerDown = 1102,
OverrideLinearDefault = 1110, OverrideLinearUp = 1111, OverrideLinearDown = 1112,
OverrideRapidDefault = 1120, OverrideRapidUp = 1121, OverrideRapidDown = 1122,
CustomButton1 = 2000, CustomButton2 = 2001, CustomButton3 = 2002, CustomButton4 = 2003, CustomButton5 = 2004, CustomButton6 = 2005, CustomButton7 = 2006, CustomButton8 = 2007, CustomButton9 = 2008, CustomButton10 = 2009
}

Expand Down Expand Up @@ -80,48 +83,84 @@ public object Clone()

public HotKeysManager()
{
Add(new HotKey(HotKey.Actions.ConnectDisconnect, Keys.F12));
Add(new HotKey(HotKey.Actions.Connect, Keys.None));
Add(new HotKey(HotKey.Actions.Disconnect, Keys.None));

Add(new HotKey(HotKey.Actions.OpenFile, Keys.Control | Keys.O));
Add(new HotKey(HotKey.Actions.ReopenLastFile, Keys.Control | Keys.R));
Add(new HotKey(HotKey.Actions.SaveFile, Keys.Control | Keys.S));
Add(new HotKey(HotKey.Actions.ExecuteFile, Keys.F5));

Add(new HotKey(HotKey.Actions.HelpOnline, Keys.Control | Keys.F1));

Add(new HotKey(HotKey.Actions.Reset, Keys.Control | Keys.X));
Add(new HotKey(HotKey.Actions.Homing, Keys.Control | Keys.H));
Add(new HotKey(HotKey.Actions.Unlock, Keys.Control | Keys.U));
Add(new HotKey(HotKey.Actions.PauseJob, Keys.F6));
Add(new HotKey(HotKey.Actions.ResumeJob, Keys.F7));
Add(new HotKey(HotKey.Actions.SetNewZero, Keys.Control | Keys.Z));

Add(new HotKey(HotKey.Actions.JogHome, Keys.NumPad5));
Add(new HotKey(HotKey.Actions.JogN, Keys.NumPad8));
Add(new HotKey(HotKey.Actions.JogNE, Keys.NumPad9));
Add(new HotKey(HotKey.Actions.JogE, Keys.NumPad6));
Add(new HotKey(HotKey.Actions.JogSE, Keys.NumPad3));
Add(new HotKey(HotKey.Actions.JogS, Keys.NumPad2));
Add(new HotKey(HotKey.Actions.JogSW, Keys.NumPad1));
Add(new HotKey(HotKey.Actions.JogW, Keys.NumPad4));
Add(new HotKey(HotKey.Actions.JogNW, Keys.NumPad7));

Add(new HotKey(HotKey.Actions.CustomButton1, Keys.Control | Keys.D1));
Add(new HotKey(HotKey.Actions.CustomButton2, Keys.Control | Keys.D2));
Add(new HotKey(HotKey.Actions.CustomButton3, Keys.Control | Keys.D3));
Add(new HotKey(HotKey.Actions.CustomButton4, Keys.Control | Keys.D4));
Add(new HotKey(HotKey.Actions.CustomButton5, Keys.Control | Keys.D5));
Add(new HotKey(HotKey.Actions.CustomButton6, Keys.Control | Keys.D6));
Add(new HotKey(HotKey.Actions.CustomButton7, Keys.Control | Keys.D7));
Add(new HotKey(HotKey.Actions.CustomButton8, Keys.Control | Keys.D8));
Add(new HotKey(HotKey.Actions.CustomButton9, Keys.Control | Keys.D9));
Add(new HotKey(HotKey.Actions.CustomButton10, Keys.Control | Keys.D0));

}

private void AddAllFeatures()
{
AddNew(new HotKey(HotKey.Actions.ConnectDisconnect, Keys.F12));
AddNew(new HotKey(HotKey.Actions.Connect, Keys.None));
AddNew(new HotKey(HotKey.Actions.Disconnect, Keys.None));

AddNew(new HotKey(HotKey.Actions.OpenFile, Keys.Control | Keys.O));
AddNew(new HotKey(HotKey.Actions.ReopenLastFile, Keys.Control | Keys.R));
AddNew(new HotKey(HotKey.Actions.SaveFile, Keys.Control | Keys.S));
AddNew(new HotKey(HotKey.Actions.ExecuteFile, Keys.F5));
AddNew(new HotKey(HotKey.Actions.AbortFile, Keys.Control | Keys.F5));

AddNew(new HotKey(HotKey.Actions.HelpOnline, Keys.Control | Keys.F1));

AddNew(new HotKey(HotKey.Actions.Reset, Keys.Control | Keys.X));
AddNew(new HotKey(HotKey.Actions.Homing, Keys.Control | Keys.H));
AddNew(new HotKey(HotKey.Actions.Unlock, Keys.Control | Keys.U));
AddNew(new HotKey(HotKey.Actions.PauseJob, Keys.F6));
AddNew(new HotKey(HotKey.Actions.ResumeJob, Keys.F7));
AddNew(new HotKey(HotKey.Actions.SetNewZero, Keys.Control | Keys.Z));

AddNew(new HotKey(HotKey.Actions.JogHome, Keys.NumPad5));
AddNew(new HotKey(HotKey.Actions.JogN, Keys.NumPad8));
AddNew(new HotKey(HotKey.Actions.JogNE, Keys.NumPad9));
AddNew(new HotKey(HotKey.Actions.JogE, Keys.NumPad6));
AddNew(new HotKey(HotKey.Actions.JogSE, Keys.NumPad3));
AddNew(new HotKey(HotKey.Actions.JogS, Keys.NumPad2));
AddNew(new HotKey(HotKey.Actions.JogSW, Keys.NumPad1));
AddNew(new HotKey(HotKey.Actions.JogW, Keys.NumPad4));
AddNew(new HotKey(HotKey.Actions.JogNW, Keys.NumPad7));

AddNew(new HotKey(HotKey.Actions.OverridePowerDefault, Keys.None));
AddNew(new HotKey(HotKey.Actions.OverridePowerUp, Keys.None));
AddNew(new HotKey(HotKey.Actions.OverridePowerDown, Keys.None));

AddNew(new HotKey(HotKey.Actions.OverrideLinearDefault, Keys.None));
AddNew(new HotKey(HotKey.Actions.OverrideLinearUp, Keys.None));
AddNew(new HotKey(HotKey.Actions.OverrideLinearDown, Keys.None));

AddNew(new HotKey(HotKey.Actions.OverrideRapidDefault, Keys.None));
AddNew(new HotKey(HotKey.Actions.OverrideRapidUp, Keys.None));
AddNew(new HotKey(HotKey.Actions.OverrideRapidDown, Keys.None));

AddNew(new HotKey(HotKey.Actions.CustomButton1, Keys.Control | Keys.D1));
AddNew(new HotKey(HotKey.Actions.CustomButton2, Keys.Control | Keys.D2));
AddNew(new HotKey(HotKey.Actions.CustomButton3, Keys.Control | Keys.D3));
AddNew(new HotKey(HotKey.Actions.CustomButton4, Keys.Control | Keys.D4));
AddNew(new HotKey(HotKey.Actions.CustomButton5, Keys.Control | Keys.D5));
AddNew(new HotKey(HotKey.Actions.CustomButton6, Keys.Control | Keys.D6));
AddNew(new HotKey(HotKey.Actions.CustomButton7, Keys.Control | Keys.D7));
AddNew(new HotKey(HotKey.Actions.CustomButton8, Keys.Control | Keys.D8));
AddNew(new HotKey(HotKey.Actions.CustomButton9, Keys.Control | Keys.D9));
AddNew(new HotKey(HotKey.Actions.CustomButton10, Keys.Control | Keys.D0));
}

private void AddNew(HotKey toadd)
{
foreach (HotKey hk in this)
if (hk.Action == toadd.Action)
return;

Add(toadd);
}

public void Init(GrblCore core)
{ mCore = core; }
{
mCore = core;
AddAllFeatures();
Sort(CompareKey);
}

private int CompareKey(HotKey x, HotKey y)
{
return x.Action - y.Action;
}

internal bool ManageHotKeys(Keys keys)
{
Expand Down Expand Up @@ -157,6 +196,8 @@ private bool PerformAction(HotKey.Actions action)
mCore.SaveProgram(); break;
case HotKey.Actions.ExecuteFile:
mCore.RunProgram(); break;
case HotKey.Actions.AbortFile:
mCore.AbortProgram(); break;
case HotKey.Actions.HelpOnline:
mCore.HelpOnLine(); break;
case HotKey.Actions.Reset:
Expand Down Expand Up @@ -189,6 +230,16 @@ private bool PerformAction(HotKey.Actions action)
mCore.Jog(GrblCore.JogDirection.W); break;
case HotKey.Actions.JogNW:
mCore.Jog(GrblCore.JogDirection.NW); break;
case HotKey.Actions.OverridePowerDefault:
case HotKey.Actions.OverridePowerUp:
case HotKey.Actions.OverridePowerDown:
case HotKey.Actions.OverrideLinearDefault:
case HotKey.Actions.OverrideLinearUp:
case HotKey.Actions.OverrideLinearDown:
case HotKey.Actions.OverrideRapidDefault:
case HotKey.Actions.OverrideRapidUp:
case HotKey.Actions.OverrideRapidDown:
mCore.HotKeyOverride(action); break;
case HotKey.Actions.CustomButton1:
mCore.HKCustomButton(0); break;
case HotKey.Actions.CustomButton2:
Expand Down
4 changes: 2 additions & 2 deletions LaserGRBL/HotkeyManagerForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions LaserGRBL/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4b4c910

Please sign in to comment.