mmu2_reporting.cpp 4.8 KB

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