From 94e62349c53bf8a6904bfc3ddacd1310ada60cd0 Mon Sep 17 00:00:00 2001 From: Alden Hart Date: Fri, 9 Dec 2016 10:54:49 -0500 Subject: [PATCH] Changing the way floats are unit converted. Part of the way there. --- g2core/canonical_machine.cpp | 60 +++++++++++++++++++++++++++--------- g2core/canonical_machine.h | 1 + g2core/config.h | 3 +- g2core/config_app.cpp | 27 ++++++++++------ g2core/json_parser.cpp | 2 +- g2core/text_parser.cpp | 2 +- 6 files changed, 68 insertions(+), 27 deletions(-) mode change 100755 => 100644 g2core/config.h mode change 100755 => 100644 g2core/text_parser.cpp diff --git a/g2core/canonical_machine.cpp b/g2core/canonical_machine.cpp index 8c38f7c6..0079c2bc 100644 --- a/g2core/canonical_machine.cpp +++ b/g2core/canonical_machine.cpp @@ -128,7 +128,7 @@ static void _exec_absolute_origin(float *value, bool *flag); static void _exec_program_finalize(float *value, bool *flag); static int8_t _get_axis(const index_t index); -static cmAxisType _get_axis_type(const index_t index); +//static cmAxisType _get_axis_type(const index_t index); /*********************************************************************************** **** CODE ************************************************************************* @@ -2080,18 +2080,11 @@ static const char *const msg_frmo[] = { msg_g93, msg_g94, msg_g95 }; /***** AXIS HELPERS ***************************************************************** - * cm_get_axis_char() - return ASCII char for axis given the axis number - * _get_axis() - return axis number or -1 if NA - * _get_axis_type() - return 0 -f axis is linear, 1 if rotary, -1 if NA + * _get_axis() - return axis number or -1 if not an axis + * cm_get_axis_char() - return ASCII char for axis given the axis number + * cm_get_axis_type() - return axis type (0 if axis is linear, 1 if rotary, -1 if NA) */ -char cm_get_axis_char(const int8_t axis) -{ - char axis_char[] = "XYZABC"; - if ((axis < 0) || (axis > AXES)) return (' '); - return (axis_char[axis]); -} - static int8_t _get_axis(const index_t index) { char *ptr; @@ -2107,7 +2100,14 @@ static int8_t _get_axis(const index_t index) return (ptr - axes); } -static cmAxisType _get_axis_type(const index_t index) +char cm_get_axis_char(const int8_t axis) +{ + char axis_char[] = "XYZABC"; + if ((axis < 0) || (axis > AXES)) return (' '); + return (axis_char[axis]); +} + +cmAxisType cm_get_axis_type(const index_t index) { int8_t axis = _get_axis(index); if (axis >= AXIS_A) return (AXIS_TYPE_ROTARY); @@ -2246,6 +2246,36 @@ stat_t cm_get_ofs(nvObj_t *nv) /* * AXIS GET AND SET FUNCTIONS */ + +/* + * _decorate_settable_float() - convert incoming float value by units and axis type & complete NV struct + * _decorate_gettable_float() - convert outcoming float value by units and axis type & complete NV struct + */ +/* +float _preprocess_float(nvObj_t *nv) +{ + if (cm_get_units_mode(MODEL) == INCHES) { // If inn inches mode + if (_get_axis_type(nv->index) == AXIS_TYPE_LINEAR) { // ...and a linear axis... + nv->value *= MM_PER_INCH; // convert to canonical millimeter units + } + } + nv->precision = GET_TABLE_WORD(precision); + nv->valuetype = TYPE_FLOAT; + return(nv->value); +} + +float _decorate_gettable_float(nvObj_t *nv) +{ + if (cm_get_units_mode(MODEL) == INCHES) { // If inn inches mode + if (_get_axis_type(nv->index) == AXIS_TYPE_LINEAR) { // ...and a linear axis... + nv->value *= MM_PER_INCH; // convert to canonical millimeter units + } + } + nv->precision = GET_TABLE_WORD(precision); + nv->valuetype = TYPE_FLOAT; + return(nv->value); +} +*/ /* Axis Basic Settings * cm_get_am() - get axis mode w/enumeration string * cm_set_am() - set axis mode w/exception handling for axis type @@ -2265,7 +2295,7 @@ stat_t cm_get_am(nvObj_t *nv) stat_t cm_set_am(nvObj_t *nv) // axis mode { nv->valuetype = TYPE_INT; - if (_get_axis_type(nv->index) == AXIS_TYPE_LINEAR) { + if (cm_get_axis_type(nv->index) == AXIS_TYPE_LINEAR) { if (nv->value > AXIS_MODE_LINEAR_MAX) { return (STAT_INPUT_VALUE_RANGE_ERROR);} } else { if (nv->value > AXIS_MODE_ROTARY_MAX) { return (STAT_INPUT_VALUE_RANGE_ERROR);} @@ -2780,7 +2810,7 @@ static void _print_axis_ui8(nvObj_t *nv, const char *format) static void _print_axis_flt(nvObj_t *nv, const char *format) { char *units; - if (_get_axis_type(nv->index) == 0) { // linear + if (cm_get_axis_type(nv->index) == 0) { // linear units = (char *)GET_UNITS(MODEL); } else { units = (char *)GET_TEXT_ITEM(msg_units, DEGREE_INDEX); @@ -2792,7 +2822,7 @@ static void _print_axis_flt(nvObj_t *nv, const char *format) static void _print_axis_coord_flt(nvObj_t *nv, const char *format) { char *units; - if (_get_axis_type(nv->index) == 0) { // linear + if (cm_get_axis_type(nv->index) == 0) { // linear units = (char *)GET_UNITS(MODEL); } else { units = (char *)GET_TEXT_ITEM(msg_units, DEGREE_INDEX); diff --git a/g2core/canonical_machine.h b/g2core/canonical_machine.h index 88cb0b2a..61cee9e5 100644 --- a/g2core/canonical_machine.h +++ b/g2core/canonical_machine.h @@ -771,6 +771,7 @@ float cm_get_jogging_dest(void); /*--- cfgArray interface functions ---*/ char cm_get_axis_char(const int8_t axis); +char cm_get_axis_type(const int8_t axis); stat_t cm_get_mline(nvObj_t *nv); // get model line number stat_t cm_get_line(nvObj_t *nv); // get active (model or runtime) line number diff --git a/g2core/config.h b/g2core/config.h old mode 100755 new mode 100644 index 49fc5c24..d7ebd517 --- a/g2core/config.h +++ b/g2core/config.h @@ -353,7 +353,8 @@ void nv_print_list(stat_t status, uint8_t text_flags, uint8_t json_flags); // application specific helpers and functions (config_app.c) stat_t set_flu(nvObj_t *nv); // set floating point number with G20/G21 units conversion -void preprocess_float(nvObj_t *nv); // pre-process float values for units and illegal values +void preprocess_incoming_float(nvObj_t *nv); // pre-process outgoing float values for units and illegal values +void preprocess_outgoing_float(nvObj_t *nv); // pre-process incoming float values for canonical units // diagnostics void nv_dump_nv(nvObj_t *nv); diff --git a/g2core/config_app.cpp b/g2core/config_app.cpp index 326634d2..faacc491 100644 --- a/g2core/config_app.cpp +++ b/g2core/config_app.cpp @@ -995,20 +995,27 @@ stat_t set_flu(nvObj_t *nv) } /* - * preprocess_float() - pre-process floating point number for units display + * preprocess_incoming_float() - pre-process an incoming floating point number for canonical units + * preprocess_outgoing_float() - pre-process an outgoing floating point number for units display */ -void preprocess_float(nvObj_t *nv) -/* +void preprocess_incoming_float(nvObj_t *nv) { - if (isnan((double)nv->value) || isinf((double)nv->value)) return; // illegal float values - if (GET_TABLE_BYTE(flags) & F_CONVERT) { // unit conversion required? - if (cm_get_units_mode(MODEL) == INCHES) { - nv->value *= INCHES_PER_MM; + uint8_t f; + f = GET_TABLE_BYTE(flags); +// if (f & (F_CONVERT | F_ICONVERT)) { // unit conversion required? + if (f & F_CONVERT) { // unit conversion required? + if (cm_get_units_mode(MODEL) == INCHES) { // If inn inches mode + if (cm_get_axis_type(nv->index) == AXIS_TYPE_LINEAR) { // ...and a linear axis... + nv->value *= MM_PER_INCH; // convert to canonical millimeter units + } } - } + } + nv->precision = GET_TABLE_WORD(precision); + nv->valuetype = TYPE_FLOAT; } -*/ + +void preprocess_outgoing_float(nvObj_t *nv) { uint8_t f; if (isnan((double)nv->value) || isinf((double)nv->value)) return; // illegal float values @@ -1022,6 +1029,8 @@ void preprocess_float(nvObj_t *nv) } } } + nv->precision = GET_TABLE_WORD(precision); + nv->valuetype = TYPE_FLOAT; } /* diff --git a/g2core/json_parser.cpp b/g2core/json_parser.cpp index e2c0b5e2..d37838d5 100644 --- a/g2core/json_parser.cpp +++ b/g2core/json_parser.cpp @@ -421,7 +421,7 @@ uint16_t json_serialize(nvObj_t *nv, char *out_buf, uint16_t size) need_a_comma = false; break; } - case (TYPE_FLOAT): { preprocess_float(nv); + case (TYPE_FLOAT): { preprocess_outgoing_float(nv); str += floattoa(str, nv->value, nv->precision); break; } diff --git a/g2core/text_parser.cpp b/g2core/text_parser.cpp old mode 100755 new mode 100644 index 505858aa..8262d48f --- a/g2core/text_parser.cpp +++ b/g2core/text_parser.cpp @@ -196,7 +196,7 @@ void text_print_multiline_formatted(nvObj_t *nv) { for (uint8_t i=0; ivaluetype != TYPE_PARENT) { - preprocess_float(nv); + preprocess_outgoing_float(nv); nv_print(nv); } if ((nv = nv->nx) == NULL) return;