Browse Source

dont scroll menu pointer out of view

Thomas Buck 3 years ago
parent
commit
4e28499ba7
4 changed files with 15 additions and 12 deletions
  1. 1
    1
      include/lcd.h
  2. 11
    8
      src/lcd.cpp
  3. 2
    2
      src/sm_menu.cpp
  4. 1
    1
      src/sm_value.cpp

+ 1
- 1
include/lcd.h View File

7
 void lcd_clear(void);
7
 void lcd_clear(void);
8
 void lcd_set_heading(const char *heading);
8
 void lcd_set_heading(const char *heading);
9
 void lcd_set_text(const char *text);
9
 void lcd_set_text(const char *text);
10
-void lcd_set_menu_text(int line, const char *text);
10
+void lcd_set_menu_text(int line, const char *text, int scroll_off);
11
 
11
 
12
 int lcd_text_lines(void);
12
 int lcd_text_lines(void);
13
 
13
 

+ 11
- 8
src/lcd.cpp View File

52
 
52
 
53
 String menu_pre[LCD_TEXT_LINES], menu_post[LCD_TEXT_LINES];
53
 String menu_pre[LCD_TEXT_LINES], menu_post[LCD_TEXT_LINES];
54
 int menu_dir[LCD_TEXT_LINES];
54
 int menu_dir[LCD_TEXT_LINES];
55
+int scroll_offset = 0;
55
 
56
 
56
 boolean redraw = false;
57
 boolean redraw = false;
57
 
58
 
62
 };
63
 };
63
 enum lcd_text_mode text_mode = lcd_mode_none;
64
 enum lcd_text_mode text_mode = lcd_mode_none;
64
 
65
 
65
-#define SCROLL_DELAY 500
66
+#define SCROLL_DELAY 1000
66
 unsigned long last_scroll_time = 0;
67
 unsigned long last_scroll_time = 0;
67
 
68
 
68
 #define IS_TEXT_CHAR(x) (((x >= 'a') && (x <= 'z')) || ((x >= 'A') && (x <= 'Z')))
69
 #define IS_TEXT_CHAR(x) (((x >= 'a') && (x <= 'z')) || ((x >= 'A') && (x <= 'Z')))
124
         }
125
         }
125
 
126
 
126
         // take first char of first line, append to pre
127
         // take first char of first line, append to pre
127
-        pre = pre + s[0][0];
128
-        s[0] = s[0].substring(1);
128
+        pre = pre + s[0][scroll_offset];
129
+        s[0] = s[0].substring(0, scroll_offset) + s[0].substring(scroll_offset + 1);
129
 
130
 
130
         // shift now empty spot to the left through lines
131
         // shift now empty spot to the left through lines
131
         for (int i = 1; i < n; i++) {
132
         for (int i = 1; i < n; i++) {
132
-            s[i - 1] = s[i - 1] + s[i][0];
133
-            s[i] = s[i].substring(1);
133
+            s[i - 1] = s[i - 1] + s[i][scroll_offset];
134
+            s[i] = s[i].substring(0, scroll_offset) + s[i].substring(scroll_offset + 1);
134
         }
135
         }
135
 
136
 
136
         // fill empty spot at end of last line with first char of post
137
         // fill empty spot at end of last line with first char of post
149
 
150
 
150
         // shift now empty sport to the right through lines
151
         // shift now empty sport to the right through lines
151
         for (int i = n - 1; i >= 1; i--) {
152
         for (int i = n - 1; i >= 1; i--) {
152
-            s[i] = s[i - 1][s[i - 1].length() - 1] + s[i];
153
+            s[i] = s[i].substring(0, scroll_offset) + s[i - 1][s[i - 1].length() - 1] + s[i].substring(scroll_offset);
153
             s[i - 1] = s[i - 1].substring(0, s[i - 1].length() - 1);
154
             s[i - 1] = s[i - 1].substring(0, s[i - 1].length() - 1);
154
         }
155
         }
155
 
156
 
156
         // fill empty spot at beginning with last char of pre
157
         // fill empty spot at beginning with last char of pre
157
-        s[0] = pre[pre.length() - 1] + s[0];
158
+        s[0] = s[0].substring(0, scroll_offset) + pre[pre.length() - 1] + s[0].substring(scroll_offset);
158
         pre = pre.substring(0, pre.length() - 1);
159
         pre = pre.substring(0, pre.length() - 1);
159
     }
160
     }
160
 
161
 
294
     Serial.println(t);
295
     Serial.println(t);
295
 
296
 
296
     text_mode = lcd_mode_multiline;
297
     text_mode = lcd_mode_multiline;
298
+    scroll_offset = 0;
297
 
299
 
298
 #ifdef USE_20X4_TEXT_LCD
300
 #ifdef USE_20X4_TEXT_LCD
299
     lcd.setCursor(0, LCD_HEADING_LINES);
301
     lcd.setCursor(0, LCD_HEADING_LINES);
309
 #endif // USE_FULL_GRAPHIC_LCD
311
 #endif // USE_FULL_GRAPHIC_LCD
310
 }
312
 }
311
 
313
 
312
-void lcd_set_menu_text(int line, const char *t) {
314
+void lcd_set_menu_text(int line, const char *t, int scroll_off) {
313
     if ((line < 0) || (line >= LCD_TEXT_LINES)) {
315
     if ((line < 0) || (line >= LCD_TEXT_LINES)) {
314
         Serial.print(F("Invalid lcd line no: "));
316
         Serial.print(F("Invalid lcd line no: "));
315
         Serial.println(line);
317
         Serial.println(line);
321
     Serial.println(t);
323
     Serial.println(t);
322
 
324
 
323
     text_mode = lcd_mode_menu;
325
     text_mode = lcd_mode_menu;
326
+    scroll_offset = scroll_off;
324
 
327
 
325
 #ifdef USE_20X4_TEXT_LCD
328
 #ifdef USE_20X4_TEXT_LCD
326
     lcd.setCursor(0, LCD_HEADING_LINES + line);
329
     lcd.setCursor(0, LCD_HEADING_LINES + line);

+ 2
- 2
src/sm_menu.cpp View File

79
         } else {
79
         } else {
80
             s += children.at(i)->getTitle();
80
             s += children.at(i)->getTitle();
81
         }
81
         }
82
-        lcd_set_menu_text(i - menuOff, s.c_str());
82
+        lcd_set_menu_text(i - menuOff, s.c_str(), 2);
83
     }
83
     }
84
 }
84
 }
85
 
85
 
161
         } else {
161
         } else {
162
             s += contents.at(i);
162
             s += contents.at(i);
163
         }
163
         }
164
-        lcd_set_menu_text(i - menuOff, s.c_str());
164
+        lcd_set_menu_text(i - menuOff, s.c_str(), 2);
165
     }
165
     }
166
 }
166
 }
167
 
167
 

+ 1
- 1
src/sm_value.cpp View File

158
             }
158
             }
159
         }
159
         }
160
 
160
 
161
-        lcd_set_menu_text(i - off, s.c_str());
161
+        lcd_set_menu_text(i - off, s.c_str(), 2);
162
     }
162
     }
163
 }
163
 }
164
 
164
 

Loading…
Cancel
Save