Marlin_Firmware/Marlin/src/lcd/menu/menu_main.cpp

486 lines
13 KiB
C++
Raw Normal View History

2018-10-27 13:15:46 -05:00
/**
* Marlin 3D Printer Firmware
2020-02-03 08:00:57 -06:00
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
2018-10-27 13:15:46 -05:00
*
* Based on Sprinter and grbl.
2019-06-27 23:57:50 -05:00
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
2018-10-27 13:15:46 -05:00
*
* 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
2020-07-22 22:20:14 -05:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-10-27 13:15:46 -05:00
*
*/
//
// Main Menu
//
#include "../../inc/MarlinConfigPre.h"
#if HAS_LCD_MENU
2020-08-21 05:21:34 -05:00
#include "menu_item.h"
2018-10-27 13:15:46 -05:00
#include "../../module/temperature.h"
2019-01-11 20:42:11 -06:00
#include "../../gcode/queue.h"
#include "../../module/printcounter.h"
#include "../../module/stepper.h"
2019-04-10 21:46:49 -05:00
#include "../../sd/cardreader.h"
2018-10-27 13:15:46 -05:00
2019-06-15 16:57:20 -05:00
#if HAS_GAMES && DISABLED(LCD_INFO_MENU)
#include "game/game.h"
#endif
2020-04-22 16:35:03 -05:00
#if EITHER(SDSUPPORT, HOST_PROMPT_SUPPORT) || defined(ACTION_ON_CANCEL)
#define MACHINE_CAN_STOP 1
#endif
#if ANY(SDSUPPORT, HOST_PROMPT_SUPPORT, PARK_HEAD_ON_PAUSE) || defined(ACTION_ON_PAUSE)
#define MACHINE_CAN_PAUSE 1
#endif
2018-11-27 14:40:40 -06:00
2020-11-18 01:27:21 -06:00
#if ENABLED(MMU2_MENUS)
2019-02-06 17:38:46 -06:00
#include "../../lcd/menu/menu_mmu2.h"
2019-01-31 19:10:52 -06:00
#endif
#if ENABLED(PASSWORD_FEATURE)
#include "../../feature/password/password.h"
#endif
2020-09-19 10:17:24 -05:00
#if ENABLED(HOST_START_MENU_ITEM) && defined(ACTION_ON_START)
2020-09-17 06:36:21 -05:00
#include "../../feature/host_actions.h"
#endif
2020-12-23 20:22:58 -06:00
#if ENABLED(GCODE_REPEAT_MARKERS)
#include "../../feature/repeat.h"
#endif
2018-10-27 13:15:46 -05:00
void menu_tune();
void menu_cancelobject();
2018-10-27 16:45:37 -05:00
void menu_motion();
2018-10-27 13:15:46 -05:00
void menu_temperature();
void menu_configuration();
2019-06-17 21:44:23 -05:00
2020-06-18 15:23:03 -05:00
#if HAS_POWER_MONITOR
void menu_power_monitor();
#endif
#if ENABLED(MIXING_EXTRUDER)
void menu_mixer();
#endif
2019-06-17 21:44:23 -05:00
#if ENABLED(ADVANCED_PAUSE_FEATURE)
void _menu_temp_filament_op(const PauseMode, const int8_t);
2019-06-17 21:44:23 -05:00
void menu_change_filament();
#endif
#if ENABLED(LCD_INFO_MENU)
void menu_info();
#endif
#if EITHER(LED_CONTROL_MENU, CASE_LIGHT_MENU)
2019-06-17 21:44:23 -05:00
void menu_led();
#endif
2018-10-27 13:15:46 -05:00
2019-06-27 23:06:49 -05:00
#if HAS_CUTTER
void menu_spindle_laser();
#endif
2021-02-25 10:23:17 -06:00
#if ENABLED(PREHEAT_SHORTCUT_MENU_ITEM)
void menu_preheat_only();
#endif
#if HAS_MULTI_LANGUAGE
void menu_language();
#endif
#if ENABLED(CUSTOM_MENU_MAIN)
void _lcd_custom_menu_main_gcode(PGM_P const cmd) {
queue.inject_P(cmd);
TERN_(CUSTOM_MENU_MAIN_SCRIPT_AUDIBLE_FEEDBACK, ui.completion_feedback());
TERN_(CUSTOM_MENU_MAIN_SCRIPT_RETURN, ui.return_to_status());
}
void custom_menus_main() {
START_MENU();
BACK_ITEM(MSG_MAIN);
#define HAS_CUSTOM_ITEM_MAIN(N) (defined(MAIN_MENU_ITEM_##N##_DESC) && defined(MAIN_MENU_ITEM_##N##_GCODE))
#define CUSTOM_TEST_MAIN(N) do{ \
constexpr char c = MAIN_MENU_ITEM_##N##_GCODE[strlen(MAIN_MENU_ITEM_##N##_GCODE) - 1]; \
static_assert(c != '\n' && c != '\r', "MAIN_MENU_ITEM_" STRINGIFY(N) "_GCODE cannot have a newline at the end. Please remove it."); \
}while(0)
#ifdef MAIN_MENU_ITEM_SCRIPT_DONE
#define _DONE_SCRIPT "\n" MAIN_MENU_ITEM_SCRIPT_DONE
#else
#define _DONE_SCRIPT ""
#endif
#define GCODE_LAMBDA_MAIN(N) []{ _lcd_custom_menu_main_gcode(PSTR(MAIN_MENU_ITEM_##N##_GCODE _DONE_SCRIPT)); }
#define _CUSTOM_ITEM_MAIN(N) ACTION_ITEM_P(PSTR(MAIN_MENU_ITEM_##N##_DESC), GCODE_LAMBDA_MAIN(N));
#define _CUSTOM_ITEM_MAIN_CONFIRM(N) \
SUBMENU_P(PSTR(MAIN_MENU_ITEM_##N##_DESC), []{ \
MenuItem_confirm::confirm_screen( \
GCODE_LAMBDA_MAIN(N), \
ui.goto_previous_screen, \
PSTR(MAIN_MENU_ITEM_##N##_DESC "?") \
); \
})
#define CUSTOM_ITEM_MAIN(N) do{ if (ENABLED(MAIN_MENU_ITEM_##N##_CONFIRM)) _CUSTOM_ITEM_MAIN_CONFIRM(N); else _CUSTOM_ITEM_MAIN(N); }while(0)
#if HAS_CUSTOM_ITEM_MAIN(1)
CUSTOM_TEST_MAIN(1);
CUSTOM_ITEM_MAIN(1);
#endif
#if HAS_CUSTOM_ITEM_MAIN(2)
CUSTOM_TEST_MAIN(2);
CUSTOM_ITEM_MAIN(2);
#endif
#if HAS_CUSTOM_ITEM_MAIN(3)
CUSTOM_TEST_MAIN(3);
CUSTOM_ITEM_MAIN(3);
#endif
#if HAS_CUSTOM_ITEM_MAIN(4)
CUSTOM_TEST_MAIN(4);
CUSTOM_ITEM_MAIN(4);
#endif
#if HAS_CUSTOM_ITEM_MAIN(5)
CUSTOM_TEST_MAIN(5);
CUSTOM_ITEM_MAIN(5);
#endif
#if HAS_CUSTOM_ITEM_MAIN(6)
CUSTOM_TEST_MAIN(6);
CUSTOM_ITEM_MAIN(6);
#endif
#if HAS_CUSTOM_ITEM_MAIN(7)
CUSTOM_TEST_MAIN(7);
CUSTOM_ITEM_MAIN(7);
#endif
#if HAS_CUSTOM_ITEM_MAIN(8)
CUSTOM_TEST_MAIN(8);
CUSTOM_ITEM_MAIN(8);
#endif
#if HAS_CUSTOM_ITEM_MAIN(9)
CUSTOM_TEST_MAIN(9);
CUSTOM_ITEM_MAIN(9);
#endif
#if HAS_CUSTOM_ITEM_MAIN(10)
CUSTOM_TEST_MAIN(10);
CUSTOM_ITEM_MAIN(10);
#endif
#if HAS_CUSTOM_ITEM_MAIN(11)
CUSTOM_TEST_MAIN(11);
CUSTOM_ITEM_MAIN(11);
#endif
#if HAS_CUSTOM_ITEM_MAIN(12)
CUSTOM_TEST_MAIN(12);
CUSTOM_ITEM_MAIN(12);
#endif
#if HAS_CUSTOM_ITEM_MAIN(13)
CUSTOM_TEST_MAIN(13);
CUSTOM_ITEM_MAIN(13);
#endif
#if HAS_CUSTOM_ITEM_MAIN(14)
CUSTOM_TEST_MAIN(14);
CUSTOM_ITEM_MAIN(14);
#endif
#if HAS_CUSTOM_ITEM_MAIN(15)
CUSTOM_TEST_MAIN(15);
CUSTOM_ITEM_MAIN(15);
#endif
#if HAS_CUSTOM_ITEM_MAIN(16)
CUSTOM_TEST_MAIN(16);
CUSTOM_ITEM_MAIN(16);
#endif
#if HAS_CUSTOM_ITEM_MAIN(17)
CUSTOM_TEST_MAIN(17);
CUSTOM_ITEM_MAIN(17);
#endif
#if HAS_CUSTOM_ITEM_MAIN(18)
CUSTOM_TEST_MAIN(18);
CUSTOM_ITEM_MAIN(18);
#endif
#if HAS_CUSTOM_ITEM_MAIN(19)
CUSTOM_TEST_MAIN(19);
CUSTOM_ITEM_MAIN(19);
#endif
#if HAS_CUSTOM_ITEM_MAIN(20)
CUSTOM_TEST_MAIN(20);
CUSTOM_ITEM_MAIN(20);
#endif
#if HAS_CUSTOM_ITEM_MAIN(21)
CUSTOM_TEST_MAIN(21);
CUSTOM_ITEM_MAIN(21);
#endif
#if HAS_CUSTOM_ITEM_MAIN(22)
CUSTOM_TEST_MAIN(22);
CUSTOM_ITEM_MAIN(22);
#endif
#if HAS_CUSTOM_ITEM_MAIN(23)
CUSTOM_TEST_MAIN(23);
CUSTOM_ITEM_MAIN(23);
#endif
#if HAS_CUSTOM_ITEM_MAIN(24)
CUSTOM_TEST_MAIN(24);
CUSTOM_ITEM_MAIN(24);
#endif
#if HAS_CUSTOM_ITEM_MAIN(25)
CUSTOM_TEST_MAIN(25);
CUSTOM_ITEM_MAIN(25);
#endif
END_MENU();
}
#endif // CUSTOM_MENU_MAIN
2018-10-27 13:15:46 -05:00
void menu_main() {
2019-10-02 18:54:20 -05:00
const bool busy = printingIsActive()
2019-02-02 17:08:44 -06:00
#if ENABLED(SDSUPPORT)
2019-09-15 03:10:59 -05:00
, card_detected = card.isMounted()
2019-02-04 06:11:17 -06:00
, card_open = card_detected && card.isFileOpen()
2019-02-02 17:08:44 -06:00
#endif
;
2019-01-11 20:42:11 -06:00
2020-04-27 23:52:11 -05:00
START_MENU();
BACK_ITEM(MSG_INFO_SCREEN);
2019-01-11 20:42:11 -06:00
if (busy) {
#if MACHINE_CAN_PAUSE
2019-10-03 05:38:30 -05:00
ACTION_ITEM(MSG_PAUSE_PRINT, ui.pause_print);
#endif
#if MACHINE_CAN_STOP
2019-11-07 00:28:33 -06:00
SUBMENU(MSG_STOP_PRINT, []{
MenuItem_confirm::select_screen(
GET_TEXT(MSG_BUTTON_STOP), GET_TEXT(MSG_BACK),
ui.abort_print, ui.goto_previous_screen,
2020-05-10 00:12:56 -05:00
GET_TEXT(MSG_STOP_PRINT), (const char *)nullptr, PSTR("?")
2019-11-07 00:28:33 -06:00
);
});
2019-01-11 20:42:11 -06:00
#endif
2020-12-23 20:22:58 -06:00
#if ENABLED(GCODE_REPEAT_MARKERS)
if (repeat.is_active())
ACTION_ITEM(MSG_END_LOOPS, repeat.cancel);
#endif
2019-10-03 05:38:30 -05:00
SUBMENU(MSG_TUNE, menu_tune);
#if ENABLED(CANCEL_OBJECTS) && DISABLED(SLIM_LCD_MENUS)
SUBMENU(MSG_CANCEL_OBJECT, []{ editable.int8 = -1; ui.goto_screen(menu_cancelobject); });
#endif
}
else {
#if !HAS_ENCODER_WHEEL && ENABLED(SDSUPPORT)
// *** IF THIS SECTION IS CHANGED, REPRODUCE BELOW ***
//
2020-11-07 17:43:47 -06:00
// Run Auto Files
//
#if ENABLED(MENU_ADDAUTOSTART)
ACTION_ITEM(MSG_RUN_AUTO_FILES, card.autofile_begin);
#endif
2019-02-02 17:08:44 -06:00
if (card_detected) {
if (!card_open) {
SUBMENU(MSG_MEDIA_MENU, MEDIA_MENU_GATEWAY);
2020-08-21 02:42:50 -05:00
#if PIN_EXISTS(SD_DETECT)
2021-01-22 15:01:19 -06:00
GCODES_ITEM(MSG_CHANGE_MEDIA, PSTR("M21"));
2020-08-21 02:42:50 -05:00
#else
GCODES_ITEM(MSG_RELEASE_MEDIA, PSTR("M22"));
#endif
}
}
else {
#if PIN_EXISTS(SD_DETECT)
2019-10-03 05:38:30 -05:00
ACTION_ITEM(MSG_NO_MEDIA, nullptr);
#else
2021-01-22 15:01:19 -06:00
GCODES_ITEM(MSG_ATTACH_MEDIA, PSTR("M21"));
#endif
}
#endif // !HAS_ENCODER_WHEEL && SDSUPPORT
2020-04-29 14:52:42 -05:00
if (TERN0(MACHINE_CAN_PAUSE, printingIsPaused()))
2020-04-22 16:35:03 -05:00
ACTION_ITEM(MSG_RESUME_PRINT, ui.resume_print);
2019-01-23 15:48:56 -06:00
2020-09-19 10:17:24 -05:00
#if ENABLED(HOST_START_MENU_ITEM) && defined(ACTION_ON_START)
2020-09-17 06:36:21 -05:00
ACTION_ITEM(MSG_HOST_START_PRINT, host_action_start);
#endif
2021-02-25 10:23:17 -06:00
#if ENABLED(PREHEAT_SHORTCUT_MENU_ITEM)
SUBMENU(MSG_PREHEAT_CUSTOM, menu_preheat_only);
#endif
2020-09-17 06:36:21 -05:00
2019-10-03 05:38:30 -05:00
SUBMENU(MSG_MOTION, menu_motion);
}
2019-01-31 19:10:52 -06:00
2019-06-27 23:06:49 -05:00
#if HAS_CUTTER
SUBMENU(MSG_CUTTER(MENU), STICKY_SCREEN(menu_spindle_laser));
2019-06-27 23:06:49 -05:00
#endif
#if HAS_TEMPERATURE
SUBMENU(MSG_TEMPERATURE, menu_temperature);
#endif
2020-06-18 15:23:03 -05:00
#if HAS_POWER_MONITOR
2020-08-21 02:42:50 -05:00
SUBMENU(MSG_POWER_MONITOR, menu_power_monitor);
2020-06-18 15:23:03 -05:00
#endif
#if ENABLED(MIXING_EXTRUDER)
2019-10-03 05:38:30 -05:00
SUBMENU(MSG_MIXER, menu_mixer);
#endif
#if ENABLED(MMU2_MENUS)
2019-10-03 05:38:30 -05:00
if (!busy) SUBMENU(MSG_MMU2_MENU, menu_mmu2);
#endif
2018-10-27 13:15:46 -05:00
2019-10-03 05:38:30 -05:00
SUBMENU(MSG_CONFIGURATION, menu_configuration);
2018-10-27 13:15:46 -05:00
#if ENABLED(CUSTOM_MENU_MAIN)
if (TERN1(CUSTOM_MENU_MAIN_ONLY_IDLE, !busy)) {
#ifdef CUSTOM_MENU_MAIN_TITLE
SUBMENU_P(PSTR(CUSTOM_MENU_MAIN_TITLE), custom_menus_main);
#else
SUBMENU(MSG_CUSTOM_COMMANDS, custom_menus_main);
#endif
}
2018-10-27 13:15:46 -05:00
#endif
#if ENABLED(ADVANCED_PAUSE_FEATURE)
#if E_STEPPERS == 1 && DISABLED(FILAMENT_LOAD_UNLOAD_GCODES)
2020-04-29 14:52:42 -05:00
if (thermalManager.targetHotEnoughToExtrude(active_extruder))
2019-10-03 05:38:30 -05:00
GCODES_ITEM(MSG_FILAMENTCHANGE, PSTR("M600 B0"));
2020-04-29 14:52:42 -05:00
else
2019-11-02 00:05:05 -05:00
SUBMENU(MSG_FILAMENTCHANGE, []{ _menu_temp_filament_op(PAUSE_MODE_CHANGE_FILAMENT, 0); });
2018-10-27 13:15:46 -05:00
#else
2019-10-03 05:38:30 -05:00
SUBMENU(MSG_FILAMENTCHANGE, menu_change_filament);
2018-10-27 13:15:46 -05:00
#endif
#endif
#if ENABLED(LCD_INFO_MENU)
2019-10-03 05:38:30 -05:00
SUBMENU(MSG_INFO_MENU, menu_info);
2018-10-27 13:15:46 -05:00
#endif
#if EITHER(LED_CONTROL_MENU, CASE_LIGHT_MENU)
SUBMENU(MSG_LEDS, menu_led);
2018-10-27 13:15:46 -05:00
#endif
//
// Switch power on/off
//
2019-10-22 15:43:37 -05:00
#if ENABLED(PSU_CONTROL)
2020-04-29 14:52:42 -05:00
if (powersupply_on)
2019-10-03 05:38:30 -05:00
GCODES_ITEM(MSG_SWITCH_PS_OFF, PSTR("M81"));
2020-04-29 14:52:42 -05:00
else
2019-10-03 05:38:30 -05:00
GCODES_ITEM(MSG_SWITCH_PS_ON, PSTR("M80"));
2018-10-27 13:15:46 -05:00
#endif
2020-04-23 21:42:38 -05:00
#if BOTH(HAS_ENCODER_WHEEL, SDSUPPORT)
2020-04-27 23:52:11 -05:00
if (!busy) {
2020-04-27 23:52:11 -05:00
// *** IF THIS SECTION IS CHANGED, REPRODUCE ABOVE ***
2018-10-27 13:15:46 -05:00
2020-04-27 23:52:11 -05:00
//
// Autostart
//
#if ENABLED(MENU_ADDAUTOSTART)
ACTION_ITEM(MSG_RUN_AUTO_FILES, card.autofile_begin);
2019-01-11 20:42:11 -06:00
#endif
2020-04-27 23:52:11 -05:00
if (card_detected) {
if (!card_open) {
2020-08-21 02:42:50 -05:00
#if PIN_EXISTS(SD_DETECT)
2021-01-22 15:01:19 -06:00
GCODES_ITEM(MSG_CHANGE_MEDIA, PSTR("M21"));
2020-08-21 02:42:50 -05:00
#else
GCODES_ITEM(MSG_RELEASE_MEDIA, PSTR("M22"));
#endif
SUBMENU(MSG_MEDIA_MENU, MEDIA_MENU_GATEWAY);
2020-04-27 23:52:11 -05:00
}
}
else {
#if PIN_EXISTS(SD_DETECT)
ACTION_ITEM(MSG_NO_MEDIA, nullptr);
#else
2021-01-22 15:01:19 -06:00
GCODES_ITEM(MSG_ATTACH_MEDIA, PSTR("M21"));
2020-04-27 23:52:11 -05:00
#endif
}
2019-01-11 20:42:11 -06:00
}
#endif // HAS_ENCODER_WHEEL && SDSUPPORT
2019-01-13 17:59:32 -06:00
#if HAS_SERVICE_INTERVALS
static auto _service_reset = [](const int index) {
print_job_timer.resetServiceInterval(index);
2020-04-23 15:14:32 -05:00
ui.completion_feedback();
ui.reset_status();
ui.return_to_status();
};
2019-02-12 15:58:56 -06:00
#if SERVICE_INTERVAL_1 > 0
CONFIRM_ITEM_P(PSTR(SERVICE_NAME_1),
MSG_BUTTON_RESET, MSG_BUTTON_CANCEL,
[]{ _service_reset(1); }, ui.goto_previous_screen,
GET_TEXT(MSG_SERVICE_RESET), F(SERVICE_NAME_1), PSTR("?")
);
2019-02-12 15:58:56 -06:00
#endif
#if SERVICE_INTERVAL_2 > 0
CONFIRM_ITEM_P(PSTR(SERVICE_NAME_2),
MSG_BUTTON_RESET, MSG_BUTTON_CANCEL,
[]{ _service_reset(2); }, ui.goto_previous_screen,
GET_TEXT(MSG_SERVICE_RESET), F(SERVICE_NAME_2), PSTR("?")
);
2019-02-12 15:58:56 -06:00
#endif
#if SERVICE_INTERVAL_3 > 0
CONFIRM_ITEM_P(PSTR(SERVICE_NAME_3),
MSG_BUTTON_RESET, MSG_BUTTON_CANCEL,
[]{ _service_reset(3); }, ui.goto_previous_screen,
GET_TEXT(MSG_SERVICE_RESET), F(SERVICE_NAME_3), PSTR("?")
);
2019-02-12 15:58:56 -06:00
#endif
#endif
2019-06-15 16:57:20 -05:00
#if HAS_GAMES && DISABLED(LCD_INFO_MENU)
#if ENABLED(GAMES_EASTER_EGG)
2019-10-03 05:38:30 -05:00
SKIP_ITEM();
SKIP_ITEM();
2019-12-31 16:06:16 -06:00
SKIP_ITEM();
#endif
2019-12-31 16:06:16 -06:00
// Game sub-menu or the individual game
{
SUBMENU(
#if HAS_GAME_MENU
MSG_GAMES, menu_game
#elif ENABLED(MARLIN_BRICKOUT)
MSG_BRICKOUT, brickout.enter_game
#elif ENABLED(MARLIN_INVADERS)
MSG_INVADERS, invaders.enter_game
#elif ENABLED(MARLIN_SNAKE)
MSG_SNAKE, snake.enter_game
#elif ENABLED(MARLIN_MAZE)
MSG_MAZE, maze.enter_game
#endif
);
}
#endif
#if HAS_MULTI_LANGUAGE
SUBMENU(LANGUAGE, menu_language);
#endif
2018-10-27 13:15:46 -05:00
END_MENU();
}
#endif // HAS_LCD_MENU