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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 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. /**
  27. * The following are needed because ARM chips ignore a "WRITE(CASE_LIGHT_PIN,x)" command to the pins that
  28. * are directly controlled by the PWM module. In order to turn them off the brightness level needs to be
  29. * set to off. Since we can't use the pwm register to save the last brightness level we need a variable
  30. * to save it.
  31. */
  32. uint8_t case_light_brightness_sav; // saves brighness info so can restore when "M355 S1" received
  33. bool case_light_arg_flag; // flag to notify if S or P arguement type
  34. #ifndef INVERT_CASE_LIGHT
  35. #define INVERT_CASE_LIGHT false
  36. #endif
  37. void update_case_light() {
  38. SET_OUTPUT(CASE_LIGHT_PIN);
  39. if (!(case_light_arg_flag && !case_light_on))
  40. case_light_brightness_sav = case_light_brightness; // save brightness except if this is an S0 arguement
  41. if (case_light_arg_flag && case_light_on)
  42. case_light_brightness = case_light_brightness_sav; // restore last brightens if this is an S1 arguement
  43. if (case_light_on) {
  44. if (USEABLE_HARDWARE_PWM(CASE_LIGHT_PIN)) {
  45. analogWrite(CASE_LIGHT_PIN, INVERT_CASE_LIGHT ? 255 - case_light_brightness : case_light_brightness );
  46. }
  47. else WRITE(CASE_LIGHT_PIN, INVERT_CASE_LIGHT ? LOW : HIGH);
  48. }
  49. else {
  50. if (USEABLE_HARDWARE_PWM(CASE_LIGHT_PIN))
  51. analogWrite(CASE_LIGHT_PIN, INVERT_CASE_LIGHT ? 255 : 0 ); // turn the light off
  52. WRITE(CASE_LIGHT_PIN, INVERT_CASE_LIGHT ? HIGH : LOW);
  53. }
  54. }
  55. #endif // HAS_CASE_LIGHT