mmu2_reporting.cpp 4.5 KB

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