Пример #1
0
 /// <summary>
 /// Creates a <see cref="SingleScaleToRangeInput"/> object scaling the values of this input to a specific numeric
 /// range.
 /// </summary>
 /// <param name="source">The source input to be scaled.</param>
 /// <param name="smallestValueMappedTo">The value that the smallest source input value will be mapped to.
 /// </param>
 /// <param name="largestValueMappedTo">The value that the largest source input value will be mapped to.</param>
 /// <remarks><paramref name="smallestValueMappedTo"/> may well be larger than
 /// <paramref name="largestValueMappedTo"/>. In this case the mapping will output a larger value for smaller
 /// source values, and you can, vor example, turn the sign of an input ranging from -1.0 to +1.0 into the
 /// resulting range +1.0 to -1.0. However, <paramref name="smallestValueMappedTo"/> must not be equal to
 /// <paramref name="largestValueMappedTo"/>.</remarks>
 /// <returns>The scaled input.</returns>
 public static SingleScaleToRangeInput ScaleToRange(
     this ISingleInput source,
     float smallestValueMappedTo,
     float largestValueMappedTo)
 {
     return(new SingleScaleToRangeInput(source, smallestValueMappedTo, largestValueMappedTo));
 }
Пример #2
0
 /// <summary>
 /// Creates a <see cref="SingleSchmittTriggerInput"/> object which maps a target <see cref="ISingleInput"/> to a
 /// boolean using a threshold.
 /// </summary>
 /// <param name="source">The source input to be mapped from float to boolean.</param>
 /// <param name="threshold">The threshold above which <see cref="Value"/> shall return true, and below which
 /// it shall return false. This can by any number.</param>
 /// <param name="hysteresis">The range that the source value must be above/below the last value in order to
 /// change the resulting value. This must not be negative.</param>
 /// <returns>The mapped boolean input.</returns>
 /// <remarks>Example: Use 0.5 as <paramref name="threshold"/> and 0.1 as <paramref name="hysteresis"/>. The
 /// following sequence of source input values, in the given order, will then result in the following resulting
 /// values: 0.0 -> false, 1.0 -> true, 0.6 -> true, 0.5 -> true, 0.4 -> true, 0.3 -> false, 0.4 -> false,
 /// 0.5 -> false, 0.6 -> false, 0.7 -> true.</remarks>
 public static SingleSchmittTriggerInput SchmittTrigger(
     this ISingleInput source,
     float threshold,
     float hysteresis)
 {
     return(new SingleSchmittTriggerInput(source, threshold, hysteresis));
 }
        /// <summary>
        /// Creates an instance.
        /// </summary>
        /// <param name="sourceInput">The input whose analog value shall be mapped to a boolean value.</param>
        /// <param name="threshold">The threshold above which <see cref="Value"/> shall return true, and below which
        /// it shall return false. This can by any number.</param>
        /// <param name="hysteresis">The range that the source value must be above/below the last value in order to
        /// change the resulting value. This must not be negative.</param>
        /// <remarks>Example: Use 0.5 as <paramref name="threshold"/> and 0.1 as <paramref name="hysteresis"/>. The
        /// following sequence of source input values, in the given order, will then result in the following resulting
        /// values: 0.0 -> false, 1.0 -> true, 0.6 -> true, 0.5 -> true, 0.4 -> true, 0.3 -> false, 0.4 -> false,
        /// 0.5 -> false, 0.6 -> false, 0.7 -> true.</remarks>
        public SingleSchmittTriggerInput(ISingleInput sourceInput, float threshold, float hysteresis)
        {
            _sourceInput = sourceInput ?? throw new ArgumentNullException(nameof(sourceInput));
            if (hysteresis < 0.0)
            {
                throw new ArgumentOutOfRangeException(nameof(hysteresis));
            }

            hysteresis     = hysteresis / 2.0f;
            _lowThreshold  = threshold - hysteresis;
            _highThreshold = threshold + hysteresis;
        }
Пример #4
0
        /// <summary>
        /// Creates an instance.
        /// </summary>
        /// <param name="source">The input whose value shall be mapped.</param>
        /// <param name="smallestValueMappedTo">The value that the smallest source input value will be mapped to.
        /// </param>
        /// <param name="largestValueMappedTo">The value that the largest source input value will be mapped to.</param>
        /// <remarks><paramref name="smallestValueMappedTo"/> may well be larger than
        /// <paramref name="largestValueMappedTo"/>. In this case the mapping will output a larger value for smaller
        /// source values, and you can, vor example, turn the sign of an input ranging from -1.0 to +1.0 into the
        /// resulting range +1.0 to -1.0. However, <paramref name="smallestValueMappedTo"/> must not be equal to
        /// <paramref name="largestValueMappedTo"/>.</remarks>
        public SingleScaleToRangeInput(ISingleInput source, float smallestValueMappedTo, float largestValueMappedTo)
        {
            _source = source ?? throw new ArgumentNullException(nameof(source));

            if (smallestValueMappedTo == largestValueMappedTo)
            {
                throw new ArgumentException(
                          nameof(smallestValueMappedTo) + " must not be equal to " + nameof(largestValueMappedTo) + ".");
            }

            _smallestValueMappedTo = smallestValueMappedTo;
            _largestValueMappedTo  = largestValueMappedTo;
            _sourceMinimum         = float.MaxValue;
            _sourceMaximum         = float.MinValue;
        }
        public static void Run(ISingleInput input, ISingleOutput lamp)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }
            if (lamp == null)
            {
                throw new ArgumentNullException(nameof(lamp));
            }

            while (true)
            {
                lamp.Value = input.Value;
                Thread.Sleep(100); // Only to give you a chance to redeploy usung firmware as of 2018-04-08.
            }
        }