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.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 float &start, const float &current, const float &target) {
  35. if (uint16_t(start) == uint16_t(target)) return 255;
  36. return (uint8_t)map(constrain(current, start, target), start, target, 0.f, 255.f);
  37. }
  38. inline void pel_set_rgb(const uint8_t r, const uint8_t g, const uint8_t b) {
  39. leds.set_color(
  40. MakeLEDColor(r, g, b, 0, neo.brightness())
  41. #if ENABLED(NEOPIXEL_IS_SEQUENTIAL)
  42. , true
  43. #endif
  44. );
  45. }
  46. #endif
  47. #if HAS_TEMP_HOTEND
  48. void PrinterEventLEDs::onHotendHeating(const float &start, const float &current, const float &target) {
  49. const uint8_t blue = pel_intensity(start, current, target);
  50. if (blue != old_intensity) {
  51. old_intensity = blue;
  52. pel_set_rgb(255, 0, 255 - blue);
  53. }
  54. }
  55. #endif
  56. #if HAS_HEATED_BED
  57. void PrinterEventLEDs::onBedHeating(const float &start, const float &current, const float &target) {
  58. const uint8_t red = pel_intensity(start, current, target);
  59. if (red != old_intensity) {
  60. old_intensity = red;
  61. pel_set_rgb(red, 0, 255);
  62. }
  63. }
  64. #endif
  65. #endif // PRINTER_EVENT_LEDS