Skip to content

Instantly share code, notes, and snippets.

@diimdeep
Created October 28, 2022 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diimdeep/7ff77e6245a42665c05c69849614813b to your computer and use it in GitHub Desktop.
Save diimdeep/7ff77e6245a42665c05c69849614813b to your computer and use it in GitHub Desktop.
Cycle temperature
#import <Foundation/Foundation.h>
// Partial header for CBBlueLightClient in private CoreBrightness API
@interface CBBlueLightClient : NSObject
- (BOOL)setStrength:(float)strength commit:(BOOL)commit;
- (BOOL)setEnabled:(BOOL)enabled;
@end
int main(int argc, const char * argv[]) {
CBBlueLightClient *client = [[CBBlueLightClient alloc] init];
float min = 1;
float max = 100;
float cycle_time = 90.0;
float update_interval = 3.0;
float range = max - min;
if (argc > 1) {
cycle_time = [[NSString stringWithUTF8String:argv[1]] floatValue];
update_interval = [[NSString stringWithUTF8String:argv[2]] floatValue];
}
float acc = range * update_interval / cycle_time;
float current_str = 1;
bool is_inc = true;
while(true) {
if (current_str >= 100){
current_str = 100;
is_inc = false;
} else if (current_str <= 1) {
current_str = 1;
is_inc = true;
}
[client setStrength:current_str/100.0 commit:true];
[client setEnabled:true];
// NSLog(@"%@", [NSString stringWithFormat:@"%1.2f", current_str]);
current_str += is_inc ? acc : -acc;
[NSThread sleepForTimeInterval:update_interval];
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment