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.

printer_event_leds.cpp 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. /**
  23. * feature/leds/printer_event_leds.cpp - LED color changing based on printer status
  24. */
  25. #include "../../inc/MarlinConfigPre.h"
  26. #if ENABLED(PRINTER_EVENT_LEDS)
  27. #include "printer_event_leds.h"
  28. PrinterEventLEDs printerEventLEDs;
  29. #if HAS_LEDS_OFF_FLAG
  30. bool PrinterEventLEDs::leds_off_after_print; // = false
  31. #endif
  32. #if HAS_TEMP_HOTEND || HAS_HEATED_BED
  33. uint8_t PrinterEventLEDs::old_intensity = 0;
  34. inline uint8_t pel_intensity(const celsius_t start, const celsius_t current, const celsius_t target) {
  35. if (start == target) return 255;
  36. return (uint8_t)map(constrain(current, start, target), start, target, 0, 255);
  37. }
  38. inline void pel_set_rgb(const uint8_t r, const uint8_t g, const uint8_t b OPTARG(HAS_WHITE_LED, const uint8_t w=0)) {
  39. leds.set_color(
  40. LEDColor(r, g, b OPTARG(HAS_WHITE_LED, w) OPTARG(NEOPIXEL_LED, neo.brightness()))
  41. OPTARG(NEOPIXEL_IS_SEQUENTIAL, true)
  42. );
  43. }
  44. #endif
  45. #if HAS_TEMP_HOTEND
  46. void PrinterEventLEDs::onHotendHeating(const celsius_t start, const celsius_t current, const celsius_t target) {
  47. const uint8_t blue = pel_intensity(start, current, target);
  48. if (blue != old_intensity) {
  49. old_intensity = blue;
  50. pel_set_rgb(255, 0, 255 - blue);
  51. }
  52. }
  53. #endif
  54. #if HAS_HEATED_BED
  55. void PrinterEventLEDs::onBedHeating(const celsius_t start, const celsius_t current, const celsius_t target) {
  56. const uint8_t red = pel_intensity(start, current, target);
  57. if (red != old_intensity) {
  58. old_intensity = red;
  59. pel_set_rgb(red, 0, 255);
  60. }
  61. }
  62. #endif
  63. #if HAS_HEATED_CHAMBER
  64. void PrinterEventLEDs::onChamberHeating(const celsius_t start, const celsius_t current, const celsius_t target) {
  65. const uint8_t green = pel_intensity(start, current, target);
  66. if (green != old_intensity) {
  67. old_intensity = green;
  68. pel_set_rgb(255, green, 255);
  69. }
  70. }
  71. #endif
  72. #endif // PRINTER_EVENT_LEDS