Esempio n. 1
0
        public virtual void LoadConfig()
        {
            WriteLog("Loading configuration...");

            if (_cecConfig == null)
            {
                WriteLog("Configuration not set, abort");
                return;
            }

            _fastScrolling         = _cecConfig.FastScrolling;
            _fastScrollingKeyCount = _cecConfig.FastScrollingRepeatDelay;
            _repeatTimer           = new System.Timers.Timer(_cecConfig.FastScrollingRepeatRate);

            _extensiveLogging        = _cecConfig.ExtensiveLogging;
            _disableScreensaver      = _cecConfig.DisableScreensaver;
            _requireDelayBetweenKeys = _cecConfig.RequireDelayBetweenKeys;

            if (_fastScrolling)
            {
                _repeatTimer.Elapsed  += new ElapsedEventHandler(OnRepeatKeyPressEvent);
                _repeatTimer.AutoReset = true;
            }


            // Build configuration for new Lib

            try
            {
                if (_libConfig == null)
                {
                    _libConfig = new LibCECConfiguration();
                    _libConfig.SetCallbacks(this);
                }

                _libConfig.DeviceTypes.Types[0] = _cecConfig.DeviceType;
                _libConfig.DeviceName           = _cecConfig.OsdName;
                _libConfig.ClientVersion        = LibCECConfiguration.CurrentVersion;
                _libConfig.WakeDevices.Clear();
                _libConfig.PowerOffDevices.Clear();
                _libConfig.PhysicalAddress = 0;
                _libConfig.ActivateSource  = false; // Control this manually based on settings.
                _libConfig.HDMIPort        = (byte)_cecConfig.HdmiPort;
                _libConfig.BaseDevice      = _cecConfig.ConnectedTo;

                if (_cecConfig.ForcePhysicalAddress)
                {
                    WriteLog("Physical address overriding enabled, ignoring HDMI port an using address: " + _cecConfig.PhysicalAddress);

                    _libConfig.PhysicalAddress = ushort.Parse(_cecConfig.PhysicalAddress, System.Globalization.NumberStyles.AllowHexSpecifier);
                }

                WriteLog("Configuration loaded succesfully.");

                if (_lib == null)
                {
                    _lib = new LibCecSharp(_libConfig);
                    WriteLog("Lib created succesfully.");
                }
                else
                {
                    _lib.SetConfiguration(_libConfig);
                    _lib.EnableCallbacks(this);
                    WriteLog("Lib configuration updated");
                }
            }
            catch (Exception ex)
            {
                WriteLog("Could not configure libCec." + ex.ToString());
                throw;
            }
        }