Skip to content

Instantly share code, notes, and snippets.

@corbett
Last active December 18, 2015 00:08
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 corbett/5693929 to your computer and use it in GitHub Desktop.
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
/* 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