浏览代码

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
 
48
 
49
 #endif // EEPROM_SETTINGS
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
   char conv[8] = { 0 };
53
   char conv[8] = { 0 };
54
 
54
 

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

45
   FORCE_INLINE bool is_bitmap_set(uint16_t bits[16], const uint8_t x, const uint8_t y) { return TEST(bits[y], x); }
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
 #endif
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
   // Convert uint8_t to string with 123 format
50
   // Convert uint8_t to string with 123 format
51
   char* i8tostr3(const uint8_t x);
51
   char* i8tostr3(const uint8_t x);

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

595
       --did_pause_print;
595
       --did_pause_print;
596
     }
596
     }
597
   #endif
597
   #endif
598
+
599
+  #if ENABLED(ULTRA_LCD)
600
+    lcd_reset_status();
601
+  #endif
598
 }
602
 }
599
 
603
 
600
 #endif // ADVANCED_PAUSE_FEATURE
604
 #endif // ADVANCED_PAUSE_FEATURE

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

58
       CHAT_PORT
58
       CHAT_PORT
59
     #endif
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
 // To implement a new UI, complete the functions below and
28
 // To implement a new UI, complete the functions below and
29
 // read or update Marlin's state using the methods in the
29
 // read or update Marlin's state using the methods in the
30
 // UI methods in "../ui_api.h"
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
 namespace UI {
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
   void onMediaInserted();
50
   void onMediaInserted();
37
   void onMediaError();
51
   void onMediaError();
38
   void onMediaRemoved();
52
   void onMediaRemoved();
41
   void onPrintTimerPaused() {}
55
   void onPrintTimerPaused() {}
42
   void onPrintTimerStopped() {}
56
   void onPrintTimerStopped() {}
43
   void onFilamentRunout() {}
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
   void onFactoryReset() {}
60
   void onFactoryReset() {}
61
+  void onLoadSettings() {}
47
   void onStoreSettings() {}
62
   void onStoreSettings() {}
48
 }
63
 }
49
 
64
 

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

27
 #include "../../module/motion.h"
27
 #include "../../module/motion.h"
28
 #include "../../module/planner.h"
28
 #include "../../module/planner.h"
29
 #include "../../module/probe.h"
29
 #include "../../module/probe.h"
30
-#include "../../module/printcounter.h"
31
 #include "../../module/temperature.h"
30
 #include "../../module/temperature.h"
32
-#include "../../sd/cardreader.h"
33
 #include "../../libs/duration_t.h"
31
 #include "../../libs/duration_t.h"
34
 
32
 
35
 #if DO_SWITCH_EXTRUDER || ENABLED(SWITCHING_NOZZLE) || ENABLED(PARKING_EXTRUDER)
33
 #if DO_SWITCH_EXTRUDER || ENABLED(SWITCHING_NOZZLE) || ENABLED(PARKING_EXTRUDER)
37
 #endif
35
 #endif
38
 
36
 
39
 #if ENABLED(SDSUPPORT)
37
 #if ENABLED(SDSUPPORT)
38
+  #include "../../sd/cardreader.h"
40
   #include "../../feature/emergency_parser.h"
39
   #include "../../feature/emergency_parser.h"
41
 
40
 
42
   bool abort_sd_printing; // =false
41
   bool abort_sd_printing; // =false
44
   constexpr bool abort_sd_printing = false;
43
   constexpr bool abort_sd_printing = false;
45
 #endif
44
 #endif
46
 
45
 
46
+#if ENABLED(PRINTCOUNTER)
47
+  #include "../../core/utility.h"
48
+  #include "../../module/printcounter.h"
49
+#endif
50
+
47
 #include "ui_api.h"
51
 #include "ui_api.h"
48
 
52
 
49
 #if ENABLED(BACKLASH_GCODE)
53
 #if ENABLED(BACKLASH_GCODE)
272
     }
276
     }
273
   #endif
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
   #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
290
   #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
287
     float getZOffset_mm() {
291
     float getZOffset_mm() {
364
     return elapsed.value;
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
   float getFeedRate_percent() {
383
   float getFeedRate_percent() {
368
     return feedrate_percentage;
384
     return feedrate_percentage;
369
   }
385
   }
564
   UI::onStartup();
580
   UI::onStartup();
565
 }
581
 }
566
 
582
 
567
-void lcd_update()                                                                {
583
+void lcd_update() {
568
   #if ENABLED(SDSUPPORT)
584
   #if ENABLED(SDSUPPORT)
569
     static bool last_sd_status;
585
     static bool last_sd_status;
570
     const bool sd_status = IS_SD_INSERTED;
586
     const bool sd_status = IS_SD_INSERTED;
585
       }
601
       }
586
     }
602
     }
587
   #endif // SDSUPPORT
603
   #endif // SDSUPPORT
588
-  UI::onUpdate();
604
+  UI::onIdle();
589
 }
605
 }
590
 
606
 
591
 bool lcd_hasstatus()                                                             { return true; }
607
 bool lcd_hasstatus()                                                             { return true; }
594
 void lcd_refresh()                                                               {}
610
 void lcd_refresh()                                                               {}
595
 void lcd_setstatus(const char * const message, const bool persist /* = false */) { UI::onStatusChanged(message); }
611
 void lcd_setstatus(const char * const message, const bool persist /* = false */) { UI::onStatusChanged(message); }
596
 void lcd_setstatusPGM(const char * const message, int8_t level /* = 0 */)        { UI::onStatusChanged((progmem_str)message); }
612
 void lcd_setstatusPGM(const char * const message, int8_t level /* = 0 */)        { UI::onStatusChanged((progmem_str)message); }
597
-void lcd_reset_status()                                                          {}
598
 void lcd_setalertstatusPGM(const char * const message)                           { lcd_setstatusPGM(message, 0); }
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
 void lcd_status_printf_P(const uint8_t level, const char * const fmt, ...) {
632
 void lcd_status_printf_P(const uint8_t level, const char * const fmt, ...) {
600
   char buff[64];
633
   char buff[64];
601
   va_list args;
634
   va_list args;

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

49
   float getAxisMaxAcceleration_mm_s2(const axis_t axis);
49
   float getAxisMaxAcceleration_mm_s2(const axis_t axis);
50
   float getMinFeedrate_mm_s();
50
   float getMinFeedrate_mm_s();
51
   float getMinTravelFeedrate_mm_s();
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
   float getFeedRate_percent();
55
   float getFeedRate_percent();
56
   uint8_t getProgress_percent();
56
   uint8_t getProgress_percent();
57
   uint32_t getProgress_seconds_elapsed();
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
   void setTargetTemp_celsius(const uint8_t extruder, float temp);
67
   void setTargetTemp_celsius(const uint8_t extruder, float temp);
60
   void setFan_percent(const uint8_t fan, const float percent);
68
   void setFan_percent(const uint8_t fan, const float percent);
61
   void setAxisPosition_mm(const axis_t axis, float position, float _feedrate_mm_s);
69
   void setAxisPosition_mm(const axis_t axis, float position, float _feedrate_mm_s);
157
   // module and will be called by Marlin.
165
   // module and will be called by Marlin.
158
 
166
 
159
   void onStartup();
167
   void onStartup();
160
-  void onUpdate();
168
+  void onIdle();
161
   void onMediaInserted();
169
   void onMediaInserted();
162
   void onMediaError();
170
   void onMediaError();
163
   void onMediaRemoved();
171
   void onMediaRemoved();
171
   void onStatusChanged(progmem_str msg);
179
   void onStatusChanged(progmem_str msg);
172
   void onFactoryReset();
180
   void onFactoryReset();
173
   void onStoreSettings();
181
   void onStoreSettings();
182
+  void onLoadSettings();
174
 };
183
 };

正在加载...
取消
保存