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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 ENABLED(CASE_LIGHT_ENABLE)
  24. #include "caselight.h"
  25. CaseLight caselight;
  26. uint8_t CaseLight::brightness = CASE_LIGHT_DEFAULT_BRIGHTNESS;
  27. bool CaseLight::on = CASE_LIGHT_DEFAULT_ON;
  28. #if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
  29. LEDColor CaseLight::color =
  30. #ifdef CASE_LIGHT_NEOPIXEL_COLOR
  31. CASE_LIGHT_NEOPIXEL_COLOR
  32. #else
  33. { 255, 255, 255, 255 }
  34. #endif
  35. ;
  36. #endif
  37. #ifndef INVERT_CASE_LIGHT
  38. #define INVERT_CASE_LIGHT false
  39. #endif
  40. void CaseLight::update(const bool sflag) {
  41. /**
  42. * The brightness_sav (and sflag) is needed because ARM chips ignore
  43. * a "WRITE(CASE_LIGHT_PIN,x)" command to the pins that are directly
  44. * controlled by the PWM module. In order to turn them off the brightness
  45. * level needs to be set to OFF. Since we can't use the PWM register to
  46. * save the last brightness level we need a variable to save it.
  47. */
  48. static uint8_t brightness_sav; // Save brightness info for restore on "M355 S1"
  49. if (on || !sflag)
  50. brightness_sav = brightness; // Save brightness except for M355 S0
  51. if (sflag && on)
  52. brightness = brightness_sav; // Restore last brightness for M355 S1
  53. #if ENABLED(CASE_LIGHT_USE_NEOPIXEL) || DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
  54. const uint8_t i = on ? brightness : 0, n10ct = INVERT_CASE_LIGHT ? 255 - i : i;
  55. #endif
  56. #if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
  57. leds.set_color(
  58. MakeLEDColor(color.r, color.g, color.b, color.w, n10ct),
  59. false
  60. );
  61. #else // !CASE_LIGHT_USE_NEOPIXEL
  62. #if DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
  63. if (PWM_PIN(CASE_LIGHT_PIN))
  64. analogWrite(pin_t(CASE_LIGHT_PIN), (
  65. #if CASE_LIGHT_MAX_PWM == 255
  66. n10ct
  67. #else
  68. map(n10ct, 0, 255, 0, CASE_LIGHT_MAX_PWM)
  69. #endif
  70. ));
  71. else
  72. #endif
  73. {
  74. const bool s = on ? !INVERT_CASE_LIGHT : INVERT_CASE_LIGHT;
  75. WRITE(CASE_LIGHT_PIN, s ? HIGH : LOW);
  76. }
  77. #endif // !CASE_LIGHT_USE_NEOPIXEL
  78. }
  79. #endif // CASE_LIGHT_ENABLE