Send notifications to ExtUI for M0/M1 (#13344)

- Send notifications to ExtUI for M0/M1

- wait_for_user can be non-volatile (not changed by interrupt)
  C / C++ compilers don't optimize away reads of non-volatile variables when a function call is used between accesses, because *any* variable could be changed by the function call. Since `wait_for_user` can't be changed without a function call, it should be non-volatile so the compiler can optimize away cases where it is read more than once without an intervening function call.
This commit is contained in:
Tobias Frost 2019-03-09 21:13:50 +01:00 committed by Scott Lahteine
parent 00fc43144a
commit 60e82e3929
6 changed files with 25 additions and 4 deletions

View File

@ -183,7 +183,7 @@ volatile bool wait_for_heatup = true;
// For M0/M1, this flag may be cleared (by M108) to exit the wait-for-user loop
#if HAS_RESUME_CONTINUE
volatile bool wait_for_user; // = false;
bool wait_for_user; // = false;
#endif
#if HAS_AUTO_REPORTING || ENABLED(HOST_KEEPALIVE_FEATURE)

View File

@ -333,7 +333,7 @@ inline bool IsStopped() { return !Running; }
extern volatile bool wait_for_heatup;
#if HAS_RESUME_CONTINUE
extern volatile bool wait_for_user;
extern bool wait_for_user;
#endif
#if HAS_AUTO_REPORTING || ENABLED(HOST_KEEPALIVE_FEATURE)

View File

@ -31,6 +31,10 @@
#include "../../lcd/ultralcd.h"
#endif
#if ENABLED(EXTENSIBLE_UI)
#include "../../lcd/extensible_ui/ui_api.h"
#endif
#include "../../sd/cardreader.h"
#if HAS_LEDS_OFF_FLAG
@ -74,6 +78,10 @@ void GcodeSuite::M0_M1() {
#endif
}
#elif ENABLED(EXTENSIBLE_UI)
ExtUI::onUserConfirmRequired(has_message ? args : MSG_USERWAIT); // SRAM string
#else
if (has_message) {
@ -97,6 +105,10 @@ void GcodeSuite::M0_M1() {
else
while (wait_for_user) idle();
#if ENABLED(EXTENSIBLE_UI)
ExtUI::onUserConfirmRequired(nullptr);
#endif
#if HAS_LEDS_OFF_FLAG
printerEventLEDs.onResumeAfterWait();
#endif

View File

@ -46,7 +46,7 @@ namespace ExtUI {
*/
}
void onIdle() {}
void onPrinterKilled(const char* msg) {}
void onPrinterKilled(PGM_P const msg) {}
void onMediaInserted() {};
void onMediaError() {};
void onMediaRemoved() {};
@ -55,6 +55,7 @@ namespace ExtUI {
void onPrintTimerPaused() {}
void onPrintTimerStopped() {}
void onFilamentRunout() {}
void onUserConfirmRequired(const char * const msg) {}
void onStatusChanged(const char * const msg) {}
void onFactoryReset() {}
void onLoadSettings() {}

View File

@ -630,6 +630,12 @@ namespace ExtUI {
feedrate_percentage = clamp(value, 10, 500);
}
void setUserConfirmed(void) {
#if HAS_RESUME_CONTINUE
wait_for_user = false;
#endif
}
void printFile(const char *filename) {
IFSD(card.openAndPrintFile(filename), NOOP);
}

View File

@ -117,6 +117,7 @@ namespace ExtUI {
void setRetractAcceleration_mm_s2(const float);
void setTravelAcceleration_mm_s2(const float);
void setFeedrate_percent(const float);
void setUserConfirmed(void);
#if ENABLED(LIN_ADVANCE)
float getLinearAdvance_mm_mm_s(const extruder_t);
@ -239,11 +240,12 @@ namespace ExtUI {
void onMediaError();
void onMediaRemoved();
void onPlayTone(const uint16_t frequency, const uint16_t duration);
void onPrinterKilled(const char* msg);
void onPrinterKilled(PGM_P const msg);
void onPrintTimerStarted();
void onPrintTimerPaused();
void onPrintTimerStopped();
void onFilamentRunout(const extruder_t extruder);
void onUserConfirmRequired(const char * const msg);
void onStatusChanged(const char * const msg);
void onFactoryReset();
void onStoreSettings();