Separate machine and settings units, settings units determinate default machine units
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Sun, 24 Jun 2018 23:12:53 +0000 (16:12 -0700)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Sun, 24 Jun 2018 23:12:53 +0000 (16:12 -0700)
17 files changed:
src/jade/index.jade
src/jade/templates/control-view.jade
src/jade/templates/gcode-view.jade [deleted file]
src/jade/templates/io-view.jade
src/jade/templates/motor-view.jade
src/jade/templates/settings-view.jade [new file with mode: 0644]
src/jade/templates/tool-view.jade
src/js/app.js
src/js/control-view.js
src/js/gcode-view.js [deleted file]
src/js/settings-view.js [new file with mode: 0644]
src/js/unit-value.js
src/py/bbctrl/MainLCDPage.py
src/py/bbctrl/Planner.py
src/py/bbctrl/State.py
src/resources/config-template.json
src/stylus/style.styl

index b7b10999ef710b4f42faad9726474544bb8ec577..7b6cbf6458c44be6ffd0a77e70a1f7936224a963 100644 (file)
@@ -60,15 +60,14 @@ html(lang="en")
         button.save.pure-button.button-success(:disabled="!modified",
           @click="save") Save
 
-        select.units(v-model="config.settings.units", @change="modified = true")
-          option(value="METRIC") Metric
-          option(value="IMPERIAL") Imperial
-
         .pure-menu
           ul.pure-menu-list
             li.pure-menu-heading
               a.pure-menu-link(href="#control") Control
 
+            li.pure-menu-heading
+              a.pure-menu-link(href="#settings") Settings
+
             li.pure-menu-heading
               a.pure-menu-link(href="#motor:0") Motors
 
@@ -81,9 +80,6 @@ html(lang="en")
             li.pure-menu-heading
               a.pure-menu-link(href="#io") I/O
 
-            li.pure-menu-heading
-              a.pure-menu-link(href="#gcode") Gcode
-
             li.pure-menu-heading
               a.pure-menu-link(href="#admin-general") Admin
 
index fd4a840f35742f61cf206a8f8c5edbe9d04b8076..1318ffc51d6850fee3a125e418d424a0562c39c5 100644 (file)
@@ -121,7 +121,10 @@ script#control-view-template(type="text/x-template")
         td
       tr(title="Currently active machine units")
         th Units
-        td {{state.imperial ? 'IMPERIAL' : 'METRIC'}}
+        td.mach_units
+          select(v-model="mach_units", :disabled="!can_mdi")
+            option(value="METRIC") METRIC
+            option(value="IMPERIAL") IMPERIAL
         td
       tr
         th Feed
@@ -191,8 +194,8 @@ script#control-view-template(type="text/x-template")
       input#tab6(type="radio", name="tabs", @click="load_video")
       label(for="tab6") Video
 
-      section#content1.tab-content
-        .toolbar
+      section#content1.tab-content.pure-form
+        .toolbar.pure-control-group
           button.pure-button(
             title="{{is_running ? 'Pause' : 'Start'}} program.",
             @click="start_pause", :disabled="!state.selected")
diff --git a/src/jade/templates/gcode-view.jade b/src/jade/templates/gcode-view.jade
deleted file mode 100644 (file)
index 730922d..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-//-/////////////////////////////////////////////////////////////////////////////
-//-                                                                           //
-//-              This file is part of the Buildbotics firmware.               //
-//-                                                                           //
-//-                Copyright (c) 2015 - 2018, Buildbotics LLC                 //
-//-                           All rights reserved.                            //
-//-                                                                           //
-//-   This file ("the software") is free software: you can redistribute it    //
-//-   and/or modify it under the terms of the GNU General Public License,     //
-//-    version 2 as published by the Free Software Foundation. You should     //
-//-    have received a copy of the GNU General Public License, version 2      //
-//-   along with the software. If not, see <http://www.gnu.org/licenses/>.    //
-//-                                                                           //
-//-   The software is distributed in the hope that it will be useful, but     //
-//-        WITHOUT ANY WARRANTY; without even the implied warranty of         //
-//-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      //
-//-             Lesser General Public License for more details.               //
-//-                                                                           //
-//-     You should have received a copy of the GNU Lesser General Public      //
-//-              License along with the software.  If not, see                //
-//-                     <http://www.gnu.org/licenses/>.                       //
-//-                                                                           //
-//-              For information regarding this software email:               //
-//-                "Joseph Coffland" <joseph@buildbotics.com>                 //
-//-                                                                           //
-//-/////////////////////////////////////////////////////////////////////////////
-
-script#gcode-view-template(type="text/x-template")
-  #gcode
-    h1 GCode Configuration
-
-    form.pure-form.pure-form-aligned
-      fieldset
-        templated-input(v-for="templ in template.gcode", :name="$key",
-          :model.sync="config.gcode[$key]", :template="templ")
index 980a973bd1168a6bcee774797dab02da4fd37d33..f0c81a3ee7203e7c63355294b982588b345ddc04 100644 (file)
@@ -29,14 +29,13 @@ script#io-view-template(type="text/x-template")
   #io
     h1 I/O Configuration
 
-    h2 Switches
-    form.pure-form.pure-form-aligned
+    .pure-form.pure-form-aligned
       fieldset
+        h2 Switches
         templated-input(v-for="templ in template.switches", :name="$key",
           :model.sync="config.switches[$key]", :template="templ")
 
-    h2 Outputs
-    form.pure-form.pure-form-aligned
       fieldset
+        h2 Outputs
         templated-input(v-for="templ in template.outputs", :name="$key",
           :model.sync="config.outputs[$key]", :template="templ")
index e1440b45084be52b682e1185ad80c03e01e8b575..6171570058ea917bd4b8abe1d97dec2fd82aed38 100644 (file)
@@ -29,7 +29,7 @@ script#motor-view-template(type="text/x-template")
   .motor(:class="{slave: is_slave}")
     h1 Motor {{index}} Configuration
 
-    form.pure-form.pure-form-aligned
+    .pure-form.pure-form-aligned
       fieldset(v-for="category in template.motors.template", :class="$key")
         h2 {{$key}}
 
diff --git a/src/jade/templates/settings-view.jade b/src/jade/templates/settings-view.jade
new file mode 100644 (file)
index 0000000..cd3444b
--- /dev/null
@@ -0,0 +1,41 @@
+//-                           All rights reserved.                            //
+//-                                                                           //
+//-   This file ("the software") is free software: you can redistribute it    //
+//-   and/or modify it under the terms of the GNU General Public License,     //
+//-    version 2 as published by the Free Software Foundation. You should     //
+//-    have received a copy of the GNU General Public License, version 2      //
+//-   along with the software. If not, see <http://www.gnu.org/licenses/>.    //
+//-                                                                           //
+//-   The software is distributed in the hope that it will be useful, but     //
+//-        WITHOUT ANY WARRANTY; without even the implied warranty of         //
+//-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      //
+//-             Lesser General Public License for more details.               //
+//-                                                                           //
+//-     You should have received a copy of the GNU Lesser General Public      //
+//-              License along with the software.  If not, see                //
+//-                     <http://www.gnu.org/licenses/>.                       //
+//-                                                                           //
+//-              For information regarding this software email:               //
+//-                "Joseph Coffland" <joseph@buildbotics.com>                 //
+//-                                                                           //
+//-/////////////////////////////////////////////////////////////////////////////
+
+script#settings-view-template(type="text/x-template")
+  #settings
+    h1 Settings
+
+    .pure-form.pure-form-aligned
+      fieldset
+        h2 Units
+        templated-input(name="units", :model.sync="config.settings.units",
+          :template="template.settings.units")
+
+        p
+          | Note, <tt>units</tt> sets both the machine default units and the
+          | units used in motor configuration.  GCode <tt>program-start</tt>,
+          | set below, may also change the default machine units.
+
+      fieldset
+        h2 GCode
+        templated-input(v-for="templ in template.gcode", :name="$key",
+          :model.sync="config.gcode[$key]", :template="templ")
index 6f33f1b3788c1b8f60c16308ff8b845681e35d81..661ceefcea122ea5a11896fe03e07520d5ae97d4 100644 (file)
@@ -29,31 +29,26 @@ script#tool-view-template(type="text/x-template")
   #tool
     h1 Tool Configuration
 
-    form.pure-form.pure-form-aligned
+    .pure-form.pure-form-aligned
       fieldset
         templated-input(v-for="templ in template.tool", :name="$key",
           :model.sync="config.tool[$key]", :template="templ",
           v-if="tool_type != 'DISABLED' || $key == 'tool-type'")
 
-    div(v-if="tool_type == 'PWM SPINDLE'")
-      h2 PWM Spindle
-      form.pure-form.pure-form-aligned
-        fieldset
-          templated-input(v-for="templ in template['pwm-spindle']",
-            :name="$key", :model.sync="config['pwm-spindle'][$key]",
-            :template="templ")
+      fieldset(v-if="tool_type == 'PWM SPINDLE'")
+        h2 PWM Spindle
+        templated-input(v-for="templ in template['pwm-spindle']",
+          :name="$key", :model.sync="config['pwm-spindle'][$key]",
+          :template="templ")
 
-    div(v-if="is_modbus")
-      h2 Modbus Configuration
-      form.pure-form.pure-form-aligned
-        fieldset
-          templated-input(v-for="templ in template['modbus-spindle']",
-            :name="$key", :model.sync="config['modbus-spindle'][$key]",
-            :template="templ", v-if="$key != 'regs'")
+      fieldset(v-if="is_modbus")
+        h2 Modbus Configuration
+        templated-input(v-for="templ in template['modbus-spindle']",
+          :name="$key", :model.sync="config['modbus-spindle'][$key]",
+          :template="templ", v-if="$key != 'regs'")
 
-    div(v-if="tool_type == 'VFD TEST'")
-      h2 Modbus Test
-      form.pure-form
+      fieldset(v-if="tool_type == 'VFD TEST'")
+        h2 Modbus Test
         table.modbus-regs
           tr
             th Address
@@ -68,9 +63,9 @@ script#tool-view-template(type="text/x-template")
               button.pure-button(@click="write") Write
             td.modbus-status {{modbus_status}}
 
-    div.modbus-program(v-if="is_modbus && this.tool_type != 'HUANYANG VFD'")
-      h2 Active Modbus Program
-      form.pure-form
+      fieldset.modbus-program(
+        v-if="is_modbus && this.tool_type != 'HUANYANG VFD'")
+        h2 Active Modbus Program
         table.modbus-regs.fixed-regs
           tr
             th Index
@@ -84,12 +79,11 @@ script#tool-view-template(type="text/x-template")
             td.reg-addr {{get_reg_addr(reg)}}
             td.reg-value {{get_reg_value(reg)}}
 
-      button.pure-button-secondary(@click="customize") Customize
-      button.pure-button-secondary(@click="clear") Clear
+        button.pure-button-secondary(@click="customize") Customize
+        button.pure-button-secondary(@click="clear") Clear
 
-    div(v-if="tool_type == 'CUSTOM MODBUS VFD'")
-      h2 Edit Modbus Program
-      form.pure-form
+      fieldset(v-if="tool_type == 'CUSTOM MODBUS VFD'")
+        h2 Edit Modbus Program
         table.modbus-regs
           tr
             th Index
index 76f9f615e9a08811ad75840daac00c5f1fba1cb2..0ca5e61da8ba5b0013a082ba14815b1258939329 100644 (file)
@@ -114,10 +114,10 @@ module.exports = new Vue({
     'estop': {template: '#estop-template'},
     'loading-view': {template: '<h1>Loading...</h1>'},
     'control-view': require('./control-view'),
+    'settings-view': require('./settings-view'),
     'motor-view': require('./motor-view'),
     'tool-view': require('./tool-view'),
     'io-view': require('./io-view'),
-    'gcode-view': require('./gcode-view'),
     'admin-general-view': require('./admin-general-view'),
     'admin-network-view': require('./admin-network-view'),
     'help-view': {template: '#help-view-template'},
index 6ff21a3b376da2d63faedb2e212a9b658ff0520b..ec4c5e75363493ff324d03ecb092b92de0e0d8d6 100644 (file)
@@ -48,6 +48,7 @@ module.exports = {
 
   data: function () {
     return {
+      mach_units: 'METRIC',
       mdi: '',
       files: [],
       axes: 'xyzabc',
@@ -71,6 +72,17 @@ module.exports = {
 
 
   watch: {
+    'state.imperial': function (imperial) {
+      this.mach_units = imperial ? 'IMPERIAL' : 'METRIC';
+    },
+
+
+    mach_units: function (units) {
+      if ((units == 'METRIC') != this.metric)
+        this.send(units == 'METRIC' ? 'G21' : 'G20');
+    },
+
+
     'state.line': function () {
       if (this.mach_state != 'HOMING')
         this.$broadcast('gcode-line', this.state.line);
@@ -82,7 +94,7 @@ module.exports = {
 
 
   computed: {
-    metric: function () {return this.$root.metric()},
+    metric: function () {return !this.state.imperial},
 
 
     mach_state: function () {
diff --git a/src/js/gcode-view.js b/src/js/gcode-view.js
deleted file mode 100644 (file)
index 9042c07..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/******************************************************************************\
-
-                 This file is part of the Buildbotics firmware.
-
-                   Copyright (c) 2015 - 2018, Buildbotics LLC
-                              All rights reserved.
-
-      This file ("the software") is free software: you can redistribute it
-      and/or modify it under the terms of the GNU General Public License,
-       version 2 as published by the Free Software Foundation. You should
-       have received a copy of the GNU General Public License, version 2
-      along with the software. If not, see <http://www.gnu.org/licenses/>.
-
-      The software is distributed in the hope that it will be useful, but
-           WITHOUT ANY WARRANTY; without even the implied warranty of
-       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-                Lesser General Public License for more details.
-
-        You should have received a copy of the GNU Lesser General Public
-                 License along with the software.  If not, see
-                        <http://www.gnu.org/licenses/>.
-
-                 For information regarding this software email:
-                   "Joseph Coffland" <joseph@buildbotics.com>
-
-\******************************************************************************/
-
-'use strict'
-
-
-module.exports = {
-  template: '#gcode-view-template',
-  props: ['config', 'template'],
-
-
-  events: {
-    'input-changed': function() {
-      this.$dispatch('config-changed');
-      return false;
-    }
-  }
-}
diff --git a/src/js/settings-view.js b/src/js/settings-view.js
new file mode 100644 (file)
index 0000000..599aea8
--- /dev/null
@@ -0,0 +1,42 @@
+/******************************************************************************\
+
+                 This file is part of the Buildbotics firmware.
+
+                   Copyright (c) 2015 - 2018, Buildbotics LLC
+                              All rights reserved.
+
+      This file ("the software") is free software: you can redistribute it
+      and/or modify it under the terms of the GNU General Public License,
+       version 2 as published by the Free Software Foundation. You should
+       have received a copy of the GNU General Public License, version 2
+      along with the software. If not, see <http://www.gnu.org/licenses/>.
+
+      The software is distributed in the hope that it will be useful, but
+           WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+                Lesser General Public License for more details.
+
+        You should have received a copy of the GNU Lesser General Public
+                 License along with the software.  If not, see
+                        <http://www.gnu.org/licenses/>.
+
+                 For information regarding this software email:
+                   "Joseph Coffland" <joseph@buildbotics.com>
+
+\******************************************************************************/
+
+'use strict'
+
+
+module.exports = {
+  template: '#settings-view-template',
+  props: ['config', 'template'],
+
+
+  events: {
+    'input-changed': function() {
+      this.$dispatch('config-changed');
+      return false;
+    }
+  }
+}
index a84a61cc51657cc77a92d8d7b43a181cdf4d61ae..d4d6ee00661469d4885ffc2f88afedd299f8ef29 100644 (file)
@@ -35,7 +35,7 @@ module.exports = {
 
 
   computed: {
-    metric: function () {return this.$root.metric()},
+    metric: function () {return !this.$root.state.imperial},
 
 
     text: function () {
index 1b14d5345742c52369744f83f13f6b38fa8b99f4..b55f9216a2c62b32c06512be21a97b66ef8db2a7 100644 (file)
@@ -48,12 +48,16 @@ class MainLCDPage(bbctrl.LCDPage):
 
         self.text('%-9s' % state.get('xx', ''), 0, 0)
 
+        metric = not state.get('imperial', False)
+        scale = 1 if metric else 25.4
+
         # Show enabled axes
         row = 0
         for axis in 'xyzabc':
             if state.is_axis_enabled(axis):
                 position = state.get(axis + 'p', 0)
                 position += state.get('offset_' + axis, 0)
+                position /= scale
                 self.text('% 10.3f%s' % (position, axis.upper()), 9, row)
                 row += 1
 
@@ -62,8 +66,7 @@ class MainLCDPage(bbctrl.LCDPage):
             row += 1
 
         # Show tool, units, feed and speed
-        units = 'INCH' if state.get('imperial', False) else 'MM'
-        self.text('%2uT' % state.get('tool', 0), 6, 1)
-        self.text('%-6s' % units,                0, 1)
-        self.text('%8uF' % state.get('feed', 0), 0, 2)
-        self.text('%8dS' % state.get('speed',0), 0, 3)
+        self.text('%2uT' % state.get('tool',  0),           6, 1)
+        self.text('%-6s' % 'MM' if metric else 'INCH',      0, 1)
+        self.text('%8uF' % (state.get('feed',  0) / scale), 0, 2)
+        self.text('%8dS' % state.get('speed', 0),           0, 3)
index fd9f01c523ec8c29974e77e9e842b68725efe147..fd824092c65ef613046d65ed3c0dc5dd1aec9ce8 100644 (file)
@@ -92,7 +92,9 @@ class Planner():
 
 
     def _get_config(self, mdi, with_limits):
+        metric = self.ctrl.state.get('metric', True)
         config = {
+            'default-units': 'METRIC' if metric else 'IMPERIAL',
             'max-vel':   self._get_config_vector('vm', 1000),
             'max-accel': self._get_config_vector('am', 1000000),
             'max-jerk':  self._get_config_vector('jm', 1000000),
index 2bee646292eba6d114683da349d5a6407ca2aef4..dcbd4a38f222157fc8fa53c11571ede8375aefcd 100644 (file)
@@ -46,7 +46,6 @@ class State(object):
         self.vars = {
             'line': -1,
             'tool': 0,
-            'units': 'METRIC',
             'feed': 0,
             'speed': 0,
         }
@@ -153,6 +152,11 @@ class State(object):
         # Indirectly configure mach via calls to config()
         self.ctrl.config.reload()
 
+        # Configure units
+        metric = self.ctrl.config.get('units') == 'METRIC'
+        self.set('metric', 1 if metric else 0)
+        self.set('imperial', 0 if metric else 1)
+
 
     def find_motor(self, axis):
         for motor in range(6):
index 93eabf589593b2788aeee7dfd8bd6d22a8ae2d5e..923d517f5e12b975794839bb46e2246d9ad404a7 100644 (file)
   "gcode": {
     "program-start": {
       "type": "text",
-      "default": "(Runs at program start)\nG21 (Metric units)\nG90 (Absolute distance mode)\nG17 (Select XY plane)\n"
+      "default": "(Runs at program start)\nG90 (Absolute distance mode)\nG17 (Select XY plane)\n"
     },
     "tool-change": {
       "type": "text",
index 41495dc5e9f7ff5af5a623423f633327b5c45f42..7d0ac76efe94a598a499b028de5754884d0113c5 100644 (file)
@@ -4,6 +4,11 @@ body
 [v-cloak]
   display none
 
+tt
+  color #000
+  background #eee
+  padding 2px
+
 .button-success:not([disabled])
   background-color #1cb841
 
@@ -114,7 +119,7 @@ span.unit
     top 50%
 
 #menu
-  .save, .units
+  .save
     display block
     margin 0.25em 0.6em
 
@@ -283,6 +288,17 @@ span.unit
     td:nth-child(3)
       text-align left
 
+    .mach_units
+      padding 0
+
+      select
+        width 100%
+        height 1.9em
+        background-color transparent
+        border 0
+        padding 3px
+        text-align right
+
   .info:nth-of-type(2)
     float left
     clear left