Browse Source

Fix up LCD_PROGRESS_BAR

- Some messages should not expire with `PROGRESS_MSG_EXPIRE`.
- Simplify conditional for progress bar with sanity checks.
- Rename `messageTick` to `expireStatusMillis` and make it the expire
time.
Scott Lahteine 9 years ago
parent
commit
5519882eea

+ 7
- 3
Marlin/Marlin_main.cpp View File

@@ -846,7 +846,7 @@ void get_command()
846 846
         sprintf_P(time, PSTR("%i hours %i minutes"),hours, minutes);
847 847
         SERIAL_ECHO_START;
848 848
         SERIAL_ECHOLN(time);
849
-        lcd_setstatus(time);
849
+        lcd_setstatus(time, true);
850 850
         card.printingHasFinished();
851 851
         card.checkautostart(true);
852 852
 
@@ -2536,9 +2536,13 @@ inline void gcode_G92() {
2536 2536
     if (starpos != NULL) *(starpos) = '\0';
2537 2537
     while (*src == ' ') ++src;
2538 2538
     if (!hasP && !hasS && *src != '\0')
2539
-      lcd_setstatus(src);
2540
-    else
2539
+      lcd_setstatus(src, true);
2540
+    else {
2541 2541
       LCD_MESSAGEPGM(MSG_USERWAIT);
2542
+      #if defined(LCD_PROGRESS_BAR) && PROGRESS_MSG_EXPIRE > 0
2543
+        dontExpireStatus();
2544
+      #endif
2545
+    }
2542 2546
 
2543 2547
     lcd_ignore_click();
2544 2548
     st_synchronize();

+ 4
- 1
Marlin/SanityCheck.h View File

@@ -17,8 +17,11 @@
17 17
    * Progress Bar
18 18
    */
19 19
   #ifdef LCD_PROGRESS_BAR
20
+    #ifndef SDSUPPORT
21
+      #error LCD_PROGRESS_BAR requires SDSUPPORT.
22
+    #endif
20 23
     #ifdef DOGLCD
21
-      #warning LCD_PROGRESS_BAR does not apply to graphical displays.
24
+      #error LCD_PROGRESS_BAR does not apply to graphical displays.
22 25
     #endif
23 26
     #ifdef FILAMENT_LCD_DISPLAY
24 27
       #error LCD_PROGRESS_BAR and FILAMENT_LCD_DISPLAY are not fully compatible. Comment out this line to use both.

+ 34
- 26
Marlin/ultralcd.cpp View File

@@ -252,7 +252,7 @@ static void lcd_goto_menu(menuFunc_t menu, const uint32_t encoder=0, const bool
252 252
     if (feedback) lcd_quick_feedback();
253 253
 
254 254
     // For LCD_PROGRESS_BAR re-initialize the custom characters
255
-    #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT) && !defined(DOGLCD)
255
+    #ifdef LCD_PROGRESS_BAR
256 256
       lcd_set_custom_characters(menu == lcd_status_screen);
257 257
     #endif
258 258
   }
@@ -262,29 +262,32 @@ static void lcd_goto_menu(menuFunc_t menu, const uint32_t encoder=0, const bool
262 262
 static void lcd_status_screen()
263 263
 {
264 264
 	encoderRateMultiplierEnabled = false;
265
-  #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT) && !defined(DOGLCD)
266
-    uint16_t mil = millis();
265
+
266
+  #ifdef LCD_PROGRESS_BAR
267
+    unsigned long ms = millis();
267 268
     #ifndef PROGRESS_MSG_ONCE
268
-      if (mil > progressBarTick + PROGRESS_BAR_MSG_TIME + PROGRESS_BAR_BAR_TIME) {
269
-        progressBarTick = mil;
269
+      if (ms > progressBarTick + PROGRESS_BAR_MSG_TIME + PROGRESS_BAR_BAR_TIME) {
270
+        progressBarTick = ms;
270 271
       }
271 272
     #endif
272 273
     #if PROGRESS_MSG_EXPIRE > 0
273
-      // keep the message alive if paused, count down otherwise
274
-      if (messageTick > 0) {
274
+      // Handle message expire
275
+      if (expireStatusMillis > 0) {
275 276
         if (card.isFileOpen()) {
277
+          // Expire the message when printing is active
276 278
           if (IS_SD_PRINTING) {
277
-            if ((mil-messageTick) >= PROGRESS_MSG_EXPIRE) {
279
+            // Expire the message when printing is active
280
+            if (ms >= expireStatusMillis) {
278 281
               lcd_status_message[0] = '\0';
279
-              messageTick = 0;
282
+              expireStatusMillis = 0;
280 283
             }
281 284
           }
282 285
           else {
283
-            messageTick += LCD_UPDATE_INTERVAL;
286
+            expireStatusMillis += LCD_UPDATE_INTERVAL;
284 287
           }
285 288
         }
286 289
         else {
287
-          messageTick = 0;
290
+          expireStatusMillis = 0;
288 291
         }
289 292
       }
290 293
     #endif
@@ -324,7 +327,7 @@ static void lcd_status_screen()
324 327
     {
325 328
         lcd_goto_menu(lcd_main_menu);
326 329
         lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
327
-          #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT) && !defined(DOGLCD)
330
+          #ifdef LCD_PROGRESS_BAR
328 331
             currentMenu == lcd_status_screen
329 332
           #endif
330 333
         );
@@ -380,7 +383,7 @@ static void lcd_sdcard_stop() {
380 383
   card.closefile();
381 384
   autotempShutdown();
382 385
   cancel_heatup = true;
383
-  lcd_setstatus(MSG_PRINT_ABORTED);
386
+  lcd_setstatus(MSG_PRINT_ABORTED, true);
384 387
 }
385 388
 
386 389
 /* Menu implementation */
@@ -1275,7 +1278,7 @@ void lcd_update() {
1275 1278
       lcdDrawUpdate = 2;
1276 1279
       lcd_oldcardstatus = IS_SD_INSERTED;
1277 1280
       lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
1278
-        #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT) && !defined(DOGLCD)
1281
+        #ifdef LCD_PROGRESS_BAR
1279 1282
           currentMenu == lcd_status_screen
1280 1283
         #endif
1281 1284
       );
@@ -1393,7 +1396,7 @@ void lcd_ignore_click(bool b) {
1393 1396
   wait_for_unclick = false;
1394 1397
 }
1395 1398
 
1396
-void lcd_finishstatus() {
1399
+void lcd_finishstatus(bool persist=false) {
1397 1400
   int len = lcd_strlen(lcd_status_message);
1398 1401
   if (len > 0) {
1399 1402
     while (len < LCD_WIDTH) {
@@ -1401,11 +1404,11 @@ void lcd_finishstatus() {
1401 1404
     }
1402 1405
   }
1403 1406
   lcd_status_message[LCD_WIDTH] = '\0';
1404
-  #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT) && !defined(DOGLCD)
1407
+  #ifdef LCD_PROGRESS_BAR
1408
+    progressBarTick = millis();
1405 1409
     #if PROGRESS_MSG_EXPIRE > 0
1406
-      messageTick =
1410
+      expireStatusMillis = persist ? 0 : progressBarTick + PROGRESS_MSG_EXPIRE;
1407 1411
     #endif
1408
-    progressBarTick = millis();
1409 1412
   #endif
1410 1413
   lcdDrawUpdate = 2;
1411 1414
 
@@ -1414,21 +1417,26 @@ void lcd_finishstatus() {
1414 1417
   #endif
1415 1418
 }
1416 1419
 
1417
-void lcd_setstatus(const char* message) {
1420
+#if defined(LCD_PROGRESS_BAR) && PROGRESS_MSG_EXPIRE > 0
1421
+  void dontExpireStatus() { expireStatusMillis = 0; }
1422
+#endif
1423
+
1424
+void lcd_setstatus(const char* message, bool persist) {
1418 1425
   if (lcd_status_message_level > 0) return;
1419 1426
   strncpy(lcd_status_message, message, LCD_WIDTH);
1420
-  lcd_finishstatus();
1427
+  lcd_finishstatus(persist);
1421 1428
 }
1422 1429
 
1423
-void lcd_setstatuspgm(const char* message) {
1424
-  if (lcd_status_message_level > 0) return;
1425
-  strncpy_P(lcd_status_message, message, LCD_WIDTH);
1426
-  lcd_finishstatus();
1430
+void lcd_setstatuspgm(const char* message, uint8_t level) {
1431
+  if (level >= lcd_status_message_level) {
1432
+    strncpy_P(lcd_status_message, message, LCD_WIDTH);
1433
+    lcd_status_message_level = level;
1434
+    lcd_finishstatus(level > 0);
1435
+  }
1427 1436
 }
1428 1437
 
1429 1438
 void lcd_setalertstatuspgm(const char* message) {
1430
-  lcd_setstatuspgm(message);
1431
-  lcd_status_message_level = 1;
1439
+  lcd_setstatuspgm(message, 1);
1432 1440
   #ifdef ULTIPANEL
1433 1441
     lcd_return_to_status();
1434 1442
   #endif

+ 6
- 2
Marlin/ultralcd.h View File

@@ -8,12 +8,16 @@
8 8
   int lcd_strlen_P(const char *s);
9 9
   void lcd_update();
10 10
   void lcd_init();
11
-  void lcd_setstatus(const char* message);
12
-  void lcd_setstatuspgm(const char* message);
11
+  void lcd_setstatus(const char* message, const bool persist=false);
12
+  void lcd_setstatuspgm(const char* message, const uint8_t level=0);
13 13
   void lcd_setalertstatuspgm(const char* message);
14 14
   void lcd_reset_alert_level();
15 15
   bool lcd_detected(void);
16 16
 
17
+  #if defined(LCD_PROGRESS_BAR) && PROGRESS_MSG_EXPIRE > 0
18
+    void dontExpireStatus();
19
+  #endif
20
+
17 21
   #ifdef DOGLCD
18 22
     extern int lcd_contrast;
19 23
     void lcd_setcontrast(uint8_t value);

+ 7
- 7
Marlin/ultralcd_implementation_hitachi_HD44780.h View File

@@ -193,10 +193,10 @@
193 193
 
194 194
 #include "utf_mapper.h"
195 195
 
196
-#if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
196
+#ifdef LCD_PROGRESS_BAR
197 197
   static uint16_t progressBarTick = 0;
198 198
   #if PROGRESS_MSG_EXPIRE > 0
199
-    static uint16_t messageTick = 0;
199
+    static uint16_t expireStatusMillis = 0;
200 200
   #endif
201 201
   #define LCD_STR_PROGRESS  "\x03\x04\x05"
202 202
 #endif
@@ -214,7 +214,7 @@
214 214
 #define LCD_STR_ARROW_RIGHT ">"  /* from the default character set */
215 215
 
216 216
 static void lcd_set_custom_characters(
217
-  #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
217
+  #ifdef LCD_PROGRESS_BAR
218 218
     bool progress_bar_set=true
219 219
   #endif
220 220
 ) {
@@ -299,7 +299,7 @@ static void lcd_set_custom_characters(
299 299
     B00000
300 300
   }; //thanks Sonny Mounicou
301 301
 
302
-  #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
302
+  #ifdef LCD_PROGRESS_BAR
303 303
     static bool char_mode = false;
304 304
     byte progress[3][8] = { {
305 305
       B00000,
@@ -360,7 +360,7 @@ static void lcd_set_custom_characters(
360 360
 }
361 361
 
362 362
 static void lcd_implementation_init(
363
-  #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
363
+  #ifdef LCD_PROGRESS_BAR
364 364
     bool progress_bar_set=true
365 365
   #endif
366 366
 ) {
@@ -390,7 +390,7 @@ static void lcd_implementation_init(
390 390
 #endif
391 391
 
392 392
     lcd_set_custom_characters(
393
-        #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
393
+        #ifdef LCD_PROGRESS_BAR
394 394
             progress_bar_set
395 395
         #endif
396 396
     );
@@ -583,7 +583,7 @@ static void lcd_implementation_status_screen()
583 583
   // Status message line at the bottom
584 584
   lcd.setCursor(0, LCD_HEIGHT - 1);
585 585
 
586
-  #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
586
+  #ifdef LCD_PROGRESS_BAR
587 587
 
588 588
     if (card.isFileOpen()) {
589 589
       uint16_t mil = millis(), diff = mil - progressBarTick;

Loading…
Cancel
Save