Beispiel #1
0
        public static void LinkToApi(this AppleTV appleTv, BasicTriList trilist, uint joinStart, string joinMapKey)
        {
            AppleTvJoinMap joinMap = new AppleTvJoinMap();

            var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey);

            if (!string.IsNullOrEmpty(joinMapSerialized))
            {
                joinMap = JsonConvert.DeserializeObject <AppleTvJoinMap>(joinMapSerialized);
            }

            joinMap.OffsetJoinNumbers(joinStart);

            Debug.Console(1, "Linking to Trilist '{0}'", trilist.ID.ToString("X"));
            Debug.Console(0, "Linking to Bridge Type {0}", appleTv.GetType().Name.ToString());

            trilist.SetBoolSigAction(joinMap.UpArrow, (b) => appleTv.Up(b));
            trilist.SetBoolSigAction(joinMap.DnArrow, (b) => appleTv.Down(b));
            trilist.SetBoolSigAction(joinMap.LeftArrow, (b) => appleTv.Left(b));
            trilist.SetBoolSigAction(joinMap.RightArrow, (b) => appleTv.Right(b));
            trilist.SetBoolSigAction(joinMap.Select, (b) => appleTv.Select(b));
            trilist.SetBoolSigAction(joinMap.Menu, (b) => appleTv.Menu(b));
            trilist.SetBoolSigAction(joinMap.PlayPause, (b) => appleTv.Play(b));
        }
Beispiel #2
0
        protected ASystem(CrestronControlSystem controlSystem)
            : base(controlSystem, Assembly.GetExecutingAssembly())
        {
            Debug.WriteInfo("System.ctor()", "Started");

            BootStatus          = "Loading System Type \"" + GetType().Name + "\"";
            BootProgressPercent = 5;

            SoftwareUpdate.SoftwareUpdate.UpdateShouldLoad += LoadUpdate;

            CrestronConsole.AddNewConsoleCommand(parameters =>
            {
                if (parameters.Trim() == "?")
                {
                    CrestronConsole.ConsoleCommandResponse(
                        "Start running a test script. Options here are as follows:\r\n" +
                        "  count  - set the number of times the script should loop and change sources\r\n" +
                        "  number - set the number to dial if the codec is selected\r\n" +
                        "for example: \"TestScriptStart count 10 number 1234");
                    return;
                }

                var args = new Dictionary <string, string>();

                try
                {
                    var matches = Regex.Matches(parameters, @"(?:(\w+)\s+(\w+))");

                    foreach (Match match in matches)
                    {
                        args[match.Groups[1].Value] = match.Groups[2].Value;
                    }
                }
                catch (Exception e)
                {
                    CrestronConsole.ConsoleCommandResponse("Error parsing args, {0}", e.Message);
                    return;
                }

                try
                {
                    TestScriptStart(args);
                }
                catch (Exception e)
                {
                    CrestronConsole.ConsoleCommandResponse("Error: {0}", e.Message);
                }
            }, "TestScriptStart", "Start a test script", ConsoleAccessLevelEnum.AccessOperator);

            CrestronConsole.AddNewConsoleCommand(parameters => TestScriptStop(), "TestScriptStop",
                                                 "Stop running the test script", ConsoleAccessLevelEnum.AccessOperator);

            CrestronConsole.AddNewConsoleCommand(parameters =>
            {
                try
                {
                    var id          = uint.Parse(parameters);
                    Rooms[1].Source = id == 0 ? null : Sources[id];
                    CrestronConsole.ConsoleCommandResponse("Selected source \"{0}\" in Room \"{1}\"", Sources[id],
                                                           Rooms[1].Name);
                }
                catch (Exception e)
                {
                    CrestronConsole.ConsoleCommandResponse("Error: {0}", e.Message);
                }
            }, "Source", "Select a source by ID for the first room", ConsoleAccessLevelEnum.AccessOperator);

            CrestronConsole.AddNewConsoleCommand(parameters =>
            {
                try
                {
                    foreach (var source in Sources)
                    {
                        CrestronConsole.ConsoleCommandResponse("Source {0}: {1}", source.Id, source.Name);
                    }
                }
                catch (Exception e)
                {
                    CrestronConsole.ConsoleCommandResponse("Error: {0}", e.Message);
                }
            }, "ListSources", "List sources by IDs", ConsoleAccessLevelEnum.AccessOperator);

            StartWebApp(9001);

            if (ConfigManager.Config.SystemType == SystemType.NotConfigured)
            {
                return;
            }

            var config = ConfigManager.Config;

            Debug.WriteInfo("System.ctor()", "Config loaded");

            #region System Switcher

            BootStatus          = "Loading switcher configuration";
            BootProgressPercent = 6;

            if (config.SwitcherType != SystemSwitcherType.NotInstalled)
            {
                try
                {
                    switch (config.SwitcherType)
                    {
                    case SystemSwitcherType.BigDmFrame:
                        Switcher = new BigDmSwitcher(controlSystem as ControlSystem,
                                                     config.SwitcherConfig);
                        Switcher.InputStatusChanged += LocalSwitcherOnInputStatusChanged;
                        break;

                    case SystemSwitcherType.DmFrame:
                        Switcher = new DmSwitcher(controlSystem as ControlSystem,
                                                  config.SwitcherConfig);
                        Switcher.InputStatusChanged += LocalSwitcherOnInputStatusChanged;
                        break;
                    }
                }
                catch (Exception e)
                {
                    CloudLog.Exception(e, "Error loading System Video Switcher");
                }
            }

            #endregion

            var controllers = config.OneBeyondAddresses.ToDictionary(address => address.Key,
                                                                     address => new OneBeyond(address.Value, address.Key));

            _oneBeyondControllers = new ReadOnlyDictionary <uint, OneBeyond>(controllers);

            #region DSP

            BootStatus          = "Loading dsp configuration";
            BootProgressPercent = 7;

            if (config.DspConfig != null && config.DspConfig.Enabled)
            {
                Dsp = new QsysCore(new[] { config.DspConfig.DeviceAddressString }, config.DspConfig.Name,
                                   config.DspConfig.Username, config.DspConfig.Password);
                Dsp.HasIntitialized += DspOnHasIntitialized;
            }

            #endregion

            #region Rooms

            BootStatus          = "Loading Room Configs";
            BootProgressPercent = 10;

            foreach (var roomConfig in config.Rooms
                     .Where(r => r.Enabled)
                     .OrderBy(r => r.Id))
            {
                Debug.WriteInfo("System.ctor()", "Setting up {0} room \"{1}\"", config.SystemType, roomConfig.Name);
                try
                {
                    var room = (ARoom)Assembly.GetExecutingAssembly()
                               .GetType(roomConfig.RoomType)
                               .GetConstructor(new CType[] { GetType(), typeof(RoomConfig) })
                               .Invoke(new object[] { this, roomConfig });
                    WebApp.AddXpanelLink(string.Format("/dashboard/app/xpanel/xpanel?room={0}", room.Id), room.Name);
                }
                catch (Exception e)
                {
                    CloudLog.Exception(e, "Failed to load room type \"{0}\"", roomConfig.RoomType);
                }
            }

            #endregion

            #region Global Sources

            if (config.GlobalSources != null)
            {
                foreach (var sourceConfig in config.GlobalSources
                         .Where(s => s.Enabled)
                         .OrderBy(s => s.Id))
                {
                    Debug.WriteInfo("System.ctor()", "Setting up global source \"{0}\", {1}", sourceConfig.Name,
                                    sourceConfig.SourceType);

                    switch (sourceConfig.SourceType)
                    {
                    case SourceType.AppleTV:
                        var appleTV = new AppleTV(controlSystem.IROutputPorts[sourceConfig.DeviceAddressNumber]);
                        new GenericSource(this, sourceConfig, appleTV);
                        break;

                    case SourceType.PC:
                        new PCSource(this, sourceConfig);
                        break;

                    default:
                        new GenericSource(this, sourceConfig);
                        break;
                    }
                }
            }

            #endregion

            #region User Interfaces

            BootStatus          = "Loading UI Controllers";
            BootProgressPercent = 15;
#if DEBUG
            Debug.WriteInfo("Setting up User Interfaces", "Count = {0}", config.UserInterfaces.Count(ui => ui.Enabled));
            Debug.WriteInfo(JToken.FromObject(config.UserInterfaces).ToString(Formatting.Indented));
#endif

            foreach (var uiConfig in config.UserInterfaces.Where(ui => ui.Enabled))
            {
                try
                {
                    Debug.WriteInfo("System.ctor()", "Setting up UIController \"{0}\", {1} 0x{2:X2}", uiConfig.Name,
                                    uiConfig.DeviceType, uiConfig.DeviceAddressNumber);

                    if (uiConfig.UIControllerType == UIControllerType.RemoteMpc)
                    {
                        var isc = new ThreeSeriesTcpIpEthernetIntersystemCommunications(uiConfig.DeviceAddressNumber,
                                                                                        uiConfig.DeviceAddressString, controlSystem);
                        var mpcUi = new MpcUIController(this, isc, Rooms.ContainsKey(uiConfig.DefaultRoom)
                            ? Rooms[uiConfig.DefaultRoom]
                            : null);
                        mpcUi.Register();
                        continue;
                    }

                    var uiAssembly = Assembly.LoadFrom(@"Crestron.SimplSharpPro.UI.dll");
                    var type       = uiAssembly.GetType("Crestron.SimplSharpPro.UI." + uiConfig.DeviceType);
                    BasicTriListWithSmartObject panel;
                    var ctor = type.GetConstructor(new CType[] { typeof(UInt32), typeof(ControlSystem) });
                    panel = (BasicTriListWithSmartObject)
                            ctor.Invoke(new object[] { uiConfig.DeviceAddressNumber, controlSystem });

                    var app = panel as CrestronApp;
                    if (app != null && !string.IsNullOrEmpty(uiConfig.DeviceAddressString))
                    {
                        app.ParameterProjectName.Value = uiConfig.DeviceAddressString;
                    }

                    if (panel != null)
                    {
                        panel.Description = uiConfig.Name;
                    }

                    UIController ui = null;

                    RoomBase defaultRoom;
                    switch (uiConfig.UIControllerType)
                    {
                    case UIControllerType.TechPanel:
                        defaultRoom = Rooms.ContainsKey(uiConfig.DefaultRoom)
                                ? Rooms[uiConfig.DefaultRoom]
                                : null;
                        ui = new RoomUIController(this, panel, defaultRoom, true);
                        break;

                    case UIControllerType.UserPanel:
                        defaultRoom = Rooms.ContainsKey(uiConfig.DefaultRoom)
                                ? Rooms[uiConfig.DefaultRoom]
                                : null;
                        ui = new RoomUIController(this, panel, defaultRoom, false);
                        break;
                    }

                    foreach (var room in uiConfig.AllowedRoomIds)
                    {
                        ui.AddRoomToAllowedRooms(Rooms[room]);
                    }

                    if (ui != null)
                    {
                        ui.Register();
                    }
                }
                catch (Exception e)
                {
                    CloudLog.Exception(e, "Error loading UI device {0} 0x{1:X2}", uiConfig.DeviceType,
                                       uiConfig.DeviceAddressNumber);
                }
            }

            UIControllers.SetupCustomTime(Serials.Time);
            UIControllers.SetupCustomDate(Serials.Date);

            #endregion

            if (this is FireAlarmMonitorSystem)
            {
                return;
            }

            var fireInterfaceAddress = ConfigManager.GetCustomValue("FireAlarmInterfaceAddress") as string;
            if (string.IsNullOrEmpty(fireInterfaceAddress))
            {
                return;
            }
            _fireAlarmListener = new FireAlarmListener(fireInterfaceAddress);
            _fireAlarmListener.StatusChanged += FireAlarmListenerOnStatusChanged;
        }