Skip to content

Commit

Permalink
Send notifications to ExtUI for M0/M1 (#13344)
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
coldtobi authored and thinkyhead committed Mar 9, 2019
1 parent 00fc431 commit 60e82e3
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Marlin/src/Marlin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/Marlin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions Marlin/src/gcode/lcd/M0_M1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Marlin/src/lcd/extensible_ui/lib/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {};
Expand All @@ -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() {}
Expand Down
6 changes: 6 additions & 0 deletions Marlin/src/lcd/extensible_ui/ui_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion Marlin/src/lcd/extensible_ui/ui_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down

1 comment on commit 60e82e3

@Vertabreak
Copy link
Contributor

@Vertabreak Vertabreak commented on 60e82e3 Mar 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wont compile reverting marlin.ccp & .h allows compile.

In file included from /tmp/arduino_build_210419/sketch/src/HAL/HAL_AVR/MarlinSerial.cpp:58:0:
/tmp/arduino_build_210419/sketch/src/HAL/HAL_AVR/../../feature/emergency_parser.h:35:22: error: conflicting declaration 'volatile bool wait_for_user'
extern volatile bool wait_for_user, wait_for_heatup;
^
In file included from /tmp/arduino_build_210419/sketch/src/HAL/HAL_AVR/MarlinSerial.cpp:44:0:
/tmp/arduino_build_210419/sketch/src/HAL/HAL_AVR/../../Marlin.h:336:15: note: previous declaration as 'bool wait_for_user'
extern bool wait_for_user;
^

Please sign in to comment.