self.i2c_bus = None
log.warning('Failed to open device: %s', e)
- self._i2c_connect()
-
def _start_sending_gcode(self, path):
if self.stream is not None:
self.stream = None
- def _i2c_connect(self):
+ def connect(self):
try:
# Reset AVR communication
self.stop();
- self.report()
+ self.ctrl.config.config_avr()
- except:
- self.ctrl.ioloop.call_later(1, self._i2c_connect)
+ except Exception as e:
+ log.warning('Connect failed: %s', e)
+ self.ctrl.ioloop.call_later(1, self.connect)
def _i2c_command(self, cmd, byte = None, word = None):
if update:
if 'firmware' in msg:
log.error('AVR rebooted')
- self.stop();
- self.report()
+ self.connect()
if 'x' in msg and msg['x'] == 'ESTOPPED':
self._stop_sending_gcode()
def encode_cmd(self, index, value, spec):
+ if not 'code' in spec: return
+
if spec['type'] == 'enum': value = spec['values'].index(value)
elif spec['type'] == 'bool': value = 1 if value else 0
elif spec['type'] == 'percent': value /= 100.0
self.ctrl.avr.set(index, spec['code'], value)
- def encode_category(self, index, config, category):
+ def encode_category(self, index, config, category, with_defaults):
for key, spec in category.items():
- if key in config:
- self.encode_cmd(index, config[key], spec)
+ if key in config: value = config[key]
+ elif with_defaults: value = spec['default']
+ else: continue
+
+ self.encode_cmd(index, value, spec)
- def encode(self, index, config, tmpl):
+ def encode(self, index, config, tmpl, with_defaults):
for category in tmpl.values():
- self.encode_category(index, config, category)
+ self.encode_category(index, config, category, with_defaults)
+
+ def update(self, config, with_defaults = False):
+ for name, tmpl in self.template.items():
+ if name == 'motors':
+ for index in range(len(config['motors'])):
+ self.encode(index, config['motors'][index], tmpl,
+ with_defaults)
- def update(self, config):
- # Motors
- tmpl = self.template['motors']
- for index in range(len(config['motors'])):
- self.encode(index, config['motors'][index], tmpl)
+ else: self.encode_category('', config.get(name, {}), tmpl,
+ with_defaults)
- # Switches
- tmpl = self.template['switches']
- for index in range(len(config['switches'])):
- self.encode_category(index, config['switches'][index], tmpl)
- # Spindle
- tmpl = self.template['spindle']
- self.encode_category('', config['spindle'], tmpl)
+ def config_avr(self): self.update(self.load(), True)
"power-mode": {
"type": "enum",
"values": ["disabled", "always-on", "in-cycle", "when-moving"],
- "default": "in-cycle",
+ "default": "when-moving",
"code": "pm"
},
"max-current": {
"min-current": {
"type": "percent",
"unit": "%",
- "default": 30,
+ "default": 20,
"code": "lc"
},
"idle-current": {
"type": "percent",
"unit": "%",
- "default": 10,
+ "default": 1,
"code": "ic"
}
},
"travel-per-rev": {
"type": "float",
"unit": "mm",
- "default": 3.175,
+ "default": 5,
"code": "tr"
},
"microsteps": {
"type": "int",
- "values": [1, 2, 4, 8, 16, 32, 64, 128, 256],
+ "values": [1, 2, 4, 8, 16, 32, 64, 128],
"unit": "per full step",
- "default": 16,
+ "default": 32,
"code": "mi"
},
"reverse": {
"type": "float",
"min": 0,
"unit": "mm/min",
- "default": 16000,
+ "default": 5000,
"code": "vm"
},
- "max-feedrate": {
- "type": "float",
- "min": 0,
- "unit": "mm/min",
- "default": 16000,
- "code": "fr"
- },
"max-jerk": {
"type": "float",
"min": 0,
"unit": "mm/min³",
- "default": 20,
+ "default": 10,
"code": "jm"
}
},
"max-soft-limit": {
"type": "float",
"unit": "mm",
- "default": 150,
+ "default": 0,
"code": "tm"
},
"min-switch": {
"homing": {
"homing-mode": {
"type": "enum",
- "values": ["disabled", "stall", "min-switch", "max-switch"],
+ "values": [
+ "disabled", "stall-min", "stall-max", "switch-min", "switch-max"
+ ],
"default": "disabled",
"code": "ho"
},
"spindle": {
"spindle-type": {
"type": "enum",
- "values": ["PWM", "HUNAYANG"],
- "default": "PWM",
+ "values": ["HUNAYANG", "PWM"],
+ "default": "HUNAYANG",
"code": "st"
},
"spin-reversed": {
"min": 0,
"default": 48000,
"code": "sd"
+ },
+ "pwm-freq": {
+ "type": "int",
+ "unit": "Hz",
+ "min": 0,
+ "max": 65535,
+ "default": 100,
+ "code": "sf"
}
},