From f1d32365c6a979e86f5c40e89a88d92f86178928 Mon Sep 17 00:00:00 2001 From: Ben Suffolk Date: Mon, 15 Jun 2015 21:35:44 +0100 Subject: [PATCH 1/2] Fixed a display issue where the gcode entry didn't expand to full size when there is no webcam --- i/index.html | 66 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 19 deletions(-) diff --git a/i/index.html b/i/index.html index 8977515..06194f3 100644 --- a/i/index.html +++ b/i/index.html @@ -107,6 +107,29 @@ padding: 10px; } +.display-table { + display: table; + width: 100%; + margin-bottom: 0px; +} + +.display-row { + display: table-row; +} + +.cell-320 { + width: 320px; + display: table-cell; + vertical-align: top; + padding-right: 10px; +} + +.cell-stretch { + width: auto; + display: table-cell; + padding-right: 10px; +} + @@ -248,32 +271,37 @@
Select Port

 
- From a93423e5194d8d61edb92368603190c56566915e Mon Sep 17 00:00:00 2001 From: Ben Suffolk Date: Mon, 15 Jun 2015 22:20:05 +0100 Subject: [PATCH 2/2] Added user configurable buttons --- i/userButton.css | 58 ++++++++++++++++++++++ i/userButton.js | 126 +++++++++++++++++++++++++++++++++++++++++++++++ userButtons.js | 59 ++++++++++++++++++++++ 3 files changed, 243 insertions(+) create mode 100644 i/userButton.css create mode 100644 i/userButton.js create mode 100644 userButtons.js diff --git a/i/userButton.css b/i/userButton.css new file mode 100644 index 0000000..668de6d --- /dev/null +++ b/i/userButton.css @@ -0,0 +1,58 @@ +/* + + userButton.css - An addition to GRBLWeb + Copyright (c) 2015, Ben Suffolk + + GRBLWeb - a web based CNC controller for GRBL + Copyright (C) 2015 Andrew Hodel + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +*/ + + +.btn-user .dropdown-menu { + padding: 0px; + width: 200px; + border: none; +} + +.btn-user .dropdown-menu input { + -webkit-border-top-left-radius: 4px; + -webkit-border-top-right-radius: 4px; + -moz-border-radius-topleft: 4px; + -moz-border-radius-topright: 4px; + border-top-left-radius: 4px; + border-top-right-radius: 4px; + -webkit-border-bottom-left-radius: 0px; + -webkit-border-bottom-right-radius: 0px; + -moz-border-radius-bottomleft: 0px; + -moz-border-radius-bottomright: 0px; + border-bottom-left-radius: 0px; + border-bottom-right-radius: 0px; +} + +.btn-user .dropdown-menu textarea { + width: 100%; + overflow: auto; + display: block; + border-color: #CCCCCC +} diff --git a/i/userButton.js b/i/userButton.js new file mode 100644 index 0000000..4ba3b9d --- /dev/null +++ b/i/userButton.js @@ -0,0 +1,126 @@ +/* + + userButton.js - An addition to GRBLWeb + Copyright (c) 2015, Ben Suffolk + + GRBLWeb - a web based CNC controller for GRBL + Copyright (C) 2015 Andrew Hodel + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + ******** + + 1. Inculde files in index.html : + + + 2. Add 1 or more user defined button elements, set the id of the button to + btn-user- where is a consecutive number starting at 1 : + +
+ +
+ + +
+
+ + 3. You may also add any simple button that executes GCode : + + + + If your GCode should have more than 1 line, use to sepcify a new line : + + + +*/ + + +var socket; + +function userButton(s) { + + socket = s; + + // Instruction from the server to configure the user buttons + socket.on('configUserButtons', function(data) { + + // Loop over each user button on the page + $('div.btn-user > button.btn-gcode').each(function() { + var number = $(this).attr('id').substring(9); + // Do we have data for this button? + if(typeof data[number] != 'undefined') { + $('#btn-user-'+number).html(data[number].title); + $('#btn-user-'+number).data('gcodeline', data[number].line); + } + }); + }); +} + + +$(document).ready(function() { + + // Make sure the dropdown form does not close when the form field is clicked. + $('.dropdown-menu :input').click(function(e) { + e.stopPropagation(); + }); + + // Load the current details into the form when the uesr clicks the configure drop down + $('.btn-user .dropdown-toggle').click(function() { + var button = $(this).closest('.btn-user').find('> .btn'); + $(this).parent().find('.dropdown-menu input').val(button.html()); + $(this).parent().find('.dropdown-menu textarea').val(button.data('gcodeline')); + }); + + // Stop the axis step keys working in the form + $('.dropdown-menu :input').keydown(function (e) { + e.stopPropagation(); + }); + + + // Pick up any changes to the title + $('.dropdown-menu input').change(function(){ + var button = $(this).closest('.btn-user').find('> .btn'); + var number = button.attr('id').substring(9); + button.html($(this).val()); + socket.emit('configUserButton', { 'button':number, 'title':button.html(), 'line': button.data('gcodeline')}); + }); + + // Pick up any changes to the gcode + $('.dropdown-menu textarea').change(function() { + var button = $(this).closest('.btn-user').find('> .btn'); + var number = button.attr('id').substring(9); + button.data('gcodeline', $(this).val()); + socket.emit('configUserButton', { 'button':number, 'title':button.html(), 'line': button.data('gcodeline')}); + }); + + // If its a button with gcode data the send the code + $('.btn-gcode').click(function() { + var gcode = $(this).data('gcodeline'); + if(typeof gcode != 'undefined' && gcode != '') { + socket.emit('gcodeLine', { line: gcode}); + } + }); +}); diff --git a/userButtons.js b/userButtons.js new file mode 100644 index 0000000..6295f21 --- /dev/null +++ b/userButtons.js @@ -0,0 +1,59 @@ +/* + + userButtons.js - An addition to GRBLWeb + Copyright (c) 2015, Ben Suffolk + + GRBLWeb - a web based CNC controller for GRBL + Copyright (C) 2015 Andrew Hodel + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +*/ + +var fs = require('fs'); + +var userButtons = {}; + +if(fs.existsSync("./userButtons.json")) { + userButtons = JSON.parse(fs.readFileSync("./userButtons.json")); +} + +module.exports = function(io) { + + io.sockets.on('connection', function (socket) { + + socket.emit('configUserButtons', userButtons); + + socket.on('configUserButton', function(data) { + + var button = data['button']; + if(typeof button != 'undefined' && button >0 && button <99) { + console.log('new user button data for button: '+button); + userButtons[button] = data; + } + + fs.writeFileSync("./userButtons.json", JSON.stringify(userButtons)); + socket.emit('configUserButtons', userButtons); + }); + }); + +} +