Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add imperial_units boolean #3

Merged
merged 1 commit into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Marlin/src/gcode/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ bool GCodeParser::volumetric_enabled;

#if ENABLED(INCH_MODE_SUPPORT)
float GCodeParser::linear_unit_factor, GCodeParser::volumetric_unit_factor;
#if ENABLED(STATUS_DISPLAY_INCHES)
bool GCodeParser::imperial_units;
#endif
#endif

#if ENABLED(TEMPERATURE_UNITS_SUPPORT)
Expand Down
15 changes: 13 additions & 2 deletions Marlin/src/gcode/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ class GCodeParser {

#if ENABLED(INCH_MODE_SUPPORT)
static float linear_unit_factor, volumetric_unit_factor;
#if ENABLED(STATUS_DISPLAY_INCHES)
static bool imperial_units;
#endif
#endif

#if ENABLED(TEMPERATURE_UNITS_SUPPORT)
Expand Down Expand Up @@ -301,8 +304,16 @@ class GCodeParser {
static inline void set_input_linear_units(const LinearUnit units) {
switch (units) {
default:
case LINEARUNIT_MM: linear_unit_factor = 1.0f; break;
case LINEARUNIT_INCH: linear_unit_factor = 25.4f; break;
case LINEARUNIT_MM: linear_unit_factor = 1.0f;
#if ENABLED(STATUS_DISPLAY_INCHES)
imperial_units = false;
#endif
break;
case LINEARUNIT_INCH: linear_unit_factor = 25.4f;
#if ENABLED(STATUS_DISPLAY_INCHES)
imperial_units = true;
#endif
break;
}
volumetric_unit_factor = POW(linear_unit_factor, 3);
}
Expand Down
35 changes: 14 additions & 21 deletions Marlin/src/lcd/dogm/status_screen_DOGM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,20 +381,18 @@ FORCE_INLINE void _draw_centered_temp(const int16_t temp, const uint8_t tx, cons
FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const bool blink) {
const AxisEnum a = TERN(LCD_SHOW_E_TOTAL, axis == E_AXIS ? X_AXIS : axis, axis);
#if ENABLED(STATUS_DISPLAY_INCHES)
if (parser.linear_unit_factor == 25.4f) {
if (parser.imperial_units) {
const uint8_t offs = (XYZ_SPACING + XYZ_SPACING_IN) * a;
lcd_put_wchar((X_LABEL_POS + X_LABEL_POS_IN) + offs, XYZ_BASELINE, axis_codes[axis]);
lcd_moveto((X_VALUE_POS + X_VALUE_POS_IN) + offs, XYZ_BASELINE);
}
else {
const uint8_t offs = (XYZ_SPACING) * a;
lcd_put_wchar(X_LABEL_POS + offs, XYZ_BASELINE, axis_codes[axis]);
lcd_moveto(X_VALUE_POS + offs, XYZ_BASELINE);
#endif
const uint8_t offs = (XYZ_SPACING) * a;
lcd_put_wchar(X_LABEL_POS + offs, XYZ_BASELINE, axis_codes[axis]);
lcd_moveto(X_VALUE_POS + offs, XYZ_BASELINE);
#if ENABLED(STATUS_DISPLAY_INCHES)
}
#else
const uint8_t offs = (XYZ_SPACING) * a;
lcd_put_wchar(X_LABEL_POS + offs, XYZ_BASELINE, axis_codes[axis]);
lcd_moveto(X_VALUE_POS + offs, XYZ_BASELINE);
#endif
if (blink)
lcd_put_u8str(value);
Expand Down Expand Up @@ -467,15 +465,11 @@ void MarlinUI::draw_status_screen() {

const xyz_pos_t lpos = current_position.asLogical();
#if ENABLED(STATUS_DISPLAY_INCHES)
if (parser.linear_unit_factor == 25.4f) {
if (parser.imperial_units)
strcpy(zstring, ftostr42sign((lpos.z / parser.linear_unit_factor)));
}
else {
strcpy(zstring, ftostr52sp(lpos.z));
}
#else
strcpy(zstring, ftostr52sp(lpos.z));
else
#endif
strcpy(zstring, ftostr52sp(lpos.z));

if (show_e_total) {
#if ENABLED(LCD_SHOW_E_TOTAL)
Expand All @@ -485,17 +479,16 @@ void MarlinUI::draw_status_screen() {
}
else {
#if ENABLED(STATUS_DISPLAY_INCHES)
if (parser.linear_unit_factor == 25.4f) {
if (parser.imperial_units) {
strcpy(xstring, ftostr53_63((lpos.x / parser.linear_unit_factor)));
strcpy(ystring, ftostr53_63((lpos.y / parser.linear_unit_factor)));
}
else {
strcpy(xstring, ftostr4sign(lpos.x));
strcpy(ystring, ftostr4sign(lpos.y));
#endif
strcpy(xstring, ftostr4sign(lpos.x));
strcpy(ystring, ftostr4sign(lpos.y));
#if ENABLED(STATUS_DISPLAY_INCHES)
}
#else
strcpy(xstring, ftostr4sign(lpos.x));
strcpy(ystring, ftostr4sign(lpos.y));
#endif
}

Expand Down