Save per-tool settings

This commit is contained in:
David Carley
2021-10-10 19:57:43 -07:00
parent a35890e15a
commit e28a0ab2d4
5 changed files with 245 additions and 171 deletions

View File

@@ -448,6 +448,19 @@ module.exports = new Vue({
}, },
save: function () { 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) { api.put('config/save', this.config).done(function (data) {
this.modified = false; this.modified = false;
}.bind(this)).fail(function (error) { }.bind(this)).fail(function (error) {

View File

@@ -27,8 +27,9 @@
'use strict'; 'use strict';
var api = require('./api'); const api = require('./api');
var modbus = require('./modbus.js'); const modbus = require('./modbus.js');
const merge = require("lodash.merge");
module.exports = { module.exports = {
template: '#tool-view-template', template: '#tool-view-template',
@@ -123,8 +124,9 @@ module.exports = {
events: { events: {
'input-changed': function () { 'input-changed': function () {
this.$dispatch('config-changed'); this.$dispatch('config-changed');
return false; return false;
} },
}, },
ready: function () { ready: function () {
@@ -140,25 +142,25 @@ module.exports = {
return this.config.tool['tool-type'].toUpperCase(); return this.config.tool['tool-type'].toUpperCase();
}, },
selected_tool: function() { selected_tool: function () {
return this.config.tool['selected-tool'].toUpperCase(); return this.config.tool['selected-tool'];
}, },
is_pwm_spindle: function () { is_pwm_spindle: function () {
return this.selected_tool == 'PWM'; return this.selected_tool == 'pwm';
},
is_laser: function () {
return this.selected_tool.includes("LASER");
},
is_router: function () {
return this.selected_tool.includes("ROUTER");
}, },
is_modbus: function () { is_modbus: function () {
return this.tool_type != 'DISABLED' && switch (this.selected_tool) {
!this.is_pwm_spindle && !this.is_laser && !this.is_router; case "disabled":
case "laser":
case "router":
case "pwm":
return false;
default:
return true;
}
}, },
modbus_status: function () { modbus_status: function () {
@@ -167,12 +169,16 @@ module.exports = {
}, },
methods: { 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']); const tool = this.toolList.find(tool => tool.id == this.config.tool['selected-tool']);
this.config.tool["tool-type"] = tool.type || tool.name; this.config.tool["tool-type"] = tool.type || tool.name;
console.log(this.config.tool["tool-type"]);
this.$dispatch("config-changed"); this.$dispatch("config-changed");
}, },
@@ -182,11 +188,11 @@ module.exports = {
case key === "selected-tool": case key === "selected-tool":
return false; return false;
case this.selected_tool === "DISABLED": case this.selected_tool === "disabled":
case this.selected_tool.includes("LASER"):
return false; return false;
case this.selected_tool.includes("ROUTER"): case this.selected_tool === "laser":
case this.selected_tool === "router":
switch (key) { switch (key) {
case "tool-enable-mode": case "tool-enable-mode":
return true; return true;
@@ -213,7 +219,7 @@ module.exports = {
}, },
get_reg_fails: function (reg) { get_reg_fails: function (reg) {
var fails = this.state[reg + 'vr'] const fails = this.state[reg + 'vr']
return fails == 255 ? 'Max' : fails; return fails == 255 ? 'Max' : fails;
}, },
@@ -236,9 +242,9 @@ module.exports = {
e.preventDefault(); e.preventDefault();
this.config.tool['tool-type'] = 'Custom Modbus VFD'; this.config.tool['tool-type'] = 'Custom Modbus VFD';
var regs = this.config['modbus-spindle'].regs; const regs = this.config['modbus-spindle'].regs;
for (var i = 0; i < regs.length; i++) { for (let i = 0; i < regs.length; i++) {
var reg = this.regs_tmpl.index[i]; const reg = this.regs_tmpl.index[i];
regs[i]['reg-type'] = this.get_reg_type(reg); regs[i]['reg-type'] = this.get_reg_type(reg);
regs[i]['reg-addr'] = this.get_reg_addr(reg); regs[i]['reg-addr'] = this.get_reg_addr(reg);
regs[i]['reg-value'] = this.get_reg_value(reg); regs[i]['reg-value'] = this.get_reg_value(reg);
@@ -251,8 +257,8 @@ module.exports = {
e.preventDefault(); e.preventDefault();
this.config.tool['tool-type'] = 'Custom Modbus VFD'; this.config.tool['tool-type'] = 'Custom Modbus VFD';
var regs = this.config['modbus-spindle'].regs; const regs = this.config['modbus-spindle'].regs;
for (var i = 0; i < regs.length; i++) { for (let i = 0; i < regs.length; i++) {
regs[i]['reg-type'] = 'disabled'; regs[i]['reg-type'] = 'disabled';
regs[i]['reg-addr'] = 0; regs[i]['reg-addr'] = 0;
regs[i]['reg-value'] = 0; regs[i]['reg-value'] = 0;
@@ -263,8 +269,8 @@ module.exports = {
reset_failures: function (e) { reset_failures: function (e) {
e.preventDefault(); e.preventDefault();
var regs = this.config['modbus-spindle'].regs; const regs = this.config['modbus-spindle'].regs;
for (var reg = 0; reg < regs.length; reg++) for (let reg = 0; reg < regs.length; reg++)
this.$dispatch('send', '\$' + reg + 'vr=0'); this.$dispatch('send', '\$' + reg + 'vr=0');
} }
} }

View File

@@ -45,9 +45,6 @@ script#tool-view-template(type="text/x-template")
| Pin {{templ.pin}} | Pin {{templ.pin}}
io-indicator(:name="$key", :state="state") 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") fieldset(v-if="is_pwm_spindle")
h2 PWM Spindle h2 PWM Spindle
templated-input(v-for="templ in template['pwm-spindle']", templated-input(v-for="templ in template['pwm-spindle']",

View File

@@ -185,6 +185,11 @@ class Config(object):
config['settings']['max-deviation'] = 0.05 config['settings']['max-deviation'] = 0.05
config['settings']['junction-accel'] = 200000 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['version'] = self.version.split('b')[0]
config['full_version'] = self.version config['full_version'] = self.version

View File

@@ -1,4 +1,11 @@
{ {
"version": "1.0.9",
"settings": {
"junction-accel": 200000,
"max-deviation": 0.05,
"units": "METRIC",
"probing-prompts": true
},
"tool": { "tool": {
"tool-reversed": false, "tool-reversed": false,
"tool-enable-mode": "disabled", "tool-enable-mode": "disabled",
@@ -7,138 +14,14 @@
"min-spin": 0, "min-spin": 0,
"max-spin": 255 "max-spin": 255
}, },
"switches": { "pwm-spindle": {
"switch-lockout": 250, "pwm-min-duty": 1,
"estop": "disabled", "pwm-inverted": false,
"switch-debounce": 5, "pwm-max-duty": 99.99,
"probe": "normally-open" "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": { "modbus-spindle": {
"baud": "9600", "baud": "9600",
"multi-write": false, "multi-write": false,
@@ -307,14 +190,184 @@
"bus-id": "1", "bus-id": "1",
"parity": "None" "parity": "None"
}, },
"pwm-spindle": { "selected-tool-settings": {
"pwm-min-duty": 1, "laser": {
"pwm-inverted": false, "tool": {
"pwm-max-duty": 99.99, "tool-reversed": false,
"pwm-freq": 1000, "tool-enable-mode": "disabled",
"dynamic-power": true, "tool-direction-mode": "disabled",
"rapid-auto-off": true "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": { "admin": {
"auto-check-upgrade": true "auto-check-upgrade": true
}, },