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.

caselight.cpp 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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 "../inc/MarlinConfig.h"
  23. #if HAS_CASE_LIGHT
  24. uint8_t case_light_brightness = CASE_LIGHT_DEFAULT_BRIGHTNESS;
  25. bool case_light_on = CASE_LIGHT_DEFAULT_ON;
  26. #if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
  27. #include "leds/leds.h"
  28. LEDColor case_light_color =
  29. #ifdef CASE_LIGHT_NEOPIXEL_COLOR
  30. CASE_LIGHT_NEOPIXEL_COLOR
  31. #else
  32. { 255, 255, 255, 255 }
  33. #endif
  34. ;
  35. #endif
  36. /**
  37. * The following are needed because ARM chips ignore a "WRITE(CASE_LIGHT_PIN,x)" command to the pins that
  38. * are directly controlled by the PWM module. In order to turn them off the brightness level needs to be
  39. * set to off. Since we can't use the pwm register to save the last brightness level we need a variable
  40. * to save it.
  41. */
  42. uint8_t case_light_brightness_sav; // saves brighness info so can restore when "M355 S1" received
  43. bool case_light_arg_flag; // flag to notify if S or P argument type
  44. #ifndef INVERT_CASE_LIGHT
  45. #define INVERT_CASE_LIGHT false
  46. #endif
  47. void update_case_light() {
  48. if (!(case_light_arg_flag && !case_light_on))
  49. case_light_brightness_sav = case_light_brightness; // save brightness except if this is an S0 argument
  50. if (case_light_arg_flag && case_light_on)
  51. case_light_brightness = case_light_brightness_sav; // restore last brightens if this is an S1 argument
  52. #if ENABLED(CASE_LIGHT_USE_NEOPIXEL) || DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
  53. const uint8_t i = case_light_on ? case_light_brightness : 0, n10ct = INVERT_CASE_LIGHT ? 255 - i : i;
  54. #endif
  55. #if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
  56. leds.set_color(
  57. MakeLEDColor(case_light_color.r, case_light_color.g, case_light_color.b, case_light_color.w, n10ct),
  58. false
  59. );
  60. #else // !CASE_LIGHT_USE_NEOPIXEL
  61. #if DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
  62. if (PWM_PIN(CASE_LIGHT_PIN))
  63. analogWrite(pin_t(CASE_LIGHT_PIN), (
  64. #if CASE_LIGHT_MAX_PWM == 255
  65. n10ct
  66. #else
  67. map(n10ct, 0, 255, 0, CASE_LIGHT_MAX_PWM)
  68. #endif
  69. ));
  70. else
  71. #endif
  72. {
  73. const bool s = case_light_on ? !INVERT_CASE_LIGHT : INVERT_CASE_LIGHT;
  74. WRITE(CASE_LIGHT_PIN, s ? HIGH : LOW);
  75. }
  76. #endif // !CASE_LIGHT_USE_NEOPIXEL
  77. }
  78. #endif // HAS_CASE_LIGHT