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 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. const uint8_t i = case_light_on ? case_light_brightness : 0, n10ct = INVERT_CASE_LIGHT ? 255 - i : i;
  53. #if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
  54. leds.set_color(
  55. MakeLEDColor(case_light_color.r, case_light_color.g, case_light_color.b, case_light_color.w, n10ct),
  56. false
  57. );
  58. #else // !CASE_LIGHT_USE_NEOPIXEL
  59. #if DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
  60. if (PWM_PIN(CASE_LIGHT_PIN))
  61. analogWrite(pin_t(CASE_LIGHT_PIN),
  62. #if CASE_LIGHT_MAX_PWM == 255
  63. n10ct
  64. #else
  65. map(n10ct, 0, 255, 0, CASE_LIGHT_MAX_PWM)
  66. #endif
  67. );
  68. else
  69. #endif
  70. {
  71. const bool s = case_light_on ? !INVERT_CASE_LIGHT : INVERT_CASE_LIGHT;
  72. WRITE(CASE_LIGHT_PIN, s ? HIGH : LOW);
  73. }
  74. #endif // !CASE_LIGHT_USE_NEOPIXEL
  75. }
  76. #endif // HAS_CASE_LIGHT