Skip to content

Commit

Permalink
🚸 Custom Menu Items for JyersUI (MarlinFirmware#24270)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryan065 authored and LCh-77 committed Jun 15, 2022
1 parent 5214c4c commit f31d477
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 1 deletion.
165 changes: 165 additions & 0 deletions Marlin/src/lcd/e3v2/jyersui/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,26 @@
#define MIN_BED_TEMP 0
#endif

/**
* Custom menu items with jyersLCD
*/
#if ENABLED(CUSTOM_MENU_CONFIG)
#ifdef CONFIG_MENU_ITEM_5_DESC
#define CUSTOM_MENU_COUNT 5
#elif defined(CONFIG_MENU_ITEM_4_DESC)
#define CUSTOM_MENU_COUNT 4
#elif defined(CONFIG_MENU_ITEM_3_DESC)
#define CUSTOM_MENU_COUNT 3
#elif defined(CONFIG_MENU_ITEM_2_DESC)
#define CUSTOM_MENU_COUNT 2
#elif defined(CONFIG_MENU_ITEM_1_DESC)
#define CUSTOM_MENU_COUNT 1
#endif
#if CUSTOM_MENU_COUNT
#define HAS_CUSTOM_MENU 1
#endif
#endif

constexpr float default_max_feedrate[] = DEFAULT_MAX_FEEDRATE;
constexpr float default_max_acceleration[] = DEFAULT_MAX_ACCELERATION;
constexpr float default_steps[] = DEFAULT_AXIS_STEPS_PER_UNIT;
Expand Down Expand Up @@ -1246,6 +1266,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
#define PREPARE_COOLDOWN (PREPARE_PREHEAT + EITHER(HAS_HOTEND, HAS_HEATED_BED))
#define PREPARE_CHANGEFIL (PREPARE_COOLDOWN + ENABLED(ADVANCED_PAUSE_FEATURE))
#define PREPARE_ACTIONCOMMANDS (PREPARE_CHANGEFIL + (ENABLED(HOST_ACTION_COMMANDS, HAS_HOSTACTION_MENUS)))
#define PREPARE_CUSTOM_MENU (PREPARE_ACTIONCOMMANDS + ENABLED(HAS_CUSTOM_MENU))
#define PREPARE_TOTAL PREPARE_ACTIONCOMMANDS

switch (item) {
Expand Down Expand Up @@ -1332,6 +1353,18 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
break;
#endif

#if HAS_CUSTOM_MENU
case PREPARE_CUSTOM_MENU:
#ifndef CUSTOM_MENU_CONFIG_TITLE
#define CUSTOM_MENU_CONFIG_TITLE "Custom Commands"
#endif
if (draw)
Draw_Menu_Item(row, ICON_Version, F(CUSTOM_MENU_CONFIG_TITLE));
else
Draw_Menu(MenuCustom);
break;
#endif

#if ENABLED(ADVANCED_PAUSE_FEATURE)
case PREPARE_CHANGEFIL:
if (draw) {
Expand Down Expand Up @@ -1974,6 +2007,126 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
break;
#endif

#if HAS_CUSTOM_MENU

case MenuCustom:

#define CUSTOM_MENU_BACK 0
#define CUSTOM_MENU_1 1
#define CUSTOM_MENU_2 2
#define CUSTOM_MENU_3 3
#define CUSTOM_MENU_4 4
#define CUSTOM_MENU_5 5
#define CUSTOM_MENU_TOTAL CUSTOM_MENU_COUNT

switch (item) {
case CUSTOM_MENU_BACK:
if (draw)
Draw_Menu_Item(row, ICON_Back, F("Back"));
else
Draw_Menu(Prepare, PREPARE_CUSTOM_MENU);
break;

#if CUSTOM_MENU_COUNT >= 1
case CUSTOM_MENU_1:
if (draw)
Draw_Menu_Item(row, ICON_Info, F(CONFIG_MENU_ITEM_1_DESC));
else {
Popup_Handler(Custom);
//queue.inject(F(CONFIG_MENU_ITEM_1_GCODE)); // Old code
gcode.process_subcommands_now(F(CONFIG_MENU_ITEM_1_GCODE));
planner.synchronize();
Redraw_Menu();
#if ENABLED(CUSTOM_MENU_CONFIG_SCRIPT_AUDIBLE_FEEDBACK)
AudioFeedback();
#endif
#ifdef CUSTOM_MENU_CONFIG_SCRIPT_RETURN
queue.inject(F(CUSTOM_MENU_CONFIG_SCRIPT_DONE));
#endif
}
break;
#endif

#if CUSTOM_MENU_COUNT >= 2
case CUSTOM_MENU_2:
if (draw)
Draw_Menu_Item(row, ICON_Info, F(CONFIG_MENU_ITEM_2_DESC));
else {
Popup_Handler(Custom);
gcode.process_subcommands_now(F(CONFIG_MENU_ITEM_2_GCODE));
planner.synchronize();
Redraw_Menu();
#if ENABLED(CUSTOM_MENU_CONFIG_SCRIPT_AUDIBLE_FEEDBACK)
AudioFeedback();
#endif
#ifdef CUSTOM_MENU_CONFIG_SCRIPT_RETURN
queue.inject(F(CUSTOM_MENU_CONFIG_SCRIPT_DONE));
#endif
}
break;
#endif

#if CUSTOM_MENU_COUNT >= 3
case CUSTOM_MENU_3:
if (draw)
Draw_Menu_Item(row, ICON_Info, F(CONFIG_MENU_ITEM_3_DESC));
else {
Popup_Handler(Custom);
gcode.process_subcommands_now(F(CONFIG_MENU_ITEM_3_GCODE));
planner.synchronize();
Redraw_Menu();
#if ENABLED(CUSTOM_MENU_CONFIG_SCRIPT_AUDIBLE_FEEDBACK)
AudioFeedback();
#endif
#ifdef CUSTOM_MENU_CONFIG_SCRIPT_RETURN
queue.inject(F(CUSTOM_MENU_CONFIG_SCRIPT_DONE));
#endif
}
break;
#endif

#if CUSTOM_MENU_COUNT >= 4
case CUSTOM_MENU_4:
if (draw)
Draw_Menu_Item(row, ICON_Info, F(CONFIG_MENU_ITEM_4_DESC));
else {
Popup_Handler(Custom);
gcode.process_subcommands_now(F(CONFIG_MENU_ITEM_4_GCODE));
planner.synchronize();
Redraw_Menu();
#if ENABLED(CUSTOM_MENU_CONFIG_SCRIPT_AUDIBLE_FEEDBACK)
AudioFeedback();
#endif
#ifdef CUSTOM_MENU_CONFIG_SCRIPT_RETURN
queue.inject(F(CUSTOM_MENU_CONFIG_SCRIPT_DONE));
#endif
}
break;
#endif

#if CUSTOM_MENU_COUNT >= 5
case CUSTOM_MENU_5:
if (draw)
Draw_Menu_Item(row, ICON_Info, F(CONFIG_MENU_ITEM_5_DESC));
else {
Popup_Handler(Custom);
gcode.process_subcommands_now(F(CONFIG_MENU_ITEM_5_GCODE));
planner.synchronize();
Redraw_Menu();
#if ENABLED(CUSTOM_MENU_CONFIG_SCRIPT_AUDIBLE_FEEDBACK)
AudioFeedback();
#endif
#ifdef CUSTOM_MENU_CONFIG_SCRIPT_RETURN
queue.inject(F(CUSTOM_MENU_CONFIG_SCRIPT_DONE));
#endif
}
break;
#endif // Custom Menu
}
break;

#endif // HAS_CUSTOM_MENU

case Control:

#define CONTROL_BACK 0
Expand Down Expand Up @@ -4547,6 +4700,14 @@ FSTR_P CrealityDWINClass::Get_Menu_Title(uint8_t menu) {
#if ENABLED(HOST_ACTION_COMMANDS, HAS_HOSTACTION_MENUS)
case HostActions: return F("Host Actions");
#endif
#if HAS_CUSTOM_MENU
case MenuCustom:
#ifdef CUSTOM_MENU_CONFIG_TITLE
return F(CUSTOM_MENU_CONFIG_TITLE);
#else
return F("Custom Commands");
#endif
#endif
case Control: return GET_TEXT_F(MSG_CONTROL);
case TempMenu: return GET_TEXT_F(MSG_TEMPERATURE);
#if HAS_HOTEND || HAS_HEATED_BED
Expand Down Expand Up @@ -4641,6 +4802,9 @@ uint8_t CrealityDWINClass::Get_Menu_Size(uint8_t menu) {
#if ENABLED(HOST_ACTION_COMMANDS, HAS_HOSTACTION_MENUS)
case HostActions: return HOSTACTIONS_TOTAL;
#endif
#if HAS_CUSTOM_MENU
case MenuCustom: return CUSTOM_MENU_TOTAL;
#endif
case Control: return CONTROL_TOTAL;
case TempMenu: return TEMP_TOTAL;
#if HAS_HOTEND || HAS_HEATED_BED
Expand Down Expand Up @@ -4745,6 +4909,7 @@ void CrealityDWINClass::Popup_Handler(PopupID popupid, bool option/*=false*/) {
case Runout: Draw_Popup(F("Filament Runout"), F(""), F(""), Wait, ICON_BLTouch); break;
case PIDWait: Draw_Popup(F("PID Autotune"), F("in process"), GET_TEXT_F(MSG_PLEASE_WAIT), Wait, ICON_BLTouch); break;
case Resuming: Draw_Popup(F("Resuming Print"), GET_TEXT_F(MSG_PLEASE_WAIT), F(""), Wait, ICON_BLTouch); break;
case Custom: Draw_Popup(F("Running Custom GCode"), GET_TEXT_F(MSG_PLEASE_WAIT), F(""), Wait, ICON_BLTouch); break;
default: break;
}
}
Expand Down
3 changes: 2 additions & 1 deletion Marlin/src/lcd/e3v2/jyersui/dwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ enum processID : uint8_t {
enum PopupID : uint8_t {
Pause, Stop, Resume, SaveLevel, ETemp, ConfFilChange, PurgeMore, MeshSlot,
Level, Home, MoveWait, Heating, FilLoad, FilChange, TempWarn, Runout, PIDWait, Resuming, ManualProbing,
FilInsert, HeaterTime, UserInput, LevelError, InvalidMesh, UI, Complete,
FilInsert, HeaterTime, UserInput, LevelError, InvalidMesh, UI, Complete, Custom,
ESDiagPopup
};

Expand All @@ -55,6 +55,7 @@ enum menuID : uint8_t {
Preheat,
ChangeFilament,
HostActions,
MenuCustom,
Control,
TempMenu,
PID,
Expand Down

0 comments on commit f31d477

Please sign in to comment.