Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gui: Add rgb side bar dimming duration control, tool light brightness control and display backlight brightness control #4174

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/leds/side_strip_control.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class SideStripControl {

void SetEnable(bool isEnable);
void set_dimming_enabled(bool set);
void set_dimming_duration(int duration_sec);
int get_dimming_duration();

/**
* @brief Quickly turn off LEDs.
Expand Down Expand Up @@ -145,7 +147,6 @@ class SideStripControl {
freertos::Mutex mutex;

// Active State
const int active_timeout_ms = 120 * 1000;
std::optional<uint32_t> active_start_timestamp;

// Custom Color State
Expand Down
48 changes: 48 additions & 0 deletions src/gui/MItem_menus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <option/has_leds.h>
#if HAS_LEDS()
#include "led_animations/animator.hpp"
#include "gui_leds.hpp"
#endif
#include "img_resources.hpp"
#include "power_panic.hpp"
Expand Down Expand Up @@ -536,6 +537,40 @@ void MI_LEDS_ENABLE::OnChange(size_t old_index) {
}
#endif

#if HAS_LEDS()
/**********************************************************************************************/
// MI_DISPLAY_BACKLIGHT_BRIGHTNESS
static constexpr NumericInputConfig led_display_backlight_brightness_spin_config = {
// Keep a min value of 2 percent to make sure the user can still see the lcd content if changed by mistake
.min_value = 2,
.max_value = 100
};

MI_DISPLAY_BACKLIGHT_BRIGHTNESS::MI_DISPLAY_BACKLIGHT_BRIGHTNESS()
: WiSpin(config_store().leds_display_backlight_brightness.get(), led_display_backlight_brightness_spin_config, _(label), nullptr, is_enabled_t::yes, is_hidden_t::no) {
}
void MI_DISPLAY_BACKLIGHT_BRIGHTNESS::OnClick() {
leds::display_backlight_brightness(GetVal());
leds::store_display_backlight_brightness(GetVal());
}
#endif

#if HAS_SIDE_LEDS()
// MI_SIDE_LEDS_DIMMING_DURATION
static constexpr NumericInputConfig side_led_dimming_spin_config = {
.max_value = 60 * 60, // 60 Minutes
};

MI_SIDE_LEDS_DIMMING_DURATION::MI_SIDE_LEDS_DIMMING_DURATION()
: WiSpin(config_store().side_leds_dimming_duration.get(), side_led_dimming_spin_config, _(label), nullptr, is_enabled_t::yes, is_hidden_t::no) {
}

void MI_SIDE_LEDS_DIMMING_DURATION::OnClick() {
config_store().side_leds_dimming_duration.set(GetVal());
leds::side_strip_control.set_dimming_duration(GetVal());
}
#endif

#if HAS_SIDE_LEDS()
/**********************************************************************************************/
// MI_SIDE_LEDS_ENABLE
Expand Down Expand Up @@ -573,6 +608,19 @@ void MI_TOOL_LEDS_ENABLE::OnChange(size_t old_index) {
config_store().tool_leds_enabled.set(!old_index);
}

/**********************************************************************************************/
// MI_TOOL_LEDS_BRIGHTNESS
static constexpr NumericInputConfig tool_leds_brightness_spin_config = {
.max_value = 100,
};

MI_TOOL_LEDS_BRIGHTNESS::MI_TOOL_LEDS_BRIGHTNESS()
: WiSpin(config_store().tool_leds_brightness.get(), tool_leds_brightness_spin_config, _(label), nullptr, is_enabled_t::yes, is_hidden_t::no) {
}
void MI_TOOL_LEDS_BRIGHTNESS::OnClick() {
config_store().tool_leds_brightness.set(GetVal());
}

/*****************************************************************************/
// MI_TOOLS_SETUP
MI_TOOLS_SETUP::MI_TOOLS_SETUP()
Expand Down
27 changes: 27 additions & 0 deletions src/gui/MItem_menus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,16 @@ class MI_LEDS_ENABLE : public WI_ICON_SWITCH_OFF_ON_t {
};
#endif

#if HAS_LEDS()
class MI_DISPLAY_BACKLIGHT_BRIGHTNESS : public WiSpin {
static constexpr const char *const label = N_("Display Backlight Brightness");

public:
MI_DISPLAY_BACKLIGHT_BRIGHTNESS();
virtual void OnClick() override;
};
#endif

#if HAS_SIDE_LEDS()
class MI_SIDE_LEDS_ENABLE : public WI_ICON_SWITCH_OFF_ON_t {
static constexpr const char *const label = N_("RGB Side Strip");
Expand All @@ -429,6 +439,15 @@ class MI_SIDE_LEDS_DIMMING : public WI_ICON_SWITCH_OFF_ON_t {
MI_SIDE_LEDS_DIMMING();
virtual void OnChange(size_t old_index) override;
};

class MI_SIDE_LEDS_DIMMING_DURATION : public WiSpin {
static constexpr const char *const label = N_("RGB Side Strip Dimming Duration");

public:
MI_SIDE_LEDS_DIMMING_DURATION();
virtual void OnClick() override;
};

#endif

#if HAS_TOOLCHANGER()
Expand All @@ -440,6 +459,14 @@ class MI_TOOL_LEDS_ENABLE : public WI_ICON_SWITCH_OFF_ON_t {
virtual void OnChange(size_t old_index) override;
};

class MI_TOOL_LEDS_BRIGHTNESS : public WiSpin {
static constexpr const char *const label = N_("Tool Light Brightness");

public:
MI_TOOL_LEDS_BRIGHTNESS();
virtual void OnClick() override;
};

class MI_TOOLS_SETUP : public IWindowMenuItem {
static constexpr const char *const label = N_("Tools");

Expand Down
3 changes: 2 additions & 1 deletion src/gui/screen_menu_enclosure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ using ScreenMenuManualSetting = ScreenMenu<GuiDefaults::MenuFooter, MI_RETURN
#endif
#if HAS_TOOLCHANGER()
,
MI_TOOL_LEDS_ENABLE
MI_TOOL_LEDS_ENABLE,
MI_TOOL_LEDS_BRIGHTNESS
#endif
>;
} // namespace detail
Expand Down
6 changes: 4 additions & 2 deletions src/gui/screen_menu_user_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ using ScreenMenuUserInterface__ = ScreenMenu<GuiDefaults::MenuFooter, MI_RETURN,
#endif
#if HAS_LEDS()
,
MI_LEDS_ENABLE
MI_LEDS_ENABLE,
MI_DISPLAY_BACKLIGHT_BRIGHTNESS
#endif
#if HAS_SIDE_LEDS()
,
Expand All @@ -39,7 +40,8 @@ using ScreenMenuUserInterface__ = ScreenMenu<GuiDefaults::MenuFooter, MI_RETURN,
#endif
#if HAS_TOOLCHANGER()
,
MI_TOOL_LEDS_ENABLE
MI_TOOL_LEDS_ENABLE,
MI_TOOL_LEDS_BRIGHTNESS
#endif /*HAS_TOOLCHANGER()*/
#if HAS_TOUCH()
,
Expand Down
16 changes: 15 additions & 1 deletion src/guiapi/include/gui_leds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,21 @@ void SetNth(Color clr, index n);
*
* @param percent Brightness in range 0 - 100
*/
void SetBrightness(unsigned percent);
void display_backlight_brightness(unsigned percent);

/**
* @brief Read the Brightness of the display backlight from ConfigStore
*
* @return percent Brightness in range 2 - 100
*/
uint8_t get_display_backlight_brightness();

/**
* @brief Store the Brightness of the display backlight to ConfigStore
*
* @param percent Brightness in range 2 - 100
*/
void store_display_backlight_brightness(uint8_t percent);

/**
* @brief Forces write on next call of tick loop
Expand Down
29 changes: 26 additions & 3 deletions src/guiapi/src/gui_leds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,28 @@ Neopixels &getNeopixels() {

void leds::Init() {
// Turn on LCD backlight
// TODO move SetBrightness to display
leds::SetBrightness(100);
// TODO move display_backlight_brightness to display
uint8_t value = leds::get_display_backlight_brightness();
// Safety: Make sure that the display is never turned off (value=0) on reboot/reset !
leds::display_backlight_brightness(value == 0 ? 100 : value);
leds::TickLoop();

#if HAS_SIDE_LEDS()
leds::side_strip_control.SetEnable(config_store().side_leds_enabled.get());
leds::side_strip_control.set_dimming_enabled(config_store().side_leds_dimming_enabled.get());
leds::side_strip_control.set_dimming_duration(config_store().side_leds_dimming_duration.get());
#endif
}

uint8_t leds::get_display_backlight_brightness() {
return config_store().leds_display_backlight_brightness.get();
}

void leds::store_display_backlight_brightness(uint8_t percent) {
leds::display_backlight_brightness(percent);
return config_store().leds_display_backlight_brightness.set(percent);
}

void leds::ForceRefresh(size_t cnt) {
getNeopixels().ForceRefresh(cnt);
}
Expand All @@ -62,14 +75,24 @@ void leds::SetNth(Color clr, leds::index n) {
// backlight is on WS2811 (RGB)
// but color structure is meant for WS2812 (GRB)
// so to set RED channel on WS2811 have to set GREEN
void leds::SetBrightness(unsigned percent) {
void leds::display_backlight_brightness(unsigned percent) {
percent = std::min(100u, percent);
percent *= 255;
percent /= 100;

SetNth(Color(0, percent, 0), index::backlight);
}

#if HAS_SIDE_LEDS()
void SideStripControl::set_dimming_duration(int duration_sec) {
config_store().side_leds_dimming_duration.set(duration_sec);
}

int SideStripControl::get_dimming_duration() {
return config_store().side_leds_dimming_duration.get();
}
#endif

extern osThreadId displayTaskHandle;

void leds::enter_power_panic() {
Expand Down
2 changes: 1 addition & 1 deletion src/leds/side_strip_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void SideStripControl::Tick() {
active = true;

} else if (active_start_timestamp.has_value()) {
if (ticks_diff(ticks_ms(), active_start_timestamp.value()) > active_timeout_ms) {
if (ticks_diff(ticks_ms(), active_start_timestamp.value()) > (get_dimming_duration() * 1000)) {
active_start_timestamp.reset();
} else {
active = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,12 @@ struct CurrentStore

/// Whether the side leds should dim down a bit when user is not interacting with the printer or stay on full power the whole time
StoreItem<bool, true, journal::hash("Enable Side LEDs dimming")> side_leds_dimming_enabled;
StoreItem<int, 120, journal::hash("Side LEDs dimming duration")> side_leds_dimming_duration;

StoreItem<uint8_t, 100, journal::hash("Display backlight brightness")> leds_display_backlight_brightness;

StoreItem<bool, true, journal::hash("Enable Tool LEDs")> tool_leds_enabled;
StoreItem<uint8_t, 100, journal::hash("Tool LED brightness")> tool_leds_brightness;

StoreItem<float, 0.0f, journal::hash("Odometer X")> odometer_x;
StoreItem<float, 0.0f, journal::hash("Odometer Y")> odometer_y;
Expand Down
6 changes: 5 additions & 1 deletion src/puppies/Dwarf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,11 @@ void Dwarf::set_cheese_led(uint8_t pwr_selected, uint8_t pwr_not_selected) {
}

void Dwarf::set_cheese_led() {
set_cheese_led(config_store().tool_leds_enabled.get() ? 0xff : 0x00, 0x00);
uint8_t brightness = config_store().tool_leds_brightness.get();
if (brightness > 0) {
brightness = min(brightness / 100 * 255, 255);
}
set_cheese_led(config_store().tool_leds_enabled.get() ? brightness : 0x00, 0x00);
}

void Dwarf::set_status_led(dwarf_shared::StatusLed::Mode mode, uint8_t r, uint8_t g, uint8_t b) {
Expand Down