Browse Source

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 years ago
parent
commit
6cdcd6c6d1

+ 8
- 4
Marlin/LiquidCrystalRus.cpp View File

14
 // it is a Russian alphabet translation
14
 // it is a Russian alphabet translation
15
 // except 0401 --> 0xa2 = ╗, 0451 --> 0xb5
15
 // except 0401 --> 0xa2 = ╗, 0451 --> 0xb5
16
 const PROGMEM uint8_t utf_recode[] = 
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
 // When the display powers up, it is configured as follows:
27
 // When the display powers up, it is configured as follows:

+ 1
- 1
Marlin/cardreader.cpp View File

65
       createFilename(lfilename,p);
65
       createFilename(lfilename,p);
66
       
66
       
67
       path[0]=0;
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
        strcat(path,"/");
70
        strcat(path,"/");
71
       }
71
       }

+ 5
- 5
Marlin/dogm_lcd_implementation.h View File

315
 
315
 
316
 static void _drawmenu_setting_edit_generic(uint8_t row, const char* pstr, char pre_char, const char* data, bool pgm) {
316
 static void _drawmenu_setting_edit_generic(uint8_t row, const char* pstr, char pre_char, const char* data, bool pgm) {
317
   char c;
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
   lcd_implementation_mark_as_selected(row, pre_char);
320
   lcd_implementation_mark_as_selected(row, pre_char);
321
 
321
 
377
   uint8_t char_width = DOG_CHAR_WIDTH;
377
   uint8_t char_width = DOG_CHAR_WIDTH;
378
 
378
 
379
   #ifdef USE_BIG_EDIT_FONT
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
       u8g.setFont(FONT_MENU_EDIT);
381
       u8g.setFont(FONT_MENU_EDIT);
382
       lcd_width = LCD_WIDTH_EDIT + 1;
382
       lcd_width = LCD_WIDTH_EDIT + 1;
383
       char_width = DOG_CHAR_WIDTH_EDIT;
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
     else {
386
     else {
387
       u8g.setFont(FONT_MENU);
387
       u8g.setFont(FONT_MENU);
388
     }
388
     }
389
   #endif
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
   const float kHalfChar = DOG_CHAR_HEIGHT_EDIT / 2;
393
   const float kHalfChar = DOG_CHAR_HEIGHT_EDIT / 2;
394
   float rowHeight = u8g.getHeight() / (rows + 1); // 1/(rows+1) = 1/2 or 1/3
394
   float rowHeight = u8g.getHeight() / (rows + 1); // 1/(rows+1) = 1/2 or 1/3
396
   u8g.setPrintPos(0, rowHeight + kHalfChar);
396
   u8g.setPrintPos(0, rowHeight + kHalfChar);
397
   lcd_printPGM(pstr);
397
   lcd_printPGM(pstr);
398
   u8g.print(':');
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
   u8g.print(value);
400
   u8g.print(value);
401
 }
401
 }
402
 
402
 

+ 15
- 15
Marlin/language_ru.h View File

13
 #define WELCOME_MSG                         MACHINE_NAME " Готов."
13
 #define WELCOME_MSG                         MACHINE_NAME " Готов."
14
 #define MSG_SD_INSERTED                     "Карта вставлена"
14
 #define MSG_SD_INSERTED                     "Карта вставлена"
15
 #define MSG_SD_REMOVED                      "Карта извлечена"
15
 #define MSG_SD_REMOVED                      "Карта извлечена"
16
-#define MSG_MAIN                            "Меню \003"
16
+#define MSG_MAIN                            "Меню"
17
 #define MSG_AUTOSTART                       "Автостарт"
17
 #define MSG_AUTOSTART                       "Автостарт"
18
 #define MSG_DISABLE_STEPPERS                "Выкл. двигатели"
18
 #define MSG_DISABLE_STEPPERS                "Выкл. двигатели"
19
 #define MSG_AUTO_HOME                       "Парковка"
19
 #define MSG_AUTO_HOME                       "Парковка"
43
 #define MSG_MOVE_1MM                        "Move 1mm"
43
 #define MSG_MOVE_1MM                        "Move 1mm"
44
 #define MSG_MOVE_10MM                       "Move 10mm"
44
 #define MSG_MOVE_10MM                       "Move 10mm"
45
 #define MSG_SPEED                           "Скорость"
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
 #define MSG_FAN_SPEED                       "Куллер"
48
 #define MSG_FAN_SPEED                       "Куллер"
49
 #define MSG_FLOW                            "Поток"
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
 #define MSG_AUTOTEMP                        "Autotemp"
54
 #define MSG_AUTOTEMP                        "Autotemp"
55
 #define MSG_ON                              "Вкл. "
55
 #define MSG_ON                              "Вкл. "
56
 #define MSG_OFF                             "Выкл. "
56
 #define MSG_OFF                             "Выкл. "
75
 #define MSG_YSTEPS                          "Y шаг/mm"
75
 #define MSG_YSTEPS                          "Y шаг/mm"
76
 #define MSG_ZSTEPS                          "Z шаг/mm"
76
 #define MSG_ZSTEPS                          "Z шаг/mm"
77
 #define MSG_ESTEPS                          "E шаг/mm"
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
 #define MSG_VOLUMETRIC                      "Filament"
80
 #define MSG_VOLUMETRIC                      "Filament"
81
-#define MSG_VOLUMETRIC_ENABLED		        "E in mm3"
81
+#define MSG_VOLUMETRIC_ENABLED		          "E in mm3"
82
 #define MSG_FILAMENT_SIZE_EXTRUDER_0        "Fil. Dia. 1"
82
 #define MSG_FILAMENT_SIZE_EXTRUDER_0        "Fil. Dia. 1"
83
 #define MSG_FILAMENT_SIZE_EXTRUDER_1        "Fil. Dia. 2"
83
 #define MSG_FILAMENT_SIZE_EXTRUDER_1        "Fil. Dia. 2"
84
 #define MSG_FILAMENT_SIZE_EXTRUDER_2        "Fil. Dia. 3"
84
 #define MSG_FILAMENT_SIZE_EXTRUDER_2        "Fil. Dia. 3"
86
 #define MSG_STORE_EPROM                     "Сохранить в EPROM"
86
 #define MSG_STORE_EPROM                     "Сохранить в EPROM"
87
 #define MSG_LOAD_EPROM                      "Загруз. из EPROM"
87
 #define MSG_LOAD_EPROM                      "Загруз. из EPROM"
88
 #define MSG_RESTORE_FAILSAFE                "Сброс настроек"
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
 #define MSG_PAUSE_PRINT                     "Продолжить печать"
93
 #define MSG_PAUSE_PRINT                     "Продолжить печать"
94
 #define MSG_RESUME_PRINT                    "возобн. печать"
94
 #define MSG_RESUME_PRINT                    "возобн. печать"
95
 #define MSG_STOP_PRINT                      "Остановить печать"
95
 #define MSG_STOP_PRINT                      "Остановить печать"
96
-#define MSG_CARD_MENU                       "Меню карты      \x7E"
96
+#define MSG_CARD_MENU                       "Меню карты"
97
 #define MSG_NO_CARD                         "Нет карты"
97
 #define MSG_NO_CARD                         "Нет карты"
98
 #define MSG_DWELL                           "Сон..."
98
 #define MSG_DWELL                           "Сон..."
99
 #define MSG_USERWAIT                        "Ожиданиие"
99
 #define MSG_USERWAIT                        "Ожиданиие"

+ 21
- 1
Marlin/ultralcd.cpp View File

1260
 #endif
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
 void lcd_update()
1283
 void lcd_update()
1264
 {
1284
 {
1265
     static unsigned long timeoutToStatus = 0;
1285
     static unsigned long timeoutToStatus = 0;
1372
 }
1392
 }
1373
 
1393
 
1374
 void lcd_finishstatus() {
1394
 void lcd_finishstatus() {
1375
-  int len = strlen(lcd_status_message);
1395
+  int len = lcd_strlen(lcd_status_message);
1376
   if (len > 0) {
1396
   if (len > 0) {
1377
     while (len < LCD_WIDTH) {
1397
     while (len < LCD_WIDTH) {
1378
       lcd_status_message[len++] = ' ';
1398
       lcd_status_message[len++] = ' ';

+ 2
- 1
Marlin/ultralcd.h View File

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

+ 9
- 9
Marlin/ultralcd_implementation_hitachi_HD44780.h View File

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

Loading…
Cancel
Save