Esempio n. 1
0
        private void UpdatePagesFromSRAM()
        {
            Trace.Assert(UCCom.IsOpen, "UCCom has no connection at the moment!");

            byte[] sram;

            try
            {
                sram = UCCom.SendCommand(2, 0, 0);
            }
            catch (UCComException ex)
            {
                MessageBox.Show(this, string.Format(CultureInfo.CurrentCulture, StringRes.StringRes.CantUpdatePages,
                                                    ex.Message), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            this.SCREEN.SetValues(sram[Constants.CONFIG_OFFSET_BRIGHTNESS], sram[Constants.CONFIG_OFFSET_BRIGHTNESS_DRIVE], sram[Constants.CONFIG_OFFSET_CONTRAST]);

            this.COLORS.SetValues(
                sram[Constants.CONFIG_OFFSET_RED_CUTOFF], sram[Constants.CONFIG_OFFSET_GREEN_CUTOFF], sram[Constants.CONFIG_OFFSET_BLUE_CUTOFF],
                sram[Constants.CONFIG_OFFSET_RED_DRIVE], sram[Constants.CONFIG_OFFSET_GREEN_DRIVE], sram[Constants.CONFIG_OFFSET_BLUE_DRIVE]);

            this.GEOMETRY.SetValues(sram[Constants.CONFIG_OFFSET_HORIZONTAL_POS], sram[Constants.CONFIG_OFFSET_HEIGHT],
                                    sram[Constants.CONFIG_OFFSET_VERTICAL_POS], sram[Constants.CONFIG_OFFSET_KEYSTONE], sram[Constants.CONFIG_OFFSET_PINCUSHION],
                                    sram[Constants.CONFIG_OFFSET_PINCUSHION_BALANCE], sram[Constants.CONFIG_OFFSET_S_CORRECTION], sram[Constants.CONFIG_OFFSET_WIDTH],
                                    sram[Constants.CONFIG_OFFSET_PARALLELOGRAM], sram[Constants.CONFIG_OFFSET_ROTATION]);
        }
Esempio n. 2
0
        private void COLORS_ColorChanged(object sender, ColorsPageEventArgs e)
        {
            if (!UCCom.IsOpen)
            {
                return;
            }

            byte what;

            switch (e.Setting)
            {
            case ColorsPageEventArgs.ChangedSetting.RedCutoff:
                what = Constants.IVAD_SETTING_RED_CUTOFF;
                break;

            case ColorsPageEventArgs.ChangedSetting.GreenCutoff:
                what = Constants.IVAD_SETTING_GREEN_CUTOFF;
                break;

            case ColorsPageEventArgs.ChangedSetting.BlueCutoff:
                what = Constants.IVAD_SETTING_BLUE_CUTOFF;
                break;

            case ColorsPageEventArgs.ChangedSetting.RedDrive:
                what = Constants.IVAD_SETTING_RED_DRIVE;
                break;

            case ColorsPageEventArgs.ChangedSetting.GreenDrive:
                what = Constants.IVAD_SETTING_GREEN_DRIVE;
                break;

            case ColorsPageEventArgs.ChangedSetting.BlueDrive:
                what = Constants.IVAD_SETTING_BLUE_DRIVE;
                break;

            default:
                Trace.Fail("Unknown setting changed.");
                return;
            }

            try
            {
                UCCom.SendCommand(3, what, (byte)e.NewValue);
            }
            catch (UCComException ex)
            {
                MessageBox.Show(this, string.Format(CultureInfo.CurrentCulture, StringRes.StringRes.CantPerformChange,
                                                    ex.Message), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            this.applyButton.Enabled = true;
        }
Esempio n. 3
0
        private void cancelButton_Click(object sender, EventArgs e)
        {
            if (UCCom.IsOpen)
            {
                try
                {
                    UCCom.SendCommand(4, 0, 0);
                }
                catch (UCComException ex)
                {
                    MessageBox.Show(this, string.Format(CultureInfo.CurrentCulture, StringRes.StringRes.CantUndoChanges,
                                                        ex.Message), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);

                    return;
                }
            }

            Close();
        }
Esempio n. 4
0
        private void SCREEN_BrightnessDriveChanged(object sender, ScreenPageEventArgs e)
        {
            if (!UCCom.IsOpen)
            {
                return;
            }

            try
            {
                UCCom.SendCommand(3, Constants.IVAD_SETTING_BRIGHTNESS_DRIVE, (byte)e.NewValue);
            }
            catch (UCComException ex)
            {
                MessageBox.Show(this, string.Format(CultureInfo.CurrentCulture, StringRes.StringRes.CantPerformChange,
                                                    ex.Message), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            this.applyButton.Enabled = true;
        }
Esempio n. 5
0
        private void connectButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(this.comPortComboBox.Text))
            {
                MessageBox.Show(this.ParentForm, StringRes.StringRes.ComErrorBadPort,
                                StringRes.StringRes.ComErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            if (string.IsNullOrWhiteSpace(this.rateComboBox.Text))
            {
                MessageBox.Show(this.ParentForm, StringRes.StringRes.ComErrorBadRate,
                                StringRes.StringRes.ComErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            try
            {
                UCCom.Open(this.comPortComboBox.Text, (int)this.rateComboBox.Items[this.rateComboBox.SelectedIndex]);
            }
            catch (UCComException ex)
            {
                if (UCCom.IsOpen)
                {
                    UCCom.Close();
                }

                MessageBox.Show(this.ParentForm, string.Format(CultureInfo.CurrentCulture,
                                                               StringRes.StringRes.ComErrorOther, ex.Message), StringRes.StringRes.ComErrorTitle,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            Settings.Default.SerialPort = this.comPortComboBox.Text;
            Settings.Default.SerialRate = (int)this.rateComboBox.SelectedItem;
            OnSettingChanged(new AdvancedPageEventArgs());
        }
Esempio n. 6
0
        private void refreshButton_Click(object sender, EventArgs e)
        {
            Trace.Assert(UCCom.IsOpen, "UCCom has no connection at the moment!");

            this.refreshButton.Enabled = false;
            this.UseWaitCursor         = true;
            this.listView.BeginUpdate();
            Application.DoEvents();

            byte[] sram;

            try
            {
                sram = UCCom.SendCommand(2, 0, 0);
            }
            catch (UCComException ex)
            {
                MessageBox.Show(this, string.Format(CultureInfo.CurrentCulture, StringRes.StringRes.CantUpdatePages,
                                                    ex.Message), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);

                for (int i = 0; i < this.listView.Items.Count; i++)
                {
                    this.listView.Items[i].SubItems[1].Text = "?";
                    this.listView.Items[i].SubItems[2].Text = "?";
                }

                goto end;
            }

            for (int i = 0; i < sram.Length; i++)
            {
                this.listView.Items[i].SubItems[1].Text = string.Format(CultureInfo.InvariantCulture, "0x{0:X2}", sram[i]);
                this.listView.Items[i].SubItems[2].Text = string.Format(CultureInfo.InvariantCulture, "{0}", sram[i]);
            }

end:
            this.refreshButton.Enabled = true;
            this.UseWaitCursor         = false;
            this.listView.EndUpdate();
        }
Esempio n. 7
0
        private void defaultsButton_Click(object sender, EventArgs e)
        {
            if (!UCCom.IsOpen)
            {
                return;
            }

            try
            {
                UCCom.SendCommand(5, 0, 0);
            }
            catch (UCComException ex)
            {
                MessageBox.Show(this, string.Format(CultureInfo.CurrentCulture, StringRes.StringRes.CantResetDefaults,
                                                    ex.Message), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            UpdatePagesFromSRAM();
            this.applyButton.Enabled = false;
        }
Esempio n. 8
0
        private void applyButton_Click(object sender, EventArgs e)
        {
            Settings.Save();

            if (!UCCom.IsOpen)
            {
                goto end;
            }

            try
            {
                UCCom.SendCommand(6, 0, 0);
            }
            catch (UCComException ex)
            {
                MessageBox.Show(this, string.Format(CultureInfo.CurrentCulture, StringRes.StringRes.CantApplyChanges,
                                                    ex.Message), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);

                return; // Not "goto end;" to allow trying again
            }

end:
            this.applyButton.Enabled = false;
        }
Esempio n. 9
0
        private void GEOMETRY_GeometryChanged(object sender, GeometryPageEventArgs e)
        {
            if (!UCCom.IsOpen)
            {
                return;
            }

            byte what;

            switch (e.What)
            {
            case GeometryPageEventArgs.ChangedGemoetry.Height:
                what = Constants.IVAD_SETTING_HEIGHT;
                break;

            case GeometryPageEventArgs.ChangedGemoetry.Horizontal:
                what = Constants.IVAD_SETTING_HORIZONTAL_POS;
                break;

            case GeometryPageEventArgs.ChangedGemoetry.Keystone:
                what = Constants.IVAD_SETTING_KEYSTONE;
                break;

            case GeometryPageEventArgs.ChangedGemoetry.Parallelogram:
                what = Constants.IVAD_SETTING_PARALLELOGRAM;
                break;

            case GeometryPageEventArgs.ChangedGemoetry.Pincushion:
                what = Constants.IVAD_SETTING_PINCUSHION;
                break;

            case GeometryPageEventArgs.ChangedGemoetry.PincushionBalance:
                what = Constants.IVAD_SETTING_PINCUSHION_BALANCE;
                break;

            case GeometryPageEventArgs.ChangedGemoetry.SCorrection:
                what = Constants.IVAD_SETTING_S_CORRECTION;
                break;

            case GeometryPageEventArgs.ChangedGemoetry.Rotation:
                what = Constants.IVAD_SETTING_ROTATION;
                break;

            case GeometryPageEventArgs.ChangedGemoetry.Vertical:
                what = Constants.IVAD_SETTING_VERTICAL_POS;
                break;

            case GeometryPageEventArgs.ChangedGemoetry.Width:
                what = Constants.IVAD_SETTING_WIDTH;
                break;

            default:
                Trace.Fail("Unknown geometry changed.");
                return;
            }

            try
            {
                UCCom.SendCommand(3, what, (byte)e.NewValue);
            }
            catch (UCComException ex)
            {
                MessageBox.Show(this, string.Format(CultureInfo.CurrentCulture, StringRes.StringRes.CantPerformChange,
                                                    ex.Message), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            this.applyButton.Enabled = true;
        }
Esempio n. 10
0
 private void disconnectButton_Click(object sender, EventArgs e)
 {
     UCCom.Close();
 }
Esempio n. 11
0
        public static int Main(string[] args)
        {
            foreach (string arg in args)
            {
                if (arg.Equals("/log", StringComparison.OrdinalIgnoreCase))
                {
                    Logging.OpenLog();
                }

                if (arg.Equals("/reset", StringComparison.OrdinalIgnoreCase))
                {
                    Logging.WriteLineToLog("Resetting settings.");

                    Settings.Reset();
                    Settings.Save();

                    MessageBox.Show(StringRes.StringRes.SettingsReset,
                                    StringRes.StringRes.SettingsResetTitle, MessageBoxButtons.OK);
                }
            }

            Logging.WriteBannerToLog("Main");

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Mutex m = new Mutex(true, "crtcpl", out bool result);

            if (!result)
            {
                Logging.WriteLineToLog("Another instance is already running.");

                try
                {
#if !MONO
                    // Best effort switch to active instance
                    Process[] procs = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Application.ExecutablePath));
                    foreach (Process p in procs)
                    {
                        if (p.Id == Process.GetCurrentProcess().Id)
                        {
                            continue;
                        }

                        if (p.MainWindowHandle == IntPtr.Zero)
                        {
                            continue;
                        }

                        const int SW_SHOW = 5;

                        NativeMethods.SetForegroundWindow(p.MainWindowHandle);
                        NativeMethods.ShowWindow(p.MainWindowHandle, SW_SHOW);

                        Logging.WriteLineToLog("Switched to other instance.");

                        break;
                    }
#else
                    Logging.WriteLineToLog("Show error message.");

                    // Sorry, don't know what to do.
                    MessageBox.Show(StringRes.StringRes.AlreadyRunning, StringRes.StringRes.AlreadyRunningTitle,
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
#endif
                }
                catch (Exception e)
                {
                    Logging.WriteLineToLog("Exception while switching to other instance: {0}", e);
#if DEBUG
                    throw;
#endif
                }

                Logging.WriteLineToLog("Exiting.");

                return(1);
            }

            try
            {
                if (!string.IsNullOrWhiteSpace(Settings.Default.SerialPort))
                {
                    Logging.WriteLineToLog("Try to connect to serial port {0} at rate {1} from settings.",
                                           Settings.Default.SerialPort, Settings.Default.SerialRate);

                    try
                    {
                        UCCom.Open(Settings.Default.SerialPort, Settings.Default.SerialRate);
                    }
                    catch (UCComException e)
                    {
                        Logging.WriteLineToLog("Could not open serial port, so set to null. Error: {0}", e);

                        Settings.Default.SerialPort = null;
                        Settings.Default.SerialRate = -1;
                    }
                }

                Logging.WriteLineToLog("Main window opening now.");

                using (AppletForm a = new AppletForm())
                {
                    Application.Run(a);
                }
            }
            catch (Exception e)
            {
                Logging.WriteLineToLog("Crashed with exception in Main: {0}", e);
                throw;
            }
            finally
            {
                Logging.WriteLineToLog("Final cleanup running.");

                m.ReleaseMutex();
                m.Dispose();

                Logging.WriteLineToLog("Released and disposed mutex.");

                Logging.WriteLineToLog("Closing serial port.");

                try
                {
                    if (UCCom.IsOpen)
                    {
                        UCCom.Close();
                    }
                }
                catch (Exception e)
                {
                    Logging.WriteLineToLog("Error closing serial port: {0}", e);
                }
            }

            Logging.WriteLineToLog("Exiting now...");

            Application.Exit();

            return(0);
        }