コード例 #1
0
        public void Bright(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.Bright);
            string dimbright = String.Format("{0:x1}", (int)(((double)percentage / 100D) * 210));

            //
            _modstatus[huc].Level += ((double)percentage / 100.0);
            if (_modstatus[huc].Level > 1.0)
            {
                _modstatus[huc].Level = 1.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) });
            }
        }
コード例 #2
0
        public static string HouseUnitCodeFromEnum(X10HouseCodes housecode, X10UnitCodes unitcodes)
        {
            string unit = unitcodes.ToString();

            unit = unit.Substring(unit.LastIndexOf("_") + 1);
            //
            return(housecode.ToString() + unit);
        }
コード例 #3
0
        public void StatusRequest(X10HouseCodes housecode, X10UnitCodes 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.Status_Request);

            _sendqueue.Enqueue(new byte[] { (int)X10CommandType.Address, byte.Parse(hcunit, System.Globalization.NumberStyles.HexNumber) });
            _sendqueue.Enqueue(new byte[] { (int)X10CommandType.Function, byte.Parse(hcfuntion, System.Globalization.NumberStyles.HexNumber) });
        }
コード例 #4
0
        public void LightOff(X10HouseCodes housecode, X10UnitCodes 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.Off);

            _sendqueue.Enqueue(new byte[] { (int)X10CommandType.Address, byte.Parse(hcunit, System.Globalization.NumberStyles.HexNumber) });
            _sendqueue.Enqueue(new byte[] { (int)X10CommandType.Function, byte.Parse(hcfuntion, System.Globalization.NumberStyles.HexNumber) });
            //
            string huc = Utility.HouseUnitCodeFromEnum(housecode, unitcode);

            _modstatus[huc].Level = 0.0;
        }
コード例 #5
0
 public void StatusRequest(X10HouseCodes housecode, X10UnitCodes unitcode)
 {
     lock (this)
     {
         //string hcunit = String.Format("{0:X}{1:X}", (int)housecode, (int)unitcode);
         string hcfuntion = String.Format("{0:x1}{1:x1}", (int)housecode, (int)X10Command.Status_Request);
         SendModuleAddress(housecode, unitcode);
         SendMessage(new byte[] {
             (int)X10CommandType.Function,
             byte.Parse(
                 hcfuntion,
                 System.Globalization.NumberStyles.HexNumber
                 )
         });
     }
 }
コード例 #6
0
 public void Bright(X10HouseCodes housecode, X10UnitCodes unitcode, int percentage)
 {
     lock (this)
     {
         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.Bright);
         //
         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 > 1)
             {
                 newLevel = 1;
             }
             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 > 1)
             {
                 newLevel = 1;
             }
             moduleStatus[huc].Level = newLevel;
         }
     }
 }
コード例 #7
0
 public void LightOff(X10HouseCodes housecode, X10UnitCodes unitcode)
 {
     lock (this)
     {
         //string hcunit = String.Format("{0:X}{1:X}", (int)housecode, (int)unitcode);
         string hcfuntion = String.Format("{0:x1}{1:x1}", (int)housecode, (int)X10Command.Off);
         SendModuleAddress(housecode, unitcode);
         SendMessage(new byte[] {
             (int)X10CommandType.Function,
             byte.Parse(
                 hcfuntion,
                 System.Globalization.NumberStyles.HexNumber
                 )
         });
         //
         string huc = Utility.HouseUnitCodeFromEnum(housecode, unitcode);
         moduleStatus[huc].Level = 0.0;
     }
 }
コード例 #8
0
 private void SendModuleAddress(X10HouseCodes housecode, X10UnitCodes unitcode)
 {
     if (!addressedModules.ContainsKey(housecode.ToString()))
     {
         addressedModules.Add(housecode.ToString(), new List <X10Module>());
     }
     string huc = Utility.HouseUnitCodeFromEnum(housecode, unitcode);
     var    mod = moduleStatus[huc];
     // TODO: do more tests about this optimization
     //if (!addressedModules[housecode.ToString()].Contains(mod) || addressedModules[housecode.ToString()].Count > 1)
     {
         addressedModules[housecode.ToString()].Clear();
         addressedModules[housecode.ToString()].Add(mod);
         string hcunit = String.Format("{0:X}{1:X}", (int)housecode, (int)unitcode);
         SendMessage(new byte[] {
             (int)X10CommandType.Address,
             byte.Parse(
                 hcunit,
                 System.Globalization.NumberStyles.HexNumber
                 )
         });
     }
 }
コード例 #9
0
ファイル: XTenManager.cs プロジェクト: florpan/HomeGenie
 private void SendModuleAddress(X10HouseCodes housecode, X10UnitCodes unitcode)
 {
     if (!addressedModules.ContainsKey(housecode.ToString()))
     {
         addressedModules.Add(housecode.ToString(), new List<X10Module>());
     }
     string huc = Utility.HouseUnitCodeFromEnum(housecode, unitcode);
     var mod = moduleStatus[huc];
     // TODO: do more tests about this optimization
     //if (!addressedModules[housecode.ToString()].Contains(mod) || addressedModules[housecode.ToString()].Count > 1)
     {
         addressedModules[housecode.ToString()].Clear();
         addressedModules[housecode.ToString()].Add(mod);
         string hcunit = String.Format("{0:X}{1:X}", (int)housecode, (int)unitcode);
         SendMessage(new byte[] {
             (int)X10CommandType.Address,
             byte.Parse(
                 hcunit,
                 System.Globalization.NumberStyles.HexNumber
             )
         });
     }
 }
コード例 #10
0
ファイル: XTenManager.cs プロジェクト: florpan/HomeGenie
 public void LightOff(X10HouseCodes housecode, X10UnitCodes unitcode)
 {
     lock (this)
     {
         //string hcunit = String.Format("{0:X}{1:X}", (int)housecode, (int)unitcode);
         string hcfuntion = String.Format("{0:x1}{1:x1}", (int)housecode, (int)X10Command.Off);
         SendModuleAddress(housecode, unitcode);
         SendMessage(new byte[] {
             (int)X10CommandType.Function,
             byte.Parse(
                 hcfuntion,
                 System.Globalization.NumberStyles.HexNumber
             )
         });
         //
         string huc = Utility.HouseUnitCodeFromEnum(housecode, unitcode);
         moduleStatus[huc].Level = 0.0;
     }
 }
コード例 #11
0
ファイル: XTenManager.cs プロジェクト: florpan/HomeGenie
 public void Bright(X10HouseCodes housecode, X10UnitCodes unitcode, int percentage)
 {
     lock (this)
     {
         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.Bright);
         //
         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 > 1) newLevel = 1;
             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 > 1) newLevel = 1;
             moduleStatus[huc].Level = newLevel;
         }
     }
 }
コード例 #12
0
ファイル: XTenManager.cs プロジェクト: florpan/HomeGenie
 public void StatusRequest(X10HouseCodes housecode, X10UnitCodes unitcode)
 {
     lock (this)
     {
         //string hcunit = String.Format("{0:X}{1:X}", (int)housecode, (int)unitcode);
         string hcfuntion = String.Format("{0:x1}{1:x1}", (int)housecode, (int)X10Command.Status_Request);
         SendModuleAddress(housecode, unitcode);
         SendMessage(new byte[] {
             (int)X10CommandType.Function,
             byte.Parse(
                 hcfuntion,
                 System.Globalization.NumberStyles.HexNumber
             )
         });
     }
 }
コード例 #13
0
        public static X10UnitCodes UnitCodeFromString(string s)
        {
            X10UnitCodes uc = X10UnitCodes.Unit_1;

            s = s.Substring(1);
            switch (s)
            {
            case "1":
                uc = X10UnitCodes.Unit_1;
                break;

            case "2":
                uc = X10UnitCodes.Unit_2;
                break;

            case "3":
                uc = X10UnitCodes.Unit_3;
                break;

            case "4":
                uc = X10UnitCodes.Unit_4;
                break;

            case "5":
                uc = X10UnitCodes.Unit_5;
                break;

            case "6":
                uc = X10UnitCodes.Unit_6;
                break;

            case "7":
                uc = X10UnitCodes.Unit_7;
                break;

            case "8":
                uc = X10UnitCodes.Unit_8;
                break;

            case "9":
                uc = X10UnitCodes.Unit_9;
                break;

            case "10":
                uc = X10UnitCodes.Unit_10;
                break;

            case "11":
                uc = X10UnitCodes.Unit_11;
                break;

            case "12":
                uc = X10UnitCodes.Unit_12;
                break;

            case "13":
                uc = X10UnitCodes.Unit_13;
                break;

            case "14":
                uc = X10UnitCodes.Unit_14;
                break;

            case "15":
                uc = X10UnitCodes.Unit_15;
                break;

            case "16":
                uc = X10UnitCodes.Unit_16;
                break;
            }
            return(uc);
        }
コード例 #14
0
ファイル: XTenData.cs プロジェクト: florpan/HomeGenie
 public static string HouseUnitCodeFromEnum(X10HouseCodes housecode, X10UnitCodes unitcodes)
 {
     string unit = unitcodes.ToString();
     unit = unit.Substring(unit.LastIndexOf("_") + 1);
     //
     return housecode.ToString() + unit;
 }
コード例 #15
0
ファイル: X10.cs プロジェクト: zhang359264726/HomeGenie-1
        public object InterfaceControl(MIGInterfaceCommand request)
        {
            string  nodeid  = request.nodeid;
            Command command = (Command)request.command;
            string  option  = request.GetOption(0);

            //process command
            #region X10HAL-commands compatibility !!! <-- DEPRECATE THIS
            if (nodeid.ToUpper() == "STATUS")
            {
                List <X10Module> tempdataitems = new List <X10Module>(x10lib.ModulesStatus.Count);
                foreach (string key in x10lib.ModulesStatus.Keys)
                {
                    tempdataitems.Add(x10lib.ModulesStatus[key]);
                }

                XmlSerializer           serializer = new XmlSerializer(typeof(List <X10Module>));
                StringWriter            sw         = new StringWriter();
                XmlSerializerNamespaces ns         = new XmlSerializerNamespaces();
                ns.Add("", "");
                serializer.Serialize(sw, tempdataitems, ns);

                StringBuilder sb = new StringBuilder();
                sb.Append(sw.ToString());
                //byte[] b = Encoding.UTF8.GetBytes(sb.ToString());
                //response.ContentLength64 = b.Length;
                //response.OutputStream.Write(b, 0, b.Length);
                return(sb.ToString());
            }
            else if (nodeid.ToUpper() == "CONFIG")
            {
                string configpath = @"C:\Program Files\ActiveHome Pro\HAL.ahx";
                string config     = "";
                //
                try
                {
                    config = System.IO.File.ReadAllText(configpath);
                    //
                    if (config.IndexOf("&amp;") <= 0)
                    {
                        config = config.Replace("&", "&amp;");
                    }
                    //
                    StringBuilder sb = new StringBuilder();
                    sb.Append(config);
                    return(sb.ToString());
                }
                catch (Exception e)
                {
                }
            }
            #endregion
            X10HouseCodes housecode = XTenLib.Utility.HouseCodeFromString(nodeid);
            X10UnitCodes  unitcode  = XTenLib.Utility.UnitCodeFromString(nodeid);
            if (command == Command.PARAMETER_STATUS)
            {
                x10lib.StatusRequest(housecode, unitcode);
            }
            else if (command == Command.CONTROL_ON)
            {
                x10lib.LightOn(housecode, unitcode);
            }
            else if (command == Command.CONTROL_OFF)
            {
                x10lib.LightOff(housecode, unitcode);
            }
            else if (command == Command.CONTROL_BRIGHT)
            {
                x10lib.Bright(housecode, unitcode, int.Parse(option));
            }
            else if (command == Command.CONTROL_DIM)
            {
                x10lib.Dim(housecode, unitcode, int.Parse(option));
            }
            else if (command == Command.CONTROL_LEVEL)
            {
                int dimvalue = int.Parse(option) - (int)(x10lib.ModulesStatus[nodeid].Level * 100.0);
                if (dimvalue > 0)
                {
                    x10lib.Bright(housecode, unitcode, dimvalue);
                }
                else if (dimvalue < 0)
                {
                    x10lib.Dim(housecode, unitcode, -dimvalue);
                }
            }
            else if (command == Command.CONTROL_TOGGLE)
            {
                string huc = XTenLib.Utility.HouseUnitCodeFromEnum(housecode, unitcode);
                if (x10lib.ModulesStatus[huc].Level == 0)
                {
                    x10lib.LightOn(housecode, unitcode);
                }
                else
                {
                    x10lib.LightOff(housecode, unitcode);
                }
            }
            else if (command == Command.CONTROL_ALLLIGHTSON)
            {
                x10lib.AllLightsOn(housecode);
            }
            else if (command == Command.CONTROL_ALLLIGHTSOFF)
            {
                x10lib.AllUnitsOff(housecode);
            }//
            return("");
        }