Last active
December 18, 2015 00:08
-
-
Save corbett/5693929 to your computer and use it in GitHub Desktop.
Relevant code snippet for Philips Hue SDK to be put into color loop mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Just a snippet from a modified PHViewController.m in Philips Hue's iOS SDK. | |
Here I have a IBOutlet UISwitch *partyTimeSwitch | |
which is hooked up to a toggle Switch in my UI via Interface Builder */ | |
/** | |
Action for the party mode button | |
*/ | |
-(IBAction) switchValueChanged{ | |
PHLightState *lightState = [[PHLightState alloc] init]; | |
if(_partyTimeSwitch.on) { | |
[lightState setEffectMode:EFFECT_COLORLOOP]; | |
} | |
else { | |
[lightState setEffectMode:EFFECT_NONE]; | |
} | |
[self sendState:lightState]; | |
} | |
-(IBAction) toggleButtonPressed{ | |
if(_partyTimeSwitch.on){ | |
[_partyTimeSwitch setOn:NO animated:YES]; | |
} | |
else{ | |
[_partyTimeSwitch setOn:YES animated:YES]; | |
} | |
} | |
/** | |
Action sending state | |
*/ | |
- (void)sendState:(PHLightState*) lightState { | |
/*************************************************** | |
The BridgeSendAPI is used to send commands to the bridge. | |
Here we are updating the settings chosen by the user | |
for the selected light. | |
These settings are sent as a PHLightState to update | |
the light with the given light identifiers. | |
Subsequent checking of the Bridge Resources cache after the next heartbeat will | |
show that changed settings have occurred. | |
*****************************************************/ | |
[lightState setOnBool:YES]; | |
// Create a bridge send api, used for sending commands to bridge locally | |
id<PHBridgeSendAPI> bridgeSendAPI = [[[PHOverallFactory alloc] init] bridgeSendAPI]; | |
// Send lightstate to light | |
PHBridgeResourcesCache *cache = [PHBridgeResourcesReader readBridgeResourcesCache]; | |
for (id light in cache.lights) { | |
NSLog(@"light identifier is %@",light); | |
[bridgeSendAPI updateLightStateForId:light withLighState:lightState completionHandler:^(NSArray *errors) { | |
// Check for errors | |
if (errors != nil) { | |
for (PHError *error in errors) { | |
// Error occured | |
UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"Error" | |
message:error.description | |
delegate:nil | |
cancelButtonTitle:nil | |
otherButtonTitles:@"Ok", nil]; | |
[errorAlert show]; | |
} | |
} | |
}]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment