2017-09-17 18:56:29 -05:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 08:00:57 -06:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-09-17 18:56:29 -05:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-27 23:57:50 -05:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2017-09-17 18:56:29 -05:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2020-07-22 22:20:14 -05:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2017-09-17 18:56:29 -05:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../inc/MarlinConfig.h"
|
|
|
|
|
2020-08-06 08:14:00 -05:00
|
|
|
#if ENABLED(CASE_LIGHT_ENABLE)
|
2017-09-17 18:56:29 -05:00
|
|
|
|
2020-08-06 08:14:00 -05:00
|
|
|
#include "caselight.h"
|
|
|
|
|
|
|
|
CaseLight caselight;
|
|
|
|
|
|
|
|
uint8_t CaseLight::brightness = CASE_LIGHT_DEFAULT_BRIGHTNESS;
|
|
|
|
bool CaseLight::on = CASE_LIGHT_DEFAULT_ON;
|
2017-09-27 04:57:14 -05:00
|
|
|
|
2018-01-20 16:58:41 -06:00
|
|
|
#if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
|
2020-08-06 08:14:00 -05:00
|
|
|
LEDColor CaseLight::color =
|
2018-01-20 16:58:41 -06:00
|
|
|
#ifdef CASE_LIGHT_NEOPIXEL_COLOR
|
|
|
|
CASE_LIGHT_NEOPIXEL_COLOR
|
|
|
|
#else
|
|
|
|
{ 255, 255, 255, 255 }
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
#endif
|
|
|
|
|
2017-09-17 18:56:29 -05:00
|
|
|
#ifndef INVERT_CASE_LIGHT
|
|
|
|
#define INVERT_CASE_LIGHT false
|
|
|
|
#endif
|
|
|
|
|
2020-08-06 08:14:00 -05:00
|
|
|
void CaseLight::update(const bool sflag) {
|
|
|
|
/**
|
|
|
|
* The brightness_sav (and sflag) is needed because ARM chips ignore
|
|
|
|
* a "WRITE(CASE_LIGHT_PIN,x)" command to the pins that are directly
|
|
|
|
* controlled by the PWM module. In order to turn them off the brightness
|
|
|
|
* level needs to be set to OFF. Since we can't use the PWM register to
|
|
|
|
* save the last brightness level we need a variable to save it.
|
|
|
|
*/
|
|
|
|
static uint8_t brightness_sav; // Save brightness info for restore on "M355 S1"
|
2017-06-17 18:36:10 -05:00
|
|
|
|
2020-08-06 08:14:00 -05:00
|
|
|
if (on || !sflag)
|
|
|
|
brightness_sav = brightness; // Save brightness except for M355 S0
|
|
|
|
if (sflag && on)
|
|
|
|
brightness = brightness_sav; // Restore last brightness for M355 S1
|
2017-06-17 18:36:10 -05:00
|
|
|
|
2020-02-01 07:55:53 -06:00
|
|
|
#if ENABLED(CASE_LIGHT_USE_NEOPIXEL) || DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
|
2020-08-06 08:14:00 -05:00
|
|
|
const uint8_t i = on ? brightness : 0, n10ct = INVERT_CASE_LIGHT ? 255 - i : i;
|
2020-01-05 02:52:38 -06:00
|
|
|
#endif
|
2018-01-20 16:58:41 -06:00
|
|
|
|
|
|
|
#if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
|
|
|
|
|
|
|
|
leds.set_color(
|
2020-08-06 08:14:00 -05:00
|
|
|
MakeLEDColor(color.r, color.g, color.b, color.w, n10ct),
|
2018-01-20 16:58:41 -06:00
|
|
|
false
|
|
|
|
);
|
|
|
|
|
|
|
|
#else // !CASE_LIGHT_USE_NEOPIXEL
|
|
|
|
|
2019-06-07 07:23:42 -05:00
|
|
|
#if DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
|
|
|
|
if (PWM_PIN(CASE_LIGHT_PIN))
|
2020-01-05 02:52:38 -06:00
|
|
|
analogWrite(pin_t(CASE_LIGHT_PIN), (
|
2019-10-05 22:32:50 -05:00
|
|
|
#if CASE_LIGHT_MAX_PWM == 255
|
|
|
|
n10ct
|
|
|
|
#else
|
|
|
|
map(n10ct, 0, 255, 0, CASE_LIGHT_MAX_PWM)
|
|
|
|
#endif
|
2020-01-05 02:52:38 -06:00
|
|
|
));
|
2019-06-07 07:23:42 -05:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2020-08-06 08:14:00 -05:00
|
|
|
const bool s = on ? !INVERT_CASE_LIGHT : INVERT_CASE_LIGHT;
|
2019-06-07 07:23:42 -05:00
|
|
|
WRITE(CASE_LIGHT_PIN, s ? HIGH : LOW);
|
|
|
|
}
|
2018-01-20 16:58:41 -06:00
|
|
|
|
|
|
|
#endif // !CASE_LIGHT_USE_NEOPIXEL
|
2017-09-17 18:56:29 -05:00
|
|
|
}
|
|
|
|
|
2020-08-06 08:14:00 -05:00
|
|
|
#endif // CASE_LIGHT_ENABLE
|