Additional numtostr functions

This commit is contained in:
Scott Lahteine
2020-03-08 19:42:18 -05:00
parent 0f39386d9b
commit 13118dbd8d
7 changed files with 105 additions and 73 deletions

View File

@ -530,7 +530,7 @@ FORCE_INLINE void _draw_heater_status(const heater_ind_t heater, const char pref
if (prefix >= 0) lcd_put_wchar(prefix);
lcd_put_u8str(i16tostr3(t1 + 0.5));
lcd_put_u8str(i16tostr3rj(t1 + 0.5));
lcd_put_wchar('/');
#if !HEATER_IDLE_HANDLER
@ -582,7 +582,7 @@ FORCE_INLINE void _draw_bed_status(const bool blink) {
#endif
));
if (progress)
lcd_put_u8str(ui8tostr3(progress));
lcd_put_u8str(ui8tostr3rj(progress));
else
lcd_put_u8str_P(PSTR("---"));
lcd_put_wchar('%');
@ -631,7 +631,7 @@ void MarlinUI::draw_status_message(const bool blink) {
lcd_put_u8str_P(PSTR("Dia "));
lcd_put_u8str(ftostr12ns(filwidth.measured_mm));
lcd_put_u8str_P(PSTR(" V"));
lcd_put_u8str(i16tostr3(planner.volumetric_percent(parser.volumetric_enabled)));
lcd_put_u8str(i16tostr3rj(planner.volumetric_percent(parser.volumetric_enabled)));
lcd_put_wchar('%');
return;
}
@ -863,7 +863,7 @@ void MarlinUI::draw_status_screen() {
#if LCD_HEIGHT > 3
lcd_put_wchar(0, 2, LCD_STR_FEEDRATE[0]);
lcd_put_u8str(i16tostr3(feedrate_percentage));
lcd_put_u8str(i16tostr3rj(feedrate_percentage));
lcd_put_wchar('%');
char buffer[14];
@ -902,7 +902,7 @@ void MarlinUI::draw_status_screen() {
#endif
}
lcd_put_wchar(c);
lcd_put_u8str(i16tostr3(per));
lcd_put_u8str(i16tostr3rj(per));
lcd_put_wchar('%');
#endif
#endif
@ -941,7 +941,7 @@ void MarlinUI::draw_status_screen() {
#endif
lcd_put_wchar(LCD_WIDTH - 9, 1, LCD_STR_FEEDRATE[0]);
lcd_put_u8str(i16tostr3(feedrate_percentage));
lcd_put_u8str(i16tostr3rj(feedrate_percentage));
lcd_put_wchar('%');
// ========== Line 3 ==========
@ -1415,9 +1415,9 @@ void MarlinUI::draw_status_screen() {
* Print plot position
*/
lcd_put_wchar(_LCD_W_POS, 0, '(');
lcd_put_u8str(ui8tostr3(x_plot));
lcd_put_u8str(ui8tostr3rj(x_plot));
lcd_put_wchar(',');
lcd_put_u8str(ui8tostr3(y_plot));
lcd_put_u8str(ui8tostr3rj(y_plot));
lcd_put_wchar(')');
#if LCD_HEIGHT <= 3 // 16x2 or 20x2 display

View File

@ -107,7 +107,7 @@
#define PROGRESS_BAR_WIDTH (LCD_PIXEL_WIDTH - PROGRESS_BAR_X)
FORCE_INLINE void _draw_centered_temp(const int16_t temp, const uint8_t tx, const uint8_t ty) {
const char *str = i16tostr3(temp);
const char *str = i16tostr3rj(temp);
const uint8_t len = str[0] != ' ' ? 3 : str[1] != ' ' ? 2 : 1;
lcd_put_u8str(tx - len * (INFO_FONT_WIDTH) / 2 + 1, ty, &str[3-len]);
lcd_put_wchar(LCD_STR_DEGREE[0]);
@ -406,7 +406,7 @@ void MarlinUI::draw_status_screen() {
#if ENABLED(FILAMENT_LCD_DISPLAY)
strcpy(wstring, ftostr12ns(filwidth.measured_mm));
strcpy(mstring, i16tostr3(planner.volumetric_percent(parser.volumetric_enabled)));
strcpy(mstring, i16tostr3rj(planner.volumetric_percent(parser.volumetric_enabled)));
#endif
// Progress / elapsed / estimation updates and string formatting to avoid float math on each LCD draw
@ -438,7 +438,7 @@ void MarlinUI::draw_status_screen() {
#if ENABLED(PRINT_PROGRESS_SHOW_DECIMALS)
permyriadtostr4(progress)
#else
ui8tostr3(progress / (PROGRESS_SCALE))
ui8tostr3rj(progress / (PROGRESS_SCALE))
#endif
));
}
@ -571,7 +571,7 @@ void MarlinUI::draw_status_screen() {
// Laser / Spindle
#if DO_DRAW_CUTTER
if (cutter.power && PAGE_CONTAINS(STATUS_CUTTER_TEXT_Y - INFO_FONT_ASCENT, STATUS_CUTTER_TEXT_Y - 1)) {
lcd_put_u8str(STATUS_CUTTER_TEXT_X, STATUS_CUTTER_TEXT_Y, i16tostr3(cutter.powerPercent(cutter.power)));
lcd_put_u8str(STATUS_CUTTER_TEXT_X, STATUS_CUTTER_TEXT_Y, i16tostr3rj(cutter.powerPercent(cutter.power)));
lcd_put_wchar('%');
}
#endif
@ -598,7 +598,7 @@ void MarlinUI::draw_status_screen() {
c = '*';
}
#endif
lcd_put_u8str(STATUS_FAN_TEXT_X, STATUS_FAN_TEXT_Y, i16tostr3(thermalManager.fanPercent(spd)));
lcd_put_u8str(STATUS_FAN_TEXT_X, STATUS_FAN_TEXT_Y, i16tostr3rj(thermalManager.fanPercent(spd)));
lcd_put_wchar(c);
}
}
@ -768,7 +768,7 @@ void MarlinUI::draw_status_screen() {
lcd_put_wchar(3, EXTRAS_2_BASELINE, LCD_STR_FEEDRATE[0]);
set_font(FONT_STATUSMENU);
lcd_put_u8str(12, EXTRAS_2_BASELINE, i16tostr3(feedrate_percentage));
lcd_put_u8str(12, EXTRAS_2_BASELINE, i16tostr3rj(feedrate_percentage));
lcd_put_wchar('%');
//

View File

@ -324,11 +324,11 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
lcd_put_wchar(LCD_PIXEL_WIDTH - 11 * (MENU_FONT_WIDTH), row_y2, 'E');
lcd_put_wchar((char)('1' + extruder));
lcd_put_wchar(' ');
lcd_put_u8str(i16tostr3(thermalManager.degHotend(extruder)));
lcd_put_u8str(i16tostr3rj(thermalManager.degHotend(extruder)));
lcd_put_wchar('/');
if (get_blink() || !thermalManager.hotend_idle[extruder].timed_out)
lcd_put_u8str(i16tostr3(thermalManager.degTargetHotend(extruder)));
lcd_put_u8str(i16tostr3rj(thermalManager.degTargetHotend(extruder)));
}
#endif // ADVANCED_PAUSE_FEATURE

View File

@ -127,7 +127,7 @@ void MenuItem_gcode::action(PGM_P const, PGM_P const pgcode) { queue.inject_P(pg
*
* The prerequisite is that in the header the type was already declared:
*
* DEFINE_MENU_EDIT_ITEM_TYPE(int16_t, int3, i16tostr3, 1)
* DEFINE_MENU_EDIT_ITEM_TYPE(int3, int16_t, i16tostr3rj, 1)
*
* For example, DEFINE_MENU_EDIT_ITEM(int3) expands into:
*
@ -396,11 +396,7 @@ void scroll_screen(const uint8_t limit, const bool is_menu) {
void lcd_babystep_zoffset() {
if (ui.use_click()) return ui.goto_previous_screen_no_defer();
ui.defer_status_screen();
#if ENABLED(BABYSTEP_HOTEND_Z_OFFSET)
const bool do_probe = (active_extruder == 0);
#else
constexpr bool do_probe = true;
#endif
const bool do_probe = DISABLED(BABYSTEP_HOTEND_Z_OFFSET) || active_extruder == 0;
if (ui.encoderPosition) {
const int16_t babystep_increment = int16_t(ui.encoderPosition) * (BABYSTEP_MULTIPLICATOR_Z);
ui.encoderPosition = 0;
@ -429,14 +425,14 @@ void scroll_screen(const uint8_t limit, const bool is_menu) {
if (ui.should_draw()) {
#if ENABLED(BABYSTEP_HOTEND_Z_OFFSET)
if (!do_probe)
MenuEditItemBase::draw_edit_screen(GET_TEXT(MSG_HOTEND_OFFSET_Z), LCD_Z_OFFSET_FUNC(hotend_offset[active_extruder].z));
else
#endif
MenuEditItemBase::draw_edit_screen(GET_TEXT(MSG_ZPROBE_ZOFFSET), LCD_Z_OFFSET_FUNC(probe.offset.z));
#if ENABLED(BABYSTEP_ZPROBE_GFX_OVERLAY)
if (do_probe) _lcd_zoffset_overlay_gfx(probe.offset.z);
MenuEditItemBase::draw_edit_screen(GET_TEXT(MSG_HOTEND_OFFSET_Z), ftostr54sign(hotend_offset[active_extruder].z));
#endif
if (do_probe) {
MenuEditItemBase::draw_edit_screen(GET_TEXT(MSG_ZPROBE_ZOFFSET), ftostr52sign(probe.offset.z));
#if ENABLED(BABYSTEP_ZPROBE_GFX_OVERLAY)
_lcd_zoffset_overlay_gfx(probe.offset.z);
#endif
}
}
}

View File

@ -48,9 +48,11 @@ typedef void (*selectFunc_t)();
#endif
#if Z_PROBE_OFFSET_RANGE_MIN >= -9 && Z_PROBE_OFFSET_RANGE_MAX <= 9
// Only values from -9.999 to 9.999
#define LCD_Z_OFFSET_FUNC(N) ftostr54sign(N)
#define LCD_Z_OFFSET_TYPE float43
#else
// Values from -99.99 to 99.99
#define LCD_Z_OFFSET_FUNC(N) ftostr52sign(N)
#define LCD_Z_OFFSET_TYPE float52
#endif
@ -266,35 +268,37 @@ class TMenuEditItem : MenuEditItemBase {
// Provide a set of Edit Item Types which encompass a primitive
// type, a string function, and a scale factor for edit and display.
// These items call the Edit Item draw method passing the prepared string.
#define DEFINE_MENU_EDIT_ITEM_TYPE(TYPE, NAME, FIX, STRFUNC, SCALE, V...) \
#define __DOFIXfloat PROBE()
#define _DOFIX(TYPE,V) TYPE(TERN(IS_PROBE(__DOFIX##TYPE),FIXFLOAT(V),(V)))
#define DEFINE_MENU_EDIT_ITEM_TYPE(NAME, TYPE, STRFUNC, SCALE, V...) \
struct MenuEditItemInfo_##NAME { \
typedef TYPE type_t; \
static inline float scale(const float value) { return value * (SCALE) + (V+0); } \
static inline float unscale(const float value) { return value / (SCALE) + (V+0); } \
static inline const char* strfunc(const float value) { return STRFUNC((TYPE)(FIX ? FIXFLOAT(value) : value)); } \
static inline const char* strfunc(const float value) { return STRFUNC(_DOFIX(TYPE,value)); } \
}; \
typedef TMenuEditItem<MenuEditItemInfo_##NAME> MenuItem_##NAME
// TYPE NAME STRFUNC SCALE
DEFINE_MENU_EDIT_ITEM_TYPE(uint8_t, percent, 0, ui8tostr4pct, 100.0/255, 0.5); // 100% right-justified
DEFINE_MENU_EDIT_ITEM_TYPE(int16_t, int3, 0, i16tostr3, 1 ); // 123, -12 right-justified
DEFINE_MENU_EDIT_ITEM_TYPE(int16_t, int4, 0, i16tostr4sign, 1 ); // 1234, -123 right-justified
DEFINE_MENU_EDIT_ITEM_TYPE(int8_t, int8, 0, i8tostr3, 1 ); // 123, -12 right-justified
DEFINE_MENU_EDIT_ITEM_TYPE(uint8_t, uint8, 0, ui8tostr3, 1 ); // 123 right-justified
DEFINE_MENU_EDIT_ITEM_TYPE(uint16_t, uint16_3, 0, ui16tostr3, 1 ); // 123 right-justified
DEFINE_MENU_EDIT_ITEM_TYPE(uint16_t, uint16_4, 0, ui16tostr4, 0.1 ); // 1234 right-justified
DEFINE_MENU_EDIT_ITEM_TYPE(uint16_t, uint16_5, 0, ui16tostr5, 0.01 ); // 12345 right-justified
DEFINE_MENU_EDIT_ITEM_TYPE(float, float3, 1, ftostr3, 1 ); // 123 right-justified
DEFINE_MENU_EDIT_ITEM_TYPE(float, float52, 1, ftostr42_52, 100 ); // _2.34, 12.34, -2.34 or 123.45, -23.45
DEFINE_MENU_EDIT_ITEM_TYPE(float, float43, 1, ftostr43sign, 1000 ); // 1.234
DEFINE_MENU_EDIT_ITEM_TYPE(float, float5, 1, ftostr5rj, 1 ); // 12345 right-justified
DEFINE_MENU_EDIT_ITEM_TYPE(float, float5_25, 1, ftostr5rj, 0.04f ); // 12345 right-justified (25 increment)
DEFINE_MENU_EDIT_ITEM_TYPE(float, float51, 1, ftostr51rj, 10 ); // 1234.5 right-justified
DEFINE_MENU_EDIT_ITEM_TYPE(float, float41sign, 1, ftostr41sign, 10 ); // +123.4
DEFINE_MENU_EDIT_ITEM_TYPE(float, float51sign, 1, ftostr51sign, 10 ); // +1234.5
DEFINE_MENU_EDIT_ITEM_TYPE(float, float52sign, 1, ftostr52sign, 100 ); // +123.45
DEFINE_MENU_EDIT_ITEM_TYPE(uint32_t, long5, 0, ftostr5rj, 0.01f ); // 12345 right-justified
DEFINE_MENU_EDIT_ITEM_TYPE(uint32_t, long5_25, 0, ftostr5rj, 0.04f ); // 12345 right-justified (25 increment)
// NAME TYPE STRFUNC SCALE +ROUND
DEFINE_MENU_EDIT_ITEM_TYPE(percent ,uint8_t ,ui8tostr4pctrj , 100.f/255.f, 0.5f); // 100% right-justified
DEFINE_MENU_EDIT_ITEM_TYPE(int3 ,int16_t ,i16tostr3rj , 1 ); // 123, -12 right-justified
DEFINE_MENU_EDIT_ITEM_TYPE(int4 ,int16_t ,i16tostr4signrj , 1 ); // 1234, -123 right-justified
DEFINE_MENU_EDIT_ITEM_TYPE(int8 ,int8_t ,i8tostr3rj , 1 ); // 123, -12 right-justified
DEFINE_MENU_EDIT_ITEM_TYPE(uint8 ,uint8_t ,ui8tostr3rj , 1 ); // 123 right-justified
DEFINE_MENU_EDIT_ITEM_TYPE(uint16_3 ,uint16_t ,ui16tostr3rj , 1 ); // 123 right-justified
DEFINE_MENU_EDIT_ITEM_TYPE(uint16_4 ,uint16_t ,ui16tostr4rj , 0.1f ); // 1234 right-justified
DEFINE_MENU_EDIT_ITEM_TYPE(uint16_5 ,uint16_t ,ui16tostr5rj , 0.01f ); // 12345 right-justified
DEFINE_MENU_EDIT_ITEM_TYPE(float3 ,float ,ftostr3 , 1 ); // 123 right-justified
DEFINE_MENU_EDIT_ITEM_TYPE(float52 ,float ,ftostr42_52 , 100 ); // _2.34, 12.34, -2.34 or 123.45, -23.45
DEFINE_MENU_EDIT_ITEM_TYPE(float43 ,float ,ftostr43sign ,1000 ); // -1.234, _1.234, +1.234
DEFINE_MENU_EDIT_ITEM_TYPE(float5 ,float ,ftostr5rj , 1 ); // 12345 right-justified
DEFINE_MENU_EDIT_ITEM_TYPE(float5_25 ,float ,ftostr5rj , 0.04f ); // 12345 right-justified (25 increment)
DEFINE_MENU_EDIT_ITEM_TYPE(float51 ,float ,ftostr51rj , 10 ); // 1234.5 right-justified
DEFINE_MENU_EDIT_ITEM_TYPE(float41sign ,float ,ftostr41sign , 10 ); // +123.4
DEFINE_MENU_EDIT_ITEM_TYPE(float51sign ,float ,ftostr51sign , 10 ); // +1234.5
DEFINE_MENU_EDIT_ITEM_TYPE(float52sign ,float ,ftostr52sign , 100 ); // +123.45
DEFINE_MENU_EDIT_ITEM_TYPE(long5 ,uint32_t ,ftostr5rj , 0.01f ); // 12345 right-justified
DEFINE_MENU_EDIT_ITEM_TYPE(long5_25 ,uint32_t ,ftostr5rj , 0.04f ); // 12345 right-justified (25 increment)
class MenuItem_bool : public MenuEditItemBase {
public: