Skip to content

Commit

Permalink
Sanitize HOST_PROMPT_SUPPORT notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
The-EG committed Sep 25, 2021
1 parent e85f622 commit 93dee40
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -3837,6 +3837,9 @@
#if ENABLED(HOST_ACTION_COMMANDS)
//#define HOST_PAUSE_M76
//#define HOST_PROMPT_SUPPORT
#if ENABLED(HOST_PROMPT_SUPPORT)
//#define HOST_STATUS_NOTIFICATIONS
#endif
//#define HOST_START_MENU_ITEM // Add a menu item that tells the host to start
#endif

Expand Down
7 changes: 5 additions & 2 deletions Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
void MarlinUI::set_status(const char * const message, const bool persist) {
if (alert_level) return;

TERN_(HOST_PROMPT_SUPPORT, host_action_notify(message));
TERN_(HOST_STATUS_NOTIFICATIONS, host_action_notify(message));

// Here we have a problem. The message is encoded in UTF8, so
// arbitrarily cutting it will be a problem. We MUST be sure
Expand Down Expand Up @@ -1419,7 +1419,7 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
if (level < alert_level) return;
alert_level = level;

TERN_(HOST_PROMPT_SUPPORT, host_action_notify_P(message));
TERN_(HOST_STATUS_NOTIFICATIONS, host_action_notify_P(message));

// Since the message is encoded in UTF8 it must
// only be cut on a character boundary.
Expand Down Expand Up @@ -1457,6 +1457,9 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
va_start(args, fmt);
vsnprintf_P(status_message, MAX_MESSAGE_LENGTH, fmt, args);
va_end(args);

TERN_(HOST_STATUS_NOTIFICATIONS, host_action_notify(status_message));

finish_status(level > 0);
}

Expand Down
13 changes: 12 additions & 1 deletion Marlin/src/module/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
#include "../lcd/e3v2/jyersui/dwin.h"
#endif

#if ENABLED(HOST_PROMPT_SUPPORT)
#include "../feature/host_actions.h"
#endif

#if HAS_SERVOS
#include "servo.h"
#endif
Expand Down Expand Up @@ -1471,7 +1475,10 @@ void MarlinSettings::postprocess() {
store_mesh(ubl.storage_slot);
#endif

if (!eeprom_error) LCD_MESSAGEPGM(MSG_SETTINGS_STORED);
if (!eeprom_error) {
LCD_MESSAGEPGM(MSG_SETTINGS_STORED);
TERN_(HOST_PROMPT_SUPPORT, host_action_notify_P(GET_TEXT(MSG_SETTINGS_STORED)));
}

TERN_(EXTENSIBLE_UI, ExtUI::onConfigurationStoreWritten(!eeprom_error));

Expand All @@ -1498,6 +1505,7 @@ void MarlinSettings::postprocess() {
}
DEBUG_ECHO_MSG("EEPROM version mismatch (EEPROM=", stored_ver, " Marlin=" EEPROM_VERSION ")");
TERN_(DWIN_CREALITY_LCD_ENHANCED, ui.set_status(GET_TEXT(MSG_ERR_EEPROM_VERSION)));
TERN_(HOST_PROMPT_SUPPORT, host_action_notify_P(GET_TEXT(MSG_ERR_EEPROM_VERSION)));

IF_DISABLED(EEPROM_AUTO_INIT, ui.eeprom_alert_version());
eeprom_error = true;
Expand Down Expand Up @@ -2363,12 +2371,14 @@ void MarlinSettings::postprocess() {
eeprom_error = true;
DEBUG_ERROR_MSG("EEPROM CRC mismatch - (stored) ", stored_crc, " != ", working_crc, " (calculated)!");
TERN_(DWIN_CREALITY_LCD_ENHANCED, ui.set_status(GET_TEXT(MSG_ERR_EEPROM_CRC)));
TERN_(HOST_PROMPT_SUPPORT, host_action_notify_P(GET_TEXT(MSG_ERR_EEPROM_CRC)));
IF_DISABLED(EEPROM_AUTO_INIT, ui.eeprom_alert_crc());
}
else if (!validating) {
DEBUG_ECHO_START();
DEBUG_ECHO(version);
DEBUG_ECHOLNPGM(" stored settings retrieved (", eeprom_index - (EEPROM_OFFSET), " bytes; crc ", (uint32_t)working_crc, ")");
TERN_(HOST_PROMPT_SUPPORT, host_action_notify("Stored settings retrieved"));
}

if (!validating && !eeprom_error) postprocess();
Expand Down Expand Up @@ -3028,6 +3038,7 @@ void MarlinSettings::reset() {
postprocess();

DEBUG_ECHO_MSG("Hardcoded Default Settings Loaded");
TERN_(HOST_PROMPT_SUPPORT, host_action_notify("Hardcoded Default Settings Loaded"));

TERN_(EXTENSIBLE_UI, ExtUI::onFactoryReset());
}
Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ volatile bool Temperature::raw_temps_ready = false;
SERIAL_ECHOLNPGM(STR_PID_TEMP_TOO_HIGH);
TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_TEMP_TOO_HIGH));
TERN_(DWIN_CREALITY_LCD_ENHANCED, DWIN_PidTuning(PID_TEMP_TOO_HIGH));
TERN_(HOST_PROMPT_SUPPORT, host_action_notify(STR_PID_TEMP_TOO_HIGH));
return;
}

Expand Down Expand Up @@ -710,6 +711,7 @@ volatile bool Temperature::raw_temps_ready = false;
SERIAL_ECHOLNPGM(STR_PID_TEMP_TOO_HIGH);
TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_TEMP_TOO_HIGH));
TERN_(DWIN_CREALITY_LCD_ENHANCED, DWIN_PidTuning(PID_TEMP_TOO_HIGH));
TERN_(HOST_PROMPT_SUPPORT, host_action_notify(STR_PID_TEMP_TOO_HIGH));
break;
}

Expand Down Expand Up @@ -747,12 +749,14 @@ volatile bool Temperature::raw_temps_ready = false;
TERN_(DWIN_CREALITY_LCD, DWIN_Popup_Temperature(0));
TERN_(DWIN_CREALITY_LCD_ENHANCED, DWIN_PidTuning(PID_TUNING_TIMEOUT));
TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_TUNING_TIMEOUT));
TERN_(HOST_PROMPT_SUPPORT, host_action_notify(STR_PID_TIMEOUT));
SERIAL_ECHOLNPGM(STR_PID_TIMEOUT);
break;
}

if (cycles > ncycles && cycles > 2) {
SERIAL_ECHOLNPGM(STR_PID_AUTOTUNE_FINISHED);
TERN_(HOST_PROMPT_SUPPORT, host_action_notify("PID Autotune Finished!")); // TODO: New str value?

#if EITHER(PIDTEMPBED, PIDTEMPCHAMBER)
PGM_P const estring = GHV(PSTR("chamber"), PSTR("bed"), NUL_STR);
Expand Down

0 comments on commit 93dee40

Please sign in to comment.