Skip to content

Commit

Permalink
Merge pull request #289 from Paciente8159/288-fr-implement-smoothiewa…
Browse files Browse the repository at this point in the history
…re-s-cluster

288 fr implement smoothieware s cluster
  • Loading branch information
Paciente8159 committed Oct 5, 2022
2 parents 51d3f7d + e744534 commit 6da62dd
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 15 deletions.
1 change: 1 addition & 0 deletions uCNC/cnc_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ extern "C"
// #define ENABLE_MAIN_LOOP_MODULES
// #define ENABLE_IO_MODULES
// #define ENABLE_PARSER_MODULES
// #define ENABLE_MOTION_CONTROL_MODULES
// #define ENABLE_SETTINGS_MODULES
// #define ENABLE_PROTOCOL_MODULES

Expand Down
13 changes: 13 additions & 0 deletions uCNC/src/core/motion_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ static float mc_last_target[AXIS_COUNT];
static uint8_t mc_last_dirbits;
#endif

#ifdef ENABLE_MOTION_CONTROL_MODULES
// event_mc_line_segment_handler
WEAK_EVENT_HANDLER(mc_line_segment)
{
DEFAULT_EVENT_HANDLER(mc_line_segment);
}
#endif

void mc_init(void)
{
#ifdef FORCE_GLOBALS_TO_0
Expand Down Expand Up @@ -158,6 +166,11 @@ static uint8_t mc_line_segment(int32_t *step_new_pos, motion_data_t *block_data)
}
}

#ifdef ENABLE_MOTION_CONTROL_MODULES
// event_mc_line_segment_handler
EVENT_INVOKE(mc_line_segment, block_data);
#endif

planner_add_line(block_data);
// dwell should only execute on the first request
block_data->dwell = 0;
Expand Down
7 changes: 6 additions & 1 deletion uCNC/src/core/motion_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ extern "C"
{
#endif

#include "../module.h"
#include <stdint.h>
#include <stdbool.h>

Expand Down Expand Up @@ -51,7 +52,6 @@ extern "C"
uint8_t : 6; // unused
#endif
uint8_t is_subsegment : 1;

} bit;
} motion_flags_t;

Expand Down Expand Up @@ -95,6 +95,11 @@ extern "C"
void mc_get_position(float *target);
void mc_sync_position(void);

#ifdef ENABLE_MOTION_CONTROL_MODULES
// event_mc_line_segment_handler
DECL_EVENT_HANDLER(mc_line_segment);
#endif

#ifdef __cplusplus
}
#endif
Expand Down
48 changes: 35 additions & 13 deletions uCNC/src/core/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ static float parser_last_pos[AXIS_COUNT];

static unsigned char parser_get_next_preprocessed(bool peek);
FORCEINLINE static void parser_get_comment(unsigned char start_char);
static uint8_t parser_get_float(float *value);
FORCEINLINE static uint8_t parser_get_token(unsigned char *word, float *value);
FORCEINLINE static uint8_t parser_gcode_word(uint8_t code, uint8_t mantissa, parser_state_t *new_state, parser_cmd_explicit_t *cmd);
FORCEINLINE static uint8_t parser_mcode_word(uint8_t code, uint8_t mantissa, parser_state_t *new_state, parser_cmd_explicit_t *cmd);
Expand Down Expand Up @@ -155,11 +154,23 @@ WEAK_EVENT_HANDLER(gcode_exec)
DEFAULT_EVENT_HANDLER(gcode_exec);
}

// event_gcode_exec_handler
WEAK_EVENT_HANDLER(gcode_exec_modifier)
{
DEFAULT_EVENT_HANDLER(gcode_exec_modifier);
}

// event_grbl_cmd_handler
WEAK_EVENT_HANDLER(grbl_cmd)
{
DEFAULT_EVENT_HANDLER(grbl_cmd);
}

// event_parse_token_handler
WEAK_EVENT_HANDLER(parse_token)
{
DEFAULT_EVENT_HANDLER(parse_token);
}
#endif

/*
Expand Down Expand Up @@ -1011,6 +1022,11 @@ uint8_t parser_exec_command(parser_state_t *new_state, parser_words_t *words, pa
uint8_t error = 0;
bool update_tools = false;

#ifdef ENABLE_PARSER_MODULES
gcode_exec_args_t args = {new_state, words, cmd};
EVENT_INVOKE(gcode_exec_modifier, &args);
#endif

// stoping from previous command M2 or M30 command
if (new_state->groups.stopping && !CHECKFLAG(cmd->groups, GCODE_GROUP_STOPPING))
{
Expand All @@ -1032,7 +1048,7 @@ uint8_t parser_exec_command(parser_state_t *new_state, parser_words_t *words, pa

if (words->p < 6)
{
io_set_pwm(words->p + SERVO0_UCNC_INTERNAL_PIN, (uint8_t)CLAMP(words->s, 0, 255));
io_set_pwm(words->p + SERVO0_UCNC_INTERNAL_PIN, (uint8_t)CLAMP(0, (uint8_t)trunc(words->s), 255));
}

return STATUS_OK;
Expand All @@ -1042,7 +1058,6 @@ uint8_t parser_exec_command(parser_state_t *new_state, parser_words_t *words, pa
#ifdef ENABLE_PARSER_MODULES
if ((cmd->group_extended != 0))
{
gcode_exec_args_t args = {new_state, words, cmd};
return EVENT_INVOKE(gcode_exec, &args);
}
#endif
Expand All @@ -1069,7 +1084,7 @@ uint8_t parser_exec_command(parser_state_t *new_state, parser_words_t *words, pa
#if TOOL_COUNT > 0
if (CHECKFLAG(cmd->words, GCODE_WORD_S))
{
new_state->spindle = words->s;
new_state->spindle = (uint16_t)trunc(words->s);
}

// 5. select tool
Expand Down Expand Up @@ -1676,7 +1691,7 @@ static uint8_t parser_gcode_command(void)
If the number is an integer the isinteger flag is set
The string pointer is also advanced to the next position
*/
static uint8_t parser_get_float(float *value)
uint8_t parser_get_float(float *value)
{
uint32_t intval = 0;
uint8_t fpcount = 0;
Expand Down Expand Up @@ -1849,7 +1864,7 @@ static uint8_t parser_get_token(unsigned char *word, float *value)
unsigned char c = serial_getc();

// if other char starts tokenization
if (c > 'Z')
if (c >= 'a' && c <= 'z')
{
c -= 32; // uppercase
}
Expand All @@ -1865,16 +1880,23 @@ static uint8_t parser_get_token(unsigned char *word, float *value)
#ifdef ECHO_CMD
serial_putc(c);
#endif
if (c < 'A' || c > 'Z') // invalid recognized char
if (c >= 'A' && c <= 'Z') // invalid recognized char
{
return STATUS_EXPECTED_COMMAND_LETTER;
}
if (!parser_get_float(value))
{
return STATUS_BAD_NUMBER_FORMAT;
}

if (!parser_get_float(value))
return STATUS_OK;
}
// event_parse_token_handler
#ifdef ENABLE_PARSER_MODULES
if (EVENT_INVOKE(parse_token, word))
{
return STATUS_BAD_NUMBER_FORMAT;
return STATUS_OK;
}
break;
#endif
return STATUS_EXPECTED_COMMAND_LETTER;
}

return STATUS_OK;
Expand Down Expand Up @@ -2303,7 +2325,7 @@ static uint8_t parser_letter_word(unsigned char c, float value, uint8_t mantissa
{
return STATUS_NEGATIVE_VALUE;
}
words->s = (uint16_t)trunc(value);
words->s = value;
break;
case 'T':
new_words |= GCODE_WORD_T;
Expand Down
9 changes: 8 additions & 1 deletion uCNC/src/core/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ extern "C"
float f;
float p;
float r;
int16_t s;
float s;
int8_t t;
uint8_t l;
#ifdef GCODE_PROCESS_LINE_NUMBERS
Expand Down Expand Up @@ -191,6 +191,7 @@ extern "C"
void parser_sync_position(void);
void parser_reset(void);
void parser_machine_to_work(float *axis);
uint8_t parser_get_float(float *value);
uint8_t parser_exec_command(parser_state_t *new_state, parser_words_t *words, parser_cmd_explicit_t *cmd);

#ifdef ENABLE_PARSER_MODULES
Expand All @@ -217,13 +218,19 @@ extern "C"
// event_gcode_exec_handler
DECL_EVENT_HANDLER(gcode_exec);

// event_gcode_exec_modifier_handler
DECL_EVENT_HANDLER(gcode_exec_modifier);

// event_grbl_cmd_handler
typedef struct grbl_cmd_args_
{
unsigned char *cmd;
uint8_t len;
} grbl_cmd_args_t;
DECL_EVENT_HANDLER(grbl_cmd);

// event_parse_token_handler
DECL_EVENT_HANDLER(parse_token);
#endif

#ifdef __cplusplus
Expand Down

0 comments on commit 6da62dd

Please sign in to comment.