My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

M42.cpp 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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 "../../MarlinCore.h" // for pin_is_protected
  24. #include "../../inc/MarlinConfig.h"
  25. #if FAN_COUNT > 0
  26. #include "../../module/temperature.h"
  27. #endif
  28. /**
  29. * M42: Change pin status via GCode
  30. *
  31. * P<pin> Pin number (LED if omitted)
  32. * For LPC1768 specify pin P1_02 as M42 P102,
  33. * P1_20 as M42 P120, etc.
  34. *
  35. * S<byte> Pin status from 0 - 255
  36. * I Flag to ignore Marlin's pin protection
  37. */
  38. void GcodeSuite::M42() {
  39. if (!parser.seenval('S')) return;
  40. const byte pin_status = parser.value_byte();
  41. const int pin_index = PARSED_PIN_INDEX('P', GET_PIN_MAP_INDEX(LED_PIN));
  42. if (pin_index < 0) return;
  43. const pin_t pin = GET_PIN_MAP_PIN(pin_index);
  44. #if FAN_COUNT > 0
  45. switch (pin) {
  46. #if HAS_FAN0
  47. case FAN0_PIN: thermalManager.fan_speed[0] = pin_status; return;
  48. #endif
  49. #if HAS_FAN1
  50. case FAN1_PIN: thermalManager.fan_speed[1] = pin_status; return;
  51. #endif
  52. #if HAS_FAN2
  53. case FAN2_PIN: thermalManager.fan_speed[2] = pin_status; return;
  54. #endif
  55. #if HAS_FAN3
  56. case FAN3_PIN: thermalManager.fan_speed[3] = pin_status; return;
  57. #endif
  58. #if HAS_FAN4
  59. case FAN4_PIN: thermalManager.fan_speed[4] = pin_status; return;
  60. #endif
  61. #if HAS_FAN5
  62. case FAN5_PIN: thermalManager.fan_speed[5] = pin_status; return;
  63. #endif
  64. #if HAS_FAN6
  65. case FAN6_PIN: thermalManager.fan_speed[6] = pin_status; return;
  66. #endif
  67. #if HAS_FAN7
  68. case FAN7_PIN: thermalManager.fan_speed[7] = pin_status; return;
  69. #endif
  70. }
  71. #endif
  72. if (!parser.boolval('I') && pin_is_protected(pin)) return protected_pin_err();
  73. pinMode(pin, OUTPUT);
  74. extDigitalWrite(pin, pin_status);
  75. analogWrite(pin, pin_status);
  76. }