Exemple #1
0
        public void Dim(X10HouseCodes housecode, X10UnitCodes unitcode, int percentage)
        {
            string huc       = Utility.HouseUnitCodeFromEnum(housecode, unitcode);
            string hcunit    = String.Format("{0:X}{1:X}", (int)housecode, (int)unitcode);
            string hcfuntion = String.Format("{0:x1}{1:x1}", (int)housecode, (int)X10Command.Dim);
            string dimbright = String.Format("{0:x1}", (int)(((double)percentage / 100D) * 210));

            //
            _modstatus[huc].Level -= ((double)percentage / 100.0);
            if (_modstatus[huc].Level < 0.0)
            {
                _modstatus[huc].Level = 0.0;
            }
            //
            _sendqueue.Enqueue(new byte[] { (int)X10CommandType.Address, byte.Parse(hcunit, System.Globalization.NumberStyles.HexNumber) });
            if (_x10interface.GetType().Equals(typeof(CM11)))
            {
                int dimvalue = (int)(((double)percentage / 100D) * 16) << 3;
                dimbright = String.Format("{0:x1}", dimvalue);
                _sendqueue.Enqueue(new byte[] { (byte)((int)X10CommandType.Function | dimvalue), byte.Parse(hcfuntion, System.Globalization.NumberStyles.HexNumber) });
            }
            else
            {
                _sendqueue.Enqueue(new byte[] { (int)X10CommandType.Function, byte.Parse(hcfuntion, System.Globalization.NumberStyles.HexNumber), byte.Parse(dimbright, System.Globalization.NumberStyles.HexNumber) });
            }
        }
Exemple #2
0
 public void Dim(X10HouseCodes housecode, X10UnitCodes unitcode, int percentage)
 {
     lock (this)
     {
         string huc       = Utility.HouseUnitCodeFromEnum(housecode, unitcode);
         string hcfuntion = String.Format("{0:x1}{1:x1}", (int)housecode, (int)X10Command.Dim);
         //
         SendModuleAddress(housecode, unitcode);
         if (x10interface.GetType().Equals(typeof(CM15)))
         {
             double normalized = ((double)percentage / 100D);
             SendMessage(new byte[] {
                 (int)X10CommandType.Function,
                 byte.Parse(
                     hcfuntion,
                     System.Globalization.NumberStyles.HexNumber
                     ),
                 (byte)(normalized * 210)
             });
             double newLevel = moduleStatus[huc].Level - normalized;
             if (newLevel < 0)
             {
                 newLevel = 0;
             }
             moduleStatus[huc].Level = newLevel;
         }
         else
         {
             byte dimvalue = Utility.GetDimValue(percentage);
             SendMessage(new byte[] {
                 (byte)((int)X10CommandType.Function | dimvalue | 0x04),
                 byte.Parse(
                     hcfuntion,
                     System.Globalization.NumberStyles.HexNumber
                     )
             });
             double newLevel = moduleStatus[huc].Level - Utility.GetPercentageValue(dimvalue);
             if (newLevel < 0)
             {
                 newLevel = 0;
             }
             moduleStatus[huc].Level = newLevel;
         }
     }
 }