From ecd7fecf9f2ed67ea5719193f8f96fe289fe922f Mon Sep 17 00:00:00 2001 From: Paciente8159 Date: Tue, 24 Sep 2024 12:12:55 +0100 Subject: [PATCH] broadcast improvements and cleaning - broadcast improvements with broadcast auto reset - code cleaning --- uCNC/src/cnc.c | 2 +- uCNC/src/core/parser.c | 11 +- uCNC/src/hal/mcus/esp32/esp32_arduino.cpp | 26 +-- uCNC/src/hal/mcus/esp8266/esp8266_arduino.cpp | 26 +-- uCNC/src/hal/mcus/rp2040/rp2040_arduino.cpp | 26 +-- uCNC/src/interface/grbl_interface.h | 2 +- uCNC/src/interface/grbl_protocol.c | 183 ++++----------- uCNC/src/interface/grbl_protocol.h | 8 +- uCNC/src/interface/grbl_stream.c | 7 +- uCNC/src/interface/grbl_stream.h | 2 +- uCNC/src/interface/print.c | 24 +- uCNC/src/interface/settings.c | 215 +----------------- 12 files changed, 114 insertions(+), 418 deletions(-) diff --git a/uCNC/src/cnc.c b/uCNC/src/cnc.c index 94780c7d..830c1712 100644 --- a/uCNC/src/cnc.c +++ b/uCNC/src/cnc.c @@ -650,7 +650,7 @@ void cnc_reset(void) #ifdef ENABLE_MAIN_LOOP_MODULES EVENT_INVOKE(cnc_reset, NULL); #endif - grbl_stream_broadcast(true); + grbl_stream_start_broadcast(); grbl_protocol_print(MSG_STARTUP); } diff --git a/uCNC/src/core/parser.c b/uCNC/src/core/parser.c index 47285270..51ebad91 100644 --- a/uCNC/src/core/parser.c +++ b/uCNC/src/core/parser.c @@ -482,7 +482,7 @@ static uint8_t parser_grbl_command(void) settings_save(block_address, NULL, UINT16_MAX); // run startup block - grbl_stream_broadcast(true); + grbl_stream_start_broadcast(); grbl_stream_eeprom(block_address); // checks the command validity error = parser_fetch_command(&next_state, &words, &cmd); @@ -493,7 +493,7 @@ static uint8_t parser_grbl_command(void) // error = parser_validate_command(&next_state, &words, &cmd); // } - grbl_stream_broadcast(false); + // reset streams grbl_stream_change(NULL); @@ -721,7 +721,7 @@ static uint8_t parser_fetch_command(parser_state_t *new_state, parser_words_t *w #ifdef ECHO_CMD if (!wordcount) { - grbl_stream_broadcast(true); + grbl_stream_start_broadcast(); grbl_protocol_print(MSG_ECHO); } #endif @@ -733,7 +733,7 @@ static uint8_t parser_fetch_command(parser_state_t *new_state, parser_words_t *w parser_discard_command(); #ifdef ECHO_CMD grbl_protocol_print(MSG_END); - grbl_stream_broadcast(false); + #endif return error; } @@ -791,7 +791,7 @@ static uint8_t parser_fetch_command(parser_state_t *new_state, parser_words_t *w DEBUG_PUTC('\n'); #ifdef ECHO_CMD grbl_protocol_print(MSG_END); - grbl_stream_broadcast(false); + #endif return STATUS_OK; case 'G': @@ -835,7 +835,6 @@ static uint8_t parser_fetch_command(parser_state_t *new_state, parser_words_t *w parser_discard_command(); #ifdef ECHO_CMD grbl_protocol_print(MSG_END); - grbl_stream_broadcast(false); #endif return error; } diff --git a/uCNC/src/hal/mcus/esp32/esp32_arduino.cpp b/uCNC/src/hal/mcus/esp32/esp32_arduino.cpp index ec6054fe..567a639e 100644 --- a/uCNC/src/hal/mcus/esp32/esp32_arduino.cpp +++ b/uCNC/src/hal/mcus/esp32/esp32_arduino.cpp @@ -153,7 +153,7 @@ extern "C" grbl_protocol_feedback("AP started"); grbl_protocol_feedback("SSID>" BOARD_NAME); sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str()); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); break; default: WiFi.mode(WIFI_AP_STA); @@ -163,7 +163,7 @@ extern "C" grbl_protocol_feedback("AP started"); grbl_protocol_feedback("SSID>" BOARD_NAME); sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str()); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); break; } @@ -206,7 +206,7 @@ extern "C" else { sprintf((char *)str, "SSID>%s", wifi_settings.ssid); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); } *(cmd_params->error) = STATUS_OK; return EVENT_HANDLED; @@ -225,13 +225,13 @@ extern "C" // print the list of networks seen: sprintf((char *)str, "%d available networks", numSsid); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); // print the network number and name for each network found: for (int netid = 0; netid < numSsid; netid++) { sprintf((char *)str, "%d) %s\tSignal: %ddBm", netid, WiFi.SSID(netid).c_str(), WiFi.RSSI(netid)); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); } *(cmd_params->error) = STATUS_OK; return EVENT_HANDLED; @@ -320,17 +320,17 @@ extern "C" { case 1: sprintf((char *)str, "IP>%s", WiFi.localIP().toString().c_str()); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); break; case 2: sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str()); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); break; default: sprintf((char *)str, "STA IP>%s", WiFi.localIP().toString().c_str()); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); sprintf((char *)str, "AP IP>%s", WiFi.softAPIP().toString().c_str()); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); break; } } @@ -379,9 +379,9 @@ extern "C" connected = true; grbl_protocol_feedback("Connected to WiFi"); sprintf((char *)str, "SSID>%s", wifi_settings.ssid); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); sprintf((char *)str, "IP>%s", WiFi.localIP().toString().c_str()); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); } if (telnet_server.hasClient()) @@ -812,7 +812,7 @@ extern "C" grbl_protocol_feedback("AP started"); grbl_protocol_feedback("SSID>" BOARD_NAME); sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str()); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); break; default: WiFi.mode(WIFI_AP_STA); @@ -822,7 +822,7 @@ extern "C" grbl_protocol_feedback("AP started"); grbl_protocol_feedback("SSID>" BOARD_NAME); sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str()); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); break; } } diff --git a/uCNC/src/hal/mcus/esp8266/esp8266_arduino.cpp b/uCNC/src/hal/mcus/esp8266/esp8266_arduino.cpp index c68e8c5d..c4761653 100644 --- a/uCNC/src/hal/mcus/esp8266/esp8266_arduino.cpp +++ b/uCNC/src/hal/mcus/esp8266/esp8266_arduino.cpp @@ -115,7 +115,7 @@ extern "C" grbl_protocol_feedback("AP started"); grbl_protocol_feedback("SSID>" BOARD_NAME); sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str()); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); break; default: WiFi.mode(WIFI_AP_STA); @@ -125,7 +125,7 @@ extern "C" grbl_protocol_feedback("AP started"); grbl_protocol_feedback("SSID>" BOARD_NAME); sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str()); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); break; } @@ -168,7 +168,7 @@ extern "C" else { sprintf((char *)str, "SSID>%s", wifi_settings.ssid); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); } *(cmd_params->error) = STATUS_OK; return EVENT_HANDLED; @@ -187,13 +187,13 @@ extern "C" // print the list of networks seen: sprintf((char *)str, "%d available networks", numSsid); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); // print the network number and name for each network found: for (int netid = 0; netid < numSsid; netid++) { sprintf((char *)str, "%d) %s\tSignal: %ddBm", netid, WiFi.SSID(netid).c_str(), WiFi.RSSI(netid)); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); } *(cmd_params->error) = STATUS_OK; return EVENT_HANDLED; @@ -284,17 +284,17 @@ extern "C" { case 1: sprintf((char *)str, "STA IP>%s", WiFi.localIP().toString().c_str()); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); sprintf((char *)str, "AP IP>%s", WiFi.softAPIP().toString().c_str()); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); break; case 2: sprintf((char *)str, "IP>%s", WiFi.localIP().toString().c_str()); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); break; default: sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str()); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); break; } } @@ -343,9 +343,9 @@ extern "C" connected = true; grbl_protocol_feedback("Connected to WiFi"); sprintf((char *)str, "SSID>%s", wifi_settings.ssid); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); sprintf((char *)str, "IP>%s", WiFi.localIP().toString().c_str()); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); } if (telnet_server.hasClient()) @@ -756,7 +756,7 @@ extern "C" grbl_protocol_feedback("AP started"); grbl_protocol_feedback("SSID>" BOARD_NAME); sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str()); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); break; default: WiFi.mode(WIFI_AP_STA); @@ -766,7 +766,7 @@ extern "C" grbl_protocol_feedback("AP started"); grbl_protocol_feedback("SSID>" BOARD_NAME); sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str()); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); break; } } diff --git a/uCNC/src/hal/mcus/rp2040/rp2040_arduino.cpp b/uCNC/src/hal/mcus/rp2040/rp2040_arduino.cpp index d6f9e207..be5d7255 100644 --- a/uCNC/src/hal/mcus/rp2040/rp2040_arduino.cpp +++ b/uCNC/src/hal/mcus/rp2040/rp2040_arduino.cpp @@ -155,7 +155,7 @@ bool mcu_custom_grbl_cmd(void *args) grbl_protocol_feedback("AP started"); grbl_protocol_feedback("SSID>" BOARD_NAME); sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str()); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); break; default: WiFi.mode(WIFI_AP_STA); @@ -165,7 +165,7 @@ bool mcu_custom_grbl_cmd(void *args) grbl_protocol_feedback("AP started"); grbl_protocol_feedback("SSID>" BOARD_NAME); sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str()); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); break; } @@ -207,7 +207,7 @@ bool mcu_custom_grbl_cmd(void *args) else { sprintf((char *)str, "SSID>%s", wifi_settings.ssid); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); } *(cmd_params->error) = STATUS_OK; return EVENT_HANDLED; @@ -226,13 +226,13 @@ bool mcu_custom_grbl_cmd(void *args) // print the list of networks seen: sprintf((char *)str, "%d available networks", numSsid); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); // print the network number and name for each network found: for (int netid = 0; netid < numSsid; netid++) { sprintf((char *)str, "%d) %s\tSignal: %ddBm", netid, WiFi.SSID(netid), WiFi.RSSI(netid)); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); } *(cmd_params->error) = STATUS_OK; return EVENT_HANDLED; @@ -320,17 +320,17 @@ bool mcu_custom_grbl_cmd(void *args) { case 1: sprintf((char *)str, "STA IP>%s", WiFi.localIP().toString().c_str()); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); sprintf((char *)str, "AP IP>%s", WiFi.softAPIP().toString().c_str()); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); break; case 2: sprintf((char *)str, "IP>%s", WiFi.localIP().toString().c_str()); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); break; default: sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str()); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); break; } } @@ -379,9 +379,9 @@ bool rp2040_wifi_clientok(void) connected = true; grbl_protocol_feedback("Connected to WiFi"); sprintf((char *)str, "SSID>%s", wifi_settings.ssid); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); sprintf((char *)str, "IP>%s", WiFi.localIP().toString().c_str()); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); } if (telnet_server.hasClient()) @@ -789,7 +789,7 @@ void rp2040_wifi_bt_init(void) grbl_protocol_feedback("AP started"); grbl_protocol_feedback("SSID>" BOARD_NAME); sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str()); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); break; default: WiFi.mode(WIFI_AP_STA); @@ -799,7 +799,7 @@ void rp2040_wifi_bt_init(void) grbl_protocol_feedback("AP started"); grbl_protocol_feedback("SSID>" BOARD_NAME); sprintf((char *)str, "IP>%s", WiFi.softAPIP().toString().c_str()); - grbl_protocol_sprintf(str); + grbl_protocol_feedback("%s", str); break; } } diff --git a/uCNC/src/interface/grbl_interface.h b/uCNC/src/interface/grbl_interface.h index 3dc25416..6733d830 100644 --- a/uCNC/src/interface/grbl_interface.h +++ b/uCNC/src/interface/grbl_interface.h @@ -177,7 +177,7 @@ extern "C" #define MSG_HELP "[HLP:$$ $# $G $I $N $x=val $Nx=line $J=line $C $X $H ~ ! ? ctrl-x]" MSG_EOL // Non query feedback messages -#define MSG_START "[MSG:" +#define MSG_START "MSG:" #define MSG_END "]" MSG_EOL #define MSG_FEEDBACK MSG_START "%S" MSG_END #define MSG_FEEDBACK_PRINTF MSG_START "%s" MSG_END diff --git a/uCNC/src/interface/grbl_protocol.c b/uCNC/src/interface/grbl_protocol.c index e32682ed..05f07473 100644 --- a/uCNC/src/interface/grbl_protocol.c +++ b/uCNC/src/interface/grbl_protocol.c @@ -252,25 +252,39 @@ void grbl_protocol_error(uint8_t error) void grbl_protocol_alarm(int8_t alarm) { - grbl_stream_broadcast(true); + grbl_stream_start_broadcast(); grbl_protocol_printf(MSG_ALARM, alarm); - grbl_stream_broadcast(false); } -void grbl_protocol_feedback_base(void *arg, uint8_t type) +void grbl_protocol_feedback_fmt(const char *fmt, bool is_feedback, ...) { - grbl_stream_broadcast(true); - if (type) + va_list args; + va_start(args, is_feedback); + grbl_stream_start_broadcast(); + grbl_protocol_putc('['); + if (is_feedback) { - grbl_protocol_printf(MSG_FEEDBACK_PRINTF, arg); + grbl_protocol_print(MSG_START); } - else - { - grbl_protocol_printf(MSG_FEEDBACK, arg); - } - grbl_stream_broadcast(false); + print_fmtva(grbl_stream_putc, NULL, fmt, &args); + grbl_protocol_print(MSG_END); + va_end(args); } +// void grbl_protocol_feedback_base(void *arg, uint8_t type) +// { +// grbl_stream_start_broadcast(); +// if (type) +// { +// grbl_protocol_printf(MSG_FEEDBACK_PRINTF, arg); +// } +// else +// { +// grbl_protocol_printf(MSG_FEEDBACK, arg); +// } + +// } + WEAK_EVENT_HANDLER(grbl_protocol_status) { // custom handler @@ -347,7 +361,7 @@ void grbl_protocol_status(void) return; } - grbl_stream_broadcast(true); + grbl_stream_start_broadcast(); float axis[MAX(AXIS_COUNT, 3)]; @@ -549,28 +563,28 @@ void grbl_protocol_gcode_coordsys(void) for (uint8_t i = 0; i < COORD_SYS_COUNT; i++) { parser_get_coordsys(i, axis); - grbl_protocol_printf("G%d:" MSG_AXIS "]" MSG_EOL, (i + 54), axis); + grbl_protocol_info("G%d:" MSG_AXIS, (i + 54), axis); } #if COORD_SYS_COUNT >= 6 for (uint8_t i = 6; i < COORD_SYS_COUNT; i++) { parser_get_coordsys(i, axis); - grbl_protocol_printf("G59.%d:" MSG_AXIS "]" MSG_EOL, (i - 5), axis); + grbl_protocol_info("G59.%d:" MSG_AXIS, (i - 5), axis); } #endif parser_get_coordsys(28, axis); - grbl_protocol_printf("G28:" MSG_AXIS "]" MSG_EOL, axis); + grbl_protocol_info("G28:" MSG_AXIS, axis); parser_get_coordsys(30, axis); - grbl_protocol_printf("G30:" MSG_AXIS "]" MSG_EOL, axis); + grbl_protocol_info("G30:" MSG_AXIS, axis); parser_get_coordsys(92, axis); - grbl_protocol_printf("G92:" MSG_AXIS "]" MSG_EOL, axis); + grbl_protocol_info("G92:" MSG_AXIS, axis); #ifdef AXIS_TOOL parser_get_coordsys(254, axis); - grbl_protocol_printf("[TLO:%1f]" MSG_EOL, axis); + grbl_protocol_info("TLO:%1f", axis); #endif grbl_protocol_probe_result(parser_get_probe_result()); @@ -581,7 +595,7 @@ void grbl_protocol_probe_result(uint8_t val) { float axis[MAX(AXIS_COUNT, 3)]; parser_get_coordsys(255, axis); - grbl_protocol_printf("PRB:" MSG_AXIS ":%d]" MSG_EOL, axis, val); + grbl_protocol_info("PRB:" MSG_AXIS ":%d", axis, val); } static void grbl_protocol_parser_modalstate(uint8_t word, uint8_t val, uint8_t mantissa) @@ -605,7 +619,7 @@ void grbl_protocol_gcode_modes(void) parser_get_modes(modalgroups, &feed, &spindle); - grbl_stream_broadcast(true); + grbl_stream_start_broadcast(); grbl_protocol_print("[GC:"); @@ -659,7 +673,7 @@ void grbl_protocol_gcode_modes(void) // permanent M9 grbl_protocol_print("M9 "); #endif - grbl_protocol_printf("M%d T%d F%f S%lu]" MSG_EOL, modalgroups[10], modalgroups[11], feed, spindle); + grbl_protocol_printf("M%d T%d F%f S%lu" MSG_END, modalgroups[10], modalgroups[11], feed, spindle); } void grbl_protocol_gcode_setting_line_int(setting_offset_t setting, uint16_t value) @@ -723,7 +737,7 @@ void grbl_protocol_cnc_settings(void) switch (SETTING_TYPE_MASK(s.type)) { case 1: - val = (uint32_t) * ((bool *)s.memptr); + val = (uint32_t)((bool *)s.memptr)[j]; grbl_protocol_gcode_setting_line_int(s.id, val); break; case 2: @@ -735,125 +749,16 @@ void grbl_protocol_cnc_settings(void) grbl_protocol_gcode_setting_line_int(s.id, val); break; default: - grbl_protocol_gcode_setting_line_flt(s.id, *((float *)s.memptr)); + grbl_protocol_gcode_setting_line_flt(s.id, ((float *)s.memptr)[j]); break; } + s.id++; } } - /* - grbl_protocol_gcode_setting_line_flt(0, (1000000.0f / g_settings.max_step_rate)); -#if EMULATE_GRBL_STARTUP > 0 || defined(ENABLE_STEPPERS_DISABLE_TIMEOUT) -// just adds this for compatibility -// this setting is not used -#ifdef ENABLE_STEPPERS_DISABLE_TIMEOUT - grbl_protocol_gcode_setting_line_int(1, g_settings.step_disable_timeout); -#else - grbl_protocol_gcode_setting_line_int(1, 0); -#endif -#endif - grbl_protocol_gcode_setting_line_int(2, g_settings.step_invert_mask); - grbl_protocol_gcode_setting_line_int(3, g_settings.dir_invert_mask); - grbl_protocol_gcode_setting_line_int(4, g_settings.step_enable_invert); - grbl_protocol_gcode_setting_line_int(5, g_settings.limits_invert_mask); - grbl_protocol_gcode_setting_line_int(6, g_settings.probe_invert_mask); - grbl_protocol_gcode_setting_line_int(7, g_settings.control_invert_mask); -#if ENCODERS > 0 - grbl_protocol_gcode_setting_line_int(8, g_settings.encoders_pulse_invert_mask); - grbl_protocol_gcode_setting_line_int(9, g_settings.encoders_dir_invert_mask); -#endif - grbl_protocol_gcode_setting_line_int(10, g_settings.status_report_mask); - grbl_protocol_gcode_setting_line_flt(11, g_settings.g64_angle_factor); - grbl_protocol_gcode_setting_line_flt(12, g_settings.arc_tolerance); - grbl_protocol_gcode_setting_line_int(13, g_settings.report_inches); -#if S_CURVE_ACCELERATION_LEVEL == -1 - grbl_protocol_gcode_setting_line_int(14, g_settings.s_curve_profile); -#endif - grbl_protocol_gcode_setting_line_int(20, g_settings.soft_limits_enabled); - grbl_protocol_gcode_setting_line_int(21, g_settings.hard_limits_enabled); - grbl_protocol_gcode_setting_line_int(22, g_settings.homing_enabled); - grbl_protocol_gcode_setting_line_int(23, g_settings.homing_dir_invert_mask); - grbl_protocol_gcode_setting_line_flt(24, g_settings.homing_slow_feed_rate); - grbl_protocol_gcode_setting_line_flt(25, g_settings.homing_fast_feed_rate); - grbl_protocol_gcode_setting_line_int(26, g_settings.debounce_ms); - grbl_protocol_gcode_setting_line_flt(27, g_settings.homing_offset); -#if (KINEMATIC == KINEMATIC_DELTA) - grbl_protocol_gcode_setting_line_flt(28, g_settings.delta_bicep_homing_angle); -#elif (KINEMATIC == KINEMATIC_SCARA) - grbl_protocol_gcode_setting_line_flt(28, g_settings.scara_arm_homing_angle); - grbl_protocol_gcode_setting_line_flt(29, g_settings.scara_forearm_homing_angle); -#endif - grbl_protocol_gcode_setting_line_int(30, g_settings.spindle_max_rpm); - grbl_protocol_gcode_setting_line_int(31, g_settings.spindle_min_rpm); - grbl_protocol_gcode_setting_line_int(32, g_settings.laser_mode); -#ifdef ENABLE_LASER_PPI - grbl_protocol_gcode_setting_line_int(33, g_settings.laser_ppi); - grbl_protocol_gcode_setting_line_int(34, g_settings.laser_ppi_uswidth); - grbl_protocol_gcode_setting_line_flt(35, g_settings.laser_ppi_mixmode_ppi); - grbl_protocol_gcode_setting_line_flt(36, g_settings.laser_ppi_mixmode_uswidth); -#endif -#ifdef ENABLE_SKEW_COMPENSATION - grbl_protocol_gcode_setting_line_flt(37, g_settings.skew_xy_factor); -#ifndef SKEW_COMPENSATION_XY_ONLY - grbl_protocol_gcode_setting_line_flt(38, g_settings.skew_xz_factor); - grbl_protocol_gcode_setting_line_flt(39, g_settings.skew_yz_factor); -#endif -#endif - -#if TOOL_COUNT > 0 -#if TOOL_COUNT > 1 - grbl_protocol_gcode_setting_line_int(80, g_settings.default_tool); -#endif - for (uint8_t i = 0; i < TOOL_COUNT; i++) - { - grbl_protocol_gcode_setting_line_flt(81 + i, g_settings.tool_length_offset[i]); - } -#endif - - for (uint8_t i = 0; i < AXIS_COUNT; i++) - { - grbl_protocol_gcode_setting_line_flt(100 + i, g_settings.step_per_mm[i]); - } - -#if (KINEMATIC == KINEMATIC_LINEAR_DELTA) - grbl_protocol_gcode_setting_line_flt(106, g_settings.delta_arm_length); - grbl_protocol_gcode_setting_line_flt(107, g_settings.delta_armbase_radius); - // grbl_protocol_gcode_setting_line_int(108, g_settings.delta_efector_height); -#elif (KINEMATIC == KINEMATIC_DELTA) - grbl_protocol_gcode_setting_line_flt(106, g_settings.delta_base_radius); - grbl_protocol_gcode_setting_line_flt(107, g_settings.delta_effector_radius); - grbl_protocol_gcode_setting_line_flt(108, g_settings.delta_bicep_length); - grbl_protocol_gcode_setting_line_flt(109, g_settings.delta_forearm_length); -#elif (KINEMATIC == KINEMATIC_SCARA) - grbl_protocol_gcode_setting_line_flt(106, g_settings.scara_arm_length); - grbl_protocol_gcode_setting_line_flt(107, g_settings.scara_forearm_length); -#endif - - for (uint8_t i = 0; i < AXIS_COUNT; i++) - { - grbl_protocol_gcode_setting_line_flt(110 + i, g_settings.max_feed_rate[i]); - } - - for (uint8_t i = 0; i < AXIS_COUNT; i++) - { - grbl_protocol_gcode_setting_line_flt(120 + i, g_settings.acceleration[i]); - } - - for (uint8_t i = 0; i < AXIS_COUNT; i++) - { - grbl_protocol_gcode_setting_line_flt(130 + i, g_settings.max_distance[i]); - } - -#ifdef ENABLE_BACKLASH_COMPENSATION - for (uint8_t i = 0; i < AXIS_TO_STEPPERS; i++) - { - grbl_protocol_gcode_setting_line_int(140 + i, g_settings.backlash_steps[i]); - } -#endif -*/ #ifdef ENABLE_SETTINGS_MODULES EVENT_INVOKE(grbl_protocol_cnc_settings, NULL); - grbl_stream_broadcast(false); + #endif protocol_busy = false; } @@ -1065,7 +970,7 @@ void grbl_protocol_pins_states(void) #define EXTENDED_VER "[VER+:" #endif #define OPT_INFO EXTENDED_OPT KINEMATIC_INFO LINES_INFO BRESENHAM_INFO DSS_INFO DYNACCEL_INFO SKEW_INFO LINPLAN_INFO HMAP_INFO PPI_INFO INVESTOP_INFO SPOLL_INFO CONTROLS_INFO LIMITS_INFO PROBE_INFO IODBG_INFO SETTINGS_INFO EXTRACMD_INFO FASTMATH_INFO -#define VER_INFO EXTENDED_VER " uCNC " CNC_VERSION " - " BOARD_NAME "]" STR_EOL +#define VER_INFO EXTENDED_VER " uCNC " CNC_VERSION " - " BOARD_NAME "]" MSG_EOL WEAK_EVENT_HANDLER(grbl_protocol_cnc_info) { @@ -1091,19 +996,19 @@ void grbl_protocol_cnc_info(bool extended) grbl_protocol_print(VER_INFO); grbl_protocol_print(OPT_INFO); EVENT_INVOKE(grbl_protocol_cnc_info, NULL); - grbl_protocol_print(PLANNER_INFO SERIAL_INFO "]" STR_EOL); + grbl_protocol_print(PLANNER_INFO SERIAL_INFO "]" MSG_EOL); #else if (!extended) { - grbl_protocol_print("[VER:1.1h.20190825:]" STR_EOL); - grbl_protocol_print("[OPT:V," PLANNER_INFO SERIAL_INFO "]" STR_EOL); + grbl_protocol_print("[VER:1.1h.20190825:]" MSG_EOL); + grbl_protocol_print("[OPT:V," PLANNER_INFO SERIAL_INFO "]" MSG_EOL); } else { grbl_protocol_print(VER_INFO); grbl_protocol_print(OPT_INFO); EVENT_INVOKE(grbl_protocol_cnc_info, NULL); - grbl_protocol_print(PLANNER_INFO SERIAL_INFO "]" STR_EOL); + grbl_protocol_print(PLANNER_INFO SERIAL_INFO "]" MSG_EOL); } #endif protocol_busy = false; diff --git a/uCNC/src/interface/grbl_protocol.h b/uCNC/src/interface/grbl_protocol.h index e140dabf..882f3ac6 100644 --- a/uCNC/src/interface/grbl_protocol.h +++ b/uCNC/src/interface/grbl_protocol.h @@ -32,15 +32,15 @@ extern "C" // protocol->stream callback // this is the base function call to output via stream #define grbl_protocol_putc grbl_stream_putc -#define grbl_protocol_printf(fmt, ...) grbl_stream_printf(__romstr__(fmt), ## __VA_ARGS__) +#define grbl_protocol_printf(fmt, ...) grbl_stream_printf(__romstr__(fmt), ##__VA_ARGS__) #define grbl_protocol_print(fmt) grbl_protocol_printf(fmt) void grbl_protocol_error(uint8_t error); void grbl_protocol_alarm(int8_t alarm); void grbl_protocol_status(void); DECL_EVENT_HANDLER(grbl_protocol_status); - void grbl_protocol_feedback_base(void *__s, uint8_t type); -#define grbl_protocol_feedback(__s) grbl_protocol_feedback_base((void*)__romstr__(__s), 0) -#define grbl_protocol_sprintf(__s) grbl_protocol_feedback_base((void*)__s, 1) + void grbl_protocol_feedback_fmt(const char *fmt, bool is_feedback, ...); +#define grbl_protocol_feedback(__s, ...) grbl_protocol_feedback_fmt(__romstr__(__s), true, ##__VA_ARGS__) +#define grbl_protocol_info(__s, __pre, ...) grbl_protocol_feedback_fmt(__romstr__(__s), false, ##__VA_ARGS__) void grbl_protocol_probe_result(uint8_t val); void grbl_protocol_gcode_coordsys(void); void grbl_protocol_gcode_modes(void); diff --git a/uCNC/src/interface/grbl_stream.c b/uCNC/src/interface/grbl_stream.c index 4be524ba..e9f22aae 100644 --- a/uCNC/src/interface/grbl_stream.c +++ b/uCNC/src/interface/grbl_stream.c @@ -281,10 +281,10 @@ void grbl_stream_clear(void) #ifndef DISABLE_MULTISTREAM_SERIAL static bool grbl_stream_broadcast_enabled; #endif -void grbl_stream_broadcast(bool enable) +void grbl_stream_start_broadcast(void) { #ifndef DISABLE_MULTISTREAM_SERIAL - grbl_stream_broadcast_enabled = enable; + grbl_stream_broadcast_enabled = true; #endif } @@ -320,6 +320,9 @@ void grbl_stream_putc(char c) { grbl_stream_tx_count = 0; grbl_stream_flush(); +#ifndef DISABLE_MULTISTREAM_SERIAL + grbl_stream_broadcast_enabled = false; +#endif } #if ASSERT_PIN(ACTIVITY_LED) io_toggle_output(ACTIVITY_LED); diff --git a/uCNC/src/interface/grbl_stream.h b/uCNC/src/interface/grbl_stream.h index a81436cb..b8ed489f 100644 --- a/uCNC/src/interface/grbl_stream.h +++ b/uCNC/src/interface/grbl_stream.h @@ -60,7 +60,7 @@ extern "C" bool grbl_stream_readonly(grbl_stream_getc_cb getc_cb, grbl_stream_available_cb available_cb, grbl_stream_clear_cb clear_cb); void grbl_stream_eeprom(uint16_t address); - void grbl_stream_broadcast(bool enable); + void grbl_stream_start_broadcast(void); void grbl_stream_putc(char c); void grbl_stream_printf(const char* fmt, ...); void grbl_stream_flush(void); diff --git a/uCNC/src/interface/print.c b/uCNC/src/interface/print.c index 0d0c6c30..d631e37f 100644 --- a/uCNC/src/interface/print.c +++ b/uCNC/src/interface/print.c @@ -219,7 +219,6 @@ void print_fmtva(print_putc_cb cb, char *buffer, const char *fmt, va_list *args) if (print_atof(NULL /*itof_getc_dummy*/, (const char **)&fmt, &f)) { elems = (uint8_t)f; - fmt++; } c = printf_getc(fmt++); } @@ -422,22 +421,25 @@ uint8_t print_atof(print_read_input_cb cb, const char **buffer, float *value) result |= ATOF_NUMBER_OK; } - else + else if ((result & ATOF_NUMBER_OK)) { - if ((result & ATOF_NUMBER_OK)) + rhs = (float)intval; + while (fpcount--) { - rhs = (float)intval; - while (fpcount--) - { - rhs *= 0.1f; - } - - *value = (result & ATOF_NUMBER_ISNEGATIVE) ? -rhs : rhs; - return result; + rhs *= 0.1f; } + + *value = (result & ATOF_NUMBER_ISNEGATIVE) ? -rhs : rhs; + return result; + } + else + { + return ATOF_NUMBER_UNDEF; } break; } + atof_get(cb, buffer); + c = (uint8_t)atof_peek(cb, buffer); } return ATOF_NUMBER_UNDEF; diff --git a/uCNC/src/interface/settings.c b/uCNC/src/interface/settings.c index 1641dbd9..5c3ae373 100644 --- a/uCNC/src/interface/settings.c +++ b/uCNC/src/interface/settings.c @@ -523,220 +523,7 @@ uint8_t settings_change(setting_offset_t id, float value) } } } - /* - switch (setting) - { - case 0: - value = 1000000.0f / value; - if (value > F_STEP_MAX) - { - return STATUS_MAX_STEP_RATE_EXCEEDED; - } - g_settings.max_step_rate = value; - break; -#if EMULATE_GRBL_STARTUP > 0 || defined(ENABLE_STEPPERS_DISABLE_TIMEOUT) - // just adds this for compatibility - // this setting is not used - case 1: -#ifdef ENABLE_STEPPERS_DISABLE_TIMEOUT - g_settings.step_disable_timeout = value16; -#endif - break; -#endif - case 2: - g_settings.step_invert_mask = value8; - break; - case 3: - g_settings.dir_invert_mask = value8; - break; - case 4: - g_settings.step_enable_invert = value8; - break; - case 5: - g_settings.limits_invert_mask = value8; - break; - case 6: - g_settings.probe_invert_mask = value1; - break; - case 7: - g_settings.control_invert_mask = (value8 & CONTROLS_MASK); - break; -#if ENCODERS > 0 - case 8: - g_settings.encoders_pulse_invert_mask = value8; - break; - case 9: - g_settings.encoders_dir_invert_mask = value8; - break; -#endif - case 10: - g_settings.status_report_mask = value8; - break; - case 11: - g_settings.g64_angle_factor = value; - break; - case 12: - g_settings.arc_tolerance = value; - break; - case 13: - g_settings.report_inches = value1; - break; -#if S_CURVE_ACCELERATION_LEVEL == -1 - case 14: - g_settings.s_curve_profile = CLAMP(0, value8, 5); - break; -#endif - case 20: - if (!g_settings.homing_enabled && value1) - { - return STATUS_SOFT_LIMIT_ERROR; - } - g_settings.soft_limits_enabled = value1; - break; - case 21: - g_settings.hard_limits_enabled = value1; - break; - case 22: - g_settings.homing_enabled = value1; - break; - case 23: - g_settings.homing_dir_invert_mask = value8; - break; - case 24: - g_settings.homing_slow_feed_rate = value; - break; - case 25: - g_settings.homing_fast_feed_rate = value; - break; - case 26: - g_settings.debounce_ms = value16; - break; - case 27: - g_settings.homing_offset = value; - break; - case 30: - g_settings.spindle_max_rpm = value16; - break; - case 31: - g_settings.spindle_min_rpm = value16; - break; - case 32: - g_settings.laser_mode = value8; - break; -#ifdef ENABLE_LASER_PPI - case 33: - g_settings.step_per_mm[STEPPER_COUNT - 1] = value; - break; - case 34: - g_settings.laser_ppi_uswidth = value16; - break; - case 35: - g_settings.laser_ppi_mixmode_ppi = value; - break; - case 36: - g_settings.laser_ppi_mixmode_uswidth = value; - break; -#endif -#ifdef ENABLE_SKEW_COMPENSATION - case 37: - g_settings.skew_xy_factor = value; - break; -#ifndef SKEW_COMPENSATION_XY_ONLY - case 38: - g_settings.skew_xz_factor = value; - break; - case 39: - g_settings.skew_yz_factor = value; - break; -#endif -#endif -#if TOOL_COUNT > 1 - case 80: - g_settings.default_tool = CLAMP(0, value8, (uint8_t)TOOL_COUNT); - break; -#endif -#if (KINEMATIC == KINEMATIC_LINEAR_DELTA) - case 106: - g_settings.delta_arm_length = value; - break; - case 107: - g_settings.delta_armbase_radius = value; - break; - // case 108: - // g_settings.delta_efector_height = value; - // break; -#elif (KINEMATIC == KINEMATIC_DELTA) - case 106: - g_settings.delta_base_radius = value; - break; - case 107: - g_settings.delta_effector_radius = value; - break; - case 108: - g_settings.delta_bicep_length = value; - break; - case 109: - g_settings.delta_forearm_length = value; - break; - case 28: - g_settings.delta_bicep_homing_angle = value; - break; -#elif (KINEMATIC == KINEMATIC_SCARA) - case 106: - g_settings.scara_arm_length = value; - break; - case 107: - g_settings.scara_forearm_length = value; - break; - case 28: - g_settings.scara_arm_homing_angle = value; - break; - case 29: - g_settings.scara_forearm_homing_angle = value; - break; -#endif - default: - if (setting >= 100 && setting < (100 + AXIS_COUNT)) - { - setting -= 100; - g_settings.step_per_mm[setting] = value; - } - else if (setting >= 110 && setting < (110 + AXIS_COUNT)) - { - setting -= 110; - g_settings.max_feed_rate[setting] = value; - } - else if (setting >= 120 && setting < (120 + AXIS_COUNT)) - { - setting -= 120; - g_settings.acceleration[setting] = value; - } - else if (setting >= 130 && setting < (130 + AXIS_COUNT)) - { - setting -= 130; - g_settings.max_distance[setting] = value; - } -#ifdef ENABLE_BACKLASH_COMPENSATION - else if (setting >= 140 && setting < (140 + AXIS_TO_STEPPERS)) - { - setting -= 140; - g_settings.backlash_steps[setting] = value16; - } -#endif -#if TOOL_COUNT > 0 - else if (setting > 80 && setting <= (80 + TOOL_COUNT)) - { - setting -= 81; - g_settings.tool_length_offset[setting] = value; - } -#endif - else - { - return STATUS_INVALID_STATEMENT; - } - } -*/ #ifdef ENABLE_SETTINGS_MODULES } else @@ -807,7 +594,7 @@ void settings_erase(uint16_t address, uint8_t *__ptr, uint16_t size) bool settings_check_startup_gcode(uint16_t address) { - grbl_stream_broadcast(true); + grbl_stream_start_broadcast(); grbl_protocol_putc('>'); #ifndef RAM_ONLY_SETTINGS if (settings_load(address, NULL, UINT16_MAX))