optimisation: refactor menu_draw_P()
Add a way to only change the LCD column Change in memory: Flash: -90 bytes SRAM: 0 bytes
This commit is contained in:
parent
730bb3708e
commit
eeb5f3d50c
|
|
@ -329,13 +329,31 @@ void lcd_no_autoscroll(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void lcd_set_cursor(uint8_t col, uint8_t row)
|
/// @brief set the current LCD row
|
||||||
|
/// @param row LCD row number, ranges from 0 to LCD_HEIGHT - 1
|
||||||
|
static void FORCE_INLINE lcd_set_current_row(uint8_t row)
|
||||||
|
{
|
||||||
|
lcd_currline = min(row, LCD_HEIGHT - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @brief Calculate the LCD row offset
|
||||||
|
/// @param row LCD row number, ranges from 0 to LCD_HEIGHT - 1
|
||||||
|
/// @return row offset which the LCD register understands
|
||||||
|
static uint8_t __attribute__((noinline)) lcd_get_row_offset(uint8_t row)
|
||||||
{
|
{
|
||||||
uint8_t row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
|
uint8_t row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
|
||||||
if (row >= LCD_HEIGHT)
|
return row_offsets[min(row, LCD_HEIGHT - 1)];
|
||||||
row = LCD_HEIGHT - 1; // we count rows starting w/0
|
}
|
||||||
lcd_currline = row;
|
|
||||||
lcd_command(LCD_SETDDRAMADDR | (col + row_offsets[row]));
|
void lcd_set_cursor(uint8_t col, uint8_t row)
|
||||||
|
{
|
||||||
|
lcd_set_current_row(row);
|
||||||
|
lcd_command(LCD_SETDDRAMADDR | (col + lcd_get_row_offset(lcd_currline)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void lcd_set_cursor_column(uint8_t col)
|
||||||
|
{
|
||||||
|
lcd_command(LCD_SETDDRAMADDR | (col + lcd_get_row_offset(lcd_currline)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allows us to fill the first 8 CGRAM locations
|
// Allows us to fill the first 8 CGRAM locations
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,10 @@ extern void lcd_no_autoscroll(void);*/
|
||||||
|
|
||||||
extern void lcd_set_cursor(uint8_t col, uint8_t row);
|
extern void lcd_set_cursor(uint8_t col, uint8_t row);
|
||||||
|
|
||||||
|
/// @brief Change the cursor column position while preserving the current row position
|
||||||
|
/// @param col column number, ranges from 0 to LCD_WIDTH - 1
|
||||||
|
void lcd_set_cursor_column(uint8_t col);
|
||||||
|
|
||||||
extern void lcd_createChar_P(uint8_t, const uint8_t*);
|
extern void lcd_createChar_P(uint8_t, const uint8_t*);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -435,13 +435,21 @@ static void menu_draw_P(char chr, const char* str, int16_t val);
|
||||||
template<>
|
template<>
|
||||||
void menu_draw_P<int16_t*>(char chr, const char* str, int16_t val)
|
void menu_draw_P<int16_t*>(char chr, const char* str, int16_t val)
|
||||||
{
|
{
|
||||||
int text_len = strlen_P(str);
|
// The LCD row position is controlled externally. We may only modify the column here
|
||||||
if (text_len > 15) text_len = 15;
|
lcd_putc(chr);
|
||||||
char spaces[LCD_WIDTH + 1] = {0};
|
uint8_t len = lcd_print_pad_P(str, LCD_WIDTH - 1);
|
||||||
memset(spaces,' ', LCD_WIDTH);
|
lcd_set_cursor_column((LCD_WIDTH - 1) - len + 1);
|
||||||
if (val <= -100) spaces[15 - text_len - 1] = 0;
|
lcd_putc(':');
|
||||||
else spaces[15 - text_len] = 0;
|
|
||||||
lcd_printf_P(menu_fmt_int3, chr, str, spaces, val);
|
// The value is right adjusted, set the cursor then render the value
|
||||||
|
if (val < 10) { // 1 digit
|
||||||
|
lcd_set_cursor_column(LCD_WIDTH - 1);
|
||||||
|
} else if (val < 100) { // 2 digits
|
||||||
|
lcd_set_cursor_column(LCD_WIDTH - 2);
|
||||||
|
} else { // 3 digits
|
||||||
|
lcd_set_cursor_column(LCD_WIDTH - 3);
|
||||||
|
}
|
||||||
|
lcd_print(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue