Case light brightness cleanup (#19856)
Co-authored-by: Chris <chris@chrisnovoa.com>
This commit is contained in:
parent
c75e98dc84
commit
0ffee29a11
@ -28,7 +28,14 @@
|
|||||||
|
|
||||||
CaseLight caselight;
|
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;
|
bool CaseLight::on = CASE_LIGHT_DEFAULT_ON;
|
||||||
|
|
||||||
#if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
|
#if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
|
||||||
@ -46,21 +53,21 @@ bool CaseLight::on = CASE_LIGHT_DEFAULT_ON;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void CaseLight::update(const bool sflag) {
|
void CaseLight::update(const bool sflag) {
|
||||||
/**
|
#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
|
* The brightness_sav (and sflag) is needed because ARM chips ignore
|
||||||
* controlled by the PWM module. In order to turn them off the brightness
|
* a "WRITE(CASE_LIGHT_PIN,x)" command to the pins that are directly
|
||||||
* level needs to be set to OFF. Since we can't use the PWM register to
|
* controlled by the PWM module. In order to turn them off the brightness
|
||||||
* save the last brightness level we need a variable to save it.
|
* 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"
|
*/
|
||||||
|
static uint8_t brightness_sav; // Save brightness info for restore on "M355 S1"
|
||||||
|
|
||||||
if (on || !sflag)
|
if (on || !sflag)
|
||||||
brightness_sav = brightness; // Save brightness except for M355 S0
|
brightness_sav = brightness; // Save brightness except for M355 S0
|
||||||
if (sflag && on)
|
if (sflag && on)
|
||||||
brightness = brightness_sav; // Restore last brightness for M355 S1
|
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;
|
const uint8_t i = on ? brightness : 0, n10ct = INVERT_CASE_LIGHT ? 255 - i : i;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -73,7 +80,7 @@ void CaseLight::update(const bool sflag) {
|
|||||||
|
|
||||||
#else // !CASE_LIGHT_USE_NEOPIXEL
|
#else // !CASE_LIGHT_USE_NEOPIXEL
|
||||||
|
|
||||||
#if DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
|
#if CASELIGHT_USES_BRIGHTNESS
|
||||||
if (PWM_PIN(CASE_LIGHT_PIN))
|
if (PWM_PIN(CASE_LIGHT_PIN))
|
||||||
analogWrite(pin_t(CASE_LIGHT_PIN), (
|
analogWrite(pin_t(CASE_LIGHT_PIN), (
|
||||||
#if CASE_LIGHT_MAX_PWM == 255
|
#if CASE_LIGHT_MAX_PWM == 255
|
||||||
|
@ -27,9 +27,15 @@
|
|||||||
#include "leds/leds.h"
|
#include "leds/leds.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if DISABLED(CASE_LIGHT_NO_BRIGHTNESS) || ENABLED(CASE_LIGHT_USE_NEOPIXEL)
|
||||||
|
#define CASELIGHT_USES_BRIGHTNESS 1
|
||||||
|
#endif
|
||||||
|
|
||||||
class CaseLight {
|
class CaseLight {
|
||||||
public:
|
public:
|
||||||
static uint8_t brightness;
|
#if CASELIGHT_USES_BRIGHTNESS
|
||||||
|
static uint8_t brightness;
|
||||||
|
#endif
|
||||||
static bool on;
|
static bool on;
|
||||||
|
|
||||||
static void update(const bool sflag);
|
static void update(const bool sflag);
|
||||||
|
@ -41,10 +41,12 @@
|
|||||||
*/
|
*/
|
||||||
void GcodeSuite::M355() {
|
void GcodeSuite::M355() {
|
||||||
bool didset = false;
|
bool didset = false;
|
||||||
if (parser.seenval('P')) {
|
#if CASELIGHT_USES_BRIGHTNESS
|
||||||
didset = true;
|
if (parser.seenval('P')) {
|
||||||
caselight.brightness = parser.value_byte();
|
didset = true;
|
||||||
}
|
caselight.brightness = parser.value_byte();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
const bool sflag = parser.seenval('S');
|
const bool sflag = parser.seenval('S');
|
||||||
if (sflag) {
|
if (sflag) {
|
||||||
didset = true;
|
didset = true;
|
||||||
@ -58,8 +60,13 @@ void GcodeSuite::M355() {
|
|||||||
if (!caselight.on)
|
if (!caselight.on)
|
||||||
SERIAL_ECHOLNPGM(STR_OFF);
|
SERIAL_ECHOLNPGM(STR_OFF);
|
||||||
else {
|
else {
|
||||||
if (!PWM_PIN(CASE_LIGHT_PIN)) SERIAL_ECHOLNPGM(STR_ON);
|
#if CASELIGHT_USES_BRIGHTNESS
|
||||||
else SERIAL_ECHOLN(int(caselight.brightness));
|
if (PWM_PIN(CASE_LIGHT_PIN)) {
|
||||||
|
SERIAL_ECHOLN(int(caselight.brightness));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
SERIAL_ECHOLNPGM(STR_ON);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,10 @@
|
|||||||
#include "../../module/motion.h"
|
#include "../../module/motion.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ENABLED(CASE_LIGHT_ENABLE)
|
||||||
|
#include "../../feature/caselight.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if ENABLED(EXTENDED_CAPABILITIES_REPORT)
|
#if ENABLED(EXTENDED_CAPABILITIES_REPORT)
|
||||||
static void cap_line(PGM_P const name, bool ena=false) {
|
static void cap_line(PGM_P const name, bool ena=false) {
|
||||||
SERIAL_ECHOPGM("Cap:");
|
SERIAL_ECHOPGM("Cap:");
|
||||||
@ -102,7 +106,7 @@ void GcodeSuite::M115() {
|
|||||||
|
|
||||||
// TOGGLE_LIGHTS (M355)
|
// TOGGLE_LIGHTS (M355)
|
||||||
cap_line(PSTR("TOGGLE_LIGHTS"), ENABLED(CASE_LIGHT_ENABLE));
|
cap_line(PSTR("TOGGLE_LIGHTS"), ENABLED(CASE_LIGHT_ENABLE));
|
||||||
cap_line(PSTR("CASE_LIGHT_BRIGHTNESS"), TERN0(CASE_LIGHT_ENABLE, PWM_PIN(CASE_LIGHT_PIN)));
|
cap_line(PSTR("CASE_LIGHT_BRIGHTNESS"), TERN0(CASE_LIGHT_ENABLE, TERN0(CASELIGHT_USES_BRIGHTNESS, TERN(CASE_LIGHT_USE_NEOPIXEL, true, PWM_PIN(CASE_LIGHT_PIN)))));
|
||||||
|
|
||||||
// EMERGENCY_PARSER (M108, M112, M410, M876)
|
// EMERGENCY_PARSER (M108, M112, M410, M876)
|
||||||
cap_line(PSTR("EMERGENCY_PARSER"), ENABLED(EMERGENCY_PARSER));
|
cap_line(PSTR("EMERGENCY_PARSER"), ENABLED(EMERGENCY_PARSER));
|
||||||
|
@ -610,7 +610,7 @@ namespace ExtUI {
|
|||||||
caselight.update_enabled();
|
caselight.update_enabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
|
#if CASELIGHT_USES_BRIGHTNESS
|
||||||
float getCaseLightBrightness_percent() { return ui8_to_percent(caselight.brightness); }
|
float getCaseLightBrightness_percent() { return ui8_to_percent(caselight.brightness); }
|
||||||
void setCaseLightBrightness_percent(const float value) {
|
void setCaseLightBrightness_percent(const float value) {
|
||||||
caselight.brightness = map(constrain(value, 0, 100), 0, 100, 0, 255);
|
caselight.brightness = map(constrain(value, 0, 100), 0, 100, 0, 255);
|
||||||
|
@ -105,7 +105,7 @@
|
|||||||
#if ENABLED(CASE_LIGHT_MENU)
|
#if ENABLED(CASE_LIGHT_MENU)
|
||||||
#include "../../feature/caselight.h"
|
#include "../../feature/caselight.h"
|
||||||
|
|
||||||
#if DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
|
#if CASELIGHT_USES_BRIGHTNESS
|
||||||
void menu_case_light() {
|
void menu_case_light() {
|
||||||
START_MENU();
|
START_MENU();
|
||||||
BACK_ITEM(MSG_CONFIGURATION);
|
BACK_ITEM(MSG_CONFIGURATION);
|
||||||
|
@ -137,9 +137,8 @@
|
|||||||
void M710_report(const bool forReplay);
|
void M710_report(const bool forReplay);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLED(CASE_LIGHT_ENABLE) && DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
|
#if ENABLED(CASE_LIGHT_ENABLE)
|
||||||
#include "../feature/caselight.h"
|
#include "../feature/caselight.h"
|
||||||
#define HAS_CASE_LIGHT_BRIGHTNESS 1
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLED(PASSWORD_FEATURE)
|
#if ENABLED(PASSWORD_FEATURE)
|
||||||
@ -422,9 +421,9 @@ typedef struct SettingsDataStruct {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//
|
//
|
||||||
// HAS_CASE_LIGHT_BRIGHTNESS
|
// CASELIGHT_USES_BRIGHTNESS
|
||||||
//
|
//
|
||||||
#if HAS_CASE_LIGHT_BRIGHTNESS
|
#if CASELIGHT_USES_BRIGHTNESS
|
||||||
uint8_t caselight_brightness; // M355 P
|
uint8_t caselight_brightness; // M355 P
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -503,7 +502,7 @@ void MarlinSettings::postprocess() {
|
|||||||
|
|
||||||
TERN_(HAS_LINEAR_E_JERK, planner.recalculate_max_e_jerk());
|
TERN_(HAS_LINEAR_E_JERK, planner.recalculate_max_e_jerk());
|
||||||
|
|
||||||
TERN_(HAS_CASE_LIGHT_BRIGHTNESS, caselight.update_brightness());
|
TERN_(CASELIGHT_USES_BRIGHTNESS, caselight.update_brightness());
|
||||||
|
|
||||||
// Refresh steps_to_mm with the reciprocal of axis_steps_per_mm
|
// Refresh steps_to_mm with the reciprocal of axis_steps_per_mm
|
||||||
// and init stepper.count[], planner.position[] with current_position
|
// and init stepper.count[], planner.position[] with current_position
|
||||||
@ -1385,7 +1384,7 @@ void MarlinSettings::postprocess() {
|
|||||||
//
|
//
|
||||||
// Case Light Brightness
|
// Case Light Brightness
|
||||||
//
|
//
|
||||||
#if HAS_CASE_LIGHT_BRIGHTNESS
|
#if CASELIGHT_USES_BRIGHTNESS
|
||||||
EEPROM_WRITE(caselight.brightness);
|
EEPROM_WRITE(caselight.brightness);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -2259,7 +2258,7 @@ void MarlinSettings::postprocess() {
|
|||||||
//
|
//
|
||||||
// Case Light Brightness
|
// Case Light Brightness
|
||||||
//
|
//
|
||||||
#if HAS_CASE_LIGHT_BRIGHTNESS
|
#if CASELIGHT_USES_BRIGHTNESS
|
||||||
_FIELD_TEST(caselight_brightness);
|
_FIELD_TEST(caselight_brightness);
|
||||||
EEPROM_READ(caselight.brightness);
|
EEPROM_READ(caselight.brightness);
|
||||||
#endif
|
#endif
|
||||||
@ -2597,7 +2596,7 @@ void MarlinSettings::reset() {
|
|||||||
//
|
//
|
||||||
// Case Light Brightness
|
// Case Light Brightness
|
||||||
//
|
//
|
||||||
TERN_(HAS_CASE_LIGHT_BRIGHTNESS, caselight.brightness = CASE_LIGHT_DEFAULT_BRIGHTNESS);
|
TERN_(CASELIGHT_USES_BRIGHTNESS, caselight.brightness = CASE_LIGHT_DEFAULT_BRIGHTNESS);
|
||||||
|
|
||||||
//
|
//
|
||||||
// TOUCH_SCREEN_CALIBRATION
|
// TOUCH_SCREEN_CALIBRATION
|
||||||
|
Loading…
Reference in New Issue
Block a user