Browse Source

MarlinUI multi-language support (#20725)

Scott Lahteine 3 years ago
parent
commit
68abaeab19
No account linked to committer's email address

+ 10
- 7
Marlin/Configuration_adv.h View File

@@ -1527,6 +1527,16 @@
1527 1527
 #endif // HAS_DGUS_LCD
1528 1528
 
1529 1529
 //
1530
+// Specify additional languages for the UI. Default specified by LCD_LANGUAGE.
1531
+//
1532
+#if EITHER(DOGLCD, TOUCH_UI_FTDI_EVE)
1533
+  //#define LCD_LANGUAGE_2 fr
1534
+  //#define LCD_LANGUAGE_3 de
1535
+  //#define LCD_LANGUAGE_4 es
1536
+  //#define LCD_LANGUAGE_5 it
1537
+#endif
1538
+
1539
+//
1530 1540
 // Touch UI for the FTDI Embedded Video Engine (EVE)
1531 1541
 //
1532 1542
 #if ENABLED(TOUCH_UI_FTDI_EVE)
@@ -1601,13 +1611,6 @@
1601 1611
   // Use a smaller font when labels don't fit buttons
1602 1612
   #define TOUCH_UI_FIT_TEXT
1603 1613
 
1604
-  // Allow language selection from menu at run-time (otherwise use LCD_LANGUAGE)
1605
-  //#define LCD_LANGUAGE_1 en
1606
-  //#define LCD_LANGUAGE_2 fr
1607
-  //#define LCD_LANGUAGE_3 de
1608
-  //#define LCD_LANGUAGE_4 es
1609
-  //#define LCD_LANGUAGE_5 it
1610
-
1611 1614
   // Use a numeric passcode for "Screen lock" keypad.
1612 1615
   // (recommended for smaller displays)
1613 1616
   //#define TOUCH_UI_PASSCODE

+ 16
- 13
Marlin/src/core/multi_language.h View File

@@ -20,6 +20,8 @@
20 20
  ****************************************************************************/
21 21
 #pragma once
22 22
 
23
+#include "../inc/MarlinConfigPre.h"
24
+
23 25
 typedef const char Language_Str[];
24 26
 
25 27
 #ifdef LCD_LANGUAGE_5
@@ -57,26 +59,27 @@ typedef const char Language_Str[];
57 59
 #define GET_LANG(LANG) _GET_LANG(LANG)
58 60
 
59 61
 #if NUM_LANGUAGES > 1
60
-  extern uint8_t lang;
62
+  #define HAS_MULTI_LANGUAGE 1
61 63
   #define GET_TEXT(MSG) ( \
62
-    lang == 0 ? GET_LANG(LCD_LANGUAGE)::MSG : \
63
-    lang == 1 ? GET_LANG(LCD_LANGUAGE_2)::MSG : \
64
-    lang == 2 ? GET_LANG(LCD_LANGUAGE_3)::MSG : \
65
-    lang == 3 ? GET_LANG(LCD_LANGUAGE_4)::MSG : \
66
-                GET_LANG(LCD_LANGUAGE_5)::MSG \
67
-    )
68
-  #define MAX_LANG_CHARSIZE _MAX(GET_LANG(LCD_LANGUAGE)::CHARSIZE, \
69
-                                GET_LANG(LCD_LANGUAGE_2)::CHARSIZE, \
70
-                                GET_LANG(LCD_LANGUAGE_3)::CHARSIZE, \
71
-                                GET_LANG(LCD_LANGUAGE_4)::CHARSIZE, \
72
-                                GET_LANG(LCD_LANGUAGE_5)::CHARSIZE)
64
+    ui.language == 0 ? GET_LANG(LCD_LANGUAGE  )::MSG : \
65
+    ui.language == 1 ? GET_LANG(LCD_LANGUAGE_2)::MSG : \
66
+    ui.language == 2 ? GET_LANG(LCD_LANGUAGE_3)::MSG : \
67
+    ui.language == 3 ? GET_LANG(LCD_LANGUAGE_4)::MSG : \
68
+                       GET_LANG(LCD_LANGUAGE_5)::MSG   )
69
+  #define MAX_LANG_CHARSIZE _MAX(GET_LANG(LCD_LANGUAGE  )::CHARSIZE, \
70
+                                 GET_LANG(LCD_LANGUAGE_2)::CHARSIZE, \
71
+                                 GET_LANG(LCD_LANGUAGE_3)::CHARSIZE, \
72
+                                 GET_LANG(LCD_LANGUAGE_4)::CHARSIZE, \
73
+                                 GET_LANG(LCD_LANGUAGE_5)::CHARSIZE  )
73 74
 #else
74 75
   #define GET_TEXT(MSG) GET_LANG(LCD_LANGUAGE)::MSG
75
-  #define MAX_LANG_CHARSIZE GET_LANG(LCD_LANGUAGE)::CHARSIZE
76
+  #define MAX_LANG_CHARSIZE LANG_CHARSIZE
76 77
 #endif
77 78
 #define GET_TEXT_F(MSG) (const __FlashStringHelper*)GET_TEXT(MSG)
78 79
 
79 80
 #define GET_LANGUAGE_NAME(INDEX) GET_LANG(LCD_LANGUAGE_##INDEX)::LANGUAGE
81
+#define LANG_CHARSIZE GET_TEXT(CHARSIZE)
82
+#define USE_WIDE_GLYPH (LANG_CHARSIZE > 2)
80 83
 
81 84
 #define MSG_1_LINE(A)     A "\0"   "\0"
82 85
 #define MSG_2_LINE(A,B)   A "\0" B "\0"

+ 4
- 0
Marlin/src/gcode/gcode.cpp View File

@@ -718,6 +718,10 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
718 718
         case 412: M412(); break;                                  // M412: Enable/Disable filament runout detection
719 719
       #endif
720 720
 
721
+      #if HAS_MULTI_LANGUAGE
722
+        case 414: M414(); break;                                  // M414: Select multi language menu
723
+      #endif
724
+
721 725
       #if HAS_LEVELING
722 726
         case 420: M420(); break;                                  // M420: Enable/Disable Bed Leveling
723 727
       #endif

+ 3
- 0
Marlin/src/gcode/gcode.h View File

@@ -213,6 +213,7 @@
213 213
  * M410 - Quickstop. Abort all planned moves.
214 214
  * M412 - Enable / Disable Filament Runout Detection. (Requires FILAMENT_RUNOUT_SENSOR)
215 215
  * M413 - Enable / Disable Power-Loss Recovery. (Requires POWER_LOSS_RECOVERY)
216
+ * M414 - Set language by index. (Requires LCD_LANGUAGE_2...)
216 217
  * M420 - Enable/Disable Leveling (with current values) S1=enable S0=disable (Requires MESH_BED_LEVELING or ABL)
217 218
  * M421 - Set a single Z coordinate in the Mesh Leveling grid. X<units> Y<units> Z<units> (Requires MESH_BED_LEVELING, AUTO_BED_LEVELING_BILINEAR, or AUTO_BED_LEVELING_UBL)
218 219
  * M422 - Set Z Stepper automatic alignment position using probe. X<units> Y<units> A<axis> (Requires Z_STEPPER_AUTO_ALIGN)
@@ -747,6 +748,8 @@ private:
747 748
 
748 749
   TERN_(HAS_FILAMENT_SENSOR, static void M412());
749 750
 
751
+  TERN_(HAS_MULTI_LANGUAGE, static void M414());
752
+
750 753
   #if HAS_LEVELING
751 754
     static void M420();
752 755
     static void M421();

+ 44
- 0
Marlin/src/gcode/lcd/M414.cpp View File

@@ -0,0 +1,44 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#include "../../inc/MarlinConfig.h"
24
+
25
+#if HAS_MULTI_LANGUAGE
26
+
27
+#include "../gcode.h"
28
+#include "../../MarlinCore.h"
29
+#include "../../lcd/marlinui.h"
30
+
31
+/**
32
+ * M414: Set the language for the UI
33
+ *
34
+ * Parameters
35
+ *  S<index> : The language to select
36
+ */
37
+void GcodeSuite::M414() {
38
+
39
+  if (parser.seenval('S'))
40
+    ui.set_language(parser.value_byte());
41
+
42
+}
43
+
44
+#endif // HAS_MULTI_LANGUAGE

+ 2
- 0
Marlin/src/inc/MarlinConfig.h View File

@@ -55,3 +55,5 @@
55 55
   #include "../core/serial.h"
56 56
 
57 57
 #endif
58
+
59
+#include "../core/multi_language.h"

+ 7
- 4
Marlin/src/lcd/dogm/marlinui_DOGM.cpp View File

@@ -54,6 +54,7 @@
54 54
 #include "../../sd/cardreader.h"
55 55
 #include "../../module/temperature.h"
56 56
 #include "../../module/printcounter.h"
57
+#include "../../MarlinCore.h"
57 58
 
58 59
 #if ENABLED(SDSUPPORT)
59 60
   #include "../../libs/duration_t.h"
@@ -455,20 +456,22 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
455 456
   inline void draw_boxed_string(const u8g_uint_t x, const u8g_uint_t y, PGM_P const pstr, const bool inv) {
456 457
     const u8g_uint_t len = utf8_strlen_P(pstr),
457 458
                       by = (y + 1) * (MENU_FONT_HEIGHT);
458
-    const pixel_len_t bw = len * (MENU_FONT_WIDTH), bx = x * (MENU_FONT_WIDTH);
459
+    const u8g_uint_t prop = USE_WIDE_GLYPH ? 2 : 1;
460
+    const pixel_len_t bw = len * prop * (MENU_FONT_WIDTH), bx = x * prop * (MENU_FONT_WIDTH);
459 461
     if (inv) {
460 462
       u8g.setColorIndex(1);
461
-      u8g.drawBox(bx - 1, by - (MENU_FONT_ASCENT) + 1, bw + 2, MENU_FONT_HEIGHT - 1);
463
+      u8g.drawBox(bx / prop - 1, by - (MENU_FONT_ASCENT) + 1, bw / prop + 2, MENU_FONT_HEIGHT - 1);
462 464
       u8g.setColorIndex(0);
463 465
     }
464
-    lcd_put_u8str_P(bx, by, pstr);
466
+    lcd_put_u8str_P(bx / prop, by, pstr);
465 467
     if (inv) u8g.setColorIndex(1);
466 468
   }
467 469
 
468 470
   void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const bool yesno, PGM_P const pref, const char * const string/*=nullptr*/, PGM_P const suff/*=nullptr*/) {
469 471
     ui.draw_select_screen_prompt(pref, string, suff);
470 472
     draw_boxed_string(1, LCD_HEIGHT - 1, no, !yesno);
471
-    draw_boxed_string(LCD_WIDTH - (utf8_strlen_P(yes) + 1), LCD_HEIGHT - 1, yes, yesno);
473
+    const u8g_uint_t xpos = (LCD_WIDTH) / (USE_WIDE_GLYPH ? 2 : 1);
474
+    draw_boxed_string(xpos - (utf8_strlen_P(yes) + 1), LCD_HEIGHT - 1, yes, yesno);
472 475
   }
473 476
 
474 477
   #if ENABLED(SDSUPPORT)

+ 0
- 1
Marlin/src/lcd/extui/lib/mks_ui/pic_manager.cpp View File

@@ -64,7 +64,6 @@ static const char assets[][LONG_FILENAME_LENGTH] = {
64 64
   "bmp_speed255.bin",
65 65
   "bmp_speed127.bin",
66 66
   "bmp_speed0.bin",
67
-  "bmp_speed0.bin",
68 67
 
69 68
   "bmp_bed.bin",
70 69
   "bmp_step1_degree.bin",

+ 1
- 0
Marlin/src/lcd/lcdprint.cpp View File

@@ -28,6 +28,7 @@
28 28
 
29 29
 #if HAS_WIRED_LCD && !HAS_GRAPHICAL_TFT
30 30
 
31
+#include "marlinui.h"
31 32
 #include "lcdprint.h"
32 33
 
33 34
 /**

+ 4
- 0
Marlin/src/lcd/marlinui.cpp View File

@@ -78,6 +78,10 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
78 78
   #endif
79 79
 #endif
80 80
 
81
+#if HAS_MULTI_LANGUAGE
82
+  uint8_t MarlinUI::language; // Initialized by settings.load()
83
+#endif
84
+
81 85
 #if ENABLED(SOUND_MENU_ITEM)
82 86
   bool MarlinUI::buzzer_enabled = true;
83 87
 #endif

+ 11
- 0
Marlin/src/lcd/marlinui.h View File

@@ -178,6 +178,17 @@ public:
178 178
     TERN_(HAS_LCD_MENU, currentScreen = status_screen);
179 179
   }
180 180
 
181
+  #if HAS_MULTI_LANGUAGE
182
+    static uint8_t language;
183
+    static inline void set_language(const uint8_t lang) {
184
+      if (lang < NUM_LANGUAGES) {
185
+        language = lang;
186
+        return_to_status();
187
+        refresh();
188
+      }
189
+    }
190
+  #endif
191
+
181 192
   #if ENABLED(SOUND_MENU_ITEM)
182 193
     static bool buzzer_enabled; // Initialized by settings.load()
183 194
   #else

+ 59
- 0
Marlin/src/lcd/menu/menu_language.cpp View File

@@ -0,0 +1,59 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+//
24
+// Language Selection Menu
25
+//
26
+
27
+#include "../../inc/MarlinConfig.h"
28
+
29
+#if HAS_MULTI_LANGUAGE
30
+
31
+#include "menu_item.h"
32
+#include "../../MarlinCore.h"
33
+#include "../../module/settings.h"
34
+
35
+static void set_lcd_language(const uint8_t inlang) {
36
+  ui.set_language(inlang);
37
+  (void)settings.save();
38
+}
39
+
40
+void menu_language() {
41
+  START_MENU();
42
+  BACK_ITEM(MSG_MAIN);
43
+
44
+  MENU_ITEM_P(function, GET_LANG(LCD_LANGUAGE  )::LANGUAGE, []{ set_lcd_language(0); });
45
+  MENU_ITEM_P(function, GET_LANG(LCD_LANGUAGE_2)::LANGUAGE, []{ set_lcd_language(1); });
46
+  #if NUM_LANGUAGES > 2
47
+    MENU_ITEM_P(function, GET_LANG(LCD_LANGUAGE_3)::LANGUAGE, []{ set_lcd_language(2); });
48
+    #if NUM_LANGUAGES > 3
49
+      MENU_ITEM_P(function, GET_LANG(LCD_LANGUAGE_4)::LANGUAGE, []{ set_lcd_language(3); });
50
+      #if NUM_LANGUAGES > 4
51
+        MENU_ITEM_P(function, GET_LANG(LCD_LANGUAGE_5)::LANGUAGE, []{ set_lcd_language(4); });
52
+      #endif
53
+    #endif
54
+  #endif
55
+
56
+  END_MENU();
57
+}
58
+
59
+#endif // HAS_MULTI_LANGUAGE

+ 8
- 0
Marlin/src/lcd/menu/menu_main.cpp View File

@@ -97,6 +97,10 @@ void menu_configuration();
97 97
   void menu_spindle_laser();
98 98
 #endif
99 99
 
100
+#if HAS_MULTI_LANGUAGE
101
+  void menu_language();
102
+#endif
103
+
100 104
 extern const char M21_STR[];
101 105
 
102 106
 void menu_main() {
@@ -325,6 +329,10 @@ void menu_main() {
325 329
     }
326 330
   #endif
327 331
 
332
+  #if HAS_MULTI_LANGUAGE
333
+    SUBMENU(LANGUAGE, menu_language);
334
+  #endif
335
+
328 336
   END_MENU();
329 337
 }
330 338
 

+ 30
- 1
Marlin/src/module/settings.cpp View File

@@ -36,7 +36,7 @@
36 36
  */
37 37
 
38 38
 // Change EEPROM version if the structure changes
39
-#define EEPROM_VERSION "V82"
39
+#define EEPROM_VERSION "V83"
40 40
 #define EEPROM_OFFSET 100
41 41
 
42 42
 // Check the integrity of data offsets.
@@ -457,6 +457,11 @@ typedef struct SettingsDataStruct {
457 457
   #if ENABLED(SOUND_MENU_ITEM)
458 458
     bool buzzer_enabled;
459 459
   #endif
460
+
461
+  #if HAS_MULTI_LANGUAGE
462
+    uint8_t ui_language;                                // M414 S
463
+  #endif
464
+
460 465
 } SettingsData;
461 466
 
462 467
 //static_assert(sizeof(SettingsData) <= MARLIN_EEPROM_SIZE, "EEPROM too small to contain SettingsData!");
@@ -1383,6 +1388,13 @@ void MarlinSettings::postprocess() {
1383 1388
     #endif
1384 1389
 
1385 1390
     //
1391
+    // Selected LCD language
1392
+    //
1393
+    #if HAS_MULTI_LANGUAGE
1394
+      EEPROM_WRITE(ui.language);
1395
+    #endif
1396
+
1397
+    //
1386 1398
     // Report final CRC and Data Size
1387 1399
     //
1388 1400
     if (!eeprom_error) {
@@ -2262,6 +2274,18 @@ void MarlinSettings::postprocess() {
2262 2274
       #endif
2263 2275
 
2264 2276
       //
2277
+      // Selected LCD language
2278
+      //
2279
+      #if HAS_MULTI_LANGUAGE
2280
+      {
2281
+        uint8_t ui_language;
2282
+        EEPROM_READ(ui_language);
2283
+        if (ui_language >= NUM_LANGUAGES) ui_language = 0;
2284
+        ui.set_language(ui_language);
2285
+      }
2286
+      #endif
2287
+
2288
+      //
2265 2289
       // Validate Final Size and CRC
2266 2290
       //
2267 2291
       eeprom_error = size_error(eeprom_index - (EEPROM_OFFSET));
@@ -3846,6 +3870,11 @@ void MarlinSettings::reset() {
3846 3870
       CONFIG_ECHO_START(); SERIAL_ECHO_SP(2); M553_report();
3847 3871
       CONFIG_ECHO_START(); SERIAL_ECHO_SP(2); M554_report();
3848 3872
     #endif
3873
+
3874
+    #if HAS_MULTI_LANGUAGE
3875
+      CONFIG_ECHO_HEADING("UI Language:");
3876
+      SERIAL_ECHO_MSG("  M414 S", int(ui.language));
3877
+    #endif
3849 3878
   }
3850 3879
 
3851 3880
 #endif // !DISABLE_M503

+ 1
- 0
buildroot/tests/FYSETC_F6-tests View File

@@ -39,6 +39,7 @@ exec_test $1 $2 "DELTA, RAMPS, L6470, UBL, Allen Key, EEPROM, OLED_PANEL_TINYBOY
39 39
 restore_configs
40 40
 opt_set MOTHERBOARD BOARD_FYSETC_F6_13
41 41
 opt_set LCD_LANGUAGE vi
42
+opt_set LCD_LANGUAGE_2 fr
42 43
 opt_set X_DRIVER_TYPE TMC2160
43 44
 opt_set Y_DRIVER_TYPE TMC5160
44 45
 opt_set Z_DRIVER_TYPE TMC2208_STANDALONE

+ 2
- 0
platformio.ini View File

@@ -39,6 +39,7 @@ default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared>
39 39
   -<src/lcd/menu/menu_filament.cpp>
40 40
   -<src/lcd/menu/menu_info.cpp>
41 41
   -<src/lcd/menu/menu_job_recovery.cpp>
42
+  -<src/lcd/menu/menu_language.cpp>
42 43
   -<src/lcd/menu/menu_led.cpp>
43 44
   -<src/lcd/menu/menu_media.cpp>
44 45
   -<src/lcd/menu/menu_mmu2.cpp>
@@ -264,6 +265,7 @@ HAS_MENU_DELTA_CALIBRATE = src_filter=+<src/lcd/menu/menu_delta_calibrate.cpp>
264 265
 HAS_MENU_FILAMENT       = src_filter=+<src/lcd/menu/menu_filament.cpp>
265 266
 LCD_INFO_MENU           = src_filter=+<src/lcd/menu/menu_info.cpp>
266 267
 HAS_MENU_JOB_RECOVERY   = src_filter=+<src/lcd/menu/menu_job_recovery.cpp>
268
+HAS_MULTI_LANGUAGE      = src_filter=+<src/lcd/menu/menu_language.cpp>
267 269
 HAS_MENU_LED            = src_filter=+<src/lcd/menu/menu_led.cpp>
268 270
 HAS_MENU_MEDIA          = src_filter=+<src/lcd/menu/menu_media.cpp>
269 271
 HAS_MENU_MIXER          = src_filter=+<src/lcd/menu/menu_mixer.cpp>

Loading…
Cancel
Save