Skip to content
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

Merged

Conversation

thinkyhead
Copy link
Member

  • Auto-report is a common paradigm in Marlin, so encapsulate this behavior as a simple template class.
  • Also apply macros like SEC_TO_MS where contextually-appropriate.

@thinkyhead thinkyhead force-pushed the bf2_time_and_autoreport_PR branch from 58feb92 to 3909cea Compare January 29, 2021 01:41
@thinkyhead thinkyhead merged commit 9d0e64a into MarlinFirmware:bugfix-2.0.x Jan 29, 2021
@thinkyhead thinkyhead deleted the bf2_time_and_autoreport_PR branch January 29, 2021 02:40
@lightmaster
Copy link

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.

mluckau added a commit to mluckau/MarlinTronxyX5SA-Pro that referenced this pull request Jan 29, 2021
soularus added a commit to soularus/Marlin that referenced this pull request Jan 30, 2021
// SD Auto Reporting
//
#if HAS_MULTI_SERIAL
static serial_index_t auto_report_port;
Copy link
Contributor

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);
Copy link
Contributor

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
Copy link
Contributor

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(); };
Copy link
Contributor

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.

Copy link
Contributor

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;

@X-Ryl669
Copy link
Contributor

X-Ryl669 commented Jan 30, 2021

@lightmaster : Can you replace the line 33 from autoreport.h from:

 inline void auto_report() { }

to

virtual void auto_report() {}

It should fix it.

@benlye
Copy link
Contributor

benlye commented Jan 30, 2021

@lightmaster : Can you replace the line 33 from autoreport.h from:

 inline void auto_report() { }

to

virtual void auto_report() {}

It should fix it.

Confirmed that this change fixes temperature auto-reporting for me. (BTT SKR 1.4 Turbo, if it matters.)

@Mezabaru
Copy link

@lightmaster : Can you replace the line 33 from autoreport.h from:

 inline void auto_report() { }

to

virtual void auto_report() {}

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
Copy link

Guilouz commented Jan 31, 2021

When I enable #define AUTO_REPORT_SD_STATUS, I can't compile, error :

Capture d’écran 2021-01-31 à 03 33 33

When disable it it's ok

@X-Ryl669
Copy link
Contributor

@Guilouz Yes, it's known. It'll be fixed soon.

@X-Ryl669
Copy link
Contributor

@Guilouz Can you try #20959 (it should fix your build issue) and report ?

@Guilouz
Copy link

Guilouz commented Jan 31, 2021

@Guilouz Can you try #20959 (it should fix your build issue) and report ?

Confirmed, it's woking !

@X-Ryl669
Copy link
Contributor

Thanks!

@Guilouz
Copy link

Guilouz commented Feb 1, 2021

@X-Ryl669

But it's failed when I try to disable #define SDSUPPORT

Capture d’écran 2021-02-01 à 01 00 33

Working with stable build 2.7.0.2 not with bugfix.

@X-Ryl669
Copy link
Contributor

X-Ryl669 commented Feb 1, 2021

Seems like it related #20846, that's another bug. Can you open a new issue ?

@Guilouz
Copy link

Guilouz commented Feb 1, 2021

#20846

Yes I can.

mluckau added a commit to mluckau/MarlinTronxyX5SA-Pro that referenced this pull request Feb 1, 2021
Jyers pushed a commit to Jyers/Marlin that referenced this pull request Feb 3, 2021
soularus added a commit to soularus/Marlin that referenced this pull request Feb 4, 2021
kpishere pushed a commit to kpishere/Marlin that referenced this pull request Feb 19, 2021
zillarob pushed a commit to zillarob/Marlin that referenced this pull request Feb 25, 2021
W4tel-BiDi pushed a commit to W4tel-BiDi/Marlin that referenced this pull request Apr 5, 2021
thinkyhead added a commit to thinkyhead/Marlin that referenced this pull request Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants