My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

M43.cpp 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../../inc/MarlinConfig.h"
  23. #if ENABLED(PINS_DEBUGGING)
  24. #include "../gcode.h"
  25. #include "../../Marlin.h" // for pin_is_protected
  26. #include "../../pins/pinsDebug.h"
  27. #include "../../module/endstops.h"
  28. #if HAS_Z_SERVO_PROBE
  29. #include "../../module/probe.h"
  30. #include "../../module/servo.h"
  31. #endif
  32. inline void toggle_pins() {
  33. const bool ignore_protection = parser.boolval('I');
  34. const int repeat = parser.intval('R', 1),
  35. start = PARSED_PIN_INDEX('S', 0),
  36. end = PARSED_PIN_INDEX('L', NUM_DIGITAL_PINS - 1),
  37. wait = parser.intval('W', 500);
  38. for (uint8_t i = start; i <= end; i++) {
  39. pin_t pin = GET_PIN_MAP_PIN(i);
  40. //report_pin_state_extended(pin, ignore_protection, false);
  41. if (!VALID_PIN(pin)) continue;
  42. if (!ignore_protection && pin_is_protected(pin)) {
  43. report_pin_state_extended(pin, ignore_protection, true, "Untouched ");
  44. SERIAL_EOL();
  45. }
  46. else {
  47. report_pin_state_extended(pin, ignore_protection, true, "Pulsing ");
  48. #if AVR_AT90USB1286_FAMILY // Teensy IDEs don't know about these pins so must use FASTIO
  49. if (pin == TEENSY_E2) {
  50. SET_OUTPUT(TEENSY_E2);
  51. for (int16_t j = 0; j < repeat; j++) {
  52. WRITE(TEENSY_E2, LOW); safe_delay(wait);
  53. WRITE(TEENSY_E2, HIGH); safe_delay(wait);
  54. WRITE(TEENSY_E2, LOW); safe_delay(wait);
  55. }
  56. }
  57. else if (pin == TEENSY_E3) {
  58. SET_OUTPUT(TEENSY_E3);
  59. for (int16_t j = 0; j < repeat; j++) {
  60. WRITE(TEENSY_E3, LOW); safe_delay(wait);
  61. WRITE(TEENSY_E3, HIGH); safe_delay(wait);
  62. WRITE(TEENSY_E3, LOW); safe_delay(wait);
  63. }
  64. }
  65. else
  66. #endif
  67. {
  68. pinMode(pin, OUTPUT);
  69. for (int16_t j = 0; j < repeat; j++) {
  70. digitalWrite(pin, 0); safe_delay(wait);
  71. digitalWrite(pin, 1); safe_delay(wait);
  72. digitalWrite(pin, 0); safe_delay(wait);
  73. }
  74. }
  75. }
  76. SERIAL_EOL();
  77. }
  78. SERIAL_ECHOLNPGM("Done.");
  79. } // toggle_pins
  80. inline void servo_probe_test() {
  81. #if !(NUM_SERVOS > 0 && HAS_SERVO_0)
  82. SERIAL_ERROR_START();
  83. SERIAL_ERRORLNPGM("SERVO not setup");
  84. #elif !HAS_Z_SERVO_PROBE
  85. SERIAL_ERROR_START();
  86. SERIAL_ERRORLNPGM("Z_PROBE_SERVO_NR not setup");
  87. #else // HAS_Z_SERVO_PROBE
  88. const uint8_t probe_index = parser.byteval('P', Z_PROBE_SERVO_NR);
  89. SERIAL_PROTOCOLLNPGM("Servo probe test");
  90. SERIAL_PROTOCOLLNPAIR(". using index: ", probe_index);
  91. SERIAL_PROTOCOLLNPAIR(". deploy angle: ", servo_angles[probe_index][0]);
  92. SERIAL_PROTOCOLLNPAIR(". stow angle: ", servo_angles[probe_index][1]);
  93. bool probe_inverting;
  94. #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
  95. #define PROBE_TEST_PIN Z_MIN_PIN
  96. SERIAL_PROTOCOLLNPAIR(". probe uses Z_MIN pin: ", PROBE_TEST_PIN);
  97. SERIAL_PROTOCOLLNPGM(". uses Z_MIN_ENDSTOP_INVERTING (ignores Z_MIN_PROBE_ENDSTOP_INVERTING)");
  98. SERIAL_PROTOCOLPGM(". Z_MIN_ENDSTOP_INVERTING: ");
  99. #if Z_MIN_ENDSTOP_INVERTING
  100. SERIAL_PROTOCOLLNPGM("true");
  101. #else
  102. SERIAL_PROTOCOLLNPGM("false");
  103. #endif
  104. probe_inverting = Z_MIN_ENDSTOP_INVERTING;
  105. #elif ENABLED(Z_MIN_PROBE_ENDSTOP)
  106. #define PROBE_TEST_PIN Z_MIN_PROBE_PIN
  107. SERIAL_PROTOCOLLNPAIR(". probe uses Z_MIN_PROBE_PIN: ", PROBE_TEST_PIN);
  108. SERIAL_PROTOCOLLNPGM(". uses Z_MIN_PROBE_ENDSTOP_INVERTING (ignores Z_MIN_ENDSTOP_INVERTING)");
  109. SERIAL_PROTOCOLPGM(". Z_MIN_PROBE_ENDSTOP_INVERTING: ");
  110. #if Z_MIN_PROBE_ENDSTOP_INVERTING
  111. SERIAL_PROTOCOLLNPGM("true");
  112. #else
  113. SERIAL_PROTOCOLLNPGM("false");
  114. #endif
  115. probe_inverting = Z_MIN_PROBE_ENDSTOP_INVERTING;
  116. #endif
  117. SERIAL_PROTOCOLLNPGM(". deploy & stow 4 times");
  118. SET_INPUT_PULLUP(PROBE_TEST_PIN);
  119. uint8_t i = 0;
  120. bool deploy_state, stow_state;
  121. do {
  122. MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][0]); // Deploy
  123. safe_delay(500);
  124. deploy_state = READ(PROBE_TEST_PIN);
  125. MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][1]); // Stow
  126. safe_delay(500);
  127. stow_state = READ(PROBE_TEST_PIN);
  128. } while (++i < 4);
  129. if (probe_inverting != deploy_state) SERIAL_PROTOCOLLNPGM("WARNING - INVERTING setting probably backwards");
  130. if (deploy_state != stow_state) {
  131. SERIAL_PROTOCOLLNPGM("BLTouch clone detected");
  132. if (deploy_state) {
  133. SERIAL_PROTOCOLLNPGM(". DEPLOYED state: HIGH (logic 1)");
  134. SERIAL_PROTOCOLLNPGM(". STOWED (triggered) state: LOW (logic 0)");
  135. }
  136. else {
  137. SERIAL_PROTOCOLLNPGM(". DEPLOYED state: LOW (logic 0)");
  138. SERIAL_PROTOCOLLNPGM(". STOWED (triggered) state: HIGH (logic 1)");
  139. }
  140. #if ENABLED(BLTOUCH)
  141. SERIAL_PROTOCOLLNPGM("ERROR: BLTOUCH enabled - set this device up as a Z Servo Probe with inverting as true.");
  142. #endif
  143. }
  144. else { // measure active signal length
  145. MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][0]); // Deploy
  146. safe_delay(500);
  147. SERIAL_PROTOCOLLNPGM("please trigger probe");
  148. uint16_t probe_counter = 0;
  149. // Allow 30 seconds max for operator to trigger probe
  150. for (uint16_t j = 0; j < 500 * 30 && probe_counter == 0 ; j++) {
  151. safe_delay(2);
  152. if (0 == j % (500 * 1)) gcode.reset_stepper_timeout(); // Keep steppers powered
  153. if (deploy_state != READ(PROBE_TEST_PIN)) { // probe triggered
  154. for (probe_counter = 1; probe_counter < 50 && deploy_state != READ(PROBE_TEST_PIN); ++probe_counter)
  155. safe_delay(2);
  156. if (probe_counter == 50)
  157. SERIAL_PROTOCOLLNPGM("Z Servo Probe detected"); // >= 100mS active time
  158. else if (probe_counter >= 2)
  159. SERIAL_PROTOCOLLNPAIR("BLTouch compatible probe detected - pulse width (+/- 4mS): ", probe_counter * 2); // allow 4 - 100mS pulse
  160. else
  161. SERIAL_PROTOCOLLNPGM("noise detected - please re-run test"); // less than 2mS pulse
  162. MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][1]); // Stow
  163. } // pulse detected
  164. } // for loop waiting for trigger
  165. if (probe_counter == 0) SERIAL_PROTOCOLLNPGM("trigger not detected");
  166. } // measure active signal length
  167. #endif
  168. } // servo_probe_test
  169. /**
  170. * M43: Pin debug - report pin state, watch pins, toggle pins and servo probe test/report
  171. *
  172. * M43 - report name and state of pin(s)
  173. * P<pin> Pin to read or watch. If omitted, reads all pins.
  174. * I Flag to ignore Marlin's pin protection.
  175. *
  176. * M43 W - Watch pins -reporting changes- until reset, click, or M108.
  177. * P<pin> Pin to read or watch. If omitted, read/watch all pins.
  178. * I Flag to ignore Marlin's pin protection.
  179. *
  180. * M43 E<bool> - Enable / disable background endstop monitoring
  181. * - Machine continues to operate
  182. * - Reports changes to endstops
  183. * - Toggles LED_PIN when an endstop changes
  184. * - Cannot reliably catch the 5mS pulse from BLTouch type probes
  185. *
  186. * M43 T - Toggle pin(s) and report which pin is being toggled
  187. * S<pin> - Start Pin number. If not given, will default to 0
  188. * L<pin> - End Pin number. If not given, will default to last pin defined for this board
  189. * I<bool> - Flag to ignore Marlin's pin protection. Use with caution!!!!
  190. * R - Repeat pulses on each pin this number of times before continueing to next pin
  191. * W - Wait time (in miliseconds) between pulses. If not given will default to 500
  192. *
  193. * M43 S - Servo probe test
  194. * P<index> - Probe index (optional - defaults to 0
  195. */
  196. void GcodeSuite::M43() {
  197. if (parser.seen('T')) { // must be first or else its "S" and "E" parameters will execute endstop or servo test
  198. toggle_pins();
  199. return;
  200. }
  201. // Enable or disable endstop monitoring
  202. if (parser.seen('E')) {
  203. endstops.monitor_flag = parser.value_bool();
  204. SERIAL_PROTOCOLPGM("endstop monitor ");
  205. serialprintPGM(endstops.monitor_flag ? PSTR("en") : PSTR("dis"));
  206. SERIAL_PROTOCOLLNPGM("abled");
  207. return;
  208. }
  209. if (parser.seen('S')) {
  210. servo_probe_test();
  211. return;
  212. }
  213. // Get the range of pins to test or watch
  214. uint8_t first_pin = PARSED_PIN_INDEX('P', 0),
  215. last_pin = parser.seenval('P') ? first_pin : NUMBER_PINS_TOTAL - 1;
  216. if (first_pin > last_pin) return;
  217. const bool ignore_protection = parser.boolval('I');
  218. // Watch until click, M108, or reset
  219. if (parser.boolval('W')) {
  220. SERIAL_PROTOCOLLNPGM("Watching pins");
  221. #ifdef ARDUINO_ARCH_SAM
  222. NOLESS(first_pin, 2); // don't hijack the UART pins
  223. #endif
  224. uint8_t pin_state[last_pin - first_pin + 1];
  225. for (uint8_t i = first_pin; i <= last_pin; i++) {
  226. pin_t pin = GET_PIN_MAP_PIN(i);
  227. if (!VALID_PIN(pin)) continue;
  228. if (!ignore_protection && pin_is_protected(pin)) continue;
  229. pinMode(pin, INPUT_PULLUP);
  230. delay(1);
  231. /*
  232. if (IS_ANALOG(pin))
  233. pin_state[pin - first_pin] = analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)); // int16_t pin_state[...]
  234. else
  235. //*/
  236. pin_state[i - first_pin] = digitalRead(pin);
  237. }
  238. #if HAS_RESUME_CONTINUE
  239. wait_for_user = true;
  240. KEEPALIVE_STATE(PAUSED_FOR_USER);
  241. #endif
  242. for (;;) {
  243. for (uint8_t i = first_pin; i <= last_pin; i++) {
  244. pin_t pin = GET_PIN_MAP_PIN(i);
  245. if (!VALID_PIN(pin)) continue;
  246. if (!ignore_protection && pin_is_protected(pin)) continue;
  247. const byte val =
  248. /*
  249. IS_ANALOG(pin)
  250. ? analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)) : // int16_t val
  251. :
  252. //*/
  253. digitalRead(pin);
  254. if (val != pin_state[i - first_pin]) {
  255. report_pin_state_extended(pin, ignore_protection, false);
  256. pin_state[i - first_pin] = val;
  257. }
  258. }
  259. #if HAS_RESUME_CONTINUE
  260. if (!wait_for_user) {
  261. KEEPALIVE_STATE(IN_HANDLER);
  262. break;
  263. }
  264. #endif
  265. safe_delay(200);
  266. }
  267. return;
  268. }
  269. // Report current state of selected pin(s)
  270. for (uint8_t i = first_pin; i <= last_pin; i++) {
  271. pin_t pin = GET_PIN_MAP_PIN(i);
  272. if (VALID_PIN(pin)) report_pin_state_extended(pin, ignore_protection, true);
  273. }
  274. }
  275. #endif // PINS_DEBUGGING