Skip to content

Commit

Permalink
fixing protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
Paciente8159 committed Sep 24, 2024
1 parent cf7e183 commit afa2511
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 26 deletions.
2 changes: 1 addition & 1 deletion uCNC/src/interface/grbl_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ extern "C"
#else
#define MSG_STATUS_FS "|F:%f"
#endif
#define MSG_STATUS_WCO "|WCO:"
#define MSG_STATUS_WCO "|WCO:" MSG_AXIS
#define MSG_STATUS_OVR "|Ov:%d,%d,%d"
#define MSG_STATUS_TOOL "|A:"
#define MSG_STATUS_LINE "|Ln:%llu"
Expand Down
4 changes: 4 additions & 0 deletions uCNC/src/interface/grbl_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,10 @@ void grbl_protocol_cnc_settings(void)
{
protocol_busy = true;
uint8_t count = settings_count();

// id 0 conversion from frequency to us
grbl_protocol_gcode_setting_line_flt(0, 1000000.f / g_settings.max_step_rate);

for (uint8_t i = 0; i < count; i++)
{
setting_id_t s = {0};
Expand Down
51 changes: 27 additions & 24 deletions uCNC/src/interface/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ static void print_int(print_putc_cb cb, char **buffer_ref, int32_t num, uint8_t
uint8_t buffer[11];
uint8_t i = 0;

if (num == 0)
{
padding = MAX(1, padding);
}

if (num < 0)
{
print_putc(cb, buffer_ref, '-');
Expand All @@ -119,11 +124,10 @@ static void print_int(print_putc_cb cb, char **buffer_ref, int32_t num, uint8_t
print_putc(cb, buffer_ref, '0');
}

do
while (i--)
{
i--;
print_putc(cb, buffer_ref, '0' + buffer[i]);
} while (i);
}
}

static void FORCEINLINE print_flt(print_putc_cb cb, char **buffer_ref, float num)
Expand Down Expand Up @@ -172,7 +176,8 @@ void print_fmtva(print_putc_cb cb, char *buffer, const char *fmt, va_list *args)
bool hexflags = HEX_NONE;
#endif
void *pt = NULL;
int32_t i = 0;
int i = 0;
int32_t li = 0;
float f, *f_ptr = NULL;
char **buffer_ref = NULL;
char *ptr = buffer;
Expand All @@ -197,7 +202,6 @@ void print_fmtva(print_putc_cb cb, char *buffer, const char *fmt, va_list *args)
__FALL_THROUGH__
case '-':
case '+':
fmt++;
__FALL_THROUGH__
case '0':
while (c >= '0' && c <= '9' && c)
Expand All @@ -206,15 +210,16 @@ void print_fmtva(print_putc_cb cb, char *buffer, const char *fmt, va_list *args)
}
__FALL_THROUGH__
case '.':
fmt++;
__FALL_THROUGH__
#endif
default:
if (c == '.' || (c >= '1' && c <= '9'))
{
if (print_atof(NULL/*itof_getc_dummy*/, (const char **)&fmt, &f))
fmt--;
if (print_atof(NULL /*itof_getc_dummy*/, (const char **)&fmt, &f))
{
elems = (uint8_t)f;
fmt++;
}
c = printf_getc(fmt++);
}
Expand Down Expand Up @@ -256,9 +261,11 @@ void print_fmtva(print_putc_cb cb, char *buffer, const char *fmt, va_list *args)
__FALL_THROUGH__
case 'x':
#endif
case 'u':
cval = 1;
__FALL_THROUGH__
case 'd':
case 'i':
case 'u':
if (elems)
{
pt = va_arg(*args, void *);
Expand All @@ -268,39 +275,34 @@ void print_fmtva(print_putc_cb cb, char *buffer, const char *fmt, va_list *args)
switch (lcount)
{
case 0:
i = (int32_t)va_arg(*args, int);
break;
case 1:
i = (int32_t)va_arg(*args, uint16_t);
i = (int32_t)va_arg(*args, int);
li = (c) ? (unsigned int)i : i;
break;
default:
i = (int32_t)va_arg(*args, uint32_t);
li = (int32_t)va_arg(*args, long int);
break;
}
elems=1;
elems = 1;
}
do
{
switch (c)
{
case 'u':
i = ABS(i);
__FALL_THROUGH__
case 'd':
case 'i':
print_int(cb, buffer_ref, i, 0);
break;
#ifndef PRINT_DISABLE_FMT_HEX
case 'x':
case 'X':
print_byte(cb, buffer_ref, (const uint8_t *)&i, (hexflags | lcount));
print_byte(cb, buffer_ref, (const uint8_t *)&li, (hexflags | lcount));
break;
#endif
#ifndef PRINT_DISABLE_FMT_IP
case 'M':
print_ip(cb, buffer_ref, i);
print_ip(cb, buffer_ref, li);
break;
#endif
default:
print_int(cb, buffer_ref, li, 0);
break;
}
if (elems && --elems)
{
Expand Down Expand Up @@ -332,7 +334,7 @@ void print_fmtva(print_putc_cb cb, char *buffer, const char *fmt, va_list *args)
{
f = (float)va_arg(*args, double);
f_ptr = &f;
elems=1;
elems = 1;
}
do
{
Expand Down Expand Up @@ -364,7 +366,8 @@ void print_fmtva(print_putc_cb cb, char *buffer, const char *fmt, va_list *args)
break;
}
}
else if(c){
else if (c)
{
cb(c);
}
} while (c);
Expand Down
12 changes: 11 additions & 1 deletion uCNC/src/interface/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ const settings_t __rom__ default_settings =
};

const setting_id_t __rom__ g_settings_id_table[] = {
{.id = 0, .memptr = &g_settings.max_step_rate, .type = SETTING_TYPE(0)},
// {.id = 0, .memptr = &g_settings.max_step_rate, .type = SETTING_TYPE(0)},
#ifdef ENABLE_STEPPERS_DISABLE_TIMEOUT
{.id = 1, .memptr = &g_settings.step_disable_timeout, .type = SETTING_TYPE(3)},
#endif
Expand Down Expand Up @@ -484,6 +484,16 @@ uint8_t settings_change(setting_offset_t id, float value)
return STATUS_NEGATIVE_VALUE;
}

// id 0 conversion from us to frequency
if (id == 0)
{
value = 1000000.0f / value;
if (value > F_STEP_MAX)
{
return STATUS_MAX_STEP_RATE_EXCEEDED;
}
}

uint8_t count = settings_count();
for (uint8_t i = 0; i < count; i++)
{
Expand Down

0 comments on commit afa2511

Please sign in to comment.