Fixed GCode EOF, Implemented axis zeroing
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Thu, 8 Sep 2016 07:29:56 +0000 (00:29 -0700)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Thu, 8 Sep 2016 07:29:56 +0000 (00:29 -0700)
src/js/axis-control.js
src/js/control-view.js
src/py/bbctrl/AVR.py
src/py/bbctrl/GCodeStream.py
src/py/bbctrl/Web.py

index 78434fe9e26af08ebd0040db9531dc3feeb60619..a8c2427312c7c26b3a83fdddefa5a27136279251 100644 (file)
@@ -9,16 +9,6 @@ module.exports = {
   methods: {
     jog: function (axis, move) {
       this.$dispatch('jog', this.axes[axis], move)
-    },
-
-
-    home: function (axis) {
-      this.$dispatch('home', this.axes[axis])
-    },
-
-
-    zero: function (axis) {
-      this.$dispatch('zero', this.axes[axis])
     }
   }
 }
index f958b0a1b3a924bccfb3246d34d5406bc81a6613..1aba59010fbc02f8433e3bbb93fa95dc322f5591 100644 (file)
@@ -35,9 +35,7 @@ module.exports = {
 
   events: {
     // TODO These should all be implemented via the API
-    jog: function (axis, move) {this.send('g91 g0' + axis + move)},
-    home: function (axis) {this.send('$home ' + axis)},
-    zero: function (axis) {this.send('$zero ' + axis)}
+    jog: function (axis, move) {this.send('g91 g0' + axis + move)}
   },
 
 
@@ -136,6 +134,11 @@ module.exports = {
     home: function () {api.put('home')},
 
 
+    zero: function (axis) {
+      api.put('zero' + (typeof axis == 'undefined' ? '' : '/' + axis));
+    },
+
+
     start_pause: function () {
       if (this.state.x == 'RUNNING') this.pause();
 
index cb4a7992285b4742688780effbf3000084a72992..3ee8ab66f7f60a391cd442136dcbcc90776bb6fe 100644 (file)
@@ -27,6 +27,7 @@ I2C_FLUSH          = 7
 I2C_REPORT         = 8
 I2C_HOME           = 9
 I2C_REBOOT         = 10
+I2C_ZERO           = 11
 
 
 class AVR():
@@ -60,6 +61,8 @@ class AVR():
             self.i2c_bus = None
             log.warning('Failed to open device: %s', e)
 
+        # Reset AVR communication
+        self.stop();
         self.report()
 
 
@@ -77,7 +80,7 @@ class AVR():
             self.stream = None
 
 
-    def _i2c_command(self, cmd, word = None):
+    def _i2c_command(self, cmd, byte = None, word = None):
         if self.i2c_bus is None: return
 
         log.info('I2C: %d' % cmd)
@@ -85,9 +88,13 @@ class AVR():
 
         while True:
             try:
-                if word is not None:
+                if byte is not None:
+                    self.i2c_bus.write_byte_data(self.i2c_addr, cmd, byte)
+
+                elif word is not None:
                     self.i2c_bus.write_word_data(self.i2c_addr, cmd, word)
-                self.i2c_bus.write_byte(self.i2c_addr, cmd)
+
+                else: self.i2c_bus.write_byte(self.i2c_addr, cmd)
                 break
 
             except IOError as e:
@@ -180,7 +187,7 @@ class AVR():
 
                 if 'firmware' in msg:
                     log.error('AVR rebooted')
-                    self._stop_sending_gcode()
+                    self.stop();
                     self.report()
 
                 if 'x' in msg and msg['x'] == 'ESTOPPED':
@@ -242,3 +249,4 @@ class AVR():
     def unpause(self): self._i2c_command(I2C_RUN)
     def optional_pause(self): self._i2c_command(I2C_OPTIONAL_PAUSE)
     def step(self): self._i2c_command(I2C_STEP)
+    def zero(self, axis = None): self._i2c_command(I2C_ZERO, byte = axis)
index d2d2e5fed01e16bee9d76cf3d2c1c254c4ed8163..5beb15b1ac2056fce48c6e8e8e5f5f29e2a34829 100644 (file)
@@ -39,7 +39,7 @@ class GCodeStream():
 
     def next(self):
         line = self.f.readline()
-        if line is None: return
+        if line is None or line == '': return
 
         # Remove comments
         line = self.comment1RE.sub('', line)
index f87d14b4f37d0216055ad6dac352a60c45aee3dd..8877cc3649c5eaba54751d7f2e17b98ac6ee653b 100644 (file)
@@ -56,6 +56,12 @@ class StepHandler(bbctrl.APIHandler):
     def put_ok(self): self.ctrl.avr.step()
 
 
+class ZeroHandler(bbctrl.APIHandler):
+    def put_ok(self, axis):
+        if axis is not None: axis = ord(axis[1:].lower())
+        self.ctrl.avr.zero(axis)
+
+
 class OverrideFeedHandler(bbctrl.APIHandler):
     def put_ok(self, value): self.ctrl.avr.override_feed(float(value))
 
@@ -110,6 +116,7 @@ class Web(tornado.web.Application):
             (r'/api/unpause', UnpauseHandler),
             (r'/api/pause/optional', OptionalPauseHandler),
             (r'/api/step', StepHandler),
+            (r'/api/zero(/[xyzabcXYZABC])?', ZeroHandler),
             (r'/api/override/feed/([\d.]+)', OverrideFeedHandler),
             (r'/api/override/speed/([\d.]+)', OverrideSpeedHandler),
             (r'/(.*)', tornado.web.StaticFileHandler,