From f22252011ae03f1c75b71d28b79c44f367a11aa3 Mon Sep 17 00:00:00 2001 From: David Carley Date: Sat, 9 Oct 2021 13:39:38 -0700 Subject: [PATCH 1/3] WIP: laser tool support --- src/js/tool-view.js | 98 ++++++++++++++++----------- src/pug/templates/templated-input.pug | 2 +- src/pug/templates/tool-view.pug | 7 +- src/resources/config-template.json | 22 ++++-- 4 files changed, 80 insertions(+), 49 deletions(-) diff --git a/src/js/tool-view.js b/src/js/tool-view.js index 958205d..9cd9835 100644 --- a/src/js/tool-view.js +++ b/src/js/tool-view.js @@ -30,12 +30,10 @@ var api = require('./api'); var modbus = require('./modbus.js'); - module.exports = { template: '#tool-view-template', props: ['config', 'template', 'state'], - data: function () { return { address: 0, @@ -43,74 +41,96 @@ module.exports = { } }, - - components: {'modbus-reg': require('./modbus-reg.js')}, - - - watch: { - 'state.mr': function () {this.value = this.state.mr} + components: { + 'modbus-reg': require('./modbus-reg.js') }, + watch: { + 'state.mr': function () { this.value = this.state.mr } + }, events: { - 'input-changed': function() { + 'input-changed': function () { this.$dispatch('config-changed'); return false; } }, - - ready: function () {this.value = this.state.mr}, - - - computed: { - regs_tmpl: function () {return this.template['modbus-spindle'].regs}, - tool_type: function () {return this.config.tool['tool-type'].toUpperCase()}, - - - is_modbus: function () { - return this.tool_type != 'DISABLED' && this.tool_type != 'PWM SPINDLE' - }, - - - modbus_status: function () {return modbus.status_to_string(this.state.mx)} + ready: function () { + this.value = this.state.mr; }, + computed: { + regs_tmpl: function () { + return this.template['modbus-spindle'].regs; + }, + + tool_type: function () { + return this.config.tool['tool-type'].toUpperCase(); + }, + + show_tool_settings: function() { + return !( + this.tool_type == "DISABLED" || + this.is_laser + ); + }, + + is_pwm_spindle: function() { + return this.tool_type == 'PWM SPINDLE'; + }, + + is_laser: function() { + return this.tool_type.includes("LASER"); + }, + + is_router: function() { + return this.tool_type.includes("ROUTER"); + }, + + is_modbus: function () { + return this.tool_type != 'DISABLED' && + !this.is_pwm_spindle && !this.is_laser && !this.is_router; + }, + + modbus_status: function () { + return modbus.status_to_string(this.state.mx); + } + }, methods: { get_reg_type: function (reg) { - return this.regs_tmpl.template['reg-type'].values[this.state[reg + 'vt']] + return this.regs_tmpl.template['reg-type'].values[this.state[reg + 'vt']]; }, + get_reg_addr: function (reg) { + return this.state[reg + 'va']; + }, - get_reg_addr: function (reg) {return this.state[reg + 'va']}, - get_reg_value: function (reg) {return this.state[reg + 'vv']}, - + get_reg_value: function (reg) { + return this.state[reg + 'vv']; + }, get_reg_fails: function (reg) { var fails = this.state[reg + 'vr'] return fails == 255 ? 'Max' : fails; }, - show_modbus_field: function (key) { return key != 'regs' && (key != 'multi-write' || this.tool_type == 'CUSTOM MODBUS VFD'); }, - read: function (e) { e.preventDefault(); - api.put('modbus/read', {address: this.address}); + api.put('modbus/read', { address: this.address }); }, - write: function (e) { e.preventDefault(); - api.put('modbus/write', {address: this.address, value: this.value}); + api.put('modbus/write', { address: this.address, value: this.value }); }, - customize: function (e) { e.preventDefault(); this.config.tool['tool-type'] = 'Custom Modbus VFD'; @@ -118,30 +138,28 @@ module.exports = { var regs = this.config['modbus-spindle'].regs; for (var i = 0; i < regs.length; i++) { var reg = this.regs_tmpl.index[i]; - regs[i]['reg-type'] = this.get_reg_type(reg); - regs[i]['reg-addr'] = this.get_reg_addr(reg); + regs[i]['reg-type'] = this.get_reg_type(reg); + regs[i]['reg-addr'] = this.get_reg_addr(reg); regs[i]['reg-value'] = this.get_reg_value(reg); } this.$dispatch('config-changed'); }, - clear: function (e) { e.preventDefault(); this.config.tool['tool-type'] = 'Custom Modbus VFD'; var regs = this.config['modbus-spindle'].regs; for (var i = 0; i < regs.length; i++) { - regs[i]['reg-type'] = 'disabled'; - regs[i]['reg-addr'] = 0; + regs[i]['reg-type'] = 'disabled'; + regs[i]['reg-addr'] = 0; regs[i]['reg-value'] = 0; } this.$dispatch('config-changed'); }, - reset_failures: function (e) { e.preventDefault(); var regs = this.config['modbus-spindle'].regs; diff --git a/src/pug/templates/templated-input.pug b/src/pug/templates/templated-input.pug index ff93c58..3be777c 100644 --- a/src/pug/templates/templated-input.pug +++ b/src/pug/templates/templated-input.pug @@ -31,7 +31,7 @@ script#templated-input-template(type="text/x-template") select(v-if="template.type == 'enum' || template.values", v-model="view", :name="name", @change="change") - option(v-for="opt in template.values", :value="opt") {{opt}} + option(v-for="opt in template.values", :value="opt" :disabled="opt === '-----' ? true : false") {{opt}} input(v-if="template.type == 'bool'", type="checkbox", v-model="view", :name="name", @change="change") diff --git a/src/pug/templates/tool-view.pug b/src/pug/templates/tool-view.pug index 4f331a4..05bc7b6 100644 --- a/src/pug/templates/tool-view.pug +++ b/src/pug/templates/tool-view.pug @@ -33,14 +33,13 @@ script#tool-view-template(type="text/x-template") 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'") + v-if="$key == 'tool-type' || show_tool_settings") - label.extra(slot="extra", - v-if="$key == 'tool-enable-mode' || $key == 'tool-direction-mode'") + label.extra(slot="extra", v-if="$key == 'tool-enable-mode' || $key == 'tool-direction-mode'") | Pin {{templ.pin}} io-indicator(:name="$key", :state="state") - fieldset(v-if="tool_type == 'PWM SPINDLE'") + fieldset(v-if="is_pwm_spindle") h2 PWM Spindle templated-input(v-for="templ in template['pwm-spindle']", :name="$key", :model.sync="config['pwm-spindle'][$key]", diff --git a/src/resources/config-template.json b/src/resources/config-template.json index 539ee3e..6cc1b69 100644 --- a/src/resources/config-template.json +++ b/src/resources/config-template.json @@ -29,6 +29,7 @@ "default": true } }, + "motors": { "type": "list", "index": "0123", @@ -250,10 +251,23 @@ "tool": { "tool-type": { "type": "enum", - "values": ["Disabled", "PWM Spindle", "Huanyang VFD", "Custom Modbus VFD", - "AC-Tech VFD", "Nowforever VFD", "Delta VFD015M21A (Beta)", - "YL600, YL620, YL620-A VFD (Beta)", "FR-D700 (Beta)", - "Sunfar E300 (Beta)", "OMRON MX2"], + "values": [ + "Disabled", + "-----", + "Router (Makita, etc)", + "J Tech Laser", + "PWM Spindle", + "-----", + "Huanyang VFD", + "Custom Modbus VFD", + "AC-Tech VFD", + "Nowforever VFD", + "Delta VFD015M21A (Beta)", + "YL600, YL620, YL620-A VFD (Beta)", + "FR-D700 (Beta)", + "Sunfar E300 (Beta)", + "OMRON MX2" + ], "default": "Disabled", "code": "st" }, From a35890e15a7a152cebf56194cf166dd376fd371a Mon Sep 17 00:00:00 2001 From: David Carley Date: Sun, 10 Oct 2021 18:42:14 -0700 Subject: [PATCH 2/3] Checkpoint --- Makefile | 2 +- src/js/tool-view.js | 125 +++++++++++++++++++++++--- src/pug/templates/templated-input.pug | 2 +- src/pug/templates/tool-view.pug | 15 +++- src/py/bbctrl/Config.py | 62 ++++++------- src/py/bbctrl/Planner.py | 2 +- src/py/bbctrl/State.py | 7 +- src/py/bbctrl/Web.py | 3 +- src/resources/config-template.json | 8 +- src/stylus/style.styl | 8 +- 10 files changed, 173 insertions(+), 61 deletions(-) diff --git a/Makefile b/Makefile index 1283b11..90eab8b 100644 --- a/Makefile +++ b/Makefile @@ -107,7 +107,7 @@ $(TARGET_DIR)/index.html: $(wildcard src/pug/templates/*) $(TARGET_DIR)/index.html: $(wildcard src/js/*) $(TARGET_DIR)/index.html: $(wildcard src/stylus/*) $(TARGET_DIR)/index.html: src/resources/config-template.json -$(TARGET_DIR)/index.html: $(wildcard src/resources/onefinity_*_defaults.json) +$(TARGET_DIR)/index.html: $(wildcard src/resources/onefinity*defaults.json) $(TARGET_DIR)/%.html: src/pug/%.pug node_modules @mkdir -p $(shell dirname $@) diff --git a/src/js/tool-view.js b/src/js/tool-view.js index 9cd9835..c214e22 100644 --- a/src/js/tool-view.js +++ b/src/js/tool-view.js @@ -37,7 +37,78 @@ module.exports = { data: function () { return { address: 0, - value: 0 + value: 0, + toolList: [ + { + id: "disabled", + name: "Disabled" + }, + { + id: "router", + type: "PWM Spindle", + name: "Router (Makita, etc)" + }, + { + id: "laser", + type: "PWM Spindle", + name: "Laser (J Tech, etc)" + }, + { + id: "pwm", + name: "PWM Spindle" + }, + { + id: "unsupported-separator", + name: "Unsupported Tools", + disabled: true, + unsupported: true + }, + { + id: "huanyang-vfd", + name: "Huanyang VFD", + unsupported: true + }, + { + id: "custom-modbus-vfd", + name: "Custom Modbus VFD", + unsupported: true + }, + { + id: "ac-tech-vfd", + name: "AC-Tech VFD", + unsupported: true + }, + { + id: "nowforever-vfd", + name: "Nowforever VFD", + unsupported: true + }, + { + id: "delta-vfd", + name: "Delta VFD015M21A (Beta)", + unsupported: true + }, + { + id: "yl600-vfd", + name: "YL600, YL620, YL620-A VFD (Beta)", + unsupported: true + }, + { + id: "fr-d700-vfd", + name: "FR-D700 (Beta)", + unsupported: true + }, + { + id: "sunfar-e300-vfd", + name: "Sunfar E300 (Beta)", + unsupported: true + }, + { + id: "omron-mx2-vfd", + name: "OMRON MX2", + unsupported: true + } + ] } }, @@ -69,23 +140,20 @@ module.exports = { return this.config.tool['tool-type'].toUpperCase(); }, - show_tool_settings: function() { - return !( - this.tool_type == "DISABLED" || - this.is_laser - ); + selected_tool: function() { + return this.config.tool['selected-tool'].toUpperCase(); }, - is_pwm_spindle: function() { - return this.tool_type == 'PWM SPINDLE'; + is_pwm_spindle: function () { + return this.selected_tool == 'PWM'; }, - is_laser: function() { - return this.tool_type.includes("LASER"); + is_laser: function () { + return this.selected_tool.includes("LASER"); }, - is_router: function() { - return this.tool_type.includes("ROUTER"); + is_router: function () { + return this.selected_tool.includes("ROUTER"); }, is_modbus: function () { @@ -99,6 +167,39 @@ module.exports = { }, methods: { + change_selected_tool: function(...args) { + const tool = this.toolList.find(tool => tool.id == this.config.tool['selected-tool']); + this.config.tool["tool-type"] = tool.type || tool.name; + + console.log(this.config.tool["tool-type"]); + + this.$dispatch("config-changed"); + }, + + show_tool_settings: function (key) { + switch (true) { + case key === "tool-type": + case key === "selected-tool": + return false; + + case this.selected_tool === "DISABLED": + case this.selected_tool.includes("LASER"): + return false; + + case this.selected_tool.includes("ROUTER"): + switch (key) { + case "tool-enable-mode": + return true; + + default: + return false; + } + + default: + return true; + } + }, + get_reg_type: function (reg) { return this.regs_tmpl.template['reg-type'].values[this.state[reg + 'vt']]; }, diff --git a/src/pug/templates/templated-input.pug b/src/pug/templates/templated-input.pug index 3be777c..c4c48ce 100644 --- a/src/pug/templates/templated-input.pug +++ b/src/pug/templates/templated-input.pug @@ -31,7 +31,7 @@ script#templated-input-template(type="text/x-template") select(v-if="template.type == 'enum' || template.values", v-model="view", :name="name", @change="change") - option(v-for="opt in template.values", :value="opt" :disabled="opt === '-----' ? true : false") {{opt}} + option(v-for="opt in template.values", track-by="$index", :value="opt" :disabled="opt === '-----' ? true : false") {{opt}} input(v-if="template.type == 'bool'", type="checkbox", v-model="view", :name="name", @change="change") diff --git a/src/pug/templates/tool-view.pug b/src/pug/templates/tool-view.pug index 05bc7b6..3eaab86 100644 --- a/src/pug/templates/tool-view.pug +++ b/src/pug/templates/tool-view.pug @@ -31,14 +31,23 @@ script#tool-view-template(type="text/x-template") .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="$key == 'tool-type' || show_tool_settings") + .pure-control-group + label(for="tool-type") tool-type + + select(v-model="config.tool['selected-tool']", name="tool-type", @change="change_selected_tool") + option(v-for="tool in toolList", :value="tool.id", :disabled="tool.disabled") {{tool.name}} + + templated-input(v-for="templ in template.tool", + :name="$key", v-if="show_tool_settings($key)" + :model.sync="config.tool[$key]", :template="templ") label.extra(slot="extra", v-if="$key == 'tool-enable-mode' || $key == 'tool-direction-mode'") | Pin {{templ.pin}} io-indicator(:name="$key", :state="state") + div(v-if="is_laser") + label Laser support is pre-configured, there are no user-adjustable settings. + fieldset(v-if="is_pwm_spindle") h2 PWM Spindle templated-input(v-for="templ in template['pwm-spindle']", diff --git a/src/py/bbctrl/Config.py b/src/py/bbctrl/Config.py index f9f283d..ee7960b 100644 --- a/src/py/bbctrl/Config.py +++ b/src/py/bbctrl/Config.py @@ -28,8 +28,6 @@ import os import json import pkg_resources -import subprocess -import copy from pkg_resources import Requirement, resource_filename @@ -55,14 +53,6 @@ class Config(object): except Exception: self.log.exception('Internal error: Failed to load config template') - def get(self, name, default = None): - return self.values.get(name, default) - - - def get_index(self, name, index, default = None): - return self.values.get(name, {}).get(str(index), None) - - def load(self): path = self.ctrl.get_path('config.json') @@ -72,7 +62,7 @@ class Config(object): else: config = {'version': self.version} try: - self.upgrade(config) + self._upgrade(config) except Exception: self.log.exception('Internal error: Failed to upgrade config') except Exception as e: @@ -83,6 +73,33 @@ class Config(object): return config + def reload(self): + self._update(self.load(), True) + + + def get(self, name, default = None): + return self.values.get(name, default) + + + def save(self, config): + self._upgrade(config) + self._update(config, False) + + with open(self.ctrl.get_path('config.json'), 'w') as f: + json.dump(config, f, indent=2) + + os.sync() + + self.ctrl.preplanner.invalidate_all() + self.log.info('Saved') + + + def reset(self): + if os.path.exists('config.json'): os.unlink('config.json') + self.reload() + self.ctrl.preplanner.invalidate_all() + + def _valid_value(self, template, value): type = template['type'] @@ -136,7 +153,7 @@ class Config(object): self.__defaults(conf, name, tmpl) - def upgrade(self, config): + def _upgrade(self, config): version = config['version'] version = version.split('b')[0] # Strip off any "beta" suffix version = tuple(map(int, version.split('.'))) # Break it into a tuple of integers @@ -171,24 +188,6 @@ class Config(object): config['version'] = self.version.split('b')[0] config['full_version'] = self.version - def save(self, config): - self.upgrade(config) - self._update(config, False) - - with open(self.ctrl.get_path('config.json'), 'w') as f: - json.dump(config, f, indent=2) - - os.sync() - - self.ctrl.preplanner.invalidate_all() - self.log.info('Saved') - - - def reset(self): - if os.path.exists('config.json'): os.unlink('config.json') - self.reload() - self.ctrl.preplanner.invalidate_all() - def _encode(self, name, index, config, tmpl, with_defaults): # Handle category @@ -238,6 +237,3 @@ class Config(object): for name, tmpl in self.template.items(): conf = config.get(name, None) self._encode(name, '', conf, tmpl, with_defaults) - - - def reload(self): self._update(self.load(), True) diff --git a/src/py/bbctrl/Planner.py b/src/py/bbctrl/Planner.py index e1efb08..d684fb8 100644 --- a/src/py/bbctrl/Planner.py +++ b/src/py/bbctrl/Planner.py @@ -96,7 +96,7 @@ class Planner(): 'max-merge-error': deviation, 'max-arc-error': deviation / 10, 'junction-accel': config.get('junction-accel'), - } + } # We place an upper limit of 1000 km/min^3 on jerk for MDI movements if mdi: diff --git a/src/py/bbctrl/State.py b/src/py/bbctrl/State.py index 3cb17e7..e4c4212 100644 --- a/src/py/bbctrl/State.py +++ b/src/py/bbctrl/State.py @@ -93,16 +93,15 @@ class State(object): observer.start() - #def is_metric(self): return self.get('units', 'METRIC') == 'METRIC' - def init(self): # Init machine units metric = self.ctrl.config.get('units', 'METRIC').upper() == 'METRIC' self.log.info('INIT Metric %d' % metric) if not 'metric' in self.vars: self.set('metric', metric) if not 'imperial' in self.vars: self.set('imperial', not metric) - #Bit diameter for probing - diameter = self.ctrl.config.get('probe-diameter',6.35) + + # Bit diameter for probing + diameter = self.ctrl.config.get('probe-diameter', 6.35) self.log.info('INIT Diameter %f' % diameter) self.set('bitDiameter',diameter) diff --git a/src/py/bbctrl/Web.py b/src/py/bbctrl/Web.py index d5a1290..17d6b8a 100644 --- a/src/py/bbctrl/Web.py +++ b/src/py/bbctrl/Web.py @@ -225,7 +225,8 @@ class PasswordHandler(bbctrl.APIHandler): class ConfigLoadHandler(bbctrl.APIHandler): - def get(self): self.write_json(self.get_ctrl().config.load()) + def get(self): + self.write_json(self.get_ctrl().config.load()) class ConfigDownloadHandler(bbctrl.APIHandler): diff --git a/src/resources/config-template.json b/src/resources/config-template.json index 6cc1b69..a39ddfd 100644 --- a/src/resources/config-template.json +++ b/src/resources/config-template.json @@ -249,15 +249,15 @@ }, "tool": { + "selected-tool": { + "type": "string", + "default": "disabled" + }, "tool-type": { "type": "enum", "values": [ "Disabled", - "-----", - "Router (Makita, etc)", - "J Tech Laser", "PWM Spindle", - "-----", "Huanyang VFD", "Custom Modbus VFD", "AC-Tech VFD", diff --git a/src/stylus/style.styl b/src/stylus/style.styl index 7acd5e1..2ded9ff 100644 --- a/src/stylus/style.styl +++ b/src/stylus/style.styl @@ -223,7 +223,7 @@ span.unit height 12em > select, > input:not([type=checkbox]) - min-width 200px + min-width 300px > tt min-width 15.25em @@ -1009,3 +1009,9 @@ tt.save label font-size 16pt align-self center + +.pure-form-aligned .pure-control-group label:not(.extra) + width 12em + +.pure-form-aligned .pure-control-group label.extra + width 8em From e28a0ab2d44b2e144b159c9d87836437960c9306 Mon Sep 17 00:00:00 2001 From: David Carley Date: Sun, 10 Oct 2021 19:57:43 -0700 Subject: [PATCH 3/3] Save per-tool settings --- src/js/app.js | 13 + src/js/tool-view.js | 66 +++--- src/pug/templates/tool-view.pug | 3 - src/py/bbctrl/Config.py | 5 + src/resources/onefinity_defaults.json | 329 +++++++++++++++----------- 5 files changed, 245 insertions(+), 171 deletions(-) diff --git a/src/js/app.js b/src/js/app.js index b5d8a18..8177d48 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -448,6 +448,19 @@ module.exports = new Vue({ }, save: function () { + const selected_tool = this.config.tool['selected-tool']; + const saveModbus = selected_tool !== "pwm" && + selected_tool !== "laser" && + selected_tool !== "router"; + const settings = { + ['tool']: { ...this.config.tool }, + ['pwm-spindle']: { ...this.config['pwm-spindle'] }, + ['modbus-spindle']: saveModbus ? { ...this.config['modbus-spindle'] } : undefined + } + delete settings.tool['tool-type']; + + this.config['selected-tool-settings'][selected_tool] = settings; + api.put('config/save', this.config).done(function (data) { this.modified = false; }.bind(this)).fail(function (error) { diff --git a/src/js/tool-view.js b/src/js/tool-view.js index c214e22..e4bc390 100644 --- a/src/js/tool-view.js +++ b/src/js/tool-view.js @@ -27,8 +27,9 @@ 'use strict'; -var api = require('./api'); -var modbus = require('./modbus.js'); +const api = require('./api'); +const modbus = require('./modbus.js'); +const merge = require("lodash.merge"); module.exports = { template: '#tool-view-template', @@ -123,8 +124,9 @@ module.exports = { events: { 'input-changed': function () { this.$dispatch('config-changed'); + return false; - } + }, }, ready: function () { @@ -140,25 +142,25 @@ module.exports = { return this.config.tool['tool-type'].toUpperCase(); }, - selected_tool: function() { - return this.config.tool['selected-tool'].toUpperCase(); + selected_tool: function () { + return this.config.tool['selected-tool']; }, is_pwm_spindle: function () { - return this.selected_tool == 'PWM'; - }, - - is_laser: function () { - return this.selected_tool.includes("LASER"); - }, - - is_router: function () { - return this.selected_tool.includes("ROUTER"); + return this.selected_tool == 'pwm'; }, is_modbus: function () { - return this.tool_type != 'DISABLED' && - !this.is_pwm_spindle && !this.is_laser && !this.is_router; + switch (this.selected_tool) { + case "disabled": + case "laser": + case "router": + case "pwm": + return false; + + default: + return true; + } }, modbus_status: function () { @@ -167,12 +169,16 @@ module.exports = { }, methods: { - change_selected_tool: function(...args) { + change_selected_tool: function () { + const selectedToolSettings = this.config['selected-tool-settings'] || {}; + const settings = selectedToolSettings[this.selected_tool] || {}; + this.config.tool = merge({}, this.config.tool, settings['tool']); + this.config['pwm-spindle'] = merge({}, this.config['pwm-spindle'], settings['pwm-spindle']); + this.config['modbus-spindle'] = merge({}, this.config['modbus-spindle'], settings['modbus-spindle']); + const tool = this.toolList.find(tool => tool.id == this.config.tool['selected-tool']); this.config.tool["tool-type"] = tool.type || tool.name; - console.log(this.config.tool["tool-type"]); - this.$dispatch("config-changed"); }, @@ -182,11 +188,11 @@ module.exports = { case key === "selected-tool": return false; - case this.selected_tool === "DISABLED": - case this.selected_tool.includes("LASER"): + case this.selected_tool === "disabled": return false; - case this.selected_tool.includes("ROUTER"): + case this.selected_tool === "laser": + case this.selected_tool === "router": switch (key) { case "tool-enable-mode": return true; @@ -213,7 +219,7 @@ module.exports = { }, get_reg_fails: function (reg) { - var fails = this.state[reg + 'vr'] + const fails = this.state[reg + 'vr'] return fails == 255 ? 'Max' : fails; }, @@ -236,9 +242,9 @@ module.exports = { e.preventDefault(); this.config.tool['tool-type'] = 'Custom Modbus VFD'; - var regs = this.config['modbus-spindle'].regs; - for (var i = 0; i < regs.length; i++) { - var reg = this.regs_tmpl.index[i]; + const regs = this.config['modbus-spindle'].regs; + for (let i = 0; i < regs.length; i++) { + const reg = this.regs_tmpl.index[i]; regs[i]['reg-type'] = this.get_reg_type(reg); regs[i]['reg-addr'] = this.get_reg_addr(reg); regs[i]['reg-value'] = this.get_reg_value(reg); @@ -251,8 +257,8 @@ module.exports = { e.preventDefault(); this.config.tool['tool-type'] = 'Custom Modbus VFD'; - var regs = this.config['modbus-spindle'].regs; - for (var i = 0; i < regs.length; i++) { + const regs = this.config['modbus-spindle'].regs; + for (let i = 0; i < regs.length; i++) { regs[i]['reg-type'] = 'disabled'; regs[i]['reg-addr'] = 0; regs[i]['reg-value'] = 0; @@ -263,8 +269,8 @@ module.exports = { reset_failures: function (e) { e.preventDefault(); - var regs = this.config['modbus-spindle'].regs; - for (var reg = 0; reg < regs.length; reg++) + const regs = this.config['modbus-spindle'].regs; + for (let reg = 0; reg < regs.length; reg++) this.$dispatch('send', '\$' + reg + 'vr=0'); } } diff --git a/src/pug/templates/tool-view.pug b/src/pug/templates/tool-view.pug index 3eaab86..c5e442a 100644 --- a/src/pug/templates/tool-view.pug +++ b/src/pug/templates/tool-view.pug @@ -45,9 +45,6 @@ script#tool-view-template(type="text/x-template") | Pin {{templ.pin}} io-indicator(:name="$key", :state="state") - div(v-if="is_laser") - label Laser support is pre-configured, there are no user-adjustable settings. - fieldset(v-if="is_pwm_spindle") h2 PWM Spindle templated-input(v-for="templ in template['pwm-spindle']", diff --git a/src/py/bbctrl/Config.py b/src/py/bbctrl/Config.py index ee7960b..2a16b56 100644 --- a/src/py/bbctrl/Config.py +++ b/src/py/bbctrl/Config.py @@ -185,6 +185,11 @@ class Config(object): config['settings']['max-deviation'] = 0.05 config['settings']['junction-accel'] = 200000 + if version < (1, 0, 9): + with open(get_resource('http/onefinity_defaults.json'), 'r', encoding = 'utf-8') as f: + defaults = json.load(f) + config['selected-tool-settings'] = defaults['selected-tool-settings']; + config['version'] = self.version.split('b')[0] config['full_version'] = self.version diff --git a/src/resources/onefinity_defaults.json b/src/resources/onefinity_defaults.json index 76883f3..07e2fe2 100644 --- a/src/resources/onefinity_defaults.json +++ b/src/resources/onefinity_defaults.json @@ -1,4 +1,11 @@ { + "version": "1.0.9", + "settings": { + "junction-accel": 200000, + "max-deviation": 0.05, + "units": "METRIC", + "probing-prompts": true + }, "tool": { "tool-reversed": false, "tool-enable-mode": "disabled", @@ -7,138 +14,14 @@ "min-spin": 0, "max-spin": 255 }, - "switches": { - "switch-lockout": 250, - "estop": "disabled", - "switch-debounce": 5, - "probe": "normally-open" + "pwm-spindle": { + "pwm-min-duty": 1, + "pwm-inverted": false, + "pwm-max-duty": 99.99, + "pwm-freq": 1000, + "dynamic-power": true, + "rapid-auto-off": true }, - "probe": { - "probe-diameter": 6.35, - "probe-ydim": 53.975, - "probe-slow-seek": 25, - "probe-fast-seek": 75, - "probe-zdim": 15.4, - "probe-xdim": 53.975 - }, - "version": "1.0.9", - "outputs": { - "load-1": "disabled", - "fault": "disabled", - "load-2": "disabled" - }, - "settings": { - "junction-accel": 200000, - "max-deviation": 0.05, - "units": "METRIC", - "probing-prompts": true - }, - "motors": [ - { - "latch-velocity": 0.1, - "max-accel": 750, - "max-velocity": 10, - "search-velocity": 1.688, - "travel-per-rev": 10, - "idle-current": 1, - "drive-current": 2.8, - "latch-backoff": 5, - "enabled": true, - "homing-mode": "stall-min", - "reverse": false, - "stall-microstep": 8, - "min-soft-limit": 0, - "max-switch": "disabled", - "step-angle": 1.8, - "stall-current": 1, - "stall-sample-time": 200, - "microsteps": 16, - "stall-volts": 2, - "axis": "X", - "min-switch": "disabled", - "max-jerk": 1000, - "max-soft-limit": 0, - "zero-backoff": 1.5 - }, - { - "latch-velocity": 0.1, - "max-accel": 750, - "max-velocity": 10, - "search-velocity": 1.688, - "travel-per-rev": 10, - "idle-current": 1, - "drive-current": 2.8, - "latch-backoff": 5, - "enabled": true, - "homing-mode": "stall-min", - "reverse": false, - "stall-microstep": 8, - "min-soft-limit": 0, - "max-switch": "disabled", - "step-angle": 1.8, - "stall-current": 1, - "stall-sample-time": 200, - "microsteps": 16, - "stall-volts": 2, - "axis": "Y", - "min-switch": "disabled", - "max-jerk": 1000, - "max-soft-limit": 0, - "zero-backoff": 1.5 - }, - { - "latch-velocity": 0.1, - "max-accel": 750, - "max-velocity": 10, - "search-velocity": 1.688, - "travel-per-rev": 10, - "idle-current": 1, - "drive-current": 2.8, - "latch-backoff": 5, - "enabled": true, - "homing-mode": "stall-min", - "reverse": false, - "stall-microstep": 8, - "min-soft-limit": 0, - "max-switch": "disabled", - "step-angle": 1.8, - "stall-current": 1, - "stall-sample-time": 200, - "microsteps": 16, - "stall-volts": 2, - "axis": "Y", - "min-switch": "disabled", - "max-jerk": 1000, - "max-soft-limit": 0, - "zero-backoff": 1.5 - }, - { - "latch-velocity": 0.1, - "max-accel": 750, - "max-velocity": 3, - "search-velocity": 0.675, - "travel-per-rev": 4, - "idle-current": 1, - "drive-current": 2.8, - "latch-backoff": 5, - "enabled": true, - "homing-mode": "stall-max", - "reverse": true, - "stall-microstep": 8, - "min-soft-limit": -133, - "max-switch": "disabled", - "step-angle": 1.8, - "stall-current": 1, - "stall-sample-time": 200, - "microsteps": 16, - "stall-volts": 2, - "axis": "Z", - "min-switch": "disabled", - "max-jerk": 1000, - "max-soft-limit": 0, - "zero-backoff": 1 - } - ], "modbus-spindle": { "baud": "9600", "multi-write": false, @@ -307,14 +190,184 @@ "bus-id": "1", "parity": "None" }, - "pwm-spindle": { - "pwm-min-duty": 1, - "pwm-inverted": false, - "pwm-max-duty": 99.99, - "pwm-freq": 1000, - "dynamic-power": true, - "rapid-auto-off": true + "selected-tool-settings": { + "laser": { + "tool": { + "tool-reversed": false, + "tool-enable-mode": "disabled", + "tool-direction-mode": "disabled", + "min-spin": 0, + "max-spin": 1000 + }, + "pwm-spindle": { + "pwm-min-duty": 1, + "pwm-inverted": false, + "pwm-max-duty": 99.99, + "pwm-freq": 1000, + "dynamic-power": true, + "rapid-auto-off": true + } + }, + "router": { + "tool": { + "tool-reversed": false, + "tool-enable-mode": "disabled", + "tool-direction-mode": "disabled", + "min-spin": 0, + "max-spin": 255 + }, + "pwm-spindle": { + "pwm-min-duty": 1, + "pwm-inverted": false, + "pwm-max-duty": 99.99, + "pwm-freq": 1000, + "dynamic-power": false, + "rapid-auto-off": false + } + }, + "pwm": { + "tool": { + "tool-reversed": false, + "tool-enable-mode": "disabled", + "tool-direction-mode": "disabled", + "min-spin": 0, + "max-spin": 255 + }, + "pwm-spindle": { + "pwm-min-duty": 1, + "pwm-inverted": false, + "pwm-max-duty": 99.99, + "pwm-freq": 1000, + "dynamic-power": true, + "rapid-auto-off": true + } + } }, + "switches": { + "switch-lockout": 250, + "estop": "disabled", + "switch-debounce": 5, + "probe": "normally-open" + }, + "probe": { + "probe-diameter": 6.35, + "probe-ydim": 53.975, + "probe-slow-seek": 25, + "probe-fast-seek": 75, + "probe-zdim": 15.4, + "probe-xdim": 53.975 + }, + "outputs": { + "load-1": "disabled", + "fault": "disabled", + "load-2": "disabled" + }, + "motors": [ + { + "latch-velocity": 0.1, + "max-accel": 750, + "max-velocity": 10, + "search-velocity": 1.688, + "travel-per-rev": 10, + "idle-current": 1, + "drive-current": 2.8, + "latch-backoff": 5, + "enabled": true, + "homing-mode": "stall-min", + "reverse": false, + "stall-microstep": 8, + "min-soft-limit": 0, + "max-switch": "disabled", + "step-angle": 1.8, + "stall-current": 1, + "stall-sample-time": 200, + "microsteps": 16, + "stall-volts": 2, + "axis": "X", + "min-switch": "disabled", + "max-jerk": 1000, + "max-soft-limit": 0, + "zero-backoff": 1.5 + }, + { + "latch-velocity": 0.1, + "max-accel": 750, + "max-velocity": 10, + "search-velocity": 1.688, + "travel-per-rev": 10, + "idle-current": 1, + "drive-current": 2.8, + "latch-backoff": 5, + "enabled": true, + "homing-mode": "stall-min", + "reverse": false, + "stall-microstep": 8, + "min-soft-limit": 0, + "max-switch": "disabled", + "step-angle": 1.8, + "stall-current": 1, + "stall-sample-time": 200, + "microsteps": 16, + "stall-volts": 2, + "axis": "Y", + "min-switch": "disabled", + "max-jerk": 1000, + "max-soft-limit": 0, + "zero-backoff": 1.5 + }, + { + "latch-velocity": 0.1, + "max-accel": 750, + "max-velocity": 10, + "search-velocity": 1.688, + "travel-per-rev": 10, + "idle-current": 1, + "drive-current": 2.8, + "latch-backoff": 5, + "enabled": true, + "homing-mode": "stall-min", + "reverse": false, + "stall-microstep": 8, + "min-soft-limit": 0, + "max-switch": "disabled", + "step-angle": 1.8, + "stall-current": 1, + "stall-sample-time": 200, + "microsteps": 16, + "stall-volts": 2, + "axis": "Y", + "min-switch": "disabled", + "max-jerk": 1000, + "max-soft-limit": 0, + "zero-backoff": 1.5 + }, + { + "latch-velocity": 0.1, + "max-accel": 750, + "max-velocity": 3, + "search-velocity": 0.675, + "travel-per-rev": 4, + "idle-current": 1, + "drive-current": 2.8, + "latch-backoff": 5, + "enabled": true, + "homing-mode": "stall-max", + "reverse": true, + "stall-microstep": 8, + "min-soft-limit": -133, + "max-switch": "disabled", + "step-angle": 1.8, + "stall-current": 1, + "stall-sample-time": 200, + "microsteps": 16, + "stall-volts": 2, + "axis": "Z", + "min-switch": "disabled", + "max-jerk": 1000, + "max-soft-limit": 0, + "zero-backoff": 1 + } + ], "admin": { "auto-check-upgrade": true },