예제 #1
0
        public static string GetJsonStringFromParamEnum(Constants.EffectParamValues value)
        {
            switch (value)
            {
            case Constants.EffectParamValues.SUDDEN:
                return("\"sudden\"");

            case Constants.EffectParamValues.SMOOTH:
                return("\"smooth\"");
            }
            return(string.Empty);
        }
예제 #2
0
 /// <summary>
 /// Sets the light device's power state
 /// </summary>
 /// <param name="powerState"> The power state to set the light device to, can be anything from Constants.PowerStateParamValues</param>
 /// <param name="duration"> Duration of the effect, minimum value for this argument is Constants.MinValueForDurationParameter and so is the default value</param>
 /// <param name="effectType"> Type of the effect, can be anything from Constants.EffectParamValues and default value is Constants.EffectParamValues.SUDDEN</param>
 /// <remarks>
 /// Throws if duration argument is out of range or if device is not connected
 /// </remarks>
 public bool SetPower(Constants.PowerStateParamValues powerState,
                      int duration = Constants.MinValueForDurationParameter,
                      Constants.EffectParamValues effectType = Constants.EffectParamValues.SUDDEN)
 {
     ThrowExceptionIfIntArgIsOutOfRange("duration", duration, Constants.MinValueForDurationParameter);
     ThrowExceptionIfNotConnected();
     return(SendCommandMessage(1,
                               "set_power",
                               new string[] {
         Utils.GetJsonStringFromParamEnum(powerState),
         Utils.GetJsonStringFromParamEnum(effectType),
         duration.ToString(System.Globalization.CultureInfo.InvariantCulture)
     }));
 }
예제 #3
0
 /// <summary>
 /// Sets the light device to white mode with the given temperature
 /// </summary>
 /// <param name="temperature"> The integer value of temperature to set the light device's color temperature</param>
 /// <param name="duration"> Duration of the effect, minimum value for this argument is Constants.MinValueForDurationParameter and so is the default value</param>
 /// <param name="effectType"> Type of the effect, can be anything from Constants.EffectParamValues and default value is Constants.EffectParamValues.SUDDEN</param>
 /// <remarks>
 /// Throws if duration argument is out of range, the temperature argument is out of range or if device is not connected
 /// </remarks>
 public bool SetColorTemperature(
     int temperature,
     int duration = Constants.MinValueForDurationParameter,
     Constants.EffectParamValues effectType = Constants.EffectParamValues.SUDDEN)
 {
     ThrowExceptionIfIntArgIsOutOfRange("duration", duration, Constants.MinValueForDurationParameter);
     ThrowExceptionIfIntArgIsOutOfRange("temperature", temperature, Constants.MinValueForTemperatureParameter, Constants.MaxValueForTemperatureParameter);
     ThrowExceptionIfNotConnected();
     return(SendCommandMessage(1,
                               "set_ct_abx",
                               new string[] {
         temperature.ToString(System.Globalization.CultureInfo.InvariantCulture),
         Utils.GetJsonStringFromParamEnum(effectType),
         duration.ToString(System.Globalization.CultureInfo.InvariantCulture)
     }));
 }
예제 #4
0
 /// <summary>
 /// Sets the light device's brightness
 /// </summary>
 /// <param name="brightness"> The brightness to set the light device to, range is 0 to 100.</param>
 /// <param name="duration"> Duration of the effect, minimum value for this argument is Constants.MinValueForDurationParameter and so is the default value</param>
 /// <param name="effectType"> Type of the effect, can be anything from Constants.EffectParamValues and default value is Constants.EffectParamValues.SUDDEN</param>
 /// <remarks>
 /// Throws if duration or brightness arguments are out of range or if device is not connected
 /// </remarks>
 public bool SetBrightness(int brightness,
                           int duration = Constants.MinValueForDurationParameter,
                           Constants.EffectParamValues effectType = Constants.EffectParamValues.SUDDEN)
 {
     ThrowExceptionIfIntArgIsOutOfRange("duration", duration, Constants.MinValueForDurationParameter);
     ThrowExceptionIfIntArgIsOutOfRange("brightness", brightness, 0, 100);
     ThrowExceptionIfNotConnected();
     return(SendCommandMessage(1,
                               "set_bright",
                               new string[]
     {
         brightness.ToString(System.Globalization.CultureInfo.InvariantCulture),
         Utils.GetJsonStringFromParamEnum(effectType),
         duration.ToString(System.Globalization.CultureInfo.InvariantCulture)
     }));
 }
예제 #5
0
        /// <summary>
        /// Sets the light device's color
        /// </summary>
        /// <param name="red"> The integer value of red channel to set the light device's color to</param>
        /// <param name="green"> The integer value of green channel to set the light device's color to</param>
        /// <param name="blue"> The integer value of blue channel to set the light device's color to</param>
        /// <param name="duration"> Duration of the effect, minimum value for this argument is Constants.MinValueForDurationParameter and so is the default value</param>
        /// <param name="effectType"> Type of the effect, can be anything from Constants.EffectParamValues and default value is Constants.EffectParamValues.SUDDEN</param>
        /// <remarks>
        /// Throws if duration argument is out of range or if device is not connected
        /// </remarks>
        public bool SetColor(byte red, byte green, byte blue,
                             int duration = Constants.MinValueForDurationParameter,
                             Constants.EffectParamValues effectType = Constants.EffectParamValues.SUDDEN)
        {
            ThrowExceptionIfIntArgIsOutOfRange("duration", duration, Constants.MinValueForDurationParameter);
            ThrowExceptionIfNotConnected();
            int value = (red << 16) | (green << 8) | blue;

            effectType.ToString();
            return(SendCommandMessage(1,
                                      "set_rgb",
                                      new string[] {
                value.ToString(System.Globalization.CultureInfo.InvariantCulture),
                Utils.GetJsonStringFromParamEnum(effectType),
                duration.ToString(System.Globalization.CultureInfo.InvariantCulture)
            }));
        }