From 44ac98ecd7f94b87f5f8485b7a27113ca0030a2e Mon Sep 17 00:00:00 2001 From: Alex Rak Date: Sat, 2 Mar 2024 21:55:04 +0200 Subject: [PATCH] added fade speed --- BrightnessControl.h | 4 +++- BrightnessControl.m | 7 ++++--- main.m | 32 +++++++++++++++++++------------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/BrightnessControl.h b/BrightnessControl.h index 530f95a..fda5332 100644 --- a/BrightnessControl.h +++ b/BrightnessControl.h @@ -10,6 +10,8 @@ + (void)setIdleDimTime:(double)value; + (double)idleDimTimeForKeyboard; + (void)enableAutoBrightness:(bool)value; -+ (void)flashKeyboardLights:(int)times withInterval:(double)interval; ++ (void)flashKeyboardLights:(int)times + withInterval:(double)interval + andFadeSpeed:(double)fadeSpeed; @end diff --git a/BrightnessControl.m b/BrightnessControl.m index 9d66bf0..3595145 100644 --- a/BrightnessControl.m +++ b/BrightnessControl.m @@ -35,15 +35,16 @@ + (void)enableAutoBrightness:(bool)value { [KeyboardManager.brightnessClient enableAutoBrightness:value forKeyboard:1]; } -+ (void)flashKeyboardLights:(int)times withInterval:(double)interval { ++ (void)flashKeyboardLights:(int)times withInterval:(double)interval andFadeSpeed:(double)fadeSpeed { float current = [self getBrightness]; for (int i = 0; i < times; i++) { - [self setBrightness:0]; + [KeyboardManager.brightnessClient setBrightness:0 fadeSpeed:fadeSpeed commit:true forKeyboard:1]; [NSThread sleepForTimeInterval:interval]; - [self setBrightness:1]; + [KeyboardManager.brightnessClient setBrightness:1 fadeSpeed:fadeSpeed commit:true forKeyboard:1]; [NSThread sleepForTimeInterval:interval]; } [self setBrightness:current]; } + @end diff --git a/main.m b/main.m index 55144f4..9ddfca0 100644 --- a/main.m +++ b/main.m @@ -58,7 +58,8 @@ void printUsage(void) { printf(" -a Enable or disable auto-brightness. Use '1' or '0'.\n"); printf(" -s Suspend or resume idle dimming. Use '1' or '0'.\n"); printf(" -t Set the idle dim time in seconds.\n"); - printf(" -f Flash the keyboard lights [n] times with interval [t] seconds. Handy for creating visual alerts, notifications, or attention-grabbing effects.\n\n"); + printf(" -f Flash the keyboard lights [n] times with interval [t] seconds and optional fade speed [s].\n" + " Useful for creating visual alerts, notifications, or attention-grabbing effects. If [s] is not provided, the default fade speed is 500 milliseconds.\n\n"); printf("Examples:\n"); printf(" mac-brightnessctl 0.75 Set brightness to 75%%\n"); @@ -69,7 +70,7 @@ void printUsage(void) { printf(" mac-brightnessctl -s 1 Suspend idle dimming\n"); printf(" mac-brightnessctl -t Get current state of idle dim time\n"); printf(" mac-brightnessctl -t 5 Set idle dim time to 5 seconds\n"); - printf(" mac-brightnessctl -f 5 0.5 Flashing 5 times with interval 0.5 seconds\n"); + printf(" mac-brightnessctl -f 5 0.5 [s] Flash the keyboard lights 5 times with an interval of 0.5 seconds and optional fade speed [s]. If [s] is not provided, the default fade speed is 500 milliseconds.\n"); } void handleAutoBrightness(int argc, const char *argv[]) { @@ -144,18 +145,23 @@ void handleSetBrightness(int argc, const char *argv[]) { } void handleFlashKeyboardLights(int argc, const char *argv[]) { - if (argc == 4) { - int flashTimes = atoi(argv[2]); - double flashInterval = atof(argv[3]); + int flashTimes, fadeSpeed = 500; // Default fade speed + double flashInterval; - if (flashTimes > 0 && flashInterval > 0) { - [BrightnessControl flashKeyboardLights:flashTimes withInterval:flashInterval]; - } else { - printf("Error: Invalid input for flashing keyboard lights. Ensure both values are positive.\n"); - printUsage(); + if (argc == 4 || argc == 5) { + flashTimes = atoi(argv[2]); + flashInterval = atof(argv[3]); + + if (argc == 5) { + fadeSpeed = atof(argv[4]); + } + + if (flashTimes > 0 && flashInterval > 0 && fadeSpeed >= 0) { + [BrightnessControl flashKeyboardLights:flashTimes withInterval:flashInterval andFadeSpeed:fadeSpeed]; + return; } - } else { - printf("Error: Invalid number of arguments for flashing keyboard lights\n"); - printUsage(); } + + printf("Error: Invalid arguments for flashing keyboard lights\n"); + printUsage(); }