From 4b84bde23cf7dc5456718ecd73152584f52d8a74 Mon Sep 17 00:00:00 2001 From: Joseph Coffland Date: Tue, 9 May 2017 12:04:37 -0700 Subject: [PATCH] Disable/enable reporting for each var --- avr/src/command.c | 11 +++ avr/src/command.def | 1 + avr/src/rtc.c | 6 +- avr/src/vars.c | 59 ++++++++++++++-- avr/src/vars.def | 158 +++++++++++++++++++++---------------------- avr/src/vars.h | 3 + avr/src/vars.json.in | 3 +- 7 files changed, 150 insertions(+), 91 deletions(-) diff --git a/avr/src/command.c b/avr/src/command.c index 5baca93..1df7e56 100644 --- a/avr/src/command.c +++ b/avr/src/command.c @@ -292,6 +292,17 @@ uint8_t command_help(int argc, char *argv[]) { } +uint8_t command_report(int argc, char *argv[]) { + if (argc == 2) { + vars_report_all(var_parse_bool(argv[1])); + return STAT_OK; + } + + vars_report_var(argv[1], var_parse_bool(argv[2])); + return STAT_OK; +} + + uint8_t command_reboot(int argc, char *argv[]) { _reboot(); return 0; diff --git a/avr/src/command.def b/avr/src/command.def index a2871c4..ec2d85d 100644 --- a/avr/src/command.def +++ b/avr/src/command.def @@ -27,6 +27,7 @@ // Name Min, Max args, Help CMD(help, 0, 1, "Print this help screen") +CMD(report, 1, 2, "[var] . Enable or disable var reporting") CMD(reboot, 0, 0, "Reboot the controller") CMD(jog, 1, 4, "Jog") CMD(mreset, 0, 1, "Reset motor") diff --git a/avr/src/rtc.c b/avr/src/rtc.c index 503d49b..e09c584 100644 --- a/avr/src/rtc.c +++ b/avr/src/rtc.c @@ -70,8 +70,4 @@ void rtc_init() { uint32_t rtc_get_time() {return ticks;} - - -bool rtc_expired(uint32_t t) { - return 0 <= (int32_t)(ticks - t); -} +bool rtc_expired(uint32_t t) {return 0 <= (int32_t)(ticks - t);} diff --git a/avr/src/vars.c b/avr/src/vars.c index 7f39c75..d1dfe57 100644 --- a/avr/src/vars.c +++ b/avr/src/vars.c @@ -94,7 +94,7 @@ static void var_print_float(float x) { else { char buf[20]; - int len = sprintf_P(buf, PSTR("%.6f"), x); + int len = sprintf_P(buf, PSTR("%.3f"), x); // Remove trailing zeros for (int i = len; 0 < i; i--) { @@ -122,7 +122,7 @@ inline static bool var_eq_bool(float a, float b) {return a == b;} static void var_print_bool(bool x) {printf_P(x ? PSTR("true") : PSTR("false"));} -static bool var_parse_bool(const char *value) { +bool var_parse_bool(const char *value) { return !strcasecmp(value, "true") || var_parse_float(value); } @@ -174,9 +174,10 @@ static void var_print_int32_t(uint32_t x) { // Ensure no code is used more than once enum { -#define VAR(NAME, CODE, ...) var_code_##CODE##_reuse, +#define VAR(NAME, CODE, ...) var_code_##CODE, #include "vars.def" #undef VAR + var_code_count }; // Var forward declarations @@ -188,8 +189,8 @@ enum { #include "vars.def" #undef VAR -// Var names, count & help -#define VAR(NAME, CODE, TYPE, INDEX, SET, HELP) \ +// Var names & help +#define VAR(NAME, CODE, TYPE, INDEX, SET, REPORT, HELP) \ static const char NAME##_name[] PROGMEM = #NAME; \ static const char NAME##_help[] PROGMEM = HELP; @@ -203,6 +204,29 @@ enum { #include "vars.def" #undef VAR +// Report +static uint8_t _report_var[(var_code_count >> 3) + 1] = {0,}; + + +static bool _get_report_var(int index) { + return _report_var[index >> 3] & (1 << (index & 7)); +} + + +static void _set_report_var(int index, bool enable) { + if (enable) _report_var[index >> 3] |= 1 << (index & 7); + else _report_var[index >> 3] &= ~(1 << (index & 7)); +} + + +static int _find_code(const char *code) { +#define VAR(NAME, CODE, TYPE, INDEX, ...) \ + if (!strcmp(code, #CODE)) return var_code_##CODE; \ + +#include "vars.def" +#undef VAR + return -1; +} void vars_init() { @@ -211,6 +235,13 @@ void vars_init() { IF(INDEX)(for (int i = 0; i < INDEX; i++)) \ (NAME##_state)IF(INDEX)([i]) = get_##NAME(IF(INDEX)(i)); +#include "vars.def" +#undef VAR + +// Report +#define VAR(NAME, CODE, TYPE, INDEX, SET, REPORT, ...) \ + _set_report_var(var_code_##CODE, REPORT); + #include "vars.def" #undef VAR } @@ -226,8 +257,9 @@ void vars_report(bool full) { IF(INDEX)(for (int i = 0; i < (INDEX ? INDEX : 1); i++)) { \ TYPE value = get_##NAME(IF(INDEX)(i)); \ TYPE last = (NAME##_state)IF(INDEX)([i]); \ + bool report = _get_report_var(var_code_##CODE); \ \ - if (!var_eq_##TYPE(value, last) || full) { \ + if ((report && !var_eq_##TYPE(value, last)) || full) { \ (NAME##_state)IF(INDEX)([i]) = value; \ \ if (!reported) { \ @@ -253,6 +285,21 @@ void vars_report(bool full) { } +void vars_report_all(bool enable) { +#define VAR(NAME, CODE, TYPE, INDEX, SET, REPORT, ...) \ + _set_report_var(var_code_##CODE, enable); + +#include "vars.def" +#undef VAR +} + + +void vars_report_var(const char *code, bool enable) { + int index = _find_code(code); + if (index != -1) _set_report_var(index, enable); +} + + int vars_find(const char *name) { uint8_t i = 0; uint8_t n = 0; diff --git a/avr/src/vars.def b/avr/src/vars.def index 09a059e..f27eca7 100644 --- a/avr/src/vars.def +++ b/avr/src/vars.def @@ -28,100 +28,100 @@ #define AXES_LABEL "xyzabcuvw" #define MOTORS_LABEL "0123" -// VAR(name, code, type, index, settable, help) +// VAR(name, code, type, index, settable, report, help) // Motor -VAR(motor_axis, an, uint8_t, MOTORS, 1, "Maps motor to axis") -VAR(step_angle, sa, float, MOTORS, 1, "In degrees per full step") -VAR(travel, tr, float, MOTORS, 1, "Travel in mm per revolution") -VAR(microstep, mi, uint16_t, MOTORS, 1, "Microsteps per full step") -VAR(reverse, rv, uint8_t, MOTORS, 1, "Reverse motor polarity") - -VAR(power_mode, pm, uint8_t, MOTORS, 1, "Motor power mode") -VAR(drive_current, dc, float, MOTORS, 1, "Max motor drive current") -VAR(idle_current, ic, float, MOTORS, 1, "Motor idle current") -VAR(active_current, ac, float, MOTORS, 0, "Motor current now") -VAR(driver_flags, df, uint16_t, MOTORS, 0, "Motor driver status flags") -VAR(status_strings, ds, flags_t, MOTORS, 0, "Motor driver status strings") -VAR(encoder, en, int32_t, MOTORS, 0, "Motor encoder") -VAR(error, ee, int32_t, MOTORS, 0, "Motor position error") - -VAR(motor_fault, fa, bool, 0, 0, "Motor fault status") - -VAR(velocity_max, vm, float, MOTORS, 1, "Maxium velocity in mm/min") -VAR(jerk_max, jm, float, MOTORS, 1, "Maxium jerk in mm/min^3") -VAR(radius, ra, float, MOTORS, 1, "Axis radius or zero") +VAR(motor_axis, an, uint8_t, MOTORS, 1, 1, "Maps motor to axis") +VAR(step_angle, sa, float, MOTORS, 1, 1, "In degrees per full step") +VAR(travel, tr, float, MOTORS, 1, 1, "Travel in mm per revolution") +VAR(microstep, mi, uint16_t, MOTORS, 1, 1, "Microsteps per full step") +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_current, dc, float, MOTORS, 1, 1, "Max motor drive current") +VAR(idle_current, ic, float, MOTORS, 1, 1, "Motor idle current") +VAR(active_current, ac, float, MOTORS, 0, 1, "Motor current now") +VAR(driver_flags, df, uint16_t, MOTORS, 0, 1, "Motor driver status flags") +VAR(status_strings, ds, flags_t, MOTORS, 0, 1, "Motor driver status strings") +VAR(encoder, en, int32_t, MOTORS, 0, 0, "Motor encoder") +VAR(error, ee, int32_t, MOTORS, 0, 0, "Motor position error") + +VAR(motor_fault, fa, bool, 0, 0, 1, "Motor fault status") + +VAR(velocity_max, vm, float, MOTORS, 1, 1, "Maxium velocity in mm/min") +VAR(jerk_max, jm, float, MOTORS, 1, 1, "Maxium jerk in mm/min^3") +VAR(radius, ra, float, MOTORS, 1, 1, "Axis radius or zero") // Switches -VAR(travel_min, tn, float, MOTORS, 1, "Minimum soft limit") -VAR(travel_max, tm, float, MOTORS, 1, "Maximum soft limit") -VAR(min_switch, ls, uint8_t, MOTORS, 1, "Minimum switch mode") -VAR(max_switch, xs, uint8_t, MOTORS, 1, "Maximum switch mode") -VAR(estop_switch, et, uint8_t, 0, 1, "Estop switch mode") -VAR(probe_switch, pt, uint8_t, 0, 1, "Probe switch mode") +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, "Homing type") -VAR(search_velocity,sv, float, MOTORS, 1, "Homing search velocity") -VAR(latch_velocity, lv, float, MOTORS, 1, "Homing latch velocity") -VAR(latch_backoff, lb, float, MOTORS, 1, "Homing latch backoff") -VAR(zero_backoff, zb, float, MOTORS, 1, "Homing zero backoff") +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 backoff") +VAR(zero_backoff, zb, float, MOTORS, 1, 1, "Homing zero backoff") // Axis -VAR(position, p, float, AXES, 0, "Current axis position") +VAR(position, p, float, AXES, 0, 1, "Current axis position") // Spindle -VAR(spindle_type, st, uint8_t, 0, 1, "PWM=0 or HUANYANG=1") -VAR(spin_reverse, sr, bool, 0, 1, "Reverse spin") -VAR(max_spin, sx, float, 0, 1, "Maximum spindle speed") -VAR(min_spin, sm, float, 0, 1, "Minimum spindle speed") -VAR(spin_min_duty, nd, float, 0, 1, "Minimum PWM duty cycle") -VAR(spin_max_duty, md, float, 0, 1, "Maximum PWM duty cycle") -VAR(spin_up, su, float, 0, 1, "Spin up velocity") -VAR(spin_down, sd, float, 0, 1, "Spin down velocity") -VAR(spin_freq, sf, uint16_t, 0, 1, "Spindle PWM frequency") +VAR(spindle_type, st, uint8_t, 0, 1, 1, "PWM=0 or HUANYANG=1") +VAR(spin_reverse, sr, bool, 0, 1, 1, "Reverse spin") +VAR(max_spin, sx, float, 0, 1, 1, "Maximum spindle speed") +VAR(min_spin, sm, float, 0, 1, 1, "Minimum spindle speed") +VAR(spin_min_duty, nd, float, 0, 1, 1, "Minimum PWM duty cycle") +VAR(spin_max_duty, md, float, 0, 1, 1, "Maximum PWM duty cycle") +VAR(spin_up, su, float, 0, 1, 1, "Spin up velocity") +VAR(spin_down, sd, float, 0, 1, 1, "Spin down velocity") +VAR(spin_freq, sf, uint16_t, 0, 1, 1, "Spindle PWM frequency") // PWM spindle -VAR(pwm_invert, pi, bool, 0, 1, "Inverted spindle PWM") -VAR(enable_invert, ei, bool, 0, 1, "Inverted spindle enable") +VAR(pwm_invert, pi, bool, 0, 1, 1, "Inverted spindle PWM") +VAR(enable_invert, ei, bool, 0, 1, 1, "Inverted spindle enable") // Huanyang spindle -VAR(huanyang_id, hi, uint8_t, 0, 1, "Huanyang ID") -VAR(huanyang_freq, hz, float, 0, 0, "Huanyang actual freq") -VAR(huanyang_current, hc, float, 0, 0, "Huanyang actual current") -VAR(huanyang_rpm, hr, uint16_t, 0, 0, "Huanyang actual RPM") -VAR(huanyang_temp, ht, uint16_t, 0, 0, "Huanyang temperature") -VAR(huanyang_max_freq, hx, float, 0, 0, "Huanyang max freq") -VAR(huanyang_min_freq, hm, float, 0, 0, "Huanyang min freq") -VAR(huanyang_rated_rpm, hq, uint16_t, 0, 0, "Huanyang rated RPM") -VAR(huanyang_status, hs, uint8_t, 0, 0, "Huanyang status flags") -VAR(huanyang_debug, hb, bool, 0, 1, "Huanyang debugging") -VAR(huanyang_connected, he, bool, 0, 0, "Huanyang connected") +VAR(huanyang_id, hi, uint8_t, 0, 1, 1, "Huanyang ID") +VAR(huanyang_freq, hz, float, 0, 0, 1, "Huanyang actual freq") +VAR(huanyang_current, hc, float, 0, 0, 1, "Huanyang actual current") +VAR(huanyang_rpm, hr, uint16_t, 0, 0, 1, "Huanyang actual RPM") +VAR(huanyang_temp, ht, uint16_t, 0, 0, 1, "Huanyang temperature") +VAR(huanyang_max_freq, hx, float, 0, 0, 1, "Huanyang max freq") +VAR(huanyang_min_freq, hm, float, 0, 0, 1, "Huanyang min freq") +VAR(huanyang_rated_rpm, hq, uint16_t, 0, 0, 1, "Huanyang rated RPM") +VAR(huanyang_status, hs, uint8_t, 0, 0, 1, "Huanyang status flags") +VAR(huanyang_debug, hb, bool, 0, 1, 1, "Huanyang debugging") +VAR(huanyang_connected, he, bool, 0, 0, 1, "Huanyang connected") // GCode -VAR(line, ln, int32_t, 0, 0, "Last GCode line executed") -VAR(unit, u, pstring, 0, 0, "Current unit of measure") -VAR(speed, s, float, 0, 0, "Current spindle speed") -VAR(feed, f, float, 0, 0, "Current feed rate") -VAR(tool, t, uint8_t, 0, 0, "Current tool") -VAR(feed_mode, fm, pstring, 0, 0, "Current feed rate mode") -VAR(plane, pa, pstring, 0, 0, "Current plane") -VAR(coord_system, cs, pstring, 0, 0, "Current coordinate system") -VAR(abs_override, ao, bool, 0, 0, "Absolute override enabled") -VAR(path_mode, pc, pstring, 0, 0, "Current path control mode") -VAR(distance_mode, dm, pstring, 0, 0, "Current distance mode") -VAR(arc_dist_mode, ad, pstring, 0, 0, "Current arc distance mode") -VAR(mist_coolant, mc, bool, 0, 0, "Mist coolant enabled") -VAR(flood_coolant, fc, bool, 0, 0, "Flood coolant enabled") -VAR(feed_override, fo, float, 0, 0, "Feed rate override") -VAR(speed_override, so, float, 0, 0, "Spindle speed override") +VAR(line, ln, int32_t, 0, 0, 1, "Last GCode line executed") +VAR(unit, u, pstring, 0, 0, 1, "Current unit of measure") +VAR(speed, s, float, 0, 0, 1, "Current spindle speed") +VAR(feed, f, float, 0, 0, 1, "Current feed rate") +VAR(tool, t, uint8_t, 0, 0, 1, "Current tool") +VAR(feed_mode, fm, pstring, 0, 0, 1, "Current feed rate mode") +VAR(plane, pa, pstring, 0, 0, 1, "Current plane") +VAR(coord_system, cs, pstring, 0, 0, 1, "Current coordinate system") +VAR(abs_override, ao, bool, 0, 0, 1, "Absolute override enabled") +VAR(path_mode, pc, pstring, 0, 0, 1, "Current path control mode") +VAR(distance_mode, dm, pstring, 0, 0, 1, "Current distance mode") +VAR(arc_dist_mode, ad, pstring, 0, 0, 1, "Current arc distance mode") +VAR(mist_coolant, mc, bool, 0, 0, 1, "Mist coolant enabled") +VAR(flood_coolant, fc, bool, 0, 0, 1, "Flood coolant enabled") +VAR(feed_override, fo, float, 0, 0, 1, "Feed rate override") +VAR(speed_override, so, float, 0, 0, 1, "Spindle speed override") // System -VAR(velocity, v, float, 0, 0, "Current velocity") -VAR(hw_id, id, string, 0, 0, "Hardware ID") -VAR(echo, ec, bool, 0, 1, "Enable or disable echo") -VAR(estop, es, bool, 0, 1, "Emergency stop") -VAR(estop_reason, er, pstring, 0, 0, "Emergency stop reason") -VAR(state, x, pstring, 0, 0, "Machine state") -VAR(cycle, c, pstring, 0, 0, "Machine cycle") -VAR(hold_reason, pr, pstring, 0, 0, "Machine pause reason") +VAR(velocity, v, float, 0, 0, 1, "Current velocity") +VAR(hw_id, id, string, 0, 0, 1, "Hardware ID") +VAR(echo, ec, bool, 0, 1, 1, "Enable or disable echo") +VAR(estop, es, bool, 0, 1, 1, "Emergency stop") +VAR(estop_reason, er, pstring, 0, 0, 1, "Emergency stop reason") +VAR(state, x, pstring, 0, 0, 1, "Machine state") +VAR(cycle, c, pstring, 0, 0, 1, "Machine cycle") +VAR(hold_reason, pr, pstring, 0, 0, 1, "Machine pause reason") diff --git a/avr/src/vars.h b/avr/src/vars.h index 4eb8ce2..fda234f 100644 --- a/avr/src/vars.h +++ b/avr/src/vars.h @@ -31,10 +31,13 @@ #include +bool var_parse_bool(const char *value); void vars_init(); void vars_report(bool full); +void vars_report_all(bool enable); +void vars_report_var(const char *code, bool enable); int vars_find(const char *name); bool vars_print(const char *name); bool vars_set(const char *name, const char *value); diff --git a/avr/src/vars.json.in b/avr/src/vars.json.in index c18d540..03195c7 100644 --- a/avr/src/vars.json.in +++ b/avr/src/vars.json.in @@ -1,11 +1,12 @@ #include "cpp_magic.h" { -#define VAR(NAME, CODE, TYPE, INDEX, SET, HELP) \ +#define VAR(NAME, CODE, TYPE, INDEX, SET, REPORT, HELP) \ #CODE: { \ "name": #NAME, \ "type": #TYPE, \ "index": IF_ELSE(INDEX)(true, false), \ "setable": IF_ELSE(SET)(true, false), \ + "report": IF_ELSE(REPORT)(true, false), \ "help": HELP \ }, #include "vars.def" -- 2.27.0