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.

M42.cpp 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 "../gcode.h"
  23. #include "../../Marlin.h" // for pin_is_protected
  24. #include "../../inc/MarlinConfig.h"
  25. /**
  26. * M42: Change pin status via GCode
  27. *
  28. * P<pin> Pin number (LED if omitted)
  29. * For LPC1768 specify pin P1_02 as M42 P102,
  30. * P1_20 as M42 P120, etc.
  31. *
  32. * S<byte> Pin status from 0 - 255
  33. */
  34. void GcodeSuite::M42() {
  35. if (!parser.seenval('S')) return;
  36. const byte pin_status = parser.value_byte();
  37. int pin_number = PARSED_PIN_INDEX('P', GET_PIN_MAP_INDEX(LED_PIN));
  38. if (pin_number < 0) return;
  39. const pin_t pin = GET_PIN_MAP_PIN(pin_number);
  40. if (pin_is_protected(pin)) {
  41. SERIAL_ERROR_START();
  42. SERIAL_ERRORLNPGM(MSG_ERR_PROTECTED_PIN);
  43. return;
  44. }
  45. pinMode(pin, OUTPUT);
  46. digitalWrite(pin, pin_status);
  47. analogWrite(pin, pin_status);
  48. #if FAN_COUNT > 0
  49. switch (pin) {
  50. #if HAS_FAN0
  51. case FAN_PIN: fanSpeeds[0] = pin_status; break;
  52. #endif
  53. #if HAS_FAN1
  54. case FAN1_PIN: fanSpeeds[1] = pin_status; break;
  55. #endif
  56. #if HAS_FAN2
  57. case FAN2_PIN: fanSpeeds[2] = pin_status; break;
  58. #endif
  59. }
  60. #endif
  61. }