From f7e2ce6f322467d2adc3fd7903e2a5d80276a76b Mon Sep 17 00:00:00 2001 From: Joseph Coffland Date: Sun, 11 Sep 2016 23:18:42 -0700 Subject: [PATCH] Show Line and hold reason, Highlight GCode line, Show GCode line numbers. --- src/jade/templates/control-view.jade | 10 +++++++- src/js/control-view.js | 36 +++++++++++++++++++++++++++- src/py/bbctrl/AVR.py | 31 ++++++++++++++---------- src/stylus/style.styl | 17 +++++++++++++ 4 files changed, 80 insertions(+), 14 deletions(-) diff --git a/src/jade/templates/control-view.jade b/src/jade/templates/control-view.jade index 3ba8b5a..6862e54 100644 --- a/src/jade/templates/control-view.jade +++ b/src/jade/templates/control-view.jade @@ -29,6 +29,10 @@ script#control-view-template(type="text/x-template") th State td {{get_state()}} td + tr + th Reason + td {{state.pr}} + td tr th Feed td {{state.f || 0}} @@ -47,6 +51,10 @@ script#control-view-template(type="text/x-template") th Velocity td {{state.v || 0 | fixed 0}} td mm/min + tr + th Line + td {{state.ln || ''}} + td tr th Tool td {{state.t || 0}} @@ -125,7 +133,7 @@ script#control-view-template(type="text/x-template") option(v-for="file in files", :value="file") {{file}} .gcode(:class="{placeholder: !gcode}") - {{gcode || 'GCode displays here.'}} + {{{gcode || 'GCode displays here.'}}} section#content2.tab-content .mdi.pure-form diff --git a/src/js/control-view.js b/src/js/control-view.js index 1aba590..4510c51 100644 --- a/src/js/control-view.js +++ b/src/js/control-view.js @@ -33,6 +33,11 @@ module.exports = { }, + watch: { + 'state.ln': function () {this.update_gcode_line();} + }, + + events: { // TODO These should all be implemented via the API jog: function (axis, move) {this.send('g91 g0' + axis + move)} @@ -64,6 +69,23 @@ module.exports = { }, + update_gcode_line: function () { + if (typeof this.last_line != 'undefined') { + $('#gcode-line-' + this.last_line).removeClass('highlight'); + this.last_line = undefined; + } + + if (0 <= this.state.ln) { + var line = this.state.ln - 1; + $('#gcode-line-' + line) + .addClass('highlight')[0] + .scrollIntoView({behavior: 'smooth'}); + + this.last_line = line; + } + }, + + update: function () { api.get('file') .done(function (files) { @@ -119,8 +141,20 @@ module.exports = { api.get('file/' + file) .done(function (data) { - this.gcode = data; + var lines = data.split(/\r?\n/); + var html = ''; + + this.gcode = html; this.last_file = file; + + Vue.nextTick(this.update_gcode_line); }.bind(this)); }, diff --git a/src/py/bbctrl/AVR.py b/src/py/bbctrl/AVR.py index 3ee8ab6..b933fd8 100644 --- a/src/py/bbctrl/AVR.py +++ b/src/py/bbctrl/AVR.py @@ -107,7 +107,9 @@ class AVR(): self.i2c_bus = smbus.SMBus(self.ctrl.args.avr_port) continue - else: raise e + else: + log.error('I2C communication failed: %s' % e) + return def report(self): self._i2c_command(I2C_REPORT) @@ -170,6 +172,8 @@ class AVR(): except Exception as e: log.warning('%s: %s', e, data) + update = {} + # Parse incoming serial data into lines while True: i = self.in_buf.find('\n') @@ -183,22 +187,25 @@ class AVR(): except Exception as e: log.error('%s, data: %s', e, line) - return + continue - if 'firmware' in msg: - log.error('AVR rebooted') - self.stop(); - self.report() + update.update(msg) + log.debug(line) - if 'x' in msg and msg['x'] == 'ESTOPPED': - self._stop_sending_gcode() + if 'msg' in update: break - self.vars.update(msg) - self.ctrl.lcd.update(msg) - self.ctrl.web.broadcast(msg) + if update: + if 'firmware' in msg: + log.error('AVR rebooted') + self.stop(); + self.report() - log.debug(line) + if 'x' in msg and msg['x'] == 'ESTOPPED': + self._stop_sending_gcode() + self.vars.update(update) + self.ctrl.lcd.update(update) + self.ctrl.web.broadcast(update) def queue_command(self, cmd): diff --git a/src/stylus/style.styl b/src/stylus/style.styl index 5c27db6..dfd5ab0 100644 --- a/src/stylus/style.styl +++ b/src/stylus/style.styl @@ -300,6 +300,23 @@ body &.placeholder color #aaa + .gcode ul + margin 0 + padding 0 + list-style none + + li + span + display inline-block + min-width 3em + margin-right 1em + padding 0 0.25em + font-family courier + color #e5aa3d + + &.highlight + background-color #eaeaea + .mdi clear both white-space nowrap -- 2.27.0