예제 #1
0
        /// <summary>
        /// Initialises the form.
        /// </summary>
        private void MainForm_Load(object sender, EventArgs e)
        {
            // Load user settings before anything.
            LoadSettings();

            // Default colors, taken from the Firmware Table. Used on CM Mizar too.
            this.colorGrid1.Colors = new ColorCollection(new Color[] {
                //Color.FromArgb(0, 0, 0),
                Color.FromArgb(0xFF, 0, 0),
                Color.FromArgb(0, 0xFF, 0),
                Color.FromArgb(0, 0, 0xFF),
                Color.FromArgb(0x9E, 0xA0, 0),
                //Color.FromArgb(0xA0, 0, 0x4E),
                Color.FromArgb(0, 0x4E, 0xA0),
                Color.FromArgb(0xFF, 0x40, 0),
                Color.FromArgb(0x52, 0, 0xA0),
                Color.FromArgb(0xFF, 0xDA, 0xAA),
            });

            if (Firmware.IsLibraryForMizar())
            {
                this.startupHandlerBtn.Enabled = false;
                this.startupHandlerBtn.Visible = false;
            }
            else
            {
                this.startupHandlerBtn.Enabled = !HasStartupHandlerInstalled();
            }

            UpdateUIFromMouseMemory();
        }
예제 #2
0
        private async void applyBtn_Click(object sender, EventArgs e)
        {
            bool startupBtnState = startupHandlerBtn.Enabled;

            try
            {
                this.programmingMouse = true;

                applyBtn.Enabled          = false;
                defaultBtn.Enabled        = false;
                startupHandlerBtn.Enabled = false;

                Firmware.LedMode progMode = Firmware.LedMode.AlwaysOn;
                int  progBright = 0;
                byte progR = 0, progG = 0, progB = 0;

                Color color = ColorSlider.ToRgbColor();

                if (Firmware.GetLED(ref progMode, ref progBright, ref progR, ref progG, ref progB))
                {
                    if (progMode == GetLedModeFromRadio() && progBright == ledBrightnessSlider.Value &&
                        color.R == progR && color.G == progG && color.B == progB)
                    {
                        Console.WriteLine("Not reprogramming, just applying.");
                        Firmware.EnableCustomLED();
                        return;
                    }
                }

                Console.WriteLine("Reprogramming...");
                await Firmware.SetLEDAsync(GetLedModeFromRadio(), ledBrightnessSlider.Value, color.R, color.G, color.B);

                Firmware.EnableCustomLED();
            }
            catch (FirmwareException ex)
            {
                // Mouse may be in a "waiting for write operations" state, better reset the mouse.
                // Additionally, scroll wheel and LED are most likely turned off, so user should indeed reconnect the mice.
                MessageBox.Show("Failed to apply changes to the mouse.\n" +
                                "\nIt's highly recommended that you disconnect and reconnect your mice right now to avoid further problems.\n" +
                                "\nAdditional error information: " + ex.Message,
                                "CmAlcorGUI", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.programmingMouse = false;

                applyBtn.Enabled          = true;
                defaultBtn.Enabled        = true;
                startupHandlerBtn.Enabled = startupBtnState;
            }
        }
예제 #3
0
 private void defaultBtn_Click(object sender, EventArgs e)
 {
     try
     {
         Firmware.DisableCustomLED();
         RemoveStartupCommandFromRegistry();
     }
     catch (FirmwareException ex)
     {
         MessageBox.Show("Failed to apply changes to the mouse.\n" +
                         "\nAdditional error information: " + ex.Message,
                         "CmAlcorGUI", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
예제 #4
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (Firmware.IsMousePresent())
            {
                Application.Run(new MainForm());
            }
            else
            {
                string message = String.Format("The CM Storm {0} mouse is not connected or couldn't be found.",
                                               Firmware.IsLibraryForMizar()? "Mizar" : "Alcor");
                MessageBox.Show(message, "CmAlcorGUI", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #5
0
        /// <summary>
        /// Checks whether the startup library at %ProgramData% is older than the one in the directory of this GUI app.
        /// </summary>
        private bool IsStartupLibraryOlderThanCurrent()
        {
            bool isOlder = true;

            IntPtr libCmAlcor = NativeMethods.LoadLibrary(Path.Combine(alcorData, "cmalcor.dll"));

            if (libCmAlcor != IntPtr.Zero) // when doesn't exist or any other error
            {
                IntPtr ptrLibraryVersion = NativeMethods.GetProcAddress(libCmAlcor, "CmAlcor_LibraryVersion");
                IntPtr ptrLibraryFlags   = NativeMethods.GetProcAddress(libCmAlcor, "CmAlcor_LibraryFlags");
                if (ptrLibraryVersion != IntPtr.Zero && ptrLibraryFlags != IntPtr.Zero)
                {
                    var programDataLibraryVersion = (Firmware.Delegate_CmAlcor_LibraryVersion)Marshal.GetDelegateForFunctionPointer(ptrLibraryVersion, typeof(Firmware.Delegate_CmAlcor_LibraryVersion));
                    var programDataLibraryFlags   = (Firmware.Delegate_CmAlcor_LibraryFlags)Marshal.GetDelegateForFunctionPointer(ptrLibraryFlags, typeof(Firmware.Delegate_CmAlcor_LibraryFlags));
                    isOlder = (programDataLibraryVersion() < Firmware.LibraryVersion()) ||
                              (programDataLibraryFlags() != Firmware.LibraryFlags());
                }
                NativeMethods.FreeLibrary(libCmAlcor);
            }
            return(isOlder);
        }
예제 #6
0
        /// <summary>
        ///
        /// </summary>
        private void UpdateUIFromMouseMemory()
        {
            // default values
            var  currMode = Firmware.LedMode.AlwaysOn;
            int  currBrightness = 10;
            byte currRed = 0xFF, currGreen = 0x00, currBlue = 0x00;

            try
            {
                Firmware.GetLED(ref currMode, ref currBrightness, ref currRed, ref currGreen, ref currBlue);
            }
            catch (FirmwareException ex)
            {
                MessageBox.Show(ex.Message, "CmAlcorGUI", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.ColorSlider          = Color.FromArgb(currRed, currGreen, currBlue);
                ledBrightnessSlider.Value = currBrightness;
                SetRadioFromLedMode(currMode);
            }

            UpdateLedImageNow();
        }
예제 #7
0
 public FirmwareException(int error)
     : base(String.Format("{0}", Firmware.ErrorToString(error)))
 {
 }