My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stress_test_screen.cpp 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /**************************
  2. * stress_test_screen.cpp *
  3. **************************/
  4. /****************************************************************************
  5. * Written By Mark Pelletier 2017 - Aleph Objects, Inc. *
  6. * Written By Marcio Teixeira 2018 - Aleph Objects, Inc. *
  7. * *
  8. * This program is free software: you can redistribute it and/or modify *
  9. * it under the terms of the GNU General Public License as published by *
  10. * the Free Software Foundation, either version 3 of the License, or *
  11. * (at your option) any later version. *
  12. * *
  13. * This program is distributed in the hope that it will be useful, *
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  16. * GNU General Public License for more details. *
  17. * *
  18. * To view a copy of the GNU General Public License, go to the following *
  19. * location: <https://www.gnu.org/licenses/>. *
  20. ****************************************************************************/
  21. #include "../config.h"
  22. #include "../screens.h"
  23. #include "../screen_data.h"
  24. #ifdef FTDI_STRESS_TEST_SCREEN
  25. #define STRESS_TEST_CHANGE_INTERVAL 6000
  26. #define GRID_COLS 4
  27. #define GRID_ROWS 9
  28. using namespace FTDI;
  29. using namespace Theme;
  30. using namespace ExtUI;
  31. constexpr static StressTestScreenData &mydata = screen_data.StressTestScreen;
  32. void StressTestScreen::drawDots(uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
  33. CommandProcessor cmd;
  34. for (uint8_t i = 0; i < 100; i++) {
  35. cmd.cmd(BEGIN(POINTS))
  36. .cmd(POINT_SIZE(20*16))
  37. .cmd(COLOR_RGB(random(0xFFFFFF)))
  38. .cmd(VERTEX2F((x + random(w)) * 16,(y + random(h)) * 16));
  39. }
  40. }
  41. bool StressTestScreen::watchDogTestNow() {
  42. return mydata.next_watchdog_trigger &&
  43. ELAPSED(millis(), mydata.next_watchdog_trigger);
  44. }
  45. void StressTestScreen::onRedraw(draw_mode_t) {
  46. using namespace ExtUI;
  47. CommandProcessor cmd;
  48. cmd.cmd(CLEAR_COLOR_RGB(bg_color))
  49. .cmd(CLEAR(true,true,true))
  50. .cmd(COLOR_RGB(bg_text_enabled))
  51. .font(font_medium)
  52. .text(BTN_POS(1,1), BTN_SIZE(4,1), FPSTR(mydata.message));
  53. drawDots(BTN_POS(1,3), BTN_SIZE(4,4));
  54. cmd.font(font_medium).enabled(!watchDogTestNow()).colors(action_btn).tag(1).button(BTN_POS(2,8), BTN_SIZE(2,1), F("Exit"));
  55. }
  56. bool StressTestScreen::onTouchEnd(uint8_t tag) {
  57. CommandProcessor cmd;
  58. switch (tag) {
  59. case 1:
  60. runTestOnBootup(false);
  61. GOTO_SCREEN(StatusScreen);
  62. break;
  63. default:
  64. return false;
  65. }
  66. return true;
  67. }
  68. void StressTestScreen::runTestOnBootup(bool enable) {
  69. // Use a magic value in passcode to indicate
  70. // whether or not we need to re-run the test
  71. // at startup.
  72. LockScreen::set_hash(enable ? 0xDEAD : 0);
  73. injectCommands(F("M500"));
  74. }
  75. void StressTestScreen::startupCheck() {
  76. if (LockScreen::get_hash() == 0xDEAD)
  77. GOTO_SCREEN(StressTestScreen);
  78. }
  79. void StressTestScreen::onEntry() {
  80. mydata.next_watchdog_trigger = millis() + 10000 + random(40000);
  81. mydata.message = PSTR("Test 1: Stress testing...");
  82. // Turn off heaters.
  83. coolDown();
  84. runTestOnBootup(true);
  85. }
  86. void StressTestScreen::recursiveLockup() {
  87. mydata.message = PSTR("Test 2: Printer will restart.");
  88. current_screen.onRefresh();
  89. recursiveLockup();
  90. }
  91. void StressTestScreen::iterativeLockup() {
  92. mydata.message = PSTR("Test 3: Printer will restart.");
  93. for (;;) current_screen.onRefresh();
  94. }
  95. void StressTestScreen::onIdle() {
  96. current_screen.onRefresh();
  97. reset_menu_timeout();
  98. if (!commandsInQueue()) {
  99. if (!isPositionKnown()) {
  100. injectCommands_P(G28_STR);
  101. }
  102. else {
  103. injectCommands(F(
  104. "G0 X100 Y100 Z100 F6000\n"
  105. "T0\nG4 S1"
  106. E_TERN_("\nT1\nG4 S1")
  107. "\nG0 X150 Y150 Z150"
  108. ));
  109. }
  110. }
  111. if (refresh_timer.elapsed(STRESS_TEST_CHANGE_INTERVAL)) {
  112. setTargetFan_percent(random(100),FAN0);
  113. }
  114. if (watchDogTestNow()) {
  115. if (random(2) % 2)
  116. iterativeLockup();
  117. else
  118. recursiveLockup();
  119. }
  120. BaseScreen::onIdle();
  121. }
  122. #endif // FTDI_STRESS_TEST_SCREEN