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.

draw_gcode.cpp 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  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. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../../../../inc/MarlinConfigPre.h"
  23. #if HAS_TFT_LVGL_UI
  24. #include "draw_ui.h"
  25. #include <lv_conf.h>
  26. #include "../../../../inc/MarlinConfig.h"
  27. extern lv_group_t *g;
  28. static lv_obj_t *scr,*outL,*outV = 0;
  29. static int currentWritePos = 0;
  30. extern uint8_t public_buf[513];
  31. extern "C" { extern char public_buf_m[100]; }
  32. enum {
  33. ID_GCODE_RETURN = 1,
  34. ID_GCODE_COMMAND,
  35. };
  36. static void event_handler(lv_obj_t *obj, lv_event_t event) {
  37. if (event != LV_EVENT_RELEASED) return;
  38. lv_clear_gcode();
  39. switch (obj->mks_obj_id) {
  40. case ID_GCODE_RETURN:
  41. lv_draw_more();
  42. return;
  43. case ID_GCODE_COMMAND:
  44. keyboard_value = GCodeCommand;
  45. lv_draw_keyboard();
  46. break;
  47. }
  48. }
  49. void lv_show_gcode_output(void * that, const char * txt) {
  50. // Ignore echo of command
  51. if (!memcmp(txt, "echo:", 5)) {
  52. public_buf[0] = 0; // Clear output buffer
  53. return;
  54. }
  55. // Avoid overflow if the answer is too large
  56. size_t len = strlen((const char*)public_buf), tlen = strlen(txt);
  57. if (len + tlen + 1 < sizeof(public_buf)) {
  58. memcpy(public_buf + len, txt, tlen);
  59. public_buf[len + tlen] = '\n';
  60. }
  61. }
  62. void lv_serial_capt_hook(void * userPointer, uint8_t c)
  63. {
  64. if (c == '\n' || currentWritePos == sizeof(public_buf_m) - 1) { // End of line, probably end of command anyway
  65. public_buf_m[currentWritePos] = 0;
  66. lv_show_gcode_output(userPointer, public_buf_m);
  67. currentWritePos = 0;
  68. }
  69. else public_buf_m[currentWritePos++] = c;
  70. }
  71. void lv_eom_hook(void *)
  72. {
  73. // Message is done, let's remove the hook now
  74. MYSERIAL1.setHook();
  75. // We are back from the keyboard, so let's redraw ourselves
  76. draw_return_ui();
  77. }
  78. void lv_draw_gcode(bool clear) {
  79. if (clear) {
  80. currentWritePos = 0;
  81. public_buf[0] = 0;
  82. }
  83. scr = lv_screen_create(GCODE_UI, more_menu.gcode);
  84. lv_screen_menu_item(scr, more_menu.entergcode, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_GCODE_COMMAND, 1);
  85. outL = lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 2, "Result:");
  86. outV = lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 3, (const char*)public_buf);
  87. lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X + 10, PARA_UI_BACL_POS_Y, event_handler, ID_GCODE_RETURN, true);
  88. }
  89. void lv_clear_gcode() {
  90. #if HAS_ROTARY_ENCODER
  91. if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
  92. #endif
  93. lv_obj_del(scr);
  94. outV = 0;
  95. }
  96. #endif // HAS_TFT_LVGL_UI