My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

M150.cpp 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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_COLOR_LEDS
  24. #include "../../gcode.h"
  25. #include "../../../feature/leds/leds.h"
  26. /**
  27. * M150: Set Status LED Color - Use R-U-B-W for R-G-B-W
  28. * and Brightness - Use P (for NEOPIXEL only)
  29. *
  30. * Always sets all 3 or 4 components unless the K flag is specified.
  31. * If a component is left out, set to 0.
  32. * If brightness is left out, no value changed.
  33. *
  34. * With NEOPIXEL_LED:
  35. * I<index> Set the NeoPixel index to affect. Default: All
  36. * K Keep all unspecified values unchanged instead of setting to 0.
  37. *
  38. * With NEOPIXEL2_SEPARATE:
  39. * S<index> The NeoPixel strip to set. Default: All.
  40. *
  41. * Examples:
  42. *
  43. * M150 R255 ; Turn LED red
  44. * M150 R255 U127 ; Turn LED orange (PWM only)
  45. * M150 ; Turn LED off
  46. * M150 R U B ; Turn LED white
  47. * M150 W ; Turn LED white using a white LED
  48. * M150 P127 ; Set LED 50% brightness
  49. * M150 P ; Set LED full brightness
  50. * M150 I1 R ; Set NEOPIXEL index 1 to red
  51. * M150 S1 I1 R ; Set SEPARATE index 1 to red
  52. * M150 K R127 ; Set LED red to 50% without changing blue or green
  53. */
  54. void GcodeSuite::M150() {
  55. int32_t old_color = 0;
  56. #if ENABLED(NEOPIXEL_LED)
  57. const pixel_index_t index = parser.intval('I', -1);
  58. #if ENABLED(NEOPIXEL2_SEPARATE)
  59. int8_t brightness = neo.brightness(), unit = parser.intval('S', -1);
  60. switch (unit) {
  61. case -1: neo2.neoindex = index; // fall-thru
  62. case 0: neo.neoindex = index; old_color = parser.seen('K') ? neo.pixel_color(index >= 0 ? index : 0) : 0; break;
  63. case 1: neo2.neoindex = index; brightness = neo2.brightness(); old_color = parser.seen('K') ? neo2.pixel_color(index >= 0 ? index : 0) : 0; break;
  64. }
  65. #else
  66. const uint8_t brightness = neo.brightness();
  67. neo.neoindex = index;
  68. #endif
  69. #endif
  70. const LEDColor color = LEDColor(
  71. parser.seen('R') ? (parser.has_value() ? parser.value_byte() : 255) : (old_color >> 16) & 0xFF,
  72. parser.seen('U') ? (parser.has_value() ? parser.value_byte() : 255) : (old_color >> 8) & 0xFF,
  73. parser.seen('B') ? (parser.has_value() ? parser.value_byte() : 255) : old_color & 0xFF
  74. OPTARG(HAS_WHITE_LED, parser.seen('W') ? (parser.has_value() ? parser.value_byte() : 255) : (old_color >> 24) & 0xFF)
  75. OPTARG(NEOPIXEL_LED, parser.seen('P') ? (parser.has_value() ? parser.value_byte() : 255) : brightness)
  76. );
  77. #if ENABLED(NEOPIXEL2_SEPARATE)
  78. switch (unit) {
  79. case 0: leds.set_color(color); return;
  80. case 1: leds2.set_color(color); return;
  81. }
  82. #endif
  83. // If 'S' is not specified use both
  84. leds.set_color(color);
  85. TERN_(NEOPIXEL2_SEPARATE, leds2.set_color(color));
  86. }
  87. #endif // HAS_COLOR_LEDS