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 () {
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) {

View File

@@ -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');
}
}

View File

@@ -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']",

View File

@@ -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

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-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
},