Sfoglia il codice sorgente

AutoReport class (Temperature, Cardreader) (#20913)

Scott Lahteine 3 anni fa
parent
commit
9d0e64a725
Nessun account collegato all'indirizzo email del committer

+ 2
- 2
Marlin/src/MarlinCore.cpp Vedi File

@@ -687,8 +687,8 @@ void idle(TERN_(ADVANCED_PAUSE_FEATURE, bool no_stepper_sleep/*=false*/)) {
687 687
   // Auto-report Temperatures / SD Status
688 688
   #if HAS_AUTO_REPORTING
689 689
     if (!gcode.autoreport_paused) {
690
-      TERN_(AUTO_REPORT_TEMPERATURES, thermalManager.auto_report_temperatures());
691
-      TERN_(AUTO_REPORT_SD_STATUS, card.auto_report_sd_status());
690
+      TERN_(AUTO_REPORT_TEMPERATURES, thermalManager.auto_reporter.tick());
691
+      TERN_(AUTO_REPORT_SD_STATUS, card.auto_reporter.tick());
692 692
     }
693 693
   #endif
694 694
 

+ 1
- 1
Marlin/src/gcode/calibrate/G76_M192_M871.cpp Vedi File

@@ -267,7 +267,7 @@ void GcodeSuite::G76() {
267 267
 
268 268
       say_waiting_for_probe_heating();
269 269
       SERIAL_ECHOLNPAIR(" Bed:", target_bed, " Probe:", target_probe);
270
-      const millis_t probe_timeout_ms = millis() + 900UL * 1000UL;
270
+      const millis_t probe_timeout_ms = millis() + SEC_TO_MS(900UL);
271 271
       while (thermalManager.degProbe() < target_probe) {
272 272
         if (report_temps(next_temp_report, probe_timeout_ms)) {
273 273
           SERIAL_ECHOLNPGM("!Probe heating timed out.");

+ 1
- 1
Marlin/src/gcode/sd/M1001.cpp Vedi File

@@ -92,7 +92,7 @@ void GcodeSuite::M1001() {
92 92
       printerEventLEDs.onPrintCompleted();
93 93
       TERN_(EXTENSIBLE_UI, ExtUI::onUserConfirmRequired_P(GET_TEXT(MSG_PRINT_DONE)));
94 94
       TERN_(HOST_PROMPT_SUPPORT, host_prompt_do(PROMPT_USER_CONTINUE, GET_TEXT(MSG_PRINT_DONE), CONTINUE_STR));
95
-      wait_for_user_response(1000UL * TERN(HAS_LCD_MENU, PE_LEDS_COMPLETED_TIME, 30));
95
+      wait_for_user_response(SEC_TO_MS(TERN(HAS_LCD_MENU, PE_LEDS_COMPLETED_TIME, 30)));
96 96
       printerEventLEDs.onResumeAfterWait();
97 97
     }
98 98
   #endif

+ 6
- 4
Marlin/src/gcode/sd/M27.cpp Vedi File

@@ -36,15 +36,17 @@ void GcodeSuite::M27() {
36 36
   if (parser.seen('C')) {
37 37
     SERIAL_ECHOPGM("Current file: ");
38 38
     card.printFilename();
39
+    return;
39 40
   }
40 41
 
41 42
   #if ENABLED(AUTO_REPORT_SD_STATUS)
42
-    else if (parser.seenval('S'))
43
-      card.set_auto_report_interval(parser.value_byte());
43
+    if (parser.seenval('S')) {
44
+      card.auto_reporter.set_interval(parser.value_byte());
45
+      return;
46
+    }
44 47
   #endif
45 48
 
46
-  else
47
-    card.report_status();
49
+  card.report_status();
48 50
 }
49 51
 
50 52
 #endif // SDSUPPORT

+ 1
- 1
Marlin/src/gcode/temp/M155.cpp Vedi File

@@ -33,7 +33,7 @@
33 33
 void GcodeSuite::M155() {
34 34
 
35 35
   if (parser.seenval('S'))
36
-    thermalManager.set_auto_report_interval(parser.value_byte());
36
+    thermalManager.auto_reporter.set_interval(parser.value_byte());
37 37
 
38 38
 }
39 39
 

+ 1
- 1
Marlin/src/lcd/dwin/e3v2/dwin.cpp Vedi File

@@ -3553,7 +3553,7 @@ void EachMomentUpdate() {
3553 3553
     static millis_t next_remain_time_update = 0;
3554 3554
     if (Percentrecord > 1 && ELAPSED(ms, next_remain_time_update) && !HMI_flag.heat_flag) {
3555 3555
       remain_time = (elapsed.value - dwin_heat_time) / (Percentrecord * 0.01f) - (elapsed.value - dwin_heat_time);
3556
-      next_remain_time_update += 20 * 1000UL;
3556
+      next_remain_time_update += SEC_TO_MS(20);
3557 3557
       Draw_Print_ProgressRemain();
3558 3558
     }
3559 3559
   }

+ 2
- 2
Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/compat.h Vedi File

@@ -43,8 +43,8 @@
43 43
   #define min(a,b) ((a)<(b)?(a):(b))
44 44
 #else
45 45
   namespace UI {
46
-    static inline uint32_t safe_millis() {return millis();};
47
-    static inline void     yield()       {};
46
+    static inline uint32_t safe_millis() { return millis(); }
47
+    static inline void     yield()       {}
48 48
   };
49 49
 #endif
50 50
 

+ 3
- 3
Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp Vedi File

@@ -889,7 +889,7 @@ void GUI_RefreshPage() {
889 889
               lv_draw_wifi_tips();
890 890
 
891 891
             }
892
-            if (tips_disp.timer_count >= 30 * 1000) {
892
+            if (tips_disp.timer_count >= SEC_TO_MS(30)) {
893 893
               tips_disp.timer = TIPS_TIMER_STOP;
894 894
               tips_disp.timer_count = 0;
895 895
               lv_clear_wifi_tips();
@@ -898,7 +898,7 @@ void GUI_RefreshPage() {
898 898
             }
899 899
             break;
900 900
           case TIPS_TYPE_TAILED_JOIN:
901
-            if (tips_disp.timer_count >= 3 * 1000) {
901
+            if (tips_disp.timer_count >= SEC_TO_MS(3)) {
902 902
               tips_disp.timer = TIPS_TIMER_STOP;
903 903
               tips_disp.timer_count = 0;
904 904
 
@@ -908,7 +908,7 @@ void GUI_RefreshPage() {
908 908
             }
909 909
             break;
910 910
           case TIPS_TYPE_WIFI_CONECTED:
911
-            if (tips_disp.timer_count >= 3 * 1000) {
911
+            if (tips_disp.timer_count >= SEC_TO_MS(3)) {
912 912
               tips_disp.timer = TIPS_TIMER_STOP;
913 913
               tips_disp.timer_count = 0;
914 914
 

+ 4
- 4
Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp Vedi File

@@ -89,8 +89,8 @@ void SysTick_Callback() {
89 89
   #endif
90 90
   if (uiCfg.filament_loading_time_flg) {
91 91
     uiCfg.filament_loading_time_cnt++;
92
-    uiCfg.filament_rate = (uint32_t)(((uiCfg.filament_loading_time_cnt / (uiCfg.filament_loading_time * 1000.0)) * 100.0) + 0.5);
93
-    if (uiCfg.filament_loading_time_cnt >= (uiCfg.filament_loading_time * 1000)) {
92
+    uiCfg.filament_rate = uint32_t(100.0f * uiCfg.filament_loading_time_cnt / SEC_TO_MS(uiCfg.filament_loading_time) + 0.5f);
93
+    if (uiCfg.filament_loading_time_cnt >= SEC_TO_MS(uiCfg.filament_loading_time)) {
94 94
       uiCfg.filament_loading_time_cnt  = 0;
95 95
       uiCfg.filament_loading_time_flg  = false;
96 96
       uiCfg.filament_loading_completed = true;
@@ -98,8 +98,8 @@ void SysTick_Callback() {
98 98
   }
99 99
   if (uiCfg.filament_unloading_time_flg) {
100 100
     uiCfg.filament_unloading_time_cnt++;
101
-    uiCfg.filament_rate = (uint32_t)(((uiCfg.filament_unloading_time_cnt / (uiCfg.filament_unloading_time * 1000.0)) * 100.0) + 0.5);
102
-    if (uiCfg.filament_unloading_time_cnt >= (uiCfg.filament_unloading_time * 1000)) {
101
+    uiCfg.filament_rate = uint32_t(100.0f * uiCfg.filament_unloading_time_cnt / SEC_TO_MS(uiCfg.filament_unloading_time) + 0.5f);
102
+    if (uiCfg.filament_unloading_time_cnt >= SEC_TO_MS(uiCfg.filament_unloading_time)) {
103 103
       uiCfg.filament_unloading_time_cnt  = 0;
104 104
       uiCfg.filament_unloading_time_flg  = false;
105 105
       uiCfg.filament_unloading_completed = true;

+ 3
- 3
Marlin/src/lcd/extui/ui_api.cpp Vedi File

@@ -123,7 +123,7 @@ namespace ExtUI {
123 123
       // Machine was killed, reinit SysTick so we are able to compute time without ISRs
124 124
       if (currTimeHI == 0) {
125 125
         // Get the last time the Arduino time computed (from CMSIS) and convert it to SysTick
126
-        currTimeHI = (uint32_t)((GetTickCount() * (uint64_t)(F_CPU / 8000)) >> 24);
126
+        currTimeHI = uint32_t((GetTickCount() * uint64_t(F_CPU / 8000)) >> 24);
127 127
 
128 128
         // Reinit the SysTick timer to maximize its period
129 129
         SysTick->LOAD  = SysTick_LOAD_RELOAD_Msk;                    // get the full range for the systick timer
@@ -148,9 +148,9 @@ namespace ExtUI {
148 148
     }
149 149
   #endif // __SAM3X8E__
150 150
 
151
-  void delay_us(unsigned long us) { DELAY_US(us); }
151
+  void delay_us(uint32_t us) { DELAY_US(us); }
152 152
 
153
-  void delay_ms(unsigned long ms) {
153
+  void delay_ms(uint32_t ms) {
154 154
     if (flags.printer_killed)
155 155
       DELAY_US(ms * 1000);
156 156
     else

+ 3
- 3
Marlin/src/lcd/extui/ui_api.h Vedi File

@@ -155,7 +155,7 @@ namespace ExtUI {
155 155
       void onMeshUpdate(const int8_t xpos, const int8_t ypos, const float zval);
156 156
       inline void onMeshUpdate(const xy_int8_t &pos, const float zval) { onMeshUpdate(pos.x, pos.y, zval); }
157 157
 
158
-      typedef enum : unsigned char {
158
+      typedef enum : uint8_t {
159 159
         MESH_START,    // Prior to start of probe
160 160
         MESH_FINISH,   // Following probe of all points
161 161
         PROBE_START,   // Beginning probe of grid location
@@ -302,8 +302,8 @@ namespace ExtUI {
302 302
     FORCE_INLINE uint32_t safe_millis() { return millis(); } // TODO: Implement for AVR
303 303
   #endif
304 304
 
305
-  void delay_us(unsigned long us);
306
-  void delay_ms(unsigned long ms);
305
+  void delay_us(uint32_t us);
306
+  void delay_ms(uint32_t ms);
307 307
   void yield();
308 308
 
309 309
   /**

+ 49
- 0
Marlin/src/libs/autoreport.h Vedi File

@@ -0,0 +1,49 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#include "../inc/MarlinConfig.h"
25
+
26
+template<serial_index_t AR_PORT_INDEX>
27
+class AutoReporter {
28
+public:
29
+  millis_t next_report_ms;
30
+  uint8_t report_interval;
31
+
32
+  // Override this method
33
+  inline void auto_report() { }
34
+
35
+  inline void set_interval(uint8_t seconds, const uint8_t limit=60) {
36
+    report_interval = _MIN(seconds, limit);
37
+    next_report_ms = millis() + SEC_TO_MS(seconds);
38
+  }
39
+
40
+  inline void tick() {
41
+    if (!report_interval) return;
42
+    const millis_t ms = millis();
43
+    if (ELAPSED(ms, next_report_ms)) {
44
+      next_report_ms = ms + SEC_TO_MS(report_interval);
45
+      PORT_REDIRECT(AR_PORT_INDEX);
46
+      auto_report();
47
+    }
48
+  }
49
+};

+ 10
- 18
Marlin/src/module/temperature.cpp Vedi File

@@ -1276,7 +1276,7 @@ void Temperature::manage_heater() {
1276 1276
             // temperature didn't drop at least MIN_COOLING_SLOPE_DEG_CHAMBER_VENT
1277 1277
             if (next_cool_check_ms_2 == 0 || ELAPSED(ms, next_cool_check_ms_2)) {
1278 1278
               if (old_temp - temp_chamber.celsius < float(MIN_COOLING_SLOPE_DEG_CHAMBER_VENT)) flag_chamber_excess_heat = true; //the bed is heating the chamber too much
1279
-              next_cool_check_ms_2 = ms + 1000UL * MIN_COOLING_SLOPE_TIME_CHAMBER_VENT;
1279
+              next_cool_check_ms_2 = ms + SEC_TO_MS(MIN_COOLING_SLOPE_TIME_CHAMBER_VENT);
1280 1280
               old_temp = temp_chamber.celsius;
1281 1281
             }
1282 1282
           }
@@ -3123,20 +3123,12 @@ void Temperature::tick() {
3123 3123
   }
3124 3124
 
3125 3125
   #if ENABLED(AUTO_REPORT_TEMPERATURES)
3126
-
3127
-    uint8_t Temperature::auto_report_temp_interval;
3128
-    millis_t Temperature::next_temp_report_ms;
3129
-
3130
-    void Temperature::auto_report_temperatures() {
3131
-      if (auto_report_temp_interval && ELAPSED(millis(), next_temp_report_ms)) {
3132
-        next_temp_report_ms = millis() + 1000UL * auto_report_temp_interval;
3133
-        PORT_REDIRECT(SERIAL_ALL);
3134
-        print_heater_states(active_extruder);
3135
-        SERIAL_EOL();
3136
-      }
3126
+    Temperature::AutoReportTemp Temperature::auto_reporter;
3127
+    void Temperature::AutoReportTemp::auto_report() {
3128
+      print_heater_states(active_extruder);
3129
+      SERIAL_EOL();
3137 3130
     }
3138
-
3139
-  #endif // AUTO_REPORT_TEMPERATURES
3131
+  #endif
3140 3132
 
3141 3133
   #if HAS_HOTEND && HAS_DISPLAY
3142 3134
     void Temperature::set_heating_message(const uint8_t e) {
@@ -3252,7 +3244,7 @@ void Temperature::tick() {
3252 3244
           // if the temperature did not drop at least MIN_COOLING_SLOPE_DEG
3253 3245
           if (!next_cool_check_ms || ELAPSED(now, next_cool_check_ms)) {
3254 3246
             if (old_temp - temp < float(MIN_COOLING_SLOPE_DEG)) break;
3255
-            next_cool_check_ms = now + 1000UL * MIN_COOLING_SLOPE_TIME;
3247
+            next_cool_check_ms = now + SEC_TO_MS(MIN_COOLING_SLOPE_TIME);
3256 3248
             old_temp = temp;
3257 3249
           }
3258 3250
         }
@@ -3377,7 +3369,7 @@ void Temperature::tick() {
3377 3369
           // if the temperature did not drop at least MIN_COOLING_SLOPE_DEG_BED
3378 3370
           if (!next_cool_check_ms || ELAPSED(now, next_cool_check_ms)) {
3379 3371
             if (old_temp - temp < float(MIN_COOLING_SLOPE_DEG_BED)) break;
3380
-            next_cool_check_ms = now + 1000UL * MIN_COOLING_SLOPE_TIME_BED;
3372
+            next_cool_check_ms = now + SEC_TO_MS(MIN_COOLING_SLOPE_TIME_BED);
3381 3373
             old_temp = temp;
3382 3374
           }
3383 3375
         }
@@ -3461,7 +3453,7 @@ void Temperature::tick() {
3461 3453
             SERIAL_ECHOLNPGM("Timed out waiting for probe temperature.");
3462 3454
             break;
3463 3455
           }
3464
-          next_delta_check_ms = now + 1000UL * MIN_DELTA_SLOPE_TIME_PROBE;
3456
+          next_delta_check_ms = now + SEC_TO_MS(MIN_DELTA_SLOPE_TIME_PROBE);
3465 3457
           old_temp = temp;
3466 3458
         }
3467 3459
 
@@ -3566,7 +3558,7 @@ void Temperature::tick() {
3566 3558
           // if the temperature did not drop at least MIN_COOLING_SLOPE_DEG_CHAMBER
3567 3559
           if (!next_cool_check_ms || ELAPSED(now, next_cool_check_ms)) {
3568 3560
             if (old_temp - temp < float(MIN_COOLING_SLOPE_DEG_CHAMBER)) break;
3569
-            next_cool_check_ms = now + 1000UL * MIN_COOLING_SLOPE_TIME_CHAMBER;
3561
+            next_cool_check_ms = now + SEC_TO_MS(MIN_COOLING_SLOPE_TIME_CHAMBER);
3570 3562
             old_temp = temp;
3571 3563
           }
3572 3564
         }

+ 6
- 8
Marlin/src/module/temperature.h Vedi File

@@ -33,6 +33,10 @@
33 33
   #include "../feature/power.h"
34 34
 #endif
35 35
 
36
+#if ENABLED(AUTO_REPORT_TEMPERATURES)
37
+  #include "../libs/autoreport.h"
38
+#endif
39
+
36 40
 #ifndef SOFT_PWM_SCALE
37 41
   #define SOFT_PWM_SCALE 0
38 42
 #endif
@@ -794,14 +798,8 @@ class Temperature {
794 798
         #endif
795 799
       );
796 800
       #if ENABLED(AUTO_REPORT_TEMPERATURES)
797
-        static uint8_t auto_report_temp_interval;
798
-        static millis_t next_temp_report_ms;
799
-        static void auto_report_temperatures();
800
-        static inline void set_auto_report_interval(uint8_t v) {
801
-          NOMORE(v, 60);
802
-          auto_report_temp_interval = v;
803
-          next_temp_report_ms = millis() + 1000UL * v;
804
-        }
801
+        class AutoReportTemp : public AutoReporter<SERIAL_ALL> { void auto_report(); };
802
+        static AutoReportTemp auto_reporter;
805 803
       #endif
806 804
     #endif
807 805
 

+ 4
- 15
Marlin/src/sd/cardreader.cpp Vedi File

@@ -1226,21 +1226,10 @@ void CardReader::fileHasFinished() {
1226 1226
 }
1227 1227
 
1228 1228
 #if ENABLED(AUTO_REPORT_SD_STATUS)
1229
-  uint8_t CardReader::auto_report_sd_interval = 0;
1230
-  millis_t CardReader::next_sd_report_ms;
1231
-  #if HAS_MULTI_SERIAL
1232
-    serial_index_t CardReader::auto_report_port;
1233
-  #endif
1234
-
1235
-  void CardReader::auto_report_sd_status() {
1236
-    millis_t current_ms = millis();
1237
-    if (auto_report_sd_interval && ELAPSED(current_ms, next_sd_report_ms)) {
1238
-      next_sd_report_ms = current_ms + 1000UL * auto_report_sd_interval;
1239
-      PORT_REDIRECT(auto_report_port);
1240
-      report_status();
1241
-    }
1242
-  }
1243
-#endif // AUTO_REPORT_SD_STATUS
1229
+  TERN_(HAS_MULTI_SERIAL, serial_index_t CardReader::auto_report_port);
1230
+  CardReader::AutoReportSD CardReader::auto_reporter;
1231
+  void CardReader::AutoReportSD::auto_report() { report_status(); }
1232
+#endif
1244 1233
 
1245 1234
 #if ENABLED(POWER_LOSS_RECOVERY)
1246 1235
 

+ 14
- 18
Marlin/src/sd/cardreader.h Vedi File

@@ -59,6 +59,10 @@ typedef struct {
59 59
     ;
60 60
 } card_flags_t;
61 61
 
62
+#if ENABLED(AUTO_REPORT_SD_STATUS)
63
+  #include "../libs/autoreport.h"
64
+#endif
65
+
62 66
 class CardReader {
63 67
 public:
64 68
   static card_flags_t flag;                         // Flags (above)
@@ -172,13 +176,16 @@ public:
172 176
   static Sd2Card& getSd2Card() { return sd2card; }
173 177
 
174 178
   #if ENABLED(AUTO_REPORT_SD_STATUS)
175
-    static void auto_report_sd_status();
176
-    static inline void set_auto_report_interval(uint8_t v) {
177
-      TERN_(HAS_MULTI_SERIAL, auto_report_port = multiSerial.portMask);
178
-      NOMORE(v, 60);
179
-      auto_report_sd_interval = v;
180
-      next_sd_report_ms = millis() + 1000UL * v;
181
-    }
179
+    //
180
+    // SD Auto Reporting
181
+    //
182
+    #if HAS_MULTI_SERIAL
183
+      static serial_index_t auto_report_port;
184
+    #else
185
+      static constexpr serial_index_t auto_report_port = 0;
186
+    #endif
187
+    class AutoReportSD : public AutoReporter<auto_report_port> { void auto_report(); };
188
+    static AutoReportSD auto_reporter;
182 189
   #endif
183 190
 
184 191
 private:
@@ -261,17 +268,6 @@ private:
261 268
   #endif
262 269
 
263 270
   //
264
-  // SD Auto Reporting
265
-  //
266
-  #if ENABLED(AUTO_REPORT_SD_STATUS)
267
-    static uint8_t auto_report_sd_interval;
268
-    static millis_t next_sd_report_ms;
269
-    #if HAS_MULTI_SERIAL
270
-      static serial_index_t auto_report_port;
271
-    #endif
272
-  #endif
273
-
274
-  //
275 271
   // Directory items
276 272
   //
277 273
   static bool is_dir_or_gcode(const dir_t &p);

Loading…
Annulla
Salva