repetier / Repetier-Firmware

Firmware for Arduino based RepRap 3D printer.
815 stars 734 forks source link

Method to check if controller has not been used for a period of time #1072

Closed nukem closed 3 years ago

nukem commented 3 years ago

The method can be used to turn on and off lights like controller backlight and case lights.

#if defined(UI_BACKLIGHT_PIN) && UI_BACKLIGHT_PIN > 0
IO_OUTPUT(controllerBackLightPin, UI_BACKLIGHT_PIN)
LIGHT_STATE_MONOCHROME(controllerBackLightState)
**LIGHT_COND(controllerBackLightState, true, !GUI::isGUIIdle(), 255, 255, 255, 255)**
LIGHT_SOURCE_MONOCHROME(controllerBackLightDriver, controllerBackLightPin, controllerBackLightState)
#endif

IO_OUTPUT(caseLightPin, CASE_LIGHT_PIN)
LIGHT_STATE_MONOCHROME(caseLightState)
LIGHT_COND(caseLightState, true, Printer::caseLightMode, 255, 255, 255, 255)
LIGHT_COND(caseLightState, Printer::isUIErrorMessage(), LIGHT_STATE_BLINK_SLOW, 255, 255, 255, 255)
LIGHT_COND(caseLightState, Printer::isDoorOpen(), LIGHT_STATE_ON, 255, 255, 255, 255)
**LIGHT_COND(caseLightState, true,  !GUI::isGUIIdle(), 255, 255, 255, 255)**
LIGHT_SOURCE_MONOCHROME(caseLightDriver, caseLightPin, caseLightState)
repetier commented 3 years ago

No need to wast memory with a state. I have uploaded an alternative where the computation is done in GUI::isGUIIdle() directly. The few extra cycles there should be no problem.

nukem commented 3 years ago

Ah ok, I thought it would hang if it was inline.