diff --git a/examples/04-AdvancedCeilingFan/04-AdvancedCeilingFan.ino b/examples/04-AdvancedCeilingFan/04-AdvancedCeilingFan.ino index 0f09f51..f849b2b 100644 --- a/examples/04-AdvancedCeilingFan/04-AdvancedCeilingFan.ino +++ b/examples/04-AdvancedCeilingFan/04-AdvancedCeilingFan.ino @@ -61,31 +61,40 @@ void setup() { new Characteristic::Version("1.1.0"); new Service::LightBulb(); - new Characteristic::On(true); // NEW: Providing an argument sets its initial value. In this case it means the LightBulb will be turned on at start-up - new Characteristic::Brightness(50); // NEW: This allows control of the Brightness of the LightBulb, with an initial value of 50% upon start-up (Note 1) - new SpanRange(20,100,5); // NEW: This sets the range of the Brightness to be from a min of 20%, to a max of 100%, in steps of 5% (Note 2) + new Characteristic::On(true); // NEW: Providing an argument sets its initial value. In this case it means the LightBulb will be turned on at start-up + + // In addition to setting the initial value of a Characteristic, it is also possible to override the default min/max/step range specified by HAP. + // We do this with the setRange() method: + + // setRange(min, max, step), where + // + // min = minimum allowed value + // max = maximum allowed value + // step = step size (can be left blank, in which case the HAP default is retained) + + // The setRange() method can be called on any numerical-based Characteristic that supports range overrides. The easiest way to apply to method is to call it right + // after instantiating a new Characteristic. Don't forget to surround the "new" command in parentheses when chaining a method in this fashion. + + // Here we create a Brightness Characteristic to set the brightness of the LightBulb with an initial value of 50% and an allowable range + // from 20-100% in steps of 5%. See Notes 1 and 2 below for more details: + + (new Characteristic::Brightness(50))->setRange(20,100,5); new Service::Fan(); new Characteristic::Active(); - new Characteristic::RotationDirection(); // NEW: This allows control of the Rotation Direction of the Fan - new Characteristic::RotationSpeed(25); // NEW: This allows control of the Rotation Speed of the Fan, with an initial value of 25% upon start-up (Note 1) - new SpanRange(0,100,25); // NEW: This sets the range of the Rotation Speed to be from a min of 0%, to a max of 100%, in steps of 25% - + new Characteristic::RotationDirection(); // NEW: This allows control of the Rotation Direction of the Fan + (new Characteristic::RotationSpeed(50))->setRange(0,100,25); // NEW: This allows control of the Rotation Speed of the Fan, with an initial value of 50% and a range from 0-100 in steps of 25% // NOTE 1: Setting the initial value of the Brightness Characteristic to 50% does not by itself cause HomeKit to turn the light on to 50% upon start-up. // Rather, this is governed by the initial value of the On Characteristic, which in this case happens to be set to true. If it were set to false, // or left unspecified (default is false) then the LightBulb will be off at start-up. However, it will jump to 50% brightness as soon as turned on // for the first time. This same logic applies to the Active and RotationSpeed Characteristics for a Fan. - // NOTE 2: The default range for Characteristics that support a range of values is specified in the HAP Section 9. For Brightness, the range defaults - // to min=0%, max=100%, step=1%. SpanRange(min,max,step) can be used to over-ride this default. SpanRange is generic and can be used wih other Characteristics - // that support a range of values, such as RotationSpeed. Whenever a new SpanRange is defined it is applied to the most recently defined Characteristic. - // It only has an effect if that Characteristic utilizes ranges. - - // RECOMMENDATION: Using SpanRange to change the minimum Brightness from 0% (the default) to 20% (or any non-zero value) provides for a better + // NOTE 2: The default range for Characteristics that support a range of values is specified in HAP Section 9. For Brightness, the range defaults + // to min=0%, max=100%, step=1%. Using setRange() to change the minimum Brightness from 0% to 20% (or any non-zero value) provides for a better // HomeKit experience. This is because the LightBulb power is controlled by the On Characteristic, and allowing Brightness to be as low as 0% // sometimes results in HomeKit turning on the LightBulb but with Brightness=0%, which is not very intuitive. This can occur when asking Siri - // to lower the Brightness all the way, and turnign on the LightBulb. By setting a minumum value of 20%, HomeKit always ensures that there is + // to lower the Brightness all the way, and then turning on the LightBulb. By setting a minumum value of 20%, HomeKit always ensures that there is // some Brightness value whenever the LightBulb is turned on. } // end of setup() diff --git a/examples/06-DimmableLED/DEV_LED.h b/examples/06-DimmableLED/DEV_LED.h index 6f24a9c..ba6f9e2 100644 --- a/examples/06-DimmableLED/DEV_LED.h +++ b/examples/06-DimmableLED/DEV_LED.h @@ -43,7 +43,7 @@ struct DEV_DimmableLED : Service::LightBulb { // Dimmable LED power=new Characteristic::On(); level=new Characteristic::Brightness(50); // NEW! Instantiate the Brightness Characteristic with an initial value of 50% (same as we did in Example 4) - new SpanRange(5,100,1); // NEW! This sets the range of the Brightness to be from a min of 5%, to a max of 100%, in steps of 1% (different from Example 4 values) + level->setRange(5,100,1); // NEW! This sets the range of the Brightness to be from a min of 5%, to a max of 100%, in steps of 1% (different from Example 4 values) this->channel=channel; // NEW! Save the channel number (from 0-15) this->pwmPin=new PwmPin(channel, ledPin); // NEW! Configures the PWM channel and attach the specified ledPin. pinMode() does NOT need to be called. diff --git a/examples/07-IdentifyRoutines/DEV_LED.h b/examples/07-IdentifyRoutines/DEV_LED.h index 0f3f027..0598e22 100644 --- a/examples/07-IdentifyRoutines/DEV_LED.h +++ b/examples/07-IdentifyRoutines/DEV_LED.h @@ -41,7 +41,7 @@ struct DEV_DimmableLED : Service::LightBulb { // Dimmable LED power=new Characteristic::On(); level=new Characteristic::Brightness(50); // Brightness Characteristic with an initial value of 50% - new SpanRange(5,100,1); // sets the range of the Brightness to be from a min of 5%, to a max of 100%, in steps of 1% + level->setRange(5,100,1); // sets the range of the Brightness to be from a min of 5%, to a max of 100%, in steps of 1% this->channel=channel; // save the channel number (from 0-15) this->pwmPin=new PwmPin(channel, ledPin); // configure the PWM channel and attach the specified ledPin. pinMode() does NOT need to be called. diff --git a/examples/08-Bridges/DEV_LED.h b/examples/08-Bridges/DEV_LED.h index 0f3f027..0598e22 100644 --- a/examples/08-Bridges/DEV_LED.h +++ b/examples/08-Bridges/DEV_LED.h @@ -41,7 +41,7 @@ struct DEV_DimmableLED : Service::LightBulb { // Dimmable LED power=new Characteristic::On(); level=new Characteristic::Brightness(50); // Brightness Characteristic with an initial value of 50% - new SpanRange(5,100,1); // sets the range of the Brightness to be from a min of 5%, to a max of 100%, in steps of 1% + level->setRange(5,100,1); // sets the range of the Brightness to be from a min of 5%, to a max of 100%, in steps of 1% this->channel=channel; // save the channel number (from 0-15) this->pwmPin=new PwmPin(channel, ledPin); // configure the PWM channel and attach the specified ledPin. pinMode() does NOT need to be called. diff --git a/examples/09-MessageLogging/DEV_LED.h b/examples/09-MessageLogging/DEV_LED.h index c639ca5..dc8e0ce 100644 --- a/examples/09-MessageLogging/DEV_LED.h +++ b/examples/09-MessageLogging/DEV_LED.h @@ -64,7 +64,7 @@ struct DEV_DimmableLED : Service::LightBulb { // Dimmable LED power=new Characteristic::On(); level=new Characteristic::Brightness(50); // Brightness Characteristic with an initial value of 50% - new SpanRange(5,100,1); // sets the range of the Brightness to be from a min of 5%, to a max of 100%, in steps of 1% + level->setRange(5,100,1); // sets the range of the Brightness to be from a min of 5%, to a max of 100%, in steps of 1% this->channel=channel; // save the channel number (from 0-15) this->ledPin=ledPin; // LED pin number <- NEW!! diff --git a/examples/10-RGB_LED/DEV_LED.h b/examples/10-RGB_LED/DEV_LED.h index f8c0cf4..d571420 100644 --- a/examples/10-RGB_LED/DEV_LED.h +++ b/examples/10-RGB_LED/DEV_LED.h @@ -56,7 +56,7 @@ struct DEV_DimmableLED : Service::LightBulb { // Dimmable LED power=new Characteristic::On(); level=new Characteristic::Brightness(50); // Brightness Characteristic with an initial value of 50% - new SpanRange(5,100,1); // sets the range of the Brightness to be from a min of 5%, to a max of 100%, in steps of 1% + level->setRange(5,100,1); // sets the range of the Brightness to be from a min of 5%, to a max of 100%, in steps of 1% this->channel=channel; // save the channel number (from 0-15) this->ledPin=ledPin; // save LED pin number @@ -116,7 +116,7 @@ struct DEV_RgbLED : Service::LightBulb { // RGB LED (Command Cathode) H=new Characteristic::Hue(0); // instantiate the Hue Characteristic with an initial value of 0 out of 360 S=new Characteristic::Saturation(0); // instantiate the Saturation Characteristic with an initial value of 0% V=new Characteristic::Brightness(100); // instantiate the Brightness Characteristic with an initial value of 100% - new SpanRange(5,100,1); // sets the range of the Brightness to be from a min of 5%, to a max of 100%, in steps of 1% + V->setRange(5,100,1); // sets the range of the Brightness to be from a min of 5%, to a max of 100%, in steps of 1% this->redChannel=redChannel; // save the channel number (from 0-15) this->greenChannel=greenChannel; diff --git a/examples/11-ServiceOptions/DEV_LED.h b/examples/11-ServiceOptions/DEV_LED.h index 77e6f67..1a9924c 100644 --- a/examples/11-ServiceOptions/DEV_LED.h +++ b/examples/11-ServiceOptions/DEV_LED.h @@ -56,7 +56,7 @@ struct DEV_DimmableLED : Service::LightBulb { // Dimmable LED power=new Characteristic::On(); level=new Characteristic::Brightness(50); // Brightness Characteristic with an initial value of 50% - new SpanRange(5,100,1); // sets the range of the Brightness to be from a min of 5%, to a max of 100%, in steps of 1% + level->setRange(5,100,1); // sets the range of the Brightness to be from a min of 5%, to a max of 100%, in steps of 1% this->channel=channel; // save the channel number (from 0-15) this->ledPin=ledPin; // save LED pin number diff --git a/examples/13-TargetStates/DEV_DoorsWindows.h b/examples/13-TargetStates/DEV_DoorsWindows.h index c9a3dfb..672e450 100644 --- a/examples/13-TargetStates/DEV_DoorsWindows.h +++ b/examples/13-TargetStates/DEV_DoorsWindows.h @@ -71,11 +71,11 @@ struct DEV_WindowShade : Service::WindowCovering { // A motorized Window Sha DEV_WindowShade() : Service::WindowCovering(){ // constructor() method - current=new Characteristic::CurrentPosition(0); // Windows Shades have positions that range from 0 (fully lowered) to 100 (fully raised) - new SpanRange(0,100,10); // set the allowable current-position range to 0-100 IN STEPS of 10 + current=new Characteristic::CurrentPosition(0); // Window Shades have positions that range from 0 (fully lowered) to 100 (fully raised) + current->setRange(0,100,10); // set the allowable current-position range to 0-100 IN STEPS of 10 - target=new Characteristic::TargetPosition(0); // Windows Shades have positions that range from 0 (fully lowered) to 100 (fully raised) - new SpanRange(0,100,10); // set the allowable target-position range to 0-100 IN STEPS of 10 + target=new Characteristic::TargetPosition(0); // Window Shades have positions that range from 0 (fully lowered) to 100 (fully raised) + target->setRange(0,100,10); // set the allowable target-position range to 0-100 IN STEPS of 10 Serial.print("Configuring Motorized Window Shade"); // initialization message Serial.print("\n"); diff --git a/examples/15-RealPushButtons/DEV_LED.h b/examples/15-RealPushButtons/DEV_LED.h index f454f11..2b22f05 100644 --- a/examples/15-RealPushButtons/DEV_LED.h +++ b/examples/15-RealPushButtons/DEV_LED.h @@ -33,7 +33,7 @@ struct DEV_DimmableLED : Service::LightBulb { // Dimmable LED power=new Characteristic::On(); level=new Characteristic::Brightness(favoriteLevel); // Brightness Characteristic with an initial value equal to the favorite level - new SpanRange(5,100,1); // sets the range of the Brightness to be from a min of 5%, to a max of 100%, in steps of 1% + level->setRange(5,100,1); // sets the range of the Brightness to be from a min of 5%, to a max of 100%, in steps of 1% // NEW! Below we create three SpanButton() objects. In the first we specify the pin number, as required, but allow SpanButton() to use // its default values for a LONG press (2000 ms), a SINGLE press (5 ms), and a DOUBLE press (200 ms). In the second and third we change the diff --git a/src/HomeSpan.h b/src/HomeSpan.h index d2d1fb7..6744bd7 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -359,7 +359,7 @@ struct SpanCharacteristic{ uvSet(stepValue,step); customRange=true; - if(step>0) + if(uvGet(stepValue)>0) sprintf(c,": %s/%s/%s\n",uvPrint(minValue),uvPrint(maxValue),uvPrint(stepValue)); else sprintf(c,": %s/%s\n",uvPrint(minValue),uvPrint(maxValue));