mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2024-11-27 13:56:24 +00:00
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;
|
||||
|
||||
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);
|
||||
|
@ -41,10 +41,12 @@
|
||||
*/
|
||||
void GcodeSuite::M355() {
|
||||
bool didset = false;
|
||||
if (parser.seenval('P')) {
|
||||
didset = true;
|
||||
caselight.brightness = parser.value_byte();
|
||||
}
|
||||
#if CASELIGHT_USES_BRIGHTNESS
|
||||
if (parser.seenval('P')) {
|
||||
didset = true;
|
||||
caselight.brightness = parser.value_byte();
|
||||
}
|
||||
#endif
|
||||
const bool sflag = parser.seenval('S');
|
||||
if (sflag) {
|
||||
didset = true;
|
||||
@ -58,8 +60,13 @@ void GcodeSuite::M355() {
|
||||
if (!caselight.on)
|
||||
SERIAL_ECHOLNPGM(STR_OFF);
|
||||
else {
|
||||
if (!PWM_PIN(CASE_LIGHT_PIN)) SERIAL_ECHOLNPGM(STR_ON);
|
||||
else SERIAL_ECHOLN(int(caselight.brightness));
|
||||
#if CASELIGHT_USES_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"
|
||||
#endif
|
||||
|
||||
#if ENABLED(CASE_LIGHT_ENABLE)
|
||||
#include "../../feature/caselight.h"
|
||||
#endif
|
||||
|
||||
#if ENABLED(EXTENDED_CAPABILITIES_REPORT)
|
||||
static void cap_line(PGM_P const name, bool ena=false) {
|
||||
SERIAL_ECHOPGM("Cap:");
|
||||
@ -102,7 +106,7 @@ void GcodeSuite::M115() {
|
||||
|
||||
// TOGGLE_LIGHTS (M355)
|
||||
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)
|
||||
cap_line(PSTR("EMERGENCY_PARSER"), ENABLED(EMERGENCY_PARSER));
|
||||
|
@ -610,7 +610,7 @@ namespace ExtUI {
|
||||
caselight.update_enabled();
|
||||
}
|
||||
|
||||
#if DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
|
||||
#if CASELIGHT_USES_BRIGHTNESS
|
||||
float getCaseLightBrightness_percent() { return ui8_to_percent(caselight.brightness); }
|
||||
void setCaseLightBrightness_percent(const float value) {
|
||||
caselight.brightness = map(constrain(value, 0, 100), 0, 100, 0, 255);
|
||||
|
@ -105,7 +105,7 @@
|
||||
#if ENABLED(CASE_LIGHT_MENU)
|
||||
#include "../../feature/caselight.h"
|
||||
|
||||
#if DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
|
||||
#if CASELIGHT_USES_BRIGHTNESS
|
||||
void menu_case_light() {
|
||||
START_MENU();
|
||||
BACK_ITEM(MSG_CONFIGURATION);
|
||||
|
@ -137,9 +137,8 @@
|
||||
void M710_report(const bool forReplay);
|
||||
#endif
|
||||
|
||||
#if ENABLED(CASE_LIGHT_ENABLE) && DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
|
||||
#if ENABLED(CASE_LIGHT_ENABLE)
|
||||
#include "../feature/caselight.h"
|
||||
#define HAS_CASE_LIGHT_BRIGHTNESS 1
|
||||
#endif
|
||||
|
||||
#if ENABLED(PASSWORD_FEATURE)
|
||||
@ -422,9 +421,9 @@ typedef struct SettingsDataStruct {
|
||||
#endif
|
||||
|
||||
//
|
||||
// HAS_CASE_LIGHT_BRIGHTNESS
|
||||
// CASELIGHT_USES_BRIGHTNESS
|
||||
//
|
||||
#if HAS_CASE_LIGHT_BRIGHTNESS
|
||||
#if CASELIGHT_USES_BRIGHTNESS
|
||||
uint8_t caselight_brightness; // M355 P
|
||||
#endif
|
||||
|
||||
@ -503,7 +502,7 @@ void MarlinSettings::postprocess() {
|
||||
|
||||
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
|
||||
// and init stepper.count[], planner.position[] with current_position
|
||||
@ -1385,7 +1384,7 @@ void MarlinSettings::postprocess() {
|
||||
//
|
||||
// Case Light Brightness
|
||||
//
|
||||
#if HAS_CASE_LIGHT_BRIGHTNESS
|
||||
#if CASELIGHT_USES_BRIGHTNESS
|
||||
EEPROM_WRITE(caselight.brightness);
|
||||
#endif
|
||||
|
||||
@ -2259,7 +2258,7 @@ void MarlinSettings::postprocess() {
|
||||
//
|
||||
// Case Light Brightness
|
||||
//
|
||||
#if HAS_CASE_LIGHT_BRIGHTNESS
|
||||
#if CASELIGHT_USES_BRIGHTNESS
|
||||
_FIELD_TEST(caselight_brightness);
|
||||
EEPROM_READ(caselight.brightness);
|
||||
#endif
|
||||
@ -2597,7 +2596,7 @@ void MarlinSettings::reset() {
|
||||
//
|
||||
// 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
|
||||
|
Loading…
Reference in New Issue
Block a user