Esempio n. 1
0
        public void DemoteProperty(BatteryPropertyCode code)
        {
            TrippLitePropertyViewModel pm = null;

            foreach (var currentPm in ProminentProperties)
            {
                pm = currentPm;

                if (pm.Code == code)
                {
                    break;
                }

                pm = null;
            }

            if (pm is null)
            {
                return;
            }

            pm.Prominent = false;

            ProminentProperties.Remove(pm);
            Properties.Add(pm);
        }
Esempio n. 2
0
        public void PromoteToLoad(BatteryPropertyCode code, bool removeFromList = false)
        {
            TrippLitePropertyViewModel pm = null;

            foreach (var currentPm in Properties)
            {
                pm = currentPm;
                if (pm.Code == code)
                {
                    break;
                }
                pm = null;
            }

            if (pm is null)
            {
                return;
            }

            if (removeFromList)
            {
                Properties.Remove(pm);
            }

            LoadProperties.Add(pm);
        }
Esempio n. 3
0
        public void DemoteFromLoad(BatteryPropertyCode code)
        {
            TrippLitePropertyViewModel pm = null;

            foreach (var currentPm in ProminentProperties)
            {
                pm = currentPm;

                if (pm.Code == code)
                {
                    break;
                }

                pm = null;
            }

            if (pm is null)
            {
                return;
            }

            if (LoadProperties.Contains(pm))
            {
                LoadProperties.Remove(pm);
            }

            Properties.Add(pm);
        }
Esempio n. 4
0
        public void MapField(out BatteryPropertyCode value, byte code, byte collection = 0x0)
        {
            value = 0;
            HidPValueCaps?caps = null;

            //var features = deviceInfo.GetFeatureValues(HidUsageType.CL | HidUsageType.CA | HidUsageType.CP, HidUsageType.DV | HidUsageType.SV);

            caps = deviceInfo.FeatureValueCaps.Where((fv) =>
            {
                if (fv.Usage == code)
                {
                    if (collection == 0 || (fv.LinkCollection == collection) || (fv.LinkUsage == collection))
                    {
                        return(true);
                    }
                }

                return(false);
            }).FirstOrDefault();

            if (caps == null)
            {
                caps = deviceInfo.InputValueCaps.Where((fv) =>
                {
                    if (fv.Usage == code)
                    {
                        if (collection == 0 || (fv.LinkCollection == collection) || (fv.LinkUsage == collection))
                        {
                            return(true);
                        }
                    }

                    return(false);
                }).FirstOrDefault();

                if (caps == null)
                {
                    caps = deviceInfo.OutputValueCaps.Where((fv) =>
                    {
                        if (fv.Usage == code)
                        {
                            if (collection == 0 || (fv.LinkCollection == collection) || (fv.LinkUsage == collection))
                            {
                                return(true);
                            }
                        }

                        return(false);
                    }).FirstOrDefault();
                }
            }

            if (caps != null)
            {
                value = caps.Value.ReportID;
            }
        }
Esempio n. 5
0
        public TrippLitePropertyViewModel FindProperty(BatteryPropertyCode c)
        {
            foreach (var m in Properties)
            {
                if (m.Code == c)
                {
                    return(m);
                }
            }

            return(null);
        }
        public TrippLitePropertyViewModel GetPropertyByCode(BatteryPropertyCode c)
        {
            foreach (var v in this)
            {
                if (v.Code == c)
                {
                    return(v);
                }
            }

            return(null);
        }
Esempio n. 7
0
        /// <summary>
        /// Gets the name of the property specified by the given code.
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public string GetNameFromCode(BatteryPropertyCode code)
        {
            foreach (var prop in props)
            {
                var bv = (BatteryPropertyCode?)prop.GetValue(this);

                if (bv != null && bv == code)
                {
                    return(prop.Name);
                }
            }

            return(((byte)code).ToString());
        }
Esempio n. 8
0
        /// <summary>
        /// Gets a <see cref="BatteryPropertyCode"/> mapped property attribute value.
        /// </summary>
        /// <typeparam name="TAttr">The type of the attribute.</typeparam>
        /// <typeparam name="TReturn">The type of the return value.</typeparam>
        /// <param name="code">The battery property code to look up.</param>
        /// <param name="attrPropName">The name of the property on the attribute to retrieve.</param>
        /// <remarks>
        /// This will look up the property that currently has the corresponding code, and then look up the specified attribute
        /// associated with that property.  If the attribute is found, it will look up the property <paramref name="attrPropName"/> and
        /// return that value.
        /// </remarks>
        /// <returns>The value of the specified property for the specified attribute for the specified code.</returns>
        public TReturn?GetValueAttribute <TAttr, TReturn>(BatteryPropertyCode code, string attrPropName) where TAttr : Attribute
        {
            TReturn?result = default;

            foreach (var prop in props)
            {
                var bv = (BatteryPropertyCode?)prop.GetValue(this);

                if (bv != null && bv == code)
                {
                    var attr = prop.GetCustomAttribute <TAttr>();
                    if (attr != null)
                    {
                        var apInfo = attr.GetType().GetProperty(attrPropName);
                        if (apInfo != null)
                        {
                            result = (TReturn?)apInfo.GetValue(attr);
                        }
                    }
                }
            }

            return(result);
        }
 /// <summary>
 /// Initialize a new TrippLiteProperty
 /// </summary>
 /// <param name="owner">The TrippLiteUPS model object that will own this property.</param>
 /// <param name="c">The property code.</param>
 /// <remarks></remarks>
 internal TrippLiteProperty(TrippLiteUPS owner, BatteryPropertyCode c)
 {
     model    = owner;
     propCode = c;
     byteLen  = ByteLength;
 }