Kaynağa Gözat

Fixes after merge and line buffer

General fixes to the lcd_edit_off item and improved way to generate the toggles.
The old process is this: Write '>' if required -> print base -> pad everything before the last character with spaces -> write the eol character -> jump back and print the toggle over the blank characters. This resulted in noticeable flickering when the toggle was redrawn and was showing the same thing. Now the process is similar, except that everything happens in a "line buffer" (a char buffer that holds an entire line) and gets printed in one go, avoiding jump instructions for the lcd and prevents flickering since it doesn't write ' ' and the letters afterwards.
This should get even better when the lcd_buffer gets implemented since the line_buffer will get compared to the existing data on the screen and avoid overwriting what is on the lcd with the same thing.
leptun 4 yıl önce
ebeveyn
işleme
e828798209
2 değiştirilmiş dosya ile 22 ekleme ve 19 silme
  1. 19 16
      Firmware/menu.cpp
  2. 3 3
      Firmware/menu.h

+ 19 - 16
Firmware/menu.cpp

@@ -184,11 +184,20 @@ static void menu_draw_item_puts_P(char type_char, const char* str)
     lcd_printf_P(PSTR("%c%-18.18S%c"), menu_selection_mark(), str, type_char);
 }
 
-static void menu_draw_toggle_puts_P(const char* str, const char* toggle, const bool fromProgmem)
-{
-	menu_draw_item_puts_P((toggle == NULL)?LCD_STR_ARROW_RIGHT[0]:LCD_STR_REFRESH[0], str);
-	lcd_set_cursor(LCD_WIDTH - 3 - (fromProgmem?(strlen_P((toggle == NULL)?_T(MSG_NA):toggle)):(strlen(toggle))), menu_row);
-	lcd_printf_P(fromProgmem?PSTR("[%S]"):PSTR("[%s]"), (toggle == NULL)?_T(MSG_NA):toggle);
+static void menu_draw_toggle_puts_P(const char* str, char* toggle, const uint8_t settings)
+{
+    //settings:
+    //xxxxxcba
+    //a = selection mark. If it's set(1), then '>' will be used as the first character on the line. Else leave blank
+    //b = toggle string is from progmem
+    //c = do not set cursor at all. Must be handled externally.
+    char lineStr[LCD_WIDTH + 1];
+    const char eol = (toggle == NULL)?LCD_STR_ARROW_RIGHT[0]:' ';
+    if (toggle == NULL) toggle = _T(MSG_NA);
+    sprintf_P(lineStr, PSTR("%c%-18.18S"), (settings & 0x01)?'>':' ', str);
+    sprintf_P(lineStr + LCD_WIDTH - ((settings & 0x02)?strlen_P(toggle):strlen(toggle)) - 3, (settings & 0x02)?PSTR("[%S]%c"):PSTR("[%s]%c"), toggle, eol);
+    if (!(settings & 0x04)) lcd_set_cursor(0, menu_row);
+    fputs(lineStr, lcdout);
 }
 
 //! @brief Format sheet name
@@ -382,11 +391,11 @@ uint8_t menu_item_function_P(const char* str, char number, void (*func)(uint8_t)
     return 0;
 }
 
-uint8_t menu_item_toggle_P(const char* str, const char* toggle, menu_func_t func, const bool fromProgmem)
+uint8_t menu_item_toggle_P(const char* str, const char* toggle, menu_func_t func, const uint8_t settings)
 {
 	if (menu_item == menu_line)
 	{
-		if (lcd_draw_update) menu_draw_toggle_puts_P(str, toggle, fromProgmem);
+		if (lcd_draw_update) menu_draw_toggle_puts_P(str, toggle, settings | (menu_selection_mark()=='>'));
 		if (menu_clicked && (lcd_encoder == menu_item))
 		{
 			if (toggle == NULL) // print N/A warning message
@@ -424,17 +433,12 @@ uint8_t menu_item_gcode_P(const char* str, const char* str_gcode)
 	return 0;
 }
 
-
-const char menu_20x_space[] PROGMEM = "                    ";
-
 const char menu_fmt_int3[] PROGMEM = "%c%.15S:%s%3d";
 
 const char menu_fmt_float31[] PROGMEM = "%-12.12S%+8.1f";
 
 const char menu_fmt_float13[] PROGMEM = "%c%-13.13S%+5.3f";
 
-const char menu_fmt_float13off[] PROGMEM = "%c%-13.13S%6.6s";
-
 template<typename T>
 static void menu_draw_P(char chr, const char* str, int16_t val);
 
@@ -443,8 +447,8 @@ void menu_draw_P<int16_t*>(char chr, const char* str, int16_t val)
 {
 	int text_len = strlen_P(str);
 	if (text_len > 15) text_len = 15;
-	char spaces[21];
-	strcpy_P(spaces, menu_20x_space);
+	char spaces[LCD_WIDTH + 1] = {0};
+    memset(spaces,' ', LCD_WIDTH);
 	if (val <= -100) spaces[15 - text_len - 1] = 0;
 	else spaces[15 - text_len] = 0;
 	lcd_printf_P(menu_fmt_int3, chr, str, spaces, val);
@@ -457,8 +461,7 @@ void menu_draw_P<uint8_t*>(char chr, const char* str, int16_t val)
     float factor = 1.0f + static_cast<float>(val) / 1000.0f;
     if (val <= _md->minEditValue)
     {
-        // lcd_printf_P(menu_fmt_float13off, chr, str, " [off]");
-        menu_draw_toggle_puts_P(str, _T(MSG_OFF), true);
+        menu_draw_toggle_puts_P(str, _T(MSG_OFF), 0x04 | 0x02 | (chr=='>'));
     }
     else
     {

+ 3 - 3
Firmware/menu.h

@@ -118,9 +118,9 @@ extern uint8_t menu_item_function_P(const char* str, menu_func_t func);
 #define MENU_ITEM_FUNCTION_NR_P(str, number, func, fn_par) do { if (menu_item_function_P(str, number, func, fn_par)) return; } while (0)
 extern uint8_t menu_item_function_P(const char* str, char number, void (*func)(uint8_t), uint8_t fn_par);
 
-#define MENU_ITEM_TOGGLE_P(str, toggle, func) do { if (menu_item_toggle_P(str, toggle, func, true)) return; } while (0)
-#define MENU_ITEM_TOGGLE(str, toggle, func) do { if (menu_item_toggle_P(str, toggle, func, false)) return; } while (0)
-extern uint8_t menu_item_toggle_P(const char* str, const char* toggle, menu_func_t func, const bool fromProgmem);
+#define MENU_ITEM_TOGGLE_P(str, toggle, func) do { if (menu_item_toggle_P(str, toggle, func, 0x02)) return; } while (0)
+#define MENU_ITEM_TOGGLE(str, toggle, func) do { if (menu_item_toggle_P(str, toggle, func, 0x00)) return; } while (0)
+extern uint8_t menu_item_toggle_P(const char* str, const char* toggle, menu_func_t func, const uint8_t settings);
 
 #define MENU_ITEM_GCODE_P(str, str_gcode) do { if (menu_item_gcode_P(str, str_gcode)) return; } while (0)
 extern uint8_t menu_item_gcode_P(const char* str, const char* str_gcode);