Browse Source

📺 Fix and optimize FTDI Eve Touch Interface (#22427)

Marcio T 4 years ago
parent
commit
b925130db1
No account linked to committer's email address

+ 22
- 4
Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/basic/commands.cpp View File

@@ -902,6 +902,7 @@ bool CLCD::CommandFifo::has_fault() {
902 902
 }
903 903
 
904 904
 #if FTDI_API_LEVEL == 800
905
+
905 906
 void CLCD::CommandFifo::start() {
906 907
   if (command_write_ptr == 0xFFFFFFFFul) {
907 908
     command_write_ptr = mem_read_32(REG::CMD_WRITE) & 0x0FFF;
@@ -979,12 +980,13 @@ template <class T> bool CLCD::CommandFifo::_write_unaligned(T data, uint16_t len
979 980
 
980 981
 template <class T> bool CLCD::CommandFifo::write(T data, uint16_t len) {
981 982
   const uint8_t padding = MULTIPLE_OF_4(len) - len;
982
-
983
-  uint8_t pad_bytes[] = {0, 0, 0, 0};
983
+  const uint8_t pad_bytes[] = { 0, 0, 0, 0 };
984 984
   return _write_unaligned(data,      len) &&
985 985
          _write_unaligned(pad_bytes, padding);
986 986
 }
987
-#else
987
+
988
+#else // FTDI_API_LEVEL != 800 ...
989
+
988 990
 void CLCD::CommandFifo::start() {
989 991
 }
990 992
 
@@ -1042,13 +1044,29 @@ template <class T> bool CLCD::CommandFifo::write(T data, uint16_t len) {
1042 1044
   mem_write_bulk(REG::CMDB_WRITE, data, len, padding);
1043 1045
   return true;
1044 1046
 }
1045
-#endif
1047
+
1048
+#endif // ... FTDI_API_LEVEL != 800
1046 1049
 
1047 1050
 template bool CLCD::CommandFifo::write(const void*, uint16_t);
1048 1051
 template bool CLCD::CommandFifo::write(progmem_str, uint16_t);
1049 1052
 
1050 1053
 // CO_PROCESSOR COMMANDS
1051 1054
 
1055
+void CLCD::CommandFifo::str(const char * data, size_t maxlen) {
1056
+  // Write the string without the terminating '\0'
1057
+  const size_t len = strnlen(data, maxlen);
1058
+  write(data, len);
1059
+
1060
+  // If padding was added by the previous write, then
1061
+  // the string is terminated. Otherwise write four
1062
+  // more zeros.
1063
+  const uint8_t padding = MULTIPLE_OF_4(len) - len;
1064
+  if (padding == 0) {
1065
+    const uint8_t pad_bytes[] = {0, 0, 0, 0};
1066
+    write(pad_bytes, 4);
1067
+  }
1068
+}
1069
+
1052 1070
 void CLCD::CommandFifo::str(const char * data) {
1053 1071
   write(data, strlen(data)+1);
1054 1072
 }

+ 1
- 0
Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/basic/commands.h View File

@@ -248,6 +248,7 @@ class CLCD::CommandFifo {
248 248
     void keys      (int16_t x, int16_t y, int16_t w, int16_t h, int16_t font, uint16_t options);
249 249
 
250 250
     // Sends the string portion of text, button, toggle and keys.
251
+    void str (const char * data, size_t maxlen);
251 252
     void str (const char * data);
252 253
     void str (progmem_str data);
253 254
 

+ 24
- 26
Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/text_box.cpp View File

@@ -29,31 +29,31 @@ namespace FTDI {
29 29
    * be broken so that the display width is less than w. The line will also
30 30
    * be broken after a '\n'. Returns the display width of the line.
31 31
    */
32
-  static uint16_t find_line_break(const FontMetrics &utf8_fm, const CLCD::FontMetrics &clcd_fm, const uint16_t w, const char *str, const char *&end, bool use_utf8) {
33
-    const char *p = str;
34
-    end = str;
32
+  static uint16_t find_line_break(const FontMetrics &utf8_fm, const CLCD::FontMetrics &clcd_fm, const uint16_t w, const char *start, const char *&end, bool use_utf8) {
33
+    const char *p = start;
34
+    end = start;
35 35
     uint16_t lw = 0, result = 0;
36 36
     for (;;) {
37 37
       const char *next = p;
38
-      utf8_char_t c = get_utf8_char_and_inc(next);
38
+      const utf8_char_t c = get_utf8_char_and_inc(next);
39 39
       // Decide whether to break the string at this location
40 40
       if (c == '\n' || c == '\0' || c == ' ') {
41 41
         end = p;
42 42
         result = lw;
43 43
       }
44 44
       if (c == '\n' || c == '\0') break;
45
-      // Now add the length of the current character to the tally.
46
-      lw += use_utf8 ? utf8_fm.get_char_width(c) : clcd_fm.char_widths[(uint8_t)c];
45
+      // Measure the next character
46
+      const uint16_t cw = use_utf8 ? utf8_fm.get_char_width(c) : clcd_fm.char_widths[(uint8_t)c];
47 47
       // Stop processing once string exceeds the display width
48
-      if (lw >= w) {
49
-        if (end == str) {
50
-          end = p;
51
-          result = lw;
52
-        }
53
-        break;
54
-      }
48
+      if (lw + cw > w) break;
49
+      // Now add the length of the current character to the tally.
50
+      lw += cw;
55 51
       p = next;
56 52
     }
53
+    if (end == start) {
54
+      end = p;
55
+      result = lw;
56
+    }
57 57
     return result;
58 58
   }
59 59
 
@@ -66,12 +66,13 @@ namespace FTDI {
66 66
     const uint16_t wrap_width = width;
67 67
     width = height = 0;
68 68
     for (;;) {
69
-      uint16_t line_width = find_line_break(utf8_fm, clcd_fm, wrap_width, line_start, line_end, use_utf8);
69
+      const uint16_t line_width = find_line_break(utf8_fm, clcd_fm, wrap_width, line_start, line_end, use_utf8);
70
+      if (line_end == line_start) break;
70 71
       width  = max(width, line_width);
71 72
       height += utf8_fm.get_height();
72 73
       line_start = line_end;
73
-      if (line_start[0] == '\n' || line_start[0] == ' ') line_start++;
74
-      if (line_start[0] == '\0') break;
74
+      if (*line_start == '\n' || *line_start == ' ') line_start++;
75
+      if (*line_start == '\0') break;
75 76
     }
76 77
   }
77 78
 
@@ -108,28 +109,25 @@ namespace FTDI {
108 109
     const char *line_start = str, *line_end;
109 110
     for (;;) {
110 111
       find_line_break(utf8_fm, clcd_fm, w, line_start, line_end, use_utf8);
112
+      if (line_end == line_start) break;
111 113
 
112 114
       const size_t line_len = line_end - line_start;
113 115
       if (line_len) {
114
-        char line[line_len + 1];
115
-        strncpy(line, line_start, line_len);
116
-        line[line_len] = 0;
117
-
118 116
         #if ENABLED(TOUCH_UI_USE_UTF8)
119
-          if (use_utf8) {
120
-            draw_utf8_text(cmd, x + dx, y + dy, line, utf8_fm.fs, options & ~(OPT_CENTERY | OPT_BOTTOMY));
121
-          } else
117
+          if (use_utf8)
118
+            draw_utf8_text(cmd, x + dx, y + dy, line_start, utf8_fm.fs, options & ~(OPT_CENTERY | OPT_BOTTOMY), line_len);
119
+          else
122 120
         #endif
123 121
           {
124 122
             cmd.CLCD::CommandFifo::text(x + dx, y + dy, font, options & ~(OPT_CENTERY | OPT_BOTTOMY));
125
-            cmd.CLCD::CommandFifo::str(line);
123
+            cmd.CLCD::CommandFifo::str(line_start, line_len);
126 124
           }
127 125
       }
128 126
       y += utf8_fm.get_height();
129 127
 
130 128
       line_start = line_end;
131
-      if (line_start[0] == '\n' || line_start[0] == ' ') line_start++;
132
-      if (line_start[0] == '\0') break;
129
+      if (*line_start == '\n' || *line_start == ' ') line_start++;
130
+      if (*line_start == '\0') break;
133 131
     }
134 132
   }
135 133
 

+ 9
- 8
Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/unicode/unicode.cpp View File

@@ -95,9 +95,9 @@
95 95
    *   fs   - A scaling object used to specify the font size.
96 96
    */
97 97
 
98
-  static uint16_t render_utf8_text(CommandProcessor* cmd, int x, int y, const char *str, font_size_t fs) {
98
+  static uint16_t render_utf8_text(CommandProcessor* cmd, int x, int y, const char *str, font_size_t fs, size_t maxlen=SIZE_MAX) {
99 99
     const int start_x = x;
100
-    while (*str) {
100
+    while (*str && maxlen--) {
101 101
       const utf8_char_t c = get_utf8_char_and_inc(str);
102 102
       #ifdef TOUCH_UI_UTF8_CYRILLIC_CHARSET
103 103
         CyrillicCharSet::render_glyph(cmd, x, y, fs, c) ||
@@ -185,8 +185,8 @@
185 185
     * Returns: A width in pixels
186 186
     */
187 187
 
188
-  uint16_t FTDI::get_utf8_text_width(const char *str, font_size_t fs) {
189
-    return render_utf8_text(nullptr, 0, 0, str, fs);
188
+  uint16_t FTDI::get_utf8_text_width(const char *str, font_size_t fs, size_t maxlen) {
189
+    return render_utf8_text(nullptr, 0, 0, str, fs, maxlen);
190 190
   }
191 191
 
192 192
   uint16_t FTDI::get_utf8_text_width(progmem_str pstr, font_size_t fs) {
@@ -210,9 +210,10 @@
210 210
     *
211 211
     *   options - Text alignment options (i.e. OPT_CENTERX, OPT_CENTERY, OPT_CENTER or OPT_RIGHTX)
212 212
     *
213
+    *   maxlen - Maximum characters to draw
213 214
     */
214 215
 
215
-  void FTDI::draw_utf8_text(CommandProcessor& cmd, int x, int y, const char *str, font_size_t fs, uint16_t options) {
216
+  void FTDI::draw_utf8_text(CommandProcessor& cmd, int x, int y, const char *str, font_size_t fs, uint16_t options, size_t maxlen) {
216 217
     cmd.cmd(SAVE_CONTEXT());
217 218
     cmd.cmd(BITMAP_TRANSFORM_A(fs.get_coefficient()));
218 219
     cmd.cmd(BITMAP_TRANSFORM_E(fs.get_coefficient()));
@@ -220,14 +221,14 @@
220 221
 
221 222
     // Apply alignment options
222 223
     if (options & OPT_CENTERX)
223
-      x -= get_utf8_text_width(str, fs) / 2;
224
+      x -= get_utf8_text_width(str, fs, maxlen) / 2;
224 225
     else if (options & OPT_RIGHTX)
225
-      x -= get_utf8_text_width(str, fs);
226
+      x -= get_utf8_text_width(str, fs, maxlen);
226 227
     if (options & OPT_CENTERY)
227 228
       y -= fs.get_height()/2;
228 229
 
229 230
     // Render the text
230
-    render_utf8_text(&cmd, x, y, str, fs);
231
+    render_utf8_text(&cmd, x, y, str, fs, maxlen);
231 232
     cmd.cmd(RESTORE_CONTEXT());
232 233
   }
233 234
 

+ 2
- 2
Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/unicode/unicode.h View File

@@ -67,10 +67,10 @@ namespace FTDI {
67 67
 
68 68
   uint16_t get_utf8_char_width(utf8_char_t, font_size_t);
69 69
   uint16_t get_utf8_text_width(progmem_str, font_size_t);
70
-  uint16_t get_utf8_text_width(const char *, font_size_t);
70
+  uint16_t get_utf8_text_width(const char *, font_size_t, size_t maxlen=SIZE_MAX);
71 71
 
72 72
   void draw_utf8_text(CommandProcessor&, int x, int y, progmem_str, font_size_t, uint16_t options = 0);
73
-  void draw_utf8_text(CommandProcessor&, int x, int y, const char *, font_size_t, uint16_t options = 0);
73
+  void draw_utf8_text(CommandProcessor&, int x, int y, const char *, font_size_t, uint16_t options = 0, size_t maxlen=SIZE_MAX);
74 74
 
75 75
   // Similar to CLCD::FontMetrics, but can be used with UTF8 encoded strings.
76 76
 

+ 6
- 4
Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/about_screen.cpp View File

@@ -76,7 +76,9 @@ void AboutScreen::onRedraw(draw_mode_t) {
76 76
     #endif
77 77
     , OPT_CENTER, font_xlarge
78 78
   );
79
-  cmd.tag(3);
79
+  #if BOTH(TOUCH_UI_DEVELOPER_MENU, FTDI_DEVELOPER_MENU)
80
+    cmd.tag(3);
81
+  #endif
80 82
   draw_text_box(cmd, FW_VERS_POS,
81 83
   #ifdef TOUCH_UI_VERSION
82 84
     F(TOUCH_UI_VERSION)
@@ -89,7 +91,7 @@ void AboutScreen::onRedraw(draw_mode_t) {
89 91
   draw_text_box(cmd, LICENSE_POS, GET_TEXT_F(MSG_LICENSE), OPT_CENTER, font_tiny);
90 92
 
91 93
   cmd.font(font_medium);
92
-  #if ENABLED(PRINTCOUNTER) && defined(FTDI_STATISTICS_SCREEN)
94
+  #if BOTH(PRINTCOUNTER, FTDI_STATISTICS_SCREEN)
93 95
     cmd.colors(normal_btn)
94 96
        .tag(2).button(STATS_POS, GET_TEXT_F(MSG_INFO_STATS_MENU));
95 97
   #endif
@@ -100,10 +102,10 @@ void AboutScreen::onRedraw(draw_mode_t) {
100 102
 bool AboutScreen::onTouchEnd(uint8_t tag) {
101 103
   switch (tag) {
102 104
     case 1: GOTO_PREVIOUS(); break;
103
-    #if ENABLED(PRINTCOUNTER) && defined(FTDI_STATISTICS_SCREEN)
105
+    #if BOTH(PRINTCOUNTER, FTDI_STATISTICS_SCREEN)
104 106
       case 2: GOTO_SCREEN(StatisticsScreen); break;
105 107
     #endif
106
-    #if ENABLED(TOUCH_UI_DEVELOPER_MENU) && defined(FTDI_DEVELOPER_MENU)
108
+    #if BOTH(TOUCH_UI_DEVELOPER_MENU, FTDI_DEVELOPER_MENU)
107 109
       case 3: GOTO_SCREEN(DeveloperMenu); break;
108 110
     #endif
109 111
     default: return false;

+ 2
- 7
Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/confirm_user_request_alert_box.cpp View File

@@ -53,17 +53,12 @@ bool ConfirmUserRequestAlertBox::onTouchEnd(uint8_t tag) {
53 53
   }
54 54
 }
55 55
 
56
-void ConfirmUserRequestAlertBox::onIdle() {
57
-  if (!ExtUI::awaitingUserConfirm()) {
58
-    hide();
59
-  }
60
-}
61
-
62 56
 void ConfirmUserRequestAlertBox::show(const char *msg) {
63 57
   drawMessage(msg);
64 58
   storeBackground();
65 59
   screen_data.AlertDialogBox.isError = false;
66
-  GOTO_SCREEN(ConfirmUserRequestAlertBox);
60
+  if (!AT_SCREEN(ConfirmUserRequestAlertBox))
61
+    GOTO_SCREEN(ConfirmUserRequestAlertBox);
67 62
 }
68 63
 
69 64
 void ConfirmUserRequestAlertBox::hide() {

+ 0
- 1
Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/confirm_user_request_alert_box.h View File

@@ -31,5 +31,4 @@ class ConfirmUserRequestAlertBox : public AlertDialogBox {
31 31
     static bool onTouchEnd(uint8_t);
32 32
     static void hide();
33 33
     static void show(const char*);
34
-    static void onIdle();
35 34
 };

Loading…
Cancel
Save