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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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: <http://www.gnu.org/licenses/>. *
  20. ****************************************************************************/
  21. #include "../config.h"
  22. #if BOTH(TOUCH_UI_FTDI_EVE, TOUCH_UI_DEVELOPER_MENU)
  23. #include "screens.h"
  24. #include "screen_data.h"
  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. void StressTestScreen::drawDots(uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
  32. CommandProcessor cmd;
  33. for(uint8_t i = 0; i < 100; i++) {
  34. cmd.cmd(BEGIN(POINTS))
  35. .cmd(POINT_SIZE(20*16))
  36. .cmd(COLOR_RGB(random(0xFFFFFF)))
  37. .cmd(VERTEX2F((x + random(w)) * 16,(y + random(h)) * 16));
  38. }
  39. }
  40. bool StressTestScreen::watchDogTestNow() {
  41. return screen_data.StressTestScreen.next_watchdog_trigger &&
  42. ELAPSED(millis(), screen_data.StressTestScreen.next_watchdog_trigger);
  43. }
  44. void StressTestScreen::onRedraw(draw_mode_t) {
  45. using namespace ExtUI;
  46. CommandProcessor cmd;
  47. cmd.cmd(CLEAR_COLOR_RGB(bg_color))
  48. .cmd(CLEAR(true,true,true))
  49. .cmd(COLOR_RGB(bg_text_enabled))
  50. .font(font_medium)
  51. .text(BTN_POS(1,1), BTN_SIZE(4,1), progmem_str(screen_data.StressTestScreen.message));
  52. drawDots(BTN_POS(1,3), BTN_SIZE(4,4));
  53. cmd.font(font_medium).enabled(!watchDogTestNow()).colors(action_btn).tag(1).button(BTN_POS(2,8), BTN_SIZE(2,1), F("Exit"));
  54. }
  55. bool StressTestScreen::onTouchEnd(uint8_t tag) {
  56. CommandProcessor cmd;
  57. switch (tag) {
  58. case 1:
  59. runTestOnBootup(false);
  60. GOTO_SCREEN(StatusScreen);
  61. break;
  62. default:
  63. return false;
  64. }
  65. return true;
  66. }
  67. void StressTestScreen::runTestOnBootup(bool enable) {
  68. // Use a magic value in passcode to indicate
  69. // whether or not we need to re-run the test
  70. // at startup.
  71. LockScreen::set_hash(enable ? 0xDEAD : 0);
  72. injectCommands_P(PSTR("M500"));
  73. }
  74. void StressTestScreen::startupCheck() {
  75. if (LockScreen::get_hash() == 0xDEAD) {
  76. GOTO_SCREEN(StressTestScreen);
  77. }
  78. }
  79. void StressTestScreen::onEntry() {
  80. screen_data.StressTestScreen.next_watchdog_trigger = millis() + 10000 + random(40000);
  81. screen_data.StressTestScreen.message = PSTR("Test 1: Stress testing...");
  82. // Turn off heaters.
  83. setTargetTemp_celsius(0, E0);
  84. setTargetTemp_celsius(0, E1);
  85. setTargetTemp_celsius(0, BED);
  86. runTestOnBootup(true);
  87. }
  88. void StressTestScreen::recursiveLockup() {
  89. screen_data.StressTestScreen.message = PSTR("Test 2: Printer will restart.");
  90. current_screen.onRefresh();
  91. recursiveLockup();
  92. }
  93. void StressTestScreen::iterativeLockup() {
  94. screen_data.StressTestScreen.message = PSTR("Test 3: Printer will restart.");
  95. for(;;) current_screen.onRefresh();
  96. }
  97. void StressTestScreen::onIdle() {
  98. current_screen.onRefresh();
  99. reset_menu_timeout();
  100. if (!commandsInQueue()) {
  101. if (!isPositionKnown()) {
  102. extern const char G28_STR[];
  103. injectCommands_P(G28_STR);
  104. } else {
  105. injectCommands_P(PSTR(
  106. "G0 X100 Y100 Z100 F6000\n"
  107. "T0\nG4 S1"
  108. #if EXTRUDERS > 1
  109. "\nT1\nG4 S1"
  110. #endif
  111. "\nG0 X150 Y150 Z150"
  112. ));
  113. }
  114. }
  115. if (refresh_timer.elapsed(STRESS_TEST_CHANGE_INTERVAL)) {
  116. setTargetFan_percent(random(100),FAN0);
  117. }
  118. if (watchDogTestNow()) {
  119. if (random(2) % 2)
  120. iterativeLockup();
  121. else
  122. recursiveLockup();
  123. }
  124. BaseScreen::onIdle();
  125. }
  126. #endif // TOUCH_UI_FTDI_EVE