-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shared AutoReport class for Temperature, Cardreader #20913
Shared AutoReport class for Temperature, Cardreader #20913
Conversation
58feb92
to
3909cea
Compare
This one has broken Temp reporting for me. I rolled back to the commit before this one, and was able to get temps in Octoprint again. |
)" This reverts commit 9d0e64a.
)" This reverts commit 9d0e64a.
// SD Auto Reporting | ||
// | ||
#if HAS_MULTI_SERIAL | ||
static serial_index_t auto_report_port; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong as a static variable is not a constexpr so it can't be used as a template parameter.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beware, since the serial hooking code, PORT_REDIRECT expect a mask, not an index, you should use PORT_REDIRECT(SERIAL_MASK(AR_PORT_INDEX)) here instead.
There is no need for template parameter here, the mask is a runtime variable, it can be changed anytime!
static constexpr serial_index_t auto_report_port = 0; | ||
#endif | ||
class AutoReportSD : public AutoReporter<auto_report_port> { void auto_report(); }; | ||
static AutoReportSD auto_reporter; | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, there is no need for a template AutoReporter
here, just set the serial_index_t as a member of the class since it's only used for PORT_REDIRECT which is a runtime check, and you can also remove the #if HAS_MULTI_SERIAL
condition here so it'll be simpler.
auto_report_temp_interval = v; | ||
next_temp_report_ms = millis() + 1000UL * v; | ||
} | ||
class AutoReportTemp : public AutoReporter<SERIAL_ALL> { void auto_report(); }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto_report
is not virtual so this is never called when manipulating the base class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to avoid the cost of a virtual table (since the instance is known at compile time), you can use CRTP here:
template <class Child>
struct AutoReporter
{
[...]
inline void auto_report() { static_cast<Child*>(this)->report(); } // Call the child's version. Does not need to be called auto_report
[...]
};
// You need a default implementation that does not report.
struct NoAutoReport : public AutoReporter<NoAutoReport> { void report() {} };
// Then subclass like this:
struct AutoReportTemp : public AutoReporter<AutoReportTemp> { void report() { ... } };
But this means you'll have to typedef the actual class to use since the type will change on each platform:
// In some common header, select the type to use based on compile time information:
#ifdef HAS_MULTI_SERIAL
typedef AutoReportMulti AutoReport;
#else if ...
typedef NoAutoReport AutoReport;
[...]
#endif
// Ok, let's declare the reporter instance
extern AutoReport auto_reporter;
@lightmaster : Can you replace the line 33 from autoreport.h from:
to
It should fix it. |
Confirmed that this change fixes temperature auto-reporting for me. (BTT SKR 1.4 Turbo, if it matters.) |
Worked for me, ender 3 pro with skr mini E3 |
@Guilouz Yes, it's known. It'll be fixed soon. |
Thanks! |
But it's failed when I try to disable #define SDSUPPORT Working with stable build 2.7.0.2 not with bugfix. |
Seems like it related #20846, that's another bug. Can you open a new issue ? |
Yes I can. |
…mware#20913)"" This reverts commit f301646.
…mware#20913)"" This reverts commit ae0eeb2.
SEC_TO_MS
where contextually-appropriate.