BOOT_LDFLAGS = $(LDFLAGS) -Wl,--section-start=.text=0x030000
# Build
-all: $(TARGET) $(PROJECT).hex $(PROJECT).eep $(PROJECT).lss xboot.hex \
- boot-size size
+all: $(PROJECT).hex build/vars.json boot size
+
+boot: xboot.hex boot-size
+
+build/vars.json: src/vars.def
# Compile
+build/%.json: src/%.json.in
+ cpp -Isrc $< | sed '/^#.*$$/d' > $@
+
build/%.o: src/%.c
@mkdir -p $(shell dirname $@)
$(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $<
#define SPI_SS_PIN SERIAL_CTS_PIN // Needed for SPI configuration
-// Compile-time settings
-#define __CLOCK_EXTERNAL_16MHZ // uses PLL to provide 32 MHz system clock
-//#define __CLOCK_INTERNAL_32MHZ
-
-
#define AXES 6 // number of axes
#define MOTORS 4 // number of motors on the board
#define COORDS 6 // number of supported coordinate systems
-#define SWITCHES 9 // number of supported limit switches
+#define SWITCHES 10 // number of supported switches
#define PWMS 2 // number of supported PWM channels
#define DISABLE_SOFT_LIMIT -1000000
bool active;
float idle_current;
- float drive_current;
+ float max_current;
+ float min_current;
float stall_threshold;
float power;
static float _driver_get_current(int driver) {
drv8711_driver_t *drv = &drivers[driver];
-#if 1
if (!drv->active) return drv->idle_current;
- return
- MOTOR_MIN_CURRENT + (drv->drive_current - MOTOR_MIN_CURRENT) * drv->power;
-
-#else
- return drv->active ? drv->drive_current : drv->idle_current;
-#endif
+ return drv->min_current + (drv->max_current - drv->min_current) * drv->power;
}
// Configure drivers
for (int i = 0; i < DRIVERS; i++) {
drivers[i].idle_current = MOTOR_IDLE_CURRENT;
- drivers[i].drive_current = MOTOR_MAX_CURRENT;
+ drivers[i].max_current = MOTOR_MAX_CURRENT;
+ drivers[i].min_current = MOTOR_MIN_CURRENT;
drivers[i].stall_threshold = MOTOR_STALL_THRESHOLD;
drv8711_disable(i);
}
-float get_drive_power(int driver) {
+float get_max_current(int driver) {
+ if (driver < 0 || DRIVERS <= driver) return 0;
+ return drivers[driver].max_current;
+}
+
+
+void set_max_current(int driver, float value) {
+ if (driver < 0 || DRIVERS <= driver || value < 0 || 1 < value) return;
+ drivers[driver].max_current = value;
+}
+
+
+float get_min_current(int driver) {
if (driver < 0 || DRIVERS <= driver) return 0;
- return drivers[driver].drive_current;
+ return drivers[driver].min_current;
}
-void set_drive_power(int driver, float value) {
+void set_min_current(int driver, float value) {
if (driver < 0 || DRIVERS <= driver || value < 0 || 1 < value) return;
- drivers[driver].drive_current = value;
+ drivers[driver].min_current = value;
}
-float get_idle_power(int driver) {
+float get_idle_current(int driver) {
if (driver < 0 || DRIVERS <= driver) return 0;
return drivers[driver].idle_current;
}
-void set_idle_power(int driver, float value) {
+void set_idle_current(int driver, float value) {
if (driver < 0 || DRIVERS <= driver || value < 0 || 1 < value) return;
drivers[driver].idle_current = value;
}
-float get_current_power(int driver) {
+float get_active_current(int driver) {
if (driver < 0 || DRIVERS <= driver) return 0;
return _driver_get_current(driver);
}
} switch_t;
-
+// Order must match indices in var functions below
static switch_t switches[SWITCHES] = {
- {.pin = MIN_X_PIN, .type = SW_NORMALLY_OPEN},
- {.pin = MAX_X_PIN, .type = SW_NORMALLY_OPEN},
- {.pin = MIN_Y_PIN, .type = SW_NORMALLY_OPEN},
- {.pin = MAX_X_PIN, .type = SW_NORMALLY_OPEN},
- {.pin = MIN_Z_PIN, .type = SW_NORMALLY_OPEN},
- {.pin = MAX_Z_PIN, .type = SW_NORMALLY_OPEN},
- {.pin = MIN_A_PIN, .type = SW_NORMALLY_OPEN},
- {.pin = MAX_A_PIN, .type = SW_NORMALLY_OPEN},
- {.pin = ESTOP_PIN, .type = SW_NORMALLY_OPEN},
- // {.pin = PROBE_PIN, .type = SW_NORMALLY_OPEN},
+ {.pin = MIN_X_PIN, .type = SW_DISABLED},
+ {.pin = MAX_X_PIN, .type = SW_DISABLED},
+ {.pin = MIN_Y_PIN, .type = SW_DISABLED},
+ {.pin = MAX_X_PIN, .type = SW_DISABLED},
+ {.pin = MIN_Z_PIN, .type = SW_DISABLED},
+ {.pin = MAX_Z_PIN, .type = SW_DISABLED},
+ {.pin = MIN_A_PIN, .type = SW_DISABLED},
+ {.pin = MAX_A_PIN, .type = SW_DISABLED},
+ {.pin = ESTOP_PIN, .type = SW_DISABLED},
+ {.pin = PROBE_PIN, .type = SW_DISABLED},
};
switch_type_t switch_get_type(int index) {
- return switches[index].type;
+ return (index < 0 || SWITCHES <= index) ? SW_DISABLED : switches[index].type;
}
void switch_set_type(int index, switch_type_t type) {
+ if (index < 0 || SWITCHES <= index) return;
switch_t *s = &switches[index];
if (s->type != type) {
// Var callbacks
-uint8_t get_switch_type(int index) {return switch_get_type(index);}
-void set_switch_type(int index, uint8_t value) {switch_set_type(index, value);}
+uint8_t get_min_switch(int index) {return switch_get_type(MIN_SWITCH(index));}
+
+
+void set_min_switch(int index, uint8_t value) {
+ switch_set_type(MIN_SWITCH(index), value);
+}
+
+
+uint8_t get_max_switch(int index) {return switch_get_type(MAX_SWITCH(index));}
+
+
+void set_max_switch(int index, uint8_t value) {
+ switch_set_type(MAX_SWITCH(index), value);
+}
+
+
+uint8_t get_estop_switch() {return switch_get_type(8);}
+void set_estop_switch(uint8_t value) {switch_set_type(8, value);}
+uint8_t get_probe_switch() {return switch_get_type(9);}
+void set_probe_switch(uint8_t value) {switch_set_type(9, value);}
}
+// Ensure no code is used more than once
+enum {
+#define VAR(NAME, CODE, ...) var_code_##CODE##_reuse,
+#include "vars.def"
+#undef VAR
+};
+
// Var forward declarations
#define VAR(NAME, CODE, TYPE, INDEX, SET, ...) \
TYPE get_##NAME(IF(INDEX)(int index)); \
VAR(reverse, rv, uint8_t, MOTORS, 1, 1, "Reverse motor polarity")
VAR(power_mode, pm, uint8_t, MOTORS, 1, 1, "Motor power mode")
-VAR(drive_power, dp, float, MOTORS, 1, 1, "Motor drive power")
-VAR(idle_power, ip, float, MOTORS, 1, 1, "Motor idle power")
-VAR(current_power, cp, float, MOTORS, 0, 0, "Motor power now")
+VAR(max_current, xc, float, MOTORS, 1, 1, "Max motor drive current")
+VAR(min_current, lc, float, MOTORS, 1, 1, "Min motor drive current")
+VAR(idle_current, ic, float, MOTORS, 1, 1, "Motor idle current")
+VAR(active_current, ac, float, MOTORS, 0, 0, "Motor current now")
VAR(status_flags, mf, uint8_t, MOTORS, 0, 0, "Motor status flags")
VAR(status_strings, ms, flags_t, MOTORS, 0, 0, "Motor status strings")
-VAR(motor_fault, mf, bool, 0, 0, 0, "Motor fault status")
+VAR(motor_fault, fa, bool, 0, 0, 0, "Motor fault status")
VAR(velocity_max, vm, float, MOTORS, 1, 1, "Maxium velocity in mm/min")
VAR(feedrate_max, fr, float, MOTORS, 1, 1, "Maxium feedrate in mm/min")
VAR(junction_dev, jd, float, MOTORS, 1, 1, "Junction deviation")
VAR(radius, ra, float, MOTORS, 1, 1, "Axis radius or zero")
-// Homing
-VAR(homing_mode, hm, uint8_t, MOTORS, 1, 1, "Homing type")
+// Switches
VAR(travel_min, tn, float, MOTORS, 1, 1, "Minimum soft limit")
VAR(travel_max, tm, float, MOTORS, 1, 1, "Maximum soft limit")
+VAR(min_switch, ls, uint8_t, MOTORS, 1, 1, "Minimum switch mode")
+VAR(max_switch, xs, uint8_t, MOTORS, 1, 1, "Maximum switch mode")
+VAR(estop_switch, et, uint8_t, 0, 1, 1, "Estop switch mode")
+VAR(probe_switch, pt, uint8_t, 0, 1, 1, "Probe switch mode")
+
+// Homing
+VAR(homing_mode, ho, uint8_t, MOTORS, 1, 1, "Homing type")
VAR(search_velocity,sv, float, MOTORS, 1, 1, "Homing search velocity")
VAR(latch_velocity, lv, float, MOTORS, 1, 1, "Homing latch velocity")
-VAR(latch_backoff, lb, float, MOTORS, 1, 1, "Homing latch backof")
-VAR(zero_backoff, zb, float, MOTORS, 1, 1, "Homing zero backof")
+VAR(latch_backoff, lb, float, MOTORS, 1, 1, "Homing latch backoff")
+VAR(zero_backoff, zb, float, MOTORS, 1, 1, "Homing zero backoff")
// Axis
VAR(position, p, float, AXES, 0, 0, "Current axis position")
VAR(huanyang_debug, hb, bool, 0, 1, 0, "Huanyang debugging")
VAR(huanyang_connected, he, bool, 0, 0, 0, "Huanyang connected")
-// Switches
-VAR(switch_type, sw, uint8_t, SWITCHES, 1, 1, "Normally open or closed")
-
// GCode
VAR(line, ln, int32_t, 0, 0, 0, "Last GCode line executed")
VAR(unit, u, pstring, 0, 0, 0, "Current unit of measure")
--- /dev/null
+#include "cpp_magic.h"
+{
+#define VAR(NAME, CODE, TYPE, INDEX, SET, SAVE, HELP) \
+ #CODE: { \
+ "name": #NAME, \
+ "type": #TYPE, \
+ "index": IF_ELSE(INDEX)(true, false), \
+ "setable": IF_ELSE(SET)(true, false), \
+ "help": HELP \
+ },
+#include "vars.def"
+#undef VAR
+ "_": {}
+}
reset: function () {
this.confirmReset = false;
api.put('config/reset').done(function () {
+ this.$dispatch('update');
this.configReset = true;
}.bind(this)).fail(function (error) {
+import os
import json
import logging
import pkg_resources
log.info('Saved')
+ def reset(self): os.unlink('config.json')
+
+
def encode_cmd(self, index, value, spec):
if spec['type'] == 'enum': value = spec['values'].index(value)
elif spec['type'] == 'bool': value = 1 if value else 0
"default": "in-cycle",
"code": "pm"
},
- "min-power": {
+ "max-current": {
"type": "percent",
"unit": "%",
- "default": 30,
- "code": "pl"
+ "default": 80,
+ "code": "xc"
},
- "max-power": {
+ "min-current": {
"type": "percent",
"unit": "%",
- "default": 80,
- "code": "th"
+ "default": 30,
+ "code": "lc"
},
- "idle-power": {
+ "idle-current": {
"type": "percent",
"unit": "%",
"default": 10,
- "code": "ip"
+ "code": "ic"
}
},
}
},
- "homing": {
- "homing-mode": {
- "type": "enum",
- "values": [
- "disabled", "stall", "min-normally-open", "min-normally-closed",
- "max-normally-open", "max-normally-closed"],
- "default": "disabled",
- "code": "hm"
- },
+ "limits": {
"min-soft-limit": {
"type": "float",
"unit": "mm",
"default": 150,
"code": "tm"
},
+ "min-switch": {
+ "type": "enum",
+ "values": ["disabled", "normally-open", "normally-closed"],
+ "default": "disabled",
+ "code": "ls"
+ },
+ "max-switch": {
+ "type": "enum",
+ "values": ["disabled", "normally-open", "normally-closed"],
+ "default": "disabled",
+ "code": "xs"
+ }
+ },
+
+ "homing": {
+ "homing-mode": {
+ "type": "enum",
+ "values": ["disabled", "stall", "min-switch", "max-switch"],
+ "default": "disabled",
+ "code": "ho"
+ },
"search-velocity": {
"type": "float",
"min": 0,