Skip to content

Commit

Permalink
Merge pull request #635 from Paciente8159/exetended-string-settings
Browse files Browse the repository at this point in the history
Extended string settings
  • Loading branch information
Paciente8159 authored Feb 20, 2024
2 parents 7433265 + 9edce78 commit 0448301
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
3 changes: 3 additions & 0 deletions uCNC/src/core/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,9 @@ static uint8_t parser_grbl_command(void)
val = 0;
if (!parser_get_float(&val))
{
#ifdef ENABLE_SETTINGS_MODULES
return settings_change(setting_num, val);
#endif
return STATUS_BAD_NUMBER_FORMAT;
}

Expand Down
1 change: 1 addition & 0 deletions uCNC/src/interface/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ void protocol_send_cnc_settings(void)

#ifdef ENABLE_SETTINGS_MODULES
EVENT_INVOKE(protocol_send_cnc_settings, NULL);
serial_broadcast(false);
#endif
protocol_busy = false;
}
Expand Down
75 changes: 75 additions & 0 deletions uCNC/src/interface/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,81 @@ typedef uint16_t setting_offset_t;
CREATE_EVENT_LISTENER(settings_erase, set##ID##_settings_erase); \
CREATE_EVENT_LISTENER(protocol_send_cnc_settings, set##ID##_protocol_send_cnc_settings)

#define DECL_EXTENDED_STRING_SETTING(ID, var, count) \
static uint32_t set##ID##_settings_address; \
bool set##ID##_settings_load(void *args) \
{ \
settings_args_t *set = (settings_args_t *)args; \
if (set->address == SETTINGS_ADDRESS_OFFSET || set->address == set##ID##_settings_address) \
{ \
settings_load(set##ID##_settings_address, (uint8_t *)var, sizeof(char) * count); \
return (set->address == set##ID##_settings_address) ? EVENT_HANDLED : EVENT_CONTINUE; \
} \
return EVENT_CONTINUE; \
} \
bool set##ID##_settings_save(void *args) \
{ \
settings_args_t *set = (settings_args_t *)args; \
if (set->address == SETTINGS_ADDRESS_OFFSET || set->address == set##ID##_settings_address) \
{ \
settings_save(set##ID##_settings_address, (uint8_t *)var, sizeof(char) * count); \
return (set->address == set##ID##_settings_address) ? EVENT_HANDLED : EVENT_CONTINUE; \
} \
return EVENT_CONTINUE; \
} \
bool set##ID##_settings_change(void *args) \
{ \
setting_args_t *set = (setting_args_t *)args; \
if (set->id == ID) \
{ \
for (uint8_t i = 0; i < count; i++) \
{ \
char c = serial_getc(); \
if (c == EOL || c == '\n') \
{ \
var[i] = EOL; \
break; \
} \
var[i] = c; \
} \
return EVENT_HANDLED; \
} \
return EVENT_CONTINUE; \
} \
bool set##ID##_settings_erase(void *args) \
{ \
settings_args_t *set = (settings_args_t *)args; \
if (set->address == SETTINGS_ADDRESS_OFFSET || set->address == set##ID##_settings_address) \
{ \
memset(var, 0, sizeof(char) * count); \
return (set->address == set##ID##_settings_address) ? EVENT_HANDLED : EVENT_CONTINUE; \
} \
return EVENT_HANDLED; \
} \
bool set##ID##_protocol_send_cnc_settings(void *args) \
{ \
settings_args_t *set = (settings_args_t *)args; \
serial_putc('$'); \
serial_print_int(ID); \
serial_putc('='); \
for (uint8_t i = 0; i < count; i++) \
{ \
char c = var[i]; \
if (c < 20 || c > 127) \
{ \
protocol_send_string(MSG_EOL); \
return EVENT_CONTINUE; \
} \
serial_putc(c); \
} \
return EVENT_CONTINUE; \
} \
CREATE_EVENT_LISTENER(settings_load, set##ID##_settings_load); \
CREATE_EVENT_LISTENER(settings_save, set##ID##_settings_save); \
CREATE_EVENT_LISTENER(settings_change, set##ID##_settings_change); \
CREATE_EVENT_LISTENER(settings_erase, set##ID##_settings_erase); \
CREATE_EVENT_LISTENER(protocol_send_cnc_settings, set##ID##_protocol_send_cnc_settings)

#define EXTENDED_SETTING_ADDRESS(ID) set##ID##_settings_address

#define EXTENDED_SETTING_INIT(ID, var) \
Expand Down

0 comments on commit 0448301

Please sign in to comment.