mirror of
https://github.com/synthetos/g2.git
synced 2026-10-06 22:52:49 +08:00
Changing the way floats are unit converted. Part of the way there.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Executable → Regular
+2
-1
@@ -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);
|
||||
|
||||
+18
-9
@@ -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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Executable → Regular
+1
-1
@@ -196,7 +196,7 @@ void text_print_multiline_formatted(nvObj_t *nv)
|
||||
{
|
||||
for (uint8_t i=0; i<NV_BODY_LEN-1; i++) {
|
||||
if (nv->valuetype != TYPE_PARENT) {
|
||||
preprocess_float(nv);
|
||||
preprocess_outgoing_float(nv);
|
||||
nv_print(nv);
|
||||
}
|
||||
if ((nv = nv->nx) == NULL) return;
|
||||
|
||||
Reference in New Issue
Block a user