Skip to content

Commit

Permalink
more changes and code optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Paciente8159 committed Sep 23, 2024
1 parent 4511c70 commit 2427026
Show file tree
Hide file tree
Showing 29 changed files with 194 additions and 239 deletions.
8 changes: 4 additions & 4 deletions uCNC/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,12 @@ void cnc_alarm(int8_t code)
cnc_stop();
cnc_state.alarm = code;
#ifdef ENABLE_IO_ALARM_DEBUG
grbl_protocol_string(MSG_START);
grbl_protocol_string("LIMITS:");
grbl_protocol_print(MSG_START);
grbl_protocol_print("LIMITS:");
serial_print_int(io_alarm_limits);
grbl_protocol_string("|CONTROLS:");
grbl_protocol_print("|CONTROLS:");
serial_print_int(io_alarm_controls);
grbl_protocol_string(MSG_END);
grbl_protocol_print(MSG_END);
#endif
// we add our callback here
Expand Down
12 changes: 4 additions & 8 deletions uCNC/src/cnc.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
See the GNU General Public License for more details.
*/

#include <stdio.h>

#include <stdlib.h>
#include <string.h>
#include <stdint.h>
Expand Down Expand Up @@ -163,7 +163,7 @@ void cnc_run(void)
if (grbl_stream_getc() == EOL)
{
grbl_protocol_feedback(MSG_FEEDBACK_1);
grbl_protocol_print(MSG_OK);
grbl_protocol_error(0);
}
}
cnc_dotasks();
Expand Down Expand Up @@ -215,13 +215,9 @@ uint8_t cnc_parse_cmd(void)
// runs any rt command in queue
// this catches for example a ?\n situation sent by some GUI like UGS
cnc_exec_rt_commands();
if (!error)
{
grbl_protocol_print(MSG_OK);
}
else
grbl_protocol_error(error);
if(error)
{
grbl_protocol_error(error);
itp_sync();
mc_sync_position();
parser_sync_position();
Expand Down
2 changes: 1 addition & 1 deletion uCNC/src/core/interpolator.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

#include "../cnc.h"
#include <stdio.h>

#include <string.h>
#include <stdint.h>
#include <math.h>
Expand Down
32 changes: 16 additions & 16 deletions uCNC/src/core/motion_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -1027,24 +1027,24 @@ void mc_flush_pending_motion(void)

void mc_print_hmap(void)
{
grbl_protocol_string(MSG_START);
grbl_protocol_string("HMAP start corner;");
grbl_protocol_print(MSG_START);
grbl_protocol_print("HMAP start corner;");
serial_print_flt(hmap_x);
serial_putc(';');
grbl_protocol_putc(';');
serial_print_flt(hmap_y);
grbl_protocol_string(MSG_END);
grbl_protocol_print(MSG_END);

grbl_protocol_string(MSG_START);
grbl_protocol_string("HMAP end corner;");
grbl_protocol_print(MSG_START);
grbl_protocol_print("HMAP end corner;");
serial_print_flt(hmap_x + hmap_x_offset);
serial_putc(';');
grbl_protocol_putc(';');
serial_print_flt(hmap_y + hmap_y_offset);
grbl_protocol_string(MSG_END);
grbl_protocol_print(MSG_END);

grbl_protocol_string(MSG_START);
grbl_protocol_string("HMAP control points;");
grbl_protocol_print(MSG_START);
grbl_protocol_print("HMAP control points;");
serial_print_int(H_MAPING_ARRAY_SIZE);
grbl_protocol_string(MSG_END);
grbl_protocol_print(MSG_END);

// print map
for (uint8_t j = 0; j < H_MAPING_GRID_FACTOR; j++)
Expand All @@ -1053,14 +1053,14 @@ void mc_print_hmap(void)
{
uint8_t map = i + (H_MAPING_GRID_FACTOR * j);
float new_h = hmap_offsets[map];
grbl_protocol_string(MSG_START);
grbl_protocol_string("HMAP;");
grbl_protocol_print(MSG_START);
grbl_protocol_print("HMAP;");
serial_print_int(i);
serial_putc(';');
grbl_protocol_putc(';');
serial_print_int(j);
serial_putc(';');
grbl_protocol_putc(';');
serial_print_flt(new_h);
grbl_protocol_string(MSG_END);
grbl_protocol_print(MSG_END);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions uCNC/src/core/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

#include "../cnc.h"
#include <stdio.h>

#include <stdint.h>
#include <math.h>
#include <string.h>
Expand Down Expand Up @@ -2600,7 +2600,7 @@ uint8_t parser_get_float(float *value)
return parser_get_expression(value);
}
#endif
return print_itof(parser_get_next_preprocessed, NULL, value);
return print_atof(parser_get_next_preprocessed, NULL, value);
}

static uint8_t parser_get_token(uint8_t *word, float *value)
Expand Down
2 changes: 1 addition & 1 deletion uCNC/src/hal/kinematics/kinematic_cartesian.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "../../cnc.h"

#if (KINEMATIC == KINEMATIC_CARTESIAN)
#include <stdio.h>

#include <math.h>

void kinematics_init(void)
Expand Down
2 changes: 1 addition & 1 deletion uCNC/src/hal/kinematics/kinematic_corexy.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "../../cnc.h"

#if (KINEMATIC == KINEMATIC_COREXY)
#include <stdio.h>

#include <math.h>

#if (COREXY_AXIS == COREXY_AXIS_XZ || COREXY_AXIS == COREXY_AXIS_YZ)
Expand Down
2 changes: 1 addition & 1 deletion uCNC/src/hal/kinematics/kinematic_delta.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "../../cnc.h"

#if (KINEMATIC == KINEMATIC_DELTA)
#include <stdio.h>

#include <stdint.h>
#include <math.h>

Expand Down
2 changes: 1 addition & 1 deletion uCNC/src/hal/kinematics/kinematic_linear_delta.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "../../cnc.h"

#if (KINEMATIC == KINEMATIC_LINEAR_DELTA)
#include <stdio.h>

#include <math.h>

#define STEPPER0_FACTX (cos(STEPPER0_ANGLE * DEG_RAD_MULT));
Expand Down
2 changes: 1 addition & 1 deletion uCNC/src/hal/kinematics/kinematic_scara.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "../../cnc.h"

#if (KINEMATIC == KINEMATIC_SCARA)
#include <stdio.h>

#include <stdint.h>
#include <math.h>

Expand Down
2 changes: 1 addition & 1 deletion uCNC/src/hal/mcus/avr/mcumap_avr.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extern "C"
*/
#include <math.h>
#include <inttypes.h>
#include <stdio.h>

#include <string.h>
#include <stdlib.h>
#include <stdint.h>
Expand Down
2 changes: 1 addition & 1 deletion uCNC/src/hal/mcus/virtual/mcu_virtual.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
#include "../../../cnc.h"
#if (MCU == MCU_VIRTUAL_WIN)
#include <stdio.h>

#include <conio.h>
#include <string.h>
#include <stdint.h>
Expand Down
2 changes: 1 addition & 1 deletion uCNC/src/hal/mcus/virtual/win_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>


typedef int(__attribute__((__stdcall__)) * available_delegate)(struct win_port_ *);
typedef int(__attribute__((__stdcall__)) * read_delegate)(struct win_port_ *, uint8_t *buffer, size_t len);
Expand Down
20 changes: 10 additions & 10 deletions uCNC/src/hal/tools/tools/plasma_thc.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <math.h>
#include <float.h>
#include <stdint.h>
#include <stdio.h>


#include "../../../cnc.h"

Expand Down Expand Up @@ -432,43 +432,43 @@ bool plasma_grbl_protocol_status(void *args)
{
uint8_t state = plasma_thc_state;

grbl_protocol_string("THC:");
grbl_protocol_print("THC:");

plasma_thc_extension_send_status();

if (CHECKFLAG(state, PLASMA_THC_ENABLED))
{
serial_putc('E');
grbl_protocol_putc('E');
}
else
{
serial_putc('*');
grbl_protocol_putc('*');
}
if (CHECKFLAG(state, PLASMA_THC_ACTIVE))
{
serial_putc('R');
grbl_protocol_putc('R');
}
#if ASSERT_PIN(PLASMA_ON_OUTPUT)
if (io_get_output(PLASMA_ON_OUTPUT))
{
serial_putc('T');
grbl_protocol_putc('T');
}
#endif
if (plasma_thc_arc_ok())
{
serial_putc('A');
grbl_protocol_putc('A');
}
if (plasma_thc_vad_active())
{
serial_putc('V');
grbl_protocol_putc('V');
}
if (plasma_thc_up())
{
serial_putc('U');
grbl_protocol_putc('U');
}
if (plasma_thc_down())
{
serial_putc('D');
grbl_protocol_putc('D');
}

return EVENT_CONTINUE;
Expand Down
6 changes: 3 additions & 3 deletions uCNC/src/hal/tools/tools/vfd_modbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ static bool modvfd_command(uint8_t *cmd, modbus_response_t *response)
}

vfd_state.connected = 0;
grbl_protocol_string(MSG_START);
grbl_protocol_string("VFD COMMUNICATION FAILED");
grbl_protocol_string(MSG_END);
grbl_protocol_print(MSG_START);
grbl_protocol_print("VFD COMMUNICATION FAILED");
grbl_protocol_print(MSG_END);
#ifdef VFD_HOLD_ON_ERROR
cnc_call_rt_command(CMD_CODE_FEED_HOLD);
#endif
Expand Down
14 changes: 7 additions & 7 deletions uCNC/src/interface/grbl_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ extern "C"
// formated messages
#define STR_EOL "\r\n"
#define MSG_EOL STR_EOL
#define MSG_OK "ok" STR_EOL
#define MSG_ERROR "error:%d" STR_EOL
#define MSG_ALARM "ALARM:%d" STR_EOL
#define MSG_OK "ok"
#define MSG_ERROR "error:%d"
#define MSG_ALARM "ALARM:%d" MSG_EOL
#define MSG_ECHO "[echo:"
#if EMULATE_GRBL_STARTUP == 0
#define MSG_STARTUP_START "uCNC "
Expand All @@ -169,16 +169,16 @@ extern "C"
#define MSG_STARTUP_START "Grbl "
#define MSG_STARTUP_END " [uCNC v" CNC_VERSION " '$' for help]"
#elif EMULATE_GRBL_STARTUP == 2
#define MSG_STARTUP "Grbl 1.1f ['$' for help]" STR_EOL
#define MSG_STARTUP "Grbl 1.1f ['$' for help]" MSG_EOL
#endif
#ifndef MSG_STARTUP
#define MSG_STARTUP MSG_STARTUP_START CNC_MAJOR_MINOR_VERSION MSG_STARTUP_END STR_EOL
#define MSG_STARTUP MSG_STARTUP_START CNC_MAJOR_MINOR_VERSION MSG_STARTUP_END MSG_EOL
#endif
#define MSG_HELP "[HLP:$$ $# $G $I $N $x=val $Nx=line $J=line $C $X $H ~ ! ? ctrl-x]" STR_EOL
#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_END "]" STR_EOL
#define MSG_END "]" MSG_EOL
#define MSG_FEEDBACK MSG_START "%S" MSG_END
#define MSG_FEEDBACK_PRINTF MSG_START "%s" MSG_END
#define MSG_FEEDBACK_IP MSG_START "%M" MSG_END
Expand Down
4 changes: 3 additions & 1 deletion uCNC/src/interface/grbl_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ WEAK_EVENT_HANDLER(grbl_protocol_gcode_modes)

void grbl_protocol_error(uint8_t error)
{
grbl_protocol_printf(MSG_ERROR, error);
(error) ? grbl_protocol_printf(MSG_ERROR, error) : grbl_protocol_print(MSG_OK);
grbl_protocol_putc('\r');
grbl_protocol_putc('\n');
}

void grbl_protocol_alarm(int8_t alarm)
Expand Down
2 changes: 1 addition & 1 deletion uCNC/src/interface/grbl_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ 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, ...) print_fmt(grbl_stream_putc, NULL, __romstr__(fmt), __VA_ARGS__)
#define grbl_protocol_printf(fmt, ...) print_fmt(grbl_stream_putc, NULL, fmt, __VA_ARGS__)
#define grbl_protocol_print(fmt) print_fmt(grbl_stream_putc, NULL, __romstr__(fmt))
void grbl_protocol_error(uint8_t error);
void grbl_protocol_alarm(int8_t alarm);
Expand Down
2 changes: 1 addition & 1 deletion uCNC/src/interface/grbl_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extern "C"
{
#endif

#include <stdio.h>

#include <stdbool.h>
#include <stdint.h>
#include <stdarg.h>
Expand Down
Loading

0 comments on commit 2427026

Please sign in to comment.