Browse Source

dont scroll menu pointer out of view

Thomas Buck 2 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,7 +7,7 @@ void lcd_loop(void);
7 7
 void lcd_clear(void);
8 8
 void lcd_set_heading(const char *heading);
9 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 12
 int lcd_text_lines(void);
13 13
 

+ 11
- 8
src/lcd.cpp View File

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

+ 2
- 2
src/sm_menu.cpp View File

@@ -79,7 +79,7 @@ void StateMenu::display(void) {
79 79
         } else {
80 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,7 +161,7 @@ void StateDynamicMenu::display(void) {
161 161
         } else {
162 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,7 +158,7 @@ void StateValues<T, N>::display(void) {
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