From 56ccb080adcd854ad4a780fdf24d2e26eecdcffa Mon Sep 17 00:00:00 2001 From: Joseph Coffland Date: Sat, 3 Sep 2016 17:21:46 -0700 Subject: [PATCH] Fixed GCode starting after disconnect --- src/js/control-view.js | 21 +++++++++++------- src/py/bbctrl/AVR.py | 41 +++++++++++++++++------------------- src/py/bbctrl/FileHandler.py | 4 ---- src/py/bbctrl/Web.py | 9 ++++++-- 4 files changed, 39 insertions(+), 36 deletions(-) diff --git a/src/js/control-view.js b/src/js/control-view.js index 7479a17..3337c29 100644 --- a/src/js/control-view.js +++ b/src/js/control-view.js @@ -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) }, diff --git a/src/py/bbctrl/AVR.py b/src/py/bbctrl/AVR.py index 0f22bb3..4e9bc52 100644 --- a/src/py/bbctrl/AVR.py +++ b/src/py/bbctrl/AVR.py @@ -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) diff --git a/src/py/bbctrl/FileHandler.py b/src/py/bbctrl/FileHandler.py index 8f9704a..c51eb23 100644 --- a/src/py/bbctrl/FileHandler.py +++ b/src/py/bbctrl/FileHandler.py @@ -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 = [] diff --git a/src/py/bbctrl/Web.py b/src/py/bbctrl/Web.py index 436c027..f87d14b 100644 --- a/src/py/bbctrl/Web.py +++ b/src/py/bbctrl/Web.py @@ -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), -- 2.27.0