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