Quellcode durchsuchen

further optimise lcdui_print_status_line

We can use lcd_print_pad to determine
whether the end of the file name was reached

lcd_print_pad now returns the last character pointed to.
If the end of the string was reached, it will be the null delimeter which
evaluates to "false" in an if statment (same as NULL).
Else "true" means the end of the string was not reached.

Change in memory:
Flash: -42 bytes
SRAM: 0 bytes
Guðni Már Gilbert vor 1 Jahr
Ursprung
Commit
184e19dd60
3 geänderte Dateien mit 6 neuen und 14 gelöschten Zeilen
  1. 2 1
      Firmware/lcd.cpp
  2. 1 1
      Firmware/lcd.h
  3. 3 12
      Firmware/ultralcd.cpp

+ 2 - 1
Firmware/lcd.cpp

@@ -528,13 +528,14 @@ void lcd_print(const char* s)
 	while (*s) lcd_write(*(s++));
 }
 
-void lcd_print_pad(const char* s, uint8_t len)
+char lcd_print_pad(const char* s, uint8_t len)
 {
     while (len && *s) {
         lcd_write(*(s++));
         --len;
     }
     lcd_space(len);
+    return *s;
 }
 
 void lcd_print(char c, int base)

+ 1 - 1
Firmware/lcd.h

@@ -53,7 +53,7 @@ extern void lcd_printNumber(unsigned long n, uint8_t base);
 extern void lcd_printFloat(double number, uint8_t digits);
 
 extern void lcd_print(const char*);
-extern void lcd_print_pad(const char*, uint8_t len);
+extern char lcd_print_pad(const char* s, uint8_t len);
 extern void lcd_print(char, int = 0);
 extern void lcd_print(unsigned char, int = 0);
 extern void lcd_print(int, int = 10);

+ 3 - 12
Firmware/ultralcd.cpp

@@ -585,20 +585,11 @@ void lcdui_print_status_line(void) {
     {
         // If printing from SD, show what we are printing
         const char* longFilenameOLD = (card.longFilename[0] ? card.longFilename : card.filename);
-        if(strlen(longFilenameOLD) > LCD_WIDTH) {
-            uint8_t gh = scrollstuff;
-            while (((gh - scrollstuff) < LCD_WIDTH)) {
-                lcd_putc_at(gh - scrollstuff, 3, longFilenameOLD[gh - 1]);
-                if (longFilenameOLD[gh] == '\0') {
-                    scrollstuff = 0;
-                    break; // Exit while loop
-                } else {
-                    gh++;
-                }
-            }
+        if( lcd_print_pad(&longFilenameOLD[scrollstuff], LCD_WIDTH) )
+        {
             scrollstuff++;
         } else {
-            lcd_print_pad(longFilenameOLD, LCD_WIDTH);
+            scrollstuff = 0;
         }
     } else { // Otherwise check for other special events
         switch (custom_message_type) {