예제 #1
0
        /// <summary>
        /// Request the error from the Mystic Light SDK
        /// </summary>
        /// <param name="statusCode">
        /// Statuscode returned from the Mystic Light SDK
        /// </param>
        /// <param name="error">
        /// The error that has been generated by the SDK
        /// </param>
        /// <returns>
        /// true if the status was OK, else false
        /// </returns>
        public static bool API_OK(int statusCode, out string error)
        {
            if (statusCode == (int)MLAPIStatus.MLAPI_OK)
            {
                error = null;
                return(true);
            }

            LightApiDLL.MLAPI_GetErrorMessage(statusCode, out error);
            return(false);
        }
예제 #2
0
        /// <summary>
        /// Constructor for the Light controller.
        /// This constructor initializes the
        /// <paramref name="dll_dir"/> if specified.
        /// </summary>
        /// <param name="dll_dir">
        /// Path to the directory containing the mystic light SDK
        /// This parameter is optional. If not provided, the default search procedure for DLL's is used.
        /// </param>
        public LightController(string dll_dir = null)
        {
            if (dll_dir != null)
            {
                LightApiDLL.SetDllDirectory(dll_dir);
            }

            // Initialize API
            if (!API_OK(LightApiDLL.MLAPI_Initialize(), out string error))
            {
                Console.WriteLine("Could not initalize Light API DLL:\n\tmsg: " + error);
                return;
            }

            _initalized = true;

            // Fetch devices
            if (!API_OK(LightApiDLL.MLAPI_GetDeviceInfo(out string[] devTypes, out string[] ledCount), out error))
            {
                Console.WriteLine("Could not fetch devices:\n\t" + error);
                return;
            }

            // Fill dictionary
            for (int i = 0; i < devTypes.Length; i++)
            {
                string device    = devTypes[i];
                uint   ledAmount = UInt32.Parse(ledCount[i]);
                if (ledAmount == 0)
                {
                    continue;
                }

                List <LED> leds = new List <LED>();
                for (uint ledIndex = 0; ledIndex < ledAmount; ledIndex++)
                {
                    leds.Add(new LED(device, ledIndex));
                }
                _availableLEDs.Add(device, leds.ToArray());
            }
        }