Skip to content

Commit

Permalink
added fade speed
Browse files Browse the repository at this point in the history
  • Loading branch information
rakalex committed Mar 2, 2024
1 parent 389fe69 commit 44ac98e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
4 changes: 3 additions & 1 deletion BrightnessControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions BrightnessControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 19 additions & 13 deletions main.m
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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[]) {
Expand Down Expand Up @@ -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();
}

0 comments on commit 44ac98e

Please sign in to comment.