Skip to content

Commit

Permalink
Add rgb status bar brightness control and rgb side bar dimming duration
Browse files Browse the repository at this point in the history
  • Loading branch information
bkerler committed Aug 31, 2024
1 parent f5a498a commit f2982e2
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 6 deletions.
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
34 changes: 34 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,22 @@ void MI_LEDS_ENABLE::OnChange(size_t old_index) {
}
#endif

#if HAS_LEDS()
/**********************************************************************************************/
// MI_LEDS_BRIGHTNESS
static constexpr NumericInputConfig led_brightness_spin_config = {
.max_value = 100,
};

MI_LEDS_BRIGHTNESS::MI_LEDS_BRIGHTNESS()
: WiSpin(config_store().leds_statusbar_brightness.get(), led_brightness_spin_config, _(label), nullptr, is_enabled_t::yes, is_hidden_t::no) {
}
void MI_LEDS_BRIGHTNESS::OnClick() {
leds::SetBrightness(GetVal());
leds::store_statusbar_brightness(GetVal());
}
#endif

#if HAS_SIDE_LEDS()
/**********************************************************************************************/
// MI_SIDE_LEDS_ENABLE
Expand All @@ -560,6 +577,23 @@ void MI_SIDE_LEDS_DIMMING::OnChange(size_t) {
}
#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 ENABLED(PRUSA_TOOLCHANGER)
/**********************************************************************************************/
// MI_TOOL_LEDS_ENABLE
Expand Down
22 changes: 22 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_LEDS_BRIGHTNESS : public WiSpin {
static constexpr const char *const label = N_("RGB Status Bar Brightness");

public:
MI_LEDS_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 @@ -421,7 +431,9 @@ class MI_SIDE_LEDS_ENABLE : public WI_ICON_SWITCH_OFF_ON_t {
MI_SIDE_LEDS_ENABLE();
virtual void OnChange(size_t old_index) override;
};
#endif

#if HAS_SIDE_LEDS()
class MI_SIDE_LEDS_DIMMING : public WI_ICON_SWITCH_OFF_ON_t {
static constexpr const char *const label = N_("RGB Side Strip Dimming");

Expand All @@ -431,6 +443,16 @@ class MI_SIDE_LEDS_DIMMING : public WI_ICON_SWITCH_OFF_ON_t {
};
#endif

#if HAS_SIDE_LEDS()
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()
class MI_TOOL_LEDS_ENABLE : public WI_ICON_SWITCH_OFF_ON_t {
static constexpr const char *const label = N_("Tool Light");
Expand Down
3 changes: 2 additions & 1 deletion 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_LEDS_BRIGHTNESS
#endif
#if HAS_SIDE_LEDS()
,
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 @@ -45,12 +45,26 @@ void TickLoop();
void SetNth(Color clr, index n);

/**
* @brief Set the Brightness of display
* @brief Set the Brightness of the display RGB status bar
*
* @param percent Brightness in range 0 - 100
*/
void SetBrightness(unsigned percent);

/**
* @brief Read the Brightness of the display RGB status bar from ConfigStore
*
* @return percent Brightness in range 0 - 100
*/
uint8_t get_statusbar_brightness();

/**
* @brief Store the Brightness of the display RGB status bar to ConfigStore
*
* @param percent Brightness in range 0 - 100
*/
void store_statusbar_brightness(uint8_t percent);

/**
* @brief Forces write on next call of tick loop
* @param cnt How many leds to refresh
Expand Down
14 changes: 12 additions & 2 deletions src/guiapi/src/gui_leds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,29 @@ Neopixels &getNeopixels() {

void leds::Init() {
// Turn on LCD backlight
// TODO move SetBrightness to display
leds::SetBrightness(100);
leds::TickLoop();
leds::SetBrightness(leds::get_statusbar_brightness());

#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
}

void leds::ForceRefresh(size_t cnt) {
getNeopixels().ForceRefresh(cnt);
}

uint8_t leds::get_statusbar_brightness() {
return config_store().leds_statusbar_brightness.get();
}

void leds::store_statusbar_brightness(uint8_t percent) {
leds::SetBrightness(percent);
return config_store().leds_statusbar_brightness.set(percent);
}

void leds::TickLoop() {
getNeopixels().Tick();

Expand Down
10 changes: 9 additions & 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 Expand Up @@ -230,3 +230,11 @@ void SideStripControl::PanicOff() {
std::unique_lock lock(mutex);
state = State::Off;
}

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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ 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 status bar RGB brightness")> leds_statusbar_brightness;

StoreItem<bool, true, journal::hash("Enable Tool LEDs")> tool_leds_enabled;

Expand Down

0 comments on commit f2982e2

Please sign in to comment.