コード例 #1
0
        static void Main(string[] args)
        {
            RGBController controller = new RGBController();
            RGB           purple     = new RGB(167, 60, 228);
            RGB           light_blue = new RGB(0, 108, 255);

            controller.Initialize();

            Console.Write("Initialize: ");
            controller.Show();
            Console.Write('\n');

            Console.WriteLine("Purple: " + purple.ToString());
            Console.WriteLine("Lightblue: " + light_blue.ToString());

            Console.Write("Mixed: ");
            RGB mixed = controller.MixColors(purple, light_blue);

            controller.Show();
            Console.Write(" from RGBcontroller class's method show.\n");

            Console.WriteLine("Mixed: " + mixed.ToString() + " from RGB class's method ToString.");

            Console.ReadKey();
        }
コード例 #2
0
        /// <summary>
        /// Load the controller with the current settings,
        /// and attempt to connect
        /// </summary>
        private void LoadController()
        {
            var settings = HexLight.Properties.Settings.Default;

            // Get the class of the controller to use
            var controllerName = settings.Controller;

            if (controllerName == null || controllerName == "")
            {
                throw new ControllerConnectionException("No controller currently configured");
            }

            var controllerType = Controllers.GetControllerByName(controllerName);

            if (controllerType == null)
            {
                throw new ControllerConnectionException(String.Format("No controller found by name '{0}'", controllerName));
            }

            // Instantiate the controller and load any custom settings for it
            controller = Controllers.LoadController(settings, controllerType);

            // Attempt to connect (to validate the current settings)
            controller.Connect();
        }
コード例 #3
0
        /// <summary>
        /// Attempt to load the given controller type,
        /// and show the appropriate settings page for it
        /// </summary>
        /// <param name="controllerType">The type of the class of the controller</param>
        protected void LoadController(Type controllerType)
        {
            // Try load the controller
            if (controllerType != null)
            {
                ActiveControllerType = controllerType;

                if (ActiveController != null)
                {
                    ActiveController = null;    // Close any existing connections
                }
                try
                {
                    ActiveController = Controllers.LoadController(Settings.Default, controllerType);
                    SetError(null);
                }
                catch (Exception ex)
                {
                    // Couldn't load the controller, show the error message and destroy the active controller
                    SetError(ex);
                    ActiveController = null;
                }
            }
            else
            {
                // Loading a null controller
                ActiveController     = null;
                ActiveControllerType = null;
                SetError(null);
            }

            if (ActiveController != null)
            {
                // Controller loaded, use its settings
                LoadSettingsPage(ActiveController.Settings);
            }
            else
            {
                // Create a temporary scratch settings page until we can properly instantiate the controller
                scratchSettings = Controllers.GetControllerSettings(HexLight.Properties.Settings.Default, controllerType);
                LoadSettingsPage(scratchSettings);
            }
        }