From 40dcb6a4e759f2d5e955085949e9e6bf7268c960 Mon Sep 17 00:00:00 2001 From: rpappa Date: Sun, 11 Oct 2015 18:24:25 -0400 Subject: [PATCH 1/5] Added a dim function --- GammaTest.xcodeproj/project.pbxproj | 2 +- GammaTest/AppDelegate.m | 3 +- GammaTest/GammaController.h | 1 + GammaTest/GammaController.m | 34 ++++++++++++++++++- GammaTest/Info.plist | 2 +- GammaTest/Launch Screen.xib | 4 +-- GammaTest/MainViewController.m | 21 ++++++++++-- GammaTest/Storyboard.storyboard | 52 +++++++++++++++++++++-------- 8 files changed, 98 insertions(+), 21 deletions(-) diff --git a/GammaTest.xcodeproj/project.pbxproj b/GammaTest.xcodeproj/project.pbxproj index 915df84..49b613f 100644 --- a/GammaTest.xcodeproj/project.pbxproj +++ b/GammaTest.xcodeproj/project.pbxproj @@ -241,7 +241,7 @@ TargetAttributes = { B9E536451B38D90D0097BF90 = { CreatedOnToolsVersion = 7.0; - DevelopmentTeam = 323K5AM3T4; + DevelopmentTeam = 8JV4RNF2B3; SystemCapabilities = { com.apple.BackgroundModes = { enabled = 1; diff --git a/GammaTest/AppDelegate.m b/GammaTest/AppDelegate.m index f32012b..732a28f 100644 --- a/GammaTest/AppDelegate.m +++ b/GammaTest/AppDelegate.m @@ -20,11 +20,12 @@ @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - [application setMinimumBackgroundFetchInterval:900]; //Wake up every 15 minutes at minimum + [application setMinimumBackgroundFetchInterval:30]; //Wake up every 15 minutes at minimum [[NSUserDefaults standardUserDefaults] registerDefaults:@{ @"enabled": @NO, @"maxOrange": @0.7, + @"dim": @0, @"colorChangingEnabled": @YES, @"lastAutoChangeDate": [NSDate distantPast], @"autoStartHour": @19, diff --git a/GammaTest/GammaController.h b/GammaTest/GammaController.h index af749ee..dfe764d 100644 --- a/GammaTest/GammaController.h +++ b/GammaTest/GammaController.h @@ -12,6 +12,7 @@ + (void)setGammaWithRed:(float)red green:(float)green blue:(float)blue; + (void)setGammaWithOrangeness:(float)percentOrange; ++ (void)setGammaWithOrangenessAndDim:(float)percentOrange percentDim:(float)percentDim; + (void)enableOrangeness; + (void)disableOrangeness; diff --git a/GammaTest/GammaController.m b/GammaTest/GammaController.m index f74a154..fd0d43f 100644 --- a/GammaTest/GammaController.m +++ b/GammaTest/GammaController.m @@ -28,6 +28,9 @@ @implementation GammaController +float dimCap = 0.85; //only allows you to dim to this percent to prevent completetely blacking out the screen + + //This function is largely the same as the one in iomfsetgamma.c from Saurik's UIKitTools package. The license is pasted below. /* UIKit Tools - command-line utilities for UIKit @@ -162,10 +165,39 @@ + (void)setGammaWithOrangeness:(float)percentOrange { [self setGammaWithRed:red green:green blue:blue]; } ++ (void)setGammaWithOrangenessAndDim:(float)percentOrange percentDim:(float)percentDim { + if (percentOrange > 1) + percentOrange = 1; + else if (percentOrange < 0) + percentOrange = 0; + + if (percentDim > 1) + percentDim = 1; + else if (percentDim < 0) + percentDim = 0; + percentDim = 1-percentDim * dimCap; + +// float red = 0.3; +// float blue = 0.3; +// float green = 0.3; + + float red = (1.0); + float blue = (1 - percentOrange); + float green = (red + blue)/2.0*percentDim; + red *= percentDim; + blue *= percentDim; + + if (percentOrange == 0) { + red = blue = green = 0.99*percentDim; + } + + [self setGammaWithRed:red green:green blue:blue]; +} + + (void)enableOrangeness { NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; [self wakeUpScreenIfNeeded]; - [GammaController setGammaWithOrangeness:[defaults floatForKey:@"maxOrange"]]; + [GammaController setGammaWithOrangenessAndDim:[defaults floatForKey:@"maxOrange"] percentDim:[defaults floatForKey:@"dim"]]; [defaults setObject:[NSDate date] forKey:@"lastOnDate"]; [defaults setBool:YES forKey:@"enabled"]; } diff --git a/GammaTest/Info.plist b/GammaTest/Info.plist index 4dc82f6..43fbfbc 100644 --- a/GammaTest/Info.plist +++ b/GammaTest/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) + com.rpappa.$(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/GammaTest/Launch Screen.xib b/GammaTest/Launch Screen.xib index f7b4719..70f375e 100644 --- a/GammaTest/Launch Screen.xib +++ b/GammaTest/Launch Screen.xib @@ -1,8 +1,8 @@ - + - + diff --git a/GammaTest/MainViewController.m b/GammaTest/MainViewController.m index 6d70802..3eabb46 100644 --- a/GammaTest/MainViewController.m +++ b/GammaTest/MainViewController.m @@ -15,6 +15,7 @@ @interface MainViewController () @property (weak, nonatomic) IBOutlet UISwitch *colorChangingEnabledSwitch; @property (weak, nonatomic) IBOutlet UITextField *startTimeTextField; @property (weak, nonatomic) IBOutlet UITextField *endTimeTextField; +@property (weak, nonatomic) IBOutlet UISlider *dimSlider; @end @@ -22,10 +23,14 @@ @implementation MainViewController @synthesize enabledSwitch; @synthesize orangeSlider; +@synthesize dimSlider; @synthesize colorChangingEnabledSwitch; @synthesize startTimeTextField; @synthesize endTimeTextField; +float orange; +float dim; + - (void)viewDidLoad { [super viewDidLoad]; @@ -38,6 +43,9 @@ - (void)viewDidLoad { self.tableView.alwaysBounceVertical = NO; enabledSwitch.on = [defaults boolForKey:@"enabled"]; orangeSlider.value = [defaults floatForKey:@"maxOrange"]; + dimSlider.value = [defaults floatForKey:@"dim"]; + orange = [defaults floatForKey:@"maxOrange"]; + dim = [defaults floatForKey:@"dim"]; colorChangingEnabledSwitch.on = [defaults boolForKey:@"colorChangingEnabled"]; NSDate *date = [self dateForHour:[defaults integerForKey:@"autoStartHour"] andMinute:[defaults integerForKey:@"autoStartMinute"]]; @@ -63,18 +71,27 @@ - (void)viewDidLoad { - (IBAction)enabledSwitchChanged:(UISwitch *)sender { if (sender.on) - [GammaController setGammaWithOrangeness:[[NSUserDefaults standardUserDefaults] floatForKey:@"maxOrange"]]; + [GammaController setGammaWithOrangenessAndDim:[[NSUserDefaults standardUserDefaults] floatForKey:@"maxOrange"] percentDim:[[NSUserDefaults standardUserDefaults] floatForKey:@"dim"]]; else [GammaController setGammaWithOrangeness:0]; [[NSUserDefaults standardUserDefaults] setBool:sender.on forKey:@"enabled"]; } + - (IBAction)maxOrangeSliderChanged:(UISlider *)sender { [[NSUserDefaults standardUserDefaults] setFloat:sender.value forKey:@"maxOrange"]; + orange = sender.value; + + if (enabledSwitch.on) + [GammaController setGammaWithOrangenessAndDim:orange percentDim:dim]; +} +- (IBAction)dimSliderChanged:(UISlider *)sender { + [[NSUserDefaults standardUserDefaults] setFloat:sender.value forKey:@"dim"]; + dim = sender.value; if (enabledSwitch.on) - [GammaController setGammaWithOrangeness:sender.value]; + [GammaController setGammaWithOrangenessAndDim:orange percentDim:dim]; } - (IBAction)colorChangingEnabledSwitchChanged:(UISwitch *)sender { diff --git a/GammaTest/Storyboard.storyboard b/GammaTest/Storyboard.storyboard index ec97b7d..a7ba55e 100644 --- a/GammaTest/Storyboard.storyboard +++ b/GammaTest/Storyboard.storyboard @@ -1,8 +1,8 @@ - + - + @@ -39,7 +39,7 @@ - + @@ -75,10 +75,10 @@ - + - + @@ -100,14 +100,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + Automatic color changing uses the background fetch feature to turn on or off orangeness. It doesn't happen immediately when the start or end times are passed, and won't work if background app refresh is disabled or iOS 9 low power mode is on. If your device's screen turns on randomly, that's the app making sure the screen is on before changing the color. - + - + @@ -139,13 +164,13 @@ - + - + - - + - + -