Show Line and hold reason, Highlight GCode line, Show GCode line numbers.
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Mon, 12 Sep 2016 06:18:42 +0000 (23:18 -0700)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Mon, 12 Sep 2016 06:18:42 +0000 (23:18 -0700)
src/jade/templates/control-view.jade
src/js/control-view.js
src/py/bbctrl/AVR.py
src/stylus/style.styl

index 3ba8b5ab01da4ec4fc362c50ea3128560d11838e..6862e54b15c9ff878cfb5ab482b8ad64faee162c 100644 (file)
@@ -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
index 1aba59010fbc02f8433e3bbb93fa95dc322f5591..4510c5150d1c9ee32860088b83b1cc710566cad8 100644 (file)
@@ -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 = '<ul>';
+
+          for (var i = 0; i < lines.length; i++)
+            // TODO escape HTML chars in lines
+            html += '<li id="gcode-line-' + i + '">' +
+            '<span>' + (i + 1) + '</span>' + lines[i] + '</li>';
+
+          html += '</ul>';
+
+          this.gcode = html;
           this.last_file = file;
+
+          Vue.nextTick(this.update_gcode_line);
         }.bind(this));
     },
 
index 3ee8ab66f7f60a391cd442136dcbcc90776bb6fe..b933fd8d23dc7b0da9028ae9c84b13c429b0cc24 100644 (file)
@@ -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):
index 5c27db64201e1e5357da4e30c22452bbca8a5224..dfd5ab026897e48ccc2b60b6b1e6f4e1d9f97f35 100644 (file)
@@ -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