Skip to content

Commit

Permalink
Merge pull request #821 from Paciente8159/improved-settings-type
Browse files Browse the repository at this point in the history
improve code readability in settings type parsing
  • Loading branch information
Paciente8159 authored Jan 25, 2025
2 parents c8d15e2 + 25adae5 commit a33f8d2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions uCNC/src/interface/grbl_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -819,19 +819,19 @@ void proto_cnc_settings(void)
uint32_t val = 0;
switch (SETTING_TYPE_MASK(s.type))
{
case 1:
case SETTING_TYPE_BOOL:
val = (uint32_t)((bool *)s.memptr)[j];
proto_gcode_setting_line_int(s.id, val);
break;
case 2:
case SETTING_TYPE_UINT8:
val = (uint32_t) * ((uint8_t *)s.memptr);
proto_gcode_setting_line_int(s.id, val);
break;
case 3:
case SETTING_TYPE_UINT16:
val = (uint32_t) * ((uint16_t *)s.memptr);
proto_gcode_setting_line_int(s.id, val);
break;
default:
default: // default is float
proto_gcode_setting_line_flt(s.id, ((float *)s.memptr)[j]);
break;
}
Expand Down
8 changes: 4 additions & 4 deletions uCNC/src/interface/grbl_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,16 +506,16 @@ uint8_t settings_change(setting_offset_t id, float value)
{
switch (SETTING_TYPE_MASK(s.type))
{
case 1:
case SETTING_TYPE_BOOL:
((bool *)s.memptr)[(uint8_t)id - s.id] = value1;
break;
case 2:
case SETTING_TYPE_UINT8:
((uint8_t *)s.memptr)[(uint8_t)id - s.id] = value8;
break;
case 3:
case SETTING_TYPE_UINT16:
((uint16_t *)s.memptr)[(uint8_t)id - s.id] = value16;
break;
default:
default: // default is float
((float *)s.memptr)[(uint8_t)id - s.id] = value;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion uCNC/src/interface/grbl_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ typedef uint16_t setting_offset_t;
#endif

#define SETTING_TYPE(T) (T << 5)
#define SETTING_TYPE_MASK(T) ((T >> 5) & 0x3)
#define SETTING_TYPE_MASK(T) (T & (0x03 << 5))
#define SETTING_ARRAY 0x80
#define SETTING_ARRCNT(X) (X & 0x1F)
#define SETTING_TYPE_BOOL SETTING_TYPE(1)
Expand Down

0 comments on commit a33f8d2

Please sign in to comment.