Skip to content

Commit

Permalink
Minor LCD cleanup, improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead authored and Alexander Yasnogor committed Aug 7, 2020
1 parent 2ad17e5 commit bcc160b
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 86 deletions.
16 changes: 6 additions & 10 deletions Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@
static void echo_and_take_a_measurement() { SERIAL_ECHOLNPGM(" and take a measurement."); }

float unified_bed_leveling::measure_business_card_thickness(float in_height) {
TERN_(HAS_LCD_MENU, ui.capture());
ui.capture();
save_ubl_active_state_and_disable(); // Disable bed level correction for probing

do_blocking_move_to(0.5f * (MESH_MAX_X - (MESH_MIN_X)), 0.5f * (MESH_MAX_Y - (MESH_MIN_Y)), in_height);
Expand Down Expand Up @@ -857,15 +857,13 @@
SERIAL_ECHOLNPGM("mm thick.");
}

ui.release();

restore_ubl_active_state_and_leave();

return thickness;
}

void unified_bed_leveling::manually_probe_remaining_mesh(const xy_pos_t &pos, const float &z_clearance, const float &thick, const bool do_ubl_mesh_map) {
TERN_(HAS_LCD_MENU, ui.capture());
ui.capture();

save_ubl_active_state_and_disable(); // No bed level correction so only raw data is obtained
do_blocking_move_to_xy_z(current_position, z_clearance);
Expand Down Expand Up @@ -893,7 +891,7 @@
do_blocking_move_to_z(z_clearance);

KEEPALIVE_STATE(PAUSED_FOR_USER);
TERN_(HAS_LCD_MENU, ui.capture());
ui.capture();

if (do_ubl_mesh_map) display_map(g29_map_type); // show user where we're probing

Expand All @@ -907,7 +905,6 @@
if (click_and_hold()) {
SERIAL_ECHOLNPGM("\nMesh only partially populated.");
do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
ui.release();
return restore_ubl_active_state_and_leave();
}

Expand Down Expand Up @@ -958,9 +955,9 @@
save_ubl_active_state_and_disable();

LCD_MESSAGEPGM(MSG_UBL_FINE_TUNE_MESH);
TERN_(HAS_LCD_MENU, ui.capture()); // Take over control of the LCD encoder
ui.capture(); // Take over control of the LCD encoder

do_blocking_move_to_xy_z(pos, Z_CLEARANCE_BETWEEN_PROBES); // Move to the given XY with probe clearance
do_blocking_move_to_xy_z(pos, Z_CLEARANCE_BETWEEN_PROBES); // Move to the given XY with probe clearance

TERN_(UBL_MESH_EDIT_MOVES_Z, do_blocking_move_to_z(h_offset)); // Move Z to the given 'H' offset

Expand Down Expand Up @@ -1016,8 +1013,6 @@

} while (lpos.x >= 0 && --g29_repetition_cnt > 0);

ui.release();

if (do_ubl_mesh_map) display_map(g29_map_type);
restore_ubl_active_state_and_leave();

Expand Down Expand Up @@ -1168,6 +1163,7 @@
}

void unified_bed_leveling::restore_ubl_active_state_and_leave() {
TERN_(HAS_LCD_MENU, ui.release());
#if ENABLED(UBL_DEVEL_DEBUGGING)
if (--ubl_state_recursion_chk) {
SERIAL_ECHOLNPGM("restore_ubl_active_state_and_leave() called too many times.");
Expand Down
16 changes: 9 additions & 7 deletions Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,20 +824,22 @@ void MarlinUI::draw_status_screen() {

#else // !HAS_DUAL_MIXING

if (TERN1(LCD_SHOW_E_TOTAL, !printingIsActive())) {
const xy_pos_t lpos = current_position.asLogical();
_draw_axis_value(X_AXIS, ftostr4sign(lpos.x), blink);
lcd_put_wchar(' ');
_draw_axis_value(Y_AXIS, ftostr4sign(lpos.y), blink);
}
else {
const bool show_e_total = TERN0(LCD_SHOW_E_TOTAL, printingIsActive() || marlin_state == MF_SD_COMPLETE);

if (show_e_total) {
#if ENABLED(LCD_SHOW_E_TOTAL)
char tmp[20];
const uint8_t escale = e_move_accumulator >= 100000.0f ? 10 : 1; // After 100m switch to cm
sprintf_P(tmp, PSTR("E %ld%cm "), uint32_t(_MAX(e_move_accumulator, 0.0f)) / escale, escale == 10 ? 'c' : 'm'); // 1234567mm
lcd_put_u8str(tmp);
#endif
}
else {
const xy_pos_t lpos = current_position.asLogical();
_draw_axis_value(X_AXIS, ftostr4sign(lpos.x), blink);
lcd_put_wchar(' ');
_draw_axis_value(Y_AXIS, ftostr4sign(lpos.y), blink);
}

#endif // !HAS_DUAL_MIXING

Expand Down
22 changes: 11 additions & 11 deletions Marlin/src/lcd/dogm/status_screen_DOGM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ void MarlinUI::draw_status_screen() {
#endif
#endif

const bool showxy = TERN1(LCD_SHOW_E_TOTAL, !printingIsActive());
const bool show_e_total = TERN0(LCD_SHOW_E_TOTAL, printingIsActive() || marlin_state == MF_SD_COMPLETE);

// At the first page, generate new display values
if (first_page) {
Expand All @@ -434,16 +434,16 @@ void MarlinUI::draw_status_screen() {
const xyz_pos_t lpos = current_position.asLogical();
strcpy(zstring, ftostr52sp(lpos.z));

if (showxy) {
strcpy(xstring, ftostr4sign(lpos.x));
strcpy(ystring, ftostr4sign(lpos.y));
}
else {
if (show_e_total) {
#if ENABLED(LCD_SHOW_E_TOTAL)
const uint8_t escale = e_move_accumulator >= 100000.0f ? 10 : 1; // After 100m switch to cm
sprintf_P(xstring, PSTR("%ld%cm"), uint32_t(_MAX(e_move_accumulator, 0.0f)) / escale, escale == 10 ? 'c' : 'm'); // 1234567mm
#endif
}
else {
strcpy(xstring, ftostr4sign(lpos.x));
strcpy(ystring, ftostr4sign(lpos.y));
}

#if ENABLED(FILAMENT_LCD_DISPLAY)
strcpy(wstring, ftostr12ns(filwidth.measured_mm));
Expand Down Expand Up @@ -772,14 +772,14 @@ void MarlinUI::draw_status_screen() {

#else

if (showxy) {
_draw_axis_value(X_AXIS, xstring, blink);
_draw_axis_value(Y_AXIS, ystring, blink);
}
else {
if (show_e_total) {
_draw_axis_value(E_AXIS, xstring, true);
lcd_put_u8str_P(PSTR(" "));
}
else {
_draw_axis_value(X_AXIS, xstring, blink);
_draw_axis_value(Y_AXIS, ystring, blink);
}

#endif

Expand Down
38 changes: 20 additions & 18 deletions Marlin/src/lcd/dogm/ultralcd_DOGM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop

#endif // ADVANCED_PAUSE_FEATURE

// Set the colors for a menu item based on whether it is selected
// Mark a menu item and set font color if selected.
// Return 'false' if the item is not on screen.
static bool mark_as_selected(const uint8_t row, const bool sel) {
row_y1 = row * (MENU_FONT_HEIGHT) + 1;
row_y2 = row_y1 + MENU_FONT_HEIGHT - 1;
Expand All @@ -330,15 +331,13 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
u8g.drawHLine(0, row_y1 + 1, LCD_PIXEL_WIDTH);
u8g.drawHLine(0, row_y2 + 2, LCD_PIXEL_WIDTH);
#else
u8g.setColorIndex(1); // black on white
u8g.setColorIndex(1); // solid outline
u8g.drawBox(0, row_y1 + 2, LCD_PIXEL_WIDTH, MENU_FONT_HEIGHT - 1);
u8g.setColorIndex(0); // white on black
u8g.setColorIndex(0); // inverted text
#endif
}
#if DISABLED(MENU_HOLLOW_FRAME)
else {
u8g.setColorIndex(1); // unmarked text is black on white
}
else u8g.setColorIndex(1); // solid text
#endif

if (!PAGE_CONTAINS(row_y1, row_y2)) return false;
Expand All @@ -352,13 +351,15 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop

if (mark_as_selected(row, style & SS_INVERT)) {

u8g_uint_t n = LCD_PIXEL_WIDTH; // pixel width of string allowed
pixel_len_t n = LCD_PIXEL_WIDTH; // pixel width of string allowed

if ((style & SS_CENTER) && !valstr) {
int8_t pad = (LCD_WIDTH - utf8_strlen_P(pstr)) / 2;
while (--pad >= 0) { lcd_put_wchar(' '); n--; }
}
n = lcd_put_u8str_ind_P(pstr, itemIndex, LCD_WIDTH) * (MENU_FONT_WIDTH);
if ((style & SS_CENTER) && !valstr)
for (int8_t pad = (LCD_WIDTH - utf8_strlen_P(pstr)) / 2; pad > 0; --pad) {
lcd_put_wchar(' ');
n -= MENU_FONT_WIDTH;
}

n = lcd_put_u8str_ind_P(pstr, itemIndex, n / (MENU_FONT_WIDTH)) * (MENU_FONT_WIDTH);
if (valstr) n -= lcd_put_u8str_max(valstr, n);
while (n > MENU_FONT_WIDTH) n -= lcd_put_wchar(' ');
}
Expand All @@ -367,7 +368,7 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
// Draw a generic menu item
void MenuItemBase::_draw(const bool sel, const uint8_t row, PGM_P const pstr, const char, const char post_char) {
if (mark_as_selected(row, sel)) {
u8g_uint_t n = lcd_put_u8str_ind_P(pstr, itemIndex, LCD_WIDTH - 2) * (MENU_FONT_WIDTH);
pixel_len_t n = lcd_put_u8str_ind_P(pstr, itemIndex, LCD_WIDTH - 1) * (MENU_FONT_WIDTH);
while (n > MENU_FONT_WIDTH) n -= lcd_put_wchar(' ');
lcd_put_wchar(LCD_PIXEL_WIDTH - (MENU_FONT_WIDTH), row_y2, post_char);
lcd_put_wchar(' ');
Expand All @@ -380,7 +381,7 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
const uint8_t vallen = (pgm ? utf8_strlen_P(data) : utf8_strlen((char*)data)),
pixelwidth = (pgm ? uxg_GetUtf8StrPixelWidthP(u8g.getU8g(), data) : uxg_GetUtf8StrPixelWidth(u8g.getU8g(), (char*)data));

u8g_uint_t n = lcd_put_u8str_ind_P(pstr, itemIndex, LCD_WIDTH - 2 - vallen) * (MENU_FONT_WIDTH);
pixel_len_t n = lcd_put_u8str_ind_P(pstr, itemIndex, LCD_WIDTH - 2 - vallen) * (MENU_FONT_WIDTH);
if (vallen) {
lcd_put_wchar(':');
while (n > MENU_FONT_WIDTH) n -= lcd_put_wchar(' ');
Expand Down Expand Up @@ -440,8 +441,9 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
}

inline void draw_boxed_string(const u8g_uint_t x, const u8g_uint_t y, PGM_P const pstr, const bool inv) {
const u8g_uint_t len = utf8_strlen_P(pstr), bw = len * (MENU_FONT_WIDTH),
bx = x * (MENU_FONT_WIDTH), by = (y + 1) * (MENU_FONT_HEIGHT);
const u8g_uint_t len = utf8_strlen_P(pstr),
by = (y + 1) * (MENU_FONT_HEIGHT);
const pixel_len_t bw = len * (MENU_FONT_WIDTH), bx = x * (MENU_FONT_WIDTH);
if (inv) {
u8g.setColorIndex(1);
u8g.drawBox(bx - 1, by - (MENU_FONT_ASCENT) + 1, bw + 2, MENU_FONT_HEIGHT - 1);
Expand All @@ -463,8 +465,8 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
if (mark_as_selected(row, sel)) {
if (isDir) lcd_put_wchar(LCD_STR_FOLDER[0]);
constexpr uint8_t maxlen = LCD_WIDTH - 1;
const u8g_uint_t pixw = maxlen * (MENU_FONT_WIDTH);
u8g_uint_t n = pixw - lcd_put_u8str_max(ui.scrolled_filename(theCard, maxlen, row, sel), pixw);
const pixel_len_t pixw = maxlen * (MENU_FONT_WIDTH);
pixel_len_t n = pixw - lcd_put_u8str_max(ui.scrolled_filename(theCard, maxlen, row, sel), pixw);
while (n > MENU_FONT_WIDTH) n -= lcd_put_wchar(' ');
}
}
Expand Down
28 changes: 11 additions & 17 deletions Marlin/src/lcd/menu/menu_motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,9 @@
#include "../../feature/bedlevel/bedlevel.h"
#endif

extern millis_t manual_move_start_time;
extern int8_t manual_move_axis;
#if ENABLED(MANUAL_E_MOVES_RELATIVE)
float manual_move_e_origin = 0;
#endif
#if IS_KINEMATIC
extern float manual_move_offset;
#endif

//
// Tell ui.update() to start a move to current_position" after a short delay.
Expand All @@ -66,8 +61,8 @@ inline void manual_move_to_current(AxisEnum axis
#if MULTI_MANUAL
if (axis == E_AXIS) ui.manual_move_e_index = eindex >= 0 ? eindex : active_extruder;
#endif
manual_move_start_time = millis() + (move_menu_scale < 0.99f ? 0UL : 250UL); // delay for bigger moves
manual_move_axis = (int8_t)axis;
ui.manual_move_start_time = millis() + (move_menu_scale < 0.99f ? 0UL : 250UL); // delay for bigger moves
ui.manual_move_axis = (int8_t)axis;
}

//
Expand Down Expand Up @@ -112,11 +107,11 @@ static void _lcd_move_xyz(PGM_P const name, const AxisEnum axis) {
// Get the new position
const float diff = float(int32_t(ui.encoderPosition)) * move_menu_scale;
#if IS_KINEMATIC
manual_move_offset += diff;
ui.manual_move_offset += diff;
if (int32_t(ui.encoderPosition) < 0)
NOLESS(manual_move_offset, min - current_position[axis]);
NOLESS(ui.manual_move_offset, min - current_position[axis]);
else
NOMORE(manual_move_offset, max - current_position[axis]);
NOMORE(ui.manual_move_offset, max - current_position[axis]);
#else
current_position[axis] += diff;
if (int32_t(ui.encoderPosition) < 0)
Expand All @@ -130,11 +125,10 @@ static void _lcd_move_xyz(PGM_P const name, const AxisEnum axis) {
}
ui.encoderPosition = 0;
if (ui.should_draw()) {
const float pos = NATIVE_TO_LOGICAL(ui.processing_manual_move ? destination[axis] : current_position[axis]
#if IS_KINEMATIC
+ manual_move_offset
#endif
, axis);
const float pos = NATIVE_TO_LOGICAL(
ui.processing_manual_move ? destination[axis] : current_position[axis] + TERN0(IS_KINEMATIC, ui.manual_move_offset),
axis
);
MenuEditItemBase::draw_edit_screen(name, move_menu_scale >= 0.1f ? ftostr41sign(pos) : ftostr43sign(pos));
}
}
Expand All @@ -149,7 +143,7 @@ void lcd_move_z() { _lcd_move_xyz(GET_TEXT(MSG_MOVE_Z), Z_AXIS); }
if (ui.encoderPosition) {
if (!ui.processing_manual_move) {
const float diff = float(int32_t(ui.encoderPosition)) * move_menu_scale;
TERN(IS_KINEMATIC, manual_move_offset, current_position.e) += diff;
TERN(IS_KINEMATIC, ui.manual_move_offset, current_position.e) += diff;
manual_move_to_current(E_AXIS
#if MULTI_MANUAL
, eindex
Expand All @@ -166,7 +160,7 @@ void lcd_move_z() { _lcd_move_xyz(GET_TEXT(MSG_MOVE_Z), Z_AXIS); }
MenuEditItemBase::draw_edit_screen(
GET_TEXT(TERN(MULTI_MANUAL, MSG_MOVE_EN, MSG_MOVE_E)),
ftostr41sign(current_position.e
+ TERN0(IS_KINEMATIC, manual_move_offset)
+ TERN0(IS_KINEMATIC, ui.manual_move_offset)
- TERN0(MANUAL_E_MOVES_RELATIVE, manual_move_e_origin)
)
);
Expand Down
24 changes: 7 additions & 17 deletions Marlin/src/lcd/menu/menu_ubl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "menu.h"
#include "../../gcode/gcode.h"
#include "../../gcode/queue.h"
#include "../../module/motion.h"
#include "../../module/planner.h"
#include "../../module/configuration_store.h"
#include "../../feature/bedlevel/bedlevel.h"
Expand Down Expand Up @@ -356,24 +357,16 @@ void _lcd_ubl_build_mesh() {
}

/**
* UBL Load Mesh Command
* UBL Load / Save Mesh Commands
*/
void _lcd_ubl_load_mesh_cmd() {
inline void _lcd_ubl_load_save_cmd(const char loadsave, PGM_P const msg) {
char ubl_lcd_gcode[40];
sprintf_P(ubl_lcd_gcode, PSTR("G29 L%i\nM117 "), ubl_storage_slot);
sprintf_P(&ubl_lcd_gcode[strlen(ubl_lcd_gcode)], GET_TEXT(MSG_MESH_LOADED), ubl_storage_slot);
gcode.process_subcommands_now(ubl_lcd_gcode);
}

/**
* UBL Save Mesh Command
*/
void _lcd_ubl_save_mesh_cmd() {
char ubl_lcd_gcode[40];
sprintf_P(ubl_lcd_gcode, PSTR("G29 S%i\nM117 "), ubl_storage_slot);
sprintf_P(&ubl_lcd_gcode[strlen(ubl_lcd_gcode)], GET_TEXT(MSG_MESH_SAVED), ubl_storage_slot);
sprintf_P(ubl_lcd_gcode, PSTR("G29 %c%i\nM117 "), loadsave, ubl_storage_slot);
sprintf_P(&ubl_lcd_gcode[strlen(ubl_lcd_gcode)], msg, ubl_storage_slot);
gcode.process_subcommands_now(ubl_lcd_gcode);
}
void _lcd_ubl_load_mesh_cmd() { _lcd_ubl_load_save_cmd('L', GET_TEXT(MSG_MESH_LOADED)); }
void _lcd_ubl_save_mesh_cmd() { _lcd_ubl_load_save_cmd('S', GET_TEXT(MSG_MESH_SAVED)); }

/**
* UBL Mesh Storage submenu
Expand Down Expand Up @@ -444,9 +437,6 @@ void ubl_map_move_to_xy() {
/**
* UBL LCD "radar" map
*/
void set_current_from_steppers_for_axis(const AxisEnum axis);
void sync_plan_position();

void _lcd_ubl_output_map_lcd() {

static int16_t step_scaler = 0;
Expand Down
10 changes: 5 additions & 5 deletions Marlin/src/lcd/ultralcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,12 +637,12 @@ void MarlinUI::quick_feedback(const bool clear_buttons/*=true*/) {

#if HAS_LCD_MENU

int8_t manual_move_axis = (int8_t)NO_AXIS;
millis_t manual_move_start_time = 0;
int8_t MarlinUI::manual_move_axis = (int8_t)NO_AXIS;
millis_t MarlinUI::manual_move_start_time = 0;

#if IS_KINEMATIC
bool MarlinUI::processing_manual_move = false;
float manual_move_offset = 0;
float MarlinUI::manual_move_offset = 0;
#endif

#if MULTI_MANUAL
Expand Down Expand Up @@ -905,8 +905,8 @@ void MarlinUI::update() {
}
#endif

// then we want to use 1/2 of the time only.
uint16_t bbr2 = planner.block_buffer_runtime() >> 1;
// Then we want to use only 50% of the time
const uint16_t bbr2 = planner.block_buffer_runtime() >> 1;

if ((should_draw() || drawing_screen) && (!bbr2 || bbr2 > max_display_update_time)) {

Expand Down
Loading

0 comments on commit bcc160b

Please sign in to comment.