Case light brightness cleanup (#19856)
Co-authored-by: Chris <chris@chrisnovoa.com>
This commit is contained in:
@ -28,7 +28,14 @@
|
||||
|
||||
CaseLight caselight;
|
||||
|
||||
uint8_t CaseLight::brightness = CASE_LIGHT_DEFAULT_BRIGHTNESS;
|
||||
#if CASELIGHT_USES_BRIGHTNESS && !defined(CASE_LIGHT_DEFAULT_BRIGHTNESS)
|
||||
#define CASE_LIGHT_DEFAULT_BRIGHTNESS 0 // For use on PWM pin as non-PWM just sets a default
|
||||
#endif
|
||||
|
||||
#if CASELIGHT_USES_BRIGHTNESS
|
||||
uint8_t CaseLight::brightness = CASE_LIGHT_DEFAULT_BRIGHTNESS;
|
||||
#endif
|
||||
|
||||
bool CaseLight::on = CASE_LIGHT_DEFAULT_ON;
|
||||
|
||||
#if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
|
||||
@ -46,21 +53,21 @@ bool CaseLight::on = CASE_LIGHT_DEFAULT_ON;
|
||||
#endif
|
||||
|
||||
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"
|
||||
#if CASELIGHT_USES_BRIGHTNESS
|
||||
/**
|
||||
* 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"
|
||||
|
||||
if (on || !sflag)
|
||||
brightness_sav = brightness; // Save brightness except for M355 S0
|
||||
if (sflag && on)
|
||||
brightness = brightness_sav; // Restore last brightness for M355 S1
|
||||
if (on || !sflag)
|
||||
brightness_sav = brightness; // Save brightness except for M355 S0
|
||||
if (sflag && on)
|
||||
brightness = brightness_sav; // Restore last brightness for M355 S1
|
||||
|
||||
#if ENABLED(CASE_LIGHT_USE_NEOPIXEL) || DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
|
||||
const uint8_t i = on ? brightness : 0, n10ct = INVERT_CASE_LIGHT ? 255 - i : i;
|
||||
#endif
|
||||
|
||||
@ -73,7 +80,7 @@ void CaseLight::update(const bool sflag) {
|
||||
|
||||
#else // !CASE_LIGHT_USE_NEOPIXEL
|
||||
|
||||
#if DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
|
||||
#if CASELIGHT_USES_BRIGHTNESS
|
||||
if (PWM_PIN(CASE_LIGHT_PIN))
|
||||
analogWrite(pin_t(CASE_LIGHT_PIN), (
|
||||
#if CASE_LIGHT_MAX_PWM == 255
|
||||
|
@ -27,9 +27,15 @@
|
||||
#include "leds/leds.h"
|
||||
#endif
|
||||
|
||||
#if DISABLED(CASE_LIGHT_NO_BRIGHTNESS) || ENABLED(CASE_LIGHT_USE_NEOPIXEL)
|
||||
#define CASELIGHT_USES_BRIGHTNESS 1
|
||||
#endif
|
||||
|
||||
class CaseLight {
|
||||
public:
|
||||
static uint8_t brightness;
|
||||
#if CASELIGHT_USES_BRIGHTNESS
|
||||
static uint8_t brightness;
|
||||
#endif
|
||||
static bool on;
|
||||
|
||||
static void update(const bool sflag);
|
||||
|
Reference in New Issue
Block a user