From 2b2a63af638518e5c3599b5c8f71f52ce615cd6f Mon Sep 17 00:00:00 2001 From: openbuilds-engineer Date: Tue, 14 Apr 2020 19:57:56 +0200 Subject: [PATCH] v1.0.223 --- CHANGELOG.txt | 3 +- app/css/main.css | 9 +++- app/js/keyboard.js | 25 ++++++++++++ app/js/macros.js | 100 +++++++++++++++++++++++++++++++++++++++------ app/js/ui.js | 9 ++++ 5 files changed, 132 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 0b719e3..ad88d1e 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,6 +1,7 @@ +v1.0.223: Added keyboard shortcuts to Macros, updated look of buttons to include showing keyboard assignment v1.0.222: Added Keyboard shortcuts for GotoZero, and switching between Incremental/Continuous jogging v1.0.221: Corrected product names for XYZ Probe Plus -v1.0.220: New XYZ and Custom Probe wizards, new Probe Button on Main toolbar, fixed File Assocation Opening (Bug #119 ), added loaded Filename to titlebar (Issue #116), changed Keybinding for Devtools to ctrl+shift+i, added shortcut key F6 to jump to console (Issue #112) +v1.0.220: New XYZ and Custom Probe wizards, new Probe Button on Main toolbar, fixed File association Opening (Bug #119 ), added loaded Filename to titlebar (Issue #116), changed Keybinding for Devtools to ctrl+shift+i, added shortcut key F6 to jump to console (Issue #112) v1.0.216-219: Internal Testing versions only v1.0.215: Fixed bug with Z Plate retract where plate is thicker than 10mm v1.0.214: Fixed bug with Z-Zero plate probing routine, added Z Plate thickness setting back diff --git a/app/css/main.css b/app/css/main.css index b1ae0f5..c127f04 100644 --- a/app/css/main.css +++ b/app/css/main.css @@ -208,8 +208,15 @@ select { background-color: #fff } +.macroedit { + position: absolute !important; + top: 5px !important; + right: 5px !important; + font-size: 11px !important; +} + .macroedit:hover { - color: #CE352C !important; + color: #ff1e11 !important; } .machineicon:hover { diff --git a/app/js/keyboard.js b/app/js/keyboard.js index 16b5169..3257ed8 100644 --- a/app/js/keyboard.js +++ b/app/js/keyboard.js @@ -95,6 +95,31 @@ function bindKeys() { } }); + // Bind for Macro keys + if (buttonsarray.length > 0) { + for (i = 0; i < buttonsarray.length; i++) { + if (buttonsarray[i].macrokeyboardshortcut.length) { + $(document).bind('keydown', buttonsarray[i].macrokeyboardshortcut, function(e) { + console.log(e) + var newVal = ""; + if (e.altKey) { + newVal += 'alt+' + } + if (e.ctrlKey) { + newVal += 'ctrl+' + } + if (e.shiftKey) { + newVal += 'shift+' + } + newVal += e.key + var macro = searchMacro("macrokeyboardshortcut", newVal, buttonsarray) + console.log(macro) + sendGcode(macro.gcode); + }); + } + } + } + // Bind for Jog and Control Buttons if (keyboardShortcuts.xM.length) { $(document).bind('keydown', keyboardShortcuts.xM, function(event) { diff --git a/app/js/macros.js b/app/js/macros.js index 1a79ffc..7a435c2 100644 --- a/app/js/macros.js +++ b/app/js/macros.js @@ -8,20 +8,35 @@ function populateMacroButtons() { if (!buttonsarray[i].tooltip) { buttonsarray[i].tooltip = "" }; + if (buttonsarray[i].macrokeyboardshortcut.length) { + var keyboardAssignment = buttonsarray[i].macrokeyboardshortcut + } else { + var keyboardAssignment = "none" + } var button = ` - ` + + + ` $("#macros").append(button); } // append add button var button = ` - ` + + + ` $("#macros").append(button); localStorage.setItem('macroButtons', JSON.stringify(buttonsarray)); } @@ -37,15 +52,22 @@ function edit(i, evt) { var gcode = buttonsarray[i].gcode; var cls = buttonsarray[i].class; var tooltip = buttonsarray[i].tooltip; + if (buttonsarray[i].macrokeyboardshortcut.length > 0) { + var macrokeyboardshortcut = buttonsarray[i].macrokeyboardshortcut; + } else { + var macrokeyboardshortcut = ""; + } + } else { var icon = "far fa-question-circle"; var title = ""; var gcode = ""; var cls = ""; var tooltip = ""; + var macrokeyboardshortcut = ""; } - var macroTemplate = `
+ var macroTemplate = `
@@ -87,6 +109,13 @@ function edit(i, evt) {
+
+ Click below to assign a new Keyboard Shortcut / combination to a function. Ctrl, Alt and Shift can be added to create combinations. + +
+ +
+
` @@ -119,6 +148,7 @@ function edit(i, evt) { buttonsarray[seq].gcode = $('#macrogcode').val(); buttonsarray[seq].class = $('#macrocls').val(); buttonsarray[seq].tooltip = $('#macrotooltip').val(); + buttonsarray[seq].macrokeyboardshortcut = $('#macrokeyboardshortcut').val(); populateMacroButtons(); } else { buttonsarray.push({ @@ -126,7 +156,8 @@ function edit(i, evt) { icon: $('#macroicon').val(), gcode: $('#macrogcode').val(), class: $('#macrocls').val(), - tooltip: $('#macrotooltip').val() + tooltip: $('#macrotooltip').val(), + macrokeyboardshortcut: $('#macrokeyboardshortcut').val(), }) populateMacroButtons(); } @@ -135,6 +166,42 @@ function edit(i, evt) { ] }); + $('#macrokeyboardshortcut').bind('keydown', null, function(e) { + e.preventDefault(); + console.log(e) + var newVal = ""; + if (e.altKey) { + newVal += 'alt+' + } + if (e.ctrlKey) { + newVal += 'ctrl+' + } + if (e.shiftKey) { + newVal += 'shift+' + } + + if (e.key.toLowerCase() != 'alt' && e.key.toLowerCase() != 'control' && e.key.toLowerCase() != 'shift') { + // Handle MetroUI naming non-standards of some keys + if (e.keyCode == 32) { + newVal += 'space'; + } else if (e.key.toLowerCase() == 'escape') { + newVal += 'esc'; + } else if (e.key.toLowerCase() == 'arrowleft') { + newVal += 'left'; + } else if (e.key.toLowerCase() == 'arrowright') { + newVal += 'right'; + } else if (e.key.toLowerCase() == 'arrowup') { + newVal += 'up'; + } else if (e.key.toLowerCase() == 'arrowdown') { + newVal += 'down'; + } else { + newVal += e.key.toLowerCase(); + } + $('.newMacroKeyAssignment').val(newVal) + } + + }); + var options = { placement: 'bottom', collision: 'none', @@ -162,4 +229,13 @@ if (localStorage.getItem('macroButtons')) { buttonsarray = JSON.parse(localStorage.getItem('macroButtons')); } -populateMacroButtons() \ No newline at end of file +populateMacroButtons() + +function searchMacro(prop, nameKey, myArray) { + console.log(nameKey, prop, myArray) + for (var i = 0; i < myArray.length; i++) { + if (myArray[i][prop] === nameKey) { + return myArray[i]; + } + } +} \ No newline at end of file diff --git a/app/js/ui.js b/app/js/ui.js index 51bb3c5..500e4da 100644 --- a/app/js/ui.js +++ b/app/js/ui.js @@ -22,6 +22,7 @@ function setConnectBar(val, status) { } $('#portUSB').parent(".select").addClass('success') $('#portUSB').parent(".select").removeClass('alert') + $('.macrobtn').addClass('disabled') // Set Port Dropdown to Current Value // Not applicable to Status 0 as its set by populatePortsMenu(); @@ -42,6 +43,8 @@ function setConnectBar(val, status) { $('#portUSB').parent(".select").addClass('alert') // Set Port Dropdown to Current Value $("#portUSB").val(status.comms.interfaces.activePort); + $('.macrobtn').removeClass('disabled') + } else if (val == 3) { // Busy Streaming GCODE // Status Badge $('#connectStatus').html("Port: Connected"); @@ -58,6 +61,7 @@ function setConnectBar(val, status) { $('#portUSB').parent(".select").addClass('alert') // Set Port Dropdown to Current Value $("#portUSB").val(status.comms.interfaces.activePort); + $('.macrobtn').addClass('disabled') } else if (val == 4) { // Paused // Status Badge @@ -75,6 +79,7 @@ function setConnectBar(val, status) { $('#portUSB').parent(".select").addClass('alert') // Set Port Dropdown to Current Value $("#portUSB").val(status.comms.interfaces.activePort); + $('.macrobtn').addClass('disabled') } else if (val == 5) { // Alarm State // Status Badge @@ -92,6 +97,8 @@ function setConnectBar(val, status) { $('#portUSB').parent(".select").addClass('alert') // Set Port Dropdown to Current Value $("#portUSB").val(status.comms.interfaces.activePort); + $('.macrobtn').addClass('disabled') + } else if (val == 6) { // Firmware Upgrade State // Status Badge $('#connectStatus').html("Port: Flashing"); @@ -108,6 +115,8 @@ function setConnectBar(val, status) { $('#portUSB').parent(".select").addClass('alert') // Set Port Dropdown to Current Value $("#portUSB").val(status.comms.interfaces.activePort); + $('.macrobtn').addClass('disabled') + } }