Pārlūkot izejas kodu

Fix iss#1492

Introduced lcd_strlen() and lcd_strlen_P().
Replaced the old functions where necessary.
Reworked language_ru.h.

Speeded up test for zero length string in cardreader.cpp
AnHardt 9 gadus atpakaļ
vecāks
revīzija
6cdcd6c6d1

+ 8
- 4
Marlin/LiquidCrystalRus.cpp Parādīt failu

@@ -14,10 +14,14 @@
14 14
 // it is a Russian alphabet translation
15 15
 // except 0401 --> 0xa2 = ╗, 0451 --> 0xb5
16 16
 const PROGMEM uint8_t utf_recode[] = 
17
-       { 0x41,0xa0,0x42,0xa1,0xe0,0x45,0xa3,0xa4,0xa5,0xa6,0x4b,0xa7,0x4d,0x48,0x4f,
18
-         0xa8,0x50,0x43,0x54,0xa9,0xaa,0x58,0xe1,0xab,0xac,0xe2,0xad,0xae,0x62,0xaf,0xb0,0xb1,
19
-         0x61,0xb2,0xb3,0xb4,0xe3,0x65,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0x6f,
20
-         0xbe,0x70,0x63,0xbf,0x79,0xe4,0x78,0xe5,0xc0,0xc1,0xe6,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7
17
+       { 0x41,0xa0,0x42,0xa1,0xe0,0x45,0xa3,0xa4,
18
+         0xa5,0xa6,0x4b,0xa7,0x4d,0x48,0x4f,0xa8,
19
+         0x50,0x43,0x54,0xa9,0xaa,0x58,0xe1,0xab,
20
+         0xac,0xe2,0xad,0xae,0x62,0xaf,0xb0,0xb1,
21
+         0x61,0xb2,0xb3,0xb4,0xe3,0x65,0xb6,0xb7,
22
+         0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0x6f,0xbe,
23
+         0x70,0x63,0xbf,0x79,0xe4,0x78,0xe5,0xc0,
24
+         0xc1,0xe6,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7
21 25
         };     
22 26
 
23 27
 // When the display powers up, it is configured as follows:

+ 1
- 1
Marlin/cardreader.cpp Parādīt failu

@@ -65,7 +65,7 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
65 65
       createFilename(lfilename,p);
66 66
       
67 67
       path[0]=0;
68
-      if(strlen(prepend)==0) //avoid leading / if already in prepend
68
+      if(prepend[0]==0) //avoid leading / if already in prepend
69 69
       {
70 70
        strcat(path,"/");
71 71
       }

+ 5
- 5
Marlin/dogm_lcd_implementation.h Parādīt failu

@@ -315,7 +315,7 @@ static void lcd_implementation_drawmenu_generic(uint8_t row, const char* pstr, c
315 315
 
316 316
 static void _drawmenu_setting_edit_generic(uint8_t row, const char* pstr, char pre_char, const char* data, bool pgm) {
317 317
   char c;
318
-  uint8_t n = LCD_WIDTH - 2 - (pgm ? strlen_P(data) : (strlen(data)));
318
+  uint8_t n = LCD_WIDTH - 2 - (pgm ? lcd_strlen_P(data) : (lcd_strlen((char*)data)));
319 319
 
320 320
   lcd_implementation_mark_as_selected(row, pre_char);
321 321
 
@@ -377,18 +377,18 @@ void lcd_implementation_drawedit(const char* pstr, char* value) {
377 377
   uint8_t char_width = DOG_CHAR_WIDTH;
378 378
 
379 379
   #ifdef USE_BIG_EDIT_FONT
380
-    if (strlen_P(pstr) <= LCD_WIDTH_EDIT - 1) {
380
+    if (lcd_strlen_P(pstr) <= LCD_WIDTH_EDIT - 1) {
381 381
       u8g.setFont(FONT_MENU_EDIT);
382 382
       lcd_width = LCD_WIDTH_EDIT + 1;
383 383
       char_width = DOG_CHAR_WIDTH_EDIT;
384
-      if (strlen_P(pstr) >= LCD_WIDTH_EDIT - strlen(value)) rows = 2;
384
+      if (lcd_strlen_P(pstr) >= LCD_WIDTH_EDIT - lcd_strlen(value)) rows = 2;
385 385
     }
386 386
     else {
387 387
       u8g.setFont(FONT_MENU);
388 388
     }
389 389
   #endif
390 390
 
391
-  if (strlen_P(pstr) > LCD_WIDTH - 2 - strlen(value)) rows = 2;
391
+  if (lcd_strlen_P(pstr) > LCD_WIDTH - 2 - lcd_strlen(value)) rows = 2;
392 392
 
393 393
   const float kHalfChar = DOG_CHAR_HEIGHT_EDIT / 2;
394 394
   float rowHeight = u8g.getHeight() / (rows + 1); // 1/(rows+1) = 1/2 or 1/3
@@ -396,7 +396,7 @@ void lcd_implementation_drawedit(const char* pstr, char* value) {
396 396
   u8g.setPrintPos(0, rowHeight + kHalfChar);
397 397
   lcd_printPGM(pstr);
398 398
   u8g.print(':');
399
-  u8g.setPrintPos((lcd_width-1-strlen(value)) * char_width, rows * rowHeight + kHalfChar);
399
+  u8g.setPrintPos((lcd_width-1-lcd_strlen(value)) * char_width, rows * rowHeight + kHalfChar);
400 400
   u8g.print(value);
401 401
 }
402 402
 

+ 15
- 15
Marlin/language_ru.h Parādīt failu

@@ -13,7 +13,7 @@
13 13
 #define WELCOME_MSG                         MACHINE_NAME " Готов."
14 14
 #define MSG_SD_INSERTED                     "Карта вставлена"
15 15
 #define MSG_SD_REMOVED                      "Карта извлечена"
16
-#define MSG_MAIN                            "Меню \003"
16
+#define MSG_MAIN                            "Меню"
17 17
 #define MSG_AUTOSTART                       "Автостарт"
18 18
 #define MSG_DISABLE_STEPPERS                "Выкл. двигатели"
19 19
 #define MSG_AUTO_HOME                       "Парковка"
@@ -43,14 +43,14 @@
43 43
 #define MSG_MOVE_1MM                        "Move 1mm"
44 44
 #define MSG_MOVE_10MM                       "Move 10mm"
45 45
 #define MSG_SPEED                           "Скорость"
46
-#define MSG_NOZZLE                          "\002 Фильера"
47
-#define MSG_BED                             "\002 Кровать"
46
+#define MSG_NOZZLE                          LCD_STR_THERMOMETER " Фильера"
47
+#define MSG_BED                             LCD_STR_THERMOMETER " Кровать"
48 48
 #define MSG_FAN_SPEED                       "Куллер"
49 49
 #define MSG_FLOW                            "Поток"
50
-#define MSG_CONTROL                         "Настройки \003"
51
-#define MSG_MIN                             "\002 Минимум"
52
-#define MSG_MAX                             "\002 Максимум"
53
-#define MSG_FACTOR                          "\002 Фактор"
50
+#define MSG_CONTROL                         "Настройки"
51
+#define MSG_MIN                             LCD_STR_THERMOMETER " Минимум"
52
+#define MSG_MAX                             LCD_STR_THERMOMETER " Максимум"
53
+#define MSG_FACTOR                          LCD_STR_THERMOMETER " Фактор"
54 54
 #define MSG_AUTOTEMP                        "Autotemp"
55 55
 #define MSG_ON                              "Вкл. "
56 56
 #define MSG_OFF                             "Выкл. "
@@ -75,10 +75,10 @@
75 75
 #define MSG_YSTEPS                          "Y шаг/mm"
76 76
 #define MSG_ZSTEPS                          "Z шаг/mm"
77 77
 #define MSG_ESTEPS                          "E шаг/mm"
78
-#define MSG_TEMPERATURE                     "Температура     \x7E"
79
-#define MSG_MOTION                          "Скорости        \x7E"
78
+#define MSG_TEMPERATURE                     "Температура"
79
+#define MSG_MOTION                          "Скорости"
80 80
 #define MSG_VOLUMETRIC                      "Filament"
81
-#define MSG_VOLUMETRIC_ENABLED		        "E in mm3"
81
+#define MSG_VOLUMETRIC_ENABLED		          "E in mm3"
82 82
 #define MSG_FILAMENT_SIZE_EXTRUDER_0        "Fil. Dia. 1"
83 83
 #define MSG_FILAMENT_SIZE_EXTRUDER_1        "Fil. Dia. 2"
84 84
 #define MSG_FILAMENT_SIZE_EXTRUDER_2        "Fil. Dia. 3"
@@ -86,14 +86,14 @@
86 86
 #define MSG_STORE_EPROM                     "Сохранить в EPROM"
87 87
 #define MSG_LOAD_EPROM                      "Загруз. из EPROM"
88 88
 #define MSG_RESTORE_FAILSAFE                "Сброс настроек"
89
-#define MSG_REFRESH                         "\004Обновить"
90
-#define MSG_WATCH                           "Обзор           \003"
91
-#define MSG_PREPARE                         "Действия        \x7E"
92
-#define MSG_TUNE                            "Настройки       \x7E"
89
+#define MSG_REFRESH                         LCD_STR_REFRESH "Обновить"
90
+#define MSG_WATCH                           "Обзор"
91
+#define MSG_PREPARE                         "Действия"
92
+#define MSG_TUNE                            "Настройки"
93 93
 #define MSG_PAUSE_PRINT                     "Продолжить печать"
94 94
 #define MSG_RESUME_PRINT                    "возобн. печать"
95 95
 #define MSG_STOP_PRINT                      "Остановить печать"
96
-#define MSG_CARD_MENU                       "Меню карты      \x7E"
96
+#define MSG_CARD_MENU                       "Меню карты"
97 97
 #define MSG_NO_CARD                         "Нет карты"
98 98
 #define MSG_DWELL                           "Сон..."
99 99
 #define MSG_USERWAIT                        "Ожиданиие"

+ 21
- 1
Marlin/ultralcd.cpp Parādīt failu

@@ -1260,6 +1260,26 @@ void lcd_init()
1260 1260
 #endif
1261 1261
 }
1262 1262
 
1263
+int lcd_strlen(char *s) {
1264
+     int i = 0, j = 0;
1265
+   while (s[i]) {
1266
+     if ((s[i] & 0xc0) != 0x80) j++;
1267
+     i++;
1268
+   }
1269
+   return j;
1270
+}
1271
+
1272
+int lcd_strlen_P(const char *s) {
1273
+     int j = 0;
1274
+   while (pgm_read_byte(s)) {
1275
+     if ((pgm_read_byte(s) & 0xc0) != 0x80) j++;
1276
+     s++;
1277
+   }
1278
+   return j;
1279
+}
1280
+
1281
+
1282
+
1263 1283
 void lcd_update()
1264 1284
 {
1265 1285
     static unsigned long timeoutToStatus = 0;
@@ -1372,7 +1392,7 @@ void lcd_ignore_click(bool b)
1372 1392
 }
1373 1393
 
1374 1394
 void lcd_finishstatus() {
1375
-  int len = strlen(lcd_status_message);
1395
+  int len = lcd_strlen(lcd_status_message);
1376 1396
   if (len > 0) {
1377 1397
     while (len < LCD_WIDTH) {
1378 1398
       lcd_status_message[len++] = ' ';

+ 2
- 1
Marlin/ultralcd.h Parādīt failu

@@ -4,7 +4,8 @@
4 4
 #include "Marlin.h"
5 5
 
6 6
 #ifdef ULTRA_LCD
7
-
7
+  int lcd_strlen(char *s);
8
+  int lcd_strlen_P(const char *s);
8 9
   void lcd_update();
9 10
   void lcd_init();
10 11
   void lcd_setstatus(const char* message);

+ 9
- 9
Marlin/ultralcd_implementation_hitachi_HD44780.h Parādīt failu

@@ -636,7 +636,7 @@ static void lcd_implementation_drawmenu_generic(uint8_t row, const char* pstr, c
636 636
     {
637 637
         lcd.print(c);
638 638
         pstr++;
639
-        n--;
639
+        if ((pgm_read_byte(pstr) & 0xc0) != 0x80) n--;
640 640
     }
641 641
     while(n--)
642 642
         lcd.print(' ');
@@ -648,9 +648,9 @@ static void lcd_implementation_drawmenu_setting_edit_generic(uint8_t row, const
648 648
     char c;
649 649
     //Use all characters in narrow LCDs
650 650
   #if LCD_WIDTH < 20
651
-      uint8_t n = LCD_WIDTH - 1 - 1 - strlen(data);
651
+      uint8_t n = LCD_WIDTH - 1 - 1 - lcd_strlen(data);
652 652
     #else
653
-      uint8_t n = LCD_WIDTH - 1 - 2 - strlen(data);
653
+      uint8_t n = LCD_WIDTH - 1 - 2 - lcd_strlen(data);
654 654
   #endif
655 655
     lcd.setCursor(0, row);
656 656
     lcd.print(pre_char);
@@ -658,7 +658,7 @@ static void lcd_implementation_drawmenu_setting_edit_generic(uint8_t row, const
658 658
     {
659 659
         lcd.print(c);
660 660
         pstr++;
661
-        n--;
661
+        if ((pgm_read_byte(pstr) & 0xc0) != 0x80) n--;
662 662
     }
663 663
     lcd.print(':');
664 664
     while(n--)
@@ -670,9 +670,9 @@ static void lcd_implementation_drawmenu_setting_edit_generic_P(uint8_t row, cons
670 670
     char c;
671 671
     //Use all characters in narrow LCDs
672 672
   #if LCD_WIDTH < 20
673
-      uint8_t n = LCD_WIDTH - 1 - 1 - strlen_P(data);
673
+      uint8_t n = LCD_WIDTH - 1 - 1 - lcd_strlen_P(data);
674 674
     #else
675
-      uint8_t n = LCD_WIDTH - 1 - 2 - strlen_P(data);
675
+      uint8_t n = LCD_WIDTH - 1 - 2 - lcd_strlen_P(data);
676 676
   #endif
677 677
     lcd.setCursor(0, row);
678 678
     lcd.print(pre_char);
@@ -680,7 +680,7 @@ static void lcd_implementation_drawmenu_setting_edit_generic_P(uint8_t row, cons
680 680
     {
681 681
         lcd.print(c);
682 682
         pstr++;
683
-        n--;
683
+        if ((pgm_read_byte(pstr) & 0xc0) != 0x80) n--;
684 684
     }
685 685
     lcd.print(':');
686 686
     while(n--)
@@ -733,9 +733,9 @@ void lcd_implementation_drawedit(const char* pstr, char* value)
733 733
     lcd_printPGM(pstr);
734 734
     lcd.print(':');
735 735
    #if LCD_WIDTH < 20
736
-      lcd.setCursor(LCD_WIDTH - strlen(value), 1);
736
+      lcd.setCursor(LCD_WIDTH - lcd_strlen(value), 1);
737 737
     #else
738
-      lcd.setCursor(LCD_WIDTH -1 - strlen(value), 1);
738
+      lcd.setCursor(LCD_WIDTH -1 - lcd_strlen(value), 1);
739 739
    #endif
740 740
     lcd.print(value);
741 741
 }

Notiek ielāde…
Atcelt
Saglabāt