Browse Source

AutoReport class (Temperature, Cardreader) (#20913)

Scott Lahteine 4 years ago
parent
commit
9d0e64a725
No account linked to committer's email address

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

687
   // Auto-report Temperatures / SD Status
687
   // Auto-report Temperatures / SD Status
688
   #if HAS_AUTO_REPORTING
688
   #if HAS_AUTO_REPORTING
689
     if (!gcode.autoreport_paused) {
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
   #endif
693
   #endif
694
 
694
 

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

267
 
267
 
268
       say_waiting_for_probe_heating();
268
       say_waiting_for_probe_heating();
269
       SERIAL_ECHOLNPAIR(" Bed:", target_bed, " Probe:", target_probe);
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
       while (thermalManager.degProbe() < target_probe) {
271
       while (thermalManager.degProbe() < target_probe) {
272
         if (report_temps(next_temp_report, probe_timeout_ms)) {
272
         if (report_temps(next_temp_report, probe_timeout_ms)) {
273
           SERIAL_ECHOLNPGM("!Probe heating timed out.");
273
           SERIAL_ECHOLNPGM("!Probe heating timed out.");

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

92
       printerEventLEDs.onPrintCompleted();
92
       printerEventLEDs.onPrintCompleted();
93
       TERN_(EXTENSIBLE_UI, ExtUI::onUserConfirmRequired_P(GET_TEXT(MSG_PRINT_DONE)));
93
       TERN_(EXTENSIBLE_UI, ExtUI::onUserConfirmRequired_P(GET_TEXT(MSG_PRINT_DONE)));
94
       TERN_(HOST_PROMPT_SUPPORT, host_prompt_do(PROMPT_USER_CONTINUE, GET_TEXT(MSG_PRINT_DONE), CONTINUE_STR));
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
       printerEventLEDs.onResumeAfterWait();
96
       printerEventLEDs.onResumeAfterWait();
97
     }
97
     }
98
   #endif
98
   #endif

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

36
   if (parser.seen('C')) {
36
   if (parser.seen('C')) {
37
     SERIAL_ECHOPGM("Current file: ");
37
     SERIAL_ECHOPGM("Current file: ");
38
     card.printFilename();
38
     card.printFilename();
39
+    return;
39
   }
40
   }
40
 
41
 
41
   #if ENABLED(AUTO_REPORT_SD_STATUS)
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
   #endif
47
   #endif
45
 
48
 
46
-  else
47
-    card.report_status();
49
+  card.report_status();
48
 }
50
 }
49
 
51
 
50
 #endif // SDSUPPORT
52
 #endif // SDSUPPORT

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

33
 void GcodeSuite::M155() {
33
 void GcodeSuite::M155() {
34
 
34
 
35
   if (parser.seenval('S'))
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 View File

3553
     static millis_t next_remain_time_update = 0;
3553
     static millis_t next_remain_time_update = 0;
3554
     if (Percentrecord > 1 && ELAPSED(ms, next_remain_time_update) && !HMI_flag.heat_flag) {
3554
     if (Percentrecord > 1 && ELAPSED(ms, next_remain_time_update) && !HMI_flag.heat_flag) {
3555
       remain_time = (elapsed.value - dwin_heat_time) / (Percentrecord * 0.01f) - (elapsed.value - dwin_heat_time);
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
       Draw_Print_ProgressRemain();
3557
       Draw_Print_ProgressRemain();
3558
     }
3558
     }
3559
   }
3559
   }

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

43
   #define min(a,b) ((a)<(b)?(a):(b))
43
   #define min(a,b) ((a)<(b)?(a):(b))
44
 #else
44
 #else
45
   namespace UI {
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
 #endif
49
 #endif
50
 
50
 

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

889
               lv_draw_wifi_tips();
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
               tips_disp.timer = TIPS_TIMER_STOP;
893
               tips_disp.timer = TIPS_TIMER_STOP;
894
               tips_disp.timer_count = 0;
894
               tips_disp.timer_count = 0;
895
               lv_clear_wifi_tips();
895
               lv_clear_wifi_tips();
898
             }
898
             }
899
             break;
899
             break;
900
           case TIPS_TYPE_TAILED_JOIN:
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
               tips_disp.timer = TIPS_TIMER_STOP;
902
               tips_disp.timer = TIPS_TIMER_STOP;
903
               tips_disp.timer_count = 0;
903
               tips_disp.timer_count = 0;
904
 
904
 
908
             }
908
             }
909
             break;
909
             break;
910
           case TIPS_TYPE_WIFI_CONECTED:
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
               tips_disp.timer = TIPS_TIMER_STOP;
912
               tips_disp.timer = TIPS_TIMER_STOP;
913
               tips_disp.timer_count = 0;
913
               tips_disp.timer_count = 0;
914
 
914
 

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

89
   #endif
89
   #endif
90
   if (uiCfg.filament_loading_time_flg) {
90
   if (uiCfg.filament_loading_time_flg) {
91
     uiCfg.filament_loading_time_cnt++;
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
       uiCfg.filament_loading_time_cnt  = 0;
94
       uiCfg.filament_loading_time_cnt  = 0;
95
       uiCfg.filament_loading_time_flg  = false;
95
       uiCfg.filament_loading_time_flg  = false;
96
       uiCfg.filament_loading_completed = true;
96
       uiCfg.filament_loading_completed = true;
98
   }
98
   }
99
   if (uiCfg.filament_unloading_time_flg) {
99
   if (uiCfg.filament_unloading_time_flg) {
100
     uiCfg.filament_unloading_time_cnt++;
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
       uiCfg.filament_unloading_time_cnt  = 0;
103
       uiCfg.filament_unloading_time_cnt  = 0;
104
       uiCfg.filament_unloading_time_flg  = false;
104
       uiCfg.filament_unloading_time_flg  = false;
105
       uiCfg.filament_unloading_completed = true;
105
       uiCfg.filament_unloading_completed = true;

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

123
       // Machine was killed, reinit SysTick so we are able to compute time without ISRs
123
       // Machine was killed, reinit SysTick so we are able to compute time without ISRs
124
       if (currTimeHI == 0) {
124
       if (currTimeHI == 0) {
125
         // Get the last time the Arduino time computed (from CMSIS) and convert it to SysTick
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
         // Reinit the SysTick timer to maximize its period
128
         // Reinit the SysTick timer to maximize its period
129
         SysTick->LOAD  = SysTick_LOAD_RELOAD_Msk;                    // get the full range for the systick timer
129
         SysTick->LOAD  = SysTick_LOAD_RELOAD_Msk;                    // get the full range for the systick timer
148
     }
148
     }
149
   #endif // __SAM3X8E__
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
     if (flags.printer_killed)
154
     if (flags.printer_killed)
155
       DELAY_US(ms * 1000);
155
       DELAY_US(ms * 1000);
156
     else
156
     else

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

155
       void onMeshUpdate(const int8_t xpos, const int8_t ypos, const float zval);
155
       void onMeshUpdate(const int8_t xpos, const int8_t ypos, const float zval);
156
       inline void onMeshUpdate(const xy_int8_t &pos, const float zval) { onMeshUpdate(pos.x, pos.y, zval); }
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
         MESH_START,    // Prior to start of probe
159
         MESH_START,    // Prior to start of probe
160
         MESH_FINISH,   // Following probe of all points
160
         MESH_FINISH,   // Following probe of all points
161
         PROBE_START,   // Beginning probe of grid location
161
         PROBE_START,   // Beginning probe of grid location
302
     FORCE_INLINE uint32_t safe_millis() { return millis(); } // TODO: Implement for AVR
302
     FORCE_INLINE uint32_t safe_millis() { return millis(); } // TODO: Implement for AVR
303
   #endif
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
   void yield();
307
   void yield();
308
 
308
 
309
   /**
309
   /**

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

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 View File

1276
             // temperature didn't drop at least MIN_COOLING_SLOPE_DEG_CHAMBER_VENT
1276
             // temperature didn't drop at least MIN_COOLING_SLOPE_DEG_CHAMBER_VENT
1277
             if (next_cool_check_ms_2 == 0 || ELAPSED(ms, next_cool_check_ms_2)) {
1277
             if (next_cool_check_ms_2 == 0 || ELAPSED(ms, next_cool_check_ms_2)) {
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
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
               old_temp = temp_chamber.celsius;
1280
               old_temp = temp_chamber.celsius;
1281
             }
1281
             }
1282
           }
1282
           }
3123
   }
3123
   }
3124
 
3124
 
3125
   #if ENABLED(AUTO_REPORT_TEMPERATURES)
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
   #if HAS_HOTEND && HAS_DISPLAY
3133
   #if HAS_HOTEND && HAS_DISPLAY
3142
     void Temperature::set_heating_message(const uint8_t e) {
3134
     void Temperature::set_heating_message(const uint8_t e) {
3252
           // if the temperature did not drop at least MIN_COOLING_SLOPE_DEG
3244
           // if the temperature did not drop at least MIN_COOLING_SLOPE_DEG
3253
           if (!next_cool_check_ms || ELAPSED(now, next_cool_check_ms)) {
3245
           if (!next_cool_check_ms || ELAPSED(now, next_cool_check_ms)) {
3254
             if (old_temp - temp < float(MIN_COOLING_SLOPE_DEG)) break;
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
             old_temp = temp;
3248
             old_temp = temp;
3257
           }
3249
           }
3258
         }
3250
         }
3377
           // if the temperature did not drop at least MIN_COOLING_SLOPE_DEG_BED
3369
           // if the temperature did not drop at least MIN_COOLING_SLOPE_DEG_BED
3378
           if (!next_cool_check_ms || ELAPSED(now, next_cool_check_ms)) {
3370
           if (!next_cool_check_ms || ELAPSED(now, next_cool_check_ms)) {
3379
             if (old_temp - temp < float(MIN_COOLING_SLOPE_DEG_BED)) break;
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
             old_temp = temp;
3373
             old_temp = temp;
3382
           }
3374
           }
3383
         }
3375
         }
3461
             SERIAL_ECHOLNPGM("Timed out waiting for probe temperature.");
3453
             SERIAL_ECHOLNPGM("Timed out waiting for probe temperature.");
3462
             break;
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
           old_temp = temp;
3457
           old_temp = temp;
3466
         }
3458
         }
3467
 
3459
 
3566
           // if the temperature did not drop at least MIN_COOLING_SLOPE_DEG_CHAMBER
3558
           // if the temperature did not drop at least MIN_COOLING_SLOPE_DEG_CHAMBER
3567
           if (!next_cool_check_ms || ELAPSED(now, next_cool_check_ms)) {
3559
           if (!next_cool_check_ms || ELAPSED(now, next_cool_check_ms)) {
3568
             if (old_temp - temp < float(MIN_COOLING_SLOPE_DEG_CHAMBER)) break;
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
             old_temp = temp;
3562
             old_temp = temp;
3571
           }
3563
           }
3572
         }
3564
         }

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

33
   #include "../feature/power.h"
33
   #include "../feature/power.h"
34
 #endif
34
 #endif
35
 
35
 
36
+#if ENABLED(AUTO_REPORT_TEMPERATURES)
37
+  #include "../libs/autoreport.h"
38
+#endif
39
+
36
 #ifndef SOFT_PWM_SCALE
40
 #ifndef SOFT_PWM_SCALE
37
   #define SOFT_PWM_SCALE 0
41
   #define SOFT_PWM_SCALE 0
38
 #endif
42
 #endif
794
         #endif
798
         #endif
795
       );
799
       );
796
       #if ENABLED(AUTO_REPORT_TEMPERATURES)
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
       #endif
803
       #endif
806
     #endif
804
     #endif
807
 
805
 

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

1226
 }
1226
 }
1227
 
1227
 
1228
 #if ENABLED(AUTO_REPORT_SD_STATUS)
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
 #if ENABLED(POWER_LOSS_RECOVERY)
1234
 #if ENABLED(POWER_LOSS_RECOVERY)
1246
 
1235
 

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

59
     ;
59
     ;
60
 } card_flags_t;
60
 } card_flags_t;
61
 
61
 
62
+#if ENABLED(AUTO_REPORT_SD_STATUS)
63
+  #include "../libs/autoreport.h"
64
+#endif
65
+
62
 class CardReader {
66
 class CardReader {
63
 public:
67
 public:
64
   static card_flags_t flag;                         // Flags (above)
68
   static card_flags_t flag;                         // Flags (above)
172
   static Sd2Card& getSd2Card() { return sd2card; }
176
   static Sd2Card& getSd2Card() { return sd2card; }
173
 
177
 
174
   #if ENABLED(AUTO_REPORT_SD_STATUS)
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
   #endif
189
   #endif
183
 
190
 
184
 private:
191
 private:
261
   #endif
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
   // Directory items
271
   // Directory items
276
   //
272
   //
277
   static bool is_dir_or_gcode(const dir_t &p);
273
   static bool is_dir_or_gcode(const dir_t &p);

Loading…
Cancel
Save