From 596451de2dbbbb66203e0954b1a90782dba70648 Mon Sep 17 00:00:00 2001 From: Joseph Coffland Date: Fri, 14 Jul 2017 22:31:50 -0700 Subject: [PATCH] Added support for new output configs --- src/jade/index.jade | 2 +- src/jade/templates/io-view.jade | 15 +++++++++++++ src/jade/templates/switches-view.jade | 8 ------- src/js/app.js | 2 +- src/js/{switches-view.js => io-view.js} | 20 +++++++++++++----- src/py/bbctrl/Config.py | 7 +++++++ src/resources/config-template.json | 28 +++++++++++++++++++++++-- src/stylus/style.styl | 2 +- 8 files changed, 66 insertions(+), 18 deletions(-) create mode 100644 src/jade/templates/io-view.jade delete mode 100644 src/jade/templates/switches-view.jade rename src/js/{switches-view.js => io-view.js} (58%) diff --git a/src/jade/index.jade b/src/jade/index.jade index 61f18d5..3de168c 100644 --- a/src/jade/index.jade +++ b/src/jade/index.jade @@ -47,7 +47,7 @@ html(lang="en") a.pure-menu-link(href="#spindle") Spindle li.pure-menu-heading - a.pure-menu-link(href="#switches") Switches + a.pure-menu-link(href="#io") I/O li.pure-menu-heading a.pure-menu-link(href="#gcode") Gcode diff --git a/src/jade/templates/io-view.jade b/src/jade/templates/io-view.jade new file mode 100644 index 0000000..b119082 --- /dev/null +++ b/src/jade/templates/io-view.jade @@ -0,0 +1,15 @@ +script#io-view-template(type="text/x-template") + #io + h1 I/O Configuration + + h2 Switches + form.pure-form.pure-form-aligned + fieldset + templated-input(v-for="templ in template.switches", :name="$key", + :model.sync="switches[$key]", :template="templ") + + h2 Outputs + form.pure-form.pure-form-aligned + fieldset + templated-input(v-for="templ in template.outputs", :name="$key", + :model.sync="outputs[$key]", :template="templ") diff --git a/src/jade/templates/switches-view.jade b/src/jade/templates/switches-view.jade deleted file mode 100644 index a8dc77b..0000000 --- a/src/jade/templates/switches-view.jade +++ /dev/null @@ -1,8 +0,0 @@ -script#switches-view-template(type="text/x-template") - #switches - h1 Switch Configuration - - form.pure-form.pure-form-aligned - fieldset - templated-input(v-for="templ in template.switches", :name="$key", - :model.sync="switches[$key]", :template="templ") diff --git a/src/js/app.js b/src/js/app.js index a4fc937..cdf6107 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -27,7 +27,7 @@ module.exports = new Vue({ 'control-view': require('./control-view'), 'motor-view': require('./motor-view'), 'spindle-view': require('./spindle-view'), - 'switches-view': require('./switches-view'), + 'io-view': require('./io-view'), 'gcode-view': require('./gcode-view'), 'admin-view': require('./admin-view') }, diff --git a/src/js/switches-view.js b/src/js/io-view.js similarity index 58% rename from src/js/switches-view.js rename to src/js/io-view.js index 6c0957a..1430f10 100644 --- a/src/js/switches-view.js +++ b/src/js/io-view.js @@ -2,13 +2,14 @@ module.exports = { - template: '#switches-view-template', + template: '#io-view-template', props: ['config', 'template'], data: function () { return { - switches: {} + switches: {}, + outputs: {} } }, @@ -21,14 +22,13 @@ module.exports = { }, - ready: function () { - this.update(); - }, + ready: function () {this.update()}, methods: { update: function () { Vue.nextTick(function () { + // Switches if (this.config.hasOwnProperty('switches')) this.switches = this.config.switches; else this.switches = {}; @@ -37,6 +37,16 @@ module.exports = { for (var key in template) if (!this.switches.hasOwnProperty(key)) this.$set('switches["' + key + '"]', template[key].default); + + // Outputs + if (this.config.hasOwnProperty('outputs')) + this.outputs = this.config.outputs; + else this.outputs = {}; + + var template = this.template.outputs; + for (var key in template) + if (!this.outputs.hasOwnProperty(key)) + this.$set('outputs["' + key + '"]', template[key].default); }.bind(this)); } } diff --git a/src/py/bbctrl/Config.py b/src/py/bbctrl/Config.py index 9cc26d3..d0e5c91 100644 --- a/src/py/bbctrl/Config.py +++ b/src/py/bbctrl/Config.py @@ -16,7 +16,9 @@ default_config = { {"axis": "A"}, ], "switches": {}, + "outputs": {}, "spindle": {}, + "gcode": {}, } @@ -41,6 +43,11 @@ class Config(object): try: config = self.load_path('config.json') config['version'] = self.version + + # Add missing sections + for key, value in default_config.items(): + if not key in config: config[key] = value + return config except Exception as e: diff --git a/src/resources/config-template.json b/src/resources/config-template.json index 45271f4..e5de560 100644 --- a/src/resources/config-template.json +++ b/src/resources/config-template.json @@ -232,17 +232,41 @@ "estop": { "type": "enum", "values": ["disabled", "normally-open", "normally-closed"], - "default": "disabled", + "default": "normally-open", "code": "et" }, "probe": { "type": "enum", "values": ["disabled", "normally-open", "normally-closed"], - "default": "disabled", + "default": "normally-open", "code": "pt" } }, + "outputs": { + "load-1": { + "type": "enum", + "values": ["disabled", "lo-hi", "hi-lo", "tri-lo", "tri-hi", "lo-tri", + "hi-tri"], + "default": "lo-hi", + "code": "1om" + }, + "load-2": { + "type": "enum", + "values": ["disabled", "lo-hi", "hi-lo", "tri-lo", "tri-hi", "lo-tri", + "hi-tri"], + "default": "lo-hi", + "code": "2om" + }, + "fault": { + "type": "enum", + "values": ["disabled", "lo-hi", "hi-lo", "tri-lo", "tri-hi", "lo-tri", + "hi-tri"], + "default": "lo-hi", + "code": "fom" + } + }, + "gcode": { "preamble": { "type": "text", diff --git a/src/stylus/style.styl b/src/stylus/style.styl index eed5df4..3915154 100644 --- a/src/stylus/style.styl +++ b/src/stylus/style.styl @@ -126,7 +126,7 @@ body 50% fill #ff9d00 -.estop +.header-content .estop width 130px transition 250ms -- 2.27.0