Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

buttons allow arbitrary gcode, also make send box work and add sent c…

…odes to log
  • Loading branch information...
commit 24c219d90507f4984e8dc11c95b492461183ef45 1 parent a44dea2
Michael Moon authored

Showing 2 changed files with 38 additions and 79 deletions. Show diff stats Hide diff stats

  1. +23 16 html/index.html
  2. +15 63 html/js/jog.js
39 html/index.html
@@ -29,7 +29,7 @@
29 29 <textarea id="log" rows="16" cols="40" readonly="readonly"></textarea><br />
30 30 <form id="manual_entry">
31 31 <input type="text" id="send" style="width: 80%; float: left;" />
32   - <input type="submit" id="sendBtn" value="Send" />
  32 + <input type="button" id="sendBtn" value="Send" />
33 33 </form>
34 34 </td></tr>
35 35 </table>
@@ -51,22 +51,26 @@
51 51 jogE.draw();
52 52
53 53 function callback_jogEvent(e) {
54   - netrap.jog(e.jogX, e.jogY, e.jogZ, e.jogE);
  54 +// alert(e.gcode.join("\n"));
  55 + for (var i = 0; i < e.gcode.length; i++) {
  56 + netrap.queueCmd(e.gcode[i]);
  57 + }
  58 + netrap.queueCommit();
55 59 };
56   - jogXY.observe('jog', callback_jogEvent);
57   - jogZ.observe('jog', callback_jogEvent);
58   - jogE.observe('jog', callback_jogEvent);
  60 + jogXY.observe('click', callback_jogEvent);
  61 + jogZ.observe('click', callback_jogEvent);
  62 + jogE.observe('click', callback_jogEvent);
59 63
60   - refreshPrinters.onclick = function() {
  64 + $('refreshPrinters').observe('click', function() {
61 65 netrap.refreshPrinterList();
62   - };
63   - getpos.onclick = function() {
  66 + });
  67 + $('getpos').observe('click', function() {
64 68 netrap.refreshPosition();
65   - };
66   - clearlog.onclick = function() {
  69 + });
  70 + $('clearlog').observe('click', function() {
67 71 log.textContent = "";
68   - };
69   - monitor.onchange = function() {
  72 + });
  73 + $('monitor').observe('change', function() {
70 74 if (this.checked) {
71 75 this.timer = setInterval(function() {
72 76 netrap.refreshTemperatureList();
@@ -78,13 +82,16 @@
78 82 this.timer = undefined;
79 83 }
80 84 }
81   - };
82   - manual_entry.onsubmit = function() {
83   - if (send.value)
  85 + });
  86 + $('sendBtn').observe('click', function() {
  87 + var send = $('send');
  88 + if (send.value) {
84 89 netrap.sendCmd(send.value);
  90 + $('log').value += "> " + send.value + "\n";
  91 + }
85 92 send.value = "";
86 93 return false;
87   - };
  94 + });
88 95 });
89 96 </script>
90 97 </body>
78 html/js/jog.js
@@ -31,10 +31,10 @@ function Point(x, y) {
31 31 this.y = y;
32 32 }
33 33
34   -function Button(axis, length) {
  34 +function Button(description, gcode) {
35 35 var self = this;
36   - this.axis = axis;
37   - this.length = length;
  36 + this.description = description;
  37 + this.gcode = gcode;
38 38
39 39 this.points = [];
40 40 }
@@ -44,7 +44,7 @@ Button.prototype = {
44 44 return pointInPolygon(this.points, x, y);
45 45 },
46 46 toString: function() {
47   - return this.axis + this.length;
  47 + return this.description;
48 48 },
49 49 highlight: function(context) {
50 50 var i;
@@ -66,7 +66,7 @@ Button.prototype = {
66 66 function Jog(canvas) {
67 67 var self = this;
68 68 this.eventListeners = {
69   - jog: []
  69 + click: []
70 70 };
71 71 this.fireEvent = function(name, e) {
72 72 if (self.eventListeners[name]) {
@@ -107,7 +107,6 @@ function Jog(canvas) {
107 107 var x = e.clientX - $(self.canvas).viewportOffset().left;
108 108 var y = e.clientY - $(self.canvas).viewportOffset().top;
109 109 var b;
110   -// $('log').textContent = 'x: ' + x + '\ny: ' + y;
111 110 self.draw();
112 111 for (b = 0; b < self.buttons.length; b++) {
113 112 if (self.buttons[b].check(x, y)) {
@@ -116,35 +115,16 @@ function Jog(canvas) {
116 115 }
117 116 }
118 117 };
119   - this.canvas.onmouseup = function(e) {
  118 + this.canvas.onclick = function(e) {
120 119 var x = e.clientX - $(self.canvas).viewportOffset().left;
121 120 var y = e.clientY - $(self.canvas).viewportOffset().top;
122 121 var b;
123   -// $('log').textContent = 'x: ' + x + '\ny: ' + y;
124 122 for (b = 0; b < self.buttons.length; b++) {
125 123 var button = self.buttons[b];
126 124 if (button.check(x, y)) {
127   - e.jogX = undefined;
128   - e.jogY = undefined;
129   - e.jogZ = undefined;
130   - e.jogE = undefined;
131   - if (button.axis == 'X') {
132   - e.jogX = button.length;
133   - self.fireEvent('jogX', e);
134   - }
135   - if (button.axis == 'Y') {
136   - e.jogY = button.length;
137   - self.fireEvent('jogY', e);
138   - }
139   - if (button.axis == 'Z') {
140   - e.jogZ = button.length;
141   - self.fireEvent('jogZ', e);
142   - }
143   - if (button.axis == 'E') {
144   - e.jogE = button.length;
145   - self.fireEvent('jogE', e);
146   - }
147   - self.fireEvent('jog', e);
  125 + e.description = button.description;
  126 + e.gcode = button.gcode;
  127 + self.fireEvent('click', e);
148 128 }
149 129 }
150 130 };
@@ -170,14 +150,12 @@ Jog.prototype = {
170 150 * XY jog buttons
171 151 */
172 152
173   -// ButtonXY.Inherits(Button);
174 153 ButtonXY.prototype = new Button();
175 154 ButtonXY.prototype.constructor = ButtonXY;
176 155 function ButtonXY(axis, length, canvas) {
177 156 var self = this, a;
178 157
179   -// this.Inherits(Button, axis, length);
180   - Button.call(this, axis, length);
  158 + Button.call(this, axis + length, [ "G91", "G1 " + axis + length, "G90" ]);
181 159
182 160 var innerR;
183 161 var outerR;
@@ -223,29 +201,19 @@ function ButtonXY(axis, length, canvas) {
223 201 this.outerR = outerR;
224 202 this.quadrant = quadrant;
225 203
226   -// self.context.arc(centerX, centerY, outerR, (quadrant * 90 - 45) * Math.PI / 180, (quadrant * 90 - 135) * Math.PI / 180, true);
227   -// self.context.arc(centerX, centerY, innerR, (quadrant * 90 - 135) * Math.PI / 180, (quadrant * 90 - 45) * Math.PI / 180, false);
228   -// self.context.lineTo(centerX + outerR * Math.cos((quadrant * 90 - 45) * Math.PI / 180), centerY + outerR * Math.sin((quadrant * 90 - 45) * Math.PI / 180));
229   -
230 204 for (a = 45; a <= 135; a += 5) {
231 205 this.points.push(new Point(centerX + innerR * Math.cos((quadrant * 90 - a) * Math.PI / 180), centerY + innerR * Math.sin((quadrant * 90 - a) * Math.PI / 180)));
232 206 }
233   -// this.points.push(new Point(centerX + innerR * Math.cos((quadrant * 90 - 90) * Math.PI / 180), centerY + innerR * Math.sin((quadrant * 90 - 90) * Math.PI / 180)));
234   -// this.points.push(new Point(centerX + innerR * Math.cos((quadrant * 90 - 135) * Math.PI / 180), centerY + innerR * Math.sin((quadrant * 90 - 135) * Math.PI / 180)));
235 207 for (a = 135; a >= 45; a -= 5) {
236 208 this.points.push(new Point(centerX + outerR * Math.cos((quadrant * 90 - a) * Math.PI / 180), centerY + outerR * Math.sin((quadrant * 90 - a) * Math.PI / 180)));
237 209 }
238   -// this.points.push(new Point(centerX + outerR * Math.cos((quadrant * 90 - 90) * Math.PI / 180), centerY + outerR * Math.sin((quadrant * 90 - 90) * Math.PI / 180)));
239   -// this.points.push(new Point(centerX + outerR * Math.cos((quadrant * 90 - 45) * Math.PI / 180), centerY + outerR * Math.sin((quadrant * 90 - 45) * Math.PI / 180)));
240 210 }
241 211
242   -// JogXY.Inherits(Jog);
243 212 JogXY.prototype = new Jog();
244 213 JogXY.prototype.constructor = JogXY;
245 214 function JogXY(canvas) {
246 215 var self = this, d;
247 216
248   -// this.Inherits(Jog, canvas);
249 217 Jog.call(this, canvas);
250 218
251 219 for (d = 0.1; d < 101; d *= 10) {
@@ -254,7 +222,7 @@ function JogXY(canvas) {
254 222 this.buttons.push(new ButtonXY('Y', d));
255 223 this.buttons.push(new ButtonXY('Y', -d));
256 224 }
257   - var Xhome = new Button('H', 'X');
  225 + var Xhome = new Button("Home X", [ "G28 X0" ]);
258 226 Xhome.points.push(new Point(11 , 8));
259 227 Xhome.points.push(new Point(11 + 47, 8));
260 228 Xhome.points.push(new Point(11 + 47, 8 + 9));
@@ -263,7 +231,7 @@ function JogXY(canvas) {
263 231 Xhome.points.push(new Point(11 , 8 + 47));
264 232 this.buttons.push(Xhome);
265 233
266   - var Yhome = new Button('H', 'Y');
  234 + var Yhome = new Button("Home Y", [ "G28 Y0" ]);
267 235 Yhome.points.push(new Point(235 , 8));
268 236 Yhome.points.push(new Point(235 - 47, 8));
269 237 Yhome.points.push(new Point(235 - 47, 8 + 9));
@@ -272,7 +240,7 @@ function JogXY(canvas) {
272 240 Yhome.points.push(new Point(235 , 8 + 47));
273 241 this.buttons.push(Yhome);
274 242
275   - var Zhome = new Button('H', 'Z');
  243 + var Zhome = new Button("Home Z", [ "G28 Z0" ]);
276 244 Zhome.points.push(new Point(236 , 232));
277 245 Zhome.points.push(new Point(236 - 47, 232));
278 246 Zhome.points.push(new Point(236 - 47, 232 - 9));
@@ -281,7 +249,7 @@ function JogXY(canvas) {
281 249 Zhome.points.push(new Point(236 , 232 - 47));
282 250 this.buttons.push(Zhome);
283 251
284   - var Allhome = new Button('H', 'A');
  252 + var Allhome = new Button("Home All", [ "G28 X0 Y0 Z0" ]);
285 253 Allhome.points.push(new Point(11 , 232));
286 254 Allhome.points.push(new Point(11 + 47, 232));
287 255 Allhome.points.push(new Point(11 + 47, 232 - 9));
@@ -295,12 +263,10 @@ function JogXY(canvas) {
295 263 * Z and E jog buttons
296 264 */
297 265
298   -// ButtonZE.Inherits(Button);
299 266 ButtonZE.prototype = new Button();
300 267 ButtonZE.prototype.constructor = ButtonZE;
301 268 function ButtonZE(axis, length, x1, y1, x2, y2) {
302   -// this.Inherits(Button, axis, length);
303   - Button.call(this, axis, length);
  269 + Button.call(this, axis + length, [ "G91", "G1 " + axis + length, "G90" ]);
304 270
305 271 this.points.push(new Point(x1, y1));
306 272 this.points.push(new Point(x2, y1));
@@ -308,7 +274,6 @@ function ButtonZE(axis, length, x1, y1, x2, y2) {
308 274 this.points.push(new Point(x1, y2));
309 275 }
310 276
311   -// ButtonZ.Inherits(ButtonZE);
312 277 ButtonZ.prototype = new ButtonZE();
313 278 ButtonZ.prototype.constructor = ButtonZ;
314 279 function ButtonZ(axis, length) {
@@ -320,19 +285,14 @@ function ButtonZ(axis, length) {
320 285 var y1 = y[q];
321 286 var y2 = y[q + 1];
322 287
323   -// $('log').textContent += '[Z] d = ' + length + ' (10^' + q + ')\ty = ' + y1 + '-' + y2 + '\n';
324   -
325   -// this.Inherits(ButtonZE, axis, length, x1, y1, x2, y2);
326 288 ButtonZE.call(this, axis, length, x1, y1, x2, y2);
327 289 }
328 290
329   -// JogZ.Inherits(Jog);
330 291 JogZ.prototype = new Jog();
331 292 JogZ.prototype.constructor = JogZ;
332 293 function JogZ(canvas) {
333 294 var self = this, d;
334 295
335   -// this.Inherits(Jog, canvas);
336 296 Jog.call(this, canvas);
337 297
338 298 this.axis = 'Z';
@@ -343,7 +303,6 @@ function JogZ(canvas) {
343 303 }
344 304 }
345 305
346   -// ButtonE.Inherits(ButtonZE);
347 306 ButtonE.prototype = new ButtonZE();
348 307 function ButtonE(axis, length) {
349 308 var x1 = 12;
@@ -355,21 +314,14 @@ function ButtonE(axis, length) {
355 314 var y1 = y[q];
356 315 var y2 = y[q + 1];
357 316
358   -// var y1 = 119 + -1 * Math.sign(length) * q * 27;
359   -// var y2 = 119 + -1 * Math.sign(length) * q * 27 + 26;
360   -// $('log').textContent += '[E] d = ' + length + ':' + q + '\ty = ' + y1 + '-' + y2 + '\n';
361   -
362   -// this.Inherits(ButtonZE, axis, length, x1, y1, x2, y2);
363 317 ButtonZE.call(this, axis, length, x1, y1, x2, y2);
364 318 }
365 319
366   -// JogE.Inherits(Jog);
367 320 JogE.prototype = new Jog();
368 321 JogE.prototype.constructor = JogE;
369 322 function JogE(canvas, axis) {
370 323 var self = this, d;
371 324
372   -// this.Inherits(Jog, canvas);
373 325 Jog.call(this, canvas);
374 326
375 327 this.axis = 'E';

0 comments on commit 24c219d

Please sign in to comment.
Something went wrong with that request. Please try again.