浏览代码

Fix and improve EXTENSIBLE_UI (#12117)

- Add methods to access print counter data
- Clean up some inconsistent method names
- Clear lcd status after filament change
- Implement `lcd_reset_status` so it works like UltraLCD
Marcio Teixeira 6 年前
父节点
当前提交
f98f4ac7ea

+ 1
- 1
Marlin/src/core/utility.cpp 查看文件

@@ -48,7 +48,7 @@ void safe_delay(millis_t ms) {
48 48
 
49 49
 #endif // EEPROM_SETTINGS
50 50
 
51
-#if ENABLED(ULTRA_LCD) || ENABLED(DEBUG_LEVELING_FEATURE)
51
+#if ENABLED(ULTRA_LCD) || ENABLED(DEBUG_LEVELING_FEATURE) || ENABLED(EXTENSIBLE_UI)
52 52
 
53 53
   char conv[8] = { 0 };
54 54
 

+ 1
- 1
Marlin/src/core/utility.h 查看文件

@@ -45,7 +45,7 @@ void safe_delay(millis_t ms);
45 45
   FORCE_INLINE bool is_bitmap_set(uint16_t bits[16], const uint8_t x, const uint8_t y) { return TEST(bits[y], x); }
46 46
 #endif
47 47
 
48
-#if ENABLED(ULTRA_LCD) || ENABLED(DEBUG_LEVELING_FEATURE)
48
+#if ENABLED(ULTRA_LCD) || ENABLED(DEBUG_LEVELING_FEATURE) || ENABLED(EXTENSIBLE_UI)
49 49
 
50 50
   // Convert uint8_t to string with 123 format
51 51
   char* i8tostr3(const uint8_t x);

+ 4
- 0
Marlin/src/feature/pause.cpp 查看文件

@@ -595,6 +595,10 @@ void resume_print(const float &slow_load_length/*=0*/, const float &fast_load_le
595 595
       --did_pause_print;
596 596
     }
597 597
   #endif
598
+
599
+  #if ENABLED(ULTRA_LCD)
600
+    lcd_reset_status();
601
+  #endif
598 602
 }
599 603
 
600 604
 #endif // ADVANCED_PAUSE_FEATURE

+ 3
- 0
Marlin/src/gcode/eeprom/M500-M504.cpp 查看文件

@@ -58,6 +58,9 @@ void GcodeSuite::M501() {
58 58
       CHAT_PORT
59 59
     #endif
60 60
   );
61
+  #if ENABLED(EXTENSIBLE_UI)
62
+    UI::onLoadSettings();
63
+  #endif
61 64
 }
62 65
 
63 66
 /**

Marlin/src/lcd/extensible_ui/lib/dummy.cpp → Marlin/src/lcd/extensible_ui/lib/example.cpp 查看文件

@@ -28,11 +28,25 @@
28 28
 // To implement a new UI, complete the functions below and
29 29
 // read or update Marlin's state using the methods in the
30 30
 // UI methods in "../ui_api.h"
31
+//
32
+// Although it may be possible to access other state
33
+// variables from Marlin, using the API here possibly
34
+// helps ensure future compatibility.
31 35
 
32 36
 namespace UI {
33
-  void onStartup() {}
34
-  void onUpdate() {}
35
-  void onPrinterKilled(const char* lcd_msg) {}
37
+  void onStartup() {
38
+    /* Initialize the display module here. The following
39
+     * routines are available for access to the GPIO pins:
40
+     *
41
+     *   SET_OUTPUT(pin)
42
+     *   SET_INPUT_PULLUP(pin)
43
+     *   SET_INPUT(pin)
44
+     *   WRITE(pin,value)
45
+     *   READ(pin)
46
+     */
47
+  }
48
+  void onIdle() {}
49
+  void onPrinterKilled(const char* msg) {}
36 50
   void onMediaInserted();
37 51
   void onMediaError();
38 52
   void onMediaRemoved();
@@ -41,9 +55,10 @@ namespace UI {
41 55
   void onPrintTimerPaused() {}
42 56
   void onPrintTimerStopped() {}
43 57
   void onFilamentRunout() {}
44
-  void onStatusChanged(const char* lcd_msg) {}
45
-  void onStatusChanged(progmem_str lcd_msg) {}
58
+  void onStatusChanged(const char* msg) {}
59
+  void onStatusChanged(progmem_str msg) {}
46 60
   void onFactoryReset() {}
61
+  void onLoadSettings() {}
47 62
   void onStoreSettings() {}
48 63
 }
49 64
 

+ 48
- 15
Marlin/src/lcd/extensible_ui/ui_api.cpp 查看文件

@@ -27,9 +27,7 @@
27 27
 #include "../../module/motion.h"
28 28
 #include "../../module/planner.h"
29 29
 #include "../../module/probe.h"
30
-#include "../../module/printcounter.h"
31 30
 #include "../../module/temperature.h"
32
-#include "../../sd/cardreader.h"
33 31
 #include "../../libs/duration_t.h"
34 32
 
35 33
 #if DO_SWITCH_EXTRUDER || ENABLED(SWITCHING_NOZZLE) || ENABLED(PARKING_EXTRUDER)
@@ -37,6 +35,7 @@
37 35
 #endif
38 36
 
39 37
 #if ENABLED(SDSUPPORT)
38
+  #include "../../sd/cardreader.h"
40 39
   #include "../../feature/emergency_parser.h"
41 40
 
42 41
   bool abort_sd_printing; // =false
@@ -44,6 +43,11 @@
44 43
   constexpr bool abort_sd_printing = false;
45 44
 #endif
46 45
 
46
+#if ENABLED(PRINTCOUNTER)
47
+  #include "../../core/utility.h"
48
+  #include "../../module/printcounter.h"
49
+#endif
50
+
47 51
 #include "ui_api.h"
48 52
 
49 53
 #if ENABLED(BACKLASH_GCODE)
@@ -272,16 +276,16 @@ namespace UI {
272 276
     }
273 277
   #endif
274 278
 
275
-  float getMinFeedrate_mm_s()                             { return planner.settings.min_feedrate_mm_s; }
276
-  float getMinTravelFeedrate_mm_s()                       { return planner.settings.min_travel_feedrate_mm_s; }
277
-  float getPrintingAcceleration_mm_s2()                   { return planner.settings.acceleration; }
278
-  float getRetractAcceleration_mm_s2()                    { return planner.settings.retract_acceleration; }
279
-  float getTravelAcceleration_mm_s2()                     { return planner.settings.travel_acceleration; }
280
-  void setMinFeedrate_mm_s(const float fr)                { planner.settings.min_feedrate_mm_s = fr; }
281
-  void setMinTravelFeedrate_mm_s(const float fr)          { planner.settings.min_travel_feedrate_mm_s = fr; }
282
-  void setPrintingAcceleration_mm_per_s2(const float acc) { planner.settings.acceleration = acc; }
283
-  void setRetractAcceleration_mm_s2(const float acc)      { planner.settings.retract_acceleration = acc; }
284
-  void setTravelAcceleration_mm_s2(const float acc)       { planner.settings.travel_acceleration = acc; }
279
+  float getMinFeedrate_mm_s()                         { return planner.settings.min_feedrate_mm_s; }
280
+  float getMinTravelFeedrate_mm_s()                   { return planner.settings.min_travel_feedrate_mm_s; }
281
+  float getPrintingAcceleration_mm_s2()               { return planner.settings.acceleration; }
282
+  float getRetractAcceleration_mm_s2()                { return planner.settings.retract_acceleration; }
283
+  float getTravelAcceleration_mm_s2()                 { return planner.settings.travel_acceleration; }
284
+  void setMinFeedrate_mm_s(const float fr)            { planner.settings.min_feedrate_mm_s = fr; }
285
+  void setMinTravelFeedrate_mm_s(const float fr)      { planner.settings.min_travel_feedrate_mm_s = fr; }
286
+  void setPrintingAcceleration_mm_s2(const float acc) { planner.settings.acceleration = acc; }
287
+  void setRetractAcceleration_mm_s2(const float acc)  { planner.settings.retract_acceleration = acc; }
288
+  void setTravelAcceleration_mm_s2(const float acc)   { planner.settings.travel_acceleration = acc; }
285 289
 
286 290
   #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
287 291
     float getZOffset_mm() {
@@ -364,6 +368,18 @@ namespace UI {
364 368
     return elapsed.value;
365 369
   }
366 370
 
371
+  #if ENABLED(PRINTCOUNTER)
372
+    char* getTotalPrints_str(char buffer[21])    { strcpy(buffer,itostr3left(print_job_timer.getStats().totalPrints));    return buffer; }
373
+    char* getFinishedPrints_str(char buffer[21]) { strcpy(buffer,itostr3left(print_job_timer.getStats().finishedPrints)); return buffer; }
374
+    char* getTotalPrintTime_str(char buffer[21]) { duration_t(print_job_timer.getStats().printTime).toString(buffer);     return buffer; }
375
+    char* getLongestPrint_str(char buffer[21])   { duration_t(print_job_timer.getStats().printTime).toString(buffer);     return buffer; }
376
+    char* getFilamentUsed_str(char buffer[21])   {
377
+      printStatistics stats = print_job_timer.getStats();
378
+      sprintf_P(buffer, PSTR("%ld.%im"), long(stats.filamentUsed / 1000), int16_t(stats.filamentUsed / 100) % 10);
379
+      return buffer;
380
+    }
381
+  #endif
382
+
367 383
   float getFeedRate_percent() {
368 384
     return feedrate_percentage;
369 385
   }
@@ -564,7 +580,7 @@ void lcd_init() {
564 580
   UI::onStartup();
565 581
 }
566 582
 
567
-void lcd_update()                                                                {
583
+void lcd_update() {
568 584
   #if ENABLED(SDSUPPORT)
569 585
     static bool last_sd_status;
570 586
     const bool sd_status = IS_SD_INSERTED;
@@ -585,7 +601,7 @@ void lcd_update()
585 601
       }
586 602
     }
587 603
   #endif // SDSUPPORT
588
-  UI::onUpdate();
604
+  UI::onIdle();
589 605
 }
590 606
 
591 607
 bool lcd_hasstatus()                                                             { return true; }
@@ -594,8 +610,25 @@ void lcd_reset_alert_level()
594 610
 void lcd_refresh()                                                               {}
595 611
 void lcd_setstatus(const char * const message, const bool persist /* = false */) { UI::onStatusChanged(message); }
596 612
 void lcd_setstatusPGM(const char * const message, int8_t level /* = 0 */)        { UI::onStatusChanged((progmem_str)message); }
597
-void lcd_reset_status()                                                          {}
598 613
 void lcd_setalertstatusPGM(const char * const message)                           { lcd_setstatusPGM(message, 0); }
614
+void lcd_reset_status() {
615
+  static const char paused[] PROGMEM = MSG_PRINT_PAUSED;
616
+  static const char printing[] PROGMEM = MSG_PRINTING;
617
+  static const char welcome[] PROGMEM = WELCOME_MSG;
618
+  PGM_P msg;
619
+  if (print_job_timer.isPaused())
620
+    msg = paused;
621
+  #if ENABLED(SDSUPPORT)
622
+    else if (card.sdprinting)
623
+      return lcd_setstatus(card.longest_filename(), true);
624
+  #endif
625
+  else if (print_job_timer.isRunning())
626
+    msg = printing;
627
+  else
628
+    msg = welcome;
629
+
630
+  lcd_setstatusPGM(msg, -1);
631
+}
599 632
 void lcd_status_printf_P(const uint8_t level, const char * const fmt, ...) {
600 633
   char buff[64];
601 634
   va_list args;

+ 13
- 4
Marlin/src/lcd/extensible_ui/ui_api.h 查看文件

@@ -49,13 +49,21 @@ namespace UI {
49 49
   float getAxisMaxAcceleration_mm_s2(const axis_t axis);
50 50
   float getMinFeedrate_mm_s();
51 51
   float getMinTravelFeedrate_mm_s();
52
-  float getPrintingAcceleration_mm_per_s2();
53
-  float getRetractAcceleration_mm_per_s2();
54
-  float getTravelAcceleration_mm_per_s2();
52
+  float getPrintingAcceleration_mm_s2();
53
+  float getRetractAcceleration_mm_s2();
54
+  float getTravelAcceleration_mm_s2();
55 55
   float getFeedRate_percent();
56 56
   uint8_t getProgress_percent();
57 57
   uint32_t getProgress_seconds_elapsed();
58 58
 
59
+  #if ENABLED(PRINTCOUNTER)
60
+    char *getTotalPrints_str(char buffer[21]);
61
+    char *getFinishedPrints_str(char buffer[21]);
62
+    char *getTotalPrintTime_str(char buffer[21]);
63
+    char *getLongestPrint_str(char buffer[21]);
64
+    char *getFilamentUsed_str(char buffer[21]);
65
+  #endif
66
+
59 67
   void setTargetTemp_celsius(const uint8_t extruder, float temp);
60 68
   void setFan_percent(const uint8_t fan, const float percent);
61 69
   void setAxisPosition_mm(const axis_t axis, float position, float _feedrate_mm_s);
@@ -157,7 +165,7 @@ namespace UI {
157 165
   // module and will be called by Marlin.
158 166
 
159 167
   void onStartup();
160
-  void onUpdate();
168
+  void onIdle();
161 169
   void onMediaInserted();
162 170
   void onMediaError();
163 171
   void onMediaRemoved();
@@ -171,4 +179,5 @@ namespace UI {
171 179
   void onStatusChanged(progmem_str msg);
172 180
   void onFactoryReset();
173 181
   void onStoreSettings();
182
+  void onLoadSettings();
174 183
 };

正在加载...
取消
保存