mmu2_reporting.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #include "mmu2.h"
  2. #include "mmu2_reporting.h"
  3. #include "mmu2_error_converter.h"
  4. #include "mmu2/error_codes.h"
  5. #include "mmu2/buttons.h"
  6. #include "ultralcd.h"
  7. #include "Filament_sensor.h"
  8. #include "language.h"
  9. #include "temperature.h"
  10. namespace MMU2 {
  11. const char * const ProgressCodeToText(uint16_t pc); // we may join progress convertor and reporter together
  12. void BeginReport(CommandInProgress cip, uint16_t ec) {
  13. custom_message_type = CustomMsg::MMUProgress;
  14. lcd_setstatuspgm( ProgressCodeToText(ec) );
  15. }
  16. void EndReport(CommandInProgress cip, uint16_t ec) {
  17. // clear the status msg line - let the printed filename get visible again
  18. custom_message_type = CustomMsg::Status;
  19. }
  20. // Callback which is called while the printer is
  21. // waiting for the user to click a button option
  22. static void ReportErrorHook_cb(void)
  23. {
  24. //TODO: MK3S needs to request an update for the FINDA value
  25. // if we want it to be updated live on the menu screen
  26. lcd_set_cursor(3, 2);
  27. lcd_printf_P(PSTR("%d"), mmu2.FindaDetectsFilament());
  28. lcd_set_cursor(8, 2);
  29. lcd_printf_P(PSTR("%d"), fsensor.getFilamentPresent());
  30. lcd_set_cursor(11, 2);
  31. lcd_print("?>?"); // This is temporary until below TODO is resolved
  32. // TODO, see lcdui_print_extruder(void)
  33. //if (MMU2::mmu2.get_current_tool() == MMU2::FILAMENT_UNKNOWN)
  34. // lcd_printf_P(_N(" ?>%u"), tmp_extruder + 1);
  35. //else
  36. // lcd_printf_P(_N(" %u>%u"), MMU2::mmu2.get_current_tool() + 1, tmp_extruder + 1);
  37. // Print active extruder temperature
  38. lcd_set_cursor(16, 2);
  39. lcd_printf_P(PSTR("%d"), (int)(degHotend(0) + 0.5));
  40. }
  41. void ReportErrorHook(CommandInProgress cip, uint16_t ec) {
  42. //! Show an error screen
  43. //! When an MMU error occurs, the LCD content will look like this:
  44. //! |01234567890123456789|
  45. //! |MMU FW update needed| <- title/header of the error: max 20 characters
  46. //! |prusa3d.com/ERR04504| <- URL 20 characters
  47. //! |FI:1 FS:1 5>3 t201°| <- status line, t is thermometer symbol
  48. //! |>Retry >Done >MoreW| <- buttons
  49. const uint8_t ei = PrusaErrorCodeIndex(ec);
  50. uint8_t choice_selected = 0;
  51. bool two_choices = false;
  52. // Read and determine what operations should be shown on the menu
  53. // Note: uint16_t is used here to avoid compiler warning. uint8_t is only half the size of void*
  54. const uint8_t button_operation = PrusaErrorButtons(ei);
  55. const uint8_t button_op_right = BUTTON_OP_RIGHT(button_operation);
  56. const uint8_t button_op_middle = BUTTON_OP_MIDDLE(button_operation);
  57. // Check if the menu should have three or two choices
  58. if (button_op_right == (uint8_t)ButtonOperations::NoOperation){
  59. // Two operations not specified, the error menu should only show two choices
  60. two_choices = true;
  61. }
  62. back_to_choices:
  63. lcd_clear();
  64. lcd_update_enable(false);
  65. // Print title and header
  66. lcd_printf_P(PSTR("%.20S\nprusa3d.com/ERR04%hu"), _T(PrusaErrorTitle(ei)), PrusaErrorCode(ei) );
  67. // Render the choices and store selection in 'choice_selected'
  68. choice_selected = lcd_show_multiscreen_message_with_choices_and_wait_P(
  69. NULL, // NULL, since title screen is not in PROGMEM
  70. false,
  71. two_choices ? LCD_LEFT_BUTTON_CHOICE : LCD_MIDDLE_BUTTON_CHOICE, // beware - LEFT button on the LCD matches the MIDDLE button on the MMU!
  72. _T(PrusaErrorButtonTitle(button_op_middle)),
  73. _T(two_choices ? PrusaErrorButtonMore() : PrusaErrorButtonTitle(button_op_right)),
  74. two_choices ? nullptr : _T(PrusaErrorButtonMore()),
  75. two_choices ? 10 : 7 // If two choices, allow the first choice to have more characters
  76. );
  77. if ((two_choices && choice_selected == LCD_MIDDLE_BUTTON_CHOICE) // Two choices and middle button selected
  78. || (!two_choices && choice_selected == LCD_RIGHT_BUTTON_CHOICE)) // Three choices and right most button selected
  79. {
  80. // 'More' show error description
  81. lcd_show_fullscreen_message_and_wait_P(_T(PrusaErrorDesc(ei)));
  82. // Return back to the choice menu
  83. goto back_to_choices;
  84. } else if(choice_selected == LCD_MIDDLE_BUTTON_CHOICE) {
  85. SetButtonResponse((ButtonOperations)button_op_right);
  86. } else {
  87. SetButtonResponse((ButtonOperations)button_op_middle);
  88. }
  89. // if any button/command selected, close the screen
  90. lcd_update_enable(true);
  91. lcd_return_to_status();
  92. }
  93. void ReportProgressHook(CommandInProgress cip, uint16_t ec) {
  94. custom_message_type = CustomMsg::MMUProgress;
  95. lcd_setstatuspgm( _T(ProgressCodeToText(ec)) );
  96. }
  97. } // namespace MMU2