mmu2_reporting.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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_low_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. false,
  51. two_choices ?
  52. static_cast<const char * const>(pgm_read_ptr(&btnOperation[button_high_nibble - 1]))
  53. : static_cast<const char * const>(pgm_read_ptr(&btnOperation[button_low_nibble - 1])),
  54. two_choices ?
  55. btnMore
  56. : static_cast<const char * const>(pgm_read_ptr(&btnOperation[button_high_nibble - 1])),
  57. two_choices ? nullptr : btnMore,
  58. two_choices ?
  59. 10 // If two choices, allow the first choice to have more characters
  60. : 7
  61. );
  62. if ((two_choices && choice_selected == MIDDLE_BUTTON_CHOICE) // Two choices and middle button selected
  63. || (!two_choices && choice_selected == RIGHT_BUTTON_CHOICE)) // Three choices and right most button selected
  64. {
  65. // 'More' show error description
  66. lcd_show_fullscreen_message_and_wait_P(
  67. static_cast<const char * const>(pgm_read_ptr(&errorDescs[ei]))
  68. );
  69. // Return back to the choice menu
  70. goto back_to_choices;
  71. } else if(choice_selected == MIDDLE_BUTTON_CHOICE) {
  72. // TODO: User selected middle choice, not sure what to do.
  73. // At the moment just return to the status screen
  74. switch (button_high_nibble)
  75. {
  76. case (uint8_t)ButtonOperations::Retry:
  77. case (uint8_t)ButtonOperations::SlowLoad:
  78. case (uint8_t)ButtonOperations::Continue:
  79. case (uint8_t)ButtonOperations::RestartMMU:
  80. case (uint8_t)ButtonOperations::Unload:
  81. case (uint8_t)ButtonOperations::StopPrint:
  82. case (uint8_t)ButtonOperations::DisableMMU:
  83. default:
  84. lcd_update_enable(true);
  85. lcd_return_to_status();
  86. break;
  87. }
  88. } else {
  89. // TODO: User selected the left most choice, not sure what to do.
  90. // At the moment just return to the status screen
  91. switch ( two_choices ?
  92. button_high_nibble
  93. : button_low_nibble
  94. )
  95. {
  96. case (uint8_t)ButtonOperations::Retry:
  97. case (uint8_t)ButtonOperations::SlowLoad:
  98. case (uint8_t)ButtonOperations::Continue:
  99. case (uint8_t)ButtonOperations::RestartMMU:
  100. case (uint8_t)ButtonOperations::Unload:
  101. case (uint8_t)ButtonOperations::StopPrint:
  102. case (uint8_t)ButtonOperations::DisableMMU:
  103. default:
  104. lcd_update_enable(true);
  105. lcd_return_to_status();
  106. break;
  107. }
  108. }
  109. }
  110. void ReportProgressHook(CommandInProgress cip, uint16_t ec) {
  111. custom_message_type = CustomMsg::MMUProgress;
  112. lcd_setstatuspgm( ProgressCodeToText(ec) );
  113. }
  114. Buttons ButtonPressed(uint16_t ec) {
  115. // query the MMU error screen if a button has been pressed/selected
  116. }
  117. } // namespace MMU2