Fix AutoReporter implementation (#20959)

This commit is contained in:
X-Ryl669
2021-02-01 01:11:50 +01:00
committed by GitHub
parent 27366197f3
commit 07b4cc145b
7 changed files with 19 additions and 25 deletions

View File

@ -23,14 +23,14 @@
#include "../inc/MarlinConfig.h"
template<serial_index_t AR_PORT_INDEX>
class AutoReporter {
public:
template <typename Helper>
struct AutoReporter {
millis_t next_report_ms;
uint8_t report_interval;
// Override this method
inline void auto_report() { }
#if HAS_MULTI_SERIAL
serial_index_t report_port_mask;
AutoReporter() : report_port_mask(SERIAL_ALL) {}
#endif
inline void set_interval(uint8_t seconds, const uint8_t limit=60) {
report_interval = _MIN(seconds, limit);
@ -42,8 +42,8 @@ public:
const millis_t ms = millis();
if (ELAPSED(ms, next_report_ms)) {
next_report_ms = ms + SEC_TO_MS(report_interval);
PORT_REDIRECT(AR_PORT_INDEX);
auto_report();
TERN_(HAS_MULTI_SERIAL, PORT_REDIRECT(report_port_mask));
Helper::report();
}
}
};

View File

@ -3123,8 +3123,8 @@ void Temperature::tick() {
}
#if ENABLED(AUTO_REPORT_TEMPERATURES)
Temperature::AutoReportTemp Temperature::auto_reporter;
void Temperature::AutoReportTemp::auto_report() {
AutoReporter<Temperature::AutoReportTemp> Temperature::auto_reporter;
void Temperature::AutoReportTemp::report() {
print_heater_states(active_extruder);
SERIAL_EOL();
}

View File

@ -798,8 +798,8 @@ class Temperature {
#endif
);
#if ENABLED(AUTO_REPORT_TEMPERATURES)
class AutoReportTemp : public AutoReporter<SERIAL_ALL> { void auto_report(); };
static AutoReportTemp auto_reporter;
struct AutoReportTemp { static void report(); };
static AutoReporter<AutoReportTemp> auto_reporter;
#endif
#endif

View File

@ -1226,9 +1226,7 @@ void CardReader::fileHasFinished() {
}
#if ENABLED(AUTO_REPORT_SD_STATUS)
TERN_(HAS_MULTI_SERIAL, serial_index_t CardReader::auto_report_port);
CardReader::AutoReportSD CardReader::auto_reporter;
void CardReader::AutoReportSD::auto_report() { report_status(); }
AutoReporter<CardReader::AutoReportSD> CardReader::auto_reporter;
#endif
#if ENABLED(POWER_LOSS_RECOVERY)

View File

@ -179,13 +179,8 @@ public:
//
// SD Auto Reporting
//
#if HAS_MULTI_SERIAL
static serial_index_t auto_report_port;
#else
static constexpr serial_index_t auto_report_port = 0;
#endif
class AutoReportSD : public AutoReporter<auto_report_port> { void auto_report(); };
static AutoReportSD auto_reporter;
struct AutoReportSD { static void report() { report_status(); } };
static AutoReporter<AutoReportSD> auto_reporter;
#endif
private: