Disable/enable reporting for each var
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Tue, 9 May 2017 19:04:37 +0000 (12:04 -0700)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Tue, 9 May 2017 19:04:37 +0000 (12:04 -0700)
avr/src/command.c
avr/src/command.def
avr/src/rtc.c
avr/src/vars.c
avr/src/vars.def
avr/src/vars.h
avr/src/vars.json.in

index 5baca9360da3ef7b1c696d12db49dcd3b641368c..1df7e56ded048d748aa8fe26579c61e4c6c5cf52 100644 (file)
@@ -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;
index a2871c43e10437f3914354ae053d599956296b4a..ec2d85d30aded66e44014f23109671f1de01e5eb 100644 (file)
@@ -27,6 +27,7 @@
 
 //  Name        Min, Max args, Help
 CMD(help,         0, 1, "Print this help screen")
+CMD(report,       1, 2, "[var] <enable>.  Enable or disable var reporting")
 CMD(reboot,       0, 0, "Reboot the controller")
 CMD(jog,          1, 4, "Jog")
 CMD(mreset,       0, 1, "Reset motor")
index 503d49bd8b2009e1f8bf7347805428fec6b56f4c..e09c584541fbb7a748e9cf70e879d92d39ace748 100644 (file)
@@ -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);}
index 7f39c7522ce7a3fc73a9cfefcd4c5d8473607c6f..d1dfe573f2be99387b7f2d3579d3583e85674bc9 100644 (file)
@@ -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;
index 09a059eff84c5d2b54d459f8dc3acec1fdbcf8be..f27eca74d1a293d5609aa301cfedf2c420830fcd 100644 (file)
 #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")
index 4eb8ce2bffc70cc91490863bcf8461f7f2067d82..fda234f2870214da4e7021d3acd83b8493d008f2 100644 (file)
 
 #include <stdbool.h>
 
+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);
index c18d540a403efa621c041a4acfed7d2c2e085f90..03195c7144fbc7acb1e732ea8a38d77c5a006084 100644 (file)
@@ -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"