Gpio changes and updates; removed some unused getters and setters

This commit is contained in:
Alden Hart
2017-03-20 16:20:23 -04:00
parent 2a7a65efa5
commit fc209a4cf2
9 changed files with 179 additions and 289 deletions
+3 -3
View File
@@ -3,8 +3,8 @@
* For: /board/g2v9
* This file is part of the g2core project
*
* Copyright (c) 2013 - 2016 Robert Giseburt
* Copyright (c) 2013 - 2016 Alden S. Hart Jr.
* Copyright (c) 2013 - 2017 Robert Giseburt
* Copyright (c) 2013 - 2017 Alden S. Hart Jr.
*
* This file ("the software") is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2 as published by the
@@ -95,7 +95,7 @@
#define TEMPERATURE_OUTPUT_ON 0
// Some pins, if the PWM capability is turned on, it will cause timer conflicts.
// So we have to explicity enable them as PWM pins.
// So we have to explicitly enable them as PWM pins.
// Generated with:
// perl -e 'for($i=1;$i<14;$i++) { print "#define OUTPUT${i}_PWM 0\n";}'
#define OUTPUT1_PWM 0
+1
View File
@@ -1992,6 +1992,7 @@ stat_t cm_get_prb(nvObj_t *nv) { return (get_float(nv, cm->probe_results[0][_ax
stat_t cm_get_coord(nvObj_t *nv) { return (get_float(nv, cm->coord_offset[_coord(nv)][_axis(nv)])); }
stat_t cm_set_coord(nvObj_t *nv) { return (set_float(nv, cm->coord_offset[_coord(nv)][_axis(nv)])); }
stat_t cm_get_g92e(nvObj_t *nv) { return (get_int(nv, cm->gmx.origin_offset_enable)); }
stat_t cm_get_g92(nvObj_t *nv) { return (get_float(nv, cm->gmx.origin_offset[_axis(nv)])); }
stat_t cm_get_g28(nvObj_t *nv) { return (get_float(nv, cm->gmx.g28_position[_axis(nv)])); }
stat_t cm_get_g30(nvObj_t *nv) { return (get_float(nv, cm->gmx.g30_position[_axis(nv)])); }
+1
View File
@@ -571,6 +571,7 @@ stat_t cm_get_ofs(nvObj_t *nv); // get runtime work offset
stat_t cm_get_coord(nvObj_t *nv); // get coordinate offset
stat_t cm_set_coord(nvObj_t *nv); // set coordinate offset
stat_t cm_get_g92e(nvObj_t *nv); // get g92 enable state
stat_t cm_get_g92(nvObj_t *nv); // get g92 offset
stat_t cm_get_g28(nvObj_t *nv); // get g28 offset
stat_t cm_get_g30(nvObj_t *nv); // get g30 offset
+27 -106
View File
@@ -125,20 +125,16 @@ void config_init()
static void _set_defa(nvObj_t *nv, bool print)
{
cm_set_units_mode(MILLIMETERS); // must do inits in MM mode
cm_set_units_mode(MILLIMETERS); // must do inits in MM mode
for (nv->index=0; nv_index_is_single(nv->index); nv->index++) {
if (cfgArray[nv->index].flags & F_INITIALIZE) {
// if (cfgArray[nv->index].flags & F_ZERO) {
// nv->value = 0;
// } else {
if ((cfgArray[nv->index].flags & F_TYPE_MASK) == TYPE_INTEGER) {
nv->value_int = cfgArray[nv->index].def_value;
} else {
nv->value_flt = cfgArray[nv->index].def_value;
}
// }
strncpy(nv->token, cfgArray[nv->index].token, TOKEN_LEN);
cfgArray[nv->index].set(nv); // run the set method, nv_set(nv);
cfgArray[nv->index].set(nv); // run the set method, nv_set(nv);
if (cfgArray[nv->index].flags & F_PERSIST) {
nv_persist(nv);
}
@@ -162,7 +158,7 @@ stat_t set_defaults(nvObj_t *nv)
// Mark the nv as $defa so it displays nicely in the response
nv_reset_nv_list();
strncpy(nv->token, "defa", TOKEN_LEN);
// nv->index = nv_get_index("", nv->token); // correct, but not required
// nv->index = nv_get_index("", nv->token); // correct, but not required
nv->valuetype = TYPE_INTEGER; // ++++ probably should be TYPE_BOOLEAN
nv->value_int = true;
return (STAT_OK);
@@ -200,8 +196,6 @@ stat_t config_test_assertions()
/* Generic gets()
* get_nul() - get nothing (returns STAT_NOOP)
* get_ui8() - get value as 8 bit uint8_t (use uint8 for booleans)
* get_int8() - get value as 8 bit int8_t
* get_int32() - get value as 32 bit integer
* get_data() - get value as 32 bit integer blind cast
* get_flt() - get value as float
@@ -212,35 +206,13 @@ stat_t get_nul(nvObj_t *nv)
return (STAT_NOOP);
}
stat_t get_ui8(nvObj_t *nv)
{
nv->value_int = *((uint8_t *)GET_TABLE_WORD(target));
nv->valuetype = TYPE_INTEGER;
return (STAT_OK);
}
stat_t get_int8(nvObj_t *nv)
{
nv->value_int = *((int8_t *)GET_TABLE_WORD(target));
nv->valuetype = TYPE_INTEGER;
return (STAT_OK);
}
stat_t get_int32(nvObj_t *nv)
{
nv->value_int = *((uint32_t *)GET_TABLE_WORD(target));
nv->value_int = *((int32_t *)GET_TABLE_WORD(target));
nv->valuetype = TYPE_INTEGER;
return (STAT_OK);
}
stat_t get_data(nvObj_t *nv)
{
uint32_t *v = (uint32_t*)&nv->value_flt;
*v = *((uint32_t *)GET_TABLE_WORD(target));
nv->valuetype = TYPE_DATA;
return (STAT_OK);
}
stat_t get_flt(nvObj_t *nv)
{
nv->value_flt= *((float *)GET_TABLE_WORD(target));
@@ -249,18 +221,21 @@ stat_t get_flt(nvObj_t *nv)
return (STAT_OK);
}
stat_t get_data(nvObj_t *nv)
{
uint32_t *v = (uint32_t*)&nv->value_flt;
*v = *((uint32_t *)GET_TABLE_WORD(target));
nv->valuetype = TYPE_DATA;
return (STAT_OK);
}
/* Generic sets()
* set_noop() - set nothing and return OK
* set_nul() - set nothing and return READ_ONLY error
* set_ro() - set nothing, return read-only error
* set_ui8() - set value as 8 bit uint8_t value
* set_int8() - set value as an 8 bit int8_t value
* set_01() - set a 0 or 1 uint8_t value with validation
* set_012() - set a 0, 1 or 2 uint8_t value with validation
* set_0123() - set a 0, 1, 2 or 3 uint8_t value with validation
* set_uint() - set value as 32 bit unsigned integer
* set_data() - set value as 32 bit integer blind cast
* set_flt() - set value as float
* set_noop() - set nothing and return OK
* set_nul() - set nothing and return READ_ONLY error
* set_ro() - set nothing, return read-only error
* set_int32() - set value as 32 bit unsigned integer
* set_flt() - set value as float
* set_data() - set value as 32 bit integer blind cast
*/
stat_t set_noop(nvObj_t *nv) {
@@ -271,7 +246,6 @@ stat_t set_noop(nvObj_t *nv) {
stat_t set_nul(nvObj_t *nv) {
nv->valuetype = TYPE_NULL;
return (STAT_PARAMETER_IS_READ_ONLY); // this is what it should be
// return (STAT_OK); // hack until JSON is refactored
}
stat_t set_ro(nvObj_t *nv) {
@@ -282,74 +256,13 @@ stat_t set_ro(nvObj_t *nv) {
return (STAT_PARAMETER_IS_READ_ONLY);
}
stat_t set_ui8(nvObj_t *nv)
{
*((uint8_t *)GET_TABLE_WORD(target)) = nv->value_int;
nv->valuetype = TYPE_INTEGER;
return(STAT_OK);
}
stat_t set_int8(nvObj_t *nv)
{
*((int8_t *)GET_TABLE_WORD(target)) = (int8_t)nv->value_int;
nv->valuetype = TYPE_INTEGER;
return(STAT_OK);
}
stat_t set_01(nvObj_t *nv)
{
if (nv->value_int < 0) {
nv->valuetype = TYPE_NULL;
return (STAT_INPUT_LESS_THAN_MIN_VALUE);
}
if (nv->value_int > 1) {
nv->valuetype = TYPE_NULL;
return (STAT_INPUT_EXCEEDS_MAX_VALUE);
}
return (set_ui8(nv));
}
stat_t set_012(nvObj_t *nv)
{
if (nv->value_int < 0) {
nv->valuetype = TYPE_NULL;
return (STAT_INPUT_LESS_THAN_MIN_VALUE);
}
if (nv->value_int > 2) {
nv->valuetype = TYPE_NULL;
return (STAT_INPUT_EXCEEDS_MAX_VALUE);
}
return (set_ui8(nv));
}
stat_t set_0123(nvObj_t *nv)
{
if (nv->value_int < 0) {
nv->valuetype = TYPE_NULL;
return (STAT_INPUT_LESS_THAN_MIN_VALUE);
}
if (nv->value_int > 3) {
nv->valuetype = TYPE_NULL;
return (STAT_INPUT_EXCEEDS_MAX_VALUE);
}
return (set_ui8(nv));
}
stat_t set_int32(nvObj_t *nv)
{
*((uint32_t *)GET_TABLE_WORD(target)) = nv->value_int;
*((int32_t *)GET_TABLE_WORD(target)) = nv->value_int;
nv->valuetype = TYPE_INTEGER;
return(STAT_OK);
}
stat_t set_data(nvObj_t *nv)
{
uint32_t *v = (uint32_t*)&nv->value_flt;
*((uint32_t *)GET_TABLE_WORD(target)) = *v;
nv->valuetype = TYPE_DATA;
return(STAT_OK);
}
stat_t set_flt(nvObj_t *nv)
{
*((float *)GET_TABLE_WORD(target)) = nv->value_flt;
@@ -358,6 +271,14 @@ stat_t set_flt(nvObj_t *nv)
return(STAT_OK);
}
stat_t set_data(nvObj_t *nv)
{
uint32_t *v = (uint32_t*)&nv->value_flt;
*((uint32_t *)GET_TABLE_WORD(target)) = *v;
nv->valuetype = TYPE_DATA;
return(STAT_OK);
}
/************************************************************************************
* Group operations
*
+6 -14
View File
@@ -362,25 +362,17 @@ bool nv_index_lt_groups(index_t index); // (see config_app.c)
bool nv_group_is_prefixed(char *group);
// generic internal functions and accessors
stat_t get_nul(nvObj_t *nv); // get null value type
stat_t get_int32(nvObj_t *nv); // get int32_t integer value
stat_t get_flt(nvObj_t *nv); // get floating point value
stat_t get_data(nvObj_t *nv); // get uint32_t integer value blind cast
stat_t set_noop(nvObj_t *nv); // set nothing and return OK
stat_t set_nul(nvObj_t *nv); // set nothing and return READ_ONLY error
stat_t set_ro(nvObj_t *nv); // set nothing, return read-only error
stat_t set_ui8(nvObj_t *nv); // set uint8_t value
stat_t set_int8(nvObj_t *nv); // set signed 8 bit integer
stat_t set_01(nvObj_t *nv); // set a 0 or 1 value with validation
stat_t set_012(nvObj_t *nv); // set a 0, 1 or 2 value with validation
stat_t set_0123(nvObj_t *nv); // set a 0, 1, 2 or 3 value with validation
stat_t set_int32(nvObj_t *nv); // set int32_t integer value
stat_t set_data(nvObj_t *nv); // set uint32_t integer value blind cast
stat_t set_flt(nvObj_t *nv); // set floating point value
stat_t get_nul(nvObj_t *nv); // get null value type
stat_t get_bool(nvObj_t *nv); // get boolean value
stat_t get_ui8(nvObj_t *nv); // get uint8_t value
stat_t get_int8(nvObj_t *nv); // get signed 8 bit integer
stat_t get_int32(nvObj_t *nv); // get int32_t integer value
stat_t get_data(nvObj_t *nv); // get uint32_t integer value blind cast
stat_t get_flt(nvObj_t *nv); // get floating point value
stat_t set_data(nvObj_t *nv); // set uint32_t integer value blind cast
stat_t set_grp(nvObj_t *nv); // set data for a group
stat_t get_grp(nvObj_t *nv); // get data for a group
+56 -55
View File
@@ -132,7 +132,8 @@ const cfgItem_t cfgArray[] = {
{ "", "admo",_i0, 0, cm_print_admo, cm_get_admo, set_ro, (float *)&cs.null, 0 }, // arc distance mode
{ "", "frmo",_i0, 0, cm_print_frmo, cm_get_frmo, set_ro, (float *)&cs.null, 0 }, // feed rate mode
{ "", "tool",_i0, 0, cm_print_tool, cm_get_toolv,set_ro, (float *)&cs.null, 0 }, // active tool
{ "", "g92e",_i0, 0, cm_print_g92e, get_ui8, set_ro, (float *)&cm->gmx.origin_offset_enable, 0 }, // G92 enabled
{ "", "g92e",_i0, 0, cm_print_g92e, cm_get_g92e, set_ro, nullptr, 0 }, // G92 enable state
// { "", "g92e",_i0, 0, cm_print_g92e, get_ui8, set_ro, (float *)&cm->gmx.origin_offset_enable, 0 }, // G92 enabled
#ifdef TEMPORARY_HAS_LEDS
{ "", "_leds",_i0, 0, tx_print_nul, _get_leds,_set_leds, (float *)&cs.null, 0 }, // TEMPORARY - change LEDs
#endif
@@ -357,56 +358,56 @@ const cfgItem_t cfgArray[] = {
{ "c","czb",_fipc, 5, cm_print_zb, cm_get_zb, cm_set_zb, (float *)&cs.null, C_ZERO_BACKOFF },
// Digital input configs
{ "di1","di1mo",_iip, 0, io_print_mo, get_int8,io_set_mo, (float *)&d_in[0].mode, DI1_MODE },
{ "di1","di1ac",_iip, 0, io_print_ac, get_ui8, io_set_ac, (float *)&d_in[0].action, DI1_ACTION },
{ "di1","di1fn",_iip, 0, io_print_fn, get_ui8, io_set_fn, (float *)&d_in[0].function, DI1_FUNCTION },
{ "di1","di1mo",_iip, 0, io_print_mo, io_get_mo, io_set_mo, nullptr, DI1_MODE },
{ "di1","di1ac",_iip, 0, io_print_ac, io_get_ac, io_set_ac, nullptr, DI1_ACTION },
{ "di1","di1fn",_iip, 0, io_print_fn, io_get_fn, io_set_fn, nullptr, DI1_FUNCTION },
{ "di2","di2mo",_iip, 0, io_print_mo, get_int8,io_set_mo, (float *)&d_in[1].mode, DI2_MODE },
{ "di2","di2ac",_iip, 0, io_print_ac, get_ui8, io_set_ac, (float *)&d_in[1].action, DI2_ACTION },
{ "di2","di2fn",_iip, 0, io_print_fn, get_ui8, io_set_fn, (float *)&d_in[1].function, DI2_FUNCTION },
{ "di2","di2mo",_iip, 0, io_print_mo, io_get_mo, io_set_mo, nullptr, DI2_MODE },
{ "di2","di2ac",_iip, 0, io_print_ac, io_get_ac, io_set_ac, nullptr, DI2_ACTION },
{ "di2","di2fn",_iip, 0, io_print_fn, io_get_fn, io_set_fn, nullptr, DI2_FUNCTION },
{ "di3","di3mo",_iip, 0, io_print_mo, get_int8,io_set_mo, (float *)&d_in[2].mode, DI3_MODE },
{ "di3","di3ac",_iip, 0, io_print_ac, get_ui8, io_set_ac, (float *)&d_in[2].action, DI3_ACTION },
{ "di3","di3fn",_iip, 0, io_print_fn, get_ui8, io_set_fn, (float *)&d_in[2].function, DI3_FUNCTION },
{ "di3","di3mo",_iip, 0, io_print_mo, io_get_mo, io_set_mo, nullptr, DI3_MODE },
{ "di3","di3ac",_iip, 0, io_print_ac, io_get_ac, io_set_ac, nullptr, DI3_ACTION },
{ "di3","di3fn",_iip, 0, io_print_fn, io_get_fn, io_set_fn, nullptr, DI3_FUNCTION },
{ "di4","di4mo",_iip, 0, io_print_mo, get_int8,io_set_mo, (float *)&d_in[3].mode, DI4_MODE },
{ "di4","di4ac",_iip, 0, io_print_ac, get_ui8, io_set_ac, (float *)&d_in[3].action, DI4_ACTION },
{ "di4","di4fn",_iip, 0, io_print_fn, get_ui8, io_set_fn, (float *)&d_in[3].function, DI4_FUNCTION },
{ "di4","di4mo",_iip, 0, io_print_mo, io_get_mo, io_set_mo, nullptr, DI4_MODE },
{ "di4","di4ac",_iip, 0, io_print_ac, io_get_ac, io_set_ac, nullptr, DI4_ACTION },
{ "di4","di4fn",_iip, 0, io_print_fn, io_get_fn, io_set_fn, nullptr, DI4_FUNCTION },
{ "di5","di5mo",_iip, 0, io_print_mo, get_int8,io_set_mo, (float *)&d_in[4].mode, DI5_MODE },
{ "di5","di5ac",_iip, 0, io_print_ac, get_ui8, io_set_ac, (float *)&d_in[4].action, DI5_ACTION },
{ "di5","di5fn",_iip, 0, io_print_fn, get_ui8, io_set_fn, (float *)&d_in[4].function, DI5_FUNCTION },
{ "di5","di5mo",_iip, 0, io_print_mo, io_get_mo, io_set_mo, nullptr, DI5_MODE },
{ "di5","di5ac",_iip, 0, io_print_ac, io_get_ac, io_set_ac, nullptr, DI5_ACTION },
{ "di5","di5fn",_iip, 0, io_print_fn, io_get_fn, io_set_fn, nullptr, DI5_FUNCTION },
{ "di6","di6mo",_iip, 0, io_print_mo, get_int8,io_set_mo, (float *)&d_in[5].mode, DI6_MODE },
{ "di6","di6ac",_iip, 0, io_print_ac, get_ui8, io_set_ac, (float *)&d_in[5].action, DI6_ACTION },
{ "di6","di6fn",_iip, 0, io_print_fn, get_ui8, io_set_fn, (float *)&d_in[5].function, DI6_FUNCTION },
{ "di6","di6mo",_iip, 0, io_print_mo, io_get_mo, io_set_mo, nullptr, DI6_MODE },
{ "di6","di6ac",_iip, 0, io_print_ac, io_get_ac, io_set_ac, nullptr, DI6_ACTION },
{ "di6","di6fn",_iip, 0, io_print_fn, io_get_fn, io_set_fn, nullptr, DI6_FUNCTION },
{ "di7","di7mo",_iip, 0, io_print_mo, get_int8,io_set_mo, (float *)&d_in[6].mode, DI7_MODE },
{ "di7","di7ac",_iip, 0, io_print_ac, get_ui8, io_set_ac, (float *)&d_in[6].action, DI7_ACTION },
{ "di7","di7fn",_iip, 0, io_print_fn, get_ui8, io_set_fn, (float *)&d_in[6].function, DI7_FUNCTION },
{ "di7","di7mo",_iip, 0, io_print_mo, io_get_mo, io_set_mo, nullptr, DI7_MODE },
{ "di7","di7ac",_iip, 0, io_print_ac, io_get_ac, io_set_ac, nullptr, DI7_ACTION },
{ "di7","di7fn",_iip, 0, io_print_fn, io_get_fn, io_set_fn, nullptr, DI7_FUNCTION },
{ "di8","di8mo",_iip, 0, io_print_mo, get_int8,io_set_mo, (float *)&d_in[7].mode, DI8_MODE },
{ "di8","di8ac",_iip, 0, io_print_ac, get_ui8, io_set_ac, (float *)&d_in[7].action, DI8_ACTION },
{ "di8","di8fn",_iip, 0, io_print_fn, get_ui8, io_set_fn, (float *)&d_in[7].function, DI8_FUNCTION },
{ "di8","di8mo",_iip, 0, io_print_mo, io_get_mo, io_set_mo, nullptr, DI8_MODE },
{ "di8","di8ac",_iip, 0, io_print_ac, io_get_ac, io_set_ac, nullptr, DI8_ACTION },
{ "di8","di8fn",_iip, 0, io_print_fn, io_get_fn, io_set_fn, nullptr, DI8_FUNCTION },
#if (D_IN_CHANNELS >= 9)
{ "di9","di9mo",_iip, 0, io_print_mo, get_int8,io_set_mo, (float *)&d_in[8].mode, DI9_MODE },
{ "di9","di9ac",_iip, 0, io_print_ac, get_ui8, io_set_ac, (float *)&d_in[8].action, DI9_ACTION },
{ "di9","di9fn",_iip, 0, io_print_fn, get_ui8, io_set_fn, (float *)&d_in[8].function, DI9_FUNCTION },
{ "di9","di9mo",_iip, 0, io_print_mo, io_get_mo, io_set_mo, nullptr, DI9_MODE },
{ "di9","di9ac",_iip, 0, io_print_ac, io_get_ac, io_set_ac, nullptr, DI9_ACTION },
{ "di9","di9fn",_iip, 0, io_print_fn, io_get_fn, io_set_fn, nullptr, DI9_FUNCTION },
#endif
#if (D_IN_CHANNELS >= 10)
{ "di10","di10mo",_iip, 0, io_print_mo, get_int8,io_set_mo, (float *)&d_in[9].mode, DI10_MODE },
{ "di10","di10ac",_iip, 0, io_print_ac, get_ui8, io_set_ac, (float *)&d_in[9].action, DI10_ACTION },
{ "di10","di10fn",_iip, 0, io_print_fn, get_ui8, io_set_fn, (float *)&d_in[9].function, DI10_FUNCTION },
{ "di10","di10mo",_iip, 0, io_print_mo, io_get_mo, io_set_mo, nullptr, DI10_MODE },
{ "di10","di10ac",_iip, 0, io_print_ac, io_get_ac, io_set_ac, nullptr, DI10_ACTION },
{ "di10","di10fn",_iip, 0, io_print_fn, io_get_fn, io_set_fn, nullptr, DI10_FUNCTION },
#endif
#if (D_IN_CHANNELS >= 11)
{ "di11","di11mo",_iip, 0, io_print_mo, get_int8,io_set_mo, (float *)&d_in[10].mode, DI11_MODE },
{ "di11","di11ac",_iip, 0, io_print_ac, get_ui8, io_set_ac, (float *)&d_in[10].action, DI11_ACTION },
{ "di11","di11fn",_iip, 0, io_print_fn, get_ui8, io_set_fn, (float *)&d_in[10].function, DI11_FUNCTION },
{ "di11","di11mo",_iip, 0, io_print_mo, io_get_mo, io_set_mo, nullptr, DI1_MODE },
{ "di11","di11ac",_iip, 0, io_print_ac, io_get_ac, io_set_ac, nullptr, DI11_ACTION },
{ "di11","di11fn",_iip, 0, io_print_fn, io_get_fn, io_set_fn, nullptr, DI11_FUNCTION },
#endif
#if (D_IN_CHANNELS >= 12)
{ "di12","di12mo",_iip, 0, io_print_mo, get_int8,io_set_mo, (float *)&d_in[11].mode, DI12_MODE },
{ "di12","di12ac",_iip, 0, io_print_ac, get_ui8, io_set_ac, (float *)&d_in[11].action, DI12_ACTION },
{ "di12","di12fn",_iip, 0, io_print_fn, get_ui8, io_set_fn, (float *)&d_in[11].function, DI12_FUNCTION },
{ "di12","di12mo",_iip, 0, io_print_mo, io_get_mo, io_set_mo, nullptr, DI12_MODE },
{ "di12","di12ac",_iip, 0, io_print_ac, io_get_ac, io_set_ac, nullptr, DI12_ACTION },
{ "di12","di12fn",_iip, 0, io_print_fn, io_get_fn, io_set_fn, nullptr, DI12_FUNCTION },
#endif
// Digital input state readers
@@ -432,19 +433,19 @@ const cfgItem_t cfgArray[] = {
#endif
// digital output configs
{ "do1", "do1mo", _iip, 0, io_print_domode, get_int8, io_set_domode, (float *)&d_out[0].mode, DO1_MODE },
{ "do2", "do2mo", _iip, 0, io_print_domode, get_int8, io_set_domode, (float *)&d_out[1].mode, DO2_MODE },
{ "do3", "do3mo", _iip, 0, io_print_domode, get_int8, io_set_domode, (float *)&d_out[2].mode, DO3_MODE },
{ "do4", "do4mo", _iip, 0, io_print_domode, get_int8, io_set_domode, (float *)&d_out[3].mode, DO4_MODE },
{ "do5", "do5mo", _iip, 0, io_print_domode, get_int8, io_set_domode, (float *)&d_out[4].mode, DO5_MODE },
{ "do6", "do6mo", _iip, 0, io_print_domode, get_int8, io_set_domode, (float *)&d_out[5].mode, DO6_MODE },
{ "do7", "do7mo", _iip, 0, io_print_domode, get_int8, io_set_domode, (float *)&d_out[6].mode, DO7_MODE },
{ "do8", "do8mo", _iip, 0, io_print_domode, get_int8, io_set_domode, (float *)&d_out[7].mode, DO8_MODE },
{ "do9", "do9mo", _iip, 0, io_print_domode, get_int8, io_set_domode, (float *)&d_out[8].mode, DO9_MODE },
{ "do10","do10mo",_iip, 0, io_print_domode, get_int8, io_set_domode, (float *)&d_out[9].mode, DO10_MODE },
{ "do11","do11mo",_iip, 0, io_print_domode, get_int8, io_set_domode, (float *)&d_out[10].mode, DO11_MODE },
{ "do12","do12mo",_iip, 0, io_print_domode, get_int8, io_set_domode, (float *)&d_out[11].mode, DO12_MODE },
{ "do13","do13mo",_iip, 0, io_print_domode, get_int8, io_set_domode, (float *)&d_out[12].mode, DO13_MODE },
{ "do1", "do1mo", _iip, 0, io_print_domode, io_get_domode, io_set_domode, nullptr, DO1_MODE },
{ "do2", "do2mo", _iip, 0, io_print_domode, io_get_domode, io_set_domode, nullptr, DO2_MODE },
{ "do3", "do3mo", _iip, 0, io_print_domode, io_get_domode, io_set_domode, nullptr, DO3_MODE },
{ "do4", "do4mo", _iip, 0, io_print_domode, io_get_domode, io_set_domode, nullptr, DO4_MODE },
{ "do5", "do5mo", _iip, 0, io_print_domode, io_get_domode, io_set_domode, nullptr, DO5_MODE },
{ "do6", "do6mo", _iip, 0, io_print_domode, io_get_domode, io_set_domode, nullptr, DO6_MODE },
{ "do7", "do7mo", _iip, 0, io_print_domode, io_get_domode, io_set_domode, nullptr, DO7_MODE },
{ "do8", "do8mo", _iip, 0, io_print_domode, io_get_domode, io_set_domode, nullptr, DO8_MODE },
{ "do9", "do9mo", _iip, 0, io_print_domode, io_get_domode, io_set_domode, nullptr, DO9_MODE },
{ "do10","do10mo",_iip, 0, io_print_domode, io_get_domode, io_set_domode, nullptr, DO10_MODE },
{ "do11","do11mo",_iip, 0, io_print_domode, io_get_domode, io_set_domode, nullptr, DO11_MODE },
{ "do12","do12mo",_iip, 0, io_print_domode, io_get_domode, io_set_domode, nullptr, DO12_MODE },
{ "do13","do13mo",_iip, 0, io_print_domode, io_get_domode, io_set_domode, nullptr, DO13_MODE },
// Digital output state readers (default to non-active)
{ "out","out1", _i0, 2, io_print_out, io_get_output, io_set_output, (float *)&cs.null, 0 },
@@ -631,11 +632,11 @@ const cfgItem_t cfgArray[] = {
{ "sys","sl", _bipn, 0, cm_print_sl, cm_get_sl, cm_set_sl, (float *)&cs.null, SOFT_LIMIT_ENABLE },
{ "sys","lim", _bipn, 0, cm_print_lim, cm_get_lim, cm_set_lim, (float *)&cs.null, HARD_LIMIT_ENABLE },
{ "sys","saf", _bipn, 0, cm_print_saf, cm_get_saf, cm_set_saf, (float *)&cs.null, SAFETY_INTERLOCK_ENABLE },
{ "sys","m48", _bin, 0, cm_print_m48, cm_get_m48, cm_get_m48, (float *)&cs.null, 1 }, // M48/M49 feedrate & spindle override enable
{ "sys","froe",_bin, 0, cm_print_froe,cm_get_froe,cm_get_froe,(float *)&cs.null, FEED_OVERRIDE_ENABLE},
{ "sys","fro", _fin, 3, cm_print_fro, cm_get_fro, cm_set_fro, (float *)&cs.null, FEED_OVERRIDE_FACTOR},
{ "sys","troe",_bin, 0, cm_print_troe,cm_get_troe,cm_get_troe,(float *)&cs.null, TRAVERSE_OVERRIDE_ENABLE},
{ "sys","tro", _fin, 3, cm_print_tro, cm_get_tro, cm_set_tro, (float *)&cs.null, TRAVERSE_OVERRIDE_FACTOR},
{ "sys","m48", _bin, 0, cm_print_m48, cm_get_m48, cm_get_m48, (float *)&cs.null, 1 }, // M48/M49 feedrate & spindle override enable
{ "sys","froe",_bin, 0, cm_print_froe, cm_get_froe,cm_get_froe,(float *)&cs.null, FEED_OVERRIDE_ENABLE},
{ "sys","fro", _fin, 3, cm_print_fro, cm_get_fro, cm_set_fro, (float *)&cs.null, FEED_OVERRIDE_FACTOR},
{ "sys","troe",_bin, 0, cm_print_troe, cm_get_troe,cm_get_troe,(float *)&cs.null, TRAVERSE_OVERRIDE_ENABLE},
{ "sys","tro", _fin, 3, cm_print_tro, cm_get_tro, cm_set_tro, (float *)&cs.null, TRAVERSE_OVERRIDE_FACTOR},
{ "sys","mt", _fipn, 2, st_print_mt, st_get_mt, st_set_mt, (float *)&cs.null, MOTOR_POWER_TIMEOUT}, // N is seconds of timeout
{ "", "me", _f0, 0, st_print_me, get_nul, st_set_me, (float *)&cs.null, 0 }, // SET to enable motors
{ "", "md", _f0, 0, st_print_md, get_nul, st_set_md, (float *)&cs.null, 0 }, // SET to disable motors
+74 -103
View File
@@ -479,43 +479,59 @@ bool gpio_read_input(const uint8_t input_num_ext)
* These functions are not part of the NIST defined functions
***********************************************************************************/
static stat_t _input_set_helper(nvObj_t *nv, const int8_t lower_bound, const int8_t upper_bound)
/* HELPERS
* _io() - get IO number from the token as an array index (reduce by one)
*/
static uint8_t _io(const index_t index)
{
if ((nv->value_int < lower_bound) || (nv->value_int >= upper_bound)) {
return (STAT_INPUT_VALUE_RANGE_ERROR);
}
set_ui8(nv); // will this work if -1 is a valid value?
const char *ptr = cfgArray[index].token;
do {
if (isdigit(*ptr)) {
return (atoi(ptr)-1); // need to reduce by 1 for internal 0-based arrays
}
} while (++ptr != NUL);
return (0);
}
/*
* io_get_mo() - get input mode
* io_set_mo() - set input mode
* io_get_ac() - get input action
* io_set_ac() - set input action
* io_get_fn() - get input function
* io_set_fn() - set input function
*/
stat_t io_get_mo(nvObj_t *nv) { return(get_int(nv, d_in[_io(nv->index)].mode)); }
stat_t io_set_mo(nvObj_t *nv)
{
ritorno(set_int(nv, (uint8_t &)d_in[_io(nv->index)].mode, 0, IO_MODE_MAX));
if (cm_get_machine_state() != MACHINE_INITIALIZING) {
inputs_reset();
}
return (STAT_OK);
}
static stat_t _output_set_helper(nvObj_t *nv, const int8_t lower_bound, const int8_t upper_bound)
stat_t io_get_ac(nvObj_t *nv) { return(get_int(nv, d_in[_io(nv->index)].action)); }
stat_t io_set_ac(nvObj_t *nv)
{
if ((nv->value_int < lower_bound) || (nv->value_int >= upper_bound)) {
return (STAT_INPUT_VALUE_RANGE_ERROR);
}
set_ui8(nv); // will this work in -1 is a valid value?
ritorno(set_int(nv, (uint8_t &)d_in[_io(nv->index)].action, 0, INPUT_ACTION_MAX));
if (cm_get_machine_state() != MACHINE_INITIALIZING) {
outputs_reset();
inputs_reset();
}
return (STAT_OK);
}
stat_t io_set_mo(nvObj_t *nv) // input type or disabled
stat_t io_get_fn(nvObj_t *nv) { return(get_int(nv, d_in[_io(nv->index)].function)); }
stat_t io_set_fn(nvObj_t *nv)
{
return (_input_set_helper(nv, IO_ACTIVE_LOW, IO_MODE_MAX));
}
stat_t io_set_ac(nvObj_t *nv) // input action
{
return (_input_set_helper(nv, INPUT_ACTION_NONE, INPUT_ACTION_MAX));
}
stat_t io_set_fn(nvObj_t *nv) // input function
{
return (_input_set_helper(nv, INPUT_FUNCTION_NONE, INPUT_FUNCTION_MAX));
ritorno(set_int(nv, (uint8_t &)d_in[_io(nv->index)].function, 0, INPUT_FUNCTION_MAX));
if (cm_get_machine_state() != MACHINE_INITIALIZING) {
inputs_reset();
}
return (STAT_OK);
}
/*
@@ -523,40 +539,22 @@ stat_t io_set_fn(nvObj_t *nv) // input function
*/
stat_t io_get_input(nvObj_t *nv)
{
char *num_start = nv->token;
if (*(nv->group) == 0) {
// if we don't have a group, then the group name is in the token
// skip over "in"
num_start+=2;
}
nv->value_int = d_in[strtol(num_start, NULL, 10)-1].state;
if (nv->value_int > 1.1) {
nv->valuetype = TYPE_NULL;
} else {
nv->valuetype = TYPE_BOOLEAN;
}
nv->value_int = d_in[_io(nv->index)].state;
nv->valuetype = TYPE_INTEGER;
return (STAT_OK);
}
stat_t io_set_domode(nvObj_t *nv) // output function
/*
* io_get_domode() - get digital output mode
* io_set_domode() - set digital output mode
*/
stat_t io_get_domode(nvObj_t *nv) { return(get_int(nv, d_out[_io(nv->index)].mode)); }
stat_t io_set_domode(nvObj_t *nv) // output function
{
char *num_start = nv->token;
if (*(nv->group) == 0) {
// if we don't have a group, then the group name is in the token
// skip over "out"
num_start+=3;
}
// the token has been stripped down to an ASCII digit string - use it as an index
uint8_t output_num = strtol(num_start, NULL, 10);
if (output_num > D_OUT_CHANNELS) {
nv->valuetype = TYPE_NULL;
return(STAT_NO_GPIO);
}
uint8_t output_num = _io(nv->index); // returns 1 based output number (arrays)
// Force pins that aren't available to be "disabled"
switch (output_num) {
switch (output_num+1) { // add 1 to get logical pin numbers
case 1: if (output_1_pin.isNull()) { nv->value_int = IO_MODE_DISABLED; } break;
case 2: if (output_2_pin.isNull()) { nv->value_int = IO_MODE_DISABLED; } break;
case 3: if (output_3_pin.isNull()) { nv->value_int = IO_MODE_DISABLED; } break;
@@ -570,12 +568,14 @@ stat_t io_set_domode(nvObj_t *nv) // output function
case 11: if (output_11_pin.isNull()) { nv->value_int = IO_MODE_DISABLED; } break;
case 12: if (output_12_pin.isNull()) { nv->value_int = IO_MODE_DISABLED; } break;
case 13: if (output_13_pin.isNull()) { nv->value_int = IO_MODE_DISABLED; } break;
default:
break;
default: {}
}
return (_output_set_helper(nv, IO_ACTIVE_LOW, IO_MODE_MAX));
ritorno(set_int(nv, (uint8_t &)d_out[output_num].mode, 0, IO_MODE_MAX));
if (cm_get_machine_state() != MACHINE_INITIALIZING) {
outputs_reset();
}
return (STAT_OK);
}
/*
@@ -583,30 +583,16 @@ stat_t io_set_domode(nvObj_t *nv) // output function
*/
stat_t io_get_output(nvObj_t *nv)
{
char *num_start = nv->token;
if (*(nv->group) == 0) {
// if we don't have a group, then the group name is in the token
// skip over "out"
num_start+=3;
}
// the token has been stripped down to an ASCII digit string - use it as an index
uint8_t output_num = strtol(num_start, NULL, 10);
uint8_t output_num = _io(nv->index);
if (output_num > D_OUT_CHANNELS) {
nv->valuetype = TYPE_NULL;
return(STAT_NO_GPIO);
}
ioMode outMode = d_out[output_num-1].mode;
ioMode outMode = d_out[output_num].mode;
if (outMode == IO_MODE_DISABLED) {
// nv->value_int = 0;
nv->valuetype = TYPE_NULL; // reports back as NULL
} else {
nv->valuetype = TYPE_FLOAT;
nv->precision = 2;
bool invert = (outMode == 0);
// Note: !! forces a value to boolean 0 or 1
switch (output_num) {
switch (output_num+1) { // add 1 to get logical pin numbers
case 1: { nv->value_flt = (float)output_1_pin; } break;
case 2: { nv->value_flt = (float)output_2_pin; } break;
case 3: { nv->value_flt = (float)output_3_pin; } break;
@@ -620,45 +606,31 @@ stat_t io_get_output(nvObj_t *nv)
case 11: { nv->value_flt = (float)output_11_pin; } break;
case 12: { nv->value_flt = (float)output_12_pin; } break;
case 13: { nv->value_flt = (float)output_13_pin; } break;
default:
{
// nv->value = 0; // inactive
nv->valuetype = TYPE_NULL; // reports back as NULL
}
default: { nv->valuetype = TYPE_NULL; } // reports back as NULL
}
if (invert) {
nv->value_flt = 1.0 - nv->value_flt;
if (outMode == IO_ACTIVE_LOW) {
nv->value_flt = 1.0 - nv->value_flt; // invert output sense
}
}
return (STAT_OK);
}
/*
* io_set_output() - return output state given an nv object
* io_set_output() - read and return output state given an nv object
*/
stat_t io_set_output(nvObj_t *nv)
{
char *num_start = nv->token;
if (*(nv->group) == 0) {
// if we don't have a group, then the group name is in the token
// skip over "out"
num_start+=3;
}
// the token has been stripped down to an ASCII digit string - use it as an index
uint8_t output_num = strtol(num_start, NULL, 10);
uint8_t output_num = _io(nv->index);
ioMode outMode = d_out[output_num-1].mode;
if (outMode == IO_MODE_DISABLED) {
nv->value_flt = 0; // Inactive?
nv->valuetype = TYPE_NULL; // reports back as NULL
} else {
bool invert = (outMode == 0);
float value = nv->value_flt;
if (invert) {
value = 1.0 - value;
}
switch (output_num) {
// send normal or inverted value to output
float value = (outMode == IO_ACTIVE_HIGH) ? nv->value_flt : 1.0 - nv->value_flt;
switch (output_num+1) { // add 1 to get logical pin numbers
// Generated with:
// perl -e 'for($i=1;$i<14;$i++) { print "case ${i}: { output_${i}_pin = value; } break;\n";}'
// BEGIN generated
@@ -671,12 +643,11 @@ stat_t io_set_output(nvObj_t *nv)
case 7: { output_7_pin = value; } break;
case 8: { output_8_pin = value; } break;
case 9: { output_9_pin = value; } break;
case 10: { output_10_pin = value; } break;
case 11: { output_11_pin = value; } break;
case 12: { output_12_pin = value; } break;
case 13: { output_13_pin = value; } break;
// END generated
default: { nv->value_flt = 0; } // inactive
case 10: { output_10_pin = value; } break;
case 11: { output_11_pin = value; } break;
case 12: { output_12_pin = value; } break;
case 13: { output_13_pin = value; } break; // END generated
default: { nv->value_flt = 0; } // inactive
}
}
return (STAT_OK);
+10 -7
View File
@@ -47,9 +47,9 @@
typedef enum {
IO_ACTIVE_LOW = 0, // input is active low (aka normally open)
IO_ACTIVE_HIGH = 1, // input is active high (aka normally closed)
IO_MODE_DISABLED = 2, // input is disabled
IO_MODE_MAX // unused. Just for range checking
IO_MODE_DISABLED = 2 // input is disabled
} ioMode;
#define IO_MODE_MAX IO_MODE_DISABLED
#define NORMALLY_OPEN IO_ACTIVE_LOW // equivalent
#define NORMALLY_CLOSED IO_ACTIVE_HIGH // equivalent
@@ -80,18 +80,18 @@ typedef enum { // actions are initiated from within the
INPUT_ACTION_ALARM, // initiate an alarm. stops everything immediately - preserves position
INPUT_ACTION_SHUTDOWN, // initiate a shutdown. stops everything immediately - does not preserve position
INPUT_ACTION_PANIC, // initiate a panic. stops everything immediately - does not preserve position
INPUT_ACTION_RESET, // reset system
INPUT_ACTION_MAX // unused. Just for range checking
INPUT_ACTION_RESET // reset system
} inputAction;
#define INPUT_ACTION_MAX INPUT_ACTION_RESET
typedef enum { // functions are requested from the ISR, run from the main loop
INPUT_FUNCTION_NONE = 0,
INPUT_FUNCTION_LIMIT = 1, // limit switch processing
INPUT_FUNCTION_INTERLOCK = 2, // interlock processing
INPUT_FUNCTION_SHUTDOWN = 3, // shutdown in support of external emergency stop
INPUT_FUNCTION_PROBE = 4, // assign input as probe input
INPUT_FUNCTION_MAX // unused. Just for range checking
INPUT_FUNCTION_PROBE = 4 // assign input as probe input
} inputFunc;
#define INPUT_FUNCTION_MAX INPUT_FUNCTION_PROBE
typedef enum {
INPUT_INACTIVE = 0, // aka switch open, also read as 'false'
@@ -151,13 +151,16 @@ void gpio_set_homing_mode(const uint8_t input_num, const bool is_homing);
void gpio_set_probing_mode(const uint8_t input_num, const bool is_probing);
int8_t gpio_get_probing_input(void);
stat_t io_get_mo(nvObj_t *nv);
stat_t io_set_mo(nvObj_t *nv);
stat_t io_get_ac(nvObj_t *nv);
stat_t io_set_ac(nvObj_t *nv);
stat_t io_get_fn(nvObj_t *nv);
stat_t io_set_fn(nvObj_t *nv);
stat_t io_get_input(nvObj_t *nv);
stat_t io_get_domode(nvObj_t *nv); // output sense
stat_t io_set_domode(nvObj_t *nv); // output sense
stat_t io_get_output(nvObj_t *nv);
stat_t io_set_output(nvObj_t *nv);
+1 -1
View File
@@ -61,7 +61,7 @@ stat_t rpt_exception(stat_t status, const char *msg)
if (cs.controller_state >= CONTROLLER_READY) {
char buffer[128];
sprintf(buffer, "{\"er\":{\"fb\":%0.2f,\"st\":%d,\"msg\":\"%s - %s\"}}\n",
G2CORE_FIRMWARE_BUILD, status, get_status_message(status), msg);
G2CORE_FIRMWARE_BUILD, status, get_status_message(status), msg);
xio_writeline(buffer);
}
}