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.

M280.cpp 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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/MarlinConfig.h"
  23. #if HAS_SERVOS
  24. #include "../gcode.h"
  25. #include "../../module/servo.h"
  26. #include "../../module/planner.h"
  27. /**
  28. * M280: Get or set servo position.
  29. * P<index> - Servo index
  30. * S<angle> - Angle to set, omit to read current angle, or use -1 to detach
  31. *
  32. * With POLARGRAPH:
  33. * T<ms> - Duration of servo move
  34. */
  35. void GcodeSuite::M280() {
  36. if (!parser.seenval('P')) return;
  37. TERN_(POLARGRAPH, planner.synchronize());
  38. const int servo_index = parser.value_int();
  39. if (WITHIN(servo_index, 0, NUM_SERVOS - 1)) {
  40. if (parser.seenval('S')) {
  41. const int anew = parser.value_int();
  42. if (anew >= 0) {
  43. #if ENABLED(POLARGRAPH)
  44. if (parser.seenval('T')) { // (ms) Total duration of servo move
  45. const int16_t t = constrain(parser.value_int(), 0, 10000);
  46. const int aold = servo[servo_index].read();
  47. millis_t now = millis();
  48. const millis_t start = now, end = start + t;
  49. while (PENDING(now, end)) {
  50. safe_delay(50);
  51. now = _MIN(millis(), end);
  52. servo[servo_index].move(LROUND(aold + (anew - aold) * (float(now - start) / t)));
  53. }
  54. }
  55. #endif // POLARGRAPH
  56. servo[servo_index].move(anew);
  57. }
  58. else
  59. servo[servo_index].detach();
  60. }
  61. else
  62. SERIAL_ECHO_MSG(" Servo ", servo_index, ": ", servo[servo_index].read());
  63. }
  64. else
  65. SERIAL_ERROR_MSG("Servo ", servo_index, " out of range");
  66. }
  67. #endif // HAS_SERVOS