Skip to content

Commit

Permalink
Add control to change the tool leds brightness
Browse files Browse the repository at this point in the history
  • Loading branch information
bkerler committed Sep 1, 2024
1 parent 380323d commit 2b3d277
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/gui/MItem_menus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,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
8 changes: 8 additions & 0 deletions src/gui/MItem_menus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,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
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 @@ -39,7 +39,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
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ struct CurrentStore
StoreItem<int, 120, journal::hash("Side LEDs dimming duration")> side_leds_dimming_duration;

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

0 comments on commit 2b3d277

Please sign in to comment.