mmu2_reporting.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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_high_nibble = BUTTON_OP_HI_NIBBLE(button_operation);
  55. const uint8_t button_low_nibble = BUTTON_OP_LO_NIBBLE(button_operation);
  56. // Check if the menu should have three or two choices
  57. if (button_high_nibble == (uint8_t)ButtonOperations::NoOperation)
  58. {
  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 static characters in third line
  68. lcd_set_cursor(0, 2);
  69. lcd_printf_P(PSTR("FI: FS: > %c %c"), LCD_STR_THERMOMETER[0], LCD_STR_DEGREE[0]);
  70. // Render the choices and store selection in 'choice_selected'
  71. choice_selected = lcd_show_multiscreen_message_with_choices_and_wait_P(
  72. NULL, // NULL, since title screen is not in PROGMEM
  73. false,
  74. two_choices ? LEFT_BUTTON_CHOICE : MIDDLE_BUTTON_CHOICE,
  75. _T(PrusaErrorButtonTitle(button_low_nibble)),
  76. _T(two_choices ? PrusaErrorButtonMore() : PrusaErrorButtonTitle(button_high_nibble)),
  77. two_choices ? nullptr : _T(PrusaErrorButtonMore()),
  78. two_choices ?
  79. 10 // If two choices, allow the first choice to have more characters
  80. : 7,
  81. ReportErrorHook_cb
  82. );
  83. if ((two_choices && choice_selected == MIDDLE_BUTTON_CHOICE) // Two choices and middle button selected
  84. || (!two_choices && choice_selected == RIGHT_BUTTON_CHOICE)) // Three choices and right most button selected
  85. {
  86. // 'More' show error description
  87. lcd_show_fullscreen_message_and_wait_P(_T(PrusaErrorDesc(ei)));
  88. // Return back to the choice menu
  89. goto back_to_choices;
  90. } else if(choice_selected == MIDDLE_BUTTON_CHOICE) {
  91. // TODO: User selected middle choice, not sure what to do.
  92. // At the moment just return to the status screen
  93. switch (button_high_nibble)
  94. {
  95. case (uint8_t)ButtonOperations::Retry:
  96. case (uint8_t)ButtonOperations::Continue:
  97. case (uint8_t)ButtonOperations::RestartMMU:
  98. case (uint8_t)ButtonOperations::Unload:
  99. case (uint8_t)ButtonOperations::StopPrint:
  100. case (uint8_t)ButtonOperations::DisableMMU:
  101. default:
  102. lcd_update_enable(true);
  103. lcd_return_to_status();
  104. break;
  105. }
  106. } else {
  107. // TODO: User selected the left most choice, not sure what to do.
  108. // At the moment just return to the status screen
  109. switch (button_low_nibble)
  110. {
  111. case (uint8_t)ButtonOperations::Retry:
  112. case (uint8_t)ButtonOperations::Continue:
  113. case (uint8_t)ButtonOperations::RestartMMU:
  114. case (uint8_t)ButtonOperations::Unload:
  115. case (uint8_t)ButtonOperations::StopPrint:
  116. case (uint8_t)ButtonOperations::DisableMMU:
  117. default:
  118. lcd_update_enable(true);
  119. lcd_return_to_status();
  120. break;
  121. }
  122. }
  123. }
  124. void ReportProgressHook(CommandInProgress cip, uint16_t ec) {
  125. custom_message_type = CustomMsg::MMUProgress;
  126. lcd_setstatuspgm( _T(ProgressCodeToText(ec)) );
  127. }
  128. Buttons ButtonPressed(uint16_t ec) {
  129. // query the MMU error screen if a button has been pressed/selected
  130. }
  131. } // namespace MMU2