-
-
Notifications
You must be signed in to change notification settings - Fork 19.7k
Shared AutoReport class for Temperature, Cardreader #20913
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /** | ||
| * Marlin 3D Printer Firmware | ||
| * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] | ||
| * | ||
| * Based on Sprinter and grbl. | ||
| * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
| #pragma once | ||
|
|
||
| #include "../inc/MarlinConfig.h" | ||
|
|
||
| template<serial_index_t AR_PORT_INDEX> | ||
| class AutoReporter { | ||
| public: | ||
| millis_t next_report_ms; | ||
| uint8_t report_interval; | ||
|
|
||
| // Override this method | ||
| inline void auto_report() { } | ||
|
|
||
| inline void set_interval(uint8_t seconds, const uint8_t limit=60) { | ||
| report_interval = _MIN(seconds, limit); | ||
| next_report_ms = millis() + SEC_TO_MS(seconds); | ||
| } | ||
|
|
||
| inline void tick() { | ||
| if (!report_interval) return; | ||
| 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(); | ||
| } | ||
| } | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,10 @@ | |
| #include "../feature/power.h" | ||
| #endif | ||
|
|
||
| #if ENABLED(AUTO_REPORT_TEMPERATURES) | ||
| #include "../libs/autoreport.h" | ||
| #endif | ||
|
|
||
| #ifndef SOFT_PWM_SCALE | ||
| #define SOFT_PWM_SCALE 0 | ||
| #endif | ||
|
|
@@ -794,14 +798,8 @@ class Temperature { | |
| #endif | ||
| ); | ||
| #if ENABLED(AUTO_REPORT_TEMPERATURES) | ||
| static uint8_t auto_report_temp_interval; | ||
| static millis_t next_temp_report_ms; | ||
| static void auto_report_temperatures(); | ||
| static inline void set_auto_report_interval(uint8_t v) { | ||
| NOMORE(v, 60); | ||
| auto_report_temp_interval = v; | ||
| next_temp_report_ms = millis() + 1000UL * v; | ||
| } | ||
| class AutoReportTemp : public AutoReporter<SERIAL_ALL> { void auto_report(); }; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: But this means you'll have to typedef the actual class to use since the type will change on each platform: |
||
| static AutoReportTemp auto_reporter; | ||
| #endif | ||
| #endif | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,6 +59,10 @@ typedef struct { | |
| ; | ||
| } card_flags_t; | ||
|
|
||
| #if ENABLED(AUTO_REPORT_SD_STATUS) | ||
| #include "../libs/autoreport.h" | ||
| #endif | ||
|
|
||
| class CardReader { | ||
| public: | ||
| static card_flags_t flag; // Flags (above) | ||
|
|
@@ -172,13 +176,16 @@ class CardReader { | |
| static Sd2Card& getSd2Card() { return sd2card; } | ||
|
|
||
| #if ENABLED(AUTO_REPORT_SD_STATUS) | ||
| static void auto_report_sd_status(); | ||
| static inline void set_auto_report_interval(uint8_t v) { | ||
| TERN_(HAS_MULTI_SERIAL, auto_report_port = multiSerial.portMask); | ||
| NOMORE(v, 60); | ||
| auto_report_sd_interval = v; | ||
| next_sd_report_ms = millis() + 1000UL * v; | ||
| } | ||
| // | ||
| // SD Auto Reporting | ||
| // | ||
| #if HAS_MULTI_SERIAL | ||
| static serial_index_t auto_report_port; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| #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; | ||
| #endif | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think, there is no need for a template |
||
|
|
||
| private: | ||
|
|
@@ -260,17 +267,6 @@ class CardReader { | |
| static char proc_filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH]; | ||
| #endif | ||
|
|
||
| // | ||
| // SD Auto Reporting | ||
| // | ||
| #if ENABLED(AUTO_REPORT_SD_STATUS) | ||
| static uint8_t auto_report_sd_interval; | ||
| static millis_t next_sd_report_ms; | ||
| #if HAS_MULTI_SERIAL | ||
| static serial_index_t auto_report_port; | ||
| #endif | ||
| #endif | ||
|
|
||
| // | ||
| // Directory items | ||
| // | ||
|
|
||
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!