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.

bed_mesh_view_screen.cpp 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /****************************
  2. * bed_mesh_view_screen.cpp *
  3. ****************************/
  4. /****************************************************************************
  5. * Written By Marcio Teixeira 2020 *
  6. * *
  7. * This program is free software: you can redistribute it and/or modify *
  8. * it under the terms of the GNU General Public License as published by *
  9. * the Free Software Foundation, either version 3 of the License, or *
  10. * (at your option) any later version. *
  11. * *
  12. * This program is distributed in the hope that it will be useful, *
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15. * GNU General Public License for more details. *
  16. * *
  17. * To view a copy of the GNU General Public License, go to the following *
  18. * location: <https://www.gnu.org/licenses/>. *
  19. ****************************************************************************/
  20. #include "../config.h"
  21. #include "../screens.h"
  22. #include "../screen_data.h"
  23. #ifdef FTDI_BED_MESH_VIEW_SCREEN
  24. using namespace FTDI;
  25. using namespace Theme;
  26. using namespace ExtUI;
  27. constexpr static BedMeshViewScreenData &mydata = screen_data.BedMeshViewScreen;
  28. constexpr static float gaugeThickness = 0.25;
  29. #if ENABLED(TOUCH_UI_PORTRAIT)
  30. #define GRID_COLS 3
  31. #define GRID_ROWS 10
  32. #define MESH_POS BTN_POS(1, 2), BTN_SIZE(3,5)
  33. #define MESSAGE_POS BTN_POS(1, 7), BTN_SIZE(3,1)
  34. #define Z_LABEL_POS BTN_POS(1, 8), BTN_SIZE(1,1)
  35. #define Z_VALUE_POS BTN_POS(2, 8), BTN_SIZE(2,1)
  36. #define OKAY_POS BTN_POS(1,10), BTN_SIZE(3,1)
  37. #else
  38. #define GRID_COLS 5
  39. #define GRID_ROWS 5
  40. #define MESH_POS BTN_POS(1,1), BTN_SIZE(3,5)
  41. #define MESSAGE_POS BTN_POS(4,1), BTN_SIZE(2,1)
  42. #define Z_LABEL_POS BTN_POS(4,2), BTN_SIZE(2,1)
  43. #define Z_VALUE_POS BTN_POS(4,3), BTN_SIZE(2,1)
  44. #define OKAY_POS BTN_POS(4,5), BTN_SIZE(2,1)
  45. #endif
  46. static float meshGetter(uint8_t x, uint8_t y, void*) {
  47. xy_uint8_t pos;
  48. pos.x = x;
  49. pos.y = y;
  50. return ExtUI::getMeshPoint(pos);
  51. }
  52. void BedMeshViewScreen::onEntry() {
  53. mydata.highlight.x = -1;
  54. mydata.count = GRID_MAX_POINTS;
  55. mydata.message = nullptr;
  56. BaseScreen::onEntry();
  57. }
  58. void BedMeshViewScreen::drawHighlightedPointValue() {
  59. CommandProcessor cmd;
  60. cmd.font(Theme::font_medium)
  61. .cmd(COLOR_RGB(bg_text_enabled))
  62. .text(Z_LABEL_POS, GET_TEXT_F(MSG_MESH_EDIT_Z))
  63. .font(font_small);
  64. if (mydata.highlight.x != -1)
  65. draw_adjuster_value(cmd, Z_VALUE_POS, ExtUI::getMeshPoint(mydata.highlight), GET_TEXT_F(MSG_UNITS_MM), 4, 3);
  66. cmd.colors(action_btn)
  67. .tag(1).button(OKAY_POS, GET_TEXT_F(MSG_BUTTON_OKAY))
  68. .tag(0);
  69. if (mydata.message) cmd.text(MESSAGE_POS, mydata.message);
  70. }
  71. void BedMeshViewScreen::onRedraw(draw_mode_t what) {
  72. #define _INSET_POS(x,y,w,h) x + min(w,h)/10, y + min(w,h)/10, w - min(w,h)/5, h - min(w,h)/5
  73. #define INSET_POS(pos) _INSET_POS(pos)
  74. CommandProcessor cmd;
  75. if (what & BACKGROUND) {
  76. cmd.cmd(CLEAR_COLOR_RGB(bg_color))
  77. .cmd(CLEAR(true,true,true));
  78. drawMeshBackground(cmd, INSET_POS(MESH_POS));
  79. }
  80. if (what & FOREGROUND) {
  81. const float progress = sq(float(mydata.count) / GRID_MAX_POINTS);
  82. if (progress >= 1.0)
  83. drawHighlightedPointValue();
  84. drawMeshForeground(cmd, INSET_POS(MESH_POS), meshGetter, nullptr, pointToTag(mydata.highlight.x, mydata.highlight.y), progress);
  85. }
  86. }
  87. bool BedMeshViewScreen::onTouchEnd(uint8_t tag) {
  88. switch (tag) {
  89. case 1: GOTO_PREVIOUS(); return true;
  90. default: return tagToPoint(tag, mydata.highlight);
  91. }
  92. return true;
  93. }
  94. void BedMeshViewScreen::onMeshUpdate(const int8_t, const int8_t, const float) {
  95. if (AT_SCREEN(BedMeshViewScreen)) {
  96. onRefresh();
  97. ExtUI::yield();
  98. }
  99. }
  100. void BedMeshViewScreen::onMeshUpdate(const int8_t x, const int8_t y, const ExtUI::probe_state_t state) {
  101. switch (state) {
  102. case ExtUI::G29_START:
  103. mydata.message = nullptr;
  104. mydata.count = 0;
  105. break;
  106. case ExtUI::G29_FINISH:
  107. if (mydata.count == GRID_MAX_POINTS && ExtUI::getMeshValid())
  108. mydata.message = GET_TEXT_F(MSG_BED_MAPPING_DONE);
  109. else
  110. mydata.message = GET_TEXT_F(MSG_BED_MAPPING_INCOMPLETE);
  111. mydata.count = GRID_MAX_POINTS;
  112. break;
  113. case ExtUI::G26_START:
  114. mydata.message = nullptr;
  115. mydata.count = 0;
  116. break;
  117. case ExtUI::G26_FINISH:
  118. GOTO_SCREEN(StatusScreen);
  119. break;
  120. case ExtUI::G29_POINT_START:
  121. case ExtUI::G26_POINT_START:
  122. mydata.highlight.x = x;
  123. mydata.highlight.y = y;
  124. break;
  125. case ExtUI::G29_POINT_FINISH:
  126. case ExtUI::G26_POINT_FINISH:
  127. mydata.count++;
  128. break;
  129. }
  130. BedMeshViewScreen::onMeshUpdate(x, y, 0);
  131. }
  132. void BedMeshViewScreen::doProbe() {
  133. GOTO_SCREEN(BedMeshViewScreen);
  134. mydata.count = 0;
  135. injectCommands(F(BED_LEVELING_COMMANDS));
  136. }
  137. void BedMeshViewScreen::show() {
  138. injectCommands(F("G29 L1"));
  139. GOTO_SCREEN(BedMeshViewScreen);
  140. }
  141. #endif // FTDI_BED_MESH_VIEW_SCREEN