Fixed GCode starting after disconnect
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Sun, 4 Sep 2016 00:21:46 +0000 (17:21 -0700)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Sun, 4 Sep 2016 00:21:46 +0000 (17:21 -0700)
src/js/control-view.js
src/py/bbctrl/AVR.py
src/py/bbctrl/FileHandler.py
src/py/bbctrl/Web.py

index 7479a179909c190a6a2eb9c5d8226e2bf6a46e95..3337c295c161c6ca7e8087d99fe7bb4c3b184700 100644 (file)
@@ -133,29 +133,34 @@ module.exports = {
     },
 
 
-    home: function () {api.put('home').done(this.update)},
+    home: function () {api.put('home')},
 
 
     start_pause: function () {
       if (this.state.x == 'running') this.pause();
+
+      else if (this.state.x == 'stopping' || this.state.x == 'holding')
+        this.unpause();
+
       else this.start();
     },
 
 
-    start: function () {api.put('start').done(this.update)},
-    pause: function () {api.put('pause').done(this.update)},
-    optional_pause: function () {api.put('pause/optional').done(this.update)},
-    stop: function () {api.put('stop').done(this.update)},
-    step: function () {api.put('step').done(this.update)},
+    start: function () {api.put('start/' + this.file).done(this.update)},
+    pause: function () {api.put('pause')},
+    unpause: function () {api.put('unpause')},
+    optional_pause: function () {api.put('pause/optional')},
+    stop: function () {api.put('stop')},
+    step: function () {api.put('step')},
 
 
     override_feed: function () {
-      api.put('override/feed/' + this.feed_override).done(this.update)
+      api.put('override/feed/' + this.feed_override)
     },
 
 
     override_speed: function () {
-      api.put('override/speed/' + this.speed_override).done(this.update)
+      api.put('override/speed/' + this.speed_override)
     },
 
 
index 0f22bb377a61c5d526023957deee5e8177798a1c..4e9bc527a51912d35f52bb8ebb27e408e2f8b8ad 100644 (file)
@@ -32,7 +32,6 @@ class AVR():
     def __init__(self, ctrl):
         self.ctrl = ctrl
 
-        self.state = 'init'
         self.vars = {}
         self.stream = None
         self.queue = deque()
@@ -61,16 +60,18 @@ class AVR():
         self.report()
 
 
-    def _start_sending_gcode(self):
-        if self.state == 'init': raise Exception('No file loaded')
-        self.state = 'streaming'
+    def _start_sending_gcode(self, path):
+        if self.stream is not None:
+            raise Exception('Busy, cannot start new GCode file')
+
+        self.stream = bbctrl.GCodeStream(path)
         self.set_write(True)
 
 
     def _stop_sending_gcode(self):
-        if self.state != 'streaming': return
-        if self.stream is not None: self.stream.reset()
-        self.state = 'idle'
+        if self.stream is not None:
+            self.stream.reset()
+            self.stream = None
 
 
     def _i2c_command(self, cmd, word = None):
@@ -122,12 +123,12 @@ class AVR():
         if len(self.queue): self.load_next_command(self.queue.pop())
 
         # Load next GCode command, if running or paused
-        elif self.state == 'streaming':
+        elif self.stream is not None:
             cmd = self.stream.next()
 
             if cmd is None:
                 self.set_write(False)
-                self.state = 'idle'
+                self.stream = None
 
             else: self.load_next_command(cmd)
 
@@ -178,23 +179,15 @@ class AVR():
         self.set_write(True)
 
 
-    def open(self, path):
-        if self.state not in ['idle', 'init']:
-            raise Exception('Busy, cannot open new file')
-
-        self.stream = bbctrl.GCodeStream(path)
-        self.state = 'idle'
-
-
     def mdi(self, cmd):
-        if self.state == 'streaming':
+        if self.stream is not None:
             raise Exception('Busy, cannot queue MDI command')
 
         self.queue_command(cmd)
 
 
     def jog(self, axes):
-        if self.state == 'streaming': raise Exception('Busy, cannot jog')
+        if self.stream is not None: raise Exception('Busy, cannot jog')
 
         # TODO jogging via I2C
 
@@ -211,9 +204,12 @@ class AVR():
     def clear(self): self._i2c_command(I2C_CLEAR)
 
 
-    def start(self):
-        if self.state == 'idle': self._start_sending_gcode()
-        self._i2c_command(I2C_RUN)
+    def start(self, path):
+        if self.stream is not None: raise Exception('Busy, cannot start file')
+
+        if path:
+            self._start_sending_gcode(path)
+            self._i2c_command(I2C_RUN)
 
 
     def stop(self):
@@ -223,5 +219,6 @@ class AVR():
         self.queue_command('$resume')
 
     def pause(self): self._i2c_command(I2C_PAUSE)
+    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)
index 8f9704add6a0a2efbd009f515a9d38b847f46a54..c51eb23abe069348ffdacd0332bd45e78ac9e7a7 100644 (file)
@@ -21,15 +21,11 @@ class FileHandler(bbctrl.APIHandler):
         with open(path, 'wb') as f:
             f.write(gcode['body'])
 
-        self.ctrl.avr.open(path)
-
 
     def get(self, path):
         if path:
             with open('upload/' + path, 'r') as f:
                 self.write_json(f.read())
-
-            self.ctrl.avr.open(path)
             return
 
         files = []
index 436c02777785270ce338b8ceaed701b723f03cd5..f87d14b4f37d0216055ad6dac352a60c45aee3dd 100644 (file)
@@ -25,7 +25,7 @@ class HomeHandler(bbctrl.APIHandler):
 
 
 class StartHandler(bbctrl.APIHandler):
-    def put_ok(self): self.ctrl.avr.start()
+    def put_ok(self, path): self.ctrl.avr.start(path)
 
 
 class EStopHandler(bbctrl.APIHandler):
@@ -44,6 +44,10 @@ class PauseHandler(bbctrl.APIHandler):
     def put_ok(self): self.ctrl.avr.pause()
 
 
+class UnpauseHandler(bbctrl.APIHandler):
+    def put_ok(self): self.ctrl.avr.unpause()
+
+
 class OptionalPauseHandler(bbctrl.APIHandler):
     def put_ok(self): self.ctrl.avr.optional_pause()
 
@@ -98,11 +102,12 @@ class Web(tornado.web.Application):
             (r'/api/save', SaveHandler),
             (r'/api/file(/.+)?', bbctrl.FileHandler),
             (r'/api/home', HomeHandler),
-            (r'/api/start', StartHandler),
+            (r'/api/start(/.+)', StartHandler),
             (r'/api/estop', EStopHandler),
             (r'/api/clear', ClearHandler),
             (r'/api/stop', StopHandler),
             (r'/api/pause', PauseHandler),
+            (r'/api/unpause', UnpauseHandler),
             (r'/api/pause/optional', OptionalPauseHandler),
             (r'/api/step', StepHandler),
             (r'/api/override/feed/([\d.]+)', OverrideFeedHandler),