Skip to content

Commit

Permalink
Fix AutoReporter implementation (MarlinFirmware#20959)
Browse files Browse the repository at this point in the history
  • Loading branch information
X-Ryl669 authored and zillarob committed Feb 25, 2021
1 parent 6ef27ea commit faff011
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 22 deletions.
16 changes: 8 additions & 8 deletions Marlin/src/libs/autoreport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -42,8 +42,8 @@ class AutoReporter {
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();
}
}
};
4 changes: 2 additions & 2 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3105,8 +3105,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();
}
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/module/temperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 1 addition & 3 deletions Marlin/src/sd/cardreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1206,9 +1206,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)
Expand Down
9 changes: 2 additions & 7 deletions Marlin/src/sd/cardreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,8 @@ class CardReader {
//
// 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:
Expand Down

0 comments on commit faff011

Please sign in to comment.