2018-07-16 00:13:52 +00:00
|
|
|
//menu.cpp
|
|
|
|
|
|
|
|
#include "menu.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <avr/pgmspace.h>
|
|
|
|
#include "lcd.h"
|
2018-07-16 21:23:15 +00:00
|
|
|
#include "Configuration.h"
|
|
|
|
#include "Marlin.h"
|
2018-08-01 20:37:10 +00:00
|
|
|
#include "ultralcd.h"
|
2018-08-24 18:06:09 +00:00
|
|
|
#include "language.h"
|
2018-09-27 17:59:29 +00:00
|
|
|
#include "static_assert.h"
|
2019-06-10 13:03:52 +00:00
|
|
|
#include "sound.h"
|
2018-07-16 00:13:52 +00:00
|
|
|
|
|
|
|
extern int32_t lcd_encoder;
|
|
|
|
|
2019-02-21 03:45:44 +00:00
|
|
|
#define MENU_DEPTH_MAX 6
|
2018-07-16 00:13:52 +00:00
|
|
|
|
2018-08-22 16:55:42 +00:00
|
|
|
static menu_record_t menu_stack[MENU_DEPTH_MAX];
|
2018-07-16 00:13:52 +00:00
|
|
|
|
|
|
|
uint8_t menu_data[MENU_DATA_SIZE];
|
2018-08-22 17:40:12 +00:00
|
|
|
#ifndef __AVR__
|
|
|
|
#error "menu_data is non-portable to non 8bit processor"
|
|
|
|
#endif
|
2018-07-16 00:13:52 +00:00
|
|
|
|
|
|
|
uint8_t menu_depth = 0;
|
2019-05-24 06:46:44 +00:00
|
|
|
uint8_t menu_block_entering_on_serious_errors = SERIOUS_ERR_NONE;
|
2018-07-16 00:13:52 +00:00
|
|
|
uint8_t menu_line = 0;
|
|
|
|
uint8_t menu_item = 0;
|
|
|
|
uint8_t menu_row = 0;
|
|
|
|
uint8_t menu_top = 0;
|
|
|
|
|
|
|
|
uint8_t menu_clicked = 0;
|
|
|
|
|
2018-08-19 11:59:33 +00:00
|
|
|
uint8_t menu_entering = 0;
|
|
|
|
uint8_t menu_leaving = 0;
|
|
|
|
|
2018-07-16 00:13:52 +00:00
|
|
|
menu_func_t menu_menu = 0;
|
|
|
|
|
2018-08-22 16:55:42 +00:00
|
|
|
static_assert(sizeof(menu_data)>= sizeof(menu_data_edit_t),"menu_data_edit_t doesn't fit into menu_data");
|
|
|
|
|
2018-07-16 00:13:52 +00:00
|
|
|
|
|
|
|
void menu_goto(menu_func_t menu, const uint32_t encoder, const bool feedback, bool reset_menu_state)
|
|
|
|
{
|
|
|
|
asm("cli");
|
|
|
|
if (menu_menu != menu)
|
|
|
|
{
|
|
|
|
menu_menu = menu;
|
|
|
|
lcd_encoder = encoder;
|
|
|
|
asm("sei");
|
|
|
|
if (reset_menu_state)
|
|
|
|
{
|
|
|
|
// Resets the global shared C union.
|
|
|
|
// This ensures, that the menu entered will find out, that it shall initialize itself.
|
|
|
|
memset(&menu_data, 0, sizeof(menu_data));
|
|
|
|
}
|
|
|
|
if (feedback) lcd_quick_feedback();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
asm("sei");
|
|
|
|
}
|
|
|
|
|
|
|
|
void menu_start(void)
|
|
|
|
{
|
|
|
|
if (lcd_encoder > 0x8000) lcd_encoder = 0;
|
2019-06-10 13:03:52 +00:00
|
|
|
if (lcd_encoder < 0)
|
|
|
|
{
|
|
|
|
lcd_encoder = 0;
|
|
|
|
Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
|
|
|
|
}
|
2018-07-16 00:13:52 +00:00
|
|
|
if (lcd_encoder < menu_top)
|
|
|
|
menu_top = lcd_encoder;
|
|
|
|
menu_line = menu_top;
|
|
|
|
menu_clicked = LCD_CLICKED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void menu_end(void)
|
|
|
|
{
|
|
|
|
if (lcd_encoder >= menu_item)
|
2019-06-10 13:03:52 +00:00
|
|
|
{
|
2018-07-16 00:13:52 +00:00
|
|
|
lcd_encoder = menu_item - 1;
|
2019-06-10 13:03:52 +00:00
|
|
|
Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
|
|
|
|
}
|
2018-07-16 00:13:52 +00:00
|
|
|
if (((uint8_t)lcd_encoder) >= menu_top + LCD_HEIGHT)
|
|
|
|
{
|
|
|
|
menu_top = lcd_encoder - LCD_HEIGHT + 1;
|
|
|
|
lcd_draw_update = 1;
|
|
|
|
menu_line = menu_top - 1;
|
|
|
|
menu_row = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-20 02:01:33 +00:00
|
|
|
void menu_back(uint8_t nLevel)
|
|
|
|
{
|
|
|
|
menu_depth = ((menu_depth > nLevel) ? (menu_depth - nLevel) : 0);
|
|
|
|
menu_goto(menu_stack[menu_depth].menu, menu_stack[menu_depth].position, true, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void menu_back(void)
|
|
|
|
{
|
|
|
|
menu_back(1);
|
|
|
|
}
|
|
|
|
|
2018-08-24 16:00:05 +00:00
|
|
|
static void menu_back_no_reset(void)
|
2018-08-19 11:59:33 +00:00
|
|
|
{
|
|
|
|
if (menu_depth > 0)
|
|
|
|
{
|
|
|
|
menu_depth--;
|
|
|
|
menu_goto(menu_stack[menu_depth].menu, menu_stack[menu_depth].position, true, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-16 00:13:52 +00:00
|
|
|
void menu_back_if_clicked(void)
|
|
|
|
{
|
|
|
|
if (lcd_clicked())
|
|
|
|
menu_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
void menu_back_if_clicked_fb(void)
|
|
|
|
{
|
|
|
|
if (lcd_clicked())
|
|
|
|
{
|
|
|
|
lcd_quick_feedback();
|
|
|
|
menu_back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void menu_submenu(menu_func_t submenu)
|
|
|
|
{
|
2019-02-06 17:25:45 +00:00
|
|
|
if (menu_depth < MENU_DEPTH_MAX)
|
2018-07-16 00:13:52 +00:00
|
|
|
{
|
|
|
|
menu_stack[menu_depth].menu = menu_menu;
|
|
|
|
menu_stack[menu_depth++].position = lcd_encoder;
|
|
|
|
menu_goto(submenu, 0, true, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-24 16:00:05 +00:00
|
|
|
static void menu_submenu_no_reset(menu_func_t submenu)
|
2018-08-19 11:59:33 +00:00
|
|
|
{
|
2019-02-06 17:25:45 +00:00
|
|
|
if (menu_depth < MENU_DEPTH_MAX)
|
2018-08-19 11:59:33 +00:00
|
|
|
{
|
|
|
|
menu_stack[menu_depth].menu = menu_menu;
|
|
|
|
menu_stack[menu_depth++].position = lcd_encoder;
|
|
|
|
menu_goto(submenu, 0, true, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-16 00:13:52 +00:00
|
|
|
uint8_t menu_item_ret(void)
|
|
|
|
{
|
2018-07-16 02:13:26 +00:00
|
|
|
lcd_beeper_quick_feedback();
|
2018-07-16 00:13:52 +00:00
|
|
|
lcd_draw_update = 2;
|
|
|
|
lcd_button_pressed = false;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-08-09 15:43:43 +00:00
|
|
|
int menu_draw_item_printf_P(char type_char, const char* format, ...)
|
2018-07-16 00:13:52 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
|
|
|
int ret = 0;
|
|
|
|
lcd_set_cursor(0, menu_row);
|
|
|
|
if (lcd_encoder == menu_item)
|
2018-07-16 17:29:27 +00:00
|
|
|
lcd_print('>');
|
2018-07-16 00:13:52 +00:00
|
|
|
else
|
2018-07-16 17:29:27 +00:00
|
|
|
lcd_print(' ');
|
2018-07-16 00:13:52 +00:00
|
|
|
int cnt = vfprintf_P(lcdout, format, args);
|
|
|
|
for (int i = cnt; i < 18; i++)
|
2018-07-16 17:29:27 +00:00
|
|
|
lcd_print(' ');
|
|
|
|
lcd_print(type_char);
|
2018-07-16 00:13:52 +00:00
|
|
|
va_end(args);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
*/
|
2018-08-09 15:43:43 +00:00
|
|
|
|
2019-07-04 11:36:02 +00:00
|
|
|
static char menu_selection_mark(){
|
|
|
|
return (lcd_encoder == menu_item)?'>':' ';
|
|
|
|
}
|
|
|
|
|
2019-05-14 13:47:25 +00:00
|
|
|
static void menu_draw_item_puts_P(char type_char, const char* str)
|
2018-07-16 00:13:52 +00:00
|
|
|
{
|
|
|
|
lcd_set_cursor(0, menu_row);
|
2019-07-04 11:36:02 +00:00
|
|
|
lcd_printf_P(PSTR("%c%-18.18S%c"), menu_selection_mark(), str, type_char);
|
2019-05-14 13:47:25 +00:00
|
|
|
}
|
|
|
|
|
2019-06-26 13:47:06 +00:00
|
|
|
//! @brief Format sheet name
|
2019-06-26 13:23:55 +00:00
|
|
|
//!
|
|
|
|
//! @param[in] sheet_E Sheet in EEPROM
|
|
|
|
//! @param[out] buffer for formatted output
|
2019-06-26 13:51:58 +00:00
|
|
|
void menu_format_sheet_E(const Sheet &sheet_E, SheetFormatBuffer &buffer)
|
2019-06-26 13:23:55 +00:00
|
|
|
{
|
2019-06-26 13:47:06 +00:00
|
|
|
uint_least8_t index = sprintf_P(buffer.c, PSTR("%.10S "), _T(MSG_SHEET));
|
2019-06-26 13:23:55 +00:00
|
|
|
eeprom_read_block(&(buffer.c[index]), sheet_E.name, 7);
|
2019-07-04 11:36:02 +00:00
|
|
|
//index += 7;
|
2019-07-04 13:31:44 +00:00
|
|
|
buffer.c[index + 7] = '\0';
|
2019-06-26 13:23:55 +00:00
|
|
|
}
|
|
|
|
|
2019-07-19 16:34:46 +00:00
|
|
|
//! @brief Format sheet name in select menu
|
|
|
|
//!
|
|
|
|
//! @param[in] sheet_E Sheet in EEPROM
|
|
|
|
//! @param[out] buffer for formatted output
|
|
|
|
void menu_format_sheet_select_E(const Sheet &sheet_E, SheetFormatBuffer &buffer)
|
|
|
|
{
|
2019-07-23 09:31:20 +00:00
|
|
|
uint_least8_t index = sprintf_P(buffer.c,PSTR("%-9.9S["), _T(MSG_SHEET));
|
2019-08-29 18:13:10 +00:00
|
|
|
eeprom_read_block(&(buffer.c[index]), sheet_E.name, sizeof(sheet_E.name)/sizeof(sheet_E.name[0]));
|
|
|
|
for (const uint_least8_t start = index;index - start < sizeof(sheet_E.name)/sizeof(sheet_E.name[0]);++index)
|
|
|
|
{
|
|
|
|
if (buffer.c[index] == '\0') break;
|
|
|
|
}
|
|
|
|
buffer.c[index] = ']';
|
|
|
|
buffer.c[index + 1] = '\0';
|
2019-07-19 16:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void menu_draw_item_select_sheet_E(char type_char, const Sheet &sheet)
|
|
|
|
{
|
|
|
|
lcd_set_cursor(0, menu_row);
|
|
|
|
SheetFormatBuffer buffer;
|
|
|
|
menu_format_sheet_select_E(sheet, buffer);
|
|
|
|
lcd_printf_P(PSTR("%c%-18.18s%c"), menu_selection_mark(), buffer.c, type_char);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-26 13:51:58 +00:00
|
|
|
static void menu_draw_item_puts_E(char type_char, const Sheet &sheet)
|
2019-06-20 14:40:53 +00:00
|
|
|
{
|
|
|
|
lcd_set_cursor(0, menu_row);
|
2019-06-26 13:23:55 +00:00
|
|
|
SheetFormatBuffer buffer;
|
2019-06-26 13:51:58 +00:00
|
|
|
menu_format_sheet_E(sheet, buffer);
|
2019-07-04 11:36:02 +00:00
|
|
|
lcd_printf_P(PSTR("%c%-18.18s%c"), menu_selection_mark(), buffer.c, type_char);
|
2019-06-20 14:40:53 +00:00
|
|
|
}
|
|
|
|
|
2019-05-14 16:32:40 +00:00
|
|
|
static void menu_draw_item_puts_P(char type_char, const char* str, char num)
|
2019-05-14 13:47:25 +00:00
|
|
|
{
|
|
|
|
lcd_set_cursor(0, menu_row);
|
2019-07-04 11:36:02 +00:00
|
|
|
lcd_printf_P(PSTR("%c%-.16S "), menu_selection_mark(), str);
|
2019-05-14 13:47:25 +00:00
|
|
|
lcd_putc(num);
|
|
|
|
lcd_set_cursor(19, menu_row);
|
|
|
|
lcd_putc(type_char);
|
2018-07-16 00:13:52 +00:00
|
|
|
}
|
2018-08-09 15:43:43 +00:00
|
|
|
|
2018-07-16 00:13:52 +00:00
|
|
|
/*
|
|
|
|
int menu_draw_item_puts_P_int16(char type_char, const char* str, int16_t val, )
|
|
|
|
{
|
|
|
|
lcd_set_cursor(0, menu_row);
|
|
|
|
int cnt = lcd_printf_P(PSTR("%c%-18S%c"), (lcd_encoder == menu_item)?'>':' ', str, type_char);
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
*/
|
2018-08-09 15:43:43 +00:00
|
|
|
|
2018-07-16 00:13:52 +00:00
|
|
|
void menu_item_dummy(void)
|
|
|
|
{
|
|
|
|
menu_item++;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t menu_item_text_P(const char* str)
|
|
|
|
{
|
|
|
|
if (menu_item == menu_line)
|
|
|
|
{
|
|
|
|
if (lcd_draw_update) menu_draw_item_puts_P(' ', str);
|
|
|
|
if (menu_clicked && (lcd_encoder == menu_item))
|
|
|
|
return menu_item_ret();
|
|
|
|
}
|
|
|
|
menu_item++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t menu_item_submenu_P(const char* str, menu_func_t submenu)
|
|
|
|
{
|
|
|
|
if (menu_item == menu_line)
|
|
|
|
{
|
|
|
|
if (lcd_draw_update) menu_draw_item_puts_P(LCD_STR_ARROW_RIGHT[0], str);
|
|
|
|
if (menu_clicked && (lcd_encoder == menu_item))
|
|
|
|
{
|
|
|
|
menu_submenu(submenu);
|
|
|
|
return menu_item_ret();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
menu_item++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-06-26 13:51:58 +00:00
|
|
|
uint8_t menu_item_submenu_E(const Sheet &sheet, menu_func_t submenu)
|
2019-06-20 14:40:53 +00:00
|
|
|
{
|
|
|
|
if (menu_item == menu_line)
|
|
|
|
{
|
2019-06-26 13:51:58 +00:00
|
|
|
if (lcd_draw_update) menu_draw_item_puts_E(LCD_STR_ARROW_RIGHT[0], sheet);
|
2019-06-20 14:40:53 +00:00
|
|
|
if (menu_clicked && (lcd_encoder == menu_item))
|
|
|
|
{
|
|
|
|
menu_submenu(submenu);
|
|
|
|
return menu_item_ret();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
menu_item++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-08-29 18:13:10 +00:00
|
|
|
uint8_t menu_item_function_E(const Sheet &sheet, menu_func_t func)
|
2019-07-19 16:34:46 +00:00
|
|
|
{
|
|
|
|
if (menu_item == menu_line)
|
|
|
|
{
|
2019-08-29 18:13:10 +00:00
|
|
|
if (lcd_draw_update) menu_draw_item_select_sheet_E(' ', sheet);
|
2019-07-19 16:34:46 +00:00
|
|
|
if (menu_clicked && (lcd_encoder == menu_item))
|
|
|
|
{
|
2019-08-29 18:13:10 +00:00
|
|
|
menu_clicked = false;
|
|
|
|
lcd_consume_click();
|
|
|
|
lcd_update_enabled = 0;
|
|
|
|
if (func) func();
|
|
|
|
lcd_update_enabled = 1;
|
2019-07-19 16:34:46 +00:00
|
|
|
return menu_item_ret();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
menu_item++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-07-16 00:13:52 +00:00
|
|
|
uint8_t menu_item_back_P(const char* str)
|
|
|
|
{
|
|
|
|
if (menu_item == menu_line)
|
|
|
|
{
|
|
|
|
if (lcd_draw_update) menu_draw_item_puts_P(LCD_STR_UPLEVEL[0], str);
|
|
|
|
if (menu_clicked && (lcd_encoder == menu_item))
|
|
|
|
{
|
|
|
|
menu_back();
|
|
|
|
return menu_item_ret();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
menu_item++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t menu_item_function_P(const char* str, menu_func_t func)
|
|
|
|
{
|
|
|
|
if (menu_item == menu_line)
|
|
|
|
{
|
|
|
|
if (lcd_draw_update) menu_draw_item_puts_P(' ', str);
|
|
|
|
if (menu_clicked && (lcd_encoder == menu_item))
|
|
|
|
{
|
|
|
|
menu_clicked = false;
|
2018-09-18 15:15:13 +00:00
|
|
|
lcd_consume_click();
|
2018-07-16 02:24:27 +00:00
|
|
|
lcd_update_enabled = 0;
|
2018-07-16 00:13:52 +00:00
|
|
|
if (func) func();
|
2018-07-16 02:24:27 +00:00
|
|
|
lcd_update_enabled = 1;
|
2018-07-16 00:13:52 +00:00
|
|
|
return menu_item_ret();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
menu_item++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-05-14 13:47:25 +00:00
|
|
|
//! @brief Menu item function taking single parameter
|
|
|
|
//!
|
|
|
|
//! Ideal for numbered lists calling functions with number parameter.
|
|
|
|
//! @param str Item caption
|
|
|
|
//! @param number aditional character to be added after str, e.g. number
|
|
|
|
//! @param func pointer to function taking uint8_t with no return value
|
|
|
|
//! @param fn_par value to be passed to function
|
|
|
|
//! @retval 0
|
|
|
|
//! @retval 1 Item was clicked
|
|
|
|
uint8_t menu_item_function_P(const char* str, char number, void (*func)(uint8_t), uint8_t fn_par)
|
|
|
|
{
|
|
|
|
if (menu_item == menu_line)
|
|
|
|
{
|
|
|
|
if (lcd_draw_update) menu_draw_item_puts_P(' ', str, number);
|
|
|
|
if (menu_clicked && (lcd_encoder == menu_item))
|
|
|
|
{
|
|
|
|
menu_clicked = false;
|
|
|
|
lcd_consume_click();
|
|
|
|
lcd_update_enabled = 0;
|
|
|
|
if (func) func(fn_par);
|
|
|
|
lcd_update_enabled = 1;
|
|
|
|
return menu_item_ret();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
menu_item++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-07-16 00:13:52 +00:00
|
|
|
uint8_t menu_item_gcode_P(const char* str, const char* str_gcode)
|
|
|
|
{
|
|
|
|
if (menu_item == menu_line)
|
|
|
|
{
|
|
|
|
if (lcd_draw_update) menu_draw_item_puts_P(' ', str);
|
|
|
|
if (menu_clicked && (lcd_encoder == menu_item))
|
|
|
|
{
|
|
|
|
if (str_gcode) enquecommand_P(str_gcode);
|
|
|
|
return menu_item_ret();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
menu_item++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-07-30 17:24:04 +00:00
|
|
|
|
2018-07-19 13:21:46 +00:00
|
|
|
const char menu_20x_space[] PROGMEM = " ";
|
2018-07-19 14:57:31 +00:00
|
|
|
|
2018-07-19 13:21:46 +00:00
|
|
|
const char menu_fmt_int3[] PROGMEM = "%c%.15S:%s%3d";
|
2018-07-19 14:57:31 +00:00
|
|
|
|
2019-05-16 14:43:44 +00:00
|
|
|
const char menu_fmt_float31[] PROGMEM = "%-12.12S%+8.1f";
|
2018-07-19 14:57:31 +00:00
|
|
|
|
2019-05-23 08:45:55 +00:00
|
|
|
const char menu_fmt_float13[] PROGMEM = "%c%-13.13S%+5.3f";
|
2018-07-30 17:24:04 +00:00
|
|
|
|
2019-05-23 08:45:55 +00:00
|
|
|
const char menu_fmt_float13off[] PROGMEM = "%c%-13.13S%6.6s";
|
2018-08-24 18:06:09 +00:00
|
|
|
|
2018-08-24 15:33:43 +00:00
|
|
|
template<typename T>
|
2018-08-24 16:00:05 +00:00
|
|
|
static void menu_draw_P(char chr, const char* str, int16_t val);
|
2018-07-30 17:24:04 +00:00
|
|
|
|
2018-08-24 15:33:43 +00:00
|
|
|
template<>
|
|
|
|
void menu_draw_P<int16_t*>(char chr, const char* str, int16_t val)
|
2018-07-19 13:21:46 +00:00
|
|
|
{
|
|
|
|
int text_len = strlen_P(str);
|
|
|
|
if (text_len > 15) text_len = 15;
|
|
|
|
char spaces[21];
|
|
|
|
strcpy_P(spaces, menu_20x_space);
|
2019-02-05 15:49:29 +00:00
|
|
|
if (val <= -100) spaces[15 - text_len - 1] = 0;
|
|
|
|
else spaces[15 - text_len] = 0;
|
2018-07-19 13:21:46 +00:00
|
|
|
lcd_printf_P(menu_fmt_int3, chr, str, spaces, val);
|
|
|
|
}
|
|
|
|
|
2018-08-24 20:04:48 +00:00
|
|
|
template<>
|
|
|
|
void menu_draw_P<uint8_t*>(char chr, const char* str, int16_t val)
|
|
|
|
{
|
|
|
|
menu_data_edit_t* _md = (menu_data_edit_t*)&(menu_data[0]);
|
2019-05-23 08:45:55 +00:00
|
|
|
float factor = 1.0f + static_cast<float>(val) / 1000.0f;
|
2018-08-24 20:04:48 +00:00
|
|
|
if (val <= _md->minEditValue)
|
|
|
|
{
|
2019-05-23 08:45:55 +00:00
|
|
|
lcd_printf_P(menu_fmt_float13off, chr, str, " [off]");
|
2018-08-24 20:04:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-23 08:45:55 +00:00
|
|
|
lcd_printf_P(menu_fmt_float13, chr, str, factor);
|
2018-08-24 20:04:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-16 14:43:44 +00:00
|
|
|
//! @brief Draw up to 10 chars of text and a float number in format from +0.0 to +12345.0. The increased range is necessary
|
2019-05-09 11:44:35 +00:00
|
|
|
//! for displaying large values of extruder positions, which caused text overflow in the previous implementation.
|
2019-05-16 14:43:44 +00:00
|
|
|
//!
|
|
|
|
//! @param str string label to print
|
2019-05-09 11:44:35 +00:00
|
|
|
//! @param val value to print aligned to the right side of the display
|
|
|
|
//!
|
|
|
|
//! Implementation comments:
|
2019-05-16 14:43:44 +00:00
|
|
|
//! The text needs to come with a colon ":", this function does not append it anymore.
|
|
|
|
//! That resulted in a much shorter implementation (234628B -> 234476B)
|
|
|
|
//! There are similar functions around which may be shortened in a similar way
|
|
|
|
void menu_draw_float31(const char* str, float val)
|
2018-07-19 14:57:31 +00:00
|
|
|
{
|
2019-05-16 14:43:44 +00:00
|
|
|
lcd_printf_P(menu_fmt_float31, str, val);
|
2018-07-19 14:57:31 +00:00
|
|
|
}
|
2018-07-16 00:13:52 +00:00
|
|
|
|
2019-05-23 08:45:55 +00:00
|
|
|
//! @brief Draw up to 14 chars of text and a float number in format +1.234
|
2019-05-16 14:43:44 +00:00
|
|
|
//!
|
|
|
|
//! @param str string label to print
|
|
|
|
//! @param val value to print aligned to the right side of the display
|
|
|
|
//!
|
|
|
|
//! Implementation comments:
|
|
|
|
//! This function uses similar optimization principles as menu_draw_float31
|
|
|
|
//! (i.e. str must include a ':' at its end)
|
|
|
|
//! FLASH usage dropped 234476B -> 234392B
|
|
|
|
//! Moreover, this function gets inlined in the final code, so removing it doesn't really help ;)
|
|
|
|
void menu_draw_float13(const char* str, float val)
|
2018-07-30 17:24:04 +00:00
|
|
|
{
|
2019-05-23 08:45:55 +00:00
|
|
|
lcd_printf_P(menu_fmt_float13, ' ', str, val);
|
2018-07-30 17:24:04 +00:00
|
|
|
}
|
|
|
|
|
2018-08-24 15:33:43 +00:00
|
|
|
template <typename T>
|
2018-08-24 16:00:05 +00:00
|
|
|
static void _menu_edit_P(void)
|
2018-07-16 00:13:52 +00:00
|
|
|
{
|
2018-08-10 00:59:49 +00:00
|
|
|
menu_data_edit_t* _md = (menu_data_edit_t*)&(menu_data[0]);
|
2018-07-16 00:13:52 +00:00
|
|
|
if (lcd_draw_update)
|
|
|
|
{
|
2018-08-10 00:59:49 +00:00
|
|
|
if (lcd_encoder < _md->minEditValue) lcd_encoder = _md->minEditValue;
|
|
|
|
if (lcd_encoder > _md->maxEditValue) lcd_encoder = _md->maxEditValue;
|
2018-07-16 00:13:52 +00:00
|
|
|
lcd_set_cursor(0, 1);
|
2018-08-24 15:33:43 +00:00
|
|
|
menu_draw_P<T>(' ', _md->editLabel, (int)lcd_encoder);
|
2018-07-16 00:13:52 +00:00
|
|
|
}
|
|
|
|
if (LCD_CLICKED)
|
|
|
|
{
|
2018-08-24 19:24:14 +00:00
|
|
|
*((T)(_md->editValue)) = lcd_encoder;
|
2018-08-19 11:59:33 +00:00
|
|
|
menu_back_no_reset();
|
2018-07-16 00:13:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-24 15:33:43 +00:00
|
|
|
template <typename T>
|
|
|
|
uint8_t menu_item_edit_P(const char* str, T pval, int16_t min_val, int16_t max_val)
|
2018-07-16 00:13:52 +00:00
|
|
|
{
|
2018-08-10 00:59:49 +00:00
|
|
|
menu_data_edit_t* _md = (menu_data_edit_t*)&(menu_data[0]);
|
2018-07-16 00:13:52 +00:00
|
|
|
if (menu_item == menu_line)
|
|
|
|
{
|
|
|
|
if (lcd_draw_update)
|
|
|
|
{
|
|
|
|
lcd_set_cursor(0, menu_row);
|
2019-07-04 11:36:02 +00:00
|
|
|
menu_draw_P<T>(menu_selection_mark(), str, *pval);
|
2018-07-16 00:13:52 +00:00
|
|
|
}
|
|
|
|
if (menu_clicked && (lcd_encoder == menu_item))
|
|
|
|
{
|
2018-08-24 15:33:43 +00:00
|
|
|
menu_submenu_no_reset(_menu_edit_P<T>);
|
2018-08-10 00:59:49 +00:00
|
|
|
_md->editLabel = str;
|
|
|
|
_md->editValue = pval;
|
|
|
|
_md->minEditValue = min_val;
|
|
|
|
_md->maxEditValue = max_val;
|
2018-07-16 00:13:52 +00:00
|
|
|
lcd_encoder = *pval;
|
|
|
|
return menu_item_ret();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
menu_item++;
|
|
|
|
return 0;
|
|
|
|
}
|
2018-07-19 14:57:31 +00:00
|
|
|
|
2018-08-24 15:33:43 +00:00
|
|
|
template uint8_t menu_item_edit_P<int16_t*>(const char* str, int16_t *pval, int16_t min_val, int16_t max_val);
|
2018-08-24 18:06:09 +00:00
|
|
|
template uint8_t menu_item_edit_P<uint8_t*>(const char* str, uint8_t *pval, int16_t min_val, int16_t max_val);
|
2018-08-24 15:33:43 +00:00
|
|
|
|
2018-07-16 00:13:52 +00:00
|
|
|
#undef _menu_data
|