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 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 <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 HAS_FAN
  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. * M<mode> Pin mode: 0=INPUT 1=OUTPUT 2=INPUT_PULLUP 3=INPUT_PULLDOWN
  39. */
  40. void GcodeSuite::M42() {
  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 (!parser.boolval('I') && pin_is_protected(pin)) return protected_pin_err();
  45. if (parser.seenval('M')) {
  46. switch (parser.value_byte()) {
  47. case 0: pinMode(pin, INPUT); break;
  48. case 1: pinMode(pin, OUTPUT); break;
  49. case 2: pinMode(pin, INPUT_PULLUP); break;
  50. #ifdef INPUT_PULLDOWN
  51. case 3: pinMode(pin, INPUT_PULLDOWN); break;
  52. #endif
  53. default: SERIAL_ECHOLNPGM("Invalid Pin Mode");
  54. }
  55. return;
  56. }
  57. if (!parser.seenval('S')) return;
  58. const byte pin_status = parser.value_byte();
  59. #if HAS_FAN
  60. switch (pin) {
  61. #if HAS_FAN0
  62. case FAN0_PIN: thermalManager.fan_speed[0] = pin_status; return;
  63. #endif
  64. #if HAS_FAN1
  65. case FAN1_PIN: thermalManager.fan_speed[1] = pin_status; return;
  66. #endif
  67. #if HAS_FAN2
  68. case FAN2_PIN: thermalManager.fan_speed[2] = pin_status; return;
  69. #endif
  70. #if HAS_FAN3
  71. case FAN3_PIN: thermalManager.fan_speed[3] = pin_status; return;
  72. #endif
  73. #if HAS_FAN4
  74. case FAN4_PIN: thermalManager.fan_speed[4] = pin_status; return;
  75. #endif
  76. #if HAS_FAN5
  77. case FAN5_PIN: thermalManager.fan_speed[5] = pin_status; return;
  78. #endif
  79. #if HAS_FAN6
  80. case FAN6_PIN: thermalManager.fan_speed[6] = pin_status; return;
  81. #endif
  82. #if HAS_FAN7
  83. case FAN7_PIN: thermalManager.fan_speed[7] = pin_status; return;
  84. #endif
  85. }
  86. #endif
  87. pinMode(pin, OUTPUT);
  88. extDigitalWrite(pin, pin_status);
  89. analogWrite(pin, pin_status);
  90. }