Exemplo n.º 1
0
 public RGBFusionManager()
 {
     _gLed         = new GLedImpl();
     _gvLed        = new GvLedImpl();
     _gLedSettings = new List <GLedSetting>();
 }
Exemplo n.º 2
0
        static void PeripheralsAPI()
        {
            // Trying to get VGA & Peripherals LED Control API working (GvLedLib.dll)
            IGvLed peripherals = new GvLedImpl();

            int deviceCount = 0;

            int[] deviceArray = new int[128];
            try
            {
                peripherals.Initialize(out deviceCount, deviceArray);
                int major = 0, minor = 0;
                peripherals.GetVersion(out major, out minor);

                Console.WriteLine("GvLedLib.dll Version: " + major + "." + minor);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return;
            }

            bool vgafound = false;

            Console.WriteLine("{0} VGA/Peripherals found", deviceCount);
            for (int i = 0; i < deviceCount; ++i)
            {
                GvDeviceID id = (GvDeviceID)deviceArray[i];
                Console.WriteLine("Device #{0}: ", id.ToString());

                if (id == GvDeviceID.GVLED_VGA)
                {
                    vgafound = true;
                }
            }

            if (vgafound)
            {
                string str;
                // Cannot get GetVgaModelName working correctly. Will have
                // to try a simple C app to see if that works before putting
                // anymore effort into it here. =/
                uint ret = peripherals.GetVgaModelName(out str);
                Console.WriteLine("VGA Name: {0}", str);
            }

            // TODO: Following could fail in multiple places, so make it safe.
            GvLedConfig   config;
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(GvLedConfig));

            string outputDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "//IdiotRGB//RGBFusion//Peripherals";

            if (!Directory.Exists(outputDir))
            {
                var info = Directory.CreateDirectory(outputDir);
            }

            var path = outputDir + "//GvLedType_SampleTest.xml";

            if (!File.Exists(path))
            {
                config           = new GvLedConfig();
                config.on        = true;
                config.color     = new GvLedColour(0, 0, 255, 0);
                config.type      = GvLedType.Pulsing;
                config.maxBright = 10;
                config.minBright = 10;
                config.time1     = 100;
                config.time2     = 200;

                FileStream outFile = File.Create(path);
                xmlSerializer.Serialize(outFile, config);
                outFile.Close();
            }

            ApplyConfigFromFile(path, peripherals);

            using (FileSystemWatcher watcher = new FileSystemWatcher())
            {
                watcher.Path         = Path.GetDirectoryName(path);
                watcher.Filter       = Path.GetFileName(path);
                watcher.NotifyFilter = NotifyFilters.LastWrite // Looks like only Size is working =/
                                       | NotifyFilters.LastAccess
                                       | NotifyFilters.Size;

                watcher.Changed += (object source, FileSystemEventArgs e) =>
                {
                    ApplyConfigFromFile(e.FullPath, peripherals);
                };

                Console.WriteLine("Watching file: " + path);
                watcher.EnableRaisingEvents = true; // Start watching.

                while (!periphThreadStop)
                {
                    Thread.Sleep(5);
                }
            }
        }