Skip to content

Commit 823178c

Browse files
robbycandrathinkyhead
authored andcommitted
Use u8g int type for screen coordinates (MarlinFirmware#14965)
1 parent 6715fd1 commit 823178c

8 files changed

+104
-107
lines changed

Marlin/src/lcd/HD44780/lcdprint_hd44780.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ static int pf_bsearch_cb_comp_hd4map_pgm(void *userdata, size_t idx, void * data
877877
return hd44780_charmap_compare(&localval, (hd44780_charmap_t *)data_pin);
878878
}
879879

880-
void lcd_moveto(const uint8_t col, const uint8_t row) { lcd.setCursor(col, row); }
880+
void lcd_moveto(const lcd_uint_t col, const lcd_uint_t row) { lcd.setCursor(col, row); }
881881

882882
void lcd_put_int(const int i) { lcd.print(i); }
883883

Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp

+32-32
Original file line numberDiff line numberDiff line change
@@ -364,14 +364,14 @@ void MarlinUI::clear_lcd() { lcd.clear(); }
364364

365365
#if ENABLED(SHOW_BOOTSCREEN)
366366

367-
void lcd_erase_line(const int16_t line) {
367+
void lcd_erase_line(const lcd_uint_t line) {
368368
lcd_moveto(0, line);
369369
for (uint8_t i = LCD_WIDTH + 1; --i;)
370370
lcd_put_wchar(' ');
371371
}
372372

373373
// Scroll the PSTR 'text' in a 'len' wide field for 'time' milliseconds at position col,line
374-
void lcd_scroll(const uint8_t col, const uint8_t line, PGM_P const text, const uint8_t len, const int16_t time) {
374+
void lcd_scroll(const lcd_uint_t col, const lcd_uint_t line, PGM_P const text, const uint8_t len, const int16_t time) {
375375
uint8_t slen = utf8_strlen_P(text);
376376
if (slen < len) {
377377
// Fits into,
@@ -1031,9 +1031,9 @@ void MarlinUI::draw_status_screen() {
10311031
if (value != nullptr) {
10321032
lcd_put_wchar(':');
10331033
int len = utf8_strlen(value);
1034-
const uint8_t valrow = (utf8_strlen_P(pstr) + 1 + len + 1) > (LCD_WIDTH - 2) ? 2 : 1; // Value on the next row if it won't fit
1035-
lcd_moveto((LCD_WIDTH - 1) - (len + 1), valrow); // Right-justified, padded by spaces
1036-
lcd_put_wchar(' '); // Overwrite char if value gets shorter
1034+
const lcd_uint_t valrow = (utf8_strlen_P(pstr) + 1 + len + 1) > (LCD_WIDTH - 2) ? 2 : 1; // Value on the next row if it won't fit
1035+
lcd_moveto((LCD_WIDTH - 1) - (len + 1), valrow); // Right-justified, padded by spaces
1036+
lcd_put_wchar(' '); // Overwrite char if value gets shorter
10371037
lcd_put_u8str(value);
10381038
}
10391039
}
@@ -1144,9 +1144,9 @@ void MarlinUI::draw_status_screen() {
11441144
} custom_char;
11451145

11461146
typedef struct {
1147-
uint8_t column, row,
1148-
x_pixel_offset, y_pixel_offset,
1149-
x_pixel_mask;
1147+
lcd_uint_t column, row,
1148+
x_pixel_offset, y_pixel_offset;
1149+
uint8_t x_pixel_mask;
11501150
} coordinate;
11511151

11521152
void add_edges_to_custom_char(custom_char &custom, const coordinate &ul, const coordinate &lr, const coordinate &brc, const uint8_t cell_location);
@@ -1174,16 +1174,16 @@ void MarlinUI::draw_status_screen() {
11741174
return ret_val;
11751175
}
11761176

1177-
inline coordinate pixel_location(const uint8_t x, const uint8_t y) { return pixel_location((int16_t)x, (int16_t)y); }
1177+
inline coordinate pixel_location(const lcd_uint_t x, const lcd_uint_t y) { return pixel_location((int16_t)x, (int16_t)y); }
11781178

1179-
void prep_and_put_map_char(custom_char &chrdata, const coordinate &ul, const coordinate &lr, const coordinate &brc, const uint8_t cl, const char c, const uint8_t x, const uint8_t y) {
1179+
void prep_and_put_map_char(custom_char &chrdata, const coordinate &ul, const coordinate &lr, const coordinate &brc, const uint8_t cl, const char c, const lcd_uint_t x, const lcd_uint_t y) {
11801180
add_edges_to_custom_char(chrdata, ul, lr, brc, cl);
11811181
lcd.createChar(c, (uint8_t*)&chrdata);
11821182
lcd_moveto(x, y);
11831183
lcd_put_wchar(c);
11841184
}
11851185

1186-
void MarlinUI::ubl_plot(const uint8_t x, const uint8_t inverted_y) {
1186+
void MarlinUI::ubl_plot(const uint8_t x_plot, const uint8_t y_plot) {
11871187

11881188
#if LCD_WIDTH >= 20
11891189
#define _LCD_W_POS 12
@@ -1209,24 +1209,24 @@ void MarlinUI::draw_status_screen() {
12091209
* Show X and Y positions
12101210
*/
12111211
_XLABEL(_PLOT_X, 0);
1212-
lcd_put_u8str(ftostr52(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x]))));
1212+
lcd_put_u8str(ftostr52(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]))));
12131213

12141214
_YLABEL(_LCD_W_POS, 0);
1215-
lcd_put_u8str(ftostr52(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[inverted_y]))));
1215+
lcd_put_u8str(ftostr52(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]))));
12161216

12171217
lcd_moveto(_PLOT_X, 0);
12181218

12191219
#else // 16x4 or 20x4 display
12201220

12211221
coordinate upper_left, lower_right, bottom_right_corner;
12221222
custom_char new_char;
1223-
uint8_t i, j, k, l, m, n, n_rows, n_cols, y,
1224-
bottom_line, right_edge,
1225-
x_map_pixels, y_map_pixels,
1226-
pixels_per_x_mesh_pnt, pixels_per_y_mesh_pnt,
1227-
suppress_x_offset = 0, suppress_y_offset = 0;
1223+
uint8_t i, n, n_rows, n_cols;
1224+
lcd_uint_t j, k, l, m, bottom_line, right_edge,
1225+
x_map_pixels, y_map_pixels,
1226+
pixels_per_x_mesh_pnt, pixels_per_y_mesh_pnt,
1227+
suppress_x_offset = 0, suppress_y_offset = 0;
12281228

1229-
y = GRID_MAX_POINTS_Y - inverted_y - 1;
1229+
const uint8_t y_plot_inv = (GRID_MAX_POINTS_Y - 1) - y_plot;
12301230

12311231
upper_left.column = 0;
12321232
upper_left.row = 0;
@@ -1310,12 +1310,12 @@ void MarlinUI::draw_status_screen() {
13101310
new_char.custom_char_bits[j] = (uint8_t)_BV(i); // Char #3 is used for the box right edge
13111311
lcd.createChar(CHAR_EDGE_R, (uint8_t*)&new_char);
13121312

1313-
i = x * pixels_per_x_mesh_pnt - suppress_x_offset;
1314-
j = y * pixels_per_y_mesh_pnt - suppress_y_offset;
1313+
i = x_plot * pixels_per_x_mesh_pnt - suppress_x_offset;
1314+
j = y_plot_inv * pixels_per_y_mesh_pnt - suppress_y_offset;
13151315
upper_left = pixel_location(i, j);
13161316

1317-
k = (x + 1) * pixels_per_x_mesh_pnt - 1 - suppress_x_offset;
1318-
l = (y + 1) * pixels_per_y_mesh_pnt - 1 - suppress_y_offset;
1317+
k = (x_plot + 1) * pixels_per_x_mesh_pnt - 1 - suppress_x_offset;
1318+
l = (y_plot_inv + 1) * pixels_per_y_mesh_pnt - 1 - suppress_y_offset;
13191319
lower_right = pixel_location(k, l);
13201320

13211321
bottom_right_corner = pixel_location(x_map_pixels, y_map_pixels);
@@ -1327,7 +1327,7 @@ void MarlinUI::draw_status_screen() {
13271327
*/
13281328

13291329
clear_custom_char(&new_char);
1330-
const uint8_t ypix = _MIN(upper_left.y_pixel_offset + pixels_per_y_mesh_pnt, HD44780_CHAR_HEIGHT);
1330+
const lcd_uint_t ypix = _MIN(upper_left.y_pixel_offset + pixels_per_y_mesh_pnt, HD44780_CHAR_HEIGHT);
13311331
for (j = upper_left.y_pixel_offset; j < ypix; j++) {
13321332
i = upper_left.x_pixel_mask;
13331333
for (k = 0; k < pixels_per_x_mesh_pnt; k++) {
@@ -1400,9 +1400,9 @@ void MarlinUI::draw_status_screen() {
14001400
*/
14011401
lcd_moveto(_LCD_W_POS, 0);
14021402
lcd_put_wchar('(');
1403-
lcd_put_u8str(ui8tostr3(x));
1403+
lcd_put_u8str(ui8tostr3(x_plot));
14041404
lcd_put_wchar(',');
1405-
lcd_put_u8str(ui8tostr3(inverted_y));
1405+
lcd_put_u8str(ui8tostr3(y_plot));
14061406
lcd_put_wchar(')');
14071407

14081408
#if LCD_HEIGHT <= 3 // 16x2 or 20x2 display
@@ -1411,8 +1411,8 @@ void MarlinUI::draw_status_screen() {
14111411
* Print Z values
14121412
*/
14131413
_ZLABEL(_LCD_W_POS, 1);
1414-
if (!isnan(ubl.z_values[x][inverted_y]))
1415-
lcd_put_u8str(ftostr43sign(ubl.z_values[x][inverted_y]));
1414+
if (!isnan(ubl.z_values[x_plot][y_plot]))
1415+
lcd_put_u8str(ftostr43sign(ubl.z_values[x_plot][y_plot]));
14161416
else
14171417
lcd_put_u8str_P(PSTR(" -----"));
14181418

@@ -1422,16 +1422,16 @@ void MarlinUI::draw_status_screen() {
14221422
* Show all values at right of screen
14231423
*/
14241424
_XLABEL(_LCD_W_POS, 1);
1425-
lcd_put_u8str(ftostr52(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x]))));
1425+
lcd_put_u8str(ftostr52(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]))));
14261426
_YLABEL(_LCD_W_POS, 2);
1427-
lcd_put_u8str(ftostr52(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[inverted_y]))));
1427+
lcd_put_u8str(ftostr52(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]))));
14281428

14291429
/**
14301430
* Show the location value
14311431
*/
14321432
_ZLABEL(_LCD_W_POS, 3);
1433-
if (!isnan(ubl.z_values[x][inverted_y]))
1434-
lcd_put_u8str(ftostr43sign(ubl.z_values[x][inverted_y]));
1433+
if (!isnan(ubl.z_values[x_plot][y_plot]))
1434+
lcd_put_u8str(ftostr43sign(ubl.z_values[x_plot][y_plot]));
14351435
else
14361436
lcd_put_u8str_P(PSTR(" -----"));
14371437

Marlin/src/lcd/dogm/lcdprint_u8g.cpp

+7-11
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
int lcd_glyph_height(void) { return u8g_GetFontBBXHeight(u8g.getU8g()); }
2424

25-
void lcd_moveto(const uint8_t col, const uint8_t row) { u8g.setPrintPos(col, row); }
25+
void lcd_moveto(const lcd_uint_t col, const lcd_uint_t row) { u8g.setPrintPos(col, row); }
2626

2727
void lcd_put_int(const int i) { u8g.print(i); }
2828

@@ -33,26 +33,22 @@ int lcd_put_wchar_max(wchar_t c, pixel_len_t max_length) {
3333
u8g.print((char)c);
3434
return u8g_GetFontBBXWidth(u8g.getU8g());
3535
}
36-
unsigned int x = u8g.getPrintCol(),
37-
y = u8g.getPrintRow(),
38-
ret = uxg_DrawWchar(u8g.getU8g(), x, y, c, max_length);
36+
u8g_uint_t x = u8g.getPrintCol(), y = u8g.getPrintRow(),
37+
ret = uxg_DrawWchar(u8g.getU8g(), x, y, c, max_length);
3938
u8g.setPrintPos(x + ret, y);
40-
4139
return ret;
4240
}
4341

4442
int lcd_put_u8str_max(const char * utf8_str, pixel_len_t max_length) {
45-
unsigned int x = u8g.getPrintCol(),
46-
y = u8g.getPrintRow(),
47-
ret = uxg_DrawUtf8Str(u8g.getU8g(), x, y, utf8_str, max_length);
43+
u8g_uint_t x = u8g.getPrintCol(), y = u8g.getPrintRow(),
44+
ret = uxg_DrawUtf8Str(u8g.getU8g(), x, y, utf8_str, max_length);
4845
u8g.setPrintPos(x + ret, y);
4946
return ret;
5047
}
5148

5249
int lcd_put_u8str_max_P(PGM_P utf8_str_P, pixel_len_t max_length) {
53-
unsigned int x = u8g.getPrintCol(),
54-
y = u8g.getPrintRow(),
55-
ret = uxg_DrawUtf8StrP(u8g.getU8g(), x, y, utf8_str_P, max_length);
50+
u8g_uint_t x = u8g.getPrintCol(), y = u8g.getPrintRow(),
51+
ret = uxg_DrawUtf8StrP(u8g.getU8g(), x, y, utf8_str_P, max_length);
5652
u8g.setPrintPos(x + ret, y);
5753
return ret;
5854
}

0 commit comments

Comments
 (0)