},
- 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)
},
def __init__(self, ctrl):
self.ctrl = ctrl
- self.state = 'init'
self.vars = {}
self.stream = None
self.queue = deque()
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):
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)
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
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):
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)
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 = []
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):
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()
(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),