diff --git a/Macro/PartialMap/macro.h b/Macro/PartialMap/macro.h index 8380a4007..f3843566e 100644 --- a/Macro/PartialMap/macro.h +++ b/Macro/PartialMap/macro.h @@ -39,6 +39,8 @@ void Macro_rotationState( uint8_t index, int8_t increment ); uint8_t Macro_tick_update( TickStore *store, uint8_t type ); void Macro_periodic(); +void Screensaver_periodic(); + void Macro_poll(); void Macro_setup(); diff --git a/Macro/PixelMap/capabilities.kll b/Macro/PixelMap/capabilities.kll index 384294242..98019534d 100644 --- a/Macro/PixelMap/capabilities.kll +++ b/Macro/PixelMap/capabilities.kll @@ -28,6 +28,14 @@ LEDGamma = 2.2; gamma_enabled => Pixel_gamma_default_define; gamma_enabled = "0"; # 0 - Disabled, 1 - Enabled +# Keyboard screensaver settings: block animations on a given key press for some ms/shut down LEDs after some s of inactivity +animation_screensaver_update => Pixel_AnimationScreenSaverUpdate(); +screensaver_led_shutdown => Pixel_screensaver_default_led_shutdown; +screensaver_led_shutdown = "0"; # number of seconds before the leds are shutdown; if 0, screensaver is disabled +screensaver_block_animation => Pixel_screensaver_default_block_animation; +screensaver_block_animation = "0"; #number of MILLIseconds to block animation when key is pressed; if 0, animation is not blocked, if screensaver disabled this is ignored +# enable screensaver with 'U[4-101,103-164,176-221,224-231,240-289] :+ animation_screensaver_update();' , the key codes counting as an 'action' to stop screensaver to go to sleep (here all kira keys) + # Animation Control # 0 - Pause/Resume # 1 - ForwardOne diff --git a/Macro/PixelMap/pixel.c b/Macro/PixelMap/pixel.c index 06438d4c8..720ceb1eb 100644 --- a/Macro/PixelMap/pixel.c +++ b/Macro/PixelMap/pixel.c @@ -132,6 +132,14 @@ CLIDict_Def( pixelCLIDict, "Pixel Module Commands" ) = { extern const uint8_t gamma_table[]; static uint8_t gamma_enabled; +//Keyboard screensaver +static uint32_t screensaver_led_shutdown; +static uint32_t screensaver_block_animation; + +//ms when the last keystroke happened (valid iff screensaver is enabled) +static volatile uint32_t last_key_stroke_time_ms; + + // Debug states PixelTest Pixel_testMode; volatile uint16_t Pixel_testPos = 0; @@ -588,6 +596,17 @@ void Pixel_FadeLayerHighlight_capability( TriggerMacro *trigger, uint8_t state, } } +void Pixel_AnimationScreenSaverUpdate( TriggerMacro *trigger, uint8_t state, uint8_t stateType, uint8_t *args ) +{ + if ( screensaver_led_shutdown ) { + last_key_stroke_time_ms = Time_now().ms; + LED_SetPixels(1); + if ( screensaver_block_animation ) { + Pixel_animationControl = AnimationControl_Pause; + } + } +} + // ----- Functions ----- @@ -1969,6 +1988,10 @@ void Pixel_SecondaryProcessing_setup() // Set default gamma setting gamma_enabled = Pixel_gamma_default_define; + // Set default screensaver settings + screensaver_block_animation = Pixel_screensaver_default_block_animation; + screensaver_led_shutdown = Pixel_screensaver_default_led_shutdown; + // Disable all fade profiles (active defaults afterwards) memset( Pixel_pixel_fade_profile, 0, Pixel_TotalPixels_KLL ); @@ -2544,6 +2567,25 @@ inline void Pixel_process() Latency_end_time( pixelLatencyResource ); } +//Screensaver periodic activity check to block animations/disable LEDs +void Screensaver_periodic() +{ + if ( screensaver_led_shutdown ) { + const uint32_t now = Time_now().ms; + if ( now <= last_key_stroke_time_ms+screensaver_block_animation ) { + return; + } + + if ( now <= last_key_stroke_time_ms+(screensaver_led_shutdown*1000) ) { + if ( screensaver_block_animation ) { + Pixel_animationControl = AnimationControl_Forward; + } + return; + } + + LED_SetPixels(0); + } +} inline void Pixel_setup() { diff --git a/Macro/PixelMap/pixel.h b/Macro/PixelMap/pixel.h index 829d22108..020ef9d69 100644 --- a/Macro/PixelMap/pixel.h +++ b/Macro/PixelMap/pixel.h @@ -277,3 +277,5 @@ void Pixel_setup(); void Pixel_setAnimationControl( AnimationControl control ); +void LED_SetPixels( uint8_t shouldSetOn ); + diff --git a/Scan/Devices/ISSILed/led_scan.c b/Scan/Devices/ISSILed/led_scan.c index 51f1720d8..9d188abab 100644 --- a/Scan/Devices/ISSILed/led_scan.c +++ b/Scan/Devices/ISSILed/led_scan.c @@ -1113,6 +1113,14 @@ void LED_control( LedControl control, uint8_t arg ) #endif } +void LED_SetPixels( uint8_t shouldSetOn ) +{ + if ( shouldSetOn ) + LED_control( LedControl_on, 0 ); + else + LED_control( LedControl_off, 0 ); +} + void LED_control_capability( TriggerMacro *trigger, uint8_t state, uint8_t stateType, uint8_t *args ) { CapabilityState cstate = KLL_CapabilityState( state, stateType ); diff --git a/main.c b/main.c index 28256bcc6..9ab8e95ec 100644 --- a/main.c +++ b/main.c @@ -46,6 +46,7 @@ typedef enum PeriodicStage { PeriodicStage_Scan, PeriodicStage_Macro, PeriodicStage_Output, + PeriodicStage_Screensaver, } PeriodicStage; @@ -55,6 +56,9 @@ typedef enum PeriodicStage { // Periodic Stage Tracker static volatile PeriodicStage stage_tracker; +//Number of times a complete periodic function rotation need to be run to try to check screensaver timing +static volatile uint8_t screensaver_div; + // ----- Functions ----- @@ -92,8 +96,16 @@ int main_periodic() // Send periodic USB results SEGGER_SYSVIEW_OnTaskStartExec(TASK_OUTPUT_PERIODIC); Output_periodic(); - stage_tracker = PeriodicStage_Scan; + stage_tracker = PeriodicStage_Screensaver; SEGGER_SYSVIEW_OnTaskTerminate(TASK_OUTPUT_PERIODIC); + break; + + case PeriodicStage_Screensaver: + if ( !screensaver_div-- ) { + screensaver_div = 100; + Screensaver_periodic(); + } + stage_tracker = PeriodicStage_Scan; // Full rotation return 1; @@ -143,6 +155,9 @@ int main() // Start scanning on first periodic loop stage_tracker = PeriodicStage_Scan; + // Fill defautl screensaver div value + screensaver_div = 100; + #if DEBUG_RESETS // Blink to indicate a reset happened errorLED(0);