My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2021 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 ENABLED(EASYTHREED_UI)
  24. #include "easythreed_ui.h"
  25. #include "pause.h"
  26. #include "../module/temperature.h"
  27. #include "../module/printcounter.h"
  28. #include "../sd/cardreader.h"
  29. #include "../gcode/queue.h"
  30. #include "../module/motion.h"
  31. #include "../module/planner.h"
  32. #include "../MarlinCore.h"
  33. EasythreedUI easythreed_ui;
  34. #define BTN_DEBOUNCE_MS 20
  35. void EasythreedUI::init() {
  36. SET_INPUT_PULLUP(BTN_HOME); SET_OUTPUT(BTN_HOME_GND);
  37. SET_INPUT_PULLUP(BTN_FEED); SET_OUTPUT(BTN_FEED_GND);
  38. SET_INPUT_PULLUP(BTN_RETRACT); SET_OUTPUT(BTN_RETRACT_GND);
  39. SET_INPUT_PULLUP(BTN_PRINT);
  40. SET_OUTPUT(EASYTHREED_LED_PIN);
  41. }
  42. void EasythreedUI::run() {
  43. blinkLED();
  44. loadButton();
  45. printButton();
  46. }
  47. enum LEDInterval : uint16_t {
  48. LED_OFF = 0,
  49. LED_ON = 4000,
  50. LED_BLINK_0 = 2500,
  51. LED_BLINK_1 = 1500,
  52. LED_BLINK_2 = 1000,
  53. LED_BLINK_3 = 800,
  54. LED_BLINK_4 = 500,
  55. LED_BLINK_5 = 300,
  56. LED_BLINK_6 = 150,
  57. LED_BLINK_7 = 50
  58. };
  59. uint16_t blink_interval_ms = LED_ON; // Status LED on Start button
  60. void EasythreedUI::blinkLED() {
  61. static millis_t prev_blink_interval_ms = 0, blink_start_ms = 0;
  62. if (blink_interval_ms == LED_OFF) { WRITE(EASYTHREED_LED_PIN, HIGH); return; } // OFF
  63. if (blink_interval_ms >= LED_ON) { WRITE(EASYTHREED_LED_PIN, LOW); return; } // ON
  64. const millis_t ms = millis();
  65. if (prev_blink_interval_ms != blink_interval_ms) {
  66. prev_blink_interval_ms = blink_interval_ms;
  67. blink_start_ms = ms;
  68. }
  69. if (PENDING(ms, blink_start_ms + blink_interval_ms))
  70. WRITE(EASYTHREED_LED_PIN, LOW);
  71. else if (PENDING(ms, blink_start_ms + 2 * blink_interval_ms))
  72. WRITE(EASYTHREED_LED_PIN, HIGH);
  73. else
  74. blink_start_ms = ms;
  75. }
  76. //
  77. // Filament Load/Unload Button
  78. // Load/Unload buttons are a 3 position switch with a common center ground.
  79. //
  80. void EasythreedUI::loadButton() {
  81. if (printingIsActive()) return;
  82. enum FilamentStatus : uint8_t { FS_IDLE, FS_PRESS, FS_CHECK, FS_PROCEED };
  83. static uint8_t filament_status = FS_IDLE;
  84. static millis_t filament_time = 0;
  85. switch (filament_status) {
  86. case FS_IDLE:
  87. if (!READ(BTN_RETRACT) || !READ(BTN_FEED)) { // If feed/retract switch is toggled...
  88. filament_status++; // ...proceed to next test.
  89. filament_time = millis();
  90. }
  91. break;
  92. case FS_PRESS:
  93. if (ELAPSED(millis(), filament_time + BTN_DEBOUNCE_MS)) { // After a short debounce delay...
  94. if (!READ(BTN_RETRACT) || !READ(BTN_FEED)) { // ...if switch still toggled...
  95. thermalManager.setTargetHotend(EXTRUDE_MINTEMP + 10, 0); // Start heating up
  96. blink_interval_ms = LED_BLINK_7; // Set the LED to blink fast
  97. filament_status++;
  98. }
  99. else
  100. filament_status = FS_IDLE; // Switch not toggled long enough
  101. }
  102. break;
  103. case FS_CHECK:
  104. if (READ(BTN_RETRACT) && READ(BTN_FEED)) { // Switch in center position (stop)
  105. blink_interval_ms = LED_ON; // LED on steady
  106. filament_status = FS_IDLE;
  107. thermalManager.disable_all_heaters();
  108. }
  109. else if (thermalManager.hotEnoughToExtrude(0)) { // Is the hotend hot enough to move material?
  110. filament_status++; // Proceed to feed / retract.
  111. blink_interval_ms = LED_BLINK_5; // Blink ~3 times per second
  112. }
  113. break;
  114. case FS_PROCEED: {
  115. // Feed or Retract just once. Hard abort all moves and return to idle on swicth release.
  116. static bool flag = false;
  117. if (READ(BTN_RETRACT) && READ(BTN_FEED)) { // Switch in center position (stop)
  118. flag = false; // Restore flag to false
  119. filament_status = FS_IDLE; // Go back to idle state
  120. quickstop_stepper(); // Hard-stop all the steppers ... now!
  121. thermalManager.disable_all_heaters(); // And disable all the heaters
  122. blink_interval_ms = LED_ON;
  123. }
  124. else if (!flag) {
  125. flag = true;
  126. queue.inject(!READ(BTN_RETRACT) ? F("G91\nG0 E10 F180\nG0 E-120 F180\nM104 S0") : F("G91\nG0 E100 F120\nM104 S0"));
  127. }
  128. } break;
  129. }
  130. }
  131. #if HAS_STEPPER_RESET
  132. void disableStepperDrivers();
  133. #endif
  134. //
  135. // Print Start/Pause/Resume Button
  136. //
  137. void EasythreedUI::printButton() {
  138. enum KeyStatus : uint8_t { KS_IDLE, KS_PRESS, KS_PROCEED };
  139. static uint8_t key_status = KS_IDLE;
  140. static millis_t key_time = 0;
  141. enum PrintFlag : uint8_t { PF_START, PF_PAUSE, PF_RESUME };
  142. static PrintFlag print_key_flag = PF_START;
  143. const millis_t ms = millis();
  144. switch (key_status) {
  145. case KS_IDLE:
  146. if (!READ(BTN_PRINT)) { // Print/Pause/Resume button pressed?
  147. key_time = ms; // Save start time
  148. key_status++; // Go to debounce test
  149. }
  150. break;
  151. case KS_PRESS:
  152. if (ELAPSED(ms, key_time + BTN_DEBOUNCE_MS)) // Wait for debounce interval to expire
  153. key_status = READ(BTN_PRINT) ? KS_IDLE : KS_PROCEED; // Proceed if still pressed
  154. break;
  155. case KS_PROCEED:
  156. if (!READ(BTN_PRINT)) break; // Wait for the button to be released
  157. key_status = KS_IDLE; // Ready for the next press
  158. if (PENDING(ms, key_time + 1200 - BTN_DEBOUNCE_MS)) { // Register a press < 1.2 seconds
  159. switch (print_key_flag) {
  160. case PF_START: { // The "Print" button starts an SD card print
  161. if (printingIsActive()) break; // Already printing? (find another line that checks for 'is planner doing anything else right now?')
  162. blink_interval_ms = LED_BLINK_2; // Blink the indicator LED at 1 second intervals
  163. print_key_flag = PF_PAUSE; // The "Print" button now pauses the print
  164. card.mount(); // Force SD card to mount - now!
  165. if (!card.isMounted) { // Failed to mount?
  166. blink_interval_ms = LED_OFF; // Turn off LED
  167. print_key_flag = PF_START;
  168. return; // Bail out
  169. }
  170. card.ls(); // List all files to serial output
  171. const uint16_t filecnt = card.countFilesInWorkDir(); // Count printable files in cwd
  172. if (filecnt == 0) return; // None are printable?
  173. card.selectFileByIndex(filecnt); // Select the last file according to current sort options
  174. card.openAndPrintFile(card.filename); // Start printing it
  175. break;
  176. }
  177. case PF_PAUSE: { // Pause printing (not currently firing)
  178. if (!printingIsActive()) break;
  179. blink_interval_ms = LED_ON; // Set indicator to steady ON
  180. queue.inject(F("M25")); // Queue Pause
  181. print_key_flag = PF_RESUME; // The "Print" button now resumes the print
  182. break;
  183. }
  184. case PF_RESUME: { // Resume printing
  185. if (printingIsActive()) break;
  186. blink_interval_ms = LED_BLINK_2; // Blink the indicator LED at 1 second intervals
  187. queue.inject(F("M24")); // Queue resume
  188. print_key_flag = PF_PAUSE; // The "Print" button now pauses the print
  189. break;
  190. }
  191. }
  192. }
  193. else { // Register a longer press
  194. if (print_key_flag == PF_START && !printingIsActive()) { // While not printing, this moves Z up 10mm
  195. blink_interval_ms = LED_ON;
  196. queue.inject(F("G91\nG0 Z10 F600\nG90")); // Raise Z soon after returning to main loop
  197. }
  198. else { // While printing, cancel print
  199. card.abortFilePrintSoon(); // There is a delay while the current steps play out
  200. blink_interval_ms = LED_OFF; // Turn off LED
  201. }
  202. planner.synchronize(); // Wait for commands already in the planner to finish
  203. TERN_(HAS_STEPPER_RESET, disableStepperDrivers()); // Disable all steppers - now!
  204. print_key_flag = PF_START; // The "Print" button now starts a new print
  205. }
  206. break;
  207. }
  208. }
  209. #endif // EASYTHREED_UI