mmu2_reporting.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #include "mmu2_reporting.h"
  2. #include "mmu2_error_converter.h"
  3. #include "mmu2/error_codes.h"
  4. #include "mmu2/buttons.h"
  5. #include "ultralcd.h"
  6. #include "language.h"
  7. namespace MMU2 {
  8. const char * const ProgressCodeToText(uint16_t pc); // we may join progress convertor and reporter together
  9. void BeginReport(CommandInProgress cip, uint16_t ec) {
  10. custom_message_type = CustomMsg::MMUProgress;
  11. lcd_setstatuspgm( ProgressCodeToText(ec) );
  12. }
  13. void EndReport(CommandInProgress cip, uint16_t ec) {
  14. // clear the status msg line - let the printed filename get visible again
  15. custom_message_type = CustomMsg::Status;
  16. }
  17. void ReportErrorHook(CommandInProgress cip, uint16_t ec) {
  18. //! Show an error screen
  19. //! When an MMU error occurs, the LCD content will look like this:
  20. //! |01234567890123456789|
  21. //! |MMU FW update needed| <- title/header of the error: max 20 characters
  22. //! |prusa3d.com/ERR04504| <- URL 20 characters
  23. //! | | <- empty line
  24. //! |>Retry >Done >MoreW| <- buttons
  25. const uint8_t ei = PrusaErrorCodeIndex(ec);
  26. uint8_t choice_selected = 0;
  27. bool two_choices = false;
  28. // Read and determine what operations should be shown on the menu
  29. // Note: uint16_t is used here to avoid compiler warning. uint8_t is only half the size of void*
  30. const uint8_t button_operation = PrusaErrorButtons(ei);
  31. const uint8_t button_high_nibble = BUTTON_OP_HI_NIBBLE(button_operation);
  32. const uint8_t button_low_nibble = BUTTON_OP_LO_NIBBLE(button_operation);
  33. // Check if the menu should have three or two choices
  34. if (button_high_nibble == (uint8_t)ButtonOperations::NoOperation)
  35. {
  36. // Two operations not specified, the error menu should only show two choices
  37. two_choices = true;
  38. }
  39. back_to_choices:
  40. lcd_clear();
  41. lcd_update_enable(false);
  42. // Print title and header
  43. lcd_printf_P(PSTR("%S\nprusa3d.com/ERR04%hu"), _T(PrusaErrorTitle(ei)), PrusaErrorCode(ei) );
  44. // Render the choices and store selection in 'choice_selected'
  45. choice_selected = lcd_show_multiscreen_message_with_choices_and_wait_P(
  46. NULL, // NULL, since title screen is not in PROGMEM
  47. false,
  48. two_choices ? LEFT_BUTTON_CHOICE : MIDDLE_BUTTON_CHOICE,
  49. _T(PrusaErrorButtonTitle(button_low_nibble - 1)),
  50. _T(two_choices ? PrusaErrorButtonMore() : PrusaErrorButtonTitle(button_high_nibble - 1)),
  51. two_choices ? nullptr : _T(PrusaErrorButtonMore()),
  52. two_choices ?
  53. 10 // If two choices, allow the first choice to have more characters
  54. : 7
  55. );
  56. if ((two_choices && choice_selected == MIDDLE_BUTTON_CHOICE) // Two choices and middle button selected
  57. || (!two_choices && choice_selected == RIGHT_BUTTON_CHOICE)) // Three choices and right most button selected
  58. {
  59. // 'More' show error description
  60. lcd_show_fullscreen_message_and_wait_P(_T(PrusaErrorDesc(ei)));
  61. // Return back to the choice menu
  62. goto back_to_choices;
  63. } else if(choice_selected == MIDDLE_BUTTON_CHOICE) {
  64. // TODO: User selected middle choice, not sure what to do.
  65. // At the moment just return to the status screen
  66. switch (button_high_nibble)
  67. {
  68. case (uint8_t)ButtonOperations::Retry:
  69. case (uint8_t)ButtonOperations::Continue:
  70. case (uint8_t)ButtonOperations::RestartMMU:
  71. case (uint8_t)ButtonOperations::Unload:
  72. case (uint8_t)ButtonOperations::StopPrint:
  73. case (uint8_t)ButtonOperations::DisableMMU:
  74. default:
  75. lcd_update_enable(true);
  76. lcd_return_to_status();
  77. break;
  78. }
  79. } else {
  80. // TODO: User selected the left most choice, not sure what to do.
  81. // At the moment just return to the status screen
  82. switch (button_low_nibble)
  83. {
  84. case (uint8_t)ButtonOperations::Retry:
  85. case (uint8_t)ButtonOperations::Continue:
  86. case (uint8_t)ButtonOperations::RestartMMU:
  87. case (uint8_t)ButtonOperations::Unload:
  88. case (uint8_t)ButtonOperations::StopPrint:
  89. case (uint8_t)ButtonOperations::DisableMMU:
  90. default:
  91. lcd_update_enable(true);
  92. lcd_return_to_status();
  93. break;
  94. }
  95. }
  96. }
  97. void ReportProgressHook(CommandInProgress cip, uint16_t ec) {
  98. custom_message_type = CustomMsg::MMUProgress;
  99. lcd_setstatuspgm( _T(ProgressCodeToText(ec)) );
  100. }
  101. Buttons ButtonPressed(uint16_t ec) {
  102. // query the MMU error screen if a button has been pressed/selected
  103. }
  104. } // namespace MMU2