My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

M42.cpp 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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"); return;
  54. }
  55. }
  56. if (!parser.seenval('S')) return;
  57. const byte pin_status = parser.value_byte();
  58. #if HAS_FAN
  59. switch (pin) {
  60. #if HAS_FAN0
  61. case FAN0_PIN: thermalManager.fan_speed[0] = pin_status; return;
  62. #endif
  63. #if HAS_FAN1
  64. case FAN1_PIN: thermalManager.fan_speed[1] = pin_status; return;
  65. #endif
  66. #if HAS_FAN2
  67. case FAN2_PIN: thermalManager.fan_speed[2] = pin_status; return;
  68. #endif
  69. #if HAS_FAN3
  70. case FAN3_PIN: thermalManager.fan_speed[3] = pin_status; return;
  71. #endif
  72. #if HAS_FAN4
  73. case FAN4_PIN: thermalManager.fan_speed[4] = pin_status; return;
  74. #endif
  75. #if HAS_FAN5
  76. case FAN5_PIN: thermalManager.fan_speed[5] = pin_status; return;
  77. #endif
  78. #if HAS_FAN6
  79. case FAN6_PIN: thermalManager.fan_speed[6] = pin_status; return;
  80. #endif
  81. #if HAS_FAN7
  82. case FAN7_PIN: thermalManager.fan_speed[7] = pin_status; return;
  83. #endif
  84. }
  85. #endif
  86. pinMode(pin, OUTPUT);
  87. extDigitalWrite(pin, pin_status);
  88. analogWrite(pin, pin_status);
  89. }