Example #1
0
        private static byte[] CreatePayloadData(
            Color color,
            Percentage brightness,
            Temperature Temperature,
            Power power,
            Label label
            )
        {
            var hueData         = HueConverter.ConvertHueToUInt16(color.Hue).GetBytes();
            var saturationData  = PercentageConverter.ConvertPercentageToUInt16(color.Saturation).GetBytes();
            var brightnessData  = PercentageConverter.ConvertPercentageToUInt16(brightness).GetBytes();
            var temperatureData = ((ushort)Temperature).GetBytes();
            var reserved1       = new byte[2];
            var powerData       = ((ushort)power).GetBytes();
            var labelData       = Encoding.UTF8.GetBytes(label);
            var reserved2       = new byte[8];

            return(CombineArrays(
                       hueData,
                       saturationData,
                       brightnessData,
                       temperatureData,
                       reserved1,
                       powerData,
                       labelData,
                       reserved2
                       ));
        }
Example #2
0
        public void PercentageConverter()
        {
            PercentageConverter target = new PercentageConverter();

            Object[] vals;
            string   result;

            // 100.0%
            vals   = new Object[] { (Int32)1000, (Int32)1000 };
            result = (string)target.Convert(vals, typeof(string), null, null);
            Assert.AreEqual("100.0%", result, true);

            //0.0%
            vals   = new Object[] { (Int32)1000, (Int32)0 };
            result = (string)target.Convert(vals, typeof(string), null, null);
            Assert.AreEqual("0.0%", result, true);

            //50.47%
            vals   = new Object[] { (Int32)100000, (Int32)50470 };
            result = (string)target.Convert(vals, typeof(string), null, null);
            Assert.AreEqual("50.47%", result, true);

            //1.01%
            vals   = new Object[] { (Int32)100000, (Int32)1010 };
            result = (string)target.Convert(vals, typeof(string), null, null);
            Assert.AreEqual("1.01%", result, true);

            //200%
            vals   = new Object[] { (Int32)1000, (Int32)2000 };
            result = (string)target.Convert(vals, typeof(string), null, null);
            Assert.AreEqual("100.0%", result, true);
        }
Example #3
0
        public void GetDataShouldReturnValidBrightnessData()
        {
            const int brightnessOffset = 5;

            var brightness = new Percentage(Percentage.MaxValue);
            var data       = CreatePayloadData(Color.None, brightness, Temperature.None, 0);

            PercentageConverter.ConvertUInt16ToPercentage(data.ToUInt16(brightnessOffset)).Should().Be(brightness);
        }
        public void ConvertTest()
        {
            PercentageConverter converter = new PercentageConverter();
            double b     = 53;
            var    value = converter.Convert(b, typeof(double), null, CultureInfo.CurrentCulture);
            double r     = 0.53;

            Assert.AreEqual(r, value);
        }
Example #5
0
        public DownloadCell(IntPtr handle) : base(handle)
        {
            this.DelayBind(() =>
            {
                var set = this.CreateBindingSet <DownloadCell, DownloadSlotViewModel>();

                this.ClearBindings(DownloadButton);
                set.Bind(SlotNameLabel).For(v => v.Text).To(vm => vm.SlotName);
                set.Bind(NameLabel).For(v => v.Text).To(vm => vm.DeviceName);
                set.Bind(IdLabel).For(v => v.Text).To(vm => vm.Id);
                set.Bind(DownloadButton).To(vm => vm.DownloadRequested);

                PercentageConverter percentageConverter = new PercentageConverter();
                set.Bind(DownloadButton)
                .To(vm => vm.DownloadProgress)
                .For("Title")
                .WithConversion(percentageConverter);

                set.Bind(DownloadButton)
                .To(vm => vm.IsDownloading)
                .For("BackgroundColor")
                .WithDictionaryConversion(new Dictionary <bool, UIColor>
                {
                    { true, UIColor.LightGray },
                    { false, blueColor },
                });

                set.Bind(DownloadButton)
                .To(vm => vm.IsDownloading)
                .For("Enabled")
                .WithDictionaryConversion(new Dictionary <bool, bool>
                {
                    { true, false },
                    { false, true },
                });

                // Progress Bar
                set.Bind(DownloadProgressBar)
                .To(vm => vm.IsDownloading)
                .For("Hidden")
                .WithDictionaryConversion(new Dictionary <bool, bool>
                {
                    { true, false },
                    { false, true },
                });

                set.Bind(DownloadProgressBar)
                .To(vm => vm.DownloadProgress)
                .For("Progress");

                set.Apply();

                DownloadButton.Layer.CornerRadius = 4f;
                AddShadowToView(SlotNameLabel);
            });
        }
        public void ConvertParameterTest()
        {
            PercentageConverter converter = new PercentageConverter();
            double b     = 500;
            int    p     = 25;
            var    value = converter.Convert(b, typeof(double), p, CultureInfo.CurrentCulture);
            double r     = 0.20;

            Assert.AreEqual(r, value);
        }
Example #7
0
        public override byte[] GetData()
        {
            var reservedData    = new byte[1];
            var hueData         = HueConverter.ConvertHueToUInt16(_color.Hue).GetBytes();
            var saturationData  = PercentageConverter.ConvertPercentageToUInt16(_color.Saturation).GetBytes();
            var brightnessData  = PercentageConverter.ConvertPercentageToUInt16(_brightness).GetBytes();
            var temperatureData = ((ushort)_temperature).GetBytes();
            var durationData    = _durationInMilliseconds.GetBytes();

            return(CombineArrays(reservedData, hueData, saturationData, brightnessData, temperatureData, durationData));
        }
Example #8
0
        public void GetDataShouldReturnValidSaturationData()
        {
            const int saturationOffset = 3;

            var color = Color.Cyan;
            var data  = CreatePayloadData(color, Percentage.MaxValue, Temperature.None, 0);

            PercentageConverter.ConvertUInt16ToPercentage(
                data.ToUInt16(saturationOffset)
                ).Should().Be(color.Saturation);
        }
Example #9
0
 public override object ProvideValue(IServiceProvider serviceProvider)
 {
     return(_instance ?? (_instance = new PercentageConverter()));
 }
Example #10
0
        private static Percentage ParseBrightness(byte[] data)
        {
            var value = data.ToUInt16(startIndex: 4);

            return(PercentageConverter.ConvertUInt16ToPercentage(value));
        }
Example #11
0
        private static Percentage ParseSaturation(byte[] data)
        {
            var value = data.ToUInt16(startIndex: 2);

            return(PercentageConverter.ConvertUInt16ToPercentage(value));
        }