我正在构建一个控制三个飞利浦色调 RGB LED 灯泡的应用程序。我希望能够使用 UISlider 更改亮度。目前我有一个 UISlider 在每次更改时调用一个方法,但是,此方法远远超过了 philips hue 桥每秒 10 个命令的限制。这是我调用 UI 滑块更改的方法。
- (void) changeBulbBrightness: (NSNumber *)currentBrightness
{
NSTimeInterval timeInterval = [self.timeLastCommandSent timeIntervalSinceNow];
NSLog(@"Time Since Last command: %f", timeInterval);
if (timeInterval < -0.3)
{
NSLog(@"COMMAND SENT!!!!");
PHBridgeResourcesCache *cache = [PHBridgeResourcesReader readBridgeResourcesCache];
PHBridgeSendAPI *bridgeSendAPI = [[PHBridgeSendAPI alloc] init];
for (PHLight *light in cache.lights.allValues)
{
PHLightState *lightState = light.lightState;
//PHLightState *lightState = [[PHLightState alloc] init];
if (lightState.on)
{
[lightState setBrightness:currentBrightness];
// Send lightstate to light
[bridgeSendAPI updateLightStateForId:light.identifier withLightState:lightState completionHandler:^(NSArray *errors) {
/*if (errors != nil) {
NSString *message = [NSString stringWithFormat:@"%@: %@", NSLocalizedString(@"Errors", @""), errors != nil ? errors : NSLocalizedString(@"none", @"")];
if (self.loggingOn)
{
NSLog(@"Brightness Change Response: %@",message);
}
}
*/
}];
}
self.timeLastCommandSent = [[NSDate alloc]init];
}
}
self.appDelegate.currentSetup.brightnessSetting = currentBrightness;
NSLog(@"Brightness Now = %@", currentBrightness);
我尝试制作一个计时器来将命令数量限制为每秒 10 个,但是当它被命令淹没时,网桥仍然会以相同的方式运行(停止接受所有命令)。任何帮助或方向将不胜感激。提前致谢!