//=================================================================
// setup.cs
//=================================================================
// Thetis is a C# implementation of a Software Defined Radio.
// Copyright (C) 2004-2009  FlexRadio Systems
// Copyright (C) 2010-2020  Doug Wigley
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
// You may contact us via email at: sales@flex-radio.com.
// Paper mail may be sent to: 
//    FlexRadio Systems
//    8900 Marybank Dr.
//    Austin, TX 78750
//    USA
//
//=================================================================
// Continual modifications Copyright (C) 2019-2024 Richard Samphire (MW0LGE)
//=================================================================

using System.Collections.Generic;
using System.Linq;
using Midi2Cat.IO;

namespace Thetis
{
    using System;
    using System.Collections;
    using System.Collections.Concurrent;
    using System.Data;
    using System.Diagnostics;
    using System.Drawing;
    using System.ComponentModel;
    using System.Threading;
    using System.Windows.Forms;
    using System.Text;
    using System.IO;
    using System.IO.Ports;
    using RawInput_dll;
    using System.Net;
    using System.Threading.Tasks;
    //using Ionic.Zip;
    using System.IO.Compression;
    using System.Timers;
    using System.Runtime.InteropServices;
    public partial class Setup : Form
    {
        private const string s_DEFAULT_GRADIENT = "9|1|0.000|-1509884160|1|0.339|-1493237760|1|0.234|-1509884160|1|0.294|-1493211648|0|0.669|-1493237760|0|0.159|-1|0|0.881|-65536|0|0.125|-32704|1|1.000|-1493237760|";
        #region Variable Declaration

        private Console console;
        private Progress progress;
        private List<Keys> KeyList;
        private bool initializing;
        public bool alex_fw_good = false;
        private string RXAntChk1Name;                   // radio dependent name for 1st check box
        private string RXAntChk2Name;                   // radio dependent name for 2nd check box
        private string RXAntChk3Name;                   // radio dependent name for 3rd check box

        private List<string> m_lstClickedControls;
        private List<string> m_lstUpdatedControls;
        private List<string> m_lstUpdatedControlsClone;
        private bool m_bShown = false; // used by the selective restore system to know accurate window state
        #endregion

        #region Constructor and Destructor

        public Setup(Console c)
        {
            InitializeComponent();

            Common.DoubleBufferAll(this, true);

            MaximumSize = MinimumSize;
            Size = MinimumSize;

            console = c;
            this.Owner = c;

            //everything here moved to AfterConstructor, which is called during singleton instance // G7KLJ's idea/implementation
        }
        internal void AfterConstructor()
        {
            Splash.SetStatus("Setting up controls");

            ThetisSkinService.Version = console.ProductVersion;

            updateDiscordState();

            addDelegates();

            //MW0LGE_21i
            ucVAC1VARGrapherIn.MaxPoints = ucVAC1VARGrapherIn.Width;
            ucVAC1VARGrapherOut.MaxPoints = ucVAC1VARGrapherOut.Width;
            ucVAC2VARGrapherIn.MaxPoints = ucVAC2VARGrapherIn.Width;
            ucVAC2VARGrapherOut.MaxPoints = ucVAC2VARGrapherOut.Width;

            //MW0LGE_21d used for selective cancel
            m_lstClickedControls = new List<string>();
            m_lstUpdatedControls = new List<string>();

            registerAllControlsForStateMonitoring();
            //-

            udDisplayFPS.Maximum = Console.MAX_FPS;

            Skin.SetConsole(console);

#if(!DEBUG)
            comboGeneralProcessPriority.Items.Remove("Idle");
            comboGeneralProcessPriority.Items.Remove("Below Normal");
#endif
            initializing = true;

            // MW0LGE note: this will allways cause the change event to fire, as the combobox does not contain any default value
            // it is bypassed in the event by use of the initializing flag, and is then
            // forced through in ForceAllEvents. This is the default radio with a blank database.
            if (comboRadioModel.Text == "") comboRadioModel.Text = "HERMES";
            //

            labelSavingLoading.Visible = false;// MW0LGE gets shown/hidden by save/cancel/apply

            // GetMixerDevices();
            GetHosts();
            InitAlexAntTables();

            KeyList = new List<Keys>();
            SetupKeyMap();

            GetTxProfiles();
            GetTxProfileDefs();
            RefreshCOMPortLists();

            InitAudioTab();

            initComboHistoryReadings0();

            //MW0LGE_21d some defaults
            chkShowZeroLine.Checked = true;
            chkGridControl.Checked = true;
            chkDisplayPanFill.Checked = true;
            showRegionBandstackWarning(false);
            //

            // init the WebImage links
            setup_comboWebImage_HamQsl();
            setup_comboWebImage_BsdWorld();
            setup_comboWebImage_nasa();
            setup_comboWebImage_noaa();
            //

            SetupDSPWarnings(false, false, false, false, false, false); // hide everything

            comboGeneralProcessPriority.Text = "Normal";
            comboOptFilterWidthMode.Text = "Linear";
            comboAudioSampleRate1.Text = "192000";
            comboAudioSampleRateRX2.Text = "192000";
            comboAudioSampleRate2.Text = "48000";
            comboAudioSampleRate3.Text = "48000";
            comboAudioBuffer2.Text = "1024";
            comboAudioBuffer3.Text = "1024";
            comboDisplayLabelAlign.Text = "Auto";
            comboColorPalette.Text = "enhanced";
            comboRX2ColorPalette.Text = "enhanced";
            comboTXLabelAlign.Text = "Cntr";
            //MW0LGE_21g comboDisplayDriver.Text = "DirectX";

            string sTip =
            "You can use the following variables anywhere in the text." + System.Environment.NewLine +
            "%nl%" + System.Environment.NewLine +
            "%swr%" + System.Environment.NewLine +
            "%signal_strength%" + System.Environment.NewLine +
            "%avg_signal_strength%" + System.Environment.NewLine +
            "%pwr%" + System.Environment.NewLine +
            "%reverse_pwr%" + System.Environment.NewLine +
            "%mic%" + System.Environment.NewLine +
            "%mic_pk%" + System.Environment.NewLine +
            "%adc_pk%" + System.Environment.NewLine +
            "%adc_av%" + System.Environment.NewLine +
            "%agc_pk%" + System.Environment.NewLine +
            "%agc_av%" + System.Environment.NewLine +
            "%agc_gain%" + System.Environment.NewLine +
            "%leveler%" + System.Environment.NewLine +
            "%leveler_pk%" + System.Environment.NewLine +
            "%lvl_g%" + System.Environment.NewLine +
            "%alc%" + System.Environment.NewLine +
            "%alc_pk%" + System.Environment.NewLine +
            "%alc_g%" + System.Environment.NewLine +
            "%alc_group%" + System.Environment.NewLine +
            "%cfc_av%" + System.Environment.NewLine +
            "%cfc_pk%" + System.Environment.NewLine +
            "%cfc_g%" + System.Environment.NewLine +
            "%comp%" + System.Environment.NewLine +
            "%comp_pk%" + System.Environment.NewLine +
            "%estimated_pbsnr%" + System.Environment.NewLine +
            System.Environment.NewLine +
            "%time_utc%" + System.Environment.NewLine +
            "%time_loc%" + System.Environment.NewLine +
            "%time_utc_int%" + System.Environment.NewLine +
            "%time_loc_int%" + System.Environment.NewLine +
            "%date_utc%" + System.Environment.NewLine +
            "%date_loc%" + System.Environment.NewLine +
            "%date_utc_int%" + System.Environment.NewLine +
            "%date_loc_int%" + System.Environment.NewLine +
            "%vfoa%" + System.Environment.NewLine +
            "%vfob%" + System.Environment.NewLine +
            "%vfoasub%" + System.Environment.NewLine +
            "%vfoa_double%" + System.Environment.NewLine +
            "%vfob_double%" + System.Environment.NewLine +
            "%vfoasub_double%" + System.Environment.NewLine +
            "%band_vfoa%" + System.Environment.NewLine +
            "%band_vfob%" + System.Environment.NewLine +
            "%band_vfoasub%" + System.Environment.NewLine +
            "%mode_vfoa%" + System.Environment.NewLine +
            "%mode_vfob%" + System.Environment.NewLine +
            "%subrx%" + System.Environment.NewLine +
            "%filter_vfoa%" + System.Environment.NewLine +
            "%filter_vfob%" + System.Environment.NewLine +
            "%filter_vfoa_name%" + System.Environment.NewLine +
            "%filter_vfob_name%" + System.Environment.NewLine +
            "%split%" + System.Environment.NewLine +
            "%qso_time%" + System.Environment.NewLine +
            "%qso_time_short%" + System.Environment.NewLine +
            "%qso_time_int%" + System.Environment.NewLine +
            "%tb_qso_time%" + System.Environment.NewLine +
            "%tb_qso_time_short%" + System.Environment.NewLine +
            "%tb_qso_time_int%" + System.Environment.NewLine +
            "%volts%" + System.Environment.NewLine +
            "%amps%" + System.Environment.NewLine +
            "%mox%" + System.Environment.NewLine +
            "%cfc%" + System.Environment.NewLine +
            "%comp%" + System.Environment.NewLine +
            "%lev%" + System.Environment.NewLine +
            "%rx2%" + System.Environment.NewLine +
            "%tx_eq%" + System.Environment.NewLine +
            "%bandtext_vfoa%" + System.Environment.NewLine +
            "%bandtext_vfob%" + System.Environment.NewLine +
            "%precis=1%" + System.Environment.NewLine +
            "%nf%" + System.Environment.NewLine +
            "%tune_step%" + System.Environment.NewLine +
            "%pa_profile%" + System.Environment.NewLine +
            "%discord_general=0%" + System.Environment.NewLine +
            "%discord_bot=0%";// + System.Environment.NewLine +

            toolTip1.SetToolTip(pbTextOverlay_variables, sTip);

            //MW0LGE_21h
            sTip =
            "The feedback gain loop attempts to keep the sample buffer about � full." + System.Environment.NewLine +
            "This gives the maximum amount of margin before an overflow or underflow will occur." + System.Environment.NewLine +
            "If the gain is too high, the loop will respond too fast and strongly and we may " + System.Environment.NewLine +
            "end up with an over-full buffer (overflow) or empty buffer (underflow)." + System.Environment.NewLine +
            "If the gain is too low, the loop will not respond fast enough to prevent an overflow or underflow. - NR0V";
            toolTip1.SetToolTip(pbVAC1FeedbackGainInfo, sTip);

            sTip =
            "In the event of an underflow, the sample stream is slewed to zero, held there until there are more samples available," + System.Environment.NewLine +
            "and then slewed back up to maximum output amplitude. In the event of an overflow," + System.Environment.NewLine +
            "some samples are discarded and the ends of the before and after curves are blended along a raised-cosine trajectory." + System.Environment.NewLine +
            "�slew time� controls the rate of slewing or blending. - NR0V";
            toolTip1.SetToolTip(pbVAC1SlewTimeInfo, sTip);

            //MW0LGE_21j
            sTip =
            "The minimum number of values that must be collected in the moving average filter (feedback loop) before" + System.Environment.NewLine +
            "its result is deemed stable enough to be of use. - NR0V";
            toolTip1.SetToolTip(pbVAC1PropFeedbackMinInfo, sTip);

            sTip =
            "The size/length of a moving average filter in the feedback loop. To reduce computation, it�s value must be a power of two." + System.Environment.NewLine +
            "Making this smaller will make the loop more responsive; however, you may need to reduce the feedback gain in that case." + System.Environment.NewLine +
            "Making it larger will make output values more stable and consistent � you might need to increase feedback gain in that case. - NR0V";
            toolTip1.SetToolTip(pbVAC1PropFeedbackMaxInfo, sTip);

            sTip =
            "In controlling the sampling ratio, there is a feed-forward term which measures the number of samples being inserted into the resampler," + System.Environment.NewLine +
            "the number of samples being withdrawn from the resampler, and essentially attempts to calculate the ratio of input/output sample rates." + System.Environment.NewLine +
            "Again we have a moving average filter with parameters, with min and max similiar to the proportional feedback loop above. - NR0V";
            toolTip1.SetToolTip(pbVAC1FFMinInfo, sTip);

            sTip =
            "In controlling the sampling ratio, this is the size/length of the moving average filter. To reduce computation, it�s value must be a power of two. - NR0V";
            toolTip1.SetToolTip(pbVAC1FFMaxInfo, sTip);

            sTip =
            "FF_Alpha is a smoothing parameter on the recursive filter. In summary, the �var� ratio of the resampler is currently determined from two sources:" + System.Environment.NewLine +
            "(1) a feedback loop that attempts to keep the buffer half full, and " + System.Environment.NewLine +
            "(2) a feed-forward term that attempts to keep the resampler at the correct sampling ratio. - NR0V";
            toolTip1.SetToolTip(pbVAC1FFAlphaInfo, sTip);

            InitAdvancedAudioTab(null);

            //OC tab //MW0LGE_21j
            comboPin1TXActionHF.SelectedIndex = comboPin1TXActionVHF.SelectedIndex = comboPin1TXActionSWL.SelectedIndex = (int)TXPinActions.MOX_TUNE_TWOTONE;
            comboPin2TXActionHF.SelectedIndex = comboPin2TXActionVHF.SelectedIndex = comboPin2TXActionSWL.SelectedIndex = (int)TXPinActions.MOX_TUNE_TWOTONE;
            comboPin3TXActionHF.SelectedIndex = comboPin3TXActionVHF.SelectedIndex = comboPin3TXActionSWL.SelectedIndex = (int)TXPinActions.MOX_TUNE_TWOTONE;
            comboPin4TXActionHF.SelectedIndex = comboPin4TXActionVHF.SelectedIndex = comboPin4TXActionSWL.SelectedIndex = (int)TXPinActions.MOX_TUNE_TWOTONE;
            comboPin5TXActionHF.SelectedIndex = comboPin5TXActionVHF.SelectedIndex = comboPin5TXActionSWL.SelectedIndex = (int)TXPinActions.MOX_TUNE_TWOTONE;
            comboPin6TXActionHF.SelectedIndex = comboPin6TXActionVHF.SelectedIndex = comboPin6TXActionSWL.SelectedIndex = (int)TXPinActions.MOX_TUNE_TWOTONE;
            comboPin7TXActionHF.SelectedIndex = comboPin7TXActionVHF.SelectedIndex = comboPin7TXActionSWL.SelectedIndex = (int)TXPinActions.MOX_TUNE_TWOTONE;

            chkPin1TXPAHF.Checked = chkPin1TXPAVHF.Checked = chkPin1TXPASWL.Checked = false;
            chkPin2TXPAHF.Checked = chkPin2TXPAVHF.Checked = chkPin2TXPASWL.Checked = false;
            chkPin3TXPAHF.Checked = chkPin3TXPAVHF.Checked = chkPin3TXPASWL.Checked = false;
            chkPin4TXPAHF.Checked = chkPin4TXPAVHF.Checked = chkPin4TXPASWL.Checked = false;
            chkPin5TXPAHF.Checked = chkPin5TXPAVHF.Checked = chkPin5TXPASWL.Checked = false;
            chkPin6TXPAHF.Checked = chkPin6TXPAVHF.Checked = chkPin6TXPASWL.Checked = false;
            chkPin7TXPAHF.Checked = chkPin7TXPAVHF.Checked = chkPin7TXPASWL.Checked = false;
            //MW0LGE_21k8 initialise these
            chkMercDither.Checked = true;
            chkMercRandom.Checked = true;
            //

            comboFRSRegion.Text = "United States";

            console.DeferUpdateDSP = true; //MW0LGE_21k9d updated below
            comboDSPPhoneRXBuf.Text = "1024";
            comboDSPPhoneTXBuf.Text = "1024";
            comboDSPFMRXBuf.Text = "1024";
            comboDSPFMTXBuf.Text = "1024";
            comboDSPCWRXBuf.Text = "1024";
            comboDSPDigRXBuf.Text = "1024";
            comboDSPDigTXBuf.Text = "1024";

            comboDSPPhoneRXFiltSize.Text = "4096";
            comboDSPPhoneTXFiltSize.Text = "4096";
            comboDSPFMRXFiltSize.Text = "4096";
            comboDSPFMTXFiltSize.Text = "4096";
            comboDSPCWRXFiltSize.Text = "4096";
            comboDSPDigRXFiltSize.Text = "4096";
            comboDSPDigTXFiltSize.Text = "4096";

            comboDSPPhoneRXFiltType.SelectedIndex = 0;
            comboDSPPhoneTXFiltType.SelectedIndex = 0;
            comboDSPFMRXFiltType.SelectedIndex = 0;
            comboDSPFMTXFiltType.SelectedIndex = 0;
            comboDSPCWRXFiltType.SelectedIndex = 0;
            comboDSPDigRXFiltType.SelectedIndex = 0;
            comboDSPDigTXFiltType.SelectedIndex = 0;

            comboDispWinType.Text = "Hann";
            comboRX2DispWinType.Text = "Hann";
            comboDispPanDetector.Text = "Peak";
            comboDispWFDetector.Text = "Peak";
            comboDispPanAveraging.Text = "Log Recursive";
            comboDispWFAveraging.Text = "Log Recursive";
            comboRX2DispPanDetector.Text = "Peak";
            comboRX2DispPanAveraging.Text = "Log Recursive";
            comboRX2DispWFDetector.Text = "Peak";
            comboRX2DispWFAveraging.Text = "Log Recursive";
            comboTXDispPanDetector.Text = "Peak";
            comboTXDispPanAveraging.Text = "Log Recursive";
            comboTXDispWinType.Text = "Hann";
            comboTXDispWFDetector.Text = "Peak";
            comboTXDispWFAveraging.Text = "Log Recursive";
            comboKeyerConnKeyLine.SelectedIndex = 0;
            comboKeyerConnSecondary.SelectedIndex = 0;
            comboKeyerConnPTTLine.SelectedIndex = 0;
            comboKeyerConnPrimary.SelectedIndex = 0;
            comboTXTUNMeter.Text = "Fwd SWR";
            comboMeterType.Text = "Edge";
            if (comboCATPort.Items.Count > 0) comboCATPort.SelectedIndex = 0;
            if (comboCATPTTPort.Items.Count > 0) comboCATPTTPort.SelectedIndex = 0;
            comboCATbaud.Text = "115200";
            comboCATparity.Text = "none";
            comboCATdatabits.Text = "8";
            comboCATstopbits.Text = "1";
            comboCATRigType.Text = "TS-2000";
            comboFocusMasterMode.Text = "None";

            if (comboCAT2Port.Items.Count > 0) comboCAT2Port.SelectedIndex = 0;
            comboCAT2baud.Text = "115200";
            comboCAT2parity.Text = "none";
            comboCAT2databits.Text = "8";
            comboCAT2stopbits.Text = "1";

            if (comboCAT3Port.Items.Count > 0) comboCAT3Port.SelectedIndex = 0;
            comboCAT3baud.Text = "115200";
            comboCAT3parity.Text = "none";
            comboCAT3databits.Text = "8";
            comboCAT3stopbits.Text = "1";

            if (comboCAT4Port.Items.Count > 0) comboCAT4Port.SelectedIndex = 0;
            comboCAT4baud.Text = "115200";
            comboCAT4parity.Text = "none";
            comboCAT4databits.Text = "8";
            comboCAT4stopbits.Text = "1";

            if (comboAndromedaCATPort.Items.Count > 0) comboAndromedaCATPort.SelectedIndex = 0;
            if (comboAriesCATPort.Items.Count > 0) comboAriesCATPort.SelectedIndex = 0;
            if (comboGanymedeCATPort.Items.Count > 0) comboGanymedeCATPort.SelectedIndex = 0;

            // some default tci server states MW0LGE_21k9d
            chkCopyRX2VFObToVFOa.Checked = true;
            chkUseRX1vfoaForRX2vfoa.Checked = true;
            chkTCIsendInitialStateOnConnect.Checked = true;
            // some default tcpipcat server states
            chkWelcomeMessageTCPIPCat.Checked = true;
            // some default tcpipcat + tci
            chkLimitPowerCATTCIMsgs.Checked = true;
            //

            console.QSOTimerAudioPlayer.LoadCompletedEvent += audioFileLoaded;

            RefreshSkinList(); //moved down the initialisation order, so we at least know if we are gdi or dx, only build the list

            //display defaults
            chkVSyncDX.Enabled = true;
            //

            //MW0LGE_22b PA Profiles
            initPAProfiles();
            //

            getOptions();

            selectSkin();

            //MW0LGE [2.9.0.7] setup amp/volts calibration
            initVoltsAmpsCalibration();
            chkLogVoltsAmps.Checked = false;
            //

            // display setup
            console.SetupDisplayEngine(false); //MW0LGE_21k9
            //

            //MW0LGE_21j
            console.RepositionExternalPAButton(CheckForAnyExternalPACheckBoxes());

            if (comboDSPPhoneRXBuf.SelectedIndex < 0 || comboDSPPhoneRXBuf.SelectedIndex >= comboDSPPhoneRXBuf.Items.Count)
                comboDSPPhoneRXBuf.SelectedIndex = comboDSPPhoneRXBuf.Items.Count - 1;
            if (comboDSPPhoneTXBuf.SelectedIndex < 0 || comboDSPPhoneTXBuf.SelectedIndex >= comboDSPPhoneTXBuf.Items.Count)
                comboDSPPhoneTXBuf.SelectedIndex = comboDSPPhoneTXBuf.Items.Count - 1;
            if (comboDSPCWRXBuf.SelectedIndex < 0 || comboDSPCWRXBuf.SelectedIndex >= comboDSPCWRXBuf.Items.Count)
                comboDSPCWRXBuf.SelectedIndex = comboDSPCWRXBuf.Items.Count - 1;
            if (comboDSPDigRXBuf.SelectedIndex < 0 || comboDSPDigRXBuf.SelectedIndex >= comboDSPDigRXBuf.Items.Count)
                comboDSPDigRXBuf.SelectedIndex = comboDSPDigRXBuf.Items.Count - 1;
            if (comboDSPDigTXBuf.SelectedIndex < 0 || comboDSPDigTXBuf.SelectedIndex >= comboDSPDigTXBuf.Items.Count)
                comboDSPDigTXBuf.SelectedIndex = comboDSPDigTXBuf.Items.Count - 1;

            if (comboCATPort.SelectedIndex < 0)
            {
                if (comboCATPort.Items.Count > 0)
                    comboCATPort.SelectedIndex = 0;
                else
                {
                    chkCATEnable.Checked = false;
                    chkCATEnable.Enabled = false;
                }
            }

            if (comboCAT2Port.SelectedIndex < 0)
            {
                if (comboCAT2Port.Items.Count > 0)
                    comboCAT2Port.SelectedIndex = 0;
                else
                {
                    chkCAT2Enable.Checked = false;
                    chkCAT2Enable.Enabled = false;
                }
            }

            if (comboCAT3Port.SelectedIndex < 0)
            {
                if (comboCAT3Port.Items.Count > 0)
                    comboCAT3Port.SelectedIndex = 0;
                else
                {
                    chkCAT3Enable.Checked = false;
                    chkCAT3Enable.Enabled = false;
                }
            }

            if (comboCAT4Port.SelectedIndex < 0)
            {
                if (comboCAT4Port.Items.Count > 0)
                    comboCAT4Port.SelectedIndex = 0;
                else
                {
                    chkCAT4Enable.Checked = false;
                    chkCAT4Enable.Enabled = false;
                }
            }

            if (comboAndromedaCATPort.SelectedIndex < 0)
            {
                if (comboAndromedaCATPort.Items.Count > 0)
                    comboAndromedaCATPort.SelectedIndex = 0;
                else
                {
                    chkEnableAndromeda.Checked = false;
                    if(!chkAndrG2Panel.Checked)
                    chkEnableAndromeda.Enabled = false;
                }
            }

            if (comboAriesCATPort.SelectedIndex < 0)
            {
                if (comboAriesCATPort.Items.Count > 0)
                    comboAriesCATPort.SelectedIndex = 0;
                else
                {
                    chkEnableAries.Checked = false;
                    chkEnableAries.Enabled = false;
                }
            }

            if (comboGanymedeCATPort.SelectedIndex < 0)
            {
                if (comboGanymedeCATPort.Items.Count > 0)
                    comboGanymedeCATPort.SelectedIndex = 0;
                else
                {
                    chkEnableGanymede.Checked = false;
                    chkEnableGanymede.Enabled = false;
                }
            }

            cmboSigGenRXMode.Text = "Radio";
            cmboSigGenTXMode.Text = "Radio";

            if (comboAudioDriver2.SelectedIndex < 0 &&
                comboAudioDriver2.Items.Count > 0)
                comboAudioDriver2.SelectedIndex = 0;

            if (comboAudioDriver3.SelectedIndex < 0 &&
                comboAudioDriver3.Items.Count > 0)
                comboAudioDriver3.SelectedIndex = 0;

            comboAudioBuffer1_SelectedIndexChanged(this, EventArgs.Empty);

            initializing = false;

            udDisplayScopeTime_ValueChanged(this, EventArgs.Empty);

            if (chkCATEnable.Checked)
            {
                chkCATEnable_CheckedChanged(this, EventArgs.Empty);
            }

            if (chkCAT2Enable.Checked)
            {
                chkCAT2Enable_CheckedChanged(this, EventArgs.Empty);
            }

            if (chkCAT3Enable.Checked)
            {
                chkCAT3Enable_CheckedChanged(this, EventArgs.Empty);
            }

            if (chkCAT4Enable.Checked)
            {
                chkCAT4Enable_CheckedChanged(this, EventArgs.Empty);
            }

            if (chkEnableAndromeda.Checked)
            {
                ChkEnableAndromeda_CheckedChanged(this, EventArgs.Empty);
            }

            if (chkEnableAries.Checked)
            {
                ChkEnableAries_CheckedChanged(this, EventArgs.Empty);
            }

            if (chkEnableGanymede.Checked)
            {
                ChkEnableGanymede_CheckedChanged(this, EventArgs.Empty);
            }

            if (chkCATPTTEnabled.Checked)
            {
                chkCATPTTEnabled_CheckedChanged(this, EventArgs.Empty);
            }

            comboKeyerConnSecondary_SelectedIndexChanged(this, EventArgs.Empty);

            chkConsoleDarkModeTitleBar.Visible = Common.IsWindows10OrGreater(); //MW0LGE [2.9.0.8]

            ForceAllEvents();

            EventArgs e = EventArgs.Empty;
            tbRX1FilterAlpha_Scroll(this, e);
            tbTXFilterAlpha_Scroll(this, e);
            tbBackgroundAlpha_Scroll(this, e);
            tbTXBackgroundAlpha_Scroll(this, e);
            tbGridCourseAlpha_Scroll(this, e);
            tbTXVGridCourseAlpha_Scroll(this, e);
            tbGridFineAlpha_Scroll(this, e);
            tbTXVGridFineAlpha_Scroll(this, e);
            tbHGridColorAlpha_Scroll(this, e);
            tbTXHGridColorAlpha_Scroll(this, e);
            tbMultiRXFilterAlpha_Scroll(this, e);
            tbTXZeroLineAlpha_Scroll(this, e);
            tbTXTextAlpha_Scroll(this, e);
            tbMeterEdgeBackgroundAlpha_Scroll(this, e);
            checkHPSDRDefaults(this, e);
            chkAlexPresent_CheckedChanged(this, e);
            chkApolloPresent_CheckedChanged(this, e);
            chkAlexAntCtrl_CheckedChanged(this, e);
            initializing = true; //MW0LGE_21d stop the lg from notifying changed events
            TbDataFillAlpha_Scroll(this, e);
            initializing = false;

            for (int i = 0; i < 2; i++)
                for (int j = 0; j < 2; j++)
                    console.radio.GetDSPRX(i, j).Update = true;

            console.DeferUpdateDSP = true;  //MW0LGE_21k9d need to set this again as it gets undone in load txprofile in ForceAllEvents (ForceTXProfile)
            comboDSPPhoneRXBuf_SelectedIndexChanged(this, EventArgs.Empty);
            comboDSPPhoneTXBuf_SelectedIndexChanged(this, EventArgs.Empty);
            comboDSPFMRXBuf_SelectedIndexChanged(this, EventArgs.Empty);
            comboDSPFMTXBuf_SelectedIndexChanged(this, EventArgs.Empty);
            comboDSPCWRXBuf_SelectedIndexChanged(this, EventArgs.Empty);
            comboDSPDigRXBuf_SelectedIndexChanged(this, EventArgs.Empty);
            comboDSPDigTXBuf_SelectedIndexChanged(this, EventArgs.Empty);
            comboDSPPhoneRXFiltSize_SelectedIndexChanged(this, EventArgs.Empty);
            comboDSPPhoneTXFiltSize_SelectedIndexChanged(this, EventArgs.Empty);
            comboDSPFMRXFiltSize_SelectedIndexChanged(this, EventArgs.Empty);
            comboDSPFMTXFiltSize_SelectedIndexChanged(this, EventArgs.Empty);
            comboDSPCWRXFiltSize_SelectedIndexChanged(this, EventArgs.Empty);
            comboDSPDigRXFiltSize_SelectedIndexChanged(this, EventArgs.Empty);
            comboDSPDigTXFiltSize_SelectedIndexChanged(this, EventArgs.Empty);
            comboDSPPhoneRXFiltType_SelectedIndexChanged(this, EventArgs.Empty);
            comboDSPPhoneTXFiltType_SelectedIndexChanged(this, EventArgs.Empty);
            comboDSPFMRXFiltType_SelectedIndexChanged(this, EventArgs.Empty);
            comboDSPFMTXFiltType_SelectedIndexChanged(this, EventArgs.Empty);
            comboDSPCWRXFiltType_SelectedIndexChanged(this, EventArgs.Empty);
            comboDSPDigRXFiltType_SelectedIndexChanged(this, EventArgs.Empty);
            comboDSPDigTXFiltType_SelectedIndexChanged(this, EventArgs.Empty);
            console.DeferUpdateDSP = false;  //MW0LGE_21k9d

            console.specRX.GetSpecRX(0).Update = true;
            console.specRX.GetSpecRX(1).Update = true;

            btnRX2PBsnr.Enabled = console.RX2Enabled; //MW0LGE [2.9.0.7]

            //MW0LGE_21e
            UpdateDDCTab();
            chkHighlightTXProfileSaveItems.Checked = false;

            if (chkKWAI.Checked)
                AllowFreqBroadcast = true;
            else
                AllowFreqBroadcast = false;

            //MW0LGE_21h
            updateNetworkThrottleCheckBox();
        }
        private bool _bAddedDelegates = false;
        private void addDelegates()
        {
            if (console == null || _bAddedDelegates) return;

            console.MoxChangeHandlers += OnMoxChangeHandler;
            console.TXBandChangeHandlers += OnTXBandChanged;
            console.RX2EnabledChangedHandlers += OnRX2EnabledChanged;
            console.TXInhibitChangedHandlers += OnTXInhibit;
            console.BandChangeHandlers += OnBCDBandChangeHandler;

            ThetisSkinService.SubscribeForSkinServerData(skinServersDataReceivedHandler);
            ThetisSkinService.SubscribeForSkinData(skinDataReceivedHandler);
            ThetisSkinService.SubscribeForImageLoaded(imageLoadedHandler);
            ThetisSkinService.SubscribeForDownload(fileDownloadHandler);

            ThetisBotDiscord.ConnectedHandlers += OnDiscordConnect;
            ThetisBotDiscord.DisconnectedHandlers += OnDiscordDisconnect;
            ThetisBotDiscord.ReadyHandlers += OnDiscordReady;

            _bAddedDelegates = true;
        }
        public void RemoveDelegates()
        {
            if (console == null || !_bAddedDelegates) return;

            // used outside by console exit
            console.MoxChangeHandlers -= OnMoxChangeHandler;
            console.TXBandChangeHandlers -= OnTXBandChanged;
            console.RX2EnabledChangedHandlers -= OnRX2EnabledChanged;
            console.TXInhibitChangedHandlers -= OnTXInhibit;
            console.BandChangeHandlers -= OnBCDBandChangeHandler;

            ThetisSkinService.UnsubscribeFromSkinData(skinDataReceivedHandler);
            ThetisSkinService.UnsubscribeFromSkinServerData(skinServersDataReceivedHandler);
            ThetisSkinService.UnsubscribeFromImageLoaded(imageLoadedHandler);
            ThetisSkinService.UnsubscribeFromDownload(fileDownloadHandler);

            ThetisBotDiscord.ConnectedHandlers -= OnDiscordConnect;
            ThetisBotDiscord.DisconnectedHandlers -= OnDiscordDisconnect;
            ThetisBotDiscord.ReadyHandlers -= OnDiscordReady;

            _bAddedDelegates = false;
        }
        private void OnTXInhibit(bool oldState, bool newState)
        {
            if (TestIMD && newState) TestIMD = false; // return button state etc

            chkTestIMD.Enabled = !newState;
        }
        private void OnRX2EnabledChanged(bool enabled)
        {
            btnRX2PBsnr.Enabled = enabled;

            // maintain selection, because updateMeter2Controls clears it
            string sId = "";
            clsContainerComboboxItem cci = (clsContainerComboboxItem)comboContainerSelect.SelectedItem;
            if (cci != null)
            {
                sId = cci.ID;
            }
            updateMeter2Controls(sId);
        }
        #endregion

        #region Init Routines
        // ======================================================
        // Init Routines
        // ======================================================

        // note: any control that needs it settings recovered from the DB when cancel clicked, uses this 'needsRecovering' system
        private void InitGeneralTab(List<string> recoveryList = null)
        {
            if (needsRecovering(recoveryList, "chkGeneralRXOnly")) chkGeneralRXOnly.Checked = console.RXOnly;
            if (needsRecovering(recoveryList, "chkGeneralDisablePTT")) chkGeneralDisablePTT.Checked = console.DisablePTT;
            if (needsRecovering(recoveryList, "chkWheelTunesOutsideSpectral")) chkWheelTunesOutsideSpectral.Checked = console.WheelTunesOutsideSpectral;
            if (needsRecovering(recoveryList, "chkAlsoUseSpecificMouseWheel")) chkAlsoUseSpecificMouseWheel.Checked = console.AlsoUseSpecificMouseWheel;
            if (needsRecovering(recoveryList, "chkZoomShiftModifier")) chkZoomShiftModifier.Checked = console.ZoomShiftModifier;
            if (needsRecovering(recoveryList, "chkExtended")) chkExtended.Checked = console.Extended;
        }

        private void InitADC(List<string> recoveryList = null)
        {
            if (needsRecovering(recoveryList, "radDDC0ADC0")) radDDC0ADC0.Checked = true;
            if (needsRecovering(recoveryList, "radDDC0ADC1")) radDDC0ADC1.Checked = false;
            if (needsRecovering(recoveryList, "radDDC0ADC2")) radDDC0ADC2.Checked = false;

            if (needsRecovering(recoveryList, "radDDC1ADC0")) radDDC1ADC0.Checked = false;
            if (needsRecovering(recoveryList, "radDDC1ADC1")) radDDC1ADC1.Checked = true;
            if (needsRecovering(recoveryList, "radDDC1ADC2")) radDDC1ADC2.Checked = false;

            if (needsRecovering(recoveryList, "radDDC2ADC0")) radDDC2ADC0.Checked = true;
            if (needsRecovering(recoveryList, "radDDC2ADC1")) radDDC2ADC1.Checked = false;
            if (needsRecovering(recoveryList, "radDDC2ADC2")) radDDC2ADC2.Checked = false;

            if (needsRecovering(recoveryList, "radDDC3ADC0")) radDDC3ADC0.Checked = false;
            if (needsRecovering(recoveryList, "radDDC3ADC1")) radDDC3ADC1.Checked = true;
            if (needsRecovering(recoveryList, "radDDC3ADC2")) radDDC3ADC2.Checked = false;

            if (needsRecovering(recoveryList, "radDDC4ADC0")) radDDC4ADC0.Checked = true;
            if (needsRecovering(recoveryList, "radDDC4ADC1")) radDDC4ADC1.Checked = false;
            if (needsRecovering(recoveryList, "radDDC4ADC2")) radDDC4ADC2.Checked = false;

            if (needsRecovering(recoveryList, "radDDC5ADC0")) radDDC5ADC0.Checked = true;
            if (needsRecovering(recoveryList, "radDDC5ADC1")) radDDC5ADC1.Checked = false;
            if (needsRecovering(recoveryList, "radDDC5ADC2")) radDDC5ADC2.Checked = false;

            if (needsRecovering(recoveryList, "radDDC6ADC0")) radDDC6ADC0.Checked = true;
            if (needsRecovering(recoveryList, "radDDC6ADC1")) radDDC6ADC1.Checked = false;
            if (needsRecovering(recoveryList, "radDDC6ADC2")) radDDC6ADC2.Checked = false;

            if (needsRecovering(recoveryList, "radP1DDC0ADC0")) radP1DDC0ADC0.Checked = true;
            if (needsRecovering(recoveryList, "radP1DDC0ADC1")) radP1DDC0ADC1.Checked = false;
            if (needsRecovering(recoveryList, "radP1DDC0ADC2")) radP1DDC0ADC2.Checked = false;

            if (needsRecovering(recoveryList, "radP1DDC1ADC0")) radP1DDC1ADC0.Checked = false;
            if (needsRecovering(recoveryList, "radP1DDC1ADC1")) radP1DDC1ADC1.Checked = true;
            if (needsRecovering(recoveryList, "radP1DDC1ADC2")) radP1DDC1ADC2.Checked = false;

            if (needsRecovering(recoveryList, "radP1DDC2ADC0")) radP1DDC2ADC0.Checked = false;
            if (needsRecovering(recoveryList, "radP1DDC2ADC1")) radP1DDC2ADC1.Checked = true;
            if (needsRecovering(recoveryList, "radP1DDC2ADC2")) radP1DDC2ADC2.Checked = false;

            if (needsRecovering(recoveryList, "radP1DDC3ADC0")) radP1DDC3ADC0.Checked = true;
            if (needsRecovering(recoveryList, "radP1DDC3ADC1")) radP1DDC3ADC1.Checked = false;
            if (needsRecovering(recoveryList, "radP1DDC3ADC2")) radP1DDC3ADC2.Checked = false;

            if (needsRecovering(recoveryList, "radP1DDC4ADC0")) radP1DDC4ADC0.Checked = true;
            if (needsRecovering(recoveryList, "radP1DDC4ADC1")) radP1DDC4ADC1.Checked = false;
            if (needsRecovering(recoveryList, "radP1DDC4ADC2")) radP1DDC4ADC2.Checked = false;

            if (needsRecovering(recoveryList, "radP1DDC5ADC0")) radP1DDC5ADC0.Checked = true;
            if (needsRecovering(recoveryList, "radP1DDC5ADC1")) radP1DDC5ADC1.Checked = false;
            if (needsRecovering(recoveryList, "radP1DDC5ADC2")) radP1DDC5ADC2.Checked = false;

            if (needsRecovering(recoveryList, "radP1DDC6ADC0")) radP1DDC6ADC0.Checked = true;
            if (needsRecovering(recoveryList, "radP1DDC6ADC1")) radP1DDC6ADC1.Checked = false;
            if (needsRecovering(recoveryList, "radP1DDC6ADC2")) radP1DDC6ADC2.Checked = false;
        }

        public void InitAudioTab(List<string> recoveryList = null)
        {
            if (!comboAudioSampleRate1.Items.Contains(96000))
                comboAudioSampleRate1.Items.Add(96000);
            if (!comboAudioSampleRate1.Items.Contains(192000))
                comboAudioSampleRate1.Items.Add(192000);

            if (NetworkIO.CurrentRadioProtocol == RadioProtocol.ETH)
            {
                if (!comboAudioSampleRate1.Items.Contains(384000))
                    comboAudioSampleRate1.Items.Add(384000);
                if (!comboAudioSampleRate1.Items.Contains(768000))
                    comboAudioSampleRate1.Items.Add(768000);
                if (!comboAudioSampleRate1.Items.Contains(1536000))
                    comboAudioSampleRate1.Items.Add(1536000);
            }
            else
            {
                if (comboAudioSampleRate1.Items.Contains(384000))
                    comboAudioSampleRate1.Items.Remove(384000);
                if (comboAudioSampleRate1.Items.Contains(768000))
                    comboAudioSampleRate1.Items.Remove(768000);
                if (comboAudioSampleRate1.Items.Contains(1536000))
                    comboAudioSampleRate1.Items.Remove(1536000);
            }

            if (needsRecovering(recoveryList, "comboAudioSampleRate1"))
            {
                if (comboAudioSampleRate1.SelectedIndex < 0)
                    comboAudioSampleRate1.Text = "192000";
            }

            if (!comboAudioSampleRateRX2.Items.Contains(96000))
                comboAudioSampleRateRX2.Items.Add(96000);
            if (!comboAudioSampleRateRX2.Items.Contains(192000))
                comboAudioSampleRateRX2.Items.Add(192000);

            if (NetworkIO.CurrentRadioProtocol == RadioProtocol.ETH)
            {
                if (!comboAudioSampleRateRX2.Items.Contains(384000))
                    comboAudioSampleRateRX2.Items.Add(384000);
                if (!comboAudioSampleRateRX2.Items.Contains(768000))
                    comboAudioSampleRateRX2.Items.Add(768000);
                if (!comboAudioSampleRateRX2.Items.Contains(1536000))
                    comboAudioSampleRateRX2.Items.Add(1536000);
            }
            else
            {
                if (comboAudioSampleRateRX2.Items.Contains(384000))
                    comboAudioSampleRateRX2.Items.Remove(384000);
                if (comboAudioSampleRateRX2.Items.Contains(768000))
                    comboAudioSampleRateRX2.Items.Remove(768000);
                if (comboAudioSampleRateRX2.Items.Contains(1536000))
                    comboAudioSampleRateRX2.Items.Remove(1536000);
            }

            if (needsRecovering(recoveryList, "comboAudioSampleRateRX2"))
            {
                if (comboAudioSampleRateRX2.SelectedIndex < 0)
                    comboAudioSampleRateRX2.Text = "192000";
            }
        }

        private void InitAdvancedAudioTab(List<string> recoveryList = null)
        {
            //MW0LGE_21j // mirrors btnVAC1AdvancedDefault and btnVAC2AdvancedDefault
            if (needsRecovering(recoveryList, "udVAC1FeedbackGainIn")) udVAC1FeedbackGainIn.Value = (decimal)4.0e-6;
            if (needsRecovering(recoveryList, "udVAC1SlewTimeIn")) udVAC1SlewTimeIn.Value = (decimal)0.003;
            if (needsRecovering(recoveryList, "udVAC1PropMinIn")) udVAC1PropMinIn.Value = 4096;
            if (needsRecovering(recoveryList, "udVAC1PropMaxIn")) udVAC1PropMaxIn.Value = 16384;
            if (needsRecovering(recoveryList, "udVAC1FFMinIn")) udVAC1FFMinIn.Value = 4096;
            if (needsRecovering(recoveryList, "udVAC1FFMaxIn")) udVAC1FFMaxIn.Value = 262144;
            if (needsRecovering(recoveryList, "udVAC1FFAlphaIn")) udVAC1FFAlphaIn.Value = (decimal)0.01;
            if (needsRecovering(recoveryList, "chkVAC1OldVarIn")) chkVAC1OldVarIn.Checked = false;
            if (needsRecovering(recoveryList, "udVAC1FeedbackGainOut")) udVAC1FeedbackGainOut.Value = (decimal)4.0e-6;
            if (needsRecovering(recoveryList, "udVAC1SlewTimeOut")) udVAC1SlewTimeOut.Value = (decimal)0.003;
            if (needsRecovering(recoveryList, "udVAC1PropMinOut")) udVAC1PropMinOut.Value = 4096;
            if (needsRecovering(recoveryList, "udVAC1PropMaxOut")) udVAC1PropMaxOut.Value = 16384;
            if (needsRecovering(recoveryList, "udVAC1FFMinOut")) udVAC1FFMinOut.Value = 4096;
            if (needsRecovering(recoveryList, "udVAC1FFMaxOut")) udVAC1FFMaxOut.Value = 262144;
            if (needsRecovering(recoveryList, "udVAC1FFAlphaOut")) udVAC1FFAlphaOut.Value = (decimal)0.01;
            if (needsRecovering(recoveryList, "chkVAC1OldVarOut")) chkVAC1OldVarOut.Checked = false;
            //
            if (needsRecovering(recoveryList, "udVAC2FeedbackGainIn")) udVAC2FeedbackGainIn.Value = (decimal)4.0e-6;
            if (needsRecovering(recoveryList, "udVAC2SlewTimeIn")) udVAC2SlewTimeIn.Value = (decimal)0.003;
            if (needsRecovering(recoveryList, "udVAC2PropMinIn")) udVAC2PropMinIn.Value = 4096;
            if (needsRecovering(recoveryList, "udVAC2PropMaxIn")) udVAC2PropMaxIn.Value = 16384;
            if (needsRecovering(recoveryList, "udVAC2FFMinIn")) udVAC2FFMinIn.Value = 4096;
            if (needsRecovering(recoveryList, "udVAC2FFMaxIn")) udVAC2FFMaxIn.Value = 262144;
            if (needsRecovering(recoveryList, "udVAC2FFAlphaIn")) udVAC2FFAlphaIn.Value = (decimal)0.01;
            if (needsRecovering(recoveryList, "chkVAC2OldVarIn")) chkVAC2OldVarIn.Checked = false;
            if (needsRecovering(recoveryList, "udVAC2FeedbackGainOut")) udVAC2FeedbackGainOut.Value = (decimal)4.0e-6;
            if (needsRecovering(recoveryList, "udVAC2SlewTimeOut")) udVAC2SlewTimeOut.Value = (decimal)0.003;
            if (needsRecovering(recoveryList, "udVAC2PropMinOut")) udVAC2PropMinOut.Value = 4096;
            if (needsRecovering(recoveryList, "udVAC2PropMaxOut")) udVAC2PropMaxOut.Value = 16384;
            if (needsRecovering(recoveryList, "udVAC2FFMinOut")) udVAC2FFMinOut.Value = 4096;
            if (needsRecovering(recoveryList, "udVAC2FFMaxOut")) udVAC2FFMaxOut.Value = 262144;
            if (needsRecovering(recoveryList, "udVAC2FFAlphaOut")) udVAC2FFAlphaOut.Value = (decimal)0.01;
            if (needsRecovering(recoveryList, "chkVAC2OldVarOut")) chkVAC2OldVarOut.Checked = false;
            //
        }

        private void InitDisplayTab(List<string> recoveryList = null)
        {
            if (needsRecovering(recoveryList, "udDisplayGridMax")) udDisplayGridMax.Value = Display.SpectrumGridMax;
            if (needsRecovering(recoveryList, "udDisplayGridMin")) udDisplayGridMin.Value = Display.SpectrumGridMin;
            if (needsRecovering(recoveryList, "udDisplayGridStep")) udDisplayGridStep.Value = Display.SpectrumGridStep;
            if (needsRecovering(recoveryList, "udRX2DisplayGridMax")) udRX2DisplayGridMax.Value = Display.RX2SpectrumGridMax;
            if (needsRecovering(recoveryList, "udRX2DisplayGridMin")) udRX2DisplayGridMin.Value = Display.RX2SpectrumGridMin;
            if (needsRecovering(recoveryList, "udRX2DisplayGridStep")) udRX2DisplayGridStep.Value = Display.RX2SpectrumGridStep;
            if (needsRecovering(recoveryList, "udDisplayFPS")) udDisplayFPS.Value = console.DisplayFPS;
            if (needsRecovering(recoveryList, "clrbtnWaterfallLow")) clrbtnWaterfallLow.Color = Display.WaterfallLowColor;
            if (needsRecovering(recoveryList, "clrbtnRX2WaterfallLow")) clrbtnRX2WaterfallLow.Color = Display.RX2WaterfallLowColor;
            if (needsRecovering(recoveryList, "udDisplayWaterfallLowLevel")) udDisplayWaterfallLowLevel.Value = (decimal)Display.WaterfallLowThreshold;
            if (needsRecovering(recoveryList, "udDisplayWaterfallHighLevel")) udDisplayWaterfallHighLevel.Value = (decimal)Display.WaterfallHighThreshold;
            if (needsRecovering(recoveryList, "udRX2DisplayWaterfallLowLevel")) udRX2DisplayWaterfallLowLevel.Value = (decimal)Display.RX2WaterfallLowThreshold;
            if (needsRecovering(recoveryList, "udRX2DisplayWaterfallHighLevel")) udRX2DisplayWaterfallHighLevel.Value = (decimal)Display.RX2WaterfallHighThreshold;
            if (needsRecovering(recoveryList, "udDisplayMeterDelay")) udDisplayMeterDelay.Value = console.MeterDelay;
            if (needsRecovering(recoveryList, "udDisplayPeakText")) udDisplayPeakText.Value = console.PeakTextDelay;
            if (needsRecovering(recoveryList, "udDisplayCPUMeter")) udDisplayCPUMeter.Value = console.CPUMeterDelay;
            if (needsRecovering(recoveryList, "udDisplayPhasePts")) udDisplayPhasePts.Value = Display.PhaseNumPts;
            if (needsRecovering(recoveryList, "udDisplayMultiPeakHoldTime")) udDisplayMultiPeakHoldTime.Value = console.MultimeterPeakHoldTime;
            if (needsRecovering(recoveryList, "udDisplayMultiTextHoldTime")) udDisplayMultiTextHoldTime.Value = console.MultimeterTextPeakTime;
            if (needsRecovering(recoveryList, "udTXGridMax")) udTXGridMax.Value = Display.TXSpectrumGridMax;
            if (needsRecovering(recoveryList, "udTXGridMin")) udTXGridMin.Value = Display.TXSpectrumGridMin;
            if (needsRecovering(recoveryList, "udTXGridStep")) udTXGridStep.Value = Display.TXSpectrumGridStep;
            if (needsRecovering(recoveryList, "udTXWFAmpMax")) udTXWFAmpMax.Value = Display.TXWFAmpMax;
            if (needsRecovering(recoveryList, "udTXWFAmpMin")) udTXWFAmpMin.Value = Display.TXWFAmpMin;

            // MW0LGE in the case where we don't have a setting in the db, this function (initdisplaytab) is called, use console instead
            SetMultiMeterMode(console.MMMeasureMode);

            if (needsRecovering(recoveryList, "comboDisplayThreadPriority")) comboDisplayThreadPriority.SelectedIndex = (int)console.DisplayThreadPriority; // MW0LGE

            if (needsRecovering(recoveryList, "lgLinearGradientRX1"))
            {
                lgLinearGradientRX1.Text = s_DEFAULT_GRADIENT;
                lgLinearGradientRX1.HighlightFirstGripper();
            }
        }

        public void SetMultiMeterMode(MultiMeterMeasureMode mode)
        {
            switch (mode)
            {
                case MultiMeterMeasureMode.SMeter:
                    radSReading.Checked = true;
                    break;
                case MultiMeterMeasureMode.DBM:
                    radDBM.Checked = true;
                    break;
                case MultiMeterMeasureMode.UV:
                    radUV.Checked = true;
                    break;
            }
        }

        private void InitDSPTab(List<string> recoveryList = null)
        {
            if (needsRecovering(recoveryList, "udDSPCWPitch")) udDSPCWPitch.Value = console.CWPitch;
        }

        private void InitKeyboardTab(List<string> recoveryList = null)
        {
            // set tune keys
            if (needsRecovering(recoveryList, "comboKBTuneUp1")) comboKBTuneUp1.Text = KeyToString(console.KeyTuneUp1);
            if (needsRecovering(recoveryList, "comboKBTuneUp2")) comboKBTuneUp2.Text = KeyToString(console.KeyTuneUp2);
            if (needsRecovering(recoveryList, "comboKBTuneUp3")) comboKBTuneUp3.Text = KeyToString(console.KeyTuneUp3);
            if (needsRecovering(recoveryList, "comboKBTuneUp4")) comboKBTuneUp4.Text = KeyToString(console.KeyTuneUp4);
            if (needsRecovering(recoveryList, "comboKBTuneUp5")) comboKBTuneUp5.Text = KeyToString(console.KeyTuneUp5);
            if (needsRecovering(recoveryList, "comboKBTuneUp6")) comboKBTuneUp6.Text = KeyToString(console.KeyTuneUp6);
            if (needsRecovering(recoveryList, "comboKBTuneUp7")) comboKBTuneUp7.Text = KeyToString(console.KeyTuneUp7);
            if (needsRecovering(recoveryList, "comboKBTuneDown1")) comboKBTuneDown1.Text = KeyToString(console.KeyTuneDown1);
            if (needsRecovering(recoveryList, "comboKBTuneDown2")) comboKBTuneDown2.Text = KeyToString(console.KeyTuneDown2);
            if (needsRecovering(recoveryList, "comboKBTuneDown3")) comboKBTuneDown3.Text = KeyToString(console.KeyTuneDown3);
            if (needsRecovering(recoveryList, "comboKBTuneDown4")) comboKBTuneDown4.Text = KeyToString(console.KeyTuneDown4);
            if (needsRecovering(recoveryList, "comboKBTuneDown5")) comboKBTuneDown5.Text = KeyToString(console.KeyTuneDown5);
            if (needsRecovering(recoveryList, "comboKBTuneDown6")) comboKBTuneDown6.Text = KeyToString(console.KeyTuneDown6);
            if (needsRecovering(recoveryList, "comboKBTuneDown7")) comboKBTuneDown7.Text = KeyToString(console.KeyTuneDown7);

            // set band keys
            if (needsRecovering(recoveryList, "comboKBBandDown")) comboKBBandDown.Text = KeyToString(console.KeyBandDown);
            if (needsRecovering(recoveryList, "comboKBBandUp")) comboKBBandUp.Text = KeyToString(console.KeyBandUp);

            // set filter keys
            if (needsRecovering(recoveryList, "comboKBFilterDown")) comboKBFilterDown.Text = KeyToString(console.KeyFilterDown);
            if (needsRecovering(recoveryList, "comboKBFilterUp")) comboKBFilterUp.Text = KeyToString(console.KeyFilterUp);

            // set mode keys
            if (needsRecovering(recoveryList, "comboKBModeDown")) comboKBModeDown.Text = KeyToString(console.KeyModeDown);
            if (needsRecovering(recoveryList, "comboKBModeUp")) comboKBModeUp.Text = KeyToString(console.KeyModeUp);

            // set RIT keys
            if (needsRecovering(recoveryList, "comboKBRITDown")) comboKBRITDown.Text = KeyToString(console.KeyRITDown);
            if (needsRecovering(recoveryList, "comboKBRITUp")) comboKBRITUp.Text = KeyToString(console.KeyRITUp);

            // set XIT keys
            if (needsRecovering(recoveryList, "comboKBXITDown")) comboKBXITDown.Text = KeyToString(console.KeyXITDown);
            if (needsRecovering(recoveryList, "comboKBXITUp")) comboKBXITUp.Text = KeyToString(console.KeyXITUp);

            // set CW keys
            if (needsRecovering(recoveryList, "comboKBCWDot")) comboKBCWDot.Text = KeyToString(console.KeyCWDot);
            if (needsRecovering(recoveryList, "comboKBCWDash")) comboKBCWDash.Text = KeyToString(console.KeyCWDash);

            // set PTT keys
            if (needsRecovering(recoveryList, "comboKBPTTTx")) comboKBPTTTx.Text = KeyToString(console.KeyPTTTx);
            if (needsRecovering(recoveryList, "comboKBPTTRx")) comboKBPTTRx.Text = KeyToString(console.KeyPTTRx);
        }

        private void InitAppearanceTab(List<string> recoveryList = null)
        {
            if (needsRecovering(recoveryList, "clrbtnBackground")) clrbtnBackground.Color = Display.DisplayBackgroundColor;
            if (needsRecovering(recoveryList, "clrbtnGrid")) clrbtnGrid.Color = Display.GridColor;
            if (needsRecovering(recoveryList, "clrbtnGridFine")) clrbtnGridFine.Color = Display.GridPenDark;
            if (needsRecovering(recoveryList, "clrbtnHGridColor")) clrbtnHGridColor.Color = Display.HGridColor;
            if (needsRecovering(recoveryList, "clrbtnZeroLine")) clrbtnZeroLine.Color = Display.GridZeroColor;
            if (needsRecovering(recoveryList, "clrbtnText")) clrbtnText.Color = Display.GridTextColor;
            if (needsRecovering(recoveryList, "clrbtnDataLine")) clrbtnDataLine.Color = Display.DataLineColor;
            if (needsRecovering(recoveryList, "clrbtnDataFill")) clrbtnDataFill.Color = Display.DataFillColor;  //MW0LGE
            if (needsRecovering(recoveryList, "chkDisablePicDisplayBackgroundImage")) chkDisablePicDisplayBackgroundImage.Checked = console.DisableBackgroundImage;  //MW0LGE
            if (needsRecovering(recoveryList, "chkShowRXFilterOnWaterfall")) chkShowRXFilterOnWaterfall.Checked = Display.ShowRXFilterOnWaterfall; //MW0LGE
            if (needsRecovering(recoveryList, "chkShowTXFilterOnWaterfall")) chkShowTXFilterOnWaterfall.Checked = Display.ShowTXFilterOnWaterfall; //MW0LGE
            if (needsRecovering(recoveryList, "chkShowRXZeroLineOnWaterfall")) chkShowRXZeroLineOnWaterfall.Checked = Display.ShowRXZeroLineOnWaterfall; //MW0LGE
            if (needsRecovering(recoveryList, "chkShowTXZeroLineOnWaterfall")) chkShowTXZeroLineOnWaterfall.Checked = Display.ShowTXZeroLineOnWaterfall; //MW0LGE
            if (needsRecovering(recoveryList, "chkShowTXFilterOnRXWaterfall")) chkShowTXFilterOnRXWaterfall.Checked = Display.ShowTXFilterOnRXWaterfall; //MW0LGE
            if (needsRecovering(recoveryList, "clrbtnFilter")) clrbtnFilter.Color = Display.DisplayFilterColor;
            if (needsRecovering(recoveryList, "clrbtnMeterLeft")) clrbtnMeterLeft.Color = console.MeterLeftColor;
            if (needsRecovering(recoveryList, "clrbtnMeterRight")) clrbtnMeterRight.Color = console.MeterRightColor;
            if (needsRecovering(recoveryList, "clrbtnBtnSel")) clrbtnBtnSel.Color = console.ButtonSelectedColor;
            if (needsRecovering(recoveryList, "clrbtnVFODark")) clrbtnVFODark.Color = console.VFOTextDarkColor;
            if (needsRecovering(recoveryList, "clrbtnVFOLight")) clrbtnVFOLight.Color = console.VFOTextLightColor;
            if (needsRecovering(recoveryList, "clrbtnBandDark")) clrbtnBandDark.Color = console.BandTextDarkColor;
            if (needsRecovering(recoveryList, "clrbtnBandLight")) clrbtnBandLight.Color = console.BandTextLightColor;
            if (needsRecovering(recoveryList, "clrbtnPeakText")) clrbtnPeakText.Color = console.PeakTextColor;
            if (needsRecovering(recoveryList, "clrbtnOutOfBand")) clrbtnOutOfBand.Color = console.OutOfBandColor;
        }

        #endregion

        #region Misc Routines
        // ======================================================
        // Misc Routines
        // ======================================================

        public void PerformDelayedInitalistion()
        {
            EventArgs e = EventArgs.Empty;

            chkDisable6mLNAonTX_CheckedChanged(this, e);
            chkDisable6mLNAonRX_CheckedChanged(this, e);
            chkDisableHPFonTX_CheckedChanged(this, e);
            chkDisableHPFonPS_CheckedChanged(this, e);

            chkLPFBypass_CheckedChanged(this, e);

            chkAlex1_5BPHPF_CheckedChanged(this, e);
            chkAlex6_5BPHPF_CheckedChanged(this, e);
            chkAlex9_5BPHPF_CheckedChanged(this, e);
            chkAlex13BPHPF_CheckedChanged(this, e);
            chkAlex20BPHPF_CheckedChanged(this, e);
            chkAlex6BPHPF_CheckedChanged(this, e);
            chkAlex21_5BPHPF_CheckedChanged(this, e);
            chkAlex26_5BPHPF_CheckedChanged(this, e);
            chkAlex29_5BPHPF_CheckedChanged(this, e);
            chkAlex213BPHPF_CheckedChanged(this, e);
            chkAlex220BPHPF_CheckedChanged(this, e);
            chkAlex26BPHPF_CheckedChanged(this, e);

            chkATTOnTX_CheckedChanged(this, e); //MW0LGE [2.10.3.6]

            //MW0LGE_21h to make G8NJJ_21h change in each function work
            chkBlockTxAnt2_CheckedChanged(this, e);
            chkBlockTxAnt3_CheckedChanged(this, e);
            //

            chkWaterfallUseRX1SpectrumMinMax_CheckedChanged(this, e);
            chkWaterfallUseRX2SpectrumMinMax_CheckedChanged(this, e);

            //MW0LGE [2.9.0.7]
            updateMeter2Controls();
        }

        private void RefreshCOMPortLists()
        {
            string[] com_ports = SerialPort.GetPortNames();

            comboKeyerConnPrimary.Items.Clear();
            comboKeyerConnPrimary.Items.Add("Radio");
            comboKeyerConnPrimary.Items.Add("None");
            comboKeyerConnPrimary.Items.AddRange(com_ports);

            comboKeyerConnSecondary.Items.Clear();
            comboKeyerConnSecondary.Items.Add("None");
            comboKeyerConnSecondary.Items.Add("CAT");
            comboKeyerConnSecondary.Items.AddRange(com_ports);

            comboCATPort.Items.Clear();
            comboCATPort.Items.Add("None");
            comboCATPort.Items.AddRange(com_ports);

            comboCAT2Port.Items.Clear();
            comboCAT2Port.Items.Add("None");
            comboCAT2Port.Items.AddRange(com_ports);

            comboCAT3Port.Items.Clear();
            comboCAT3Port.Items.Add("None");
            comboCAT3Port.Items.AddRange(com_ports);

            comboCAT4Port.Items.Clear();
            comboCAT4Port.Items.Add("None");
            comboCAT4Port.Items.AddRange(com_ports);

            comboCATPTTPort.Items.Clear();
            comboCATPTTPort.Items.Add("None");
            comboCATPTTPort.Items.Add("CAT");
            comboCATPTTPort.Items.AddRange(com_ports);

            comboAndromedaCATPort.Items.Clear();
            comboAndromedaCATPort.Items.Add("None");
            comboAndromedaCATPort.Items.AddRange(com_ports);

            comboAriesCATPort.Items.Clear();
            comboAriesCATPort.Items.Add("None");
            comboAriesCATPort.Items.AddRange(com_ports);

            comboGanymedeCATPort.Items.Clear();
            comboGanymedeCATPort.Items.Add("None");
            comboGanymedeCATPort.Items.AddRange(com_ports);
        }
        private string _skinPath = "";
        private void RefreshSkinList()
        {
            comboAppSkin.Items.Clear();
            btnRemoveSkin.Enabled = false;

            string path = ".\\Skins\\";
            if (Directory.Exists(path))
                path = ".\\Skins\\";
            else
                path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
                    "\\OpenHPSDR\\Skins";
            _skinPath = path;

            if (!Directory.Exists(path))
            {
                MessageBox.Show("The console presentation files (skins) were not found.\n" +
                    "Appearance will suffer until this is rectified.\n",
                    "Skins files not found",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST); //MW0LGE_[2.9.0.7]);
                return;
            }

            foreach (string d in Directory.GetDirectories(path))
            {
                string s = d.Substring(d.LastIndexOf("\\") + 1);
                if (!s.StartsWith("."))
                    comboAppSkin.Items.Add(d.Substring(d.LastIndexOf("\\") + 1));
            }

            btnRemoveSkin.Enabled = comboAppSkin.Items.Count > 1;

            if (comboAppSkin.Items.Count == 0)
            {
                MessageBox.Show("The console presentation files (skins) were not found.\n" +
                    "Appearance will suffer until this is rectified.\n",
                    "Skins files not found",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST); //MW0LGE_[2.9.0.7]);
                return;
            }
        }
        private void selectSkin()
        {
            string skin = comboAppSkin.Text;

            if (skin == "")
            {
                if (comboAppSkin.Items.Contains("IK3VIG Special"))
                    comboAppSkin.Text = "IK3VIG Special";
                else
                    comboAppSkin.Text = "OpenHPSDR-Gray";
            }
            else if (comboAppSkin.Items.Contains(skin))
                comboAppSkin.Text = skin;
            else comboAppSkin.Text = "IK3VIG Special";
        }

        private void GetHosts()
        {
            comboAudioDriver2.Items.Clear();
            comboAudioDriver3.Items.Clear();
            int host_index = 0;
            foreach (string PAHostName in Audio.GetPAHosts())
            {
                if (Audio.GetPAInputDevices(host_index).Count > 0 ||
                    Audio.GetPAOutputDevices(host_index).Count > 0)
                {
                    comboAudioDriver2.Items.Add(new PADeviceInfo(PAHostName, host_index));
                    comboAudioDriver3.Items.Add(new PADeviceInfo(PAHostName, host_index));
                }
                host_index++; //Increment host index
            }
        }

        private void GetDevices2()
        {
            comboAudioInput2.Items.Clear();
            comboAudioOutput2.Items.Clear();
            int host = ((PADeviceInfo)comboAudioDriver2.SelectedItem).Index;
            ArrayList a = Audio.GetPAInputDevices(host);
            foreach (PADeviceInfo p in a)
                comboAudioInput2.Items.Add(p);

            a = Audio.GetPAOutputDevices(host);
            foreach (PADeviceInfo p in a)
                comboAudioOutput2.Items.Add(p);
        }

        private void GetDevices3()
        {
            comboAudioInput3.Items.Clear();
            comboAudioOutput3.Items.Clear();
            int host = ((PADeviceInfo)comboAudioDriver3.SelectedItem).Index;
            ArrayList a = Audio.GetPAInputDevices(host);
            foreach (PADeviceInfo p in a)
                comboAudioInput3.Items.Add(p);

            a = Audio.GetPAOutputDevices(host);
            foreach (PADeviceInfo p in a)
                comboAudioOutput3.Items.Add(p);
        }

        private void getControlList(Control c, ref Dictionary<string, Control> a)
        {
            if (c.Controls.Count > 0)
            {
                foreach (Control c2 in c.Controls)
                    getControlList(c2, ref a);
            }

            if (c.GetType() == typeof(CheckBoxTS) || c.GetType() == typeof(CheckBox) ||
                c.GetType() == typeof(ComboBoxTS) || c.GetType() == typeof(ComboBox) ||
                c.GetType() == typeof(NumericUpDownTS) || c.GetType() == typeof(NumericUpDown) ||
                c.GetType() == typeof(RadioButtonTS) || c.GetType() == typeof(RadioButton) ||
                c.GetType() == typeof(TextBoxTS) || c.GetType() == typeof(TextBox) ||
                c.GetType() == typeof(TrackBarTS) || c.GetType() == typeof(TrackBar) ||
                c.GetType() == typeof(ColorButton) ||
                c.GetType() == typeof(ucLGPicker))
                a.Add(c.Name, c);
        }

        //MW0LGE_21d
        // new code for selective cancel
        public new void Show()
        {
            if (!m_bShown)
            {
                // always clear them when showing, they will re-appear if needed
                lblTXProfileWarning.Visible = false;
                txtboxTXProfileChangedReport.Visible = false;
            }

            // shadow method to always clear the list if someone somewhere shows the form
            // this may not be 100%, but best effort, we only want to do this if we come from a 'hidden' state
            if (!m_bShown) clearUpdatedClickControlList();

            if (!m_bShown && isSkinServerTabVisible(false))
                getSkinServers();

            m_bShown = true;

            if (this.WindowState != FormWindowState.Normal) this.WindowState = FormWindowState.Normal; //MW0LGE_21i

            base.Show();
        }
        public new void Hide()
        {
            // shadow method to unset m_bShown when .Hide called from anywhere
            m_bShown = false;

            chkContainerHighlight.Checked = false; // no point highlighting when setup closed

            hideAllSkinServerRelatedControls();
            ThetisSkinService.CancelDownload();

            base.Hide();
        }
        // shadow property to unset m_bShown when .Visible called from anywhere
        public new bool Visible
        {
            get { return base.Visible; }
            set
            {
                m_bShown = value;
                base.Visible = value;
            }
        }

        private bool inBothUpdateAndClick(string s)
        {
            return (m_lstUpdatedControls.Contains(s) && m_lstClickedControls.Contains(s));
        }
        private bool inUpdateOnly(string s)
        {
            return (m_lstUpdatedControls.Contains(s) && !m_lstClickedControls.Contains(s));
        }
        private bool inClickOnly(string s)
        {
            return (!m_lstClickedControls.Contains(s) && m_lstClickedControls.Contains(s));
        }
        private void removeSpecialCases()
        {
            // this will remove all special cases from m_lstUpdatedControls if there have been no associated click event for the control
            // without a click we know that we didn't do it through setup
            // we cant just use this globally, because setup changes can cause a number of other control in setup to change
            // which would not have the associated click

            List<string> toRemove = new List<string>();

            toRemove.Add("udDisplayGridMax");
            toRemove.Add("udDisplayGridMin");
            toRemove.Add("udRX2DisplayGridMax");
            toRemove.Add("udRX2DisplayGridMin");

            foreach (string sControlName in toRemove)
            {
                if (inUpdateOnly(sControlName)) m_lstUpdatedControls.Remove(sControlName);
            }

            // also remove any that make no sense to track/update MW0LGE_21j
            toRemove.Clear();

            toRemove.Add("txtVAC1OldVarIn");
            toRemove.Add("txtVAC1OldVarOut");
            toRemove.Add("txtVAC2OldVarIn");
            toRemove.Add("txtVAC2OldVarOut");

            // multimeter
            foreach (Control c in grpMultiMeterHolder.Controls)
            {
                toRemove.Add(c.Name);
            }
            foreach (Control c in grpMeterItemSettings.Controls)
            {
                toRemove.Add(c.Name);
            }
            foreach (Control c in grpMeterItemClockSettings.Controls)
            {
                toRemove.Add(c.Name);
            }
            foreach (Control c in grpMeterItemVfoDisplaySettings.Controls)
            {
                toRemove.Add(c.Name);
            }
            //

            // multimeter io // fixes #485
            foreach (Control c in pnlMMIO_network_container.Controls)
            {
                toRemove.Add(c.Name);
            }
            //

            foreach (string sControlName in toRemove)
            {
                if (m_lstUpdatedControls.Contains(sControlName)) m_lstUpdatedControls.Remove(sControlName);
            }
        }
        private bool needsRecovering(List<string> recoveryList, string s)
        {
            return (recoveryList == null || recoveryList.Contains(s));
        }
        private void listClickedControls()
        {
            foreach (string s in m_lstClickedControls)
            {
                Debug.Print("CONTROL CLICKED -> " + s);
            }
        }
        private void listUpdatedControls()
        {
            foreach (string s in m_lstUpdatedControls)
            {
                Debug.Print("CONTROL UPDATED -> " + s);
            }
        }
        private void clearUpdatedClickControlList()
        {
            m_lstClickedControls.Clear();
            m_lstUpdatedControls.Clear();
        }
        private void everyControlClickHandler(object sender, EventArgs e)
        {
            if (initializing) return;
            string sName = ((Control)sender).Name;
            if (!m_lstClickedControls.Contains(sName)) m_lstClickedControls.Add(sName);
        }
        private void checkBoxCheckedChangeHandler(object sender, EventArgs e)
        {
            //[2.6.10.3]MW0LGE this had been removed, and was spotted after I diffed older version. I put it here to keep a record
            //of which check controls had been clicked. This is so that cancel works.
            if (initializing) return;
            string sName = ((Control)sender).Name;
            if (!m_lstUpdatedControls.Contains(sName)) m_lstUpdatedControls.Add(sName);
        }
        private void comboboxSelectedIndexChangeHandler(object sender, EventArgs e)
        {
            if (initializing) return;
            string sName = ((Control)sender).Name;
            if (!m_lstUpdatedControls.Contains(sName)) m_lstUpdatedControls.Add(sName);
        }
        private void numericUDValueChangeHandler(object sender, EventArgs e)
        {
            if (initializing) return;
            string sName = ((Control)sender).Name;
            if (!m_lstUpdatedControls.Contains(sName)) m_lstUpdatedControls.Add(sName);
        }
        private void radioButtonCheckedChangeHandler(object sender, EventArgs e)
        {
            if (initializing) return;
            string sName = ((Control)sender).Name;
            if (!m_lstUpdatedControls.Contains(sName)) m_lstUpdatedControls.Add(sName);
        }
        private void textBoxTextChangeHandler(object sender, EventArgs e)
        {
            if (initializing) return;
            string sName = ((Control)sender).Name;
            if (!m_lstUpdatedControls.Contains(sName)) m_lstUpdatedControls.Add(sName);
        }
        private void trackBarValueChangeHandler(object sender, EventArgs e)
        {
            if (initializing) return;
            string sName = ((Control)sender).Name;
            if (!m_lstUpdatedControls.Contains(sName)) m_lstUpdatedControls.Add(sName);
        }
        private void colourButtonChangeHandler(object sender, EventArgs e)
        {
            if (initializing) return;
            string sName = ((Control)sender).Name;
            if (!m_lstUpdatedControls.Contains(sName)) m_lstUpdatedControls.Add(sName);
        }
        private void lgPickerChangeHandler(object sender, EventArgs e)
        {
            if (initializing) return;
            string sName = ((Control)sender).Name;
            if (!m_lstUpdatedControls.Contains(sName)) m_lstUpdatedControls.Add(sName);
        }
        private void registerAllControlsForStateMonitoring()
        {
            Dictionary<string, Control> controls = new Dictionary<string, Control>();

            getControlList(this, ref controls);

            foreach (KeyValuePair<string, Control> kvp in controls)
            {
                Control c = kvp.Value;

                c.Click += new System.EventHandler(everyControlClickHandler);

                if (c.GetType() == typeof(CheckBoxTS))
                    ((CheckBoxTS)c).CheckedChanged += new System.EventHandler(checkBoxCheckedChangeHandler);
                else if (c.GetType() == typeof(ComboBoxTS))
                    ((ComboBoxTS)c).SelectedIndexChanged += new System.EventHandler(comboboxSelectedIndexChangeHandler);
                else if (c.GetType() == typeof(NumericUpDownTS))
                    ((NumericUpDownTS)c).ValueChanged += new System.EventHandler(numericUDValueChangeHandler);
                else if (c.GetType() == typeof(RadioButtonTS))
                    ((RadioButtonTS)c).CheckedChanged += new System.EventHandler(radioButtonCheckedChangeHandler);
                else if (c.GetType() == typeof(TextBoxTS))
                    ((TextBoxTS)c).TextChanged += new System.EventHandler(textBoxTextChangeHandler);
                else if (c.GetType() == typeof(TrackBarTS))
                    ((TrackBarTS)c).ValueChanged += new System.EventHandler(trackBarValueChangeHandler);
                else if (c.GetType() == typeof(ColorButton))
                    ((ColorButton)c).Changed += new System.EventHandler(colourButtonChangeHandler);
                else if (c.GetType() == typeof(ucLGPicker))
                    ((ucLGPicker)c).Changed += new System.EventHandler(lgPickerChangeHandler);
            }
        }
        //-
        private bool _savingOptions = false;
        public void SaveOptions()
        {
            // Automatically saves all control settings to the database in the tab
            // pages on this form of the following types: CheckBoxTS, ComboBoxTS,
            // NumericUpDownTS, RadioButtonTS, TextBox, and TrackBar (slider)

            if (DB.Merged) return; // prevent saving options as we want to ignore everything

            _savingOptions = true;

            //MW0LGE_21a moved to dictionary to use same code as get options
            Dictionary<string, Control> controls = new Dictionary<string, Control>();

            getControlList(this, ref controls);

            // we need to save everything sorted
            // because on reload certain settings require a specific order
            // which is defined by the sorting order
            List<string> sortedList = controls.Keys.ToList();
            sortedList.Sort();

            //MW0LGE_21k8 converted to dictionary as everything will be unique
            Dictionary<string, string> a = new Dictionary<string, string>();

            foreach (string sKey in sortedList)
            {
                Control c = controls[sKey];

                if (c.GetType() == typeof(CheckBoxTS))
                    a.Add(c.Name, ((CheckBoxTS)c).Checked.ToString());
                else if (c.GetType() == typeof(ComboBoxTS))
                {
                    a.Add(c.Name, ((ComboBoxTS)c).Text);
                }
                else if (c.GetType() == typeof(NumericUpDownTS))
                    a.Add(c.Name, ((NumericUpDownTS)c).Value.ToString());
                else if (c.GetType() == typeof(RadioButtonTS))
                    a.Add(c.Name, ((RadioButtonTS)c).Checked.ToString());
                else if (c.GetType() == typeof(TextBoxTS))
                    a.Add(c.Name, ((TextBoxTS)c).Text);
                else if (c.GetType() == typeof(TrackBarTS))
                    a.Add(c.Name, ((TrackBarTS)c).Value.ToString());
                else if (c.GetType() == typeof(ColorButton))
                {
                    Color clr = ((ColorButton)c).Color;
                    a.Add(c.Name, clr.R + "." + clr.G + "." + clr.B + "." + clr.A);
                }
#if(DEBUG)
                else if (c.GetType() == typeof(GroupBox) ||
                    c.GetType() == typeof(CheckBox) ||
                    c.GetType() == typeof(ComboBox) ||
                    c.GetType() == typeof(NumericUpDown) ||
                    c.GetType() == typeof(RadioButton) ||
                    c.GetType() == typeof(TextBox) ||
                    c.GetType() == typeof(TrackBar))
                    Debug.WriteLine(this.Name + " -> " + c.Name + " needs to be converted to a Thread Safe control.");
#endif
            }

            // add this manually because the usbbcd combo box will need this to recover previously selected
            a.Add("UsbBCDSerialNumber", m_sUsbBCDSerialNumber);

            // add this manually because soundfile string not stored in any control in setup
            a.Add("QSOTimerFilenameWav", console.QSOTimerAudioPlayer.SoundFile);

            //a.Add("chkRadioProtocolSelect_checkstate", chkRadioProtocolSelect.CheckState.ToString()); //[2.10.3.5]MW0LGE not used anymore
            a.Add("lgLinearGradientRX1", lgLinearGradientRX1.Text);

            // store PA profiles
            if (_PAProfiles != null)
            {
                int nIndex = 0;
                a.Add("PAProfileCount", _PAProfiles.Count.ToString());
                foreach (KeyValuePair<string, PAProfile> kvp in _PAProfiles)
                {
                    string sData = kvp.Value.DataToString();
                    a.Add("PAProfile_" + nIndex.ToString(), sData);
                    nIndex++;
                }
            }
            //

            //
            DB.PurgeMeters(MeterManager.GetFormGuidList()); // clear the db of any meter info before we try to add it
            if (!MeterManager.StoreSettings2(ref a))
            {
                MessageBox.Show("There was an issue storing the settings for MultiMeter.", "MultiMeter StoreSettings",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST);
            }
            //
            a.Add("multimeter_io2", MultiMeterIO.GetSaveData());
            //

            // remove any outdated options from the DB MW0LGE_22b
            removeOutdatedOptions();

            DB.SaveVarsDictionary("Options", ref a, true);

            DB.WriteDB();

            _savingOptions = false;
        }

        private void InitTransmitTab(List<string> recoveryList = null)
        {
            if (needsRecovering(recoveryList, "comboTXTUNMeter")) comboTXTUNMeter.Text = "Fwd SWR"; // this needs to be setup in the case of new database and we havent hit tx/tune yet // MW0LGE_21a
        }
        private List<string> _oldSettings = new List<string>();
        private void handleOutdatedOptions(ref Dictionary<string, string> getDict)
        {
            _oldSettings.Clear();

            if (getDict.ContainsKey("chkTXTunePower"))
            {
                if (bool.Parse(getDict["chkTXTunePower"]))
                    radUseDriveSliderTune.Checked = true;
                else
                    radUseFixedDriveTune.Checked = true;
                _oldSettings.Add("chkTXTunePower");
            }
            if (getDict.ContainsKey("chkTestIMDPower"))
            {
                if (bool.Parse(getDict["chkTestIMDPower"]))
                    radUseDriveSlider2Tone.Checked = true;
                else
                    radUseFixedDrive2Tone.Checked = true;
                _oldSettings.Add("chkTestIMDPower");
            }
            if (getDict.ContainsKey("chkRadioProtocolSelect_checkstate")) //[2.10.3.5]MW0LGE this is no longer used
            {
                CheckState cs = (CheckState)(Enum.Parse(typeof(CheckState), getDict["chkRadioProtocolSelect_checkstate"]));

                switch (cs)
                {
                    case CheckState.Checked: // auto
                        radRadioProtocolAutoSelect.Checked = true;
                        break;
                    case CheckState.Indeterminate: // p1
                        radRadioProtocol1Select.Checked = true;
                        break;
                    case CheckState.Unchecked: // p2
                        radRadioProtocol2Select.Checked = true;
                        break;
                }

                _oldSettings.Add("chkRadioProtocolSelect_checkstate");
            }

            if (getDict.ContainsKey("multimeter_io"))
                _oldSettings.Add("multimeter_io");

            handleOldPAGainSettings(ref getDict);
        }
        private void removeOutdatedOptions()
        {
            if (_oldSettings == null || _oldSettings.Count == 0) return;

            // remove any old settings we dont use any more
            DB.RemoveVarsList("Options", _oldSettings);
            _oldSettings.Clear();
        }
        private void addToIgnore(ref List<string>controlNames, Control rootControl)
        {
            if(rootControl == null)return;

            if (!controlNames.Contains(rootControl.Name) && !string.IsNullOrEmpty(rootControl.Name))
            {
                controlNames.Add(rootControl.Name);
            }

            foreach(Control childControl in rootControl.Controls)
            {
                addToIgnore(ref controlNames,childControl);
            }
        }
        private bool _gettingOptions = false;
        private void getOptions(List<string> recoveryList = null)
        {
            _gettingOptions = true;
            //MW0LGE_21d
            //if a list of control names is provided, only those will be recovered from the database
            //mostly used when cancelling the setup form

            //MW0LGE moved to dictionary, as control names are unique, and does away with old loop through every control to find the one we want
            Dictionary<string, Control> controls = new Dictionary<string, Control>();

            getControlList(this, ref controls);

            //MW0LGE_21k8 converted to dictionary
            Dictionary<string, string> a = DB.GetVarsDictionary("Options");

            // deal with out dated settings //MW0LGE_22b
            // these will be removed in saveOptions
            handleOutdatedOptions(ref a);

            List<string> sortedList = a.Keys.ToList();
            sortedList.Sort();

            if (a.Count < controls.Count)		// some control values are not in the database
            {								// so set all of them to the defaults
                InitGeneralTab(recoveryList);
                InitAudioTab(recoveryList);
                InitAdvancedAudioTab(recoveryList);
                InitDSPTab(recoveryList);
                InitTransmitTab(recoveryList);
                InitDisplayTab(recoveryList);
                InitKeyboardTab(recoveryList);
                InitAppearanceTab(recoveryList);
                InitADC(recoveryList);
            }

            if (sortedList.Contains("comboPAProfile")) sortedList.Remove("comboPAProfile"); // this is done after the PA profiles are recovered // MW0LGE_22b

            // remove any that will be set by clicking on related item
            List<string> ignoreList = new List<string>();
            addToIgnore(ref ignoreList, tpMultiMetersIO);
            addToIgnore(ref ignoreList, tpAppearanceMeter2);
            addToIgnore(ref ignoreList, grpMultiMeterHolder);
            addToIgnore(ref ignoreList, pnlMMIO_network_container);

            addToIgnore(ref ignoreList, txtVAC1OldVarIn);
            addToIgnore(ref ignoreList, txtVAC1OldVarOut);
            addToIgnore(ref ignoreList, txtVAC2OldVarIn);
            addToIgnore(ref ignoreList, txtVAC2OldVarOut);

            addToIgnore(ref ignoreList, grpHistoryItem);
            addToIgnore(ref ignoreList, grpWebImage);
            addToIgnore(ref ignoreList, grpTextOverlay);
            addToIgnore(ref ignoreList, grpMeterItemClockSettings);
            addToIgnore(ref ignoreList, grpMeterItemSpacerSettings);
            addToIgnore(ref ignoreList, grpBandButtons);
            addToIgnore(ref ignoreList, ucTunestepOptionsGrid_buttons);
            addToIgnore(ref ignoreList, pnlButtonBox_antenna_toggles);
            addToIgnore(ref ignoreList, grpLedIndicator);
            addToIgnore(ref ignoreList, grpMeterItemDataOutNode);
            addToIgnore(ref ignoreList, grpMeterItemVfoDisplaySettings);
            addToIgnore(ref ignoreList, grpMeterItemRotator);
            addToIgnore(ref ignoreList, grpMeterItemSettings);

            addToIgnore(ref ignoreList, grpGainByBandPA);

            foreach (string key in ignoreList)
            {
                if(sortedList.Contains(key)) sortedList.Remove(key);
            }
            //

            foreach (string sKey in sortedList)
            {
                string name = sKey;
                string val = a[sKey];

                if (needsRecovering(recoveryList, name)) //MW0LGE_21d selective recovery
                {
                    if (controls.ContainsKey(name))
                    {
                        Control cc = controls[name];

                        if (cc.GetType() == typeof(CheckBoxTS))          // the control is a CheckBoxTS
                        {
                            CheckBoxTS c = (CheckBoxTS)cc;
                            c.Checked = bool.Parse(val);
                        }
                        else if (cc.GetType() == typeof(ComboBoxTS))     // the control is a ComboBoxTS
                        {
                            ComboBoxTS c = (ComboBoxTS)cc;
                            if (c.Items.Count > 0 && c.Items[0].GetType() == typeof(string))
                            {
                                c.Text = val;
                            }
                            else
                            {
                                foreach (object o in c.Items)
                                {
                                    if (o.ToString() == val)
                                        c.Text = val;   // restore value
                                }
                            }
                        }
                        else if (cc.GetType() == typeof(NumericUpDownTS))    // the control is a NumericUpDownTS
                        {
                            NumericUpDownTS c = (NumericUpDownTS)cc;
                            decimal num = decimal.Parse(val);

                            if (num > c.Maximum) num = c.Maximum;       // check endpoints
                            else if (num < c.Minimum) num = c.Minimum;
                            c.Value = num;          // restore value
                        }
                        else if (cc.GetType() == typeof(RadioButtonTS))  // the control is a RadioButtonTS
                        {
                            RadioButtonTS c = (RadioButtonTS)cc;
                            c.Checked = bool.Parse(val);    // restore value
                        }
                        else if (cc.GetType() == typeof(TextBoxTS))      // the control is a TextBox
                        {
                            TextBoxTS c = (TextBoxTS)cc;
                            c.Text = val;   // restore value
                        }
                        else if (cc.GetType() == typeof(TrackBarTS))     // the control is a TrackBar (slider)
                        {
                            TrackBarTS c = (TrackBarTS)cc;
                            c.Value = Int32.Parse(val);
                        }
                        else if (cc.GetType() == typeof(ColorButton))
                        {
                            string[] colors = val.Split('.');
                            if (colors.Length == 4)
                            {
                                int R, G, B, A;
                                R = Int32.Parse(colors[0]);
                                G = Int32.Parse(colors[1]);
                                B = Int32.Parse(colors[2]);
                                A = Int32.Parse(colors[3]);

                                ColorButton c = (ColorButton)cc;
                                c.Color = Color.FromArgb(A, R, G, B);
                                c.Automatic = "";
                            }
                        }
                        else if (name == "lgLinearGradientRX1")
                        {
                            lgLinearGradientRX1.Text = val;
                        }
                    }
                    else if (name == "UsbBCDSerialNumber") // [2.10.3.5]MW0LGE recover this as the usbbcd combo box will not have any entries at this point
                    {
                        m_sUsbBCDSerialNumber = val;
                    }
                    else if (name == "QSOTimerFilenameWav")
                    {
                        console.QSOTimerAudioPlayer.LoadSound(val);
                    }
                    else if (name.StartsWith("PAProfile_") || name == "PAProfileCount")
                    {
                        // ignore, done later
                    }
                    else if (name.StartsWith("meterContData_") ||
                        name.StartsWith("meterData_") ||
                        name.StartsWith("meterIGData_") ||
                        name.StartsWith("meterIGSettings_") ||
                        name.StartsWith("meterIGSettings_2_")) // need _2_ as the above will eventually be remoed from the db
                    {
                        // ignore, done later
                    }
                    else
                    {
                        Debug.WriteLine("Control not found: " + name);
                    }
                }
            }

            //MW0LGE_22b
            // get PA profiles, use dictionary directly and not the sorted list
            if (_PAProfiles != null && a.ContainsKey("PAProfileCount"))
            {
                int nProfiles = int.Parse(a["PAProfileCount"]);
                for (int n = 0; n < nProfiles; n++)
                {
                    string sDataKey = "PAProfile_" + n.ToString();
                    if (a.ContainsKey(sDataKey))
                    {
                        string sData = a[sDataKey];

                        PAProfile p = new PAProfile("", HPSDRModel.FIRST, false);
                        p.DataFromString(sData); // this will fully update p

                        if (_PAProfiles.ContainsKey(p.ProfileName)) _PAProfiles.Remove(p.ProfileName); // scrap any dupes, this will be true for defaults for example

                        _PAProfiles.Add(p.ProfileName, p);
                    }
                }
            }

            updatePAProfileCombo();

            if (a.ContainsKey("comboPAProfile"))
            {
                string sPAProfileName = a["comboPAProfile"];
                PAProfile p = getPAProfile(sPAProfileName);
                if (p != null)
                {
                    // check in list
                    bool bFound = false;
                    for (int n = 0; n < comboPAProfile.Items.Count; n++)
                    {
                        string s = (string)comboPAProfile.Items[n];
                        if (s == sPAProfileName)
                        {
                            bFound = true;
                            break;
                        }
                    }
                    if (bFound) comboPAProfile.Text = sPAProfileName;
                }
            }
            //

            //
            if (recoveryList == null) // MW0LGE [2.9.0.8] ignore if we hit cancel, not possible to undo multimeter changes at this time
            {
                bool ok = true;
                if (a.ContainsKey("multimeter_io2"))
                {
                    //try version2 first                    
                    try
                    {
                        ok = MultiMeterIO.RestoreSaveData2(a["multimeter_io2"]);
                    }
                    catch
                    {
                        ok = false;
                    }
                }
                else if (a.ContainsKey("multimeter_io"))
                {
                    try
                    {
                        ok = MultiMeterIO.RestoreSaveData(a["multimeter_io"]);
                    }
                    catch
                    {
                        ok = false;
                    }
                }
                if (!ok)
                {
                    MessageBox.Show("There was an issue restoring the settings for MultiMeterIO. Existing settings will be lost.", "MultiMeterIO RestoreSaveData",
                        MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST);
                }

                if (!MeterManager.RestoreSettings(ref a)) // pass this dictionary of settings to the meter manager to restore from
                {
                    MessageBox.Show("There was an issue restoring the settings for MultiMeter. Please remove all meters, re-add, and restart Thetis.", "MultiMeter RestoreSettings",
                        MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST);
                }
            }
            //

            //MW0LGE We have overwritten controls with data that might not match the current profile
            //load in current profile
            if (comboTXProfileName.SelectedIndex < 0 &&
                comboTXProfileName.Items.Count > 0)
                comboTXProfileName.SelectedIndex = 0;

            if (loadTXProfile(comboTXProfileName.Text)) current_profile = comboTXProfileName.Text;
            else current_profile = "";

            _gettingOptions = false;
        }

        private string KeyToString(Keys k)
        {
            if (!k.ToString().StartsWith("Oem"))
                return k.ToString();

            string s = "";
            switch (k)
            {
                case Keys.OemOpenBrackets:
                    s = "[";
                    break;
                case Keys.OemCloseBrackets:
                    s = "]";
                    break;
                case Keys.OemQuestion:
                    s = "/";
                    break;
                case Keys.OemPeriod:
                    s = ".";
                    break;
                case Keys.OemPipe:
                    s = (k & Keys.Shift) == 0 ? "\\" : "|";
                    break;
            }
            return s;
        }

        private void SetupKeyMap()
        {
            KeyList.Add(Keys.None);
            KeyList.Add(Keys.A);
            KeyList.Add(Keys.B);
            KeyList.Add(Keys.C);
            KeyList.Add(Keys.D);
            KeyList.Add(Keys.E);
            KeyList.Add(Keys.F);
            KeyList.Add(Keys.G);
            KeyList.Add(Keys.H);
            KeyList.Add(Keys.I);
            KeyList.Add(Keys.J);
            KeyList.Add(Keys.K);
            KeyList.Add(Keys.L);
            KeyList.Add(Keys.M);
            KeyList.Add(Keys.N);
            KeyList.Add(Keys.O);
            KeyList.Add(Keys.P);
            KeyList.Add(Keys.Q);
            KeyList.Add(Keys.R);
            KeyList.Add(Keys.S);
            KeyList.Add(Keys.T);
            KeyList.Add(Keys.U);
            KeyList.Add(Keys.V);
            KeyList.Add(Keys.W);
            KeyList.Add(Keys.X);
            KeyList.Add(Keys.Y);
            KeyList.Add(Keys.Z);
            KeyList.Add(Keys.F1);
            KeyList.Add(Keys.F2);
            KeyList.Add(Keys.F3);
            KeyList.Add(Keys.F4);
            KeyList.Add(Keys.F5);
            KeyList.Add(Keys.F6);
            KeyList.Add(Keys.F7);
            KeyList.Add(Keys.F8);
            KeyList.Add(Keys.F9);
            KeyList.Add(Keys.F10);
            KeyList.Add(Keys.Insert);
            KeyList.Add(Keys.Delete);
            KeyList.Add(Keys.Home);
            KeyList.Add(Keys.End);
            KeyList.Add(Keys.PageUp);
            KeyList.Add(Keys.PageDown);
            KeyList.Add(Keys.Up);
            KeyList.Add(Keys.Down);
            KeyList.Add(Keys.Left);
            KeyList.Add(Keys.Right);
            KeyList.Add(Keys.OemOpenBrackets);
            KeyList.Add(Keys.OemCloseBrackets);
            KeyList.Add(Keys.OemPeriod);
            KeyList.Add(Keys.OemQuestion);
            //			KeyList.Add(Keys.OemSemicolon);
            //			KeyList.Add(Keys.OemQuotes);
            //			KeyList.Add(Keys.Oemcomma);
            //			KeyList.Add(Keys.OemPeriod);
            //			KeyList.Add(Keys.OemBackslash);
            //			KeyList.Add(Keys.OemQuestion);
            //          KeyList.Add(Keys.Space);

            foreach (Control c in tpKeyboard.Controls)
            {
                if (c.GetType() == typeof(GroupBoxTS))
                {

                    foreach (Control c2 in c.Controls)
                    {
                        if (c2.GetType() != typeof(ComboBoxTS)) continue;
                        ComboBoxTS combo = (ComboBoxTS)c2;

                        combo.Items.Clear();
                        foreach (Keys k in KeyList)
                        {
                            if (!combo.Items.Contains(k.ToString()))
                                combo.Items.Add(k.ToString().StartsWith("Oem") ? KeyToString(k) : k.ToString());
                        }
                    }
                }
                else if (c.GetType() == typeof(ComboBoxTS))
                {
                    ComboBoxTS combo = (ComboBoxTS)c;
                    combo.Items.Clear();
                    foreach (Keys k in KeyList)
                    {
                        if (!combo.Items.Contains(k.ToString()))
                            combo.Items.Add(k.ToString());
                    }
                }
            }
        }

        public int CollapsedWidth
        {
            get { return int.Parse(txtCollapsedWidth.Text); }
            set
            {
                this.txtCollapsedWidth.Text = value.ToString();
            }
        }

        public int CollapsedHeight
        {
            get { return int.Parse(txtCollapsedHeight.Text); }
            set
            {
                this.txtCollapsedHeight.Text = value.ToString();
            }
        }

        private void ForceAllEvents()
        {
            EventArgs e = EventArgs.Empty;

            // General Tab
            comboRadioModel_SelectedIndexChanged(this, e);
            udGeneralLPTDelay_ValueChanged(this, e);
            chkGeneralRXOnly_CheckedChanged(this, e);
            comboGeneralXVTR_SelectedIndexChanged(this, e);
            chkGeneralDisablePTT_CheckedChanged(this, e);
            comboGeneralProcessPriority_SelectedIndexChanged(this, e);
            chkFullDiscovery_CheckedChanged(this, e);
            btnSetIPAddr_Click(this, e);
            radOrionPTTOff_CheckedChanged(this, e);
            radOrionMicTip_CheckedChanged(this, e);
            radOrionBiasOn_CheckedChanged(this, e);
            chkNetworkWDT_CheckedChanged(this, e);

            radRadioProtocolSelect_CheckedChanged(this, e);
            chkTuneStepPerModeRX1_CheckedChanged(this, e);
            chkCTUNignore0beat_CheckedChanged(this, e); //MW0LGE_21k9d

            //NAVigation-general
            ChkAlsoUseSpecificMouseWheel_CheckedChanged(this, e);
            chkClickTuneFilter_CheckedChanged(this, e);
            chkShowCTHLine_CheckedChanged(this, e);

            // Audio Tab
            comboAudioBuffer2_SelectedIndexChanged(this, e);
            comboAudioSampleRate1_SelectedIndexChanged(this, e);

            comboAudioSampleRate2_SelectedIndexChanged(this, e);
            comboAudioSampleRateRX2_SelectedIndexChanged(this, e);

            udAudioLatency2_ValueChanged(this, e);
            udAudioLatency2_Out_ValueChanged(this, e);
            udAudioLatencyPAIn_ValueChanged(this, e);
            udAudioLatencyPAOut_ValueChanged(this, e);
            udVAC2Latency_ValueChanged(this, e);
            udVAC2LatencyOut_ValueChanged(this, e);
            udVAC2LatencyPAIn_ValueChanged(this, e);
            udVAC2LatencyPAOut_ValueChanged(this, e);
            udAudioVACGainRX_ValueChanged(this, e);
            udVAC2GainRX_ValueChanged(this, e);
            udAudioVACGainTX_ValueChanged(this, e);
            udVAC2GainTX_ValueChanged(this, e);
            chkVAC2UseRX2_CheckedChanged(this, e);
            chkAudioRX2toVAC_CheckedChanged(this, e);
            chkAudioLatencyManual2_CheckedChanged(this, e);
            chkAudioLatencyManual2_Out_CheckedChanged(this, e);
            chkAudioLatencyPAInManual_CheckedChanged(this, e);
            chkAudioLatencyPAOutManual_CheckedChanged(this, e);
            chkVAC2LatencyManual_CheckedChanged(this, e);
            chkVAC2LatencyOutManual_CheckedChanged(this, e);
            chkVAC2LatencyPAInManual_CheckedChanged(this, e);
            chkVAC2LatencyPAOutManual_CheckedChanged(this, e);
            chkBypassVACPlayingRecording_CheckedChanged(this, e);
            // MW0LGE_21h
            udVAC1FeedbackGainIn_ValueChanged(this, e);
            udVAC1FeedbackGainOut_ValueChanged(this, e);
            udVAC1SlewTimeIn_ValueChanged(this, e);
            udVAC1SlewTimeOut_ValueChanged(this, e);
            udVAC2FeedbackGainIn_ValueChanged(this, e);
            udVAC2FeedbackGainOut_ValueChanged(this, e);
            udVAC2SlewTimeIn_ValueChanged(this, e);
            udVAC2SlewTimeOut_ValueChanged(this, e);
            // MW0LGE_21j
            udVAC1PropMinIn_ValueChanged(this, e);
            udVAC1PropMaxIn_ValueChanged(this, e);
            udVAC1FFMinIn_ValueChanged(this, e);
            udVAC1FFMaxIn_ValueChanged(this, e);
            udVAC1FFAlphaIn_ValueChanged(this, e);
            chkVAC1OldVarIn_CheckedChanged(this, e);
            udVAC1PropMinOut_ValueChanged(this, e);
            udVAC1PropMaxOut_ValueChanged(this, e);
            udVAC1FFMinOut_ValueChanged(this, e);
            udVAC1FFMaxOut_ValueChanged(this, e);
            udVAC1FFAlphaOut_ValueChanged(this, e);
            chkVAC1OldVarOut_CheckedChanged(this, e);

            udVAC2PropMinIn_ValueChanged(this, e);
            udVAC2PropMaxIn_ValueChanged(this, e);
            udVAC2FFMinIn_ValueChanged(this, e);
            udVAC2FFMaxIn_ValueChanged(this, e);
            udVAC2FFAlphaIn_ValueChanged(this, e);
            chkVAC2OldVarIn_CheckedChanged(this, e);
            udVAC2PropMinOut_ValueChanged(this, e);
            udVAC2PropMaxOut_ValueChanged(this, e);
            udVAC2FFMinOut_ValueChanged(this, e);
            udVAC2FFMaxOut_ValueChanged(this, e);
            udVAC2FFAlphaOut_ValueChanged(this, e);
            chkVAC2OldVarOut_CheckedChanged(this, e);

            txtVAC1OldVarIn_TextChanged(this, e);
            txtVAC1OldVarOut_TextChanged(this, e);
            txtVAC2OldVarIn_TextChanged(this, e);
            txtVAC2OldVarOut_TextChanged(this, e);

            chkVAC1WillMute_CheckedChanged(this, e);
            chkVAC2WillMute_CheckedChanged(this, e);

            chkLinkMaster_CheckedChanged(this, e);
            chkLinkRX0AF_CheckedChanged(this, e);
            chkLinkRX1AF_CheckedChanged(this, e);
            chkLinkRX2AF_CheckedChanged(this, e);

            chkAudioIQtoVAC_CheckedChanged(this, e);
            chkVAC2DirectIQ_CheckedChanged(this, e);
            chkSwapIQVac1_CheckedChanged(this, e);
            chkSwapIQVac2_CheckedChanged(this, e);

            chkVAC1ExclusiveIn_CheckedChanged(this, e);
            chkVAC2ExclusiveIn_CheckedChanged(this, e);
            chkVAC1ExclusiveOut_CheckedChanged(this, e);
            chkVAC2ExclusiveOut_CheckedChanged(this, e);
            // 

            // Calibration Tab
            udTXDisplayCalOffset_ValueChanged(this, e);
            chkUsing10MHzRef_CheckedChanged(this, e); //MW0LGE_21k9rc6
            chkLogVoltsAmps_CheckedChanged(this, e);

            // Filter tab
            udFilterDefaultLowCut_ValueChanged(this, e); //MW0LGE_21d5
            udRX2FilterDefaultLowCut_ValueChanged(this, e);

            // Test Tab
            udTXGenFreq_ValueChanged(this, e);
            udTXGenScale_ValueChanged(this, e);
            udTwoToneLevel_ValueChanged(this, e);
            chkShowControlDebug_CheckedChanged(this, e);
            udTestIMDPower_ValueChanged(this, e); //MW0LGE_22b
            setupTuneAnd2ToneRadios(); //MW0LGE_22b

            // Display Tab
            udDisplayGridMax_ValueChanged(this, e);
            udDisplayGridMin_ValueChanged(this, e);
            udDisplayGridStep_ValueChanged(this, e);
            udDisplayFPS_ValueChanged(this, e);
            udTXGridMax_ValueChanged(this, e);
            udTXGridMin_ValueChanged(this, e);
            udTXGridStep_ValueChanged(this, e);
            udDisplayMeterDelay_ValueChanged(this, e);
            udDisplayPeakText_ValueChanged(this, e);
            udDisplayCPUMeter_ValueChanged(this, e);
            udDisplayPhasePts_ValueChanged(this, e);
            udDisplayAVGTime_ValueChanged(this, e);
            udRX2DisplayAVGTime_ValueChanged(this, e);
            udDisplayWaterfallLowLevel_ValueChanged(this, e);
            udDisplayWaterfallHighLevel_ValueChanged(this, e);
            clrbtnWaterfallLow_Changed(this, e);
            udDisplayMultiPeakHoldTime_ValueChanged(this, e);
            udDisplayMultiTextHoldTime_ValueChanged(this, e);
            udRX2DisplayGridMax_ValueChanged(this, e);
            udRX2DisplayGridMin_ValueChanged(this, e);
            udRX2DisplayGridStep_ValueChanged(this, e);
            udRX2DisplayWaterfallLowLevel_ValueChanged(this, e);
            udRX2DisplayWaterfallHighLevel_ValueChanged(this, e);
            clrbtnRX2WaterfallLow_Changed(this, e);
            chkRX1WaterfallAGC_CheckedChanged(this, e);
            chkRX2WaterfallAGC_CheckedChanged(this, e);
            chkStopRX1WaterfallOnTx_CheckedChanged(this, e); //[2.10.3.5]MW0LGE
            chkStopRX2WaterfallOnTx_CheckedChanged(this, e);
            chkANAN8000DLEDisplayVoltsAmps_CheckedChanged(this, e);
            udDisplayWaterfallUpdatePeriod_ValueChanged(this, e);
            udRX2DisplayWaterfallUpdatePeriod_ValueChanged(this, e);
            comboTXLabelAlign_SelectedIndexChanged(this, e);
            udPeakBlobs_ValueChanged(this, e);
            chkPeakBlobInsideFilterOnly_CheckedChanged(this, e);
            chkPeakBlobsEnabled_CheckedChanged(this, e);
            chkAccurateFrameTiming_CheckedChanged(this, e);
            clrbtnSignalHistoryColour_Changed(this, e);
            chkSignalHistory_CheckedChanged(this, e);
            chkVSyncDX_CheckedChanged(this, e);
            chkBlobPeakHold_CheckedChanged(this, e);
            udSignalHistoryDuration_ValueChanged(this, e);
            udBlobPeakHoldMS_ValueChanged(this, e);
            chkPeakHoldDrop_CheckedChanged(this, e);
            clrbtnSliderLimitBar_Changed(this, e); //MW0LGE_22b

            chkQSOTimerEnabled_CheckedChanged(this, e);
            chkQSOTimerOnlyDuringMOX_CheckedChanged(this, e);
            chkQSOTimerResetOnMOX_CheckedChanged(this, e);
            chkQSOTimerResetOnExpiry_CheckedChanged(this, e);
            //MW0LGE_21d
            tbRX1WaterfallOpacity_Scroll(this, e);
            tbRX2WaterfallOpacity_Scroll(this, e);
            chkQSOTimerFlashTimerIfResetOnExpiry_CheckedChanged(this, e);
            chkQSOTimerPlaySoundOnExpiry_CheckedChanged(this, e);
            udQSOTimerMinutes_ValueChanged(this, e);
            udQSOTimerSeconds_ValueChanged(this, e);
            //MW0LGE_21k
            chkShowRX1NoiseFloor_CheckedChanged(this, e);
            chkShowRX2NoiseFloor_CheckedChanged(this, e);
            //21k6
            udWaterfallAGCOffsetRX1_ValueChanged(this, e);
            udWaterfallAGCOffsetRX2_ValueChanged(this, e);
            chkWaterfallUseNFForAGCRX1_CheckedChanged(this, e);
            chkWaterfallUseNFForAGCRX2_CheckedChanged(this, e);
            //
            setQSOTimerDuration();

            chkPanadpatorGradient_CheckedChanged(this, e);
            chkSpecWarningLEDRenderDelay_CheckedChanged(this, e);
            chkSpecWarningLEDGetPixels_CheckedChanged(this, e);

            chkShowRXFilterOnWaterfall_CheckedChanged(this, e);
            chkShowRXZeroLineOnWaterfall_CheckedChanged(this, e);
            chkShowTXFilterOnRXWaterfall_CheckedChanged(this, e);

            chkConsoleDarkModeTitleBar_CheckedChanged(this, e); //MW0LGE [2.9.0.8]

            //collapsed display related items [2.10.3.6]MW0LGE
            chkShowBandControls_CheckedChanged(this, e);
            chkModeControls_CheckedChanged(this, e);
            chkShowAndromedaTop_CheckedChanged(this, e);
            chkShowAndromedaBar_CheckedChanged(this, e);

            // DSP Tab
            udLMSANF_ValueChanged(this, e);
            udLMSNR_ValueChanged(this, e);
            udLMSANF2_ValueChanged(this, e);
            udLMSNR2_ValueChanged(this, e);
            udDSPCWPitch_ValueChanged(this, e);
            udDSPNB_ValueChanged(this, e);
            comboDSPNOBmode_SelectedIndexChanged(this, e);
            comboDSPRxWindow_SelectedIndexChanged(this, e);
            comboDSPTxWindow_SelectedIndexChanged(this, e);
            chkCWBreakInEnabled_CheckStateChanged(this, e);
            udHWKeyDownDelay_ValueChanged(this, e);
            chkCWKeyerRevPdl_CheckedChanged(this, e);
            chkCWKeyerIambic_CheckedChanged(this, e);
            udCWKeyerWeight_ValueChanged(this, e);
            chkStrictCharSpacing_CheckedChanged(this, e);
            chkCWKeyerMode_CheckedChanged(this, e);
            chkDSPKeyerSidetone_CheckedChanged(this, e);
            chkDSPCESSB_CheckedChanged(this, e);
            udRXAMSQMaxTail_ValueChanged(this, e);
            radANFPreAGC_CheckedChanged(this, e);
            radANF2PreAGC_CheckedChanged(this, e);
            chkMNFAutoIncrease_CheckedChanged(this, e);
            udCWEdgeLength_ValueChanged(this, e);
            //MW0LGE_21d
            chkShowAGC_CheckedChanged(this, e);
            chkAGCDisplayHangLine_CheckedChanged(this, e);
            chkSpectrumLine_CheckedChanged(this, e);
            chkAGCHangSpectrumLine_CheckedChanged(this, e);
            chkDisplayRX2GainLine_CheckedChanged(this, e);
            chkDisplayRX2HangLine_CheckedChanged(this, e);
            chkRX2GainSpectrumLine_CheckedChanged(this, e);
            chkRX2HangSpectrumLine_CheckedChanged(this, e);

            chkCFCDisplayAutoScale_CheckedChanged(this, e);
            udCFCPicDBPerLine_ValueChanged(this, e);

            chkCWAutoSwitchMode_CheckedChanged(this, e);
            chkAutoModeSwitchCWReturn_CheckedChanged(this, e);

            //AGC
            udDSPAGCFixedGaindB_ValueChanged(this, e);
            udDSPAGCMaxGaindB_ValueChanged(this, e);
            udDSPAGCSlope_ValueChanged(this, e);
            udDSPAGCDecay_ValueChanged(this, e);
            udDSPAGCHangTime_ValueChanged(this, e);
            tbDSPAGCHangThreshold_Scroll(this, e);

            udDSPAGCRX2FixedGaindB_ValueChanged(this, e);
            udDSPAGCRX2MaxGaindB_ValueChanged(this, e);
            udDSPAGCRX2Slope_ValueChanged(this, e);
            udDSPAGCRX2Decay_ValueChanged(this, e);
            udDSPAGCRX2HangTime_ValueChanged(this, e);
            tbDSPAGCRX2HangThreshold_Scroll(this, e);

            //MW0LGE_21k
            chkAutoAGCRX1_CheckedChanged(this, e);
            chkAutoAGCRX2_CheckedChanged(this, e);
            udRX1AutoAGCOffset_ValueChanged(this, e);
            udRX2AutoAGCOffset_ValueChanged(this, e);
            udNoiseFloorAttackRX1_ValueChanged(this, e);
            udNoiseFloorAttackRX2_ValueChanged(this, e);
            //

            //Leveler
            chkDSPLevelerEnabled_CheckedChanged(this, e);
            udDSPLevelerThreshold_ValueChanged(this, e);
            udDSPLevelerDecay_ValueChanged(this, e);

            //ALC
            udDSPALCMaximumGain_ValueChanged(this, e);
            udDSPALCDecay_ValueChanged(this, e);

            // AM/SAM Tab
            chkLevelFades_CheckedChanged(this, e);
            chkRX2LevelFades_CheckedChanged(this, e);
            radLSBUSB_CheckedChanged(this, e);
            radLSB_CheckedChanged(this, e);
            radUSB_CheckedChanged(this, e);
            radRX2LSBUSB_CheckedChanged(this, e);
            radRX2LSB_CheckedChanged(this, e);
            radRX2USB_CheckedChanged(this, e);
            chkCBlock_CheckedChanged(this, e);
            chkRX2CBlock_CheckedChanged(this, e);
            radTXDSB_CheckedChanged(this, e);

            // FM Tab
            chkEmphPos_CheckedChanged(this, e);
            chkRemoveTone_CheckedChanged(this, e);
            chkFMDetLimON_CheckedChanged(this, e);
            tbDSPDetLimGain_Scroll(this, e);
            udFMLowCutRX_ValueChanged(this, e);
            udFMHighCutRX_ValueChanged(this, e);
            udFMLowCutTX_ValueChanged(this, e);
            udFMHighCutTX_ValueChanged(this, e);

            // EER Tab
            chkDSPEERon_CheckedChanged(this, e);
            udDSPEERmgain_ValueChanged(this, e);
            udDSPEERpgain_ValueChanged(this, e);
            chkDSPEERRunDelays_CheckedChanged(this, e);
            udDSPEERmdelay_ValueChanged(this, e);
            udDSPEERpdelay_ValueChanged(this, e);
            chkDSPEERamIQ_CheckedChanged(this, e);
            udDSPEERpwmMax_ValueChanged(this, e);
            udDSPEERpwmMin_ValueChanged(this, e);

            // NR Tab
            radDSPNR2Linear_CheckedChanged(this, e);
            radDSPNR2Log_CheckedChanged(this, e);
            radDSPNR2TRND_CheckedChanged(this, e);

            udDSPNR2trainThresh_ValueChanged(this, e);
            udDSPNR2trainThreshRX2_ValueChanged(this, e);
            udDSPNR2trainT2_ValueChanged(this, e);
            udDSPNR2trainT2RX2_ValueChanged(this, e);

            radDSPNR2OSMS_CheckedChanged(this, e);
            radDSPNR2MMSE_CheckedChanged(this, e);
            radDSPNR2NSTAT_CheckedChanged(this, e);
            radDSPNR2OSMSRX2_CheckedChanged(this, e);
            radDSPNR2MMSERX2_CheckedChanged(this, e);
            radDSPNR2NSTATRX2_CheckedChanged(this, e);

            chkDSPNR2AE_CheckedChanged(this, e);
            radDSPNR2LinearRX2_CheckedChanged(this, e);
            radDSPNR2LogRX2_CheckedChanged(this, e);
            radDSPNR2TRNDRX2_CheckedChanged(this, e);
            chkDSPNR2AERX2_CheckedChanged(this, e);

            // Transmit Tab
            udTXFilterHigh_ValueChanged(this, e);
            udTXFilterLow_ValueChanged(this, e);
            udTransmitTunePower_ValueChanged(this, e);
            radMicIn_CheckedChanged(this, e);
            radLineIn_CheckedChanged(this, e);
            udMicGainMax_ValueChanged(this, e);
            udMicGainMin_ValueChanged(this, e);
            udLineInBoost_ValueChanged(this, e);
            udTXAMCarrierLevel_ValueChanged(this, e);
            chkLimitExtAmpOnOverload_CheckedChanged(this, e);
            chkSaveTXProfileOnExit_CheckedChanged(this, e);
            chkRecoverPAProfileFromTXProfile_CheckedChanged(this, e);
            ForceTXProfileUpdate();

            // Keyboard Tab
            comboKBTuneUp1_SelectedIndexChanged(this, e);
            comboKBTuneUp2_SelectedIndexChanged(this, e);
            comboKBTuneUp3_SelectedIndexChanged(this, e);
            comboKBTuneUp4_SelectedIndexChanged(this, e);
            comboKBTuneUp5_SelectedIndexChanged(this, e);
            comboKBTuneUp6_SelectedIndexChanged(this, e);
            comboKBTuneDown1_SelectedIndexChanged(this, e);
            comboKBTuneDown2_SelectedIndexChanged(this, e);
            comboKBTuneDown3_SelectedIndexChanged(this, e);
            comboKBTuneDown4_SelectedIndexChanged(this, e);
            comboKBTuneDown5_SelectedIndexChanged(this, e);
            comboKBTuneDown6_SelectedIndexChanged(this, e);
            comboKBBandUp_SelectedIndexChanged(this, e);
            comboKBBandDown_SelectedIndexChanged(this, e);
            comboKBFilterUp_SelectedIndexChanged(this, e);
            comboKBFilterDown_SelectedIndexChanged(this, e);
            comboKBModeUp_SelectedIndexChanged(this, e);
            comboKBModeDown_SelectedIndexChanged(this, e);
            comboKBCWDash_SelectedIndexChanged(this, e);
            comboKBCWDot_SelectedIndexChanged(this, e);
            comboKBPTTTx_SelectedIndexChanged(this, e);
            comboKBPTTRx_SelectedIndexChanged(this, e);
            radSpaceBarVFOBTX_CheckedChanged(this, e);

            // Appearance Tab
            clrbtnBtnSel_Changed(this, e);
            clrbtnVFODark_Changed(this, e);
            clrbtnVFOLight_Changed(this, e);
            clrbtnBandDark_Changed(this, e);
            clrbtnBandLight_Changed(this, e);
            clrbtnPeakText_Changed(this, e);
            clrbtnBackground_Changed(this, e);
            clrbtnTXBackground_Changed(this, e);
            clrbtnGrid_Changed(this, e);
            clrbtnTXVGrid_Changed(this, e);
            clrbtnGridFine_Changed(this, e);
            clrbtnHGridColor_Changed(this, e);
            clrbtnTXHGridColor_Changed(this, e);
            clrbtnZeroLine_Changed(this, e);
            clrbtnTXZeroLine_Changed(this, e);
            clrbtnFilter_Changed(this, e);
            clrbtnGridTXFilter_Changed(this, e);
            clrbtnText_Changed(this, e);
            clrbtnDataLine_Changed(this, e);
            clrbtnDataFill_Changed(this, e);
            clrbtnBandstackOverlay_Changed(this, e);
            udDisplayLineWidth_ValueChanged(this, e);
            udTXLineWidth_ValueChanged(this, e);
            clrbtnTXDataLine_Changed(this, e);
            clrbtnMeterLeft_Changed(this, e);
            clrbtnMeterRight_Changed(this, e);
            chkGridControl_CheckedChanged(this, e);
            clrbtnBandEdge_Changed(this, e);
            clrbtnTXBandEdge_Changed(this, e);
            tbDisplayFFTSize_Scroll(this, e);
            tbRX2DisplayFFTSize_Scroll(this, e);
            comboDispPanDetector_SelectedIndexChanged(this, e);
            comboDispWFDetector_SelectedIndexChanged(this, e);
            comboDispPanAveraging_SelectedIndexChanged(this, e);
            comboDispWFAveraging_SelectedIndexChanged(this, e);
            udDisplayAVTimeWF_ValueChanged(this, e);
            comboRX2DispPanDetector_SelectedIndexChanged(this, e);
            comboRX2DispPanAveraging_SelectedIndexChanged(this, e);
            comboRX2DispWFDetector_SelectedIndexChanged(this, e);
            comboRX2DispWFAveraging_SelectedIndexChanged(this, e);
            udRX2DisplayWFAVTime_ValueChanged(this, e);
            chkDispRX2Normalize_CheckedChanged(this, e);
            chkDispNormalize_CheckedChanged(this, e);
            comboTXDispPanDetector_SelectedIndexChanged(this, e);
            comboTXDispPanAveraging_SelectedIndexChanged(this, e);
            udTXDisplayAVGTime_ValueChanged(this, e);
            chkDispTXNormalize_CheckedChanged(this, e);
            comboTXDispWFDetector_SelectedIndexChanged(this, e);
            comboTXDispWFAveraging_SelectedIndexChanged(this, e);
            udTXDisplayAVTime_ValueChanged(this, e);
            comboTXDispWinType_SelectedIndexChanged(this, e);
            comboDispWinType_SelectedIndexChanged(this, e);
            comboRX2DispWinType_SelectedIndexChanged(this, e);
            udDSPNBTransition_ValueChanged(this, e);
            udDSPNBLead_ValueChanged(this, e);
            udDSPNBLag_ValueChanged(this, e);
            comboMeterType_SelectedIndexChanged(this, e);
            comboAppSkin_SelectedIndexChanged(this, e);
            chkDisablePicDisplayBackgroundImage_CheckedChanged(this, e);

            clrbtnActiveSpectralPeak_Changed(this, e);
            chkActivePeakHoldRX1_CheckedChanged(this, e);
            udActivePeakHoldDurationRX1_ValueChanged(this, e);
            chkActivePeakHoldRX2_CheckedChanged(this, e);
            udActivePeakHoldDurationRX2_ValueChanged(this, e);

            clrbtnNoiseFloor_Changed(this, e);
            clrbtnNoiseFloorText_Changed(this, e);
            chkNoiseFloorShowDBM_CheckedChanged(this, e);
            udNoiseFloorLineWidth_ValueChanged(this, e);

            //[2.10.1.0]MW0LGE
            clrbtnOutOfBand_Changed(this, e);
            chkVFOSmallLSD_CheckedChanged(this, e);
            clrbtnVFOSmallColor_Changed(this, e);
            clrbtnInfoButtonsColor_Changed(this, e);
            clrbtnPeakBackground_Changed(this, e);
            clrbtnMeterBackground_Changed(this, e);
            clrbtnBandBackground_Changed(this, e);
            clrbtnVFOBackground_Changed(this, e);

            chkLegacyMeters_CheckedChanged(this, e);

            chkJoinBandEdges_CheckedChanged(this, e);

            clrbtnTXAttenuationBackground_Changed(this, e);

            lstMetersInUse_SelectedIndexChanged(this, e);
            lstMMIO_network_list_SelectedIndexChanged(this, e);
            //

            // RX2 tab
            chkRX2AutoMuteTX_CheckedChanged(this, e);
            udMoxDelay_ValueChanged(this, e);
            udCWKeyUpDelay_ValueChanged(this, e);

            // PS 
            console.psform.ForcePS();

            // APF
            chkDSPRX1APFEnable_CheckedChanged(this, e);
            chkDSPRX1subAPFEnable_CheckedChanged(this, e);
            chkDSPRX2APFEnable_CheckedChanged(this, e);
            tbDSPAudRX1APFGain_ValueChanged(this, e);
            tbDSPAudRX1subAPFGain_ValueChanged(this, e);
            tbDSPAudRX2APFGain_ValueChanged(this, e);
            tbRX1APFTune_Scroll(this, e);
            tbRX1subAPFTune_Scroll(this, e);
            tbRX2APFTune_Scroll(this, e);
            tbRX1APFBW_Scroll(this, e);
            tbRX1subAPFBW_Scroll(this, e);
            tbRX2APFBW_Scroll(this, e);
            radDSPRX1APFControls_CheckedChanged(this, e);
            radDSPRX1subAPFControls_CheckedChanged(this, e);
            radDSPRX2APFControls_CheckedChanged(this, e);

            // dolly filter
            chkDSPRX1DollyEnable_CheckedChanged(this, e);
            chkDSPRX1DollySubEnable_CheckedChanged(this, e);
            chkDSPRX2DollyEnable_CheckedChanged(this, e);
            udDSPRX1DollyF0_ValueChanged(this, e);
            udDSPRX1SubDollyF0_ValueChanged(this, e);
            udDSPRX2DollyF0_ValueChanged(this, e);
            udDSPRX1DollyF1_ValueChanged(this, e);
            udDSPRX1SubDollyF1_ValueChanged(this, e);
            udDSPRX2DollyF1_ValueChanged(this, e);

            // CAT
            comboFocusMasterMode_SelectedIndexChanged(this, e);
            chkRecenterOnZZFx_CheckedChanged(this, e);
            //MW0GLE [2.10.3.6_dev4]
            chkKWAI_CheckedChanged(this, e);

            //MW0LGE_21d n1mm
            chkN1MMEnableRX1_CheckedChanged(this, e);
            chkN1MMEnableRX2_CheckedChanged(this, e);
            txtN1MMSendTo_TextChanged(this, e);
            udN1MMSendRate_ValueChanged(this, e);
            udN1MMRX1Scaling_ValueChanged(this, e);
            udN1MMRX2Scaling_ValueChanged(this, e);
            udMaxTCISpots_ValueChanged(this, EventArgs.Empty);
            udTCISpotLifetime_ValueChanged(this, EventArgs.Empty);
            chkShowTCISpots_CheckedChanged(this, EventArgs.Empty);
            chkSpotOwnCallAppearance_CheckedChanged(this, EventArgs.Empty);

            //MIDI
            chkIgnore14bitMidiMessages_CheckedChanged(this, EventArgs.Empty);
            chkMidiControlIDincludesChannel_CheckedChanged(this, EventArgs.Empty);
            chkMidiControlIDincludesStatus_CheckedChanged(this, EventArgs.Empty);

            // SNB
            udDSPSNBThresh1_ValueChanged(this, e);
            udDSPSNBThresh2_ValueChanged(this, e);

            // MNF
            chkMNFAutoIncrease_CheckedChanged(this, e);

            // CFCompressor
            chkCFCEnable_CheckedChanged(this, e);
            setCFCProfile(this, e);
            tbCFCPRECOMP_Scroll(this, e);
            chkCFCPeqEnable_CheckedChanged(this, e);
            tbCFCPEG_Scroll(this, e);

            // Phase Rotator
            chkPHROTEnable_CheckedChanged(this, e);
            udPhRotFreq_ValueChanged(this, e);
            udPHROTStages_ValueChanged(this, e);
            chkPHROTReverse_CheckedChanged(this, e);

            // TXEQ
            console.EQForm.setTXEQProfile(this, e);

            //ADC assignment
            radDDCADC_CheckedChanged(this, e);
            radP1DDCADC_CheckedChanged(this, e);
            chkWheelReverse_CheckedChanged(this, e);

            // IVAC
            chkVAC1_Force_CheckedChanged(this, e);
            chkVAC1_Force2_CheckedChanged(this, e);
            chkVAC2onSplit_CheckedChanged(this, e);
            chkAudioEnableVAC_CheckedChanged(this, e);
            chkVAC2Enable_CheckedChanged(this, e);

            // DEXP-VOX
            chkVOXEnable_CheckedChanged(this, e);
            chkDEXPEnable_CheckedChanged(this, e);
            udDEXPAttack_ValueChanged(this, e);
            udDEXPHold_ValueChanged(this, e);
            udDEXPRelease_ValueChanged(this, e);
            udDEXPThreshold_ValueChanged(this, e);
            udDEXPExpansionRatio_ValueChanged(this, e);
            udDEXPHysteresisRatio_ValueChanged(this, e);
            udDEXPDetTau_ValueChanged(this, e);
            chkSCFEnable_CheckedChanged(this, e);
            udSCFLowCut_ValueChanged(this, e);
            udSCFHighCut_ValueChanged(this, e);
            chkDEXPLookAheadEnable_CheckedChanged(this, e);
            udDEXPLookAhead_ValueChanged(this, e);
            chkAntiVoxEnable_CheckedChanged(this, e);
            udAntiVoxGain_ValueChanged(this, e);
            udAntiVoxTau_ValueChanged(this, e);
            chkAntiVoxSource_CheckedChanged(this, e);

            // F/W Set
            chkMercDither_CheckedChanged(this, e);
            chkMercRandom_CheckedChanged(this, e);

            //OC tab
            chkAllowHotSwitching_CheckedChanged(this, e);
            chkUsbBCD_CheckedChanged(this, e); //[2.10.3.5]MW0LGE

            //PA
            comboPAProfile_SelectedIndexChanged(this, e); //MW0LGE_22b

            //
            chkForceATTwhenPSAoff_CheckedChanged(this, e); //MW0LGE [2.9.0.7]
            chkForceATTwhenOutPowerChanges_CheckedChanged(this, e);
            chkAutoATTTXPsOff_CheckedChanged(this, e);
            chkUndoAutoATTTx_CheckedChanged(this, e);
            chkAutoATTRx1_CheckedChanged(this, e);
            chkAutoATTRx2_CheckedChanged(this, e);

            //options1 tab
            chkPurgeBuffers_CheckedChanged(this, e);

            //options2 tab
            chkQuickSplit_CheckedChanged(this, e);
            chkQuickSplitPanAudio_CheckedChanged(this, e);
            chkToTMox_CheckedChanged(this, e);
            chkToTPing_CheckedChanged(this, e);
            chkAutoPowerOn_CheckedChanged(this, e);
            nudPBsnrShiftRx1_ValueChanged(this, e);
            nudPBsnrShiftRx2_ValueChanged(this, e);

            // auto start tab
            updateAutoLaunchControls();

            // alex/antenna
            chkRxOutOnTx_CheckedChanged(this, e);
            chkEXT1OutOnTx_CheckedChanged(this, e);
            chkEXT2OutOnTx_CheckedChanged(this, e);
            chkHFTRRelay_CheckedChanged(this, e);
            chkBPF2Gnd_CheckedChanged(this, e);
            chkEnableXVTRHF_CheckedChanged(this, e);

            chkSWRProtection_CheckedChanged(this, e);
            chkSWRTuneProtection_CheckedChanged(this, e);

            //multimeter io tab
            init_lstMMIO();

            //multimeter tab
            comboContainerSelect_SelectedIndexChanged(this, e);

            //legacy item tab
            chkLegacyItems_band_CheckedChanged(this, e);
            chkLegacyItems_mode_CheckedChanged(this, e);
            chkLegacyItems_filter_CheckedChanged(this, e);
            chkLegacyItems_expand_spectral_CheckedChanged(this, e);
            chkLegacyItems_vfoa_CheckedChanged(this, e);
            chkLegacyItems_vfob_CheckedChanged(this, e);
            chkLegacyItems_expand_spectral_top_CheckedChanged(this, e);
            chkLegacyItems_vfosync_CheckedChanged(this, e);

            //
            chkDiscordEnabled_CheckedChanged(this, e);
        }

        public string[] GetTXProfileStrings()
        {
            string[] s = new string[comboTXProfileName.Items.Count];
            for (int i = 0; i < comboTXProfileName.Items.Count; i++)
                s[i] = (string)comboTXProfileName.Items[i];
            return s;
        }

        public string TXProfile
        {
            get
            {
                return comboTXProfileName != null ? comboTXProfileName.Text : "";
            }
            set { if (comboTXProfileName != null) comboTXProfileName.Text = value; }
        }

        public void GetTxProfiles()
        {
            comboTXProfileName.Items.Clear();
            foreach (DataRow dr in DB.ds.Tables["TXProfile"].Rows)
            {
                if (dr.RowState != DataRowState.Deleted)
                {
                    if (!comboTXProfileName.Items.Contains(dr["Name"]))
                        comboTXProfileName.Items.Add(dr["Name"]);
                }
            }
        }

        public void GetTxProfileDefs()
        {
            lstTXProfileDef.Items.Clear();
            foreach (DataRow dr in DB.ds.Tables["TxProfileDef"].Rows)
            {
                if (dr.RowState != DataRowState.Deleted)
                {
                    if (!lstTXProfileDef.Items.Contains(dr["Name"]))
                        lstTXProfileDef.Items.Add(dr["name"]);
                }
            }
        }
        public static T ConvertFromDBVal<T>(object obj)
        {
            if (obj == null || obj == DBNull.Value)
            {
                return default(T); // returns the default value for the type
            }
            else
            {
                return (T)obj;
            }
        }
        private bool isTXProfileSettingDifferent<T>(DataRow dr, string setting, T value, out string report)
        {
            if (dr.IsNull(setting))
            {
                report = "";
                return false;
            }

            if (dr[setting] is T dbVal && !dbVal.Equals(value))
            {
                report = setting + " from [" + dbVal.ToString() + "] to [" + value.ToString() + "]" + Environment.NewLine;
                return true;
            }

            report = "";
            return false;
        }
        private DataRow[] getDataRowsForTXProfile(string profile)
        {
            //[2.10.3.6]MW0LGE fix for case sensitive tx profile names. For example, if you name one
            //'ABC' and another 'abc', then two will be returned without this change causing issues
            //to delete etc.
            bool old_case_sen = DB.ds.Tables["TXProfile"].CaseSensitive;
            DB.ds.Tables["TXProfile"].CaseSensitive = true;
            DataRow[] rows = DB.ds.Tables["TXProfile"].Select("Name = '" + profile.Replace("'", "''") + "'");//MW0LGE_21k9rc6 replace ' for ''
            DB.ds.Tables["TXProfile"].CaseSensitive = old_case_sen;
            return rows;
        }
        private string getTXProfileChangeReport(DataRow drToCheck = null, bool bOnlyVac = false)
        {
            // duplicate of code from checkTXProfileChanged2

            string sReport = "";
            string sReportOut = "";
            //bOnlyVac will only consider settings related to VAC

            DataRow dr;
            if (drToCheck == null)
            {
                // check everything in the TX profile
                DataRow[] rows = getDataRowsForTXProfile(current_profile);// DB.ds.Tables["TXProfile"].Select("Name = '" + current_profile.Replace("'", "''") + "'"); 

                if (rows.Length != 1)
                    return "";

                dr = rows[0];
            }
            else
            {
                dr = drToCheck;
            }

            if (!bOnlyVac)
            {
                if (isTXProfileSettingDifferent<int>(dr, "FilterLow", (int)udTXFilterLow.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<int>(dr, "FilterHigh", (int)udTXFilterHigh.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<int>(dr, "TXEQNumBands", console.EQForm.NumBands, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<bool>(dr, "TXEQEnabled", console.EQForm.TXEQEnabled, out sReportOut)) sReport += sReportOut;
                int[] eq = console.EQForm.TXEQ;
                if (isTXProfileSettingDifferent<int>(dr, "TXEQPreamp", eq[0], out sReportOut)) sReport += sReportOut;
                for (int i = 1; i < 11; i++)
                    if (isTXProfileSettingDifferent<int>(dr, "TXEQ" + i.ToString(), eq[i], out sReportOut)) sReport += sReportOut;
                for (int i = 11; i < 21; i++)
                    if (isTXProfileSettingDifferent<int>(dr, "TxEqFreq" + (i - 10).ToString(), eq[i], out sReportOut)) sReport += sReportOut;

                if (isTXProfileSettingDifferent<bool>(dr, "DXOn", console.DX, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<bool>(dr, "CompanderOn", console.CPDR, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<int>(dr, "CompanderLevel", console.CPDRLevel, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<int>(dr, "MicGain", console.Mic, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<int>(dr, "FMMicGain", console.FMMic, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<bool>(dr, "MicMute", console.MicMute, out sReportOut)) sReport += sReportOut;

                if (isTXProfileSettingDifferent<bool>(dr, "Lev_On", chkDSPLevelerEnabled.Checked, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<int>(dr, "Lev_Slope", (int)udDSPLevelerSlope.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<int>(dr, "Lev_MaxGain", (int)udDSPLevelerThreshold.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<int>(dr, "Lev_Attack", (int)udDSPLevelerAttack.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<int>(dr, "Lev_Decay", (int)udDSPLevelerDecay.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<int>(dr, "Lev_Hang", (int)udDSPLevelerHangTime.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<int>(dr, "Lev_HangThreshold", tbDSPLevelerHangThreshold.Value, out sReportOut)) sReport += sReportOut;

                if (isTXProfileSettingDifferent<int>(dr, "ALC_Slope", (int)udDSPALCSlope.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<int>(dr, "ALC_MaximumGain", (int)udDSPALCMaximumGain.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<int>(dr, "ALC_Attack", (int)udDSPALCAttack.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<int>(dr, "ALC_Decay", (int)udDSPALCDecay.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<int>(dr, "ALC_Hang", (int)udDSPALCHangTime.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<int>(dr, "ALC_HangThreshold", tbDSPALCHangThreshold.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<bool>(dr, "VOX_On", chkVOXEnable.Checked, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<bool>(dr, "Dexp_On", chkDEXPEnable.Checked, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<int>(dr, "Dexp_Threshold", (int)udDEXPThreshold.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<int>(dr, "Dexp_Attack", (int)udDEXPAttack.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<int>(dr, "VOX_HangTime", (int)udDEXPHold.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<int>(dr, "Dexp_Release", (int)udDEXPRelease.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<decimal>(dr, "Dexp_Attenuate", udDEXPExpansionRatio.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<decimal>(dr, "Dexp_Hysterisis", udDEXPHysteresisRatio.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<int>(dr, "Dexp_Tau", (int)udDEXPDetTau.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<bool>(dr, "Dexp_SCF_On", chkSCFEnable.Checked, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<int>(dr, "Dexp_SCF_Low", (int)udSCFLowCut.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<int>(dr, "Dexp_SCF_High", (int)udSCFHighCut.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<bool>(dr, "Dexp_LookAhead_On", chkDEXPLookAheadEnable.Checked, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<int>(dr, "Dexp_LookAhead", (int)udDEXPLookAhead.Value, out sReportOut)) sReport += sReportOut;

                if (isTXProfileSettingDifferent<int>(dr, "TX_AF_Level", console.TXAF, out sReportOut)) sReport += sReportOut;

                if (isTXProfileSettingDifferent<int>(dr, "AM_Carrier_Level", (int)udTXAMCarrierLevel.Value, out sReportOut)) sReport += sReportOut;

                if (isTXProfileSettingDifferent<bool>(dr, "Show_TX_Filter", (bool)console.ShowTXFilter, out sReportOut)) sReport += sReportOut;
            }

            if (isTXProfileSettingDifferent<bool>(dr, "VAC1_On", (bool)chkAudioEnableVAC.Checked, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<bool>(dr, "VAC1_Auto_On", (bool)chkAudioVACAutoEnable.Checked, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<int>(dr, "VAC1_RX_GAIN", (int)udAudioVACGainRX.Value, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<int>(dr, "VAC1_TX_GAIN", (int)udAudioVACGainTX.Value, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<bool>(dr, "VAC1_Stereo_On", (bool)chkAudio2Stereo.Checked, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<string>(dr, "VAC1_Sample_Rate", (string)comboAudioSampleRate2.Text, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<string>(dr, "VAC1_Buffer_Size", (string)comboAudioBuffer2.Text, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<bool>(dr, "VAC1_IQ_Output", (bool)chkAudioIQtoVAC.Checked, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<bool>(dr, "VAC1_IQ_Correct", (bool)chkAudioCorrectIQ.Checked, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<bool>(dr, "VAC1_PTT_OverRide", (bool)chkVACAllowBypass.Checked, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<bool>(dr, "VAC1_Combine_Input_Channels", (bool)chkVACCombine.Checked, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<bool>(dr, "VAC1_Latency_On", (bool)chkAudioLatencyManual2.Checked, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<int>(dr, "VAC1_Latency_Duration", (int)udAudioLatency2.Value, out sReportOut)) sReport += sReportOut;

            if (isTXProfileSettingDifferent<bool>(dr, "VAC1_Latency_RBOut_On", (bool)chkAudioLatencyManual2_Out.Checked, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<int>(dr, "VAC1_Latency_RBOut_Duration", (int)udAudioLatency2_Out.Value, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<bool>(dr, "VAC1_Latency_PAIn_On", (bool)chkAudioLatencyPAInManual.Checked, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<int>(dr, "VAC1_Latency_PAIn_Duration", (int)udAudioLatencyPAIn.Value, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<bool>(dr, "VAC1_Latency_PAOut_On", (bool)chkAudioLatencyPAOutManual.Checked, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<int>(dr, "VAC1_Latency_PAOut_Duration", (int)udAudioLatencyPAOut.Value, out sReportOut)) sReport += sReportOut;

            if (isTXProfileSettingDifferent<string>(dr, "VAC1_AudioDriver", (string)comboAudioDriver2.Text, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<string>(dr, "VAC1_AudioInput", (string)comboAudioInput2.Text, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<string>(dr, "VAC1_AudioOutput", (string)comboAudioOutput2.Text, out sReportOut)) sReport += sReportOut;

            if (isTXProfileSettingDifferent<bool>(dr, "VAC2_On", (bool)chkVAC2Enable.Checked, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<bool>(dr, "VAC2_Auto_On", (bool)chkVAC2AutoEnable.Checked, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<int>(dr, "VAC2_RX_GAIN", (int)udVAC2GainRX.Value, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<int>(dr, "VAC2_TX_GAIN", (int)udVAC2GainTX.Value, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<bool>(dr, "VAC2_Stereo_On", (bool)chkAudioStereo3.Checked, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<string>(dr, "VAC2_Sample_Rate", (string)comboAudioSampleRate3.Text, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<string>(dr, "VAC2_Buffer_Size", (string)comboAudioBuffer3.Text, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<bool>(dr, "VAC2_IQ_Output", (bool)chkVAC2DirectIQ.Checked, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<bool>(dr, "VAC2_IQ_Correct", (bool)chkVAC2DirectIQCal.Checked, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<bool>(dr, "VAC2_Combine_Input_Channels", (bool)chkVAC2Combine.Checked, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<bool>(dr, "VAC2_Latency_On", (bool)chkVAC2LatencyManual.Checked, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<int>(dr, "VAC2_Latency_Duration", (int)udVAC2Latency.Value, out sReportOut)) sReport += sReportOut;

            if (isTXProfileSettingDifferent<bool>(dr, "VAC2_Latency_RBOut_On", (bool)chkVAC2LatencyOutManual.Checked, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<int>(dr, "VAC2_Latency_RBOut_Duration", (int)udVAC2LatencyOut.Value, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<bool>(dr, "VAC2_Latency_PAIn_On", (bool)chkVAC2LatencyPAInManual.Checked, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<int>(dr, "VAC2_Latency_PAIn_Duration", (int)udVAC2LatencyPAIn.Value, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<bool>(dr, "VAC2_Latency_PAOut_On", (bool)chkVAC2LatencyPAOutManual.Checked, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<int>(dr, "VAC2_Latency_PAOut_Duration", (int)udVAC2LatencyPAOut.Value, out sReportOut)) sReport += sReportOut;

            if (isTXProfileSettingDifferent<string>(dr, "VAC2_AudioDriver", (string)comboAudioDriver3.Text, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<string>(dr, "VAC2_AudioInput", (string)comboAudioInput3.Text, out sReportOut)) sReport += sReportOut;
            if (isTXProfileSettingDifferent<string>(dr, "VAC2_AudioOutput", (string)comboAudioOutput3.Text, out sReportOut)) sReport += sReportOut;

            if (!bOnlyVac)
            {
                if (isTXProfileSettingDifferent<string>(dr, "Phone_RX_DSP_Buffer", (string)comboDSPPhoneRXBuf.Text, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<string>(dr, "Phone_TX_DSP_Buffer", (string)comboDSPPhoneTXBuf.Text, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<string>(dr, "FM_RX_DSP_Buffer", (string)comboDSPFMRXBuf.Text, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<string>(dr, "FM_TX_DSP_Buffer", (string)comboDSPFMTXBuf.Text, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<string>(dr, "Digi_RX_DSP_Buffer", (string)comboDSPDigRXBuf.Text, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<string>(dr, "Digi_TX_DSP_Buffer", (string)comboDSPDigTXBuf.Text, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<string>(dr, "CW_RX_DSP_Buffer", (string)comboDSPCWRXBuf.Text, out sReportOut)) sReport += sReportOut;

                if (isTXProfileSettingDifferent<string>(dr, "Phone_RX_DSP_Filter_Size", (string)comboDSPPhoneRXFiltSize.Text, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<string>(dr, "Phone_TX_DSP_Filter_Size", (string)comboDSPPhoneTXFiltSize.Text, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<string>(dr, "FM_RX_DSP_Filter_Size", (string)comboDSPFMRXFiltSize.Text, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<string>(dr, "FM_TX_DSP_Filter_Size", (string)comboDSPFMTXFiltSize.Text, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<string>(dr, "Digi_RX_DSP_Filter_Size", (string)comboDSPDigRXFiltSize.Text, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<string>(dr, "Digi_TX_DSP_Filter_Size", (string)comboDSPDigTXFiltSize.Text, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<string>(dr, "CW_RX_DSP_Filter_Size", (string)comboDSPCWRXFiltSize.Text, out sReportOut)) sReport += sReportOut;

                if (isTXProfileSettingDifferent<string>(dr, "Phone_RX_DSP_Filter_Type", (string)comboDSPPhoneRXFiltType.Text, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<string>(dr, "Phone_TX_DSP_Filter_Type", (string)comboDSPPhoneTXFiltType.Text, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<string>(dr, "FM_RX_DSP_Filter_Type", (string)comboDSPFMRXFiltType.Text, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<string>(dr, "FM_TX_DSP_Filter_Type", (string)comboDSPFMTXFiltType.Text, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<string>(dr, "Digi_RX_DSP_Filter_Type", (string)comboDSPDigRXFiltType.Text, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<string>(dr, "Digi_TX_DSP_Filter_Type", (string)comboDSPDigTXFiltType.Text, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<string>(dr, "CW_RX_DSP_Filter_Type", (string)comboDSPCWRXFiltType.Text, out sReportOut)) sReport += sReportOut;

                if (isTXProfileSettingDifferent<bool>(dr, "Mic_Input_On", (bool)radMicIn.Checked, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<bool>(dr, "Mic_Input_Boost", (bool)chk20dbMicBoost.Checked, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<bool>(dr, "Line_Input_On", (bool)radLineIn.Checked, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<decimal>(dr, "Line_Input_Level", udLineInBoost.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<bool>(dr, "CESSB_On", chkDSPCESSB.Checked, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<bool>(dr, "Pure_Signal_Enabled", console.PureSignalEnabled, out sReportOut)) sReport += sReportOut;

                //
                if (isTXProfileSettingDifferent<decimal>(dr, "FM_RX_AFFilter_Low", (decimal)udFMLowCutRX.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<decimal>(dr, "FM_RX_AFFilter_High", (decimal)udFMHighCutRX.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<decimal>(dr, "FM_TX_AFFilter_Low", (decimal)udFMLowCutTX.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<decimal>(dr, "FM_TX_AFFilter_High", (decimal)udFMHighCutTX.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<bool>(dr, "VAC1_Force_In", (bool)chkVAC1_Force2.Checked, out sReportOut)) sReport += sReportOut;  // note in is force2, and out is force
                if (isTXProfileSettingDifferent<bool>(dr, "VAC1_Force_Out", (bool)chkVAC1_Force.Checked, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<bool>(dr, "VAC2_Force_In", (bool)chkVAC2_Force2.Checked, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<bool>(dr, "VAC2_Force_Out", (bool)chkVAC2_Force.Checked, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<bool>(dr, "VAC1_SwapIQ", (bool)chkSwapIQVac1.Checked, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<bool>(dr, "VAC2_SwapIQ", (bool)chkSwapIQVac2.Checked, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<bool>(dr, "Audio_Disable_Audio_Amp", (bool)chkDisableRearSpeakerJacksAudioAmplifier.Checked, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<string>(dr, "PA_Profile", (string)comboPAProfile.Text, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<bool>(dr, "RXEQEnabled", console.EQForm.RXEQEnabled, out sReportOut)) sReport += sReportOut;
                int[] rxeq = console.EQForm.RXEQ;
                if (isTXProfileSettingDifferent<int>(dr, "RXEQPreamp", rxeq[0], out sReportOut)) sReport += sReportOut;
                for (int i = 1; i < rxeq.Length; i++)
                    if (isTXProfileSettingDifferent<int>(dr, "RXEQ" + i.ToString(), rxeq[i], out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<bool>(dr, "VAC1_Exclusive_In", (bool)chkVAC1ExclusiveIn.Checked, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<bool>(dr, "VAC1_Exclusive_Out", (bool)chkVAC1ExclusiveOut.Checked, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<bool>(dr, "VAC2_Exclusive_In", (bool)chkVAC2ExclusiveIn.Checked, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<bool>(dr, "VAC2_Exclusive_Out", (bool)chkVAC2ExclusiveOut.Checked, out sReportOut)) sReport += sReportOut;
                //

                //CFC
                if (isTXProfileSettingDifferent<bool>(dr, "CFCEnabled", chkCFCEnable.Checked, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<bool>(dr, "CFCPostEqEnabled", chkCFCPeqEnable.Checked, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<bool>(dr, "CFCPhaseRotatorEnabled", chkPHROTEnable.Checked, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<bool>(dr, "CFCPhaseReverseEnabled", chkPHROTReverse.Checked, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<int>(dr, "CFCPhaseRotatorFreq", (int)udPhRotFreq.Value, out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<int>(dr, "CFCPhaseRotatorStages", (int)udPHROTStages.Value, out sReportOut)) sReport += sReportOut;
                int[] cfceq = CFCCOMPEQ;
                if (isTXProfileSettingDifferent<int>(dr, "CFCPreComp", cfceq[0], out sReportOut)) sReport += sReportOut;
                for (int i = 1; i < 11; i++)
                    if (isTXProfileSettingDifferent<int>(dr, "CFCPreComp" + (i - 1).ToString(), cfceq[i], out sReportOut)) sReport += sReportOut;
                if (isTXProfileSettingDifferent<int>(dr, "CFCPostEqGain", cfceq[11], out sReportOut)) sReport += sReportOut;
                for (int i = 12; i < 22; i++)
                    if (isTXProfileSettingDifferent<int>(dr, "CFCPostEqGain" + (i - 12).ToString(), cfceq[i], out sReportOut)) sReport += sReportOut;
                for (int i = 22; i < 32; i++)
                    if (isTXProfileSettingDifferent<int>(dr, "CFCEqFreq" + (i - 22).ToString(), cfceq[i], out sReportOut)) sReport += sReportOut;
            }

            return sReport;
        }
        private bool checkTXProfileChanged2(DataRow drToCheck = null, bool bOnlyVac = false)
        {
            //bOnlyVac will only consider settings related to VAC

            DataRow dr;
            if (drToCheck == null)
            {
                // check everything in the TX profile
                DataRow[] rows = getDataRowsForTXProfile(current_profile);// DB.ds.Tables["TXProfile"].Select("Name = '" + current_profile.Replace("'", "''") + "'"); //MW0LGE_21k9rc6 replace ' for ''

                if (rows.Length != 1)
                    return false;

                dr = rows[0];
            }
            else
            {
                dr = drToCheck;
            }

            if (!bOnlyVac)
            {
                if (DB.ConvertFromDBVal<int>(dr["FilterLow"]) != (int)udTXFilterLow.Value) return true;
                if (DB.ConvertFromDBVal<int>(dr["FilterHigh"]) != (int)udTXFilterHigh.Value) return true;
                if (DB.ConvertFromDBVal<int>(dr["TXEQNumBands"]) != console.EQForm.NumBands) return true;
                if (DB.ConvertFromDBVal<bool>(dr["TXEQEnabled"]) != console.EQForm.TXEQEnabled) return true;
                int[] eq = console.EQForm.TXEQ;
                if (DB.ConvertFromDBVal<int>(dr["TXEQPreamp"]) != eq[0]) return true;
                for (int i = 1; i < 11; i++)
                    if (DB.ConvertFromDBVal<int>(dr["TXEQ" + i.ToString()]) != eq[i]) return true;
                for (int i = 11; i < 21; i++)
                    if (DB.ConvertFromDBVal<int>(dr["TxEqFreq" + (i - 10).ToString()]) != eq[i]) return true;

                if (DB.ConvertFromDBVal<bool>(dr["DXOn"]) != console.DX) return true;

                if (DB.ConvertFromDBVal<bool>(dr["CompanderOn"]) != console.CPDR) return true;
                if (DB.ConvertFromDBVal<int>(dr["CompanderLevel"]) != console.CPDRLevel) return true;
                if (DB.ConvertFromDBVal<int>(dr["MicGain"]) != console.Mic) return true;
                if (DB.ConvertFromDBVal<int>(dr["FMMicGain"]) != console.FMMic) return true;
                if (DB.ConvertFromDBVal<bool>(dr["MicMute"]) != console.MicMute) return true;

                if (DB.ConvertFromDBVal<bool>(dr["Lev_On"]) != chkDSPLevelerEnabled.Checked) return true;
                if (DB.ConvertFromDBVal<int>(dr["Lev_Slope"]) != (int)udDSPLevelerSlope.Value) return true;
                if (DB.ConvertFromDBVal<int>(dr["Lev_MaxGain"]) != (int)udDSPLevelerThreshold.Value) return true;
                if (DB.ConvertFromDBVal<int>(dr["Lev_Attack"]) != (int)udDSPLevelerAttack.Value) return true;
                if (DB.ConvertFromDBVal<int>(dr["Lev_Decay"]) != (int)udDSPLevelerDecay.Value) return true;
                if (DB.ConvertFromDBVal<int>(dr["Lev_Hang"]) != (int)udDSPLevelerHangTime.Value) return true;
                if (DB.ConvertFromDBVal<int>(dr["Lev_HangThreshold"]) != tbDSPLevelerHangThreshold.Value) return true;

                if (DB.ConvertFromDBVal<int>(dr["ALC_Slope"]) != (int)udDSPALCSlope.Value) return true;
                if (DB.ConvertFromDBVal<int>(dr["ALC_MaximumGain"]) != (int)udDSPALCMaximumGain.Value) return true;
                if (DB.ConvertFromDBVal<int>(dr["ALC_Attack"]) != (int)udDSPALCAttack.Value) return true;
                if (DB.ConvertFromDBVal<int>(dr["ALC_Decay"]) != (int)udDSPALCDecay.Value) return true;
                if (DB.ConvertFromDBVal<int>(dr["ALC_Hang"]) != (int)udDSPALCHangTime.Value) return true;
                if (DB.ConvertFromDBVal<int>(dr["ALC_HangThreshold"]) != tbDSPALCHangThreshold.Value) return true;

                if (DB.ConvertFromDBVal<bool>(dr["VOX_On"]) != chkVOXEnable.Checked) return true;
                if (DB.ConvertFromDBVal<bool>(dr["Dexp_On"]) != chkDEXPEnable.Checked) return true;
                if (DB.ConvertFromDBVal<int>(dr["Dexp_Threshold"]) != (int)udDEXPThreshold.Value) return true;
                if (DB.ConvertFromDBVal<int>(dr["Dexp_Attack"]) != (int)udDEXPAttack.Value) return true;
                if (DB.ConvertFromDBVal<int>(dr["VOX_HangTime"]) != (int)udDEXPHold.Value) return true;
                if (DB.ConvertFromDBVal<int>(dr["Dexp_Release"]) != (int)udDEXPRelease.Value) return true;
                if (DB.ConvertFromDBVal<decimal>(dr["Dexp_Attenuate"]) != udDEXPExpansionRatio.Value) return true;
                if (DB.ConvertFromDBVal<decimal>(dr["Dexp_Hysterisis"]) != udDEXPHysteresisRatio.Value) return true;
                if (DB.ConvertFromDBVal<int>(dr["Dexp_Tau"]) != (int)udDEXPDetTau.Value) return true;
                if (DB.ConvertFromDBVal<bool>(dr["Dexp_SCF_On"]) != chkSCFEnable.Checked) return true;
                if (DB.ConvertFromDBVal<int>(dr["Dexp_SCF_Low"]) != (int)udSCFLowCut.Value) return true;
                if (DB.ConvertFromDBVal<int>(dr["Dexp_SCF_High"]) != (int)udSCFHighCut.Value) return true;
                if (DB.ConvertFromDBVal<bool>(dr["Dexp_LookAhead_On"]) != chkDEXPLookAheadEnable.Checked) return true;
                if (DB.ConvertFromDBVal<int>(dr["Dexp_LookAhead"]) != (int)udDEXPLookAhead.Value) return true;

                if (DB.ConvertFromDBVal<int>(dr["TX_AF_Level"]) != console.TXAF) return true;

                if (DB.ConvertFromDBVal<int>(dr["AM_Carrier_Level"]) != (int)udTXAMCarrierLevel.Value) return true;

                if (DB.ConvertFromDBVal<bool>(dr["Show_TX_Filter"]) != (bool)console.ShowTXFilter) return true;
            }

            if (DB.ConvertFromDBVal<bool>(dr["VAC1_On"]) != (bool)chkAudioEnableVAC.Checked) return true;
            if (DB.ConvertFromDBVal<bool>(dr["VAC1_Auto_On"]) != (bool)chkAudioVACAutoEnable.Checked) return true;
            if (DB.ConvertFromDBVal<int>(dr["VAC1_RX_GAIN"]) != (int)udAudioVACGainRX.Value) return true;
            if (DB.ConvertFromDBVal<int>(dr["VAC1_TX_GAIN"]) != (int)udAudioVACGainTX.Value) return true;
            if (DB.ConvertFromDBVal<bool>(dr["VAC1_Stereo_On"]) != (bool)chkAudio2Stereo.Checked) return true;
            if (DB.ConvertFromDBVal<string>(dr["VAC1_Sample_Rate"]) != (string)comboAudioSampleRate2.Text) return true;
            if (DB.ConvertFromDBVal<string>(dr["VAC1_Buffer_Size"]) != (string)comboAudioBuffer2.Text) return true;
            if (DB.ConvertFromDBVal<bool>(dr["VAC1_IQ_Output"]) != (bool)chkAudioIQtoVAC.Checked) return true;
            if (DB.ConvertFromDBVal<bool>(dr["VAC1_IQ_Correct"]) != (bool)chkAudioCorrectIQ.Checked) return true;
            if (DB.ConvertFromDBVal<bool>(dr["VAC1_PTT_OverRide"]) != (bool)chkVACAllowBypass.Checked) return true;
            if (DB.ConvertFromDBVal<bool>(dr["VAC1_Combine_Input_Channels"]) != (bool)chkVACCombine.Checked) return true;
            if (DB.ConvertFromDBVal<bool>(dr["VAC1_Latency_On"]) != (bool)chkAudioLatencyManual2.Checked) return true;
            if (DB.ConvertFromDBVal<int>(dr["VAC1_Latency_Duration"]) != (int)udAudioLatency2.Value) return true;

            if (DB.ConvertFromDBVal<bool>(dr["VAC1_Latency_RBOut_On"]) != (bool)chkAudioLatencyManual2_Out.Checked) return true;
            if (DB.ConvertFromDBVal<int>(dr["VAC1_Latency_RBOut_Duration"]) != (int)udAudioLatency2_Out.Value) return true;
            if (DB.ConvertFromDBVal<bool>(dr["VAC1_Latency_PAIn_On"]) != (bool)chkAudioLatencyPAInManual.Checked) return true;
            if (DB.ConvertFromDBVal<int>(dr["VAC1_Latency_PAIn_Duration"]) != (int)udAudioLatencyPAIn.Value) return true;
            if (DB.ConvertFromDBVal<bool>(dr["VAC1_Latency_PAOut_On"]) != (bool)chkAudioLatencyPAOutManual.Checked) return true;
            if (DB.ConvertFromDBVal<int>(dr["VAC1_Latency_PAOut_Duration"]) != (int)udAudioLatencyPAOut.Value) return true;

            if (DB.ConvertFromDBVal<string>(dr["VAC1_AudioDriver"]) != (string)comboAudioDriver2.Text) return true;
            if (DB.ConvertFromDBVal<string>(dr["VAC1_AudioInput"]) != (string)comboAudioInput2.Text) return true;
            if (DB.ConvertFromDBVal<string>(dr["VAC1_AudioOutput"]) != (string)comboAudioOutput2.Text) return true;

            if (DB.ConvertFromDBVal<bool>(dr["VAC1_Exclusive_In"]) != (bool)chkVAC1ExclusiveIn.Checked) return true;
            if (DB.ConvertFromDBVal<bool>(dr["VAC1_Exclusive_Out"]) != (bool)chkVAC1ExclusiveOut.Checked) return true;

            if (DB.ConvertFromDBVal<bool>(dr["VAC2_On"]) != (bool)chkVAC2Enable.Checked) return true;
            if (DB.ConvertFromDBVal<bool>(dr["VAC2_Auto_On"]) != (bool)chkVAC2AutoEnable.Checked) return true;
            if (DB.ConvertFromDBVal<int>(dr["VAC2_RX_GAIN"]) != (int)udVAC2GainRX.Value) return true;
            if (DB.ConvertFromDBVal<int>(dr["VAC2_TX_GAIN"]) != (int)udVAC2GainTX.Value) return true;
            if (DB.ConvertFromDBVal<bool>(dr["VAC2_Stereo_On"]) != (bool)chkAudioStereo3.Checked) return true;
            if (DB.ConvertFromDBVal<string>(dr["VAC2_Sample_Rate"]) != (string)comboAudioSampleRate3.Text) return true;
            if (DB.ConvertFromDBVal<string>(dr["VAC2_Buffer_Size"]) != (string)comboAudioBuffer3.Text) return true;
            if (DB.ConvertFromDBVal<bool>(dr["VAC2_IQ_Output"]) != (bool)chkVAC2DirectIQ.Checked) return true;
            if (DB.ConvertFromDBVal<bool>(dr["VAC2_IQ_Correct"]) != (bool)chkVAC2DirectIQCal.Checked) return true;
            if (DB.ConvertFromDBVal<bool>(dr["VAC2_Combine_Input_Channels"]) != (bool)chkVAC2Combine.Checked) return true;
            if (DB.ConvertFromDBVal<bool>(dr["VAC2_Latency_On"]) != (bool)chkVAC2LatencyManual.Checked) return true;
            if (DB.ConvertFromDBVal<int>(dr["VAC2_Latency_Duration"]) != (int)udVAC2Latency.Value) return true;

            if (DB.ConvertFromDBVal<bool>(dr["VAC2_Latency_RBOut_On"]) != (bool)chkVAC2LatencyOutManual.Checked) return true;
            if (DB.ConvertFromDBVal<int>(dr["VAC2_Latency_RBOut_Duration"]) != (int)udVAC2LatencyOut.Value) return true;
            if (DB.ConvertFromDBVal<bool>(dr["VAC2_Latency_PAIn_On"]) != (bool)chkVAC2LatencyPAInManual.Checked) return true;
            if (DB.ConvertFromDBVal<int>(dr["VAC2_Latency_PAIn_Duration"]) != (int)udVAC2LatencyPAIn.Value) return true;
            if (DB.ConvertFromDBVal<bool>(dr["VAC2_Latency_PAOut_On"]) != (bool)chkVAC2LatencyPAOutManual.Checked) return true;
            if (DB.ConvertFromDBVal<int>(dr["VAC2_Latency_PAOut_Duration"]) != (int)udVAC2LatencyPAOut.Value) return true;

            if (DB.ConvertFromDBVal<string>(dr["VAC2_AudioDriver"]) != (string)comboAudioDriver3.Text) return true;
            if (DB.ConvertFromDBVal<string>(dr["VAC2_AudioInput"]) != (string)comboAudioInput3.Text) return true;
            if (DB.ConvertFromDBVal<string>(dr["VAC2_AudioOutput"]) != (string)comboAudioOutput3.Text) return true;

            if (DB.ConvertFromDBVal<bool>(dr["VAC2_Exclusive_In"]) != (bool)chkVAC2ExclusiveIn.Checked) return true;
            if (DB.ConvertFromDBVal<bool>(dr["VAC2_Exclusive_Out"]) != (bool)chkVAC2ExclusiveOut.Checked) return true;

            if (!bOnlyVac)
            {
                if (DB.ConvertFromDBVal<string>(dr["Phone_RX_DSP_Buffer"]) != (string)comboDSPPhoneRXBuf.Text) return true;
                if (DB.ConvertFromDBVal<string>(dr["Phone_TX_DSP_Buffer"]) != (string)comboDSPPhoneTXBuf.Text) return true;
                if (DB.ConvertFromDBVal<string>(dr["FM_RX_DSP_Buffer"]) != (string)comboDSPFMRXBuf.Text) return true;
                if (DB.ConvertFromDBVal<string>(dr["FM_TX_DSP_Buffer"]) != (string)comboDSPFMTXBuf.Text) return true;
                if (DB.ConvertFromDBVal<string>(dr["Digi_RX_DSP_Buffer"]) != (string)comboDSPDigRXBuf.Text) return true;
                if (DB.ConvertFromDBVal<string>(dr["Digi_TX_DSP_Buffer"]) != (string)comboDSPDigTXBuf.Text) return true;
                if (DB.ConvertFromDBVal<string>(dr["CW_RX_DSP_Buffer"]) != (string)comboDSPCWRXBuf.Text) return true;

                if (DB.ConvertFromDBVal<string>(dr["Phone_RX_DSP_Filter_Size"]) != (string)comboDSPPhoneRXFiltSize.Text) return true;
                if (DB.ConvertFromDBVal<string>(dr["Phone_TX_DSP_Filter_Size"]) != (string)comboDSPPhoneTXFiltSize.Text) return true;
                if (DB.ConvertFromDBVal<string>(dr["FM_RX_DSP_Filter_Size"]) != (string)comboDSPFMRXFiltSize.Text) return true;
                if (DB.ConvertFromDBVal<string>(dr["FM_TX_DSP_Filter_Size"]) != (string)comboDSPFMTXFiltSize.Text) return true;
                if (DB.ConvertFromDBVal<string>(dr["Digi_RX_DSP_Filter_Size"]) != (string)comboDSPDigRXFiltSize.Text) return true;
                if (DB.ConvertFromDBVal<string>(dr["Digi_TX_DSP_Filter_Size"]) != (string)comboDSPDigTXFiltSize.Text) return true;
                if (DB.ConvertFromDBVal<string>(dr["CW_RX_DSP_Filter_Size"]) != (string)comboDSPCWRXFiltSize.Text) return true;

                if (DB.ConvertFromDBVal<string>(dr["Phone_RX_DSP_Filter_Type"]) != (string)comboDSPPhoneRXFiltType.Text) return true;
                if (DB.ConvertFromDBVal<string>(dr["Phone_TX_DSP_Filter_Type"]) != (string)comboDSPPhoneTXFiltType.Text) return true;
                if (DB.ConvertFromDBVal<string>(dr["FM_RX_DSP_Filter_Type"]) != (string)comboDSPFMRXFiltType.Text) return true;
                if (DB.ConvertFromDBVal<string>(dr["FM_TX_DSP_Filter_Type"]) != (string)comboDSPFMTXFiltType.Text) return true;
                if (DB.ConvertFromDBVal<string>(dr["Digi_RX_DSP_Filter_Type"]) != (string)comboDSPDigRXFiltType.Text) return true;
                if (DB.ConvertFromDBVal<string>(dr["Digi_TX_DSP_Filter_Type"]) != (string)comboDSPDigTXFiltType.Text) return true;
                if (DB.ConvertFromDBVal<string>(dr["CW_RX_DSP_Filter_Type"]) != (string)comboDSPCWRXFiltType.Text) return true;

                if (DB.ConvertFromDBVal<bool>(dr["Mic_Input_On"]) != (bool)radMicIn.Checked) return true;
                if (DB.ConvertFromDBVal<bool>(dr["Mic_Input_Boost"]) != (bool)chk20dbMicBoost.Checked) return true;
                if (DB.ConvertFromDBVal<bool>(dr["Line_Input_On"]) != (bool)radLineIn.Checked) return true;
                if (DB.ConvertFromDBVal<decimal>(dr["Line_Input_Level"]) != udLineInBoost.Value) return true;
                if (DB.ConvertFromDBVal<bool>(dr["CESSB_On"]) != chkDSPCESSB.Checked) return true;
                if (DB.ConvertFromDBVal<bool>(dr["Pure_Signal_Enabled"]) != console.PureSignalEnabled) return true;

                //
                if (DB.ConvertFromDBVal<decimal>(dr["FM_RX_AFFilter_Low"]) != (decimal)udFMLowCutRX.Value) return true;
                if (DB.ConvertFromDBVal<decimal>(dr["FM_RX_AFFilter_High"]) != (decimal)udFMHighCutRX.Value) return true;
                if (DB.ConvertFromDBVal<decimal>(dr["FM_TX_AFFilter_Low"]) != (decimal)udFMLowCutTX.Value) return true;
                if (DB.ConvertFromDBVal<decimal>(dr["FM_TX_AFFilter_High"]) != (decimal)udFMHighCutTX.Value) return true;
                if (DB.ConvertFromDBVal<bool>(dr["VAC1_Force_In"]) != (bool)chkVAC1_Force2.Checked) return true;  // note in is force2, and out is force
                if (DB.ConvertFromDBVal<bool>(dr["VAC1_Force_Out"]) != (bool)chkVAC1_Force.Checked) return true;
                if (DB.ConvertFromDBVal<bool>(dr["VAC2_Force_In"]) != (bool)chkVAC2_Force2.Checked) return true;
                if (DB.ConvertFromDBVal<bool>(dr["VAC2_Force_Out"]) != (bool)chkVAC2_Force.Checked) return true;
                if (DB.ConvertFromDBVal<bool>(dr["VAC1_SwapIQ"]) != (bool)chkSwapIQVac1.Checked) return true;
                if (DB.ConvertFromDBVal<bool>(dr["VAC2_SwapIQ"]) != (bool)chkSwapIQVac2.Checked) return true;
                if (DB.ConvertFromDBVal<bool>(dr["Audio_Disable_Audio_Amp"]) != (bool)chkDisableRearSpeakerJacksAudioAmplifier.Checked) return true;
                if (DB.ConvertFromDBVal<string>(dr["PA_Profile"]) != (string)comboPAProfile.Text) return true;
                if (DB.ConvertFromDBVal<bool>(dr["RXEQEnabled"]) != console.EQForm.RXEQEnabled) return true;
                int[] rxeq = console.EQForm.RXEQ;
                if (DB.ConvertFromDBVal<int>(dr["RXEQPreamp"]) != rxeq[0]) return true;
                for (int i = 1; i < rxeq.Length; i++)
                    if (DB.ConvertFromDBVal<int>(dr["RXEQ" + i.ToString()]) != rxeq[i]) return true;
                if (DB.ConvertFromDBVal<bool>(dr["VAC1_Exclusive_In"]) != (bool)chkVAC1ExclusiveIn.Checked) return true;
                if (DB.ConvertFromDBVal<bool>(dr["VAC1_Exclusive_Out"]) != (bool)chkVAC1ExclusiveOut.Checked) return true;
                if (DB.ConvertFromDBVal<bool>(dr["VAC2_Exclusive_In"]) != (bool)chkVAC2ExclusiveIn.Checked) return true;
                if (DB.ConvertFromDBVal<bool>(dr["VAC2_Exclusive_Out"]) != (bool)chkVAC2ExclusiveOut.Checked) return true;
                //

                //CFC
                if (DB.ConvertFromDBVal<bool>(dr["CFCEnabled"]) != chkCFCEnable.Checked) return true;
                if (DB.ConvertFromDBVal<bool>(dr["CFCPostEqEnabled"]) != chkCFCPeqEnable.Checked) return true;
                if (DB.ConvertFromDBVal<bool>(dr["CFCPhaseRotatorEnabled"]) != chkPHROTEnable.Checked) return true;
                if (DB.ConvertFromDBVal<bool>(dr["CFCPhaseReverseEnabled"]) != chkPHROTReverse.Checked) return true;
                if (DB.ConvertFromDBVal<int>(dr["CFCPhaseRotatorFreq"]) != (int)udPhRotFreq.Value) return true;
                if (DB.ConvertFromDBVal<int>(dr["CFCPhaseRotatorStages"]) != (int)udPHROTStages.Value) return true;
                int[] cfceq = CFCCOMPEQ;
                if (DB.ConvertFromDBVal<int>(dr["CFCPreComp"]) != cfceq[0]) return true;
                for (int i = 1; i < 11; i++)
                    if (DB.ConvertFromDBVal<int>(dr["CFCPreComp" + (i - 1).ToString()]) != cfceq[i]) return true;
                if (DB.ConvertFromDBVal<int>(dr["CFCPostEqGain"]) != cfceq[11]) return true;
                for (int i = 12; i < 22; i++)
                    if (DB.ConvertFromDBVal<int>(dr["CFCPostEqGain" + (i - 12).ToString()]) != cfceq[i]) return true;
                for (int i = 22; i < 32; i++)
                    if (DB.ConvertFromDBVal<int>(dr["CFCEqFreq" + (i - 22).ToString()]) != cfceq[i]) return true;
            }

            return false;
        }

        private void highlightTXProfileSaveItems(bool bHighlight)
        {
            if (initializing) return;

            Common.HightlightControl(udTXFilterLow, bHighlight);
            Common.HightlightControl(udTXFilterHigh, bHighlight);

            console.EQForm.HighlightTXProfileSaveItems(bHighlight);
            console.HighlightTXProfileSaveItems(bHighlight);

            Common.HightlightControl(chkDSPLevelerEnabled, bHighlight);
            Common.HightlightControl(udDSPLevelerSlope, bHighlight);
            Common.HightlightControl(udDSPLevelerThreshold, bHighlight);
            Common.HightlightControl(udDSPLevelerAttack, bHighlight);
            Common.HightlightControl(udDSPLevelerDecay, bHighlight);
            Common.HightlightControl(udDSPLevelerHangTime, bHighlight);
            Common.HightlightControl(tbDSPLevelerHangThreshold, bHighlight);

            Common.HightlightControl(udDSPALCSlope, bHighlight);
            Common.HightlightControl(udDSPALCMaximumGain, bHighlight);
            Common.HightlightControl(udDSPALCAttack, bHighlight);
            Common.HightlightControl(udDSPALCDecay, bHighlight);
            Common.HightlightControl(udDSPALCHangTime, bHighlight);
            Common.HightlightControl(tbDSPALCHangThreshold, bHighlight);

            Common.HightlightControl(chkVOXEnable, bHighlight);
            Common.HightlightControl(chkDEXPEnable, bHighlight);
            Common.HightlightControl(udDEXPThreshold, bHighlight);
            Common.HightlightControl(udDEXPAttack, bHighlight);
            Common.HightlightControl(udDEXPHold, bHighlight);
            Common.HightlightControl(udDEXPRelease, bHighlight);
            Common.HightlightControl(udDEXPExpansionRatio, bHighlight);
            Common.HightlightControl(udDEXPHysteresisRatio, bHighlight);
            Common.HightlightControl(udDEXPDetTau, bHighlight);
            Common.HightlightControl(chkSCFEnable, bHighlight);
            Common.HightlightControl(udSCFLowCut, bHighlight);
            Common.HightlightControl(udSCFHighCut, bHighlight);
            Common.HightlightControl(chkDEXPLookAheadEnable, bHighlight);
            Common.HightlightControl(udDEXPLookAhead, bHighlight);

            Common.HightlightControl(udTXAF, bHighlight);

            Common.HightlightControl(udTXAMCarrierLevel, bHighlight);

            Common.HightlightControl(chkAudioEnableVAC, bHighlight);
            Common.HightlightControl(chkAudioVACAutoEnable, bHighlight);
            Common.HightlightControl(udAudioVACGainRX, bHighlight);
            Common.HightlightControl(udAudioVACGainTX, bHighlight);
            Common.HightlightControl(chkAudio2Stereo, bHighlight);
            Common.HightlightControl(comboAudioSampleRate2, bHighlight);
            Common.HightlightControl(comboAudioBuffer2, bHighlight);
            Common.HightlightControl(chkAudioIQtoVAC, bHighlight);
            Common.HightlightControl(chkAudioCorrectIQ, bHighlight);
            Common.HightlightControl(chkVACAllowBypass, bHighlight);
            Common.HightlightControl(chkVACCombine, bHighlight);
            Common.HightlightControl(chkAudioLatencyManual2, bHighlight);
            Common.HightlightControl(udAudioLatency2, bHighlight);

            Common.HightlightControl(chkAudioLatencyManual2_Out, bHighlight);
            Common.HightlightControl(udAudioLatency2_Out, bHighlight);
            Common.HightlightControl(chkAudioLatencyPAInManual, bHighlight);
            Common.HightlightControl(udAudioLatencyPAIn, bHighlight);
            Common.HightlightControl(chkAudioLatencyPAOutManual, bHighlight);
            Common.HightlightControl(udAudioLatencyPAOut, bHighlight);

            Common.HightlightControl(comboAudioDriver2, bHighlight);
            Common.HightlightControl(comboAudioInput2, bHighlight);
            Common.HightlightControl(comboAudioOutput2, bHighlight);

            Common.HightlightControl(chkVAC2Enable, bHighlight);
            Common.HightlightControl(chkVAC2AutoEnable, bHighlight);
            Common.HightlightControl(udVAC2GainRX, bHighlight);
            Common.HightlightControl(udVAC2GainTX, bHighlight);
            Common.HightlightControl(chkAudioStereo3, bHighlight);
            Common.HightlightControl(comboAudioSampleRate3, bHighlight);
            Common.HightlightControl(comboAudioBuffer3, bHighlight);
            Common.HightlightControl(chkVAC2DirectIQ, bHighlight);
            Common.HightlightControl(chkVAC2DirectIQCal, bHighlight);
            Common.HightlightControl(chkVAC2Combine, bHighlight);
            Common.HightlightControl(chkVAC2LatencyManual, bHighlight);
            Common.HightlightControl(udVAC2Latency, bHighlight);

            Common.HightlightControl(chkVAC2LatencyOutManual, bHighlight);
            Common.HightlightControl(udVAC2LatencyOut, bHighlight);
            Common.HightlightControl(chkVAC2LatencyPAInManual, bHighlight);
            Common.HightlightControl(udVAC2LatencyPAIn, bHighlight);
            Common.HightlightControl(chkVAC2LatencyPAOutManual, bHighlight);
            Common.HightlightControl(udVAC2LatencyPAOut, bHighlight);

            Common.HightlightControl(comboAudioDriver3, bHighlight);
            Common.HightlightControl(comboAudioInput3, bHighlight);
            Common.HightlightControl(comboAudioOutput3, bHighlight);

            Common.HightlightControl(comboDSPPhoneRXBuf, bHighlight);
            Common.HightlightControl(comboDSPPhoneTXBuf, bHighlight);
            Common.HightlightControl(comboDSPFMRXBuf, bHighlight);
            Common.HightlightControl(comboDSPFMTXBuf, bHighlight);
            Common.HightlightControl(comboDSPDigRXBuf, bHighlight);
            Common.HightlightControl(comboDSPDigTXBuf, bHighlight);
            Common.HightlightControl(comboDSPCWRXBuf, bHighlight);

            Common.HightlightControl(comboDSPPhoneRXFiltSize, bHighlight);
            Common.HightlightControl(comboDSPPhoneTXFiltSize, bHighlight);
            Common.HightlightControl(comboDSPFMRXFiltSize, bHighlight);
            Common.HightlightControl(comboDSPFMTXFiltSize, bHighlight);
            Common.HightlightControl(comboDSPDigRXFiltSize, bHighlight);
            Common.HightlightControl(comboDSPDigTXFiltSize, bHighlight);
            Common.HightlightControl(comboDSPCWRXFiltSize, bHighlight);

            Common.HightlightControl(comboDSPPhoneRXFiltType, bHighlight);
            Common.HightlightControl(comboDSPPhoneTXFiltType, bHighlight);
            Common.HightlightControl(comboDSPFMRXFiltType, bHighlight);
            Common.HightlightControl(comboDSPFMTXFiltType, bHighlight);
            Common.HightlightControl(comboDSPDigRXFiltType, bHighlight);
            Common.HightlightControl(comboDSPDigTXFiltType, bHighlight);
            Common.HightlightControl(comboDSPCWRXFiltType, bHighlight);

            Common.HightlightControl(radMicIn, bHighlight);
            Common.HightlightControl(chk20dbMicBoost, bHighlight);
            Common.HightlightControl(radLineIn, bHighlight);
            Common.HightlightControl(udLineInBoost, bHighlight);
            Common.HightlightControl(chkDSPCESSB, bHighlight);

            //
            Common.HightlightControl(udFMLowCutRX, bHighlight);
            Common.HightlightControl(udFMHighCutRX, bHighlight);
            Common.HightlightControl(udFMLowCutTX, bHighlight);
            Common.HightlightControl(udFMHighCutTX, bHighlight);
            Common.HightlightControl(chkVAC1_Force2, bHighlight);  // note in is force2, and out is force
            Common.HightlightControl(chkVAC1_Force, bHighlight);
            Common.HightlightControl(chkVAC2_Force2, bHighlight);
            Common.HightlightControl(chkVAC2_Force, bHighlight);
            Common.HightlightControl(chkSwapIQVac1, bHighlight);
            Common.HightlightControl(chkSwapIQVac2, bHighlight);
            Common.HightlightControl(chkDisableRearSpeakerJacksAudioAmplifier, bHighlight);
            Common.HightlightControl(comboPAProfile, bHighlight);
            Common.HightlightControl(chkVAC1ExclusiveIn, bHighlight);
            Common.HightlightControl(chkVAC1ExclusiveOut, bHighlight);
            Common.HightlightControl(chkVAC2ExclusiveIn, bHighlight);
            Common.HightlightControl(chkVAC2ExclusiveOut, bHighlight);
            //

            //CFC
            Common.HightlightControl(chkCFCEnable, bHighlight);
            Common.HightlightControl(chkCFCPeqEnable, bHighlight);
            Common.HightlightControl(chkPHROTEnable, bHighlight);
            Common.HightlightControl(udPhRotFreq, bHighlight);
            Common.HightlightControl(udPHROTStages, bHighlight);
            Common.HightlightControl(chkPHROTReverse, bHighlight);

            Common.HightlightControl(tbCFCPRECOMP, bHighlight);
            Common.HightlightControl(tbCFC0, bHighlight);
            Common.HightlightControl(tbCFC1, bHighlight);
            Common.HightlightControl(tbCFC2, bHighlight);
            Common.HightlightControl(tbCFC3, bHighlight);
            Common.HightlightControl(tbCFC4, bHighlight);
            Common.HightlightControl(tbCFC5, bHighlight);
            Common.HightlightControl(tbCFC6, bHighlight);
            Common.HightlightControl(tbCFC7, bHighlight);
            Common.HightlightControl(tbCFC8, bHighlight);
            Common.HightlightControl(tbCFC9, bHighlight);

            Common.HightlightControl(tbCFCPEQGAIN, bHighlight);
            Common.HightlightControl(tbCFCEQ0, bHighlight);
            Common.HightlightControl(tbCFCEQ1, bHighlight);
            Common.HightlightControl(tbCFCEQ2, bHighlight);
            Common.HightlightControl(tbCFCEQ3, bHighlight);
            Common.HightlightControl(tbCFCEQ4, bHighlight);
            Common.HightlightControl(tbCFCEQ5, bHighlight);
            Common.HightlightControl(tbCFCEQ6, bHighlight);
            Common.HightlightControl(tbCFCEQ7, bHighlight);
            Common.HightlightControl(tbCFCEQ8, bHighlight);
            Common.HightlightControl(tbCFCEQ9, bHighlight);

            Common.HightlightControl(udCFC0, bHighlight);
            Common.HightlightControl(udCFC1, bHighlight);
            Common.HightlightControl(udCFC2, bHighlight);
            Common.HightlightControl(udCFC3, bHighlight);
            Common.HightlightControl(udCFC4, bHighlight);
            Common.HightlightControl(udCFC5, bHighlight);
            Common.HightlightControl(udCFC6, bHighlight);
            Common.HightlightControl(udCFC7, bHighlight);
            Common.HightlightControl(udCFC8, bHighlight);
            Common.HightlightControl(udCFC9, bHighlight);
        }

        private void updateTXProfileInDB(DataRow dr)
        {
            if (dr == null) return;

            dr["FilterLow"] = (int)udTXFilterLow.Value;
            dr["FilterHigh"] = (int)udTXFilterHigh.Value;
            dr["TXEQNumBands"] = console.EQForm.NumBands;
            dr["TXEQEnabled"] = console.EQForm.TXEQEnabled;
            int[] eq = console.EQForm.TXEQ;
            dr["TXEQPreamp"] = eq[0];
            for (int i = 1; i < 11; i++)
                dr["TXEQ" + i.ToString()] = eq[i];
            for (int i = 11; i < 21; i++)
                dr["TxEqFreq" + (i - 10).ToString()] = eq[i];

            dr["DXOn"] = console.DX;

            dr["CompanderOn"] = console.CPDR;
            dr["CompanderLevel"] = console.CPDRLevel;
            dr["MicGain"] = console.Mic;
            dr["FMMicGain"] = console.FMMic;
            dr["MicMute"] = console.MicMute;

            dr["Lev_On"] = chkDSPLevelerEnabled.Checked;
            dr["Lev_Slope"] = (int)udDSPLevelerSlope.Value;
            dr["Lev_MaxGain"] = (int)udDSPLevelerThreshold.Value;
            dr["Lev_Attack"] = (int)udDSPLevelerAttack.Value;
            dr["Lev_Decay"] = (int)udDSPLevelerDecay.Value;
            dr["Lev_Hang"] = (int)udDSPLevelerHangTime.Value;
            dr["Lev_HangThreshold"] = tbDSPLevelerHangThreshold.Value;

            dr["ALC_Slope"] = (int)udDSPALCSlope.Value;
            dr["ALC_MaximumGain"] = (int)udDSPALCMaximumGain.Value;
            dr["ALC_Attack"] = (int)udDSPALCAttack.Value;
            dr["ALC_Decay"] = (int)udDSPALCDecay.Value;
            dr["ALC_Hang"] = (int)udDSPALCHangTime.Value;
            dr["ALC_HangThreshold"] = tbDSPALCHangThreshold.Value;

            dr["Power"] = console.PWR;

            dr["VOX_On"] = (bool)chkVOXEnable.Checked;
            dr["Dexp_On"] = (bool)chkDEXPEnable.Checked;
            dr["Dexp_Threshold"] = (int)udDEXPThreshold.Value;
            dr["Dexp_Attack"] = (int)udDEXPAttack.Value;
            dr["VOX_HangTime"] = (int)udDEXPHold.Value;
            dr["Dexp_Release"] = (int)udDEXPRelease.Value;
            dr["Dexp_Attenuate"] = udDEXPExpansionRatio.Value;
            dr["Dexp_Hysterisis"] = udDEXPHysteresisRatio.Value;
            dr["Dexp_Tau"] = (int)udDEXPDetTau.Value;
            dr["Dexp_SCF_On"] = (bool)chkSCFEnable.Checked;
            dr["Dexp_SCF_Low"] = (int)udSCFLowCut.Value;
            dr["Dexp_SCF_High"] = (int)udSCFHighCut.Value;
            dr["Dexp_LookAhead_On"] = (bool)chkDEXPLookAheadEnable.Checked;
            dr["Dexp_LookAhead"] = (int)udDEXPLookAhead.Value;

            dr["TX_AF_Level"] = console.TXAF;

            dr["AM_Carrier_Level"] = (int)udTXAMCarrierLevel.Value;

            dr["Show_TX_Filter"] = (bool)console.ShowTXFilter;

            dr["VAC1_On"] = (bool)chkAudioEnableVAC.Checked;
            dr["VAC1_Auto_On"] = (bool)chkAudioVACAutoEnable.Checked;
            dr["VAC1_RX_GAIN"] = (int)udAudioVACGainRX.Value;
            dr["VAC1_TX_GAIN"] = (int)udAudioVACGainTX.Value;
            dr["VAC1_Stereo_On"] = (bool)chkAudio2Stereo.Checked;
            dr["VAC1_Sample_Rate"] = (string)comboAudioSampleRate2.Text;
            dr["VAC1_Buffer_Size"] = (string)comboAudioBuffer2.Text;
            dr["VAC1_IQ_Output"] = (bool)chkAudioIQtoVAC.Checked;
            dr["VAC1_IQ_Correct"] = (bool)chkAudioCorrectIQ.Checked;
            dr["VAC1_PTT_OverRide"] = (bool)chkVACAllowBypass.Checked;
            dr["VAC1_Combine_Input_Channels"] = (bool)chkVACCombine.Checked;
            dr["VAC1_Latency_On"] = (bool)chkAudioLatencyManual2.Checked;
            dr["VAC1_Latency_Duration"] = (int)udAudioLatency2.Value;

            dr["VAC1_Latency_RBOut_On"] = (bool)chkAudioLatencyManual2_Out.Checked;
            dr["VAC1_Latency_RBOut_Duration"] = (int)udAudioLatency2_Out.Value;
            dr["VAC1_Latency_PAIn_On"] = (bool)chkAudioLatencyPAInManual.Checked;
            dr["VAC1_Latency_PAIn_Duration"] = (int)udAudioLatencyPAIn.Value;
            dr["VAC1_Latency_PAOut_On"] = (bool)chkAudioLatencyPAOutManual.Checked;
            dr["VAC1_Latency_PAOut_Duration"] = (int)udAudioLatencyPAOut.Value;

            dr["VAC1_AudioDriver"] = (string)comboAudioDriver2.Text;
            dr["VAC1_AudioInput"] = (string)comboAudioInput2.Text;
            dr["VAC1_AudioOutput"] = (string)comboAudioOutput2.Text;

            dr["VAC2_On"] = (bool)chkVAC2Enable.Checked;
            dr["VAC2_Auto_On"] = (bool)chkVAC2AutoEnable.Checked;
            dr["VAC2_RX_GAIN"] = (int)udVAC2GainRX.Value;
            dr["VAC2_TX_GAIN"] = (int)udVAC2GainTX.Value;
            dr["VAC2_Stereo_On"] = (bool)chkAudioStereo3.Checked;
            dr["VAC2_Sample_Rate"] = (string)comboAudioSampleRate3.Text;
            dr["VAC2_Buffer_Size"] = (string)comboAudioBuffer3.Text;
            dr["VAC2_IQ_Output"] = (bool)chkVAC2DirectIQ.Checked;
            dr["VAC2_IQ_Correct"] = (bool)chkVAC2DirectIQCal.Checked;
            dr["VAC2_Combine_Input_Channels"] = (bool)chkVAC2Combine.Checked;
            dr["VAC2_Latency_On"] = (bool)chkVAC2LatencyManual.Checked;
            dr["VAC2_Latency_Duration"] = (int)udVAC2Latency.Value;

            dr["VAC2_Latency_RBOut_On"] = (bool)chkVAC2LatencyOutManual.Checked;
            dr["VAC2_Latency_RBOut_Duration"] = (int)udVAC2LatencyOut.Value;
            dr["VAC2_Latency_PAIn_On"] = (bool)chkVAC2LatencyPAInManual.Checked;
            dr["VAC2_Latency_PAIn_Duration"] = (int)udVAC2LatencyPAIn.Value;
            dr["VAC2_Latency_PAOut_On"] = (bool)chkVAC2LatencyPAOutManual.Checked;
            dr["VAC2_Latency_PAOut_Duration"] = (int)udVAC2LatencyPAOut.Value;

            dr["VAC2_AudioDriver"] = (string)comboAudioDriver3.Text;
            dr["VAC2_AudioInput"] = (string)comboAudioInput3.Text;
            dr["VAC2_AudioOutput"] = (string)comboAudioOutput3.Text;

            dr["Phone_RX_DSP_Buffer"] = (string)comboDSPPhoneRXBuf.Text;
            dr["Phone_TX_DSP_Buffer"] = (string)comboDSPPhoneTXBuf.Text;
            dr["FM_RX_DSP_Buffer"] = (string)comboDSPFMRXBuf.Text;
            dr["FM_TX_DSP_Buffer"] = (string)comboDSPFMTXBuf.Text;
            dr["Digi_RX_DSP_Buffer"] = (string)comboDSPDigRXBuf.Text;
            dr["Digi_TX_DSP_Buffer"] = (string)comboDSPDigTXBuf.Text;
            dr["CW_RX_DSP_Buffer"] = (string)comboDSPCWRXBuf.Text;

            dr["Phone_RX_DSP_Filter_Size"] = (string)comboDSPPhoneRXFiltSize.Text;
            dr["Phone_TX_DSP_Filter_Size"] = (string)comboDSPPhoneTXFiltSize.Text;
            dr["FM_RX_DSP_Filter_Size"] = (string)comboDSPFMRXFiltSize.Text;
            dr["FM_TX_DSP_Filter_Size"] = (string)comboDSPFMTXFiltSize.Text;
            dr["Digi_RX_DSP_Filter_Size"] = (string)comboDSPDigRXFiltSize.Text;
            dr["Digi_TX_DSP_Filter_Size"] = (string)comboDSPDigTXFiltSize.Text;
            dr["CW_RX_DSP_Filter_Size"] = (string)comboDSPCWRXFiltSize.Text;

            dr["Phone_RX_DSP_Filter_Type"] = (string)comboDSPPhoneRXFiltType.Text;
            dr["Phone_TX_DSP_Filter_Type"] = (string)comboDSPPhoneTXFiltType.Text;
            dr["FM_RX_DSP_Filter_Type"] = (string)comboDSPFMRXFiltType.Text;
            dr["FM_TX_DSP_Filter_Type"] = (string)comboDSPFMTXFiltType.Text;
            dr["Digi_RX_DSP_Filter_Type"] = (string)comboDSPDigRXFiltType.Text;
            dr["Digi_TX_DSP_Filter_Type"] = (string)comboDSPDigTXFiltType.Text;
            dr["CW_RX_DSP_Filter_Type"] = (string)comboDSPCWRXFiltType.Text;

            dr["Mic_Input_On"] = (bool)radMicIn.Checked;
            dr["Mic_Input_Boost"] = (bool)chk20dbMicBoost.Checked;
            dr["Line_Input_On"] = (bool)radLineIn.Checked;
            dr["Line_Input_Level"] = (decimal)udLineInBoost.Value;
            dr["CESSB_On"] = (bool)chkDSPCESSB.Checked;
            dr["Pure_Signal_Enabled"] = (bool)console.PureSignalEnabled;

            //
            dr["FM_RX_AFFilter_Low"] = (decimal)udFMLowCutRX.Value;
            dr["FM_RX_AFFilter_High"] = (decimal)udFMHighCutRX.Value;
            dr["FM_TX_AFFilter_Low"] = (decimal)udFMLowCutTX.Value;
            dr["FM_TX_AFFilter_High"] = (decimal)udFMHighCutTX.Value;
            dr["VAC1_Force_In"] = (bool)chkVAC1_Force2.Checked;  // note in is force2, and out is force
            dr["VAC1_Force_Out"] = (bool)chkVAC1_Force.Checked;
            dr["VAC2_Force_In"] = (bool)chkVAC2_Force2.Checked;
            dr["VAC2_Force_Out"] = (bool)chkVAC2_Force.Checked;
            dr["VAC1_SwapIQ"] = (bool)chkSwapIQVac1.Checked;
            dr["VAC2_SwapIQ"] = (bool)chkSwapIQVac2.Checked;
            dr["Audio_Disable_Audio_Amp"] = (bool)chkDisableRearSpeakerJacksAudioAmplifier.Checked;
            dr["PA_Profile"] = (string)comboPAProfile.Text;
            dr["RXEQEnabled"] = console.EQForm.RXEQEnabled;
            int[] rxeq = console.EQForm.RXEQ;
            dr["RXEQPreamp"] = rxeq[0];
            for (int i = 1; i < rxeq.Length; i++)
                dr["RXEQ" + i.ToString()] = rxeq[i];
            dr["VAC1_Exclusive_In"] = (bool)chkVAC1ExclusiveIn.Checked;
            dr["VAC1_Exclusive_Out"] = (bool)chkVAC1ExclusiveOut.Checked;
            dr["VAC2_Exclusive_In"] = (bool)chkVAC2ExclusiveIn.Checked;
            dr["VAC2_Exclusive_Out"] = (bool)chkVAC2ExclusiveOut.Checked;
            //

            //CFC
            dr["CFCEnabled"] = (bool)chkCFCEnable.Checked;
            dr["CFCPostEqEnabled"] = (bool)chkCFCPeqEnable.Checked;
            dr["CFCPhaseRotatorEnabled"] = (bool)chkPHROTEnable.Checked;
            dr["CFCPhaseReverseEnabled"] = (bool)chkPHROTReverse.Checked;
            dr["CFCPhaseRotatorFreq"] = (int)udPhRotFreq.Value;
            dr["CFCPhaseRotatorStages"] = (int)udPHROTStages.Value;
            int[] cfceq = CFCCOMPEQ;
            dr["CFCPreComp"] = cfceq[0];
            for (int i = 1; i < 11; i++)
                dr["CFCPreComp" + (i - 1).ToString()] = cfceq[i];
            dr["CFCPostEqGain"] = cfceq[11];
            for (int i = 12; i < 22; i++)
                dr["CFCPostEqGain" + (i - 12).ToString()] = cfceq[i];
            for (int i = 22; i < 32; i++)
                dr["CFCEqFreq" + (i - 22).ToString()] = cfceq[i];
        }

        public void SaveTXProfileData()
        {
            if (profile_deleted == true)
            {
                profile_deleted = false;
                return;
            }

            string name = current_profile;

            DataRow dr = null;

            foreach (DataRow dd in from DataRow d in DB.ds.Tables["TXProfile"].Rows where (string)d["Name"] == name select d)
            {
                dr = dd;
                break;
            }

            if (dr == null)
            {
                DialogResult dres = MessageBox.Show(
                    "Unable to find txprofile in the database for name [" + name + "] in SaveTXProfileData()",
                    "Missing TX Profile Table",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST);
            }
            else
            {
                updateTXProfileInDB(dr); //MW0LGE_21a remove duplication
            }
        }

        public void UpdateWaterfallBandInfo()
        {
            if (!initializing)
            {
                //MW0LGE_21e
                txtWaterFallBandLevel.Text = BandStackManager.BandToString(console.RX1Band);
                txtRX2WaterFallBandLevel.Text = BandStackManager.BandToString(console.RX2Band);
            }
        }

        public void UpdateDisplayGridBandInfo()
        {
            if (!initializing)
            {
                //MW0LGE_21e
                txtDisplayGridBandLevel.Text = BandStackManager.BandToString(console.RX1Band);
                txtRX2DisplayGridBandLevel.Text = BandStackManager.BandToString(console.RX2Band);
            }
        }

        public void UpdateTXDisplayFFT()
        {
            tbTXDisplayFFTSize_Scroll(this, EventArgs.Empty);
        }

        #endregion

        #region Properties


        public FocusMasterMode FocusMasterMode
        {
            set
            {
                switch (value)
                {
                    case FocusMasterMode.None:
                        comboFocusMasterMode.Text = "None";
                        break;
                    case FocusMasterMode.Logger:
                        comboFocusMasterMode.Text = "N1MM+ Logger";
                        break;
                    case FocusMasterMode.Click:
                        comboFocusMasterMode.Text = "Select by Click";
                        break;
                    case FocusMasterMode.Title:
                        comboFocusMasterMode.Text = "Enter Window Title";
                        break;
                }
            }
        }

        public string FocusMasterTitle
        {
            set
            {
                txtFocusMasterWinTitle.Text = value;
            }
        }

        public bool EnableRX1APFControl
        {
            set
            {
                chkDSPRX1APFEnable.Enabled = value;
                chkDSPRX1subAPFEnable.Enabled = value;
            }
        }

        public bool EnableRX2APFControl
        {
            set
            {
                chkDSPRX2APFEnable.Enabled = value;
            }
        }

        public float RX6mGainOffset
        {
            get
            {
                if (ud6mLNAGainOffset != null) return (float)ud6mLNAGainOffset.Value;
                else return -1;
            }
            set
            {
                if (ud6mLNAGainOffset != null) ud6mLNAGainOffset.Value = (decimal)value;
            }
        }

        public bool AlexTRRelay
        {
            get
            {
                if (chkHFTRRelay != null) return chkHFTRRelay.Checked;
                else return false;
            }
            set
            {
                if (chkHFTRRelay != null)
                    chkHFTRRelay.Checked = value;
            }
        }

        public bool RX1EnableAtt
        {
            get
            {
                if (chkHermesStepAttenuator != null) return chkHermesStepAttenuator.Checked;
                else return false;
            }
            set
            {
                if (chkHermesStepAttenuator != null) chkHermesStepAttenuator.Checked = value;
            }
        }

        public int ATTOnRX1
        {
            get
            {
                if (udHermesStepAttenuatorData != null) return (int)udHermesStepAttenuatorData.Value;
                else return -1;
            }
            set
            {
                if (udHermesStepAttenuatorData != null)
                {
                    if (udHermesStepAttenuatorData.Value == value)
                        udHermesStepAttenuatorData_ValueChanged(this, EventArgs.Empty); //[2.10.3.6] no event will fire if the same, so force it
                    else
                        udHermesStepAttenuatorData.Value = value;
                }
            }
        }
        public int ATTOnRX2
        {
            get
            {
                if (udHermesStepAttenuatorDataRX2 != null) return (int)udHermesStepAttenuatorDataRX2.Value;
                else return -1;
            }
            set
            {
                if (udHermesStepAttenuatorDataRX2 != null)
                {
                    if (udHermesStepAttenuatorDataRX2.Value == value)
                        udHermesStepAttenuatorDataRX2_ValueChanged(this, EventArgs.Empty); //[2.10.3.6]MW0LGE no event will fire if the same, so force it
                    else
                        udHermesStepAttenuatorDataRX2.Value = value;
                }
            }
        }
        public bool RX2EnableAtt
        {
            get
            {
                if (chkRX2StepAtt != null) return chkRX2StepAtt.Checked;
                else return false;
            }
            set
            {
                if (chkRX2StepAtt != null)
                {
                    chkRX2StepAtt.Checked = value;
                }
            }
        }
        public int ATTOnTX
        {
            get
            {
                if (udATTOnTX != null) return (int)udATTOnTX.Value;
                else return -1;
            }
            set
            {
                if (udATTOnTX != null)
                {
                    if (value > 31) value = 31;
                    if (value < 0) value = 0; //MW0LGE [2.9.0.7] added after mi0bot source review
                    lblTXattBand.Text = console.TXBand.ToString();
                    if (udATTOnTX.Value == value) //[2.10.3.6]MW0LGE no event will fire if the same, so force it
                        udATTOnTX_ValueChanged(this, EventArgs.Empty);
                    else
                        udATTOnTX.Value = value;
                }
            }
        }

        public string SerialNumber
        {
            get { return txtZZSN.Text; }

        }

        public int VACDriver
        {
            get
            {
                return comboAudioDriver2.SelectedIndex;
            }
            set
            {
                if ((comboAudioDriver2.Items.Count - 1) > value)
                {
                    comboAudioDriver2.SelectedIndex = value;
                }
            }
        }

        public int VAC2Driver
        {
            get
            {
                return comboAudioDriver3.SelectedIndex;
            }
            set
            {
                if ((comboAudioDriver3.Items.Count - 1) > value)
                {
                    comboAudioDriver3.SelectedIndex = value;
                }
            }
        }

        public int VACInputCable
        {
            get
            {
                return comboAudioInput2.SelectedIndex;
            }
            set
            {
                if ((comboAudioInput2.Items.Count - 1) > value)
                {
                    comboAudioInput2.SelectedIndex = value;
                }
            }
        }

        public int VAC2InputCable
        {
            get
            {
                return comboAudioInput3.SelectedIndex;
            }
            set
            {
                if ((comboAudioInput3.Items.Count - 1) > value)
                {
                    comboAudioInput3.SelectedIndex = value;
                }
            }
        }

        public int VACOutputCable
        {
            get
            {
                return comboAudioOutput2.SelectedIndex;
            }
            set
            {
                if ((comboAudioOutput2.Items.Count - 1) > value)
                {
                    comboAudioOutput2.SelectedIndex = value;
                }
            }
        }

        public int VAC2OutputCable
        {
            get
            {
                return comboAudioOutput3.SelectedIndex;
            }
            set
            {
                if ((comboAudioOutput3.Items.Count - 1) > value)
                {
                    comboAudioOutput3.SelectedIndex = value;
                }
            }
        }

        public bool VACUseRX2
        {
            get
            {
                if (chkAudioRX2toVAC != null && IQOutToVAC)
                {
                    return chkAudioRX2toVAC.Checked;
                }
                else return false;
            }
            set
            {
                if (chkAudioRX2toVAC != null && IQOutToVAC)
                {
                    chkAudioRX2toVAC.Checked = value;
                }
            }
        }

        public bool VAC2UseRX2
        {
            get
            {
                if (chkVAC2UseRX2 != null && IQOutToVAC)
                {
                    return chkVAC2UseRX2.Checked;
                }
                else return false;
            }
            set
            {
                if (chkVAC2UseRX2 != null && IQOutToVAC)
                {
                    chkVAC2UseRX2.Checked = value;
                }
            }
        }

        public bool CATEnabled
        {
            get
            {
                if (chkCATEnable != null) return chkCATEnable.Checked;
                else return false;
            }
            set
            {
                if (chkCATEnable != null) chkCATEnable.Checked = value;
            }
        }

        public bool CAT2Enabled
        {
            get
            {
                if (chkCAT2Enable != null) return chkCAT2Enable.Checked;
                else return false;
            }
            set
            {
                if (chkCAT2Enable != null) chkCAT2Enable.Checked = value;
            }
        }

        public bool CAT3Enabled
        {
            get
            {
                if (chkCAT3Enable != null) return chkCAT3Enable.Checked;
                else return false;
            }
            set
            {
                if (chkCAT3Enable != null) chkCAT3Enable.Checked = value;
            }
        }

        public bool CAT4Enabled
        {
            get
            {
                if (chkCAT4Enable != null) return chkCAT4Enable.Checked;
                else return false;
            }
            set
            {
                if (chkCAT4Enable != null) chkCAT4Enable.Checked = value;
            }
        }

        public bool AndromedaCATEnabled
        {
            get
            {
                if (chkEnableAndromeda != null) return chkEnableAndromeda.Checked;
                else return false;
            }
            set
            {
                if (chkEnableAndromeda != null) chkEnableAndromeda.Checked = value;
            }
        }

        public bool AriesCATEnabled
        {
            get
            {
                if (chkEnableAries != null) return chkEnableAries.Checked;
                else return false;
            }
            set
            {
                if (chkEnableAries != null) chkEnableAries.Checked = value;
            }
        }
        public bool GanymedeCATEnabled
        {
            get
            {
                if (chkEnableGanymede != null) return chkEnableGanymede.Checked;
                else return false;
            }
            set
            {
                if (chkEnableGanymede != null) chkEnableGanymede.Checked = value;
            }
        }

        public int RXAGCAttack
        {
            get
            {
                if (udDSPAGCAttack != null) return (int)udDSPAGCAttack.Value;
                else return 0;
            }
            set
            {
                if (udDSPAGCAttack != null) udDSPAGCAttack.Value = value;
            }
        }

        public int RXAGCHang
        {
            get
            {
                if (udDSPAGCHangTime != null) return (int)udDSPAGCHangTime.Value;
                else return 0;
            }
            set
            {
                if (udDSPAGCHangTime != null) udDSPAGCHangTime.Value = value;
            }
        }

        public int RXAGCDecay
        {
            get
            {
                if (udDSPAGCDecay != null) return (int)udDSPAGCDecay.Value;
                else return 0;
            }
            set
            {
                if (udDSPAGCDecay != null) udDSPAGCDecay.Value = value;
            }
        }

        public int RX2AGCAttack
        {
            get
            {
                if (udDSPAGCRX2Attack != null) return (int)udDSPAGCRX2Attack.Value;
                else return 0;
            }
            set
            {
                if (udDSPAGCRX2Attack != null) udDSPAGCRX2Attack.Value = value;
            }
        }

        public int RX2AGCHang
        {
            get
            {
                if (udDSPAGCRX2HangTime != null) return (int)udDSPAGCRX2HangTime.Value;
                else return 0;
            }
            set
            {
                if (udDSPAGCRX2HangTime != null) udDSPAGCRX2HangTime.Value = value;
            }
        }

        public int RX2AGCDecay
        {
            get
            {
                if (udDSPAGCRX2Decay != null) return (int)udDSPAGCRX2Decay.Value;
                else return 0;
            }
            set
            {
                if (udDSPAGCRX2Decay != null) udDSPAGCRX2Decay.Value = value;
            }
        }

        private float display_contrast = 1.0f;
        public float DisplayContrast
        {
            get { return display_contrast; }

            set { display_contrast = value; }
        }

        public int BreakInDelay
        {
            get
            {
                if (udCWBreakInDelay != null) return (int)udCWBreakInDelay.Value;
                else return -1;
            }
            set
            {
                if (udCWBreakInDelay != null)
                {
                    udCWBreakInDelay.Value = value;
                    udCWKeyerSemiBreakInDelay_ValueChanged(this, EventArgs.Empty);
                }
            }
        }

        public int CWPitch
        {
            get
            {
                if (udDSPCWPitch != null) return (int)udDSPCWPitch.Value;
                else return -1;
            }
            set
            {
                if (udDSPCWPitch != null) udDSPCWPitch.Value = value;
            }
        }

        public bool CWDisableMonitor
        {
            get
            {
                if (chkDSPKeyerSidetone != null) return chkDSPKeyerSidetone.Checked;
                else return false;
            }
            set
            {
                if (chkDSPKeyerSidetone != null) chkDSPKeyerSidetone.Checked = value;
            }
        }

        public bool CWIambic
        {
            get
            {
                if (chkCWKeyerIambic != null) return chkCWKeyerIambic.Checked;
                else return false;
            }
            set
            {
                if (chkCWKeyerIambic != null) chkCWKeyerIambic.Checked = value;
            }
        }

        public bool CFCEnabled
        {
            get
            {
                return chkCFCEnable.Checked;
            }
            set
            {
                if (chkCFCEnable != null)
                {
                    chkCFCEnable.Checked = value;
                }
            }
        }
        public bool CFCPEQEnabled
        {
            get
            {
                return chkCFCPeqEnable.Checked;
            }
            set
            {
                if (chkCFCPeqEnable != null)
                {
                    chkCFCPeqEnable.Checked = value;
                }
            }
        }
        public bool PhaseRotEnabled
        {
            get
            {
                return chkPHROTEnable.Checked;
            }
            set
            {
                if (chkPHROTEnable != null)
                {
                    chkPHROTEnable.Checked = value;
                }
            }
        }
        public string VACSampleRate
        {
            get
            {
                if (comboAudioSampleRate2 != null) return comboAudioSampleRate2.Text;
                else return "";
            }
            set
            {
                if (comboAudioSampleRate2 != null) comboAudioSampleRate2.Text = value;
            }
        }

        public string VAC2SampleRate
        {
            get
            {
                if (comboAudioSampleRate3 != null) return comboAudioSampleRate3.Text;
                else return "";
            }
            set
            {
                if (comboAudioSampleRate3 != null) comboAudioSampleRate3.Text = value;
            }
        }

        public string VAC1BufferSize
        {
            get
            {
                if (comboAudioBuffer2 != null)
                    return comboAudioBuffer2.Text;
                else return "";
            }
            set
            {
                if (comboAudioBuffer2 != null)
                    comboAudioBuffer2.Text = value;
            }
        }

        public string VAC2BufferSize
        {
            get
            {
                if (comboAudioBuffer3 != null)
                    return comboAudioBuffer3.Text;
                else return "";
            }
            set
            {
                if (comboAudioBuffer3 != null)
                    comboAudioBuffer3.Text = value;
            }
        }

        public bool IQOutToVAC
        {
            get
            {
                if (chkAudioIQtoVAC != null) return chkAudioIQtoVAC.Checked;
                else return false;
            }
            set
            {
                if (chkAudioIQtoVAC != null) chkAudioIQtoVAC.Checked = value;
            }
        }

        public bool VAC2DirectIQ
        {
            get
            {
                if (chkVAC2DirectIQ != null) return chkVAC2DirectIQ.Checked;
                else return false;
            }
            set
            {
                if (chkVAC2DirectIQ != null) chkVAC2DirectIQ.Checked = value;
            }
        }

        public bool VAC1Calibrate
        {
            get
            {
                if (chkAudioCorrectIQ != null) return chkAudioIQtoVAC.Checked;
                else return false;
            }
            set
            {
                if (chkAudioCorrectIQ != null) chkAudioIQtoVAC.Checked = value;
            }
        }

        public bool VAC2Calibrate
        {
            get
            {
                if (chkVAC2DirectIQCal != null) return chkVAC2DirectIQ.Checked;
                else return false;
            }
            set
            {
                if (chkVAC2DirectIQCal != null) chkVAC2DirectIQ.Checked = value;
            }
        }

        public bool VACStereo
        {
            get
            {
                if (chkAudio2Stereo != null) return chkAudio2Stereo.Checked;
                else return false;
            }
            set
            {
                if (chkAudio2Stereo != null) chkAudio2Stereo.Checked = value;
            }
        }

        public bool VAC2Stereo
        {
            get
            {
                if (chkAudioStereo3 != null) return chkAudioStereo3.Checked;
                else return false;
            }
            set
            {
                if (chkAudioStereo3 != null) chkAudioStereo3.Checked = value;
            }
        }

        public int VOXSens
        {
            get
            {
                if (udDEXPThreshold != null) return (int)udDEXPThreshold.Value;
                else return -1;
            }
            set
            {
                if (udDEXPThreshold != null) udDEXPThreshold.Value = value;
            }
        }

        public bool NoiseGateEnabled
        {
            get
            {
                if (chkDEXPEnable != null) return chkDEXPEnable.Checked;
                else return false;
            }
            set
            {
                if (chkDEXPEnable != null) chkDEXPEnable.Checked = value;
            }
        }

        public bool TXLevelerOn
        {
            get
            {
                if (chkDSPLevelerEnabled != null) return chkDSPLevelerEnabled.Checked;
                else return false;
            }
            set
            {
                if (chkDSPLevelerEnabled != null) chkDSPLevelerEnabled.Checked = value;
            }
        }

        public int VACRXGain
        {
            get
            {
                if (udAudioVACGainRX != null) return (int)udAudioVACGainRX.Value;
                else return -99;
            }
            set
            {
                if (udAudioVACGainRX != null) udAudioVACGainRX.Value = value;
            }
        }

        public int VAC2RXGain
        {
            get
            {
                if (udVAC2GainRX != null) return (int)udVAC2GainRX.Value;
                else return -99;
            }
            set
            {
                if (udVAC2GainRX != null) udVAC2GainRX.Value = value;
            }
        }

        public int VACTXGain
        {
            get
            {
                if (udAudioVACGainTX != null) return (int)udAudioVACGainTX.Value;
                else return -99;
            }
            set
            {
                if (udAudioVACGainTX != null) udAudioVACGainTX.Value = value;
            }
        }

        public int VAC2TXGain
        {
            get
            {
                if (udVAC2GainTX != null) return (int)udVAC2GainTX.Value;
                else return -99;
            }
            set
            {
                if (udVAC2GainTX != null) udVAC2GainTX.Value = value;
            }
        }

        public CheckState BreakInEnabledState
        {
            get
            {
                if (chkCWBreakInEnabled != null)
                    return chkCWBreakInEnabled.CheckState;
                else return CheckState.Unchecked;
            }
            set
            {
                if (chkCWBreakInEnabled != null)
                {
                    if (chkCWBreakInEnabled.CheckState == value) chkCWBreakInEnabled_CheckStateChanged(this, EventArgs.Empty);
                    chkCWBreakInEnabled.CheckState = value;
                }

            }
        }

        public bool RX1APFEnable
        {
            get
            {
                if (chkDSPRX1APFEnable != null)
                    return chkDSPRX1APFEnable.Checked;
                else return false;
            }
            set
            {
                if (chkDSPRX1APFEnable != null)
                {
                    chkDSPRX1APFEnable.Checked = value;
                    chkDSPRX1APFEnable_CheckedChanged(this, EventArgs.Empty);
                }
            }
        }

        public bool RX1subAPFEnable
        {
            get
            {
                if (chkDSPRX1subAPFEnable != null)
                    return chkDSPRX1subAPFEnable.Checked;
                else return false;
            }
            set
            {
                if (chkDSPRX1subAPFEnable != null)
                {
                    chkDSPRX1subAPFEnable.Checked = value;
                    chkDSPRX1subAPFEnable_CheckedChanged(this, EventArgs.Empty);
                }
            }
        }

        public bool RX2APFEnable
        {
            get
            {
                if (chkDSPRX2APFEnable != null)
                    return chkDSPRX2APFEnable.Checked;
                else return false;
            }
            set
            {
                if (chkDSPRX2APFEnable != null)
                {
                    chkDSPRX2APFEnable.Checked = value;
                    chkDSPRX2APFEnable_CheckedChanged(this, EventArgs.Empty);
                }
            }
        }

        public int RX1APFFreq
        {
            get
            {
                if (tbRX1APFTune != null) return (int)tbRX1APFTune.Value;
                else return -1;
            }
            set
            {
                if (tbRX1APFTune != null)
                {
                    tbRX1APFTune.Value = value;
                    tbRX1APFTune_Scroll(this, EventArgs.Empty);
                }
            }
        }

        public int RX1subAPFFreq
        {
            get
            {
                if (tbRX1subAPFTune != null) return (int)tbRX1subAPFTune.Value;
                else return -1;
            }
            set
            {
                if (tbRX1subAPFTune != null)
                {
                    tbRX1subAPFTune.Value = value;
                    tbRX1subAPFTune_Scroll(this, EventArgs.Empty);
                }
            }
        }

        public int RX2APFFreq
        {
            get
            {
                if (tbRX2APFTune != null) return (int)tbRX2APFTune.Value;
                else return -1;
            }
            set
            {
                if (tbRX2APFTune != null)
                {
                    tbRX2APFTune.Value = value;
                    tbRX2APFTune_Scroll(this, EventArgs.Empty);
                }
            }
        }

        public int RX1APFBandwidth
        {
            get
            {
                if (tbRX1APFBW != null) return (int)tbRX1APFBW.Value;
                else return -1;
            }
            set
            {
                if (tbRX1APFBW != null)
                {
                    tbRX1APFBW.Value = value;
                    tbRX1APFBW_Scroll(this, EventArgs.Empty);
                }
            }
        }

        public int RX1subAPFBandwidth
        {
            get
            {
                if (tbRX1subAPFBW != null) return (int)tbRX1subAPFBW.Value;
                else return -1;
            }
            set
            {
                if (tbRX1subAPFBW != null)
                {
                    tbRX1subAPFBW.Value = value;
                    tbRX1subAPFBW_Scroll(this, EventArgs.Empty);
                }
            }
        }

        public int RX2APFBandwidth
        {
            get
            {
                if (tbRX2APFBW != null) return (int)tbRX2APFBW.Value;
                else return -1;
            }
            set
            {
                if (tbRX2APFBW != null)
                {
                    tbRX2APFBW.Value = value;
                    tbRX2APFBW_Scroll(this, EventArgs.Empty);
                }
            }
        }

        public int RX1APFGain
        {
            get
            {
                if (tbDSPAudRX1APFGain != null) return tbDSPAudRX1APFGain.Value;
                else return -1;
            }
            set
            {
                if (tbDSPAudRX1APFGain != null)
                {
                    tbDSPAudRX1APFGain.Value = value;
                }
            }
        }

        public int RX1subAPFGain
        {
            get
            {
                if (tbDSPAudRX1subAPFGain != null) return tbDSPAudRX1subAPFGain.Value;
                else return -1;
            }
            set
            {
                if (tbDSPAudRX1subAPFGain != null)
                {
                    tbDSPAudRX1subAPFGain.Value = value;
                }
            }
        }

        public int RX2APFGain
        {
            get
            {
                if (tbDSPAudRX2APFGain != null) return tbDSPAudRX2APFGain.Value;
                else return -1;
            }
            set
            {
                if (tbDSPAudRX2APFGain != null)
                {
                    tbDSPAudRX2APFGain.Value = value;
                }
            }
        }

        public bool RX1APFControls
        {
            get
            {
                if (radDSPRX1APFControls != null)
                    return radDSPRX1APFControls.Checked;
                else return false;
            }
        }

        public bool RX1subAPFControls
        {
            get
            {
                if (radDSPRX1subAPFControls != null)
                    return radDSPRX1subAPFControls.Checked;
                else return false;
            }
        }

        public bool RX2APFControls
        {
            get
            {
                if (radDSPRX2APFControls != null)
                    return radDSPRX2APFControls.Checked;
                else return false;
            }
        }


        public bool VOXEnable
        {
            get
            {
                if (chkVOXEnable != null) return chkVOXEnable.Checked;
                else return false;
            }
            set
            {
                if (chkVOXEnable != null) chkVOXEnable.Checked = value;
            }
        }
        public int VOXHangTime
        {
            get
            {
                if (udDEXPHold != null) return (int)udDEXPHold.Value;
                else return 125;
            }
            set
            {
                if (udDEXPHold != null) udDEXPHold.Value = value;
            }
        }

        public int AGCMaxGain
        {
            get
            {
                if (udDSPAGCMaxGaindB != null) return (int)udDSPAGCMaxGaindB.Value;
                else return -1;
            }
            set
            {
                if (udDSPAGCMaxGaindB != null) udDSPAGCMaxGaindB.Value = value;
            }
        }

        public int AGCFixedGain
        {
            get
            {
                if (udDSPAGCFixedGaindB != null) return (int)udDSPAGCFixedGaindB.Value;
                else return -1;
            }
            set
            {
                if (udDSPAGCFixedGaindB != null) udDSPAGCFixedGaindB.Value = value;
            }
        }

        public int AGCRX2MaxGain
        {
            get
            {
                if (udDSPAGCRX2MaxGaindB != null) return (int)udDSPAGCRX2MaxGaindB.Value;
                else return -1;
            }
            set
            {
                if (udDSPAGCRX2MaxGaindB != null) udDSPAGCRX2MaxGaindB.Value = value;
            }
        }

        public int AGCRX2FixedGain
        {
            get
            {
                if (udDSPAGCRX2FixedGaindB != null) return (int)udDSPAGCRX2FixedGaindB.Value;
                else return -1;
            }
            set
            {
                if (udDSPAGCRX2FixedGaindB != null) udDSPAGCRX2FixedGaindB.Value = value;
            }
        }

        public int AGCRX2HangThreshold
        {
            get
            {
                return tbDSPAGCRX2HangThreshold.Value;
            }
            set
            {
                if (tbDSPAGCRX2HangThreshold != null)
                {
                    if (value > tbDSPAGCRX2HangThreshold.Maximum) value = (int)tbDSPAGCRX2HangThreshold.Maximum;
                    if (value < tbDSPAGCRX2HangThreshold.Minimum) value = (int)tbDSPAGCRX2HangThreshold.Minimum;

                    bool oldF1 = console.radio.GetDSPRX(1, 0).Force;

                    console.radio.GetDSPRX(1, 0).Force = true;

                    tbDSPAGCRX2HangThreshold.Value = value;
                    tbDSPAGCRX2HangThreshold_Scroll(this, EventArgs.Empty);

                    console.radio.GetDSPRX(1, 0).Force = oldF1;
                }

            }
        }

        public int AGCRX1HangThreshold
        {
            get
            {
                return tbDSPAGCHangThreshold.Value;
            }
            set
            {
                if (tbDSPAGCHangThreshold != null)
                {
                    if (value > tbDSPAGCHangThreshold.Maximum) value = (int)tbDSPAGCHangThreshold.Maximum;
                    if (value < tbDSPAGCHangThreshold.Minimum) value = (int)tbDSPAGCHangThreshold.Minimum;

                    bool oldF1 = console.radio.GetDSPRX(0, 0).Force;
                    bool oldF2 = console.radio.GetDSPRX(0, 1).Force;

                    console.radio.GetDSPRX(0, 0).Force = true;
                    console.radio.GetDSPRX(0, 1).Force = true;

                    tbDSPAGCHangThreshold.Value = value;
                    tbDSPAGCHangThreshold_Scroll(this, EventArgs.Empty);

                    console.radio.GetDSPRX(0, 0).Force = oldF1;
                    console.radio.GetDSPRX(0, 1).Force = oldF2;
                }
            }
        }

        public int DisplayFFTSize
        {
            get { return (int)tbDisplayFFTSize.Value; }
            set
            {
                if (value > tbDisplayFFTSize.Maximum) value = (int)tbDisplayFFTSize.Maximum;
                if (value < tbDisplayFFTSize.Minimum) value = (int)tbDisplayFFTSize.Minimum;
                tbDisplayFFTSize.Value = value;
                tbDisplayFFTSize_Scroll(this, EventArgs.Empty);
            }
        }

        public int TXFilterHigh
        {
            get { return (int)udTXFilterHigh.Value; }
            set
            {
                if (value > udTXFilterHigh.Maximum) value = (int)udTXFilterHigh.Maximum;
                if (value < udTXFilterHigh.Minimum) value = (int)udTXFilterHigh.Minimum;
                udTXFilterHigh.Value = value;
            }
        }

        public int TXFilterLow
        {
            get { return (int)udTXFilterLow.Value; }
            set
            {
                if (value > udTXFilterLow.Maximum) value = (int)udTXFilterLow.Maximum;
                if (value < udTXFilterLow.Minimum) value = (int)udTXFilterLow.Minimum;
                udTXFilterLow.Value = value;
            }
        }

        public int TXFilterHighSave
        {
            get { return (int)udTXFilterHighSave.Value; }
            set
            {
                if (console.TXBand != Band.B60M)
                {
                    if (value > udTXFilterHighSave.Maximum) value = (int)udTXFilterHighSave.Maximum;
                    if (value < udTXFilterHighSave.Minimum) value = (int)udTXFilterHighSave.Minimum;
                    udTXFilterHighSave.Value = value;
                }
            }
        }

        public int TXFilterLowSave
        {
            get { return (int)udTXFilterLowSave.Value; }
            set
            {
                if (console.TXBand != Band.B60M)
                {
                    if (value > udTXFilterLowSave.Maximum) value = (int)udTXFilterLowSave.Maximum;
                    if (value < udTXFilterLowSave.Minimum) value = (int)udTXFilterLowSave.Minimum;
                    udTXFilterLowSave.Value = value;
                }
            }
        }

        public bool CustomRXAGCEnabled
        {
            set
            {
                udDSPAGCAttack.Enabled = value;
                udDSPAGCDecay.Enabled = value;
                udDSPAGCHangTime.Enabled = value;

                if (value)
                {
                    console.radio.GetDSPRX(0, 0).Force = true;
                    console.radio.GetDSPRX(0, 1).Force = true;
                    udDSPAGCHangTime_ValueChanged(this, EventArgs.Empty); // MW0LGE_21f moved above the decay
                    udDSPAGCDecay_ValueChanged(this, EventArgs.Empty);
                    console.radio.GetDSPRX(0, 0).Force = false;
                    console.radio.GetDSPRX(0, 1).Force = false;
                }
            }
        }

        public bool CustomRX2AGCEnabled
        {
            set
            {
                udDSPAGCRX2Attack.Enabled = value;
                udDSPAGCRX2Decay.Enabled = value;
                udDSPAGCRX2HangTime.Enabled = value;

                if (value)
                {
                    console.radio.GetDSPRX(1, 0).Force = true;
                    udDSPAGCRX2HangTime_ValueChanged(this, EventArgs.Empty); // MW0LGE_21f moved above the decay
                    udDSPAGCRX2Decay_ValueChanged(this, EventArgs.Empty);
                    console.radio.GetDSPRX(1, 0).Force = false;
                }
            }
        }

        public bool VACEnable
        {
            get { return chkAudioEnableVAC.Checked; }
            set { chkAudioEnableVAC.Checked = value; }
        }

        public bool VAC2Enable
        {
            get { return chkVAC2Enable.Checked; }
            set { chkVAC2Enable.Checked = value; }
        }

        public bool RXOnly
        {
            get { return chkGeneralRXOnly.Checked; }
            set { chkGeneralRXOnly.Checked = value; }
        }

        private bool mox;
        public bool MOX
        {
            get { return mox; }
            set
            {
                mox = value;
                chkAudioEnableVAC.Enabled = !mox;
                if (chkAudioEnableVAC.Checked)
                {
                    grpAudioDetails2.Enabled = !mox;
                    grpAudioBuffer2.Enabled = !mox;
                    grpAudioLatency2.Enabled = !mox;
                    grpAudioSampleRate2.Enabled = !mox;
                    grpAudio2Stereo.Enabled = !mox;
                    grpVAC1ResamplerAdvanced.Enabled = !mox;
                }
                else
                {
                    grpAudioDetails2.Enabled = true;
                    grpAudioBuffer2.Enabled = true;
                    grpAudioLatency2.Enabled = true;
                    grpAudioSampleRate2.Enabled = true;
                    grpAudio2Stereo.Enabled = true;
                    grpVAC1ResamplerAdvanced.Enabled = true;
                }
                grpDSPBufferSize.Enabled = !mox;
            }
        }

        public int TXAF
        {
            get { return (int)udTXAF.Value; }
            set { udTXAF.Value = value; }
        }

        private bool _freqCorrectFactorChangedViaAutoCalibration = false;
        public double HPSDRFreqCorrectFactorViaAutoCalibration
        {
            get { return (double)udHPSDRFreqCorrectFactor.Value; }
            set
            {
                _freqCorrectFactorChangedViaAutoCalibration = true;
                udHPSDRFreqCorrectFactor.Value = (decimal)value;
                udHPSDRFreqCorrectFactor_ValueChanged(this, EventArgs.Empty);
            }
        }

        public bool CESSB
        {
            get { return chkDSPCESSB.Checked; }
            set { chkDSPCESSB.Checked = value; }
        }

        public bool AlexPresent
        {
            get { return chkAlexPresent.Checked; }
            set { chkAlexPresent.Checked = value; }
        }

        public bool MercuryPresent
        {
            get { return chkMercuryPresent.Checked; }
            set { chkMercuryPresent.Checked = value; }
        }

        public bool PenelopePresent
        {
            get { return chkPennyPresent.Checked; }
            set { chkPennyPresent.Checked = value; }
        }

        public bool PennyLanePresent
        {
            get { return chkPennyLane.Checked; }
            set { chkPennyLane.Checked = value; }
        }

        public double BPF1_1_5Start
        {
            get { return (double)ud1_5BPF1Start.Value; }
        }

        public double BPF1_1_5End
        {
            get { return (double)ud1_5BPF1End.Value; }
        }

        public double BPF1_6_5Start
        {
            get { return (double)ud6_5BPF1Start.Value; }
        }

        public double BPF1_6_5End
        {
            get { return (double)ud6_5BPF1End.Value; }
        }

        public double BPF1_9_5Start
        {
            get { return (double)ud9_5BPF1Start.Value; }
        }

        public double BPF1_9_5End
        {
            get { return (double)ud9_5BPF1End.Value; }
        }

        public double BPF1_13Start
        {
            get { return (double)ud13BPF1Start.Value; }
        }

        public double BPF1_13End
        {
            get { return (double)ud13BPF1End.Value; }
        }

        public double BPF1_20Start
        {
            get { return (double)ud20BPF1Start.Value; }
        }

        public double BPF1_20End
        {
            get { return (double)ud20BPF1End.Value; }
        }

        public double BPF1_6Start
        {
            get { return (double)ud6BPF1Start.Value; }
        }

        public double BPF1_6End
        {
            get { return (double)ud6BPF1End.Value; }
        }

        public bool BPF1_1_5led
        {
            set { rad1_5BPF1led.Checked = value; }
        }

        public bool BPF1_6_5led
        {
            set { rad6_5BPF1led.Checked = value; }
        }

        public bool BPF1_9_5led
        {
            set { rad9_5BPF1led.Checked = value; }
        }

        public bool BPF1_13led
        {
            set { rad13BPF1led.Checked = value; }
        }

        public bool BPF1_20led
        {
            set { rad20BPF1led.Checked = value; }
        }

        public bool BPF1_6led
        {
            set { rad6BPF1led.Checked = value; }
        }

        public bool BPBPF1led
        {
            set { radBPBPF1led.Checked = value; }
        }

        public bool BPF1BPTXled
        {
            set { radBPF1BPTXled.Checked = value; }
        }

        public int FixedTunePower
        {
            get { return (int)udTXTunePower.Value; }
            set { udTXTunePower.Value = (decimal)value; }
        }
        public int TwoTonePower
        {
            get { return (int)udTestIMDPower.Value; }
            set { udTestIMDPower.Value = (decimal)value; }
        }

        public bool DigUIsUSB
        {
            get { return chkDigUIsUSB.Checked; }
        }

        public int DigU_CT_Offset
        {
            get { return (int)udOptClickTuneOffsetDIGU.Value; }
            set { udOptClickTuneOffsetDIGU.Value = value; }
        }

        public int DigL_CT_Offset
        {
            get { return (int)udOptClickTuneOffsetDIGL.Value; }
            set { udOptClickTuneOffsetDIGL.Value = value; }
        }

        public float WaterfallLowThreshold
        {
            get { return (float)udDisplayWaterfallLowLevel.Value; }
            set { udDisplayWaterfallLowLevel.Value = (decimal)value; }
        }

        public float WaterfallHighThreshold
        {
            get { return (float)udDisplayWaterfallHighLevel.Value; }
            set { udDisplayWaterfallHighLevel.Value = (decimal)value; }
        }

        public float RX2WaterfallLowThreshold
        {
            get { return (float)udRX2DisplayWaterfallLowLevel.Value; }
            set { udRX2DisplayWaterfallLowLevel.Value = (decimal)value; }
        }

        public float RX2WaterfallHighThreshold
        {
            get { return (float)udRX2DisplayWaterfallHighLevel.Value; }
            set { udRX2DisplayWaterfallHighLevel.Value = (decimal)value; }
        }

        public float DisplayGridMin
        {
            get { return (float)udDisplayGridMin.Value; }
            set
            {
                if (udDisplayGridMin != null)
                {
                    if (value > (float)udDisplayGridMin.Maximum) value = (float)udDisplayGridMin.Maximum;
                    if (value < (float)udDisplayGridMin.Minimum) value = (float)udDisplayGridMin.Minimum;
                    udDisplayGridMin.Value = (decimal)value;
                }
            }
        }

        public float DisplayGridMax
        {
            get { return (float)udDisplayGridMax.Value; }
            set
            {
                if (udDisplayGridMax != null)
                {
                    if (value > (float)udDisplayGridMax.Maximum) value = (float)udDisplayGridMax.Maximum;
                    if (value < (float)udDisplayGridMax.Minimum) value = (float)udDisplayGridMax.Minimum;
                    udDisplayGridMax.Value = (decimal)value;
                }
            }
        }

        public float RX2DisplayGridMin
        {
            get { return (float)udRX2DisplayGridMin.Value; }
            set
            {
                if (udRX2DisplayGridMin != null)
                {
                    if (value > (float)udRX2DisplayGridMin.Maximum) value = (float)udRX2DisplayGridMin.Maximum;
                    if (value < (float)udRX2DisplayGridMin.Minimum) value = (float)udRX2DisplayGridMin.Minimum;
                    udRX2DisplayGridMin.Value = (decimal)value;
                }
            }
        }

        public float RX2DisplayGridMax
        {
            get { return (float)udRX2DisplayGridMax.Value; }
            set
            {
                if (udRX2DisplayGridMax != null)
                {
                    if (value > (float)udRX2DisplayGridMax.Maximum) value = (float)udRX2DisplayGridMax.Maximum;
                    if (value < (float)udRX2DisplayGridMax.Minimum) value = (float)udRX2DisplayGridMax.Minimum;
                    udRX2DisplayGridMax.Value = (decimal)value;
                }
            }
        }

        public float TXGridMax
        {
            get
            {
                if (udTXGridMax != null) return (float)udTXGridMax.Value;
                else return -1;
            }
            set
            {
                if (udTXGridMax != null)
                {
                    if (value > (float)udTXGridMax.Maximum) value = (float)udTXGridMax.Maximum;
                    if (value < (float)udTXGridMax.Minimum) value = (float)udTXGridMax.Minimum;
                    udTXGridMax.Value = (decimal)value;
                }
            }
        }

        public float TXGridMin
        {
            get
            {
                if (udTXGridMin != null) return (float)udTXGridMin.Value;
                else return -1;
            }
            set
            {
                if (udTXGridMin != null)
                {
                    if (value > (float)udTXGridMin.Maximum) value = (float)udTXGridMin.Maximum;
                    if (value < (float)udTXGridMin.Minimum) value = (float)udTXGridMin.Minimum;
                    udTXGridMin.Value = (decimal)value;
                }
            }
        }

        public float PA10W
        {
            get
            {
                float rv = (float)ud100PA10W.Value;

                switch (console.CurrentHPSDRModel)
                {
                    case HPSDRModel.ANAN10:
                    case HPSDRModel.ANAN10E:
                        rv = (float)ud10PA1W.Value;
                        break;
                    case HPSDRModel.ANAN8000D:
                        rv = (float)ud200PA20W.Value;
                        break;
                }
                return rv;

            }
        }

        public float PA20W
        {
            get
            {
                float rv = (float)ud100PA20W.Value;
                switch (console.CurrentHPSDRModel)
                {
                    case HPSDRModel.ANAN10:
                    case HPSDRModel.ANAN10E:
                        rv = (float)ud10PA2W.Value;
                        break;
                    case HPSDRModel.ANAN8000D:
                        rv = (float)ud200PA40W.Value;
                        break;
                }
                return rv;
            }
        }

        public float PA30W
        {
            get
            {
                float rv = (float)ud100PA30W.Value;
                switch (console.CurrentHPSDRModel)
                {
                    case HPSDRModel.ANAN10:
                    case HPSDRModel.ANAN10E:
                        rv = (float)ud10PA3W.Value;
                        break;
                    case HPSDRModel.ANAN8000D:
                        rv = (float)ud200PA60W.Value;
                        break;
                }
                return rv;
            }
        }

        public float PA40W
        {
            get
            {
                float rv = (float)ud100PA40W.Value;
                switch (console.CurrentHPSDRModel)
                {
                    case HPSDRModel.ANAN10:
                    case HPSDRModel.ANAN10E:
                        rv = (float)ud10PA4W.Value;
                        break;
                    case HPSDRModel.ANAN8000D:
                        rv = (float)ud200PA80W.Value;
                        break;
                }
                return rv;
            }
        }

        public float PA50W
        {
            get
            {
                float rv = (float)ud100PA50W.Value;
                switch (console.CurrentHPSDRModel)
                {
                    case HPSDRModel.ANAN10:
                    case HPSDRModel.ANAN10E:
                        rv = (float)ud10PA5W.Value;
                        break;
                    case HPSDRModel.ANAN8000D:
                        rv = (float)ud200PA100W.Value;
                        break;
                }
                return rv;
            }
        }

        public float PA60W
        {
            get
            {
                float rv = (float)ud100PA60W.Value;
                switch (console.CurrentHPSDRModel)
                {
                    case HPSDRModel.ANAN10:
                    case HPSDRModel.ANAN10E:
                        rv = (float)ud10PA6W.Value;
                        break;
                    case HPSDRModel.ANAN8000D:
                        rv = (float)ud200PA120W.Value;
                        break;
                }
                return rv;
            }
        }

        public float PA70W
        {
            get
            {
                float rv = (float)ud100PA70W.Value;
                switch (console.CurrentHPSDRModel)
                {
                    case HPSDRModel.ANAN10:
                    case HPSDRModel.ANAN10E:
                        rv = (float)ud10PA7W.Value;
                        break;
                    case HPSDRModel.ANAN8000D:
                        rv = (float)ud200PA140W.Value;
                        break;
                }
                return rv;
            }
        }

        public float PA80W
        {
            get
            {
                float rv = (float)ud100PA80W.Value;
                switch (console.CurrentHPSDRModel)
                {
                    case HPSDRModel.ANAN10:
                    case HPSDRModel.ANAN10E:
                        rv = (float)ud10PA8W.Value;
                        break;
                    case HPSDRModel.ANAN8000D:
                        rv = (float)ud200PA160W.Value;
                        break;
                }
                return rv;
            }
        }

        public float PA90W
        {
            get
            {
                float rv = (float)ud100PA90W.Value;
                switch (console.CurrentHPSDRModel)
                {
                    case HPSDRModel.ANAN10:
                    case HPSDRModel.ANAN10E:
                        rv = (float)ud10PA9W.Value;
                        break;
                    case HPSDRModel.ANAN8000D:
                        rv = (float)ud200PA180W.Value;
                        break;
                }
                return rv;
            }
        }

        public float PA100W
        {
            get
            {
                float rv = (float)ud100PA100W.Value;
                switch (console.CurrentHPSDRModel)
                {
                    case HPSDRModel.ANAN10:
                    case HPSDRModel.ANAN10E:
                        rv = (float)ud10PA10W.Value;
                        break;
                    case HPSDRModel.ANAN8000D:
                        rv = (float)ud200PA200W.Value;
                        break;
                }
                return rv;
            }
        }

        public float PA110W
        {
            get
            {
                float rv = (float)ud100PA110W.Value;
                switch (console.CurrentHPSDRModel)
                {
                    case HPSDRModel.ANAN10:
                    case HPSDRModel.ANAN10E:
                        rv = (float)ud10PA11W.Value;
                        break;
                    case HPSDRModel.ANAN8000D:
                        rv = (float)ud200PA220W.Value;
                        break;
                }
                return rv;
            }
        }

        public float PA120W
        {
            get
            {
                float rv = (float)ud100PA120W.Value;
                switch (console.CurrentHPSDRModel)
                {
                    case HPSDRModel.ANAN10:
                    case HPSDRModel.ANAN10E:
                        rv = (float)ud10PA12W.Value;
                        break;
                    case HPSDRModel.ANAN8000D:
                        rv = (float)ud200PA240W.Value;
                        break;
                }
                return rv;
            }
        }

        public float PA130W
        {
            get
            {
                float rv = (float)ud100PA130W.Value;
                switch (console.CurrentHPSDRModel)
                {
                    case HPSDRModel.ANAN10:
                    case HPSDRModel.ANAN10E:
                        rv = (float)ud10PA13W.Value;
                        break;
                    case HPSDRModel.ANAN8000D:
                        rv = (float)ud200PA260W.Value;
                        break;
                }
                return rv;
            }
        }

        public float PA140W
        {
            get
            {
                float rv = (float)ud100PA140W.Value;
                switch (console.CurrentHPSDRModel)
                {
                    case HPSDRModel.ANAN10:
                    case HPSDRModel.ANAN10E:
                        rv = (float)ud10PA14W.Value;
                        break;
                    case HPSDRModel.ANAN8000D:
                        rv = (float)ud200PA280W.Value;
                        break;
                }
                return rv;
            }
        }


        // Added 06/21/05 BT for CAT commands

        public int CATNB1Threshold
        {
            get { return Convert.ToInt32(udDSPNB.Value); }
            set
            {
                value = (int)Math.Max(udDSPNB.Minimum, value);			// lower bound
                value = (int)Math.Min(udDSPNB.Maximum, value);			// upper bound
                udDSPNB.Value = value;
            }
        }

        // Added 06/21/05 BT for CAT commands
        public int CATNB2Threshold
        {
            get { return 0; }
            set
            {
                //[2.10.3.5]MW0LGE no code here, TODO
            }
        }

        public int CATCWPitch
        {
            get { return (int)udDSPCWPitch.Value; }
            set
            {
                value = (int)Math.Max(udDSPCWPitch.Minimum, value);
                value = (int)Math.Min(udDSPCWPitch.Maximum, value);
                udDSPCWPitch.Value = value;
            }
        }

        public void CATSetRig(string rig)
        {
            comboCATRigType.Text = rig;
        }

        //Reads or sets the setup form Spectrum Grid Display Maximum value.
        public int CATSGMax
        {
            get { return (int)udDisplayGridMax.Value; }
            set
            {
                value = (int)Math.Max(udDisplayGridMax.Minimum, value);
                value = (int)Math.Min(udDisplayGridMin.Maximum, value);
                udDisplayGridMax.Value = value;
            }
        }

        //Reads or sets the setup form Spectrum Grid Display Minimum value.
        public int CATSGMin
        {
            get { return (int)udDisplayGridMin.Value; }
            set
            {
                value = (int)Math.Max(udDisplayGridMax.Minimum, value);
                value = (int)Math.Min(udDisplayGridMin.Maximum, value);
                udDisplayGridMin.Value = value;
            }
        }

        //Reads or sets the setup form Spectrum Grid Display Step value.
        public int CATSGStep
        {
            get { return (int)udDisplayGridStep.Value; }
            set
            {
                value = (int)Math.Max(udDisplayGridStep.Minimum, value);
                value = (int)Math.Min(udDisplayGridStep.Maximum, value);
                udDisplayGridStep.Value = value;
            }
        }

        //Reads or sets the setup form Waterfall low level value.
        public int CATWFLo
        {
            get { return (int)udDisplayWaterfallLowLevel.Value; }
            set
            {
                value = (int)Math.Max(udDisplayWaterfallLowLevel.Minimum, value);
                value = (int)Math.Min(udDisplayWaterfallLowLevel.Maximum, value);
                udDisplayWaterfallLowLevel.Value = value;
            }
        }

        //Reads or sets the setup form Waterfall high level value.
        public int CATWFHi
        {
            get { return (int)udDisplayWaterfallHighLevel.Value; }
            set
            {
                value = (int)Math.Max(udDisplayWaterfallHighLevel.Minimum, value);
                value = (int)Math.Min(udDisplayWaterfallHighLevel.Maximum, value);
                udDisplayWaterfallHighLevel.Value = value;
            }
        }

        public int DSPPhoneRXBuffer
        {
            get { return Int32.Parse(comboDSPPhoneRXBuf.Text); }
            set
            {
                string temp = value.ToString();
                if (comboDSPPhoneRXBuf.Items.Contains(temp))
                    comboDSPPhoneRXBuf.SelectedItem = temp;
            }
        }

        public int DSPPhoneTXBuffer
        {
            get { return Int32.Parse(comboDSPPhoneTXBuf.Text); }
            set
            {
                string temp = value.ToString();
                if (comboDSPPhoneTXBuf.Items.Contains(temp))
                    comboDSPPhoneTXBuf.SelectedItem = temp;
            }
        }

        public int DSPCWRXBuffer
        {
            get { return Int32.Parse(comboDSPCWRXBuf.Text); }
            set
            {
                string temp = value.ToString();
                if (comboDSPCWRXBuf.Items.Contains(temp))
                    comboDSPCWRXBuf.SelectedItem = temp;
            }
        }

        public int DSPDigRXBuffer
        {
            get { return Int32.Parse(comboDSPDigRXBuf.Text); }
            set
            {
                string temp = value.ToString();
                if (comboDSPDigRXBuf.Items.Contains(temp))
                    comboDSPDigRXBuf.SelectedItem = temp;
            }
        }

        public int DSPDigTXBuffer
        {
            get { return Int32.Parse(comboDSPDigTXBuf.Text); }
            set
            {
                string temp = value.ToString();
                if (comboDSPDigTXBuf.Items.Contains(temp))
                    comboDSPDigTXBuf.SelectedItem = temp;
            }
        }

        public int AudioBufferSize
        {
            get { return console.BlockSize1; }
            set
            {
                string temp = value.ToString();

                //[2.10.3.5]MW0LGE no code here, TODO
            }
        }

        private bool allow_freq_broadcast = false;
        public bool AllowFreqBroadcast
        {
            get { return allow_freq_broadcast; }
            set
            {
                allow_freq_broadcast = value;
                console.KWAutoInformation = value;

                //update the 1/2/3/4/tcp visibility
                updatePortAIstate(value);
            }
        }

        public bool AutoMuteRX2onVFOATX
        {
            get { return chkRX2AutoMuteTX.Checked; }
            set { chkRX2AutoMuteTX.Checked = value; }
        }

        public bool AutoMuteRX1onVFOBTX
        {
            get { return chkRX2AutoMuteRX1OnVFOBTX.Checked; }
            set { chkRX2AutoMuteRX1OnVFOBTX.Checked = value; }
        }

        private bool rtty_offset_enabled_a;
        public bool RttyOffsetEnabledA
        {
            get { return rtty_offset_enabled_a; }
            set { chkRTTYOffsetEnableA.Checked = value; }
        }

        private bool rtty_offset_enabled_b;
        public bool RttyOffsetEnabledB
        {
            get { return rtty_offset_enabled_b; }
            set { chkRTTYOffsetEnableB.Checked = value; }
        }

        private int rtty_offset_high = 2125;
        public int RttyOffsetHigh
        {
            get { return rtty_offset_high; }
            set
            {
                value = (int)Math.Max(udRTTYU.Minimum, value);
                value = (int)Math.Min(udRTTYU.Maximum, value);
                udRTTYU.Value = value;
            }
        }

        private int rtty_offset_low = 2125;
        public int RttyOffsetLow
        {
            get { return rtty_offset_low; }
            set
            {
                value = (int)Math.Max(udRTTYL.Minimum, value);
                value = (int)Math.Min(udRTTYL.Maximum, value);
                udRTTYL.Value = value;
            }
        }

        private bool firmware_bypass = false;
        public bool FirmwareBypass
        {
            get
            {
                return firmware_bypass;
            }
            set
            {
                firmware_bypass = value;
            }
        }

        public int[] CFCCOMPEQ
        {
            get
            {
                int[] cfceq = new int[32];
                cfceq[0] = tbCFCPRECOMP.Value;
                cfceq[1] = tbCFC0.Value;
                cfceq[2] = tbCFC1.Value;
                cfceq[3] = tbCFC2.Value;
                cfceq[4] = tbCFC3.Value;
                cfceq[5] = tbCFC4.Value;
                cfceq[6] = tbCFC5.Value;
                cfceq[7] = tbCFC6.Value;
                cfceq[8] = tbCFC7.Value;
                cfceq[9] = tbCFC8.Value;
                cfceq[10] = tbCFC9.Value;

                cfceq[11] = tbCFCPEQGAIN.Value;
                cfceq[12] = tbCFCEQ0.Value;
                cfceq[13] = tbCFCEQ1.Value;
                cfceq[14] = tbCFCEQ2.Value;
                cfceq[15] = tbCFCEQ3.Value;
                cfceq[16] = tbCFCEQ4.Value;
                cfceq[17] = tbCFCEQ5.Value;
                cfceq[18] = tbCFCEQ6.Value;
                cfceq[19] = tbCFCEQ7.Value;
                cfceq[20] = tbCFCEQ8.Value;
                cfceq[21] = tbCFCEQ9.Value;

                cfceq[22] = (int)udCFC0.Value;
                cfceq[23] = (int)udCFC1.Value;
                cfceq[24] = (int)udCFC2.Value;
                cfceq[25] = (int)udCFC3.Value;
                cfceq[26] = (int)udCFC4.Value;
                cfceq[27] = (int)udCFC5.Value;
                cfceq[28] = (int)udCFC6.Value;
                cfceq[29] = (int)udCFC7.Value;
                cfceq[30] = (int)udCFC8.Value;
                cfceq[31] = (int)udCFC9.Value;

                return cfceq;
            }

            set
            {
                if (value.Length < 32)
                {
                    MessageBox.Show("Error setting CFC EQ");
                    return;
                }
                tbCFCPRECOMP.Value = Math.Max(tbCFCPRECOMP.Minimum, Math.Min(tbCFCPRECOMP.Maximum, value[0]));
                tbCFC0.Value = Math.Max(tbCFC0.Minimum, Math.Min(tbCFC0.Maximum, value[1]));
                tbCFC1.Value = Math.Max(tbCFC1.Minimum, Math.Min(tbCFC1.Maximum, value[2]));
                tbCFC2.Value = Math.Max(tbCFC2.Minimum, Math.Min(tbCFC2.Maximum, value[3]));
                tbCFC3.Value = Math.Max(tbCFC3.Minimum, Math.Min(tbCFC3.Maximum, value[4]));
                tbCFC4.Value = Math.Max(tbCFC4.Minimum, Math.Min(tbCFC4.Maximum, value[5]));
                tbCFC5.Value = Math.Max(tbCFC5.Minimum, Math.Min(tbCFC5.Maximum, value[6]));
                tbCFC6.Value = Math.Max(tbCFC6.Minimum, Math.Min(tbCFC6.Maximum, value[7]));
                tbCFC7.Value = Math.Max(tbCFC7.Minimum, Math.Min(tbCFC7.Maximum, value[8]));
                tbCFC8.Value = Math.Max(tbCFC8.Minimum, Math.Min(tbCFC8.Maximum, value[9]));
                tbCFC9.Value = Math.Max(tbCFC9.Minimum, Math.Min(tbCFC9.Maximum, value[10]));
                tbCFCPEQGAIN.Value = Math.Max(tbCFCPEQGAIN.Minimum, Math.Min(tbCFCPEQGAIN.Maximum, value[11]));
                tbCFCEQ0.Value = Math.Max(tbCFCEQ0.Minimum, Math.Min(tbCFCEQ0.Maximum, value[12]));
                tbCFCEQ1.Value = Math.Max(tbCFCEQ1.Minimum, Math.Min(tbCFCEQ1.Maximum, value[13]));
                tbCFCEQ2.Value = Math.Max(tbCFCEQ2.Minimum, Math.Min(tbCFCEQ2.Maximum, value[14]));
                tbCFCEQ3.Value = Math.Max(tbCFCEQ3.Minimum, Math.Min(tbCFCEQ3.Maximum, value[15]));
                tbCFCEQ4.Value = Math.Max(tbCFCEQ4.Minimum, Math.Min(tbCFCEQ4.Maximum, value[16]));
                tbCFCEQ5.Value = Math.Max(tbCFCEQ5.Minimum, Math.Min(tbCFCEQ5.Maximum, value[17]));
                tbCFCEQ6.Value = Math.Max(tbCFCEQ6.Minimum, Math.Min(tbCFCEQ6.Maximum, value[18]));
                tbCFCEQ7.Value = Math.Max(tbCFCEQ7.Minimum, Math.Min(tbCFCEQ7.Maximum, value[19]));
                tbCFCEQ8.Value = Math.Max(tbCFCEQ8.Minimum, Math.Min(tbCFCEQ8.Maximum, value[20]));
                tbCFCEQ9.Value = Math.Max(tbCFCEQ9.Minimum, Math.Min(tbCFCEQ9.Maximum, value[21]));
                udCFC0.Value = Math.Max(udCFC0.Minimum, Math.Min(udCFC0.Maximum, value[22]));
                udCFC1.Value = Math.Max(udCFC1.Minimum, Math.Min(udCFC1.Maximum, value[23]));
                udCFC2.Value = Math.Max(udCFC2.Minimum, Math.Min(udCFC2.Maximum, value[24]));
                udCFC3.Value = Math.Max(udCFC3.Minimum, Math.Min(udCFC3.Maximum, value[25]));
                udCFC4.Value = Math.Max(udCFC4.Minimum, Math.Min(udCFC4.Maximum, value[26]));
                udCFC5.Value = Math.Max(udCFC5.Minimum, Math.Min(udCFC5.Maximum, value[27]));
                udCFC6.Value = Math.Max(udCFC6.Minimum, Math.Min(udCFC6.Maximum, value[28]));
                udCFC7.Value = Math.Max(udCFC7.Minimum, Math.Min(udCFC7.Maximum, value[29]));
                udCFC8.Value = Math.Max(udCFC8.Minimum, Math.Min(udCFC8.Maximum, value[30]));
                udCFC9.Value = Math.Max(udCFC9.Minimum, Math.Min(udCFC9.Maximum, value[31]));

                tbCFCPRECOMP_Scroll(this, EventArgs.Empty);
                tbCFCPEG_Scroll(this, EventArgs.Empty);
                setCFCProfile(this, EventArgs.Empty);

                // nasty, if only the value changed event had been used instead
                setDBtip(tbCFCPRECOMP);
                setDBtip(tbCFC0);
                setDBtip(tbCFC1);
                setDBtip(tbCFC2);
                setDBtip(tbCFC3);
                setDBtip(tbCFC4);
                setDBtip(tbCFC5);
                setDBtip(tbCFC6);
                setDBtip(tbCFC7);
                setDBtip(tbCFC8);
                setDBtip(tbCFC9);

                setDBtip(tbCFCPEQGAIN);
                setDBtip(tbCFCEQ0);
                setDBtip(tbCFCEQ1);
                setDBtip(tbCFCEQ2);
                setDBtip(tbCFCEQ3);
                setDBtip(tbCFCEQ4);
                setDBtip(tbCFCEQ5);
                setDBtip(tbCFCEQ6);
                setDBtip(tbCFCEQ7);
                setDBtip(tbCFCEQ8);
                setDBtip(tbCFCEQ9);
            }
        }



        // added G8NJJ for Andromeda
        public string AndromedaVersionNumber
        {
            get { return lblAndromedaVersion.Text; }
            set { lblAndromedaVersion.Text = value; }
        }

        // added G8NJJ for Aries
        public string AriesVersionNumber
        {
            get { return lblAriesFW.Text; }
            set { lblAriesFW.Text = value; }
        }

        // added G8NJJ for Aries
        public string AriesEraseStatus
        {
            get { return lblAriesEraseStatus.Text; }
            set { lblAriesEraseStatus.Text = value; }
        }

        // added G8NJJ for Ganymede
        public string GanymedeVersionNumber
        {
            get { return lblGanymedeFW.Text; }
            set { lblGanymedeFW.Text = value; }
        }

        // added G8NJJ for Ganymede
        public string GanymedeStatus
        {
            get { return lblGanymedeStatus.Text; }
            set { lblGanymedeStatus.Text = value; }
        }

        public TabControl TabSetup
        {
            get { return tcSetup; }
            set { tcSetup = value; }
        }
        public TabControl TabPowerAmplifier
        {
            get { return tcPowerAmplifier; }
            set { tcPowerAmplifier = value; }
        }
        public TabControl TabGeneral
        {
            get { return tcGeneral; }
            set { tcGeneral = value; }
        }
        public TabControl TabOptions
        {
            get { return tcOptions; }
            set { tcOptions = value; }
        }
        public TabControl TabDisplay
        {
            get { return tcDisplay; }
            //set { tcDisplay = value; }
        }
        public TabControl TabAppearance
        {
            get { return tcAppearance; }
            //set { tcAppearance = value; }
        }
        public TabControl TabDSP
        {
            get { return tcDSP; }
            set { tcDSP = value; }
        }

        public TabControl TabAudio
        {
            get { return tcAudio; }
            set { tcAudio = value; }
        }

        public TabControl TabCAT
        {
            get { return tcCAT; }
            //set { tcCAT = value; }
        }


        #endregion

        #region General Tab Event Handlers
        // ======================================================
        // General Tab Event Handlers
        // ======================================================

        private void InitHPSDR()
        {
            if (!initializing)
                AddHPSDRPages();

            grpFRSRegion.Visible = true;

            grpGenCalRXImage.Visible = false;
            lblMoxDelay.Visible = true;
            udMoxDelay.Visible = true;
            udMoxDelay.Enabled = true;
            udRFDelay.Visible = true;
            udRFDelay.Enabled = true;
            lblRFDelay.Visible = true;
            grpImpulseTest.Visible = false;
            grpGenCalRXImage.Enabled = false;
            chkCalExpert.Enabled = false;
            grpHPSDRFreqCalDbg.Visible = true;
            grpOzyType.Visible = true;
            grpOzyType.Enabled = true;
            grpMetisAddr.Visible = true;

            if (console.CurrentHPSDRModel == HPSDRModel.ANAN200D ||
                console.CurrentHPSDRModel == HPSDRModel.ANAN7000D ||
                console.CurrentHPSDRModel == HPSDRModel.ANAN8000D ||
                console.CurrentHPSDRModel == HPSDRModel.ANAN_G2 ||
                console.CurrentHPSDRModel == HPSDRModel.ANAN_G2_1K)
            {
                groupBoxHPSDRHW.Visible = false;
                grpGeneralHardwareORION.Visible = true;
            }
            else
            {
                grpGeneralHardwareORION.Visible = false;

            }

            if (console.CurrentHPSDRModel == HPSDRModel.ANAN8000D ||
                console.CurrentHPSDRModel == HPSDRModel.ANAN7000D ||
                console.CurrentHPSDRModel == HPSDRModel.ANAN_G2 ||
                console.CurrentHPSDRModel == HPSDRModel.ANAN_G2_1K)
            {
                chkLPFBypass.Checked = false;
                chkLPFBypass.Visible = false;

                chkDisableRXOut.Visible = false;
                chkBPF2Gnd.Visible = true;
                chkEnableXVTRHF.Visible = true;
                toolTip1.SetToolTip(chkEXT2OutOnTx, "Enable Rx BYPASS during transmit.");
                if (console.CurrentHPSDRModel == HPSDRModel.ANAN_G2 ||
                    console.CurrentHPSDRModel == HPSDRModel.ANAN_G2_1K)
                {
                    panelSaturnMicInput.Visible = true;
                    lblSaturnMicInput.Visible = true;
                }
                else
                {
                    panelSaturnMicInput.Visible = false;
                    lblSaturnMicInput.Visible = false;
                }
            }
            else
            {
                chkLPFBypass.Visible = true;

                chkDisableRXOut.Visible = true;
                chkBPF2Gnd.Visible = false;
                chkEnableXVTRHF.Visible = false;
                toolTip1.SetToolTip(chkEXT2OutOnTx, "Enable RX 1 IN on Alex or Ext 2 on ANAN during transmit.");
            }


            if (console.CurrentHPSDRModel == HPSDRModel.ANAN10 ||
                console.CurrentHPSDRModel == HPSDRModel.ANAN10E)
            {
                chkRxOutOnTx.Checked = false;
                chkRxOutOnTx.Visible = false;
                chkEXT1OutOnTx.Checked = false;
                chkEXT1OutOnTx.Visible = false;
                chkEXT2OutOnTx.Checked = false;
                chkEXT2OutOnTx.Visible = false;
                panelAlex1HPFControl.Visible = false;
                tpAlexFilterControl.Text = "LPF";
                panelAlexRXXVRTControl.Visible = false;
                labelAlexFilterActive.Location = new Point(298, 0);
                grp10WattMeterTrim.BringToFront();
                chkEnableXVTRHF.Visible = false;
            }
            else
            if (console.CurrentHPSDRModel == HPSDRModel.ANAN7000D ||
                console.CurrentHPSDRModel == HPSDRModel.ANAN8000D ||
                console.CurrentHPSDRModel == HPSDRModel.ANAN_G2 ||
                console.CurrentHPSDRModel == HPSDRModel.ANAN_G2_1K)
            {
                if ((console.CurrentHPSDRModel == HPSDRModel.ANAN7000D) || (console.CurrentHPSDRModel == HPSDRModel.ANAN_G2))
                {
                    chkRxOutOnTx.Visible = false;
                    chkEXT1OutOnTx.Visible = true;
                    chkEXT2OutOnTx.Visible = true;
                    panelAlexRXXVRTControl.Visible = true;
                    grp100WattMeterTrim.BringToFront();
                }
                else if (console.CurrentHPSDRModel == HPSDRModel.ANAN8000D)
                {
                    chkRxOutOnTx.Visible = false;
                    chkEXT1OutOnTx.Visible = false;
                    chkEXT2OutOnTx.Visible = false;
                    panelAlexRXXVRTControl.Visible = false;
                    grp200WattMeterTrim.BringToFront();
                }
                else if (console.CurrentHPSDRModel == HPSDRModel.ANAN_G2_1K)            // G8NJJ. will need more work ofr high power PA
                {
                    chkRxOutOnTx.Visible = false;
                    chkEXT1OutOnTx.Visible = false;
                    chkEXT2OutOnTx.Visible = false;
                    panelAlexRXXVRTControl.Visible = false;
                    grp200WattMeterTrim.BringToFront();
                }


                tpAlexFilterControl.Text = "BPF1/LPF";
                tpAlex2FilterControl.Text = "BPF2";
                labelAlex1FilterHPF.Text = "BPF1";
                chkAlexHPFBypass.Text = "ByPass/55 MHz BPF";
                chkDisableHPFonTX.Text = "BPF ByPass on TX";
                chkDisableHPFonPSb.Text = "BPF ByPass on PS";
                chkDisableHPFonPSb.Visible = true;
                labelAlexFilterActive.Location = new Point(275, 0);
                ud6mRx2LNAGainOffset.Visible = true;
                lblRx26mLNA.Visible = true;
                chkEnableXVTRHF.Visible = true;
            }
            else
            {
                chkRxOutOnTx.Enabled = true;
                chkRxOutOnTx.Visible = true;
                chkEXT1OutOnTx.Enabled = true;
                chkEXT1OutOnTx.Visible = true;
                chkEXT2OutOnTx.Enabled = true;
                chkEXT2OutOnTx.Visible = true;

                tpAlexFilterControl.Text = "HPF/LPF";
                labelAlex1FilterHPF.Text = "HPF";
                chkAlexHPFBypass.Text = "ByPass/55 MHz HPF";
                chkDisableHPFonTX.Text = "HPF ByPass on TX";
                chkDisableHPFonPSb.Visible = false;
                panelAlexRXXVRTControl.Visible = true;
                labelAlexFilterActive.Location = new Point(275, 0);
                ud6mRx2LNAGainOffset.Visible = false;
                lblRx26mLNA.Visible = false;
                grp100WattMeterTrim.BringToFront();
                chkEnableXVTRHF.Visible = false;
            }

            if (console.CurrentHPSDRModel == HPSDRModel.HERMES ||
               (console.CurrentHPSDRModel == HPSDRModel.HPSDR))
            {
                tpAlexControl.Text = "Alex";
                chkHFTRRelay.Checked = false;
                chkHFTRRelay.Enabled = false;
                chkHFTRRelay.Visible = false;
            }
            else
            {
                tpAlexControl.Text = "Ant/Filters";
                chkHFTRRelay.Visible = true;
                chkHFTRRelay.Enabled = true;
            }

            if (console.CurrentHPSDRModel != HPSDRModel.ANAN200D &&
                console.CurrentHPSDRModel != HPSDRModel.ANAN7000D &&
                console.CurrentHPSDRModel != HPSDRModel.ANAN8000D &&
                console.CurrentHPSDRModel != HPSDRModel.ANAN_G2 &&
                console.CurrentHPSDRModel != HPSDRModel.ANAN_G2_1K)
            {
                chkAlexPresent.Parent = groupBoxHPSDRHW;
                chkAlexPresent.Location = new Point(25, 80);
                chkApolloPresent.Parent = groupBoxHPSDRHW;
                chkApolloPresent.Location = new Point(25, 100);

                panelBPFControl.Visible = false;
                panelAlex1HPFControl.Visible = true;

                chkDisable6mLNAonRX.Parent = panelAlex1HPFControl;
                chkDisable6mLNAonRX.Location = new Point(16, 208);
                chkDisable6mLNAonTX.Parent = panelAlex1HPFControl;
                chkDisable6mLNAonTX.Location = new Point(63, 208);

                chkAlexHPFBypass.Parent = panelAlex1HPFControl;
                chkAlexHPFBypass.Location = new Point(140, 185);
                chkDisableHPFonTX.Parent = panelAlex1HPFControl;
                chkDisableHPFonTX.Location = new Point(140, 213);
                chkDisableHPFonPSb.Parent = panelAlex1HPFControl;
                chkDisableHPFonPSb.Location = new Point(140, 241);
            }

            if (console.CurrentHPSDRModel == HPSDRModel.HERMES) tpPennyCtrl.Text = "Hermes Ctrl";
            else tpPennyCtrl.Text = "OC Control";

            if (!console.RX2PreampPresent &&
                console.diversityForm != null)
                console.diversityForm.Dispose();

            if (console.path_Illustrator != null)
                console.path_Illustrator.pi_Changed();
        }

        public void AddHPSDRPages()
        {
            if (!tcGeneral.TabPages.Contains(tpHPSDR))
            {
                Common.TabControlInsert(tcGeneral, tpHPSDR, 1);
            }
            else
            {
                if (tcGeneral.TabPages.IndexOf(tpHPSDR) != 1)
                {
                    tcGeneral.TabPages.Remove(tpHPSDR);
                    Common.TabControlInsert(tcGeneral, tpHPSDR, 1);
                }
            }

            if (console.CurrentHPSDRModel == HPSDRModel.ANAN200D || console.CurrentHPSDRModel == HPSDRModel.ANAN100D ||
                console.CurrentHPSDRModel == HPSDRModel.ANAN8000D || console.CurrentHPSDRModel == HPSDRModel.ANAN7000D ||
                console.CurrentHPSDRModel == HPSDRModel.ANAN_G2 || console.CurrentHPSDRModel == HPSDRModel.ANAN_G2_1K)
            {
                if (!tcGeneral.TabPages.Contains(tpADC))
                {
                    Common.TabControlInsert(tcGeneral, tpADC, 2);
                }
            }

            if (!tcGeneral.TabPages.Contains(tpPennyCtrl))
            {
                Common.TabControlInsert(tcGeneral, tpPennyCtrl, 5);
            }
            else
            {
                if (tcGeneral.TabPages.IndexOf(tpPennyCtrl) != 5)
                {
                    tcGeneral.TabPages.Remove(tpPennyCtrl);
                    Common.TabControlInsert(tcGeneral, tpPennyCtrl, 5);
                }
            }

            if (!tcGeneral.TabPages.Contains(tpAlexControl))
            {
                Common.TabControlInsert(tcGeneral, tpAlexControl, 6);
            }
            else
            {
                if (tcGeneral.TabPages.IndexOf(tpAlexControl) != 6)
                {
                    tcGeneral.TabPages.Remove(tpAlexControl);
                    Common.TabControlInsert(tcGeneral, tpAlexControl, 6);
                }
            }

            if (console.CurrentHPSDRModel == HPSDRModel.HERMES || console.CurrentHPSDRModel == HPSDRModel.ANAN7000D || console.CurrentHPSDRModel == HPSDRModel.ANAN_G2)
            {
                if (!tcGeneral.TabPages.Contains(tpApolloControl))
                {
                    Common.TabControlInsert(tcGeneral, tpApolloControl, 7);
                }

                else
                {
                    if (tcGeneral.TabPages.IndexOf(tpApolloControl) != 7)
                    {
                        tcGeneral.TabPages.Remove(tpApolloControl);
                        Common.TabControlInsert(tcGeneral, tpApolloControl, 7);
                    }
                }

                if (AndromedaCATEnabled) tpApolloControl.Text = "Andromeda";
            }
            else
            {
                if (tcGeneral.TabPages.Contains(tpApolloControl))
                {
                    tcGeneral.TabPages.Remove(tpApolloControl);
                    tcGeneral.SelectedIndex = 0;
                }
            }

            if (console.CurrentHPSDRModel == HPSDRModel.ANAN8000D || console.CurrentHPSDRModel == HPSDRModel.ANAN7000D ||
                console.CurrentHPSDRModel == HPSDRModel.ANAN_G2 || console.CurrentHPSDRModel == HPSDRModel.ANAN_G2_1K)
            {
                if (!tcAlexControl.TabPages.Contains(tpAlex2FilterControl))
                {
                    tcAlexControl.TabPages.Add(tpAlex2FilterControl);
                }

            }
            else
            {
                if (tcAlexControl.TabPages.Contains(tpAlex2FilterControl))
                {
                    tcAlexControl.TabPages.Remove(tpAlex2FilterControl);
                }
            }

            console.MaxFreq = (double)udMaxFreq.Value;
        }

        private void chkGeneralRXOnly_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            if (chkGeneralRXOnly.Focused &&
                !chkGeneralRXOnly.Checked)
            {
                DialogResult dr = MessageBox.Show(
                    "Unchecking Receive Only while in Unsupported Card mode may \n" +
                    "cause damage to your SDR-1000 hardware.  Are you sure you want \n" +
                    "to enable transmit?",
                    "Warning: Enable Transmit?",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, Common.MB_TOPMOST); //MW0LGE_[2.9.0.7]);
                if (dr == DialogResult.No)
                {
                    chkGeneralRXOnly.Checked = true;
                    return;
                }
            }
            console.RXOnly = chkGeneralRXOnly.Checked;
            tpTransmit.Enabled = !chkGeneralRXOnly.Checked;
            tpPowerAmplifier.Enabled = !chkGeneralRXOnly.Checked;
            grpTestTXIMD.Enabled = !chkGeneralRXOnly.Checked;
        }

        private void btnGeneralCalFreqStart_Click(object sender, System.EventArgs e)
        {
            btnGeneralCalFreqStart.Enabled = false;
            Thread t = new Thread(new ThreadStart(CalibrateFreq))
            {
                Name = "Freq Calibration Thread",
                IsBackground = true,
                Priority = ThreadPriority.AboveNormal
            };
            t.Start();
        }

        private void btnGeneralCalLevelStart_Click(object sender, System.EventArgs e)
        {
            DialogResult dr = MessageBox.Show(
            "Is the calibrated signal present at the correct frequency?",
            "Level Calibration Check",
            MessageBoxButtons.YesNo,
            MessageBoxIcon.Question);
            if (dr == DialogResult.No) return; //MW0LGE_[2.9.0.6] double check we want to do this, prevents accidental click from changing config

            btnGeneralCalLevelStart.Enabled = false;
            btnResetLevelCal.Enabled = false;
            progress = new Progress("Calibrate RX Level");

            Thread t = new Thread(new ThreadStart(CalibrateLevel))
            {
                Name = "Level Calibration Thread",
                IsBackground = true,
                Priority = ThreadPriority.AboveNormal
            };
            t.Start();

            if (console.PowerOn)
                progress.Show();
        }

        private void btnCalLevel_Click(object sender, System.EventArgs e)
        {
            btnCalLevel.Enabled = false;
            progress = new Progress("Calibrate RX2 Level");

            Thread t = new Thread(new ThreadStart(CalibrateRX2Level))
            {
                Name = "Level Calibration Thread",
                IsBackground = true,
                Priority = ThreadPriority.Normal
            };
            t.Start();

            if (console.PowerOn)
                progress.Show();
        }

        private void btnGeneralCalImageStart_Click(object sender, System.EventArgs e)
        {
        }

        private void CalibrateFreq()
        {
            bool done = console.CalibrateFreq((float)udGeneralCalFreq1.Value);
            if (done) MessageBox.Show("Frequency Calibration complete.");
            btnGeneralCalFreqStart.Enabled = true;
        }

        private void CalibrateLevel()
        {
            bool done = console.CalibrateLevel(
                (float)udGeneralCalLevel.Value,
                (float)udGeneralCalFreq2.Value,
                progress,
                false);

            if (done) MessageBox.Show("Level Calibration complete.");
            btnGeneralCalLevelStart.Enabled = true;
            btnResetLevelCal.Enabled = true;
        }

        private void CalibrateRX2Level()
        {
            bool done = console.CalibrateRX2Level(
                (float)udGeneralCalRX2Level.Value,
                (float)udGeneralCalRX2Freq2.Value,
                progress,
                false);
            if (done) MessageBox.Show("Level Calibration complete.");
            btnCalLevel.Enabled = true;
        }

        private void chkGeneralDisablePTT_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.DisablePTT = chkGeneralDisablePTT.Checked;
        }

        private void comboGeneralXVTR_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
        }

        private void comboGeneralProcessPriority_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Process p = Process.GetCurrentProcess();

            if (comboGeneralProcessPriority.Text == "Real Time" &&
                comboGeneralProcessPriority.Focused)
            {
                DialogResult dr = MessageBox.Show(
                    "Setting the Process Priority to Realtime can cause the system to become unresponsive.\n" +
                    "This setting is not recommended.\n" +
                    "Are you sure you want to change to Realtime?",
                    "Warning: Realtime Not Recommended",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST); //MW0LGE_[2.9.0.7]);
                if (dr == DialogResult.No)
                {
                    switch (p.PriorityClass)
                    {
                        case ProcessPriorityClass.Idle:
                            comboGeneralProcessPriority.Text = "Idle";
                            break;
                        case ProcessPriorityClass.BelowNormal:
                            comboGeneralProcessPriority.Text = "Below Normal";
                            break;
                        case ProcessPriorityClass.AboveNormal:
                            comboGeneralProcessPriority.Text = "Above Normal";
                            break;
                        case ProcessPriorityClass.High:
                            comboGeneralProcessPriority.Text = "Highest";
                            break;
                        default:
                            comboGeneralProcessPriority.Text = "Normal";
                            break;
                    }
                    return;
                }
            }

            switch (comboGeneralProcessPriority.Text)
            {
                case "Idle":
                    p.PriorityClass = ProcessPriorityClass.Idle;
                    break;
                case "Below Normal":
                    p.PriorityClass = ProcessPriorityClass.BelowNormal;
                    break;
                case "Normal":
                    p.PriorityClass = ProcessPriorityClass.Normal;
                    break;
                case "Above Normal":
                    p.PriorityClass = ProcessPriorityClass.AboveNormal;
                    break;
                case "High":
                    p.PriorityClass = ProcessPriorityClass.High;
                    break;
                case "Real Time":
                    p.PriorityClass = ProcessPriorityClass.RealTime;
                    break;
            }
        }

        private void chkOptQuickQSY_CheckedChanged(object sender, System.EventArgs e)
        {
            console.QuickQSY = chkOptQuickQSY.Checked;
        }

        private void chkOptAlwaysOnTop_CheckedChanged(object sender, System.EventArgs e)
        {
            console.AlwaysOnTop = chkOptAlwaysOnTop.Checked;
        }

        private void udOptClickTuneOffsetDIGL_ValueChanged(object sender, System.EventArgs e)
        {
            console.DIGLClickTuneOffset = (int)udOptClickTuneOffsetDIGL.Value;
        }

        private void udOptClickTuneOffsetDIGU_ValueChanged(object sender, System.EventArgs e)
        {
            console.DIGUClickTuneOffset = (int)udOptClickTuneOffsetDIGU.Value;
        }

        private void udOptMaxFilterWidth_ValueChanged(object sender, System.EventArgs e)
        {
            console.MaxFilterWidth = (int)udOptMaxFilterWidth.Value;
        }

        private void comboOptFilterWidthMode_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            switch (comboOptFilterWidthMode.Text)
            {
                case "Linear":
                    console.CurrentFilterWidthMode = FilterWidthMode.Linear;
                    break;
                case "Log":
                    console.CurrentFilterWidthMode = FilterWidthMode.Log;
                    break;
                case "Log10":
                    console.CurrentFilterWidthMode = FilterWidthMode.Log10;
                    break;
            }
        }

        private void udOptMaxFilterShift_ValueChanged(object sender, System.EventArgs e)
        {
            console.MaxFilterShift = (int)udOptMaxFilterShift.Value;
        }

        private void chkOptFilterSaveChanges_CheckedChanged(object sender, System.EventArgs e)
        {
            console.SaveFilterChanges = chkOptFilterSaveChanges.Checked;
        }

        private void chkOptEnableKBShortcuts_CheckedChanged(object sender, System.EventArgs e)
        {
            console.EnableKBShortcuts = chkOptEnableKBShortcuts.Checked;
            chkOptQuickQSY.Enabled = chkOptEnableKBShortcuts.Checked;
        }

        private void udFilterDefaultLowCut_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.DefaultLowCut = (int)udFilterDefaultLowCut.Value;
        }

        private void udRX2FilterDefaultLowCut_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.DefaultRX2LowCut = (int)udRX2FilterDefaultLowCut.Value;
        }

        #endregion

        #region Audio Tab Event Handlers
        // ======================================================
        // Audio Tab Event Handlers
        // ======================================================

        private void chkAudioEnableVAC_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            bool val = chkAudioEnableVAC.Checked;
            //bool old_val = console.VACEnabled;  //MW0LGE_21i not used

            if (val)
            {
                if (comboAudioDriver2.SelectedIndex < 0 &&
                    comboAudioDriver2.Items.Count > 0)
                    comboAudioDriver2.SelectedIndex = 0;
            }

            console.VACEnabled = val;
            if (console.sliderForm != null)
                console.sliderForm.RX1VACOnOff = val;

        }

        private void chkVAC2Enable_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            bool val = chkVAC2Enable.Checked;

            if (val)
            {
                if (comboAudioDriver3.SelectedIndex < 0 &&
                    comboAudioDriver3.Items.Count > 0)
                    comboAudioDriver3.SelectedIndex = 0;
            }

            console.VAC2Enabled = val;
            if (console.sliderForm != null)
                console.sliderForm.RX2VACOnOff = val;

        }

        private void comboAudioDriver2_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboAudioDriver2.SelectedIndex < 0) return;

            int old_driver = Audio.Host2;
            int new_driver = ((PADeviceInfo)comboAudioDriver2.SelectedItem).Index;
            bool power = console.PowerOn;

            if (power && chkAudioEnableVAC.Checked && old_driver != new_driver)
            {
                Audio.EnableVAC1(false);
            }

            //[2.10.3]MW0LGE only enable if wasapi
            if (comboAudioDriver2.SelectedIndex < PA19.PA_GetHostApiCount()) //[2.10.3.4]MW0LGE ignore the manually added HPSDR (PCM A/D)
            {
                PA19.PaHostApiInfo hostInfo = PA19.PA_GetHostApiInfo(new_driver);
                bool bIsWASAPI = hostInfo.type == (int)PA19.PaHostApiTypeId.paWASAPI;
                chkVAC1ExclusiveOut.Enabled = bIsWASAPI;
                chkVAC1ExclusiveIn.Enabled = bIsWASAPI;
                if (!bIsWASAPI) // turn these off so that when they are enabled again and vac is on, we dont start exclusive
                {
                    chkVAC1ExclusiveOut.Checked = false;
                    chkVAC1ExclusiveIn.Checked = false;
                }
            }
            else
            {
                chkVAC1ExclusiveOut.Checked = false;
                chkVAC1ExclusiveIn.Checked = false;
                chkVAC1ExclusiveOut.Enabled = false;
                chkVAC1ExclusiveIn.Enabled = false;
            }
            //

            string new_driver_name = ((PADeviceInfo)comboAudioDriver2.SelectedItem).Name;

            console.AudioDriverIndex2 = new_driver;
            Audio.Host2 = new_driver;
            GetDevices2();
            if (comboAudioInput2.Items.Count != 0)
                comboAudioInput2.SelectedIndex = 0;
            if (comboAudioOutput2.Items.Count != 0)
                comboAudioOutput2.SelectedIndex = 0;
            if (power && chkAudioEnableVAC.Checked && old_driver != new_driver)
            {
                Audio.EnableVAC1(false);
                Audio.VACEnabled = chkAudioEnableVAC.Checked;
            }
        }

        private void comboAudioDriver3_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboAudioDriver3.SelectedIndex < 0) return;

            int old_driver = Audio.Host3;
            int new_driver = ((PADeviceInfo)comboAudioDriver3.SelectedItem).Index;
            bool power = console.PowerOn;

            if (power && chkVAC2Enable.Checked && old_driver != new_driver)
            {
                Audio.EnableVAC2(false);
            }

            //[2.10.3]MW0LGE only enable if wasapi
            if (comboAudioDriver3.SelectedIndex < PA19.PA_GetHostApiCount()) //[2.10.3.4]MW0LGE ignore the manually added HPSDR (PCM A/D)
            {
                PA19.PaHostApiInfo hostInfo = PA19.PA_GetHostApiInfo(new_driver);
                bool bIsWASAPI = hostInfo.type == (int)PA19.PaHostApiTypeId.paWASAPI;
                chkVAC2ExclusiveOut.Enabled = bIsWASAPI;
                chkVAC2ExclusiveIn.Enabled = bIsWASAPI;
                if (!bIsWASAPI) // turn these off so that when they are enabled again and vac is on, we dont start exclusive
                {
                    chkVAC2ExclusiveOut.Checked = false;
                    chkVAC1ExclusiveOut.Checked = false;
                }
            }
            else
            {
                chkVAC2ExclusiveOut.Checked = false;
                chkVAC1ExclusiveOut.Checked = false;
                chkVAC2ExclusiveOut.Enabled = false;
                chkVAC2ExclusiveIn.Enabled = false;
            }
            //

            string new_driver_name = ((PADeviceInfo)comboAudioDriver3.SelectedItem).Name;

            console.AudioDriverIndex3 = new_driver;
            Audio.Host3 = new_driver;
            GetDevices3();
            if (comboAudioInput3.Items.Count != 0)
                comboAudioInput3.SelectedIndex = 0;
            if (comboAudioOutput3.Items.Count != 0)
                comboAudioOutput3.SelectedIndex = 0;

            if (power && chkVAC2Enable.Checked && old_driver != new_driver)
            {
                Audio.EnableVAC2(false);
                Audio.VAC2Enabled = chkVAC2Enable.Checked;
            }
        }

        private void comboAudioInput2_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboAudioInput2.SelectedIndex < 0) return;

            int old_input = Audio.Input2;
            int new_input = ((PADeviceInfo)comboAudioInput2.SelectedItem).Index;
            bool power = console.PowerOn;

            if (power && chkAudioEnableVAC.Checked && old_input != new_input)
            {
                Audio.EnableVAC1(false);
            }

            console.AudioInputIndex2 = new_input;
            Audio.Input2 = new_input;

            if (power && chkAudioEnableVAC.Checked && old_input != new_input)
            {
                Audio.EnableVAC1(false);
                Audio.VACEnabled = chkAudioEnableVAC.Checked;
            }
        }

        private void comboAudioInput3_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboAudioInput3.SelectedIndex < 0) return;

            int old_input = Audio.Input3;
            int new_input = ((PADeviceInfo)comboAudioInput3.SelectedItem).Index;
            bool power = console.PowerOn;

            if (power && chkVAC2Enable.Checked && old_input != new_input)
            {
                Audio.EnableVAC2(false);
            }

            console.AudioInputIndex3 = new_input;
            Audio.Input3 = new_input;

            if (power && chkVAC2Enable.Checked && old_input != new_input)
            {
                Audio.EnableVAC2(false);
                Audio.VAC2Enabled = chkVAC2Enable.Checked;
            }
        }

        private void comboAudioOutput2_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboAudioOutput2.SelectedIndex < 0) return;

            int old_output = Audio.Output2;
            int new_output = ((PADeviceInfo)comboAudioOutput2.SelectedItem).Index;
            bool power = console.PowerOn;

            if (power && chkAudioEnableVAC.Checked && old_output != new_output)
            {
                Audio.EnableVAC1(false);
            }

            console.AudioOutputIndex2 = new_output;
            Audio.Output2 = new_output;

            if (power && chkAudioEnableVAC.Checked && old_output != new_output)
            {
                Audio.EnableVAC1(false);
                Audio.VACEnabled = chkAudioEnableVAC.Checked;
            }
        }

        private void comboAudioOutput3_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboAudioOutput3.SelectedIndex < 0) return;

            int old_output = Audio.Output3;
            int new_output = ((PADeviceInfo)comboAudioOutput3.SelectedItem).Index;
            bool power = console.PowerOn;
            if (power && chkVAC2Enable.Checked && old_output != new_output)
            {
                Audio.EnableVAC2(false);
            }

            console.AudioOutputIndex3 = new_output;
            Audio.Output3 = new_output;

            if (power && chkVAC2Enable.Checked && old_output != new_output)
            {
                Audio.EnableVAC2(false);
                Audio.VAC2Enabled = chkVAC2Enable.Checked;
            }

        }

        public void forceAudioSampleRate1(String rate)
        {
            comboAudioSampleRate1.Text = rate;
        }

        public void forceAudioSampleRateRX2(String rate)
        {
            comboAudioSampleRateRX2.Text = rate;
        }

        public void ForceAudioReset()
        {
            // pavel-demin_21a    [nothing would be forced if sample rates the same, so pavel used init flag to bypass the check in both the selectedindexchanged]
            //                    [NOTE: this had an impact on SendStopToMetis in networkproto1.c   (MW0LGE_21g comment)]
            m_bForceAudio = true;
            comboAudioSampleRate1_SelectedIndexChanged(this, EventArgs.Empty);
            comboAudioSampleRateRX2_SelectedIndexChanged(this, EventArgs.Empty);
            m_bForceAudio = false;
        }

        // access the check box for Andromeda to control variable rate (fast) tuning
        public bool AndromedaFastTune
        {
            get
            {
                return chkAndrFastStepTune.Checked;
            }
            set
            {
                chkAndrFastStepTune.Checked = value;
            }
        }

        // access the check box for Andromeda to control auto-show of the gain setting form
        public bool AndromedaGainAutoShow
        {
            get
            {
                return chkAndrGainAutoshow.Checked;
            }
            set
            {
                chkAndrGainAutoshow.Checked = value;
            }
        }

        // access the check box for Andromeda to control auto-show of the diversity form
        public bool AndromedaDiversityAutoShow
        {
            get
            {
                return chkAndrDiversityAutoshow.Checked;
            }
            set
            {
                chkAndrDiversityAutoshow.Checked = value;
            }
        }

        // access the check box for Andromeda to control Diversity form portrait or landscape layout
        public bool AndromedaDiversityFormLandscape
        {
            get
            {
                return chkAndrDiversityLandscape.Checked;
            }
            set
            {
                chkAndrDiversityLandscape.Checked = value;
            }
        }

        private bool m_bForceAudio = false;

        private void comboAudioSampleRate1_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            if (comboAudioSampleRate1.SelectedIndex < 0) return;

            int old_rate = console.SampleRateRX1;
            int new_rate = Int32.Parse(comboAudioSampleRate1.Text);
            bool was_enabled = console.RX1Enabled;  //... was set to RX2 for some reason, it should be RX1 which always true. MW0LGE_21a

            if (new_rate != old_rate || initializing || m_bForceAudio)
            {
                switch (NetworkIO.CurrentRadioProtocol)
                {
                    case RadioProtocol.ETH:
                        // turn OFF the DSP channels so they get flushed out (must do while data is flowing to get slew-down and flush)
                        WDSP.SetChannelState(WDSP.id(0, 1), 0, 0);
                        WDSP.SetChannelState(WDSP.id(0, 0), 0, 1);
                        Thread.Sleep(10);

                        // remove the RX1 main and sub audio streams from the mix set
                        unsafe { cmaster.SetAAudioMixStates((void*)0, 0, 3, 0); }

                        // disable VAC
                        if (console.PowerOn && console.VACEnabled && !initializing) Audio.EnableVAC1(false);

                        // turn OFF the DDC(s) 
                        NetworkIO.EnableRx(0, 0);
                        NetworkIO.EnableRx(1, 0);
                        NetworkIO.EnableRx(2, 0);

                        // wait for all inflight packets to arrive - need to experiment with this delay value
                        Thread.Sleep(20);

                        // flush any buffers where these old-rate packets may be stored ... this is done via operations in SetXcmInrate()

                        // in the property SampleRate1:
                        //    (1) the new samplerate will be sent to the DDC
                        //    (2) SetXcmInrate() is called by Audio.SampleRate1 which is called by console.SampleRate1
                        console.SampleRateRX1 = new_rate;

                        // set the corresponding new buffer size
                        int new_size = cmaster.GetBuffSize(new_rate);
                        console.BlockSize1 = new_size;

                        // set rate and size for the display too; could move this to SetXcmInrate() in cmaster.c
                        console.specRX.GetSpecRX(0).SampleRate = new_rate;
                        console.specRX.GetSpecRX(0).BlockSize = new_size;

                        // turn on the DDC(s)
                        console.UpdateDDCs(console.RX2Enabled);

                        // wait for samples at the new rate to be received
                        Thread.Sleep(1);
                        // add the audio streams to the mix set
                        unsafe { cmaster.SetAAudioMixStates((void*)0, 0, 3, 3); }

                        // enable VAC
                        if (console.PowerOn && console.VACEnabled && !initializing) Audio.EnableVAC1(true);

                        // turn ON the DSP channels
                        int w_enable = 0;
                        if (was_enabled) w_enable = 1;
                        WDSP.SetChannelState(WDSP.id(0, 0), w_enable, 0);
                        if (console.radio.GetDSPRX(0, 1).Active) WDSP.SetChannelState(WDSP.id(0, 1), w_enable, 0);

                        // calculate and display the new bin_width
                        double bin_width = (double)new_rate / (double)console.specRX.GetSpecRX(0).FFTSize;
                        lblDisplayBinWidth.Text = bin_width.ToString("N3");

                        // be sure RX2 sample rate setting is enabled, UNLESS it's a 10E or 100B
                        if (console.CurrentHPSDRModel == HPSDRModel.ANAN10E ||
                            console.CurrentHPSDRModel == HPSDRModel.ANAN100B)
                        {
                            // if it's a 10E/100B, set RX2 sample_rate equal to RX1 rate
                            comboAudioSampleRateRX2.Enabled = false;
                            comboAudioSampleRateRX2.SelectedIndex = comboAudioSampleRate1.SelectedIndex;
                        }
                        else
                            comboAudioSampleRateRX2.Enabled = true;

                        break;
                    case RadioProtocol.USB:
                        // turn OFF the RX DSP channels so they get flushed out (must do while data is flowing to get slew-down and flush)
                        WDSP.SetChannelState(3, 0, 0); // RX2_sub
                        WDSP.SetChannelState(2, 0, 0); // RX2_main
                        WDSP.SetChannelState(1, 0, 0); // RX1_sub
                        WDSP.SetChannelState(0, 0, 1);  // RX1_main
                        Thread.Sleep(10);

                        // remove the RX1 and RX2 (main and sub) audio streams from the mix set
                        unsafe { cmaster.SetAAudioMixStates((void*)0, 0, 15, 0); }

                        // disable VAC
                        if (console.PowerOn && console.VACEnabled && !initializing) Audio.EnableVAC1(false);
                        if (console.PowerOn && console.VAC2Enabled && !initializing) Audio.EnableVAC2(false);

                        // turn OFF the DDC(s) [SendStopToMetis]
                        NetworkIO.SendStopToMetis();

                        // wait for all inflight packets to arrive - need to experiment with this delay value
                        Thread.Sleep(25);

                        // flush any buffers where these old-rate packets may be stored ... this is done via operations in SetXcmInrate()
                        // in the property SampleRate1:  SetXcmInrate() is called by Audio.SampleRate1 which is called by console.SampleRate1
                        console.SampleRateRX1 = new_rate;
                        console.SampleRateRX2 = new_rate;

                        // set protocol_1 network software sample rate
                        NetworkIO.SetDDCRate(0, new_rate);

                        // set the corresponding new buffer size
                        int new_size1 = cmaster.GetBuffSize(new_rate);
                        console.BlockSize1 = new_size1;
                        console.BlockSizeRX2 = new_size1;

                        // set rate and size for the display too; could move this to SetXcmInrate() in cmaster.c
                        console.specRX.GetSpecRX(0).SampleRate = new_rate;
                        console.specRX.GetSpecRX(0).BlockSize = new_size1;
                        console.specRX.GetSpecRX(1).SampleRate = new_rate;
                        console.specRX.GetSpecRX(1).BlockSize = new_size1;

                        // turn on the DDC(s) [SendStartToMetis]
                        NetworkIO.SendStartToMetis();

                        // wait for samples at the new rate to be received
                        Thread.Sleep(5);

                        // add the audio streams to the mix set
                        unsafe { cmaster.SetAAudioMixStates((void*)0, 0, 3, 3); }
                        if (console.RX2Enabled)
                            unsafe { cmaster.SetAAudioMixState((void*)0, 0, 2, true); }

                        // enable VAC
                        if (console.PowerOn && console.VACEnabled && !initializing) Audio.EnableVAC1(true);
                        if (console.PowerOn && console.VAC2Enabled && !initializing) Audio.EnableVAC2(true);

                        // turn ON the DSP channels
                        WDSP.SetChannelState(0, 1, 0);              // RX1_main
                        if (console.radio.GetDSPRX(0, 1).Active)
                            WDSP.SetChannelState(1, 1, 0);          // RX1_sub
                        if (console.RX2Enabled)
                            WDSP.SetChannelState(2, 1, 0);          // RX2_main

                        // calculate and display the new bin_width
                        double bin_width1 = (double)new_rate / (double)console.specRX.GetSpecRX(0).FFTSize;
                        lblDisplayBinWidth.Text = bin_width1.ToString("N3");
                        lblRX2DisplayBinWidth.Text = bin_width1.ToString("N3");

                        // set displayed RX2 rate equal to RX1 Rate
                        comboAudioSampleRateRX2.Enabled = false;
                        comboAudioSampleRateRX2.SelectedIndex = comboAudioSampleRate1.SelectedIndex;

                        break;
                }

                console.InitFFTFillTime(1);//[2.10.1.0]MW0LGE
            }
        }

        private void comboAudioSampleRateRX2_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            if (comboAudioSampleRateRX2.SelectedIndex < 0) return;

            int old_rate = console.SampleRateRX2;
            int new_rate = Int32.Parse(comboAudioSampleRateRX2.Text);
            bool was_enabled = console.RX2Enabled;

            // MW0LGE [2.9.07] always initialise rx2 even if P1. Thanks to Reid (Gi8TME/Mi0BOT) and DH1KLM
            // see https://github.com/ramdor/Thetis-2.9.0/issues/66
            //if ((NetworkIO.CurrentRadioProtocol == RadioProtocol.ETH) && (new_rate != old_rate || initializing || m_bForceAudio))
            if (new_rate != old_rate || initializing || m_bForceAudio)
            {
                // turn OFF the DSP channel so it gets flushed out (must do while data is flowing to get slew-down and flush)
                WDSP.SetChannelState(WDSP.id(2, 0), 0, 1);
                // remove the RX2 audio stream from the mix set
                unsafe { cmaster.SetAAudioMixState((void*)0, 0, 2, false); }
                // disable VAC
                if (console.PowerOn && console.VAC2Enabled && !initializing) Audio.EnableVAC2(false);
                // turn OFF the DDC for RX2; had to add rx2_enabled as a parameter to UpdateReceivers() to do this --- THIS IS S HACK.  BETTER WAY?
                console.UpdateDDCs(false);
                // wait for all inflight packets to arrive
                Thread.Sleep(20);   // need to experiment with this time

                // flush any buffers where these old-rate packets may be stored ... this is done via operations in SetXcmInrate()

                // in the property SampleRateRX2:
                //    (1) the new samplerate will be sent to the DDC
                //    (2) SetXcmInrate() is called by Audio.SampleRateRX2 which is called by console.SampleRateRX2
                console.SampleRateRX2 = new_rate;
                // set the corresponding new buffer size
                int new_size = cmaster.GetBuffSize(new_rate);
                console.BlockSizeRX2 = new_size;
                // set rate and size for the display too; could move this to SetXcmInrate() in cmaster.c
                console.specRX.GetSpecRX(1).SampleRate = new_rate;
                console.specRX.GetSpecRX(1).BlockSize = new_size;
                // turn the DDC for RX2 back ON; had to add rx2_enabled as a parameter to UpdateReceivers() to do this
                if (was_enabled)
                {
                    console.UpdateDDCs(true);
                    // wait for samples at the new rate to be received
                    Thread.Sleep(1);   // need to experiment with this time
                    // add the RX2 audio stream to the mix set
                    unsafe { cmaster.SetAAudioMixState((void*)0, 0, 2, true); }
                }
                // enable VAC2
                if (console.PowerOn && console.VAC2Enabled && !initializing) Audio.EnableVAC2(true);
                // turn ON the DSP channel if it was ON before
                int w_enable = 0;
                if (was_enabled) w_enable = 1;
                WDSP.SetChannelState(WDSP.id(2, 0), w_enable, 0);
                // calculate and display the new bin_width
                double bin_width = (double)new_rate / (double)console.specRX.GetSpecRX(1).FFTSize;
                lblRX2DisplayBinWidth.Text = bin_width.ToString("N3");
            }

            console.InitFFTFillTime(2);//[2.10.1.0]MW0LGE
        }

        private void comboAudioSampleRate2_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            if (comboAudioSampleRate2.SelectedIndex < 0) return;

            int old_rate = console.SampleRate2;
            int new_rate = Int32.Parse(comboAudioSampleRate2.Text);
            bool poweron = console.PowerOn;

            if (poweron && chkAudioEnableVAC.Checked && new_rate != old_rate)
            {
                Audio.EnableVAC1(false);
            }

            console.SampleRate2 = new_rate;
            console.VACSampleRate = comboAudioSampleRate2.Text;

            if (poweron && chkAudioEnableVAC.Checked && new_rate != old_rate)
            {
                Audio.VACEnabled = chkAudioEnableVAC.Checked;
            }
        }

        private void comboAudioSampleRate3_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboAudioSampleRate3.SelectedIndex < 0) return;

            int old_rate = console.SampleRate3;
            int new_rate = Int32.Parse(comboAudioSampleRate3.Text);
            bool poweron = console.PowerOn;

            if (poweron && chkVAC2Enable.Checked && new_rate != old_rate)
            {
                Audio.EnableVAC2(false);
            }

            console.SampleRate3 = new_rate;
            console.VAC2SampleRate = comboAudioSampleRate3.Text;

            if (poweron && chkVAC2Enable.Checked && new_rate != old_rate)
            {
                Audio.VAC2Enabled = chkVAC2Enable.Checked;
            }
        }

        private void comboAudioBuffer1_SelectedIndexChanged(object sender, System.EventArgs e)
        {

        }

        private void comboAudioBuffer2_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            if (comboAudioBuffer2.SelectedIndex < 0) return;

            int old_size = console.BlockSize2;
            int new_size = Int32.Parse(comboAudioBuffer2.Text);
            bool power = console.PowerOn;

            if (power && chkAudioEnableVAC.Checked && old_size != new_size)
            {
                Audio.EnableVAC1(false);
            }

            console.BlockSize2 = new_size;

            if (power && chkAudioEnableVAC.Checked && old_size != new_size)
            {
                Audio.VACEnabled = chkAudioEnableVAC.Checked;
            }
        }

        private void comboAudioBuffer3_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboAudioBuffer3.SelectedIndex < 0) return;

            int old_size = console.BlockSize3;
            int new_size = Int32.Parse(comboAudioBuffer3.Text);
            bool power = console.PowerOn;

            if (power && chkVAC2Enable.Checked && old_size != new_size)
            {
                Audio.EnableVAC2(false);
            }

            console.BlockSize3 = new_size;

            if (power && chkVAC2Enable.Checked && old_size != new_size)
            {
                Audio.VAC2Enabled = chkVAC2Enable.Checked;
            }
        }

        private void udAudioLatency2_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            // RingBuffer In
            bool power = console.PowerOn;
            if (power && chkAudioEnableVAC.Checked)
            {
                Audio.EnableVAC1(false);
            }

            Audio.Latency2 = (int)udAudioLatency2.Value;

            if (power && chkAudioEnableVAC.Checked)
                Audio.VACEnabled = chkAudioEnableVAC.Checked;
        }

        private void udAudioLatency2_Out_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            // RingBuffer Out
            bool power = console.PowerOn;
            if (power && chkAudioEnableVAC.Checked)
            {
                Audio.EnableVAC1(false);
            }

            Audio.Latency2_Out = (int)udAudioLatency2_Out.Value;

            if (power && chkAudioEnableVAC.Checked)
                Audio.VACEnabled = chkAudioEnableVAC.Checked;
        }


        private void udAudioLatencyPAIn_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            // PortAudio In
            bool power = console.PowerOn;
            if (power && chkAudioEnableVAC.Checked)
            {
                Audio.EnableVAC1(false);
            }

            Audio.LatencyPAIn = (int)udAudioLatencyPAIn.Value;

            if (power && chkAudioEnableVAC.Checked)
                Audio.VACEnabled = chkAudioEnableVAC.Checked;
        }

        private void udAudioLatencyPAOut_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            // PortAudio Out
            bool power = console.PowerOn;
            if (power && chkAudioEnableVAC.Checked)
            {
                Audio.EnableVAC1(false);
            }

            Audio.LatencyPAOut = (int)udAudioLatencyPAOut.Value;

            if (power && chkAudioEnableVAC.Checked)
                Audio.VACEnabled = chkAudioEnableVAC.Checked;
        }

        private void udVAC2Latency_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            bool power = console.PowerOn;
            if (power && chkVAC2Enable.Checked)
            {
                Audio.EnableVAC2(false);
            }

            Audio.Latency3 = (int)udVAC2Latency.Value;

            if (power && chkVAC2Enable.Checked)
                Audio.VAC2Enabled = chkVAC2Enable.Checked;
        }

        private void udVAC2LatencyOut_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            bool power = console.PowerOn;
            if (power && chkVAC2Enable.Checked)
            {
                Audio.EnableVAC2(false);
            }

            Audio.VAC2LatencyOut = (int)udVAC2LatencyOut.Value;

            if (power && chkVAC2Enable.Checked)
                Audio.VAC2Enabled = chkVAC2Enable.Checked;
        }

        private void udVAC2LatencyPAIn_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            bool power = console.PowerOn;
            if (power && chkVAC2Enable.Checked)
            {
                Audio.EnableVAC2(false);
            }

            Audio.VAC2LatencyPAIn = (int)udVAC2LatencyPAIn.Value;

            if (power && chkVAC2Enable.Checked)
                Audio.VAC2Enabled = chkVAC2Enable.Checked;
        }

        private void udVAC2LatencyPAOut_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            bool power = console.PowerOn;
            if (power && chkVAC2Enable.Checked)
            {
                Audio.EnableVAC2(false);
            }

            Audio.VAC2LatencyPAOut = (int)udVAC2LatencyPAOut.Value;

            if (power && chkVAC2Enable.Checked)
                Audio.VAC2Enabled = chkVAC2Enable.Checked;
        }

        private void chkAudio2Stereo_CheckedChanged(object sender, System.EventArgs e)
        {
            console.VACSoundCardStereo = chkAudio2Stereo.Checked;
            console.VACStereo = chkAudio2Stereo.Checked;
            chkVACCombine.Enabled = chkAudio2Stereo.Checked;
        }

        private void chkAudioStereo3_CheckedChanged(object sender, System.EventArgs e)
        {
            console.VAC2SoundCardStereo = chkAudio2Stereo.Checked;
            console.VAC2Stereo = chkAudioStereo3.Checked;
            chkVAC2Combine.Enabled = chkAudioStereo3.Checked;
        }

        private void udAudioVACGainRX_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Audio.VACRXScale = Math.Pow(10.0, (int)udAudioVACGainRX.Value / 20.0);
            console.VACRXGain = (int)udAudioVACGainRX.Value;
            if (console.sliderForm != null)
            {
                console.sliderForm.RX1VACRX = (int)udAudioVACGainRX.Value;

                //wd5y
                console.sliderForm.lblRX1VACRX.Text = console.VACRXGain.ToString();
                //wd5y
            }
        }

        private void udVAC2GainRX_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Audio.VAC2RXScale = Math.Pow(10.0, (int)udVAC2GainRX.Value / 20.0);
            console.VAC2RXGain = (int)udVAC2GainRX.Value;
            if (console.sliderForm != null)
            {
                console.sliderForm.RX2VACRX = (int)udVAC2GainRX.Value;

                //wd5y
                console.sliderForm.lblRX2VACRX.Text = console.VAC2RXGain.ToString();
                //wd5y
            }
        }

        private void udAudioVACGainTX_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Audio.VACPreamp = Math.Pow(10.0, (int)udAudioVACGainTX.Value / 20.0);
            console.VACTXGain = (int)udAudioVACGainTX.Value;
            if (console.sliderForm != null)
            {
                console.sliderForm.RX1VACTX = (int)udAudioVACGainTX.Value;

                //wd5y
                console.sliderForm.lblRX1VACTX.Text = console.VACTXGain.ToString();
                //wd5y
            }
        }

        private void udVAC2GainTX_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Audio.VAC2TXScale = Math.Pow(10.0, (int)udVAC2GainTX.Value / 20.0);
            console.VAC2TXGain = (int)udVAC2GainTX.Value;
            if (console.sliderForm != null)
            {
                console.sliderForm.RX2VACTX = (int)udVAC2GainTX.Value;

                //wd5y
                console.sliderForm.lblRX2VACTX.Text = console.VAC2TXGain.ToString();
                //wd5y
            }
        }

        private void chkAudioVACAutoEnable_CheckedChanged(object sender, System.EventArgs e)
        {
            console.VACAutoEnable = chkAudioVACAutoEnable.Checked;
        }

        private void chkVAC2AutoEnable_CheckedChanged(object sender, System.EventArgs e)
        {
            console.VAC2AutoEnable = chkVAC2AutoEnable.Checked;
        }

        private void chkAudioLatencyManual2_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            bool power = console.PowerOn;
            if (power && chkAudioEnableVAC.Checked)
            {
                ivac.SetIVACrun(0, 0);
                ivac.StopAudioIVAC(0);
            }

            udAudioLatency2.Enabled = chkAudioLatencyManual2.Checked;
            Audio.VAC1LatencyManual = chkAudioLatencyManual2.Checked;

            if (power && chkAudioEnableVAC.Checked)
                Audio.VACEnabled = chkAudioEnableVAC.Checked;
        }

        private void chkAudioLatencyManual2_Out_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            bool power = console.PowerOn;
            if (power && chkAudioEnableVAC.Checked)
            {
                ivac.SetIVACrun(0, 0);
                ivac.StopAudioIVAC(0);
            }

            udAudioLatency2_Out.Enabled = chkAudioLatencyManual2_Out.Checked;
            Audio.VAC1LatencyManualOut = chkAudioLatencyManual2_Out.Checked;

            if (power && chkAudioEnableVAC.Checked)
                Audio.VACEnabled = chkAudioEnableVAC.Checked;
        }

        private void chkAudioLatencyPAInManual_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            bool power = console.PowerOn;
            if (power && chkAudioEnableVAC.Checked)
            {
                ivac.SetIVACrun(0, 0);
                ivac.StopAudioIVAC(0);
            }

            udAudioLatencyPAIn.Enabled = chkAudioLatencyPAInManual.Checked;
            Audio.VAC1LatencyPAInManual = chkAudioLatencyPAInManual.Checked;

            if (power && chkAudioEnableVAC.Checked)
                Audio.VACEnabled = chkAudioEnableVAC.Checked;
        }

        private void chkAudioLatencyPAOutManual_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            bool power = console.PowerOn;
            if (power && chkAudioEnableVAC.Checked)
            {
                ivac.SetIVACrun(0, 0);
                ivac.StopAudioIVAC(0);
            }

            udAudioLatencyPAOut.Enabled = chkAudioLatencyPAOutManual.Checked;
            Audio.VAC1LatencyPAOutManual = chkAudioLatencyPAOutManual.Checked;

            if (power && chkAudioEnableVAC.Checked)
                Audio.VACEnabled = chkAudioEnableVAC.Checked;
        }

        private void chkVAC2LatencyManual_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            bool power = console.PowerOn;
            if (power && chkVAC2Enable.Checked)
            {
                ivac.SetIVACrun(1, 0);
                ivac.StopAudioIVAC(1);
            }

            udVAC2Latency.Enabled = chkVAC2LatencyManual.Checked;
            Audio.VAC2LatencyManual = chkVAC2LatencyManual.Checked;

            if (power && chkVAC2Enable.Checked)
                Audio.VAC2Enabled = chkVAC2Enable.Checked;
        }

        private void chkVAC2LatencyOutManual_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            bool power = console.PowerOn;
            if (power && chkVAC2Enable.Checked)
            {
                ivac.SetIVACrun(1, 0);
                ivac.StopAudioIVAC(1);
            }

            udVAC2LatencyOut.Enabled = chkVAC2LatencyOutManual.Checked;
            Audio.VAC2LatencyOutManual = chkVAC2LatencyOutManual.Checked;

            if (power && chkVAC2Enable.Checked)
                Audio.VAC2Enabled = chkVAC2Enable.Checked;
        }

        private void chkVAC2LatencyPAInManual_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            bool power = console.PowerOn;
            if (power && chkVAC2Enable.Checked)
            {
                ivac.SetIVACrun(1, 0);
                ivac.StopAudioIVAC(1);
            }

            udVAC2LatencyPAIn.Enabled = chkVAC2LatencyPAInManual.Checked;
            Audio.VAC2LatencyPAInManual = chkVAC2LatencyPAInManual.Checked;

            if (power && chkVAC2Enable.Checked)
                Audio.VAC2Enabled = chkVAC2Enable.Checked;
        }

        private void chkVAC2LatencyPAOutManual_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            bool power = console.PowerOn;
            if (power && chkVAC2Enable.Checked)
            {
                ivac.SetIVACrun(1, 0);
                ivac.StopAudioIVAC(1);
            }

            udVAC2LatencyPAOut.Enabled = chkVAC2LatencyPAOutManual.Checked;
            Audio.VAC2LatencyPAOutManual = chkVAC2LatencyPAOutManual.Checked;
            if (power && chkVAC2Enable.Checked)
                Audio.VAC2Enabled = chkVAC2Enable.Checked;
        }

        private void chk20dbMicBoost_CheckedChanged(object sender, System.EventArgs e)
        {
            if (chk20dbMicBoost.Checked) udVOXGain_ValueChanged(this, e);
            console.MicBoost = chk20dbMicBoost.Checked;
        }

        #endregion

        #region Display Tab Event Handlers
        // ======================================================
        // Display Tab Event Handlers
        // ======================================================

        private void udDisplayGridMax_LostFocus(object sender, System.EventArgs e)
        {
            Display.SpectrumGridMax = (int)udDisplayGridMax.Value;
        }

        private void udTXGridMax_LostFocus(object sender, System.EventArgs e)
        {
            Display.TXSpectrumGridMax = (int)udTXGridMax.Value;
        }

        private void udDisplayGridMax_Click(object sender, System.EventArgs e)
        {
            udDisplayGridMax_LostFocus(sender, e);
        }

        private void udDisplayGridMax_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            udDisplayGridMax_LostFocus(sender, new System.EventArgs());
        }

        private void udDisplayFPS_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.DisplayFPS = (int)udDisplayFPS.Value;

            Display.ResetDX2DModeDescription();

            udDisplayAVGTime_ValueChanged(this, EventArgs.Empty);

            setWaterFallCalculatedDelayText();
        }

        private void udDisplayGridMax_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            //[2.10.3.6]MW0LGE limit
            if (udDisplayGridMax.Value < udDisplayGridMin.Value + udDisplayGridStep.Value)
            {
                udDisplayGridMax.Value = udDisplayGridMin.Value + udDisplayGridStep.Value;
                return;
            }
            //
            UpdateDisplayGridBandInfo();
            switch (console.RX1Band)
            {
                case Band.B160M:
                    console.DisplayGridMax160m = (float)udDisplayGridMax.Value;
                    Display.SpectrumGridMax = (int)console.DisplayGridMax160m;
                    break;
                case Band.B80M:
                    console.DisplayGridMax80m = (float)udDisplayGridMax.Value;
                    Display.SpectrumGridMax = (int)console.DisplayGridMax80m;
                    break;
                case Band.B60M:
                    console.DisplayGridMax60m = (float)udDisplayGridMax.Value;
                    Display.SpectrumGridMax = (int)console.DisplayGridMax60m;
                    break;
                case Band.B40M:
                    console.DisplayGridMax40m = (float)udDisplayGridMax.Value;
                    Display.SpectrumGridMax = (int)console.DisplayGridMax40m;
                    break;
                case Band.B30M:
                    console.DisplayGridMax30m = (float)udDisplayGridMax.Value;
                    Display.SpectrumGridMax = (int)console.DisplayGridMax30m;
                    break;
                case Band.B20M:
                    console.DisplayGridMax20m = (float)udDisplayGridMax.Value;
                    Display.SpectrumGridMax = (int)console.DisplayGridMax20m;
                    break;
                case Band.B17M:
                    console.DisplayGridMax17m = (float)udDisplayGridMax.Value;
                    Display.SpectrumGridMax = (int)console.DisplayGridMax17m;
                    break;
                case Band.B15M:
                    console.DisplayGridMax15m = (float)udDisplayGridMax.Value;
                    Display.SpectrumGridMax = (int)console.DisplayGridMax15m;
                    break;
                case Band.B12M:
                    console.DisplayGridMax12m = (float)udDisplayGridMax.Value;
                    Display.SpectrumGridMax = (int)console.DisplayGridMax12m;
                    break;
                case Band.B10M:
                    console.DisplayGridMax10m = (float)udDisplayGridMax.Value;
                    Display.SpectrumGridMax = (int)console.DisplayGridMax10m;
                    break;
                case Band.B6M:
                    console.DisplayGridMax6m = (float)udDisplayGridMax.Value;
                    Display.SpectrumGridMax = (int)console.DisplayGridMax6m;
                    break;
                case Band.WWV:
                    console.DisplayGridMaxWWV = (float)udDisplayGridMax.Value;
                    Display.SpectrumGridMax = (int)console.DisplayGridMaxWWV;
                    break;
                case Band.GEN:
                    console.DisplayGridMaxGEN = (float)udDisplayGridMax.Value;
                    Display.SpectrumGridMax = (int)console.DisplayGridMaxGEN;
                    break;
                default:
                    console.DisplayGridMaxXVTR = (float)udDisplayGridMax.Value;
                    Display.SpectrumGridMax = (int)console.DisplayGridMaxXVTR;
                    break;
            }

            console.WaterfallUseRX1SpectrumMinMax = chkWaterfallUseRX1SpectrumMinMax.Checked; // MW0LGE_21d this will force an update
                                                                                              // which is needed because Cat etc will cause
                                                                                              // this valuechanged event

        }

        private void udDisplayGridMin_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            //[2.10.3.6]MW0LGE limit
            if(udDisplayGridMin.Value > udDisplayGridMax.Value - udDisplayGridStep.Value)
            {
                udDisplayGridMin.Value = udDisplayGridMax.Value - udDisplayGridStep.Value;
                return;
            }
            //
            UpdateDisplayGridBandInfo();
            switch (console.RX1Band)
            {
                case Band.B160M:
                    console.DisplayGridMin160m = (float)udDisplayGridMin.Value;
                    Display.SpectrumGridMin = (int)console.DisplayGridMin160m;
                    break;
                case Band.B80M:
                    console.DisplayGridMin80m = (float)udDisplayGridMin.Value;
                    Display.SpectrumGridMin = (int)console.DisplayGridMin80m;
                    break;
                case Band.B60M:
                    console.DisplayGridMin60m = (float)udDisplayGridMin.Value;
                    Display.SpectrumGridMin = (int)console.DisplayGridMin60m;
                    break;
                case Band.B40M:
                    console.DisplayGridMin40m = (float)udDisplayGridMin.Value;
                    Display.SpectrumGridMin = (int)console.DisplayGridMin40m;
                    break;
                case Band.B30M:
                    console.DisplayGridMin30m = (float)udDisplayGridMin.Value;
                    Display.SpectrumGridMin = (int)console.DisplayGridMin30m;
                    break;
                case Band.B20M:
                    console.DisplayGridMin20m = (float)udDisplayGridMin.Value;
                    Display.SpectrumGridMin = (int)console.DisplayGridMin20m;
                    break;
                case Band.B17M:
                    console.DisplayGridMin17m = (float)udDisplayGridMin.Value;
                    Display.SpectrumGridMin = (int)console.DisplayGridMin17m;
                    break;
                case Band.B15M:
                    console.DisplayGridMin15m = (float)udDisplayGridMin.Value;
                    Display.SpectrumGridMin = (int)console.DisplayGridMin15m;
                    break;
                case Band.B12M:
                    console.DisplayGridMin12m = (float)udDisplayGridMin.Value;
                    Display.SpectrumGridMin = (int)console.DisplayGridMin12m;
                    break;
                case Band.B10M:
                    console.DisplayGridMin10m = (float)udDisplayGridMin.Value;
                    Display.SpectrumGridMin = (int)console.DisplayGridMin10m;
                    break;
                case Band.B6M:
                    console.DisplayGridMin6m = (float)udDisplayGridMin.Value;
                    Display.SpectrumGridMin = (int)console.DisplayGridMin6m;
                    break;
                case Band.WWV:
                    console.DisplayGridMinWWV = (float)udDisplayGridMin.Value;
                    Display.SpectrumGridMin = (int)console.DisplayGridMinWWV;
                    break;
                case Band.GEN:
                    console.DisplayGridMinGEN = (float)udDisplayGridMin.Value;
                    Display.SpectrumGridMin = (int)console.DisplayGridMinGEN;
                    break;
                default:
                    console.DisplayGridMinXVTR = (float)udDisplayGridMin.Value;
                    Display.SpectrumGridMin = (int)console.DisplayGridMinXVTR;
                    break;
            }
            console.UpdateDisplayGridLevelMinValues(true); //MW0LGE  //MW0LGE_21e
            console.WaterfallUseRX1SpectrumMinMax = chkWaterfallUseRX1SpectrumMinMax.Checked; // MW0LGE_21d this will force an update
                                                                                              // which is needed because Cat etc will cause
                                                                                              // this valuechanged event

        }

        private void udDisplayGridStep_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Display.SpectrumGridStep = (int)udDisplayGridStep.Value;
        }

        private void udRX2DisplayGridMax_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            //[2.10.3.6]MW0LGE limit
            if (udRX2DisplayGridMax.Value < udRX2DisplayGridMin.Value + udRX2DisplayGridStep.Value)
            {
                udRX2DisplayGridMax.Value = udRX2DisplayGridMin.Value + udRX2DisplayGridStep.Value;
                return;
            }
            //
            UpdateDisplayGridBandInfo();
            switch (console.RX2Band)
            {
                case Band.B160M:
                    console.RX2DisplayGridMax160m = (float)udRX2DisplayGridMax.Value;
                    Display.RX2SpectrumGridMax = (int)console.RX2DisplayGridMax160m;
                    break;
                case Band.B80M:
                    console.RX2DisplayGridMax80m = (float)udRX2DisplayGridMax.Value;
                    Display.RX2SpectrumGridMax = (int)console.RX2DisplayGridMax80m;
                    break;
                case Band.B60M:
                    console.RX2DisplayGridMax60m = (float)udRX2DisplayGridMax.Value;
                    Display.RX2SpectrumGridMax = (int)console.RX2DisplayGridMax60m;
                    break;
                case Band.B40M:
                    console.RX2DisplayGridMax40m = (float)udRX2DisplayGridMax.Value;
                    Display.RX2SpectrumGridMax = (int)console.RX2DisplayGridMax40m;
                    break;
                case Band.B30M:
                    console.RX2DisplayGridMax30m = (float)udRX2DisplayGridMax.Value;
                    Display.RX2SpectrumGridMax = (int)console.RX2DisplayGridMax30m;
                    break;
                case Band.B20M:
                    console.RX2DisplayGridMax20m = (float)udRX2DisplayGridMax.Value;
                    Display.RX2SpectrumGridMax = (int)console.RX2DisplayGridMax20m;
                    break;
                case Band.B17M:
                    console.RX2DisplayGridMax17m = (float)udRX2DisplayGridMax.Value;
                    Display.RX2SpectrumGridMax = (int)console.RX2DisplayGridMax17m;
                    break;
                case Band.B15M:
                    console.RX2DisplayGridMax15m = (float)udRX2DisplayGridMax.Value;
                    Display.RX2SpectrumGridMax = (int)console.RX2DisplayGridMax15m;
                    break;
                case Band.B12M:
                    console.RX2DisplayGridMax12m = (float)udRX2DisplayGridMax.Value;
                    Display.RX2SpectrumGridMax = (int)console.RX2DisplayGridMax12m;
                    break;
                case Band.B10M:
                    console.RX2DisplayGridMax10m = (float)udRX2DisplayGridMax.Value;
                    Display.RX2SpectrumGridMax = (int)console.RX2DisplayGridMax10m;
                    break;
                case Band.B6M:
                    console.RX2DisplayGridMax6m = (float)udRX2DisplayGridMax.Value;
                    Display.RX2SpectrumGridMax = (int)console.RX2DisplayGridMax6m;
                    break;
                case Band.WWV:
                    console.RX2DisplayGridMaxWWV = (float)udRX2DisplayGridMax.Value;
                    Display.RX2SpectrumGridMax = (int)console.RX2DisplayGridMaxWWV;
                    break;
                case Band.GEN:
                    console.RX2DisplayGridMaxGEN = (float)udRX2DisplayGridMax.Value;
                    Display.RX2SpectrumGridMax = (int)console.RX2DisplayGridMaxGEN;
                    break;
                default:
                    console.RX2DisplayGridMaxXVTR = (float)udRX2DisplayGridMax.Value;
                    Display.RX2SpectrumGridMax = (int)console.RX2DisplayGridMaxXVTR;
                    break;
            }

            console.UpdateDisplayGridLevelMaxValues(false); //MW0LGE  //MW0LGE_21e
            console.WaterfallUseRX2SpectrumMinMax = chkWaterfallUseRX2SpectrumMinMax.Checked; // MW0LGE_21d this will force an update
                                                                                              // which is needed because Cat etc will cause
                                                                                              // this valuechanged event

        }

        private void udRX2DisplayGridMin_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            //[2.10.3.6]MW0LGE limit
            if (udRX2DisplayGridMin.Value > udRX2DisplayGridMax.Value - udRX2DisplayGridStep.Value)
            {
                udRX2DisplayGridMin.Value = udRX2DisplayGridMax.Value - udRX2DisplayGridStep.Value;
                return;
            }
            //
            UpdateDisplayGridBandInfo();
            switch (console.RX2Band)
            {
                case Band.B160M:
                    console.RX2DisplayGridMin160m = (float)udRX2DisplayGridMin.Value;
                    Display.RX2SpectrumGridMin = (int)console.RX2DisplayGridMin160m;
                    break;
                case Band.B80M:
                    console.RX2DisplayGridMin80m = (float)udRX2DisplayGridMin.Value;
                    Display.RX2SpectrumGridMin = (int)console.RX2DisplayGridMin80m;
                    break;
                case Band.B60M:
                    console.RX2DisplayGridMin60m = (float)udRX2DisplayGridMin.Value;
                    Display.RX2SpectrumGridMin = (int)console.RX2DisplayGridMin60m;
                    break;
                case Band.B40M:
                    console.RX2DisplayGridMin40m = (float)udRX2DisplayGridMin.Value;
                    Display.RX2SpectrumGridMin = (int)console.RX2DisplayGridMin40m;
                    break;
                case Band.B30M:
                    console.RX2DisplayGridMin30m = (float)udRX2DisplayGridMin.Value;
                    Display.RX2SpectrumGridMin = (int)console.RX2DisplayGridMin30m;
                    break;
                case Band.B20M:
                    console.RX2DisplayGridMin20m = (float)udRX2DisplayGridMin.Value;
                    Display.RX2SpectrumGridMin = (int)console.RX2DisplayGridMin20m;
                    break;
                case Band.B17M:
                    console.RX2DisplayGridMin17m = (float)udRX2DisplayGridMin.Value;
                    Display.RX2SpectrumGridMin = (int)console.RX2DisplayGridMin17m;
                    break;
                case Band.B15M:
                    console.RX2DisplayGridMin15m = (float)udRX2DisplayGridMin.Value;
                    Display.RX2SpectrumGridMin = (int)console.RX2DisplayGridMin15m;
                    break;
                case Band.B12M:
                    console.RX2DisplayGridMin12m = (float)udRX2DisplayGridMin.Value;
                    Display.RX2SpectrumGridMin = (int)console.RX2DisplayGridMin12m;
                    break;
                case Band.B10M:
                    console.RX2DisplayGridMin10m = (float)udRX2DisplayGridMin.Value;
                    Display.RX2SpectrumGridMin = (int)console.RX2DisplayGridMin10m;
                    break;
                case Band.B6M:
                    console.RX2DisplayGridMin6m = (float)udRX2DisplayGridMin.Value;
                    Display.RX2SpectrumGridMin = (int)console.RX2DisplayGridMin6m;
                    break;
                case Band.WWV:
                    console.RX2DisplayGridMinWWV = (float)udRX2DisplayGridMin.Value;
                    Display.RX2SpectrumGridMin = (int)console.RX2DisplayGridMinWWV;
                    break;
                case Band.GEN:
                    console.RX2DisplayGridMinGEN = (float)udRX2DisplayGridMin.Value;
                    Display.RX2SpectrumGridMin = (int)console.RX2DisplayGridMinGEN;
                    break;
                default:
                    console.RX2DisplayGridMinXVTR = (float)udRX2DisplayGridMin.Value;
                    Display.RX2SpectrumGridMin = (int)console.RX2DisplayGridMinXVTR;
                    break;
            }
            console.WaterfallUseRX2SpectrumMinMax = chkWaterfallUseRX2SpectrumMinMax.Checked; // MW0LGE_21d this will force an update
                                                                                              // which is needed because Cat etc will cause
                                                                                              // this valuechanged event
        }

        private void udRX2DisplayGridStep_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Display.RX2SpectrumGridStep = (int)udRX2DisplayGridStep.Value;
        }

        private void comboDisplayLabelAlign_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            switch (comboDisplayLabelAlign.Text)
            {
                case "Left":
                    Display.DisplayLabelAlign = DisplayLabelAlignment.LEFT;
                    break;
                case "Cntr":
                    Display.DisplayLabelAlign = DisplayLabelAlignment.CENTER;
                    break;
                case "Right":
                    Display.DisplayLabelAlign = DisplayLabelAlignment.RIGHT;
                    break;
                case "Auto":
                    Display.DisplayLabelAlign = DisplayLabelAlignment.AUTO;
                    break;
                case "Off":
                    Display.DisplayLabelAlign = DisplayLabelAlignment.OFF;
                    break;
                default:
                    Display.DisplayLabelAlign = DisplayLabelAlignment.LEFT;
                    break;
            }
        }

        private void udDisplayPhasePts_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Display.PhaseNumPts = (int)udDisplayPhasePts.Value;
        }

        private void udDisplayAVGTime_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.specRX.GetSpecRX(0).AvTau = 0.001 * (double)udDisplayAVGTime.Value;
            console.UpdateRXSpectrumDisplayVars();
            console.specRX.GetSpecRX(cmaster.inid(1, 0)).AvTau = 0.001 * (double)udDisplayAVGTime.Value;
            console.UpdateTXSpectrumDisplayVars();
            double display_time = 1 / (double)udDisplayFPS.Value;
            int buffersToAvg = (int)((float)udDisplayAVGTime.Value * 0.001 / display_time);
        }

        private void udRX2DisplayAVGTime_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.specRX.GetSpecRX(1).AvTau = 0.001 * (double)udRX2DisplayAVGTime.Value;
        }

        private void udDisplayMeterDelay_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.MeterDelay = (int)udDisplayMeterDelay.Value;
        }

        private void udDisplayPeakText_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.PeakTextDelay = (int)udDisplayPeakText.Value;
        }

        private void udDisplayCPUMeter_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.CPUMeterDelay = (int)udDisplayCPUMeter.Value;
        }

        private void clrbtnWaterfallLow_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Display.WaterfallLowColor = clrbtnWaterfallLow.Color;
        }

        private void udDisplayWaterfallLowLevel_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            //[2.10.3.6]MW0LGE limit
            if(udDisplayWaterfallLowLevel.Value > udDisplayWaterfallHighLevel.Value - 3)
            {
                udDisplayWaterfallLowLevel.Value = udDisplayWaterfallHighLevel.Value - 3;
                return;
            }
            //
            UpdateWaterfallBandInfo();
            switch (console.RX1Band)
            {
                case Band.B160M:
                    console.WaterfallLowThreshold160m = (float)udDisplayWaterfallLowLevel.Value;
                    Display.WaterfallLowThreshold = console.WaterfallLowThreshold160m;
                    break;
                case Band.B80M:
                    console.WaterfallLowThreshold80m = (float)udDisplayWaterfallLowLevel.Value;
                    Display.WaterfallLowThreshold = console.WaterfallLowThreshold80m;
                    break;
                case Band.B60M:
                    console.WaterfallLowThreshold60m = (float)udDisplayWaterfallLowLevel.Value;
                    Display.WaterfallLowThreshold = console.WaterfallLowThreshold60m;
                    break;
                case Band.B40M:
                    console.WaterfallLowThreshold40m = (float)udDisplayWaterfallLowLevel.Value;
                    Display.WaterfallLowThreshold = console.WaterfallLowThreshold40m;
                    break;
                case Band.B30M:
                    console.WaterfallLowThreshold30m = (float)udDisplayWaterfallLowLevel.Value;
                    Display.WaterfallLowThreshold = console.WaterfallLowThreshold30m;
                    break;
                case Band.B20M:
                    console.WaterfallLowThreshold20m = (float)udDisplayWaterfallLowLevel.Value;
                    Display.WaterfallLowThreshold = console.WaterfallLowThreshold20m;
                    break;
                case Band.B17M:
                    console.WaterfallLowThreshold17m = (float)udDisplayWaterfallLowLevel.Value;
                    Display.WaterfallLowThreshold = console.WaterfallLowThreshold17m;
                    break;
                case Band.B15M:
                    console.WaterfallLowThreshold15m = (float)udDisplayWaterfallLowLevel.Value;
                    Display.WaterfallLowThreshold = console.WaterfallLowThreshold15m;
                    break;
                case Band.B12M:
                    console.WaterfallLowThreshold12m = (float)udDisplayWaterfallLowLevel.Value;
                    Display.WaterfallLowThreshold = console.WaterfallLowThreshold12m;
                    break;
                case Band.B10M:
                    console.WaterfallLowThreshold10m = (float)udDisplayWaterfallLowLevel.Value;
                    Display.WaterfallLowThreshold = console.WaterfallLowThreshold10m;
                    break;
                case Band.B6M:
                    console.WaterfallLowThreshold6m = (float)udDisplayWaterfallLowLevel.Value;
                    Display.WaterfallLowThreshold = console.WaterfallLowThreshold6m;
                    break;
                case Band.WWV:
                    console.WaterfallLowThresholdWWV = (float)udDisplayWaterfallLowLevel.Value;
                    Display.WaterfallLowThreshold = console.WaterfallLowThresholdWWV;
                    break;
                case Band.GEN:
                    console.WaterfallLowThresholdGEN = (float)udDisplayWaterfallLowLevel.Value;
                    Display.WaterfallLowThreshold = console.WaterfallLowThresholdGEN;
                    break;
                default:
                    console.WaterfallLowThresholdXVTR = (float)udDisplayWaterfallLowLevel.Value;
                    Display.WaterfallLowThreshold = console.WaterfallLowThresholdXVTR;
                    break;
            }
        }

        private void udDisplayWaterfallHighLevel_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            //[2.10.3.6]MW0LGE limit
            if (udDisplayWaterfallHighLevel.Value < udDisplayWaterfallLowLevel.Value + 3)
            {
                udDisplayWaterfallHighLevel.Value = udDisplayWaterfallLowLevel.Value + 3;
                return;
            }
            //
            UpdateWaterfallBandInfo();
            switch (console.RX1Band)
            {
                case Band.B160M:
                    console.WaterfallHighThreshold160m = (float)udDisplayWaterfallHighLevel.Value;
                    Display.WaterfallHighThreshold = console.WaterfallHighThreshold160m;
                    break;
                case Band.B80M:
                    console.WaterfallHighThreshold80m = (float)udDisplayWaterfallHighLevel.Value;
                    Display.WaterfallHighThreshold = console.WaterfallHighThreshold80m;
                    break;
                case Band.B60M:
                    console.WaterfallHighThreshold60m = (float)udDisplayWaterfallHighLevel.Value;
                    Display.WaterfallHighThreshold = console.WaterfallHighThreshold60m;
                    break;
                case Band.B40M:
                    console.WaterfallHighThreshold40m = (float)udDisplayWaterfallHighLevel.Value;
                    Display.WaterfallHighThreshold = console.WaterfallHighThreshold40m;
                    break;
                case Band.B30M:
                    console.WaterfallHighThreshold30m = (float)udDisplayWaterfallHighLevel.Value;
                    Display.WaterfallHighThreshold = console.WaterfallHighThreshold30m;
                    break;
                case Band.B20M:
                    console.WaterfallHighThreshold20m = (float)udDisplayWaterfallHighLevel.Value;
                    Display.WaterfallHighThreshold = console.WaterfallHighThreshold20m;
                    break;
                case Band.B17M:
                    console.WaterfallHighThreshold17m = (float)udDisplayWaterfallHighLevel.Value;
                    Display.WaterfallHighThreshold = console.WaterfallHighThreshold17m;
                    break;
                case Band.B15M:
                    console.WaterfallHighThreshold15m = (float)udDisplayWaterfallHighLevel.Value;
                    Display.WaterfallHighThreshold = console.WaterfallHighThreshold15m;
                    break;
                case Band.B12M:
                    console.WaterfallHighThreshold12m = (float)udDisplayWaterfallHighLevel.Value;
                    Display.WaterfallHighThreshold = console.WaterfallHighThreshold12m;
                    break;
                case Band.B10M:
                    console.WaterfallHighThreshold10m = (float)udDisplayWaterfallHighLevel.Value;
                    Display.WaterfallHighThreshold = console.WaterfallHighThreshold10m;
                    break;
                case Band.B6M:
                    console.WaterfallHighThreshold6m = (float)udDisplayWaterfallHighLevel.Value;
                    Display.WaterfallHighThreshold = console.WaterfallHighThreshold6m;
                    break;
                case Band.WWV:
                    console.WaterfallHighThresholdWWV = (float)udDisplayWaterfallHighLevel.Value;
                    Display.WaterfallHighThreshold = console.WaterfallHighThresholdWWV;
                    break;
                case Band.GEN:
                    console.WaterfallHighThresholdGEN = (float)udDisplayWaterfallHighLevel.Value;
                    Display.WaterfallHighThreshold = console.WaterfallHighThresholdGEN;
                    break;
                default:
                    console.WaterfallHighThresholdXVTR = (float)udDisplayWaterfallHighLevel.Value;
                    Display.WaterfallHighThreshold = console.WaterfallHighThresholdXVTR;
                    break;
            }
        }

        private void udDisplayMultiPeakHoldTime_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.MultimeterPeakHoldTime = (int)udDisplayMultiPeakHoldTime.Value;
        }

        private void udDisplayMultiTextHoldTime_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.MultimeterTextPeakTime = (int)udDisplayMultiTextHoldTime.Value;
        }

        // RX2 WaterFall
        private void clrbtnRX2WaterfallLow_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Display.RX2WaterfallLowColor = clrbtnRX2WaterfallLow.Color;
        }

        private void udRX2DisplayWaterfallLowLevel_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            //[2.10.3.6]MW0LGE limit
            if (udRX2DisplayWaterfallLowLevel.Value > udRX2DisplayWaterfallHighLevel.Value - 3)
            {
                udRX2DisplayWaterfallLowLevel.Value = udRX2DisplayWaterfallHighLevel.Value - 3;
                return;
            }
            //
            UpdateWaterfallBandInfo();
            switch (console.RX2Band)
            {
                case Band.B160M:
                    console.RX2WaterfallLowThreshold160m = (float)udRX2DisplayWaterfallLowLevel.Value;
                    Display.RX2WaterfallLowThreshold = console.RX2WaterfallLowThreshold160m;
                    break;
                case Band.B80M:
                    console.RX2WaterfallLowThreshold80m = (float)udRX2DisplayWaterfallLowLevel.Value;
                    Display.RX2WaterfallLowThreshold = console.RX2WaterfallLowThreshold80m;
                    break;
                case Band.B60M:
                    console.RX2WaterfallLowThreshold60m = (float)udRX2DisplayWaterfallLowLevel.Value;
                    Display.RX2WaterfallLowThreshold = console.RX2WaterfallLowThreshold60m;
                    break;
                case Band.B40M:
                    console.RX2WaterfallLowThreshold40m = (float)udRX2DisplayWaterfallLowLevel.Value;
                    Display.RX2WaterfallLowThreshold = console.RX2WaterfallLowThreshold40m;
                    break;
                case Band.B30M:
                    console.RX2WaterfallLowThreshold30m = (float)udRX2DisplayWaterfallLowLevel.Value;
                    Display.RX2WaterfallLowThreshold = console.RX2WaterfallLowThreshold30m;
                    break;
                case Band.B20M:
                    console.RX2WaterfallLowThreshold20m = (float)udRX2DisplayWaterfallLowLevel.Value;
                    Display.RX2WaterfallLowThreshold = console.RX2WaterfallLowThreshold20m;
                    break;
                case Band.B17M:
                    console.RX2WaterfallLowThreshold17m = (float)udRX2DisplayWaterfallLowLevel.Value;
                    Display.RX2WaterfallLowThreshold = console.RX2WaterfallLowThreshold17m;
                    break;
                case Band.B15M:
                    console.RX2WaterfallLowThreshold15m = (float)udRX2DisplayWaterfallLowLevel.Value;
                    Display.RX2WaterfallLowThreshold = console.RX2WaterfallLowThreshold15m;
                    break;
                case Band.B12M:
                    console.RX2WaterfallLowThreshold12m = (float)udRX2DisplayWaterfallLowLevel.Value;
                    Display.RX2WaterfallLowThreshold = console.RX2WaterfallLowThreshold12m;
                    break;
                case Band.B10M:
                    console.RX2WaterfallLowThreshold10m = (float)udRX2DisplayWaterfallLowLevel.Value;
                    Display.RX2WaterfallLowThreshold = console.RX2WaterfallLowThreshold10m;
                    break;
                case Band.B6M:
                    console.RX2WaterfallLowThreshold6m = (float)udRX2DisplayWaterfallLowLevel.Value;
                    Display.RX2WaterfallLowThreshold = console.RX2WaterfallLowThreshold6m;
                    break;
                case Band.WWV:
                    console.RX2WaterfallLowThresholdWWV = (float)udRX2DisplayWaterfallLowLevel.Value;
                    Display.RX2WaterfallLowThreshold = console.RX2WaterfallLowThresholdWWV;
                    break;
                case Band.GEN:
                    console.RX2WaterfallLowThresholdGEN = (float)udRX2DisplayWaterfallLowLevel.Value;
                    Display.RX2WaterfallLowThreshold = console.RX2WaterfallLowThresholdGEN;
                    break;
                default:
                    console.RX2WaterfallLowThresholdXVTR = (float)udRX2DisplayWaterfallLowLevel.Value;
                    Display.RX2WaterfallLowThreshold = console.RX2WaterfallLowThresholdXVTR;
                    break;
            }
        }

        private void udRX2DisplayWaterfallHighLevel_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            //[2.10.3.6]MW0LGE limit
            if (udRX2DisplayWaterfallHighLevel.Value < udRX2DisplayWaterfallLowLevel.Value + 3)
            {
                udRX2DisplayWaterfallHighLevel.Value = udRX2DisplayWaterfallLowLevel.Value + 3;
                return;
            }
            //
            UpdateWaterfallBandInfo();
            switch (console.RX2Band)
            {
                case Band.B160M:
                    console.RX2WaterfallHighThreshold160m = (float)udRX2DisplayWaterfallHighLevel.Value;
                    Display.RX2WaterfallHighThreshold = console.RX2WaterfallHighThreshold160m;
                    break;
                case Band.B80M:
                    console.RX2WaterfallHighThreshold80m = (float)udRX2DisplayWaterfallHighLevel.Value;
                    Display.RX2WaterfallHighThreshold = console.RX2WaterfallHighThreshold80m;
                    break;
                case Band.B60M:
                    console.RX2WaterfallHighThreshold60m = (float)udRX2DisplayWaterfallHighLevel.Value;
                    Display.RX2WaterfallHighThreshold = console.RX2WaterfallHighThreshold60m;
                    break;
                case Band.B40M:
                    console.RX2WaterfallHighThreshold40m = (float)udRX2DisplayWaterfallHighLevel.Value;
                    Display.RX2WaterfallHighThreshold = console.RX2WaterfallHighThreshold40m;
                    break;
                case Band.B30M:
                    console.RX2WaterfallHighThreshold30m = (float)udRX2DisplayWaterfallHighLevel.Value;
                    Display.RX2WaterfallHighThreshold = console.RX2WaterfallHighThreshold30m;
                    break;
                case Band.B20M:
                    console.RX2WaterfallHighThreshold20m = (float)udRX2DisplayWaterfallHighLevel.Value;
                    Display.RX2WaterfallHighThreshold = console.RX2WaterfallHighThreshold20m;
                    break;
                case Band.B17M:
                    console.RX2WaterfallHighThreshold17m = (float)udRX2DisplayWaterfallHighLevel.Value;
                    Display.RX2WaterfallHighThreshold = console.RX2WaterfallHighThreshold17m;
                    break;
                case Band.B15M:
                    console.RX2WaterfallHighThreshold15m = (float)udRX2DisplayWaterfallHighLevel.Value;
                    Display.RX2WaterfallHighThreshold = console.RX2WaterfallHighThreshold15m;
                    break;
                case Band.B12M:
                    console.RX2WaterfallHighThreshold12m = (float)udRX2DisplayWaterfallHighLevel.Value;
                    Display.RX2WaterfallHighThreshold = console.RX2WaterfallHighThreshold12m;
                    break;
                case Band.B10M:
                    console.RX2WaterfallHighThreshold10m = (float)udRX2DisplayWaterfallHighLevel.Value;
                    Display.RX2WaterfallHighThreshold = console.RX2WaterfallHighThreshold10m;
                    break;
                case Band.B6M:
                    console.RX2WaterfallHighThreshold6m = (float)udRX2DisplayWaterfallHighLevel.Value;
                    Display.RX2WaterfallHighThreshold = console.RX2WaterfallHighThreshold6m;
                    break;
                case Band.WWV:
                    console.RX2WaterfallHighThresholdWWV = (float)udRX2DisplayWaterfallHighLevel.Value;
                    Display.RX2WaterfallHighThreshold = console.RX2WaterfallHighThresholdWWV;
                    break;
                case Band.GEN:
                    console.RX2WaterfallHighThresholdGEN = (float)udRX2DisplayWaterfallHighLevel.Value;
                    Display.RX2WaterfallHighThreshold = console.RX2WaterfallHighThresholdGEN;
                    break;
                default:
                    console.RX2WaterfallHighThresholdXVTR = (float)udRX2DisplayWaterfallHighLevel.Value;
                    Display.RX2WaterfallHighThreshold = console.RX2WaterfallHighThresholdXVTR;
                    break;
            }
        }

        private void udDisplayScopeTime_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;

            //[2.10.3.5]MW0LGE changed the above to keep calcs internal to Audio
            Audio.ScopeTime = (int)udDisplayScopeTime.Value;
        }

        public int ScopeTime
        {
            get { return (int)udDisplayScopeTime.Value; }
        }

        private void udDisplayMeterAvg_ValueChanged(object sender, System.EventArgs e)
        {
            double block_time = (double)udDisplayMeterDelay.Value * 0.001;
            int blocksToAvg = (int)((float)udDisplayMeterAvg.Value * 0.001 / block_time);
            blocksToAvg = Math.Max(2, blocksToAvg);
            console.MultiMeterAvgBlocks = blocksToAvg;
        }

        private void udTXGridMax_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            if (udTXGridMax.Value <= udTXGridMin.Value)
                udTXGridMax.Value = udTXGridMin.Value + 10;
            Display.TXSpectrumGridMax = (int)udTXGridMax.Value;
        }

        private void udTXGridMin_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            if (udTXGridMin.Value >= udTXGridMax.Value)
                udTXGridMin.Value = udTXGridMax.Value - 10;
            Display.TXSpectrumGridMin = (int)udTXGridMin.Value;
        }

        private void udTXGridStep_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Display.TXSpectrumGridStep = (int)udTXGridStep.Value;
        }

        private void udTXWFAmpMax_ValueChanged(object sender, EventArgs e)
        {
            if (udTXWFAmpMax.Value <= udTXWFAmpMin.Value)
                udTXWFAmpMax.Value = udTXWFAmpMin.Value + 10;
            Display.TXWFAmpMax = (int)udTXWFAmpMax.Value;
        }

        private void udTXWFAmpMin_ValueChanged(object sender, EventArgs e)
        {
            if (udTXWFAmpMin.Value >= udTXWFAmpMax.Value)
                udTXWFAmpMin.Value = udTXWFAmpMax.Value - 10;
            Display.TXWFAmpMin = (int)udTXWFAmpMin.Value;
        }

        private void comboTXLabelAlign_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            switch (comboTXLabelAlign.Text)
            {
                case "Left":
                    Display.TXDisplayLabelAlign = DisplayLabelAlignment.LEFT;
                    break;
                case "Cntr":
                    Display.TXDisplayLabelAlign = DisplayLabelAlignment.CENTER;
                    break;
                case "Right":
                    Display.TXDisplayLabelAlign = DisplayLabelAlignment.RIGHT;
                    break;
                case "Auto":
                    Display.TXDisplayLabelAlign = DisplayLabelAlignment.AUTO;
                    break;
                case "Off":
                    Display.TXDisplayLabelAlign = DisplayLabelAlignment.OFF;
                    break;
                default:
                    Display.TXDisplayLabelAlign = DisplayLabelAlignment.LEFT;
                    break;
            }
        }

        #endregion

        #region DSP Tab Event Handlers
        // ======================================================
        // DSP Tab Event Handlers
        // ======================================================

        private void udLMSNR_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(0, 0).SetNRVals(
                (int)udLMSNRtaps.Value,
                (int)udLMSNRdelay.Value,
                1e-6 * (double)udLMSNRgain.Value,
                1e-3 * (double)udLMSNRLeak.Value);
            console.radio.GetDSPRX(0, 1).SetNRVals(
                (int)udLMSNRtaps.Value,
                (int)udLMSNRdelay.Value,
                1e-6 * (double)udLMSNRgain.Value,
                1e-3 * (double)udLMSNRLeak.Value);
        }

        private void udLMSNR2_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(1, 0).SetNRVals(
                (int)udLMSNR2taps.Value,
                (int)udLMSNR2delay.Value,
                1e-6 * (double)udLMSNR2gain.Value,
                1e-3 * (double)udLMSNR2Leak.Value);
            console.radio.GetDSPRX(1, 1).SetNRVals(
                (int)udLMSNR2taps.Value,
                (int)udLMSNR2delay.Value,
                1e-6 * (double)udLMSNR2gain.Value,
                1e-3 * (double)udLMSNR2Leak.Value);
        }

        private void udDSPNB_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(0, 0).NBThreshold = 0.165 * (double)(udDSPNB.Value);
            console.radio.GetDSPRX(1, 0).NBThreshold = 0.165 * (double)(udDSPNB.Value);
        }

        private void comboDSPPhoneRXBuf_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            console.DSPBufPhoneRX = int.Parse(comboDSPPhoneRXBuf.Text);
        }

        private void comboDSPPhoneTXBuf_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            console.DSPBufPhoneTX = int.Parse(comboDSPPhoneTXBuf.Text);
        }

        private void comboDSPFMRXBuf_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            console.DSPBufFMRX = int.Parse(comboDSPFMRXBuf.Text);
        }

        private void comboDSPFMTXBuf_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            console.DSPBufFMTX = int.Parse(comboDSPFMTXBuf.Text);
        }

        private void comboDSPCWRXBuf_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            console.DSPBufCWRX = int.Parse(comboDSPCWRXBuf.Text);
        }

        private void comboDSPDigRXBuf_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            console.DSPBufDigRX = int.Parse(comboDSPDigRXBuf.Text);
        }

        private void comboDSPDigTXBuf_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            console.DSPBufDigTX = int.Parse(comboDSPDigTXBuf.Text);
        }

        private void comboDSPPhoneRXFiltSize_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            console.DSPFiltSizePhoneRX = int.Parse(comboDSPPhoneRXFiltSize.Text);
        }

        private void comboDSPPhoneTXFiltSize_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            console.DSPFiltSizePhoneTX = int.Parse(comboDSPPhoneTXFiltSize.Text);
        }

        private void comboDSPFMRXFiltSize_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            console.DSPFiltSizeFMRX = int.Parse(comboDSPFMRXFiltSize.Text);
        }

        private void comboDSPFMTXFiltSize_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            console.DSPFiltSizeFMTX = int.Parse(comboDSPFMTXFiltSize.Text);
        }

        private void comboDSPCWRXFiltSize_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            console.DSPFiltSizeCWRX = int.Parse(comboDSPCWRXFiltSize.Text);
        }

        private void comboDSPDigRXFiltSize_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            console.DSPFiltSizeDigRX = int.Parse(comboDSPDigRXFiltSize.Text);
        }

        private void comboDSPDigTXFiltSize_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            console.DSPFiltSizeDigTX = int.Parse(comboDSPDigTXFiltSize.Text);
        }

        private void comboDSPPhoneRXFiltType_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            console.DSPFiltTypePhoneRX = (DSPFilterType)comboDSPPhoneRXFiltType.SelectedIndex;
        }

        private void comboDSPPhoneTXFiltType_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            console.DSPFiltTypePhoneTX = (DSPFilterType)comboDSPPhoneTXFiltType.SelectedIndex;
        }

        private void comboDSPFMRXFiltType_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            console.DSPFiltTypeFMRX = (DSPFilterType)comboDSPFMRXFiltType.SelectedIndex;
        }

        private void comboDSPFMTXFiltType_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            console.DSPFiltTypeFMTX = (DSPFilterType)comboDSPFMTXFiltType.SelectedIndex;
        }

        private void comboDSPCWRXFiltType_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            console.DSPFiltTypeCWRX = (DSPFilterType)comboDSPCWRXFiltType.SelectedIndex;
        }

        private void comboDSPDigRXFiltType_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            console.DSPFiltTypeDigRX = (DSPFilterType)comboDSPDigRXFiltType.SelectedIndex;
        }

        private void comboDSPDigTXFiltType_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            console.DSPFiltTypeDigTX = (DSPFilterType)comboDSPDigTXFiltType.SelectedIndex;
        }

        #region Image Reject

        private void udLMSANF_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(0, 0).SetANFVals(
                (int)udLMSANFtaps.Value,
                (int)udLMSANFdelay.Value,
                1e-6 * (double)udLMSANFgain.Value,
                1e-3 * (double)udLMSANFLeak.Value);
            console.radio.GetDSPRX(0, 1).SetANFVals(
                (int)udLMSANFtaps.Value,
                (int)udLMSANFdelay.Value,
                1e-6 * (double)udLMSANFgain.Value,
                1e-3 * (double)udLMSANFLeak.Value);
        }

        private void udLMSANF2_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(1, 0).SetANFVals(
                (int)udLMSANF2taps.Value,
                (int)udLMSANF2delay.Value,
                1e-6 * (double)udLMSANF2gain.Value,
                1e-3 * (double)udLMSANF2Leak.Value);
            console.radio.GetDSPRX(1, 1).SetANFVals(
                (int)udLMSANF2taps.Value,
                (int)udLMSANF2delay.Value,
                1e-6 * (double)udLMSANF2gain.Value,
                1e-3 * (double)udLMSANF2Leak.Value);
        }

        private void radANFPreAGC_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            int position;
            if (radANFPreAGC.Checked)
                position = 0;
            else
                position = 1;
            console.radio.GetDSPRX(0, 0).RXANFPosition = position;
            console.radio.GetDSPRX(0, 1).RXANFPosition = position;
            console.radio.GetDSPRX(0, 0).RXANRPosition = position;
            console.radio.GetDSPRX(0, 1).RXANRPosition = position;
            console.radio.GetDSPRX(0, 0).RXANR2Position = position;
            console.radio.GetDSPRX(0, 1).RXANR2Position = position;
        }

        private void radANF2PreAGC_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            int position;
            if (radANF2PreAGC.Checked)
                position = 0;
            else
                position = 1;
            console.radio.GetDSPRX(1, 0).RXANFPosition = position;
            console.radio.GetDSPRX(1, 0).RXANRPosition = position;
            console.radio.GetDSPRX(1, 0).RXANR2Position = position;
        }

        #endregion

        #region Keyer

        private void udDSPCWPitch_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.CWPitch = (int)udDSPCWPitch.Value;
        }

        private void chkCWKeyerIambic_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.CWIambic = chkCWKeyerIambic.Checked;
            if (chkCWKeyerIambic.Checked)
                NetworkIO.SetCWIambic(1);
            else NetworkIO.SetCWIambic(0);
        }

        private void udCWKeyerWeight_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            NetworkIO.SetCWKeyerWeight((int)udCWKeyerWeight.Value);
        }

        private void udCWKeyerSemiBreakInDelay_ValueChanged(object sender, System.EventArgs e)
        {
            console.BreakInDelay = (double)udCWBreakInDelay.Value;
        }

        private void chkDSPKeyerSemiBreakInEnabled_CheckedChanged(object sender, System.EventArgs e)
        {
        }

        private void chkCWBreakInEnabled_CheckStateChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.BreakInEnabledState = chkCWBreakInEnabled.CheckState;

            switch (chkCWBreakInEnabled.CheckState)
            {
                case CheckState.Checked:
                    console.BreakInEnabledState = chkCWBreakInEnabled.CheckState;
                    chkCWBreakInEnabled.Text = "SEMI";
                    console.CurrentBreakInMode = BreakIn.Semi;
                    break;
                case CheckState.Unchecked:
                    console.BreakInEnabledState = chkCWBreakInEnabled.CheckState;
                    chkCWBreakInEnabled.Text = "OFF";
                    console.CurrentBreakInMode = BreakIn.Manual;
                    break;
                case CheckState.Indeterminate:
                    // G8NJJ Saturn has QSK capability in any version.
                    if (((console.CurrentHPSDRHardware == HPSDRHW.Orion || console.CurrentHPSDRHardware == HPSDRHW.OrionMKII) &&
                        (NetworkIO.FWCodeVersion >= 17) && !Alex.trx_ant_different) || (console.CurrentHPSDRHardware == HPSDRHW.Saturn))
                    {
                        console.BreakInEnabledState = chkCWBreakInEnabled.CheckState;
                        chkCWBreakInEnabled.Text = "QSK";
                        console.CurrentBreakInMode = BreakIn.QSK;
                    }
                    else
                    {
                        console.BreakInEnabledState = chkCWBreakInEnabled.CheckState;
                        chkCWBreakInEnabled.Text = "SEMI";
                        console.CurrentBreakInMode = BreakIn.Semi;
                    }
                    break;
            }

            udCWBreakInDelay.Enabled = chkCWBreakInEnabled.Checked;
            udCWKeyerSemiBreakInDelay_ValueChanged(this, EventArgs.Empty);
        }

        private void chkDSPKeyerSidetone_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.CWSidetone = chkDSPKeyerSidetone.Checked;
            if (chkDSPKeyerSidetone.Checked)
                NetworkIO.SetCWSidetone(1);
            else NetworkIO.SetCWSidetone(0);

        }

        private void chkCWKeyerRevPdl_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.ReversePaddles = chkCWKeyerRevPdl.Checked;
        }

        private void comboKeyerConnPrimary_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (!CWInput.SetPrimaryInput(comboKeyerConnPrimary.Text))
            {
                MessageBox.Show("Error using " + comboKeyerConnPrimary.Text + " for Keyer Primary Input.\n" +
                    "The port may already be in use by another application.",
                    "Error using " + comboKeyerConnPrimary.Text,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST); //MW0LGE_[2.9.0.7]
                comboKeyerConnPrimary.Text = CWInput.PrimaryInput;
            }
        }

        private void comboKeyerConnSecondary_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;

            if (comboKeyerConnSecondary.Text == "CAT")
            {
                if (!chkCATEnable.Checked)
                {
                    MessageBox.Show("CAT is not Enabled.  Please enable the CAT interface before selecting this option.",
                        "CAT not enabled",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST); //MW0LGE_[2.9.0.7]
                    comboKeyerConnSecondary.Text = CWInput.SecondaryInput;
                    return;
                }
                else
                {
                    CWInput.SetSecondaryInput("None");
                    if (console.Siolisten != null) console.Siolisten.UseForKeyPTT = true;
                }
            }
            else
            {
                if (console.Siolisten != null) console.Siolisten.UseForKeyPTT = false;

            }

            if (!CWInput.SetSecondaryInput(comboKeyerConnSecondary.Text))
            {
                MessageBox.Show("Error using " + comboKeyerConnSecondary.Text + " for Keyer Secondary Input.\n" +
                    "The port may already be in use by another application.",
                    "Error using " + comboKeyerConnSecondary.Text,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST); //MW0LGE_[2.9.0.7]);

                comboKeyerConnSecondary.Text = CWInput.SecondaryInput;
                return;
            }

            switch (comboKeyerConnSecondary.Text)
            {
                case "None":
                    lblKeyerConnPTTLine.Visible = false;
                    comboKeyerConnPTTLine.Visible = false;
                    lblKeyerConnKeyLine.Visible = false;
                    comboKeyerConnKeyLine.Visible = false;
                    break;
                case "CAT":
                    lblKeyerConnPTTLine.Visible = true;
                    comboKeyerConnPTTLine.Visible = true;
                    lblKeyerConnKeyLine.Visible = true;
                    comboKeyerConnKeyLine.Visible = true;

                    comboKeyerConnPTTLine_SelectedIndexChanged(this, EventArgs.Empty);
                    comboKeyerConnKeyLine_SelectedIndexChanged(this, EventArgs.Empty);
                    break;
                default: // COMx
                    lblKeyerConnPTTLine.Visible = true;
                    comboKeyerConnPTTLine.Visible = true;
                    lblKeyerConnKeyLine.Visible = true;
                    comboKeyerConnKeyLine.Visible = true;

                    comboKeyerConnPTTLine_SelectedIndexChanged(this, EventArgs.Empty);
                    comboKeyerConnKeyLine_SelectedIndexChanged(this, EventArgs.Empty);
                    break;
            }
        }

        private void comboKeyerConnKeyLine_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboKeyerConnKeyLine.SelectedIndex < 0) return;

            if (comboKeyerConnSecondary.Text == "CAT")
            {
                switch ((KeyerLine)comboKeyerConnKeyLine.SelectedIndex)
                {
                    case KeyerLine.None:
                        console.Siolisten.KeyOnDTR = false;
                        console.Siolisten.KeyOnRTS = false;
                        break;
                    case KeyerLine.DTR:
                        console.Siolisten.KeyOnDTR = true;
                        console.Siolisten.KeyOnRTS = false;
                        break;
                    case KeyerLine.RTS:
                        console.Siolisten.KeyOnDTR = false;
                        console.Siolisten.KeyOnRTS = true;
                        break;
                }
            }
            else CWInput.SecondaryKeyLine = (KeyerLine)comboKeyerConnKeyLine.SelectedIndex;
        }

        private void comboKeyerConnPTTLine_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboKeyerConnPTTLine.SelectedIndex < 0) return;

            if (comboKeyerConnSecondary.Text == "CAT")
            {
                switch ((KeyerLine)comboKeyerConnPTTLine.SelectedIndex)
                {
                    case KeyerLine.None:
                        console.Siolisten.PTTOnDTR = false;
                        console.Siolisten.PTTOnRTS = false;
                        break;
                    case KeyerLine.DTR:
                        console.Siolisten.PTTOnDTR = true;
                        console.Siolisten.PTTOnRTS = false;
                        break;
                    case KeyerLine.RTS:
                        console.Siolisten.PTTOnDTR = false;
                        console.Siolisten.PTTOnRTS = true;
                        break;
                }
            }
            else CWInput.SecondaryPTTLine = (KeyerLine)comboKeyerConnPTTLine.SelectedIndex;
        }

        #endregion

        #region AGC

        private void udDSPAGCFixedGaindB_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(0, 0).RXFixedAGC = (double)udDSPAGCFixedGaindB.Value;
            console.radio.GetDSPRX(0, 1).RXFixedAGC = (double)udDSPAGCFixedGaindB.Value;

            if (console.RX1AGCMode == AGCMode.FIXD)
                console.RF = (int)udDSPAGCFixedGaindB.Value;
        }

        private void udDSPAGCMaxGaindB_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(0, 0).RXAGCMaxGain = (double)udDSPAGCMaxGaindB.Value;
            console.radio.GetDSPRX(0, 1).RXAGCMaxGain = (double)udDSPAGCMaxGaindB.Value;

            if (console.RX1AGCMode != AGCMode.FIXD)
                console.RF = (int)udDSPAGCMaxGaindB.Value;
        }

        private void udDSPAGCRX2MaxGaindB_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(1, 0).RXAGCMaxGain = (double)udDSPAGCRX2MaxGaindB.Value;

            if (console.RX2AGCMode != AGCMode.FIXD)
                console.RX2RF = (int)udDSPAGCRX2MaxGaindB.Value;
        }

        private void udDSPAGCRX2FixedGaindB_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(1, 0).RXFixedAGC = (double)udDSPAGCRX2FixedGaindB.Value;

            if (console.RX2AGCMode == AGCMode.FIXD)
                console.RX2RF = (int)udDSPAGCRX2FixedGaindB.Value;
        }

        private void udDSPAGCDecay_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;

            console.radio.GetDSPRX(0, 0).RXAGCDecay = (int)udDSPAGCDecay.Value;
            console.radio.GetDSPRX(0, 1).RXAGCDecay = (int)udDSPAGCDecay.Value;
        }

        private void udDSPAGCRX2Decay_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;

            console.radio.GetDSPRX(1, 0).RXAGCDecay = (int)udDSPAGCRX2Decay.Value;
        }

        private void udDSPAGCSlope_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(0, 0).RXAGCSlope = 10 * (int)(udDSPAGCSlope.Value);
            console.radio.GetDSPRX(0, 1).RXAGCSlope = 10 * (int)(udDSPAGCSlope.Value);
        }

        private void udDSPAGCRX2Slope_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(1, 0).RXAGCSlope = 10 * (int)(udDSPAGCRX2Slope.Value);
        }

        private void udDSPAGCHangTime_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;

            console.radio.GetDSPRX(0, 0).RXAGCHang = (int)udDSPAGCHangTime.Value;
            console.radio.GetDSPRX(0, 1).RXAGCHang = (int)udDSPAGCHangTime.Value;
        }

        private void udDSPAGCRX2HangTime_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(1, 0).RXAGCHang = (int)udDSPAGCRX2HangTime.Value;
        }

        private void tbDSPAGCHangThreshold_Scroll(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(0, 0).RXAGCHangThreshold = (int)tbDSPAGCHangThreshold.Value;
            console.radio.GetDSPRX(0, 1).RXAGCHangThreshold = (int)tbDSPAGCHangThreshold.Value;
        }

        private void tbDSPAGCRX2HangThreshold_Scroll(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(1, 0).RXAGCHangThreshold = (int)tbDSPAGCRX2HangThreshold.Value;
        }

        #endregion

        #region Leveler

        private void udDSPLevelerThreshold_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPTX(0).TXLevelerMaxGain = (double)udDSPLevelerThreshold.Value;
        }

        private void udDSPLevelerDecay_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPTX(0).TXLevelerDecay = (int)udDSPLevelerDecay.Value;
        }

        private bool _oldLevelerState = true; //it is true in frm design
        private void chkDSPLevelerEnabled_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPTX(0).TXLevelerOn = chkDSPLevelerEnabled.Checked;

            console.SetupInfoBarButton(ucInfoBar.ActionTypes.Leveler, chkDSPLevelerEnabled.Checked);

            if (_oldLevelerState != chkDSPLevelerEnabled.Checked)
            {
                console.LevelerChangedHandlers?.Invoke(_oldLevelerState, chkDSPLevelerEnabled.Checked);
                _oldLevelerState = chkDSPLevelerEnabled.Checked;
            }
        }

        #endregion

        #region ALC

        private void udDSPALCMaximumGain_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            WDSP.SetTXAALCMaxGain(WDSP.id(1, 0), (double)udDSPALCMaximumGain.Value);
            WDSP.ALCGain = (double)udDSPALCMaximumGain.Value;
        }

        private void udDSPALCDecay_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPTX(0).TXALCDecay = (int)udDSPALCDecay.Value;
        }

        #endregion

        #endregion

        #region Transmit Tab Event Handlers

        private void udTXFilterHigh_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            if (_timerCheckingTXProfile) return;
            if (udTXFilterHigh.Value < udTXFilterLow.Value + 100)
            {
                udTXFilterHigh.Value = udTXFilterLow.Value + 100;
                return;
            }

            if (udTXFilterHigh.Focused &&
                (udTXFilterHigh.Value - udTXFilterLow.Value) > 3000 &&
                (console.TXFilterHigh - console.TXFilterLow) <= 3000)
            {
                (new Thread(new ThreadStart(TXBW))).Start();
            }

            console.TXFilterHigh = (int)udTXFilterHigh.Value;

        }

        private void TXBW()
        {
            MessageBox.Show("The transmit bandwidth is being increased beyond 3kHz.\n\n" +
                "As the control operator, you are responsible for compliance with current " +
                "rules and good operating practice.",
                "Warning: Transmit Bandwidth",
                MessageBoxButtons.OK,
                MessageBoxIcon.Warning);
        }

        private void udTXFilterLow_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            if (_timerCheckingTXProfile) return;
            if (udTXFilterLow.Value > udTXFilterHigh.Value - 100)
            {
                udTXFilterLow.Value = udTXFilterHigh.Value - 100;
                return;
            }

            if (udTXFilterLow.Focused &&
                (udTXFilterHigh.Value - udTXFilterLow.Value) > 3000 &&
                (console.TXFilterHigh - console.TXFilterLow) <= 3000)
            {
                (new Thread(new ThreadStart(TXBW))).Start();
            }

            console.TXFilterLow = (int)udTXFilterLow.Value;
        }

        private void udTransmitTunePower_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.TunePower = (int)udTXTunePower.Value;
        }

        private bool loadTXProfile(String sProfileName)
        {
            //
            // NOTE: make sure you update checkTXProfileChanged2, if anything is added/removed
            //

            DataRow[] rows = getDataRowsForTXProfile(sProfileName);// DB.ds.Tables["TXProfile"].Select("Name = '" + sProfileName.Replace("'", "''") + "'"); //MW0LGE_21k9rc6 replace ' for ''

            if (rows.Length != 1)
            {
                MessageBox.Show("Database error reading TxProfile Table.",
                    "Database error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return false;
            }

            DataRow dr = rows[0];
            int[] eq = new int[21];
            int[] cfceq = new int[32];

            if (checkTXProfileChanged2(dr, true)) // check if vac settings are different
            {
                // diable the vacs, so we can make changes without them trying to re-init etc MW0LGE_21dk5
                chkAudioEnableVAC.Checked = false;
                chkVAC2Enable.Checked = false;
            }

            console.EQForm.TXEQEnabled = (bool)dr["TXEQEnabled"];
            console.EQForm.NumBands = (int)dr["TXEQNumBands"];

            eq[0] = (int)dr["TXEQPreamp"];
            for (int i = 1; i < 11; i++)
                eq[i] = (int)dr["TXEQ" + i.ToString()];
            for (int i = 11; i < 21; i++)
                eq[i] = (int)dr["TxEqFreq" + (i - 10).ToString()];
            console.EQForm.TXEQ = eq;

            udTXFilterLow.Value = Math.Min(Math.Max((int)dr["FilterLow"], udTXFilterLow.Minimum), udTXFilterLow.Maximum);
            udTXFilterHigh.Value = Math.Min(Math.Max((int)dr["FilterHigh"], udTXFilterHigh.Minimum), udTXFilterHigh.Maximum);

            console.TXFilterLow = (int)udTXFilterLow.Value;
            console.TXFilterHigh = (int)udTXFilterHigh.Value;

            console.DX = (bool)dr["DXOn"];
            //console.DXLevel = (int)dr["DXLevel"]; //MW0LGE_22b

            console.CPDR = (bool)dr["CompanderOn"];
            console.CPDRLevel = (int)dr["CompanderLevel"];

            console.Mic = (int)dr["MicGain"];
            console.FMMic = (int)dr["FMMicGain"];
            console.MicMute = (bool)dr["MicMute"]; //MW0LGE_21f

            chkDSPLevelerEnabled.Checked = (bool)dr["Lev_On"];
            udDSPLevelerSlope.Value = (int)dr["Lev_Slope"];
            udDSPLevelerThreshold.Value = (int)dr["Lev_MaxGain"];
            udDSPLevelerAttack.Value = (int)dr["Lev_Attack"];
            udDSPLevelerDecay.Value = (int)dr["Lev_Decay"];
            udDSPLevelerHangTime.Value = (int)dr["Lev_Hang"];
            tbDSPLevelerHangThreshold.Value = (int)dr["Lev_HangThreshold"];

            udDSPALCSlope.Value = (int)dr["ALC_Slope"];
            udDSPALCMaximumGain.Value = (int)dr["ALC_MaximumGain"];
            udDSPALCAttack.Value = (int)dr["ALC_Attack"];
            udDSPALCDecay.Value = (int)dr["ALC_Decay"];
            udDSPALCHangTime.Value = (int)dr["ALC_Hang"];
            tbDSPALCHangThreshold.Value = (int)dr["ALC_HangThreshold"];

            chkVOXEnable.Checked = (bool)dr["VOX_On"];
            chkDEXPEnable.Checked = (bool)dr["Dexp_On"];
            udDEXPThreshold.Value = (int)dr["Dexp_Threshold"];
            udDEXPAttack.Value = (int)dr["Dexp_Attack"];
            udDEXPHold.Value = (int)dr["VOX_HangTime"];
            udDEXPRelease.Value = (int)dr["Dexp_Release"];
            udDEXPExpansionRatio.Value = (decimal)dr["Dexp_Attenuate"];
            udDEXPHysteresisRatio.Value = (decimal)dr["Dexp_Hysterisis"];
            udDEXPDetTau.Value = (int)dr["Dexp_Tau"];
            chkSCFEnable.Checked = (bool)dr["Dexp_SCF_On"];
            udSCFLowCut.Value = (int)dr["Dexp_SCF_Low"];
            udSCFHighCut.Value = (int)dr["Dexp_SCF_High"];
            chkDEXPLookAheadEnable.Checked = (bool)dr["Dexp_LookAhead_On"];
            udDEXPLookAhead.Value = (int)dr["Dexp_LookAhead"];

            console.TXAF = (int)dr["TX_AF_Level"];

            udTXAMCarrierLevel.Value = (int)dr["AM_Carrier_Level"];

            console.ShowTXFilter = (bool)dr["Show_TX_Filter"];

            udAudioVACGainRX.Value = (int)dr["VAC1_RX_GAIN"];
            udAudioVACGainTX.Value = (int)dr["VAC1_TX_GAIN"];
            chkAudio2Stereo.Checked = (bool)dr["VAC1_Stereo_On"];
            comboAudioSampleRate2.Text = (string)dr["VAC1_Sample_Rate"];
            comboAudioBuffer2.Text = (string)dr["VAC1_Buffer_Size"];
            chkAudioIQtoVAC.Checked = (bool)dr["VAC1_IQ_Output"];
            chkAudioCorrectIQ.Checked = (bool)dr["VAC1_IQ_Correct"];
            chkVACAllowBypass.Checked = (bool)dr["VAC1_PTT_OverRide"];
            chkVACCombine.Checked = (bool)dr["VAC1_Combine_Input_Channels"];
            chkAudioLatencyManual2.Checked = (bool)dr["VAC1_Latency_On"];
            udAudioLatency2.Value = (int)dr["VAC1_Latency_Duration"];

            chkAudioLatencyManual2_Out.Checked = (bool)dr["VAC1_Latency_RBOut_On"];
            udAudioLatency2_Out.Value = (int)dr["VAC1_Latency_RBOut_Duration"];
            chkAudioLatencyPAInManual.Checked = (bool)dr["VAC1_Latency_PAIn_On"];
            udAudioLatencyPAIn.Value = (int)dr["VAC1_Latency_PAIn_Duration"];
            chkAudioLatencyPAOutManual.Checked = (bool)dr["VAC1_Latency_PAOut_On"];
            udAudioLatencyPAOut.Value = (int)dr["VAC1_Latency_PAOut_Duration"];

            if (chkRestoreVAC1DeviceDetailsFromTXProfile.Checked)
            {
                comboAudioDriver2.Text = DB.ConvertFromDBVal<string>(dr["VAC1_AudioDriver"]);
                comboAudioInput2.Text = DB.ConvertFromDBVal<string>(dr["VAC1_AudioInput"]);
                comboAudioOutput2.Text = DB.ConvertFromDBVal<string>(dr["VAC1_AudioOutput"]);

                chkVAC1ExclusiveIn.Checked = (bool)dr["VAC1_Exclusive_In"];
                chkVAC1ExclusiveOut.Checked = (bool)dr["VAC1_Exclusive_Out"];
            }

            udVAC2GainRX.Value = (int)dr["VAC2_RX_GAIN"];
            udVAC2GainTX.Value = (int)dr["VAC2_TX_GAIN"];
            chkAudioStereo3.Checked = (bool)dr["VAC2_Stereo_On"];
            comboAudioSampleRate3.Text = (string)dr["VAC2_Sample_Rate"];
            comboAudioBuffer3.Text = (string)dr["VAC2_Buffer_Size"];
            chkVAC2DirectIQ.Checked = (bool)dr["VAC2_IQ_Output"];
            chkVAC2DirectIQCal.Checked = (bool)dr["VAC2_IQ_Correct"];
            chkVAC2Combine.Checked = (bool)dr["VAC2_Combine_Input_Channels"];
            chkVAC2LatencyManual.Checked = (bool)dr["VAC2_Latency_On"];
            udVAC2Latency.Value = (int)dr["VAC2_Latency_Duration"];

            chkVAC2LatencyOutManual.Checked = (bool)dr["VAC2_Latency_RBOut_On"];
            udVAC2LatencyOut.Value = (int)dr["VAC2_Latency_RBOut_Duration"];
            chkVAC2LatencyPAInManual.Checked = (bool)dr["VAC2_Latency_PAIn_On"];
            udVAC2LatencyPAIn.Value = (int)dr["VAC2_Latency_PAIn_Duration"];
            chkVAC2LatencyPAOutManual.Checked = (bool)dr["VAC2_Latency_PAOut_On"];
            udVAC2LatencyPAOut.Value = (int)dr["VAC2_Latency_PAOut_Duration"];

            if (chkRestoreVAC2DeviceDetailsFromTXProfile.Checked)
            {
                comboAudioDriver3.Text = DB.ConvertFromDBVal<string>(dr["VAC2_AudioDriver"]);
                comboAudioInput3.Text = DB.ConvertFromDBVal<string>(dr["VAC2_AudioInput"]);
                comboAudioOutput3.Text = DB.ConvertFromDBVal<string>(dr["VAC2_AudioOutput"]);

                chkVAC2ExclusiveIn.Checked = (bool)dr["VAC2_Exclusive_In"];
                chkVAC2ExclusiveOut.Checked = (bool)dr["VAC2_Exclusive_Out"];
            }

            console.DeferUpdateDSP = true; //MW0LGE_21k9d
            comboDSPPhoneRXBuf.Text = (string)dr["Phone_RX_DSP_Buffer"];
            comboDSPPhoneTXBuf.Text = (string)dr["Phone_TX_DSP_Buffer"];
            comboDSPFMRXBuf.Text = (string)dr["FM_RX_DSP_Buffer"];
            comboDSPFMTXBuf.Text = (string)dr["FM_TX_DSP_Buffer"];
            comboDSPDigRXBuf.Text = (string)dr["Digi_RX_DSP_Buffer"];
            comboDSPDigTXBuf.Text = (string)dr["Digi_TX_DSP_Buffer"];
            comboDSPCWRXBuf.Text = (string)dr["CW_RX_DSP_Buffer"];

            comboDSPPhoneRXFiltSize.Text = (string)dr["Phone_RX_DSP_Filter_Size"];
            comboDSPPhoneTXFiltSize.Text = (string)dr["Phone_TX_DSP_Filter_Size"];
            comboDSPFMRXFiltSize.Text = (string)dr["FM_RX_DSP_Filter_Size"];
            comboDSPFMTXFiltSize.Text = (string)dr["FM_TX_DSP_Filter_Size"];
            comboDSPDigRXFiltSize.Text = (string)dr["Digi_RX_DSP_Filter_Size"];
            comboDSPDigTXFiltSize.Text = (string)dr["Digi_TX_DSP_Filter_Size"];
            comboDSPCWRXFiltSize.Text = (string)dr["CW_RX_DSP_Filter_Size"];

            comboDSPPhoneRXFiltType.Text = (string)dr["Phone_RX_DSP_Filter_Type"];
            comboDSPPhoneTXFiltType.Text = (string)dr["Phone_TX_DSP_Filter_Type"];
            comboDSPFMRXFiltType.Text = (string)dr["FM_RX_DSP_Filter_Type"];
            comboDSPFMTXFiltType.Text = (string)dr["FM_TX_DSP_Filter_Type"];
            comboDSPDigRXFiltType.Text = (string)dr["Digi_RX_DSP_Filter_Type"];
            comboDSPDigTXFiltType.Text = (string)dr["Digi_TX_DSP_Filter_Type"];
            comboDSPCWRXFiltType.Text = (string)dr["CW_RX_DSP_Filter_Type"];
            if (!initializing) console.DeferUpdateDSP = false;  //MW0LGE_21k9d  we dont want to undo this if we are initalising

            radMicIn.Checked = (bool)dr["Mic_Input_On"];
            chk20dbMicBoost.Checked = (bool)dr["Mic_Input_Boost"];
            radLineIn.Checked = (bool)dr["Line_Input_On"];
            udLineInBoost.Value = (decimal)dr["Line_Input_Level"];
            chkDSPCESSB.Checked = (bool)dr["CESSB_On"];
            console.PureSignalEnabled = (bool)dr["Pure_Signal_Enabled"];

            //
            udFMLowCutRX.Value = (decimal)dr["FM_RX_AFFilter_Low"];
            udFMHighCutRX.Value = (decimal)dr["FM_RX_AFFilter_High"];
            udFMLowCutTX.Value = (decimal)dr["FM_TX_AFFilter_Low"];
            udFMHighCutTX.Value = (decimal)dr["FM_TX_AFFilter_High"];
            chkVAC1_Force2.Checked = (bool)dr["VAC1_Force_In"];  // note in is force2, and out is force
            chkVAC1_Force.Checked = (bool)dr["VAC1_Force_Out"];
            chkVAC2_Force2.Checked = (bool)dr["VAC2_Force_In"];
            chkVAC2_Force.Checked = (bool)dr["VAC2_Force_Out"];
            chkSwapIQVac1.Checked = (bool)dr["VAC1_SwapIQ"];
            chkSwapIQVac2.Checked = (bool)dr["VAC2_SwapIQ"];
            chkDisableRearSpeakerJacksAudioAmplifier.Checked = (bool)dr["Audio_Disable_Audio_Amp"];
            if (chkRecoverPAProfileFromTXProfile.Checked)
            {
                string paProf = (string)dr["PA_Profile"];
                if (comboPAProfile.Items.Contains(paProf))
                    comboPAProfile.Text = paProf;
            }
            console.EQForm.RXEQEnabled = (bool)dr["RXEQEnabled"];
            //[2.10.3.2]MW0LGE console.EQForm.NumBands is set above, so just use RXeq to get the array, then adjust it
            int[] rxeq = console.EQForm.RXEQ;
            rxeq[0] = (int)dr["RXEQPreamp"];
            for (int i = 1; i < rxeq.Length; i++)
                rxeq[i] = (int)dr["RXEQ" + i.ToString()];
            console.EQForm.RXEQ = rxeq;
            //

            //CFC
            chkCFCEnable.Checked = (bool)dr["CFCEnabled"];
            chkCFCPeqEnable.Checked = (bool)dr["CFCPostEqEnabled"];
            chkPHROTEnable.Checked = (bool)dr["CFCPhaseRotatorEnabled"];
            chkPHROTReverse.Checked = (bool)dr["CFCPhaseReverseEnabled"];

            udPhRotFreq.Value = Math.Min(Math.Max((int)dr["CFCPhaseRotatorFreq"], udPhRotFreq.Minimum), udPhRotFreq.Maximum);
            udPHROTStages.Value = Math.Min(Math.Max((int)dr["CFCPhaseRotatorStages"], udPHROTStages.Minimum), udPHROTStages.Maximum);

            cfceq[0] = (int)dr["CFCPreComp"];
            for (int i = 1; i < 11; i++)
                cfceq[i] = (int)dr["CFCPreComp" + (i - 1).ToString()];

            cfceq[11] = (int)dr["CFCPostEqGain"];
            for (int i = 12; i < 22; i++)
                cfceq[i] = (int)dr["CFCPostEqGain" + (i - 12).ToString()];
            for (int i = 22; i < 32; i++)
                cfceq[i] = (int)dr["CFCEqFreq" + (i - 22).ToString()];

            CFCCOMPEQ = cfceq;

            chkAudioEnableVAC.Checked = (bool)dr["VAC1_On"];    // moved here after setting to off MW0LGE_21k9d
            chkAudioVACAutoEnable.Checked = (bool)dr["VAC1_Auto_On"]; //[2.10.1.0] MW0LGE moved here
            chkVAC2Enable.Checked = (bool)dr["VAC2_On"];    // moved here after setting to off MW0LGE_21k9d
            chkVAC2AutoEnable.Checked = (bool)dr["VAC2_Auto_On"]; //[2.10.1.0] MW0LGE moved here

            console.TXProfile = sProfileName;
            console.LoadedTXProfile();

            return true;
        }

        public int TCIClientsConnectedChange
        {
            set { grpTCIServer.Text = "TCI Server (" + value.ToString() + " clients)"; }
        }
        public int TCPIPcatClientsConnectedChange
        {
            set { grpTCPIPcatServer.Text = "TCP / IP CAT Server (" + value.ToString() + " clients)"; }
        }
        public void ForceTXProfileUpdate()
        {
            comboTXProfileName_SelectedIndexChanged(this, EventArgs.Empty);
        }

        private string current_profile = "";
        private void comboTXProfileName_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboTXProfileName.SelectedIndex < 0 || initializing)
                return;

            if (chkAutoSaveTXProfile.Checked)
            {
                SaveTXProfileData();
            }
            else
            {
                if (comboTXProfileName.Focused && checkTXProfileChanged2()) //MW0LGE_21k8 swap the order so focus is needed before check profile is called
                {
                    DialogResult result = MessageBox.Show("The current profile has changed.  " +
                        "Would you like to save the current profile?",
                        "Save Current Profile?",
                        MessageBoxButtons.YesNoCancel,
                        MessageBoxIcon.Question);

                    if (result == DialogResult.Yes)
                    {
                        btnTXProfileSave_Click(this, EventArgs.Empty);
                        //return;
                    }
                    else if (result == DialogResult.Cancel)
                        return;
                }
            }

            if (loadTXProfile(comboTXProfileName.Text)) current_profile = comboTXProfileName.Text;
            else current_profile = "";
        }

        private void btnTXProfileSave_Click(object sender, System.EventArgs e)
        {
            string name = InputBox.Show("Save Profile", "Please enter a profile name:",
                current_profile);

            if (string.IsNullOrEmpty(name))
            {
                MessageBox.Show("TX Profile Save cancelled",
                    "TX Profile",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
                return;
            }

            DataRow dr = null;
            if (comboTXProfileName.Items.Contains(name))
            {
                DialogResult result = MessageBox.Show(
                    "Are you sure you want to overwrite the " + name + " TX Profile?",
                    "Overwrite Profile?",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question);

                if (result == DialogResult.No)
                    return;

                foreach (DataRow dd in from DataRow d in DB.ds.Tables["TXProfile"].Rows where (string)d["Name"] == name select d)
                {
                    dr = dd;
                    break;
                }
            }
            else
            {
                dr = DB.ds.Tables["TXProfile"].NewRow();
                dr["Name"] = name;
            }

            if (dr == null)
            {
                DialogResult dres = MessageBox.Show(
                    "Unable to find txprofile in the database for name [" + name + "] in btnTXProfileSave_Click()",
                    "Missing TX Profile Table",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST);
            }
            else
            {
                updateTXProfileInDB(dr); //MW0LGE_21a remove duplication
            }

            if (!comboTXProfileName.Items.Contains(name))
            {
                DB.ds.Tables["TXProfile"].Rows.Add(dr);
                comboTXProfileName.Items.Add(name);
                comboTXProfileName.Text = name;
            }

            console.UpdateTXProfile(name);
        }

        private bool profile_deleted = false;
        private void btnTXProfileDelete_Click(object sender, System.EventArgs e)
        {
            DialogResult dr = MessageBox.Show(
                "Are you sure you want to delete the " + comboTXProfileName.Text + " TX Profile?",
                "Delete Profile?",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Warning);

            if (dr == DialogResult.No)
                return;

            profile_deleted = true;

            DataRow[] rows = getDataRowsForTXProfile(comboTXProfileName.Text);// DB.ds.Tables["TXProfile"].Select("Name = '" + comboTXProfileName.Text.Replace("'", "''") + "'"); //MW0LGE_21k9rc6 replace ' for ''

            if (rows.Length == 1)
                rows[0].Delete();

            int index = comboTXProfileName.SelectedIndex;
            comboTXProfileName.Items.Remove(comboTXProfileName.Text);
            if (comboTXProfileName.Items.Count > 0)
            {
                if (index > comboTXProfileName.Items.Count - 1)
                    index = comboTXProfileName.Items.Count - 1;
                comboTXProfileName.SelectedIndex = index;
            }

            console.UpdateTXProfile(comboTXProfileName.Text);
        }

        private void udVOXGain_ValueChanged(object sender, System.EventArgs e)
        {
        }

        private void udTXAF_ValueChanged(object sender, System.EventArgs e)
        {
            console.TXAF = (int)udTXAF.Value;
        }

        private void udTXAMCarrierLevel_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPTX(0).TXAMCarrierLevel = Math.Sqrt(0.01 * (double)udTXAMCarrierLevel.Value) * 0.5;
        }

        private void chkSaveTXProfileOnExit_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.SaveTXProfileOnExit = chkSaveTXProfileOnExit.Checked;
        }

        private void udMicGainMin_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.MicGainMin = (int)udMicGainMin.Value;
        }

        private void udMicGainMax_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.MicGainMax = (int)udMicGainMax.Value;
        }

        private void udLineInBoost_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.LineInBoost = (double)udLineInBoost.Value;
        }

        private void chkShowBandControls_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.ShowBandControls = chkShowBandControls.Checked;
            // G8NJJ: all logic moved to the console properties code
        }

        private void chkModeControls_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.ShowModeControls = chkShowModeControls.Checked;
            // G8NJJ: all logic moved to the console properties code
        }

        //
        // G8NJJ: setup control to select an Andromeda top bar when display is collapsed
        //
        private void chkShowAndromedaTop_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.ShowAndromedaTopControls = chkShowAndromedaTop.Checked;
            // G8NJJ: all logic moved to the console properties code
        }

        //
        // G8NJJ: setup control to select an Andromeda top bar when display is collapsed
        //
        private void chkShowAndromedaBar_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.ShowAndromedaButtonBar = chkShowAndromedaBar.Checked;
            // G8NJJ: all logic moved to the console properties code
        }


        #endregion

        #region PA Settings Tab Event Handlers

        private void btnPAGainCalibration_Click(object sender, System.EventArgs e)
        {
            string s = "NOTE: this routine works well with Penelope. At present this calibration\n" +
                       "routine is NOT recommended if you are using PennyLane, Hermes or \n" +
                       "Angelia as it produces a large overshoot during the calibraion \n" +
                       "process when used with those boards! \n\n" +
                "Is a 50 Ohm dummy load connected to the amplifier?\n" +
                "\n This function is valid only with an external amplifier and Alex (or equivalent) present." +
                "\n\nFailure to use a dummy load with this routine could cause damage to the amplifier.\n\n";

            s += "Is a 50 Ohm dummy load connected to the correct antenna port (";
            switch (FWCAnt.ANT1)
            {
                case FWCAnt.ANT1: s += "ANT 1"; break;
                    /*case FWCAnt.ANT2: s += "ANT 2"; break;
                    case FWCAnt.ANT3: s += "ANT 3"; break;*/
            }
            s += ")?\nFailure to connect a dummy load properly could cause damage to the radio.";

            DialogResult dr = MessageBox.Show(s,
                "Warning: Is dummy load properly connected?",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Warning);

            if (dr == DialogResult.No)
                return;

            btnPAGainCalibration.Enabled = false;
            progress = new Progress("Calibrate PA Gain");

            Thread t = new Thread(CalibratePAGain)
            {
                Name = "PA Gain Calibration Thread",
                IsBackground = true,
                Priority = ThreadPriority.AboveNormal
            };
            t.Start();

            if (console.PowerOn)
                progress.Show();
        }

        private void CalibratePAGain()
        {
            bool[] run = new bool[11];

            if (radPACalAllBands.Checked)
            {
                for (int i = 0; i < 11; i++) run[i] = true;
            }
            else
            {
                run[0] = chkPA160.Checked;
                run[1] = chkPA80.Checked;
                run[2] = chkPA60.Checked;
                run[3] = chkPA40.Checked;
                run[4] = chkPA30.Checked;
                run[5] = chkPA20.Checked;
                run[6] = chkPA17.Checked;
                run[7] = chkPA15.Checked;
                run[8] = chkPA12.Checked;
                run[9] = chkPA10.Checked;
                run[10] = chkPA6.Checked;
            }
            bool done = false;
            done = chkPANewCal.Checked ? console.CalibratePAGain2(progress, run, false) : console.CalibratePAGain(progress, run, (int)udPACalPower.Value);
            if (done) MessageBox.Show("PA Gain Calibration complete.");
            btnPAGainCalibration.Enabled = true;
        }
        #endregion

        #region Appearance Tab Event Handlers

        private void clrbtnBackground_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Display.DisplayBackgroundColor = Color.FromArgb(tbBackgroundAlpha.Value, clrbtnBackground.Color);
        }

        private void clrbtnTXBackground_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Display.TXDisplayBackgroundColor = Color.FromArgb(tbTXBackgroundAlpha.Value, clrbtnTXBackground.Color);
        }

        private void clrbtnGrid_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Display.GridColor = Color.FromArgb(tbGridCourseAlpha.Value, clrbtnGrid.Color);
        }

        private void clrbtnTXVGrid_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Display.TXVGridColor = Color.FromArgb(tbTXVGridCourseAlpha.Value, clrbtnTXVGrid.Color);
        }

        private void clrbtnZeroLine_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Display.GridZeroColor = clrbtnZeroLine.Color;
        }

        private void clrbtnTXZeroLine_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Display.TXGridZeroColor = Color.FromArgb(tbTXZeroLineAlpha.Value, clrbtnTXZeroLine.Color);
        }

        private void clrbtnText_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Display.GridTextColor = clrbtnText.Color;
        }

        private void clrbtnTXText_Changed(object sender, System.EventArgs e)
        {
            Display.GridTXTextColor = Color.FromArgb(tbTXTextAlpha.Value, clrbtnTXText.Color);
        }

        private void clrbtnDataLine_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Display.DataLineColor = Color.FromArgb(tbDataLineAlpha.Value, clrbtnDataLine.Color); // MW0LGE_21b
            rebuildLGBrushes();
        }

        private void rebuildLGBrushes()
        {
            //lg brushes use the line alpha and lgPickerRX1_Changed
            //may have independant LGs at some point
            Display.RebuildLinearGradientBrushRX1 = true;
            Display.RebuildLinearGradientBrushRX2 = true;
        }
        private void clrbtnTXDataLine_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Display.TXDataLineColor = clrbtnTXDataLine.Color;
        }

        private void clrbtnFilter_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Display.DisplayFilterColor = Color.FromArgb(tbRX1FilterAlpha.Value, clrbtnFilter.Color);
        }

        private void clrbtnGridTXFilter_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Display.TXFilterColor = Color.FromArgb(tbTXFilterAlpha.Value, clrbtnGridTXFilter.Color);
        }

        private void udDisplayLineWidth_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Display.DisplayLineWidth = (float)udDisplayLineWidth.Value;
        }

        private void udTXLineWidth_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Display.TXDisplayLineWidth = (float)udTXLineWidth.Value;
        }

        private void clrbtnMeterLeft_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.MeterLeftColor = clrbtnMeterLeft.Color;
        }

        private void clrbtnMeterRight_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.MeterRightColor = clrbtnMeterRight.Color;
        }

        private void clrbtnBtnSel_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.ButtonSelectedColor = clrbtnBtnSel.Color;
        }

        private void clrbtnVFODark_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.VFOTextDarkColor = clrbtnVFODark.Color;
        }

        private void clrbtnVFOLight_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.VFOTextLightColor = clrbtnVFOLight.Color;
        }

        private void clrbtnBandDark_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.BandTextDarkColor = clrbtnBandDark.Color;
        }

        private void clrbtnBandLight_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.BandTextLightColor = clrbtnBandLight.Color;
        }

        private void clrbtnPeakText_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.PeakTextColor = clrbtnPeakText.Color;
        }

        private void clrbtnOutOfBand_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.OutOfBandColor = clrbtnOutOfBand.Color;
        }

        private void chkVFOSmallLSD_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.SmallLSD = chkVFOSmallLSD.Checked;
        }

        private void clrbtnVFOSmallColor_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.SmallVFOColor = clrbtnVFOSmallColor.Color;
        }

        private void clrbtnInfoButtonsColor_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.InfoButtonsColor = clrbtnInfoButtonsColor.Color;
        }

        private void clrbtnPeakBackground_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.PeakBackgroundColor = clrbtnPeakBackground.Color;
        }

        private void clrbtnMeterBackground_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.MeterBackgroundColor = clrbtnMeterBackground.Color;
        }

        private void clrbtnBandBackground_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.BandBackgroundColor = clrbtnBandBackground.Color;
        }

        private void clrbtnVFOBackground_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.VFOBackgroundColor = clrbtnVFOBackground.Color;
        }

        #endregion

        #region Keyboard Tab Event Handlers

        private void comboKBTuneUp1_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.KeyTuneUp1 = (Keys)KeyList[comboKBTuneUp1.SelectedIndex];
        }

        private void comboKBTuneDown1_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.KeyTuneDown1 = (Keys)KeyList[comboKBTuneDown1.SelectedIndex];
        }

        private void comboKBTuneUp2_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.KeyTuneUp2 = (Keys)KeyList[comboKBTuneUp2.SelectedIndex];
        }

        private void comboKBTuneDown2_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.KeyTuneDown2 = (Keys)KeyList[comboKBTuneDown2.SelectedIndex];
        }

        private void comboKBTuneUp3_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.KeyTuneUp3 = (Keys)KeyList[comboKBTuneUp3.SelectedIndex];
        }

        private void comboKBTuneDown3_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.KeyTuneDown3 = (Keys)KeyList[comboKBTuneDown3.SelectedIndex];
        }

        private void comboKBTuneUp4_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.KeyTuneUp4 = (Keys)KeyList[comboKBTuneUp4.SelectedIndex];
        }

        private void comboKBTuneDown4_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.KeyTuneDown4 = (Keys)KeyList[comboKBTuneDown4.SelectedIndex];
        }

        private void comboKBTuneUp5_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.KeyTuneUp5 = (Keys)KeyList[comboKBTuneUp5.SelectedIndex];
        }

        private void comboKBTuneDown5_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.KeyTuneDown5 = (Keys)KeyList[comboKBTuneDown5.SelectedIndex];
        }

        private void comboKBTuneUp6_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.KeyTuneUp6 = (Keys)KeyList[comboKBTuneUp6.SelectedIndex];
        }

        private void comboKBTuneDown6_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.KeyTuneDown6 = (Keys)KeyList[comboKBTuneDown6.SelectedIndex];
        }

        private void comboKBTuneUp7_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            console.KeyTuneUp7 = (Keys)KeyList[comboKBTuneUp7.SelectedIndex];
        }

        private void comboKBTuneDown7_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            console.KeyTuneDown7 = (Keys)KeyList[comboKBTuneDown7.SelectedIndex];
        }

        private void comboKBBandUp_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.KeyBandUp = (Keys)KeyList[comboKBBandUp.SelectedIndex];
        }

        private void comboKBBandDown_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.KeyBandDown = (Keys)KeyList[comboKBBandDown.SelectedIndex];
        }

        private void comboKBFilterUp_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.KeyFilterUp = (Keys)KeyList[comboKBFilterUp.SelectedIndex];
        }

        private void comboKBFilterDown_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.KeyFilterDown = (Keys)KeyList[comboKBFilterDown.SelectedIndex];
        }

        private void comboKBModeUp_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.KeyModeUp = (Keys)KeyList[comboKBModeUp.SelectedIndex];
        }

        private void comboKBModeDown_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.KeyModeDown = (Keys)KeyList[comboKBModeDown.SelectedIndex];
        }

        private void comboKBCWDot_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.KeyCWDot = (Keys)KeyList[comboKBCWDot.SelectedIndex];
        }

        private void comboKBCWDash_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.KeyCWDash = (Keys)KeyList[comboKBCWDash.SelectedIndex];
        }

        private void comboKBRITUp_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            console.KeyRITUp = (Keys)KeyList[comboKBRITUp.SelectedIndex];
        }

        private void comboKBRITDown_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            console.KeyRITDown = (Keys)KeyList[comboKBRITDown.SelectedIndex];
        }

        private void comboKBXITUp_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            console.KeyXITUp = (Keys)KeyList[comboKBXITUp.SelectedIndex];
        }

        private void comboKBXITDown_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            console.KeyXITDown = (Keys)KeyList[comboKBXITDown.SelectedIndex];
        }

        private void comboKBPTTTx_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.KeyPTTTx = (Keys)KeyList[comboKBPTTTx.SelectedIndex];
        }

        private void comboKBPTTRx_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.KeyPTTRx = (Keys)KeyList[comboKBPTTRx.SelectedIndex];
        }

        #endregion

        #region CAT Setup event handlers

        public void initCATandPTTprops()
        {
            //-W2PA MIDI wheel as VFO sensitivity adjustments
            console.MaxMIDIMessagesPerTuneStep = Convert.ToInt32(udUpdatesPerStepMax.Value);
            console.MinMIDIMessagesPerTuneStep = Convert.ToInt32(udUpdatesPerStepMin.Value);

            if (comboCATPort.Text.StartsWith("COM"))
                console.CATPort = Int32.Parse(comboCATPort.Text.Substring(3));
            console.CATPTTRTS = chkCATPTT_RTS.Checked;
            console.CATPTTDTR = chkCATPTT_DTR.Checked;

            if (comboCATPTTPort.Text.StartsWith("COM"))
                console.CATPTTBitBangPort = Int32.Parse(comboCATPTTPort.Text.Substring(3));
            console.CATParity = SDRSerialPort.StringToParity((string)comboCATparity.SelectedItem);
            console.CATDataBits = int.Parse((string)comboCATdatabits.SelectedItem);
            console.CATStopBits = SDRSerialPort.StringToStopBits((string)comboCATstopbits.SelectedItem);
            console.CATEnabled = chkCATEnable.Checked;

            // make sure the enabled state of bitbang ptt is correct 
            if (chkCATPTT_RTS.Checked || chkCATPTT_DTR.Checked)
            {
                chkCATPTTEnabled.Enabled = true;
            }
            else
            {
                chkCATPTTEnabled.Enabled = false;
                chkCATPTTEnabled.Checked = false;
            }

            if (comboCAT2Port.Text.StartsWith("COM"))
                console.CAT2Port = Int32.Parse(comboCAT2Port.Text.Substring(3));
            console.CAT2Parity = SDRSerialPort.StringToParity((string)comboCAT2parity.SelectedItem);
            console.CAT2DataBits = int.Parse((string)comboCAT2databits.SelectedItem);
            console.CAT2StopBits = SDRSerialPort.StringToStopBits((string)comboCAT2stopbits.SelectedItem);
            console.CAT2Enabled = chkCAT2Enable.Checked;

            if (comboCAT3Port.Text.StartsWith("COM"))
                console.CAT3Port = Int32.Parse(comboCAT3Port.Text.Substring(3));
            console.CAT3Parity = SDRSerialPort.StringToParity((string)comboCAT3parity.SelectedItem);
            console.CAT3DataBits = int.Parse((string)comboCAT3databits.SelectedItem);
            console.CAT3StopBits = SDRSerialPort.StringToStopBits((string)comboCAT3stopbits.SelectedItem);
            console.CAT3Enabled = chkCAT3Enable.Checked;

            if (comboCAT4Port.Text.StartsWith("COM"))
                console.CAT4Port = Int32.Parse(comboCAT4Port.Text.Substring(3));
            console.CAT4Parity = SDRSerialPort.StringToParity((string)comboCAT4parity.SelectedItem);
            console.CAT4DataBits = int.Parse((string)comboCAT4databits.SelectedItem);
            console.CAT4StopBits = SDRSerialPort.StringToStopBits((string)comboCAT4stopbits.SelectedItem);
            console.CAT4Enabled = chkCAT4Enable.Checked;

            if (comboAndromedaCATPort.Text.StartsWith("COM"))
                console.AndromedaCATPort = Int32.Parse(comboAndromedaCATPort.Text.Substring(3));
            console.AndromedaCATEnabled = chkEnableAndromeda.Checked;

            if (comboAriesCATPort.Text.StartsWith("COM"))
                console.AriesCATPort = Int32.Parse(comboAriesCATPort.Text.Substring(3));
            console.AriesCATEnabled = chkEnableAries.Checked;

            if (comboGanymedeCATPort.Text.StartsWith("COM"))
                console.GanymedeCATPort = Int32.Parse(comboGanymedeCATPort.Text.Substring(3));
            console.GanymedeCATEnabled = chkEnableGanymede.Checked;

        }

        // called in error cases to set the dialiog vars from 
        // the console properties -- sort of ugly, we should only have 1 copy 
        // of this stuff 
        public void copyCATPropsToDialogVars()
        {
            chkCATEnable.Checked = console.CATEnabled;
            string port = "COM" + console.CATPort.ToString();
            if (comboCATPort.Items.Contains(port))
                comboCATPort.Text = port;
            chkCATPTT_RTS.Checked = console.CATPTTRTS;
            chkCATPTT_DTR.Checked = console.CATPTTDTR;
            chkCATPTTEnabled.Checked = console.PTTBitBangEnabled;
            port = "COM" + console.CATPTTBitBangPort.ToString();
            if (comboCATPTTPort.Items.Contains(port))
                comboCATPTTPort.Text = port;

        }


        public void copyCAT2PropsToDialogVars()
        {
            chkCAT2Enable.Checked = console.CAT2Enabled;
            string port = "COM" + console.CAT2Port.ToString();
            if (comboCAT2Port.Items.Contains(port))
                comboCAT2Port.Text = port;
        }

        public void copyCAT3PropsToDialogVars()
        {
            chkCAT3Enable.Checked = console.CAT3Enabled;
            string port = "COM" + console.CAT3Port.ToString();
            if (comboCAT3Port.Items.Contains(port))
                comboCAT3Port.Text = port;
        }

        public void copyCAT4PropsToDialogVars()
        {
            chkCAT4Enable.Checked = console.CAT4Enabled;
            string port = "COM" + console.CAT4Port.ToString();
            if (comboCAT4Port.Items.Contains(port))
                comboCAT4Port.Text = port;
        }

        public void copyAndromedaCATPropsToDialogVars()
        {
            chkEnableAndromeda.Checked = console.AndromedaCATEnabled;
            string port = "COM" + console.AndromedaCATPort.ToString();
            if (comboAndromedaCATPort.Items.Contains(port))
                comboAndromedaCATPort.Text = port;
        }

        public void copyAriesCATPropsToDialogVars()
        {

            chkEnableAries.Checked = console.AriesCATEnabled;
            string port = "COM" + console.AriesCATPort.ToString();
            if (comboAriesCATPort.Items.Contains(port))
                comboAriesCATPort.Text = port;
        }

        public void copyGanymedeCATPropsToDialogVars()
        {
            chkEnableGanymede.Checked = console.GanymedeCATEnabled;
            string port = "COM" + console.GanymedeCATPort.ToString();
            if (comboGanymedeCATPort.Items.Contains(port))
                comboGanymedeCATPort.Text = port;
        }

        private void chkCATEnable_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;

            if (comboCATPort.Text == "" || !comboCATPort.Text.StartsWith("COM"))
            {
                if (chkCATEnable.Focused)
                {
                    if (chkCATEnable.Checked)
                    {
                        MessageBox.Show("The CAT port \"" + comboCATPort.Text + "\" is not a valid port.\n" +
                            "Please select another port.");
                        chkCATEnable.Checked = false;
                    }
                }
                return;
            }

            // make sure we're not using the same comm port as the bit banger 
            if (chkCATEnable.Checked && console.PTTBitBangEnabled &&
                (comboCATPort.Text == comboCATPTTPort.Text))
            {
                MessageBox.Show("CAT port cannot be the same as Bit Bang Port", "Port Selection Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST); //MW0LGE_[2.9.0.7]
                chkCATEnable.Checked = false;
            }

            // if enabled, disable changing of serial port 
            bool enable_sub_fields = !chkCATEnable.Checked;
            comboCATPort.Enabled = enable_sub_fields;

            enableCAT_HardwareFields(enable_sub_fields);

            if (chkCATEnable.Checked)
            {
                try
                {
                    console.CATEnabled = true;
                }
                catch (Exception ex)
                {
                    console.CATEnabled = false;
                    chkCATEnable.Checked = false;
                    MessageBox.Show("Could not initialize CAT control.  Exception was:\n\n " + ex.Message +
                        "\n\nCAT control has been disabled.", "Error Initializing CAT control",
                        MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST); //MW0LGE_[2.9.0.7]
                }
            }
            else
            {
                if (comboKeyerConnSecondary.Text == "CAT" && chkCATEnable.Focused)
                {
                    MessageBox.Show("The Secondary Keyer option has been changed to None since CAT has been disabled.",
                        "CAT Disabled",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST); //MW0LGE_[2.9.0.7]
                    comboKeyerConnSecondary.Text = "None";
                }

                if (comboCATPTTPort.Text == "CAT" && chkCATEnable.Focused)
                {
                    MessageBox.Show("The PTT Control Port option has been changed to None since CAT has been disabled.",
                        "CAT Disabled",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST); //MW0LGE_[2.9.0.7]

                    chkCATPTT_RTS.Checked = false;
                    chkCATPTT_DTR.Checked = false;
                    comboCATPTTPort.Text = "None";
                }

                console.CATEnabled = false;
            }

            console.UpdateStatusBarStatusIcons(StatusBarIconGroup.SerialCat);
        }

        private void chkCAT2Enable_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;

            if (comboCAT2Port.Text == "" || !comboCAT2Port.Text.StartsWith("COM"))
            {
                if (chkCAT2Enable.Focused)
                {
                    if (chkCAT2Enable.Checked)
                    {
                        MessageBox.Show("The CAT port \"" + comboCAT2Port.Text + "\" is not a valid port.\n" +
                            "Please select another port.");
                        chkCAT2Enable.Checked = false;
                    }
                }
                return;
            }

            // make sure we're not using the same comm port as the bit banger 
            if (chkCAT2Enable.Checked && console.PTTBitBangEnabled &&
                (comboCAT2Port.Text == comboCATPTTPort.Text))
            {
                MessageBox.Show("CAT port cannot be the same as Bit Bang Port", "Port Selection Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST); //MW0LGE_[2.9.0.7]
                chkCAT2Enable.Checked = false;
            }

            // if enabled, disable changing of serial port 
            bool enable_sub_fields = !chkCAT2Enable.Checked;
            comboCAT2Port.Enabled = enable_sub_fields;

            enableCAT2_HardwareFields(enable_sub_fields);

            if (chkCAT2Enable.Checked)
            {
                try
                {
                    console.CAT2Enabled = true;
                }
                catch (Exception ex)
                {
                    console.CAT2Enabled = false;
                    chkCAT2Enable.Checked = false;
                    MessageBox.Show("Could not initialize CAT control.  Exception was:\n\n " + ex.Message +
                        "\n\nCAT control has been disabled.", "Error Initializing CAT control",
                        MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST); //MW0LGE_[2.9.0.7]
                }
            }
            else
            {
                console.CAT2Enabled = false;
            }

            console.UpdateStatusBarStatusIcons(StatusBarIconGroup.SerialCat);
        }

        private void chkCAT3Enable_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;

            if (comboCAT3Port.Text == "" || !comboCAT3Port.Text.StartsWith("COM"))
            {
                if (chkCAT3Enable.Focused)
                {
                    if (chkCAT3Enable.Checked)
                    {
                        MessageBox.Show("The CAT port \"" + comboCAT3Port.Text + "\" is not a valid port.\n" +
                            "Please select another port.");
                        chkCAT3Enable.Checked = false;
                    }
                }
                return;
            }

            // make sure we're not using the same comm port as the bit banger 
            if (chkCAT3Enable.Checked && console.PTTBitBangEnabled &&
                (comboCAT3Port.Text == comboCATPTTPort.Text))
            {
                MessageBox.Show("CAT port cannot be the same as Bit Bang Port", "Port Selection Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST); //MW0LGE_[2.9.0.7]
                chkCAT3Enable.Checked = false;
            }

            // if enabled, disable changing of serial port 
            bool enable_sub_fields = !chkCAT3Enable.Checked;
            comboCAT3Port.Enabled = enable_sub_fields;

            enableCAT3_HardwareFields(enable_sub_fields);

            if (chkCAT3Enable.Checked)
            {
                try
                {
                    console.CAT3Enabled = true;
                }
                catch (Exception ex)
                {
                    console.CAT3Enabled = false;
                    chkCAT3Enable.Checked = false;
                    MessageBox.Show("Could not initialize CAT control.  Exception was:\n\n " + ex.Message +
                        "\n\nCAT control has been disabled.", "Error Initializing CAT control",
                        MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST); //MW0LGE_[2.9.0.7]
                }
            }
            else
            {
                console.CAT3Enabled = false;
            }

            console.UpdateStatusBarStatusIcons(StatusBarIconGroup.SerialCat);
        }

        private void chkCAT4Enable_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;

            if (comboCAT4Port.Text == "" || !comboCAT4Port.Text.StartsWith("COM"))
            {
                if (chkCAT4Enable.Focused)
                {
                    if (chkCAT4Enable.Checked)
                    {
                        MessageBox.Show("The CAT port \"" + comboCAT4Port.Text + "\" is not a valid port.\n" +
                            "Please select another port.");
                        chkCAT4Enable.Checked = false;
                    }
                }
                return;
            }

            // make sure we're not using the same comm port as the bit banger 
            if (chkCAT4Enable.Checked && console.PTTBitBangEnabled &&
                (comboCAT4Port.Text == comboCATPTTPort.Text))
            {
                MessageBox.Show("CAT port cannot be the same as Bit Bang Port", "Port Selection Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST); //MW0LGE_[2.9.0.7]
                chkCAT4Enable.Checked = false;
            }

            // if enabled, disable changing of serial port 
            bool enable_sub_fields = !chkCAT4Enable.Checked;
            comboCAT4Port.Enabled = enable_sub_fields;

            enableCAT4_HardwareFields(enable_sub_fields);

            if (chkCAT4Enable.Checked)
            {
                try
                {
                    console.CAT4Enabled = true;
                }
                catch (Exception ex)
                {
                    console.CAT4Enabled = false;
                    chkCAT4Enable.Checked = false;
                    MessageBox.Show("Could not initialize CAT control.  Exception was:\n\n " + ex.Message +
                        "\n\nCAT control has been disabled.", "Error Initializing CAT control",
                        MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST); //MW0LGE_[2.9.0.7]
                }
            }
            else
            {
                console.CAT4Enabled = false;
            }

            console.UpdateStatusBarStatusIcons(StatusBarIconGroup.SerialCat);
        }

        // reguire a valid COM port for Andromeda; not needed for G2 panel
        private void ChkEnableAndromeda_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;

            chkAndrG2Panel.Checked = false;
            if (comboAndromedaCATPort.Text == "" || !comboAndromedaCATPort.Text.StartsWith("COM"))
            {
                if (chkEnableAndromeda.Focused)
                {
                    if (chkEnableAndromeda.Checked)
                    {
                        MessageBox.Show("The CAT port \"" + comboAndromedaCATPort.Text + "\" is not a valid port.\n" +
                            "Please select another port.");
                        chkEnableAndromeda.Checked = false;
                    }
                }
                return;
            }

            // make sure we're not using the same comm port as the bit banger
            if (chkEnableAndromeda.Checked && console.PTTBitBangEnabled &&
                (comboAndromedaCATPort.Text == comboCATPTTPort.Text))
            {
                MessageBox.Show("Andromeda CAT port cannot be the same as Bit Bang Port", "Port Selection Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST); //MW0LGE_[2.9.0.7]
                chkEnableAndromeda.Checked = false;
            }

            // if enabled, disable changing of serial port
            bool enable_sub_fields = !chkEnableAndromeda.Checked;
            comboAndromedaCATPort.Enabled = enable_sub_fields;

            if (chkEnableAndromeda.Checked)
            {
                try
                {
                    console.AndromedaCATEnabled = true;
                    chkAndrG2Panel.Enabled = false;
                }
                catch (Exception ex)
                {
                    console.AndromedaCATEnabled = false;
                    chkEnableAndromeda.Checked = false;
                    MessageBox.Show("Could not initialize Andromeda control.  Exception was:\n\n " + ex.Message +
                        "\n\nAndromeda control has been disabled.", "Error Initializing Andromeda control",
                        MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST); //MW0LGE_[2.9.0.7]
                }
            }
            else
            {
                if (comboKeyerConnSecondary.Text == "CAT" && chkCATEnable.Focused)
                {
                    MessageBox.Show("The Secondary Keyer option has been changed to None since CAT has been disabled.",
                        "CAT Disabled",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST); //MW0LGE_[2.9.0.7]
                    comboKeyerConnSecondary.Text = "None";
                }

                if (comboCATPTTPort.Text == "CAT" && chkCATEnable.Focused)
                {
                    MessageBox.Show("The PTT Control Port option has been changed to None since CAT has been disabled.",
                        "CAT Disabled",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST); //MW0LGE_[2.9.0.7]

                    chkCATPTT_RTS.Checked = false;
                    chkCATPTT_DTR.Checked = false;
                    comboCATPTTPort.Text = "None";
                }

                console.AndromedaCATEnabled = false;
                chkAndrG2Panel.Enabled = true;
            }

        }

        private void enableCAT_HardwareFields(bool enable)
        {
            comboCATbaud.Enabled = enable;
            comboCATparity.Enabled = enable;
            comboCATdatabits.Enabled = enable;
            comboCATstopbits.Enabled = enable;
        }

        private void enableCAT2_HardwareFields(bool enable)
        {
            comboCAT2baud.Enabled = enable;
            comboCAT2parity.Enabled = enable;
            comboCAT2databits.Enabled = enable;
            comboCAT2stopbits.Enabled = enable;
        }

        private void enableCAT3_HardwareFields(bool enable)
        {
            comboCAT3baud.Enabled = enable;
            comboCAT3parity.Enabled = enable;
            comboCAT3databits.Enabled = enable;
            comboCAT3stopbits.Enabled = enable;
        }

        private void enableCAT4_HardwareFields(bool enable)
        {
            comboCAT4baud.Enabled = enable;
            comboCAT4parity.Enabled = enable;
            comboCAT4databits.Enabled = enable;
            comboCAT4stopbits.Enabled = enable;
        }

        private void doEnablementOnBitBangEnable()
        {
            if (comboCATPTTPort.Text != "None" &&
                (chkCATPTT_RTS.Checked || chkCATPTT_DTR.Checked))  // if RTS or DTR & port is not None, enable 
            {
                chkCATPTTEnabled.Enabled = true;
            }
            else
            {
                chkCATPTTEnabled.Enabled = false;
                chkCATPTTEnabled.Checked = false; // make sure it is not checked 
            }
        }

        private void chkCATPTT_RTS_CheckedChanged(object sender, System.EventArgs e)
        {
            console.Siolisten.PTTOnRTS = chkCATPTT_RTS.Checked;
            console.CATPTTRTS = chkCATPTT_RTS.Checked;
            doEnablementOnBitBangEnable();
        }

        private void chkCATPTT_DTR_CheckedChanged(object sender, System.EventArgs e)
        {
            console.Siolisten.PTTOnDTR = chkCATPTT_DTR.Checked;
            console.CATPTTDTR = chkCATPTT_DTR.Checked;
            doEnablementOnBitBangEnable();
        }

        private void chkCATPTTEnabled_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;

            bool enable_sub_fields;

            if (comboCATPTTPort.Text == "" || (!comboCATPTTPort.Text.StartsWith("COM") &&
                !comboCATPTTPort.Text.StartsWith("CAT")))
            {
                if (chkCATPTTEnabled.Focused && chkCATPTTEnabled.Checked)
                {
                    MessageBox.Show("The PTT port \"" + comboCATPTTPort.Text + "\" is not a valid port.  Please select another port.");
                }
                chkCATPTTEnabled.Checked = false;
                return;
            }

            if (chkCATPTTEnabled.Checked && console.CATEnabled &&
                comboCATPort.Text == comboCATPTTPort.Text)
            {
                if (chkCATPTTEnabled.Focused)
                {
                    MessageBox.Show("CAT port cannot be the same as Bit Bang Port", "Port Selection Error",
                        MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST); //MW0LGE_[2.9.0.7]
                    chkCATPTTEnabled.Checked = false;
                }
                return;
            }

            if (comboCATPTTPort.Text.StartsWith("CAT")) console.PTTBitBangEnabled = false;
            else console.PTTBitBangEnabled = chkCATPTTEnabled.Checked;

            if (chkCATPTTEnabled.Checked) // if it's enabled don't allow changing settings on port 
            {
                if (comboCATPTTPort.Text.StartsWith("CAT")) console.Siolisten.UseForCATPTT = true;
                enable_sub_fields = false;
            }
            else
            {
                console.Siolisten.UseForCATPTT = false;
                enable_sub_fields = true;
            }
            chkCATPTT_RTS.Enabled = enable_sub_fields;
            chkCATPTT_DTR.Enabled = enable_sub_fields;
            comboCATPTTPort.Enabled = enable_sub_fields;
        }

        private void comboCATparity_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            string selection = comboCATparity.SelectedText;
            if (selection == null) return;

            console.CATParity = SDRSerialPort.StringToParity(selection);
        }

        private void comboCAT2parity_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            string selection = comboCAT2parity.SelectedText;
            if (selection == null) return;

            console.CAT2Parity = SDRSerialPort.StringToParity(selection);
        }

        private void comboCAT3parity_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            string selection = comboCAT3parity.SelectedText;
            if (selection == null) return;

            console.CAT3Parity = SDRSerialPort.StringToParity(selection);
        }

        private void comboCAT4parity_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            string selection = comboCAT4parity.SelectedText;
            if (selection == null) return;

            console.CAT4Parity = SDRSerialPort.StringToParity(selection);
        }

        private void comboCATPort_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboCATPort.Text == "None")
            {
                if (chkCATEnable.Checked)
                {
                    if (comboCATPort.Focused)
                        chkCATEnable.Checked = false;
                }

                chkCATEnable.Enabled = false;
            }
            else chkCATEnable.Enabled = true;

            if (comboCATPort.Text.StartsWith("COM"))
                console.CATPort = Int32.Parse(comboCATPort.Text.Substring(3));

            console.UpdateStatusBarStatusIcons(StatusBarIconGroup.SerialCat);
        }

        private void comboCAT2Port_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboCAT2Port.Text == "None")
            {
                if (chkCAT2Enable.Checked)
                {
                    if (comboCAT2Port.Focused)
                        chkCAT2Enable.Checked = false;
                }

                chkCAT2Enable.Enabled = false;
            }
            else chkCAT2Enable.Enabled = true;

            if (comboCAT2Port.Text.StartsWith("COM"))
                console.CAT2Port = Int32.Parse(comboCAT2Port.Text.Substring(3));

            console.UpdateStatusBarStatusIcons(StatusBarIconGroup.SerialCat);
        }

        private void comboCAT3Port_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboCAT3Port.Text == "None")
            {
                if (chkCAT3Enable.Checked)
                {
                    if (comboCAT3Port.Focused)
                        chkCAT3Enable.Checked = false;
                }

                chkCAT3Enable.Enabled = false;
            }
            else chkCAT3Enable.Enabled = true;

            if (comboCAT3Port.Text.StartsWith("COM"))
                console.CAT3Port = Int32.Parse(comboCAT3Port.Text.Substring(3));

            console.UpdateStatusBarStatusIcons(StatusBarIconGroup.SerialCat);
        }

        private void comboCAT4Port_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboCAT4Port.Text == "None")
            {
                if (chkCAT4Enable.Checked)
                {
                    if (comboCAT4Port.Focused)
                        chkCAT4Enable.Checked = false;
                }

                chkCAT4Enable.Enabled = false;
            }
            else chkCAT4Enable.Enabled = true;

            if (comboCAT4Port.Text.StartsWith("COM"))
                console.CAT4Port = Int32.Parse(comboCAT4Port.Text.Substring(3));

            console.UpdateStatusBarStatusIcons(StatusBarIconGroup.SerialCat);
        }

        private void ComboAndromedaCATPort_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboAndromedaCATPort.Text == "None")
            {
                if (chkEnableAndromeda.Checked)
                {
                    if (comboAndromedaCATPort.Focused)
                        chkEnableAndromeda.Checked = false;
                }

                if(!chkAndrG2Panel.Checked)
                chkEnableAndromeda.Enabled = false;
            }
            else chkEnableAndromeda.Enabled = true;

            if (comboAndromedaCATPort.Text.StartsWith("COM"))
                console.AndromedaCATPort = Int32.Parse(comboAndromedaCATPort.Text.Substring(3));
        }

        private void comboCATPTTPort_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboCATPTTPort.Text == "None")
            {
                if (chkCATPTTEnabled.Checked)
                {
                    if (comboCATPTTPort.Focused)
                        chkCATPTTEnabled.Checked = false;
                }

                doEnablementOnBitBangEnable();
            }
            else if (comboCATPTTPort.Text == "CAT")
            {
                if (!chkCATEnable.Checked)
                {
                    MessageBox.Show("CAT is not Enabled.  Please enable the CAT interface before selecting this option.",
                        "CAT not enabled",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST); //MW0LGE_[2.9.0.7]
                    comboCATPTTPort.Text = "None";
                    return;
                }
                else
                {
                    if (chkCATPTT_RTS.Checked || chkCATPTT_DTR.Checked)
                        doEnablementOnBitBangEnable();
                }
            }
            else
            {
                if (chkCATPTT_RTS.Checked || chkCATPTT_DTR.Checked)
                    doEnablementOnBitBangEnable();
            }

            if (console.Siolisten != null && comboCATPTTPort.Text != "CAT")
                console.Siolisten.UseForCATPTT = false;

            if (comboCATPTTPort.Text.StartsWith("COM"))
                console.CATPTTBitBangPort = Int32.Parse(comboCATPTTPort.Text.Substring(3));
            if (!comboCATPTTPort.Focused)
                chkCATPTTEnabled_CheckedChanged(sender, e);
        }

        private void comboCATbaud_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboCATbaud.SelectedIndex >= 0)
                console.CATBaudRate = Int32.Parse(comboCATbaud.Text);
        }

        private void comboCAT2baud_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboCAT2baud.SelectedIndex >= 0)
                console.CAT2BaudRate = Int32.Parse(comboCAT2baud.Text);
        }

        private void comboCAT3baud_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboCAT3baud.SelectedIndex >= 0)
                console.CAT3BaudRate = Int32.Parse(comboCAT3baud.Text);
        }

        private void comboCAT4baud_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboCAT4baud.SelectedIndex >= 0)
                console.CAT4BaudRate = Int32.Parse(comboCAT4baud.Text);
        }

        private void comboCATdatabits_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboCATdatabits.SelectedIndex >= 0)
                console.CATDataBits = int.Parse(comboCATdatabits.Text);
        }

        private void comboCAT2databits_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboCAT2databits.SelectedIndex >= 0)
                console.CAT2DataBits = int.Parse(comboCAT2databits.Text);
        }

        private void comboCAT3databits_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboCAT3databits.SelectedIndex >= 0)
                console.CAT3DataBits = int.Parse(comboCAT3databits.Text);
        }

        private void comboCAT4databits_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboCAT4databits.SelectedIndex >= 0)
                console.CAT4DataBits = int.Parse(comboCAT4databits.Text);
        }

        private void comboCATstopbits_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboCATstopbits.SelectedIndex >= 0)
                console.CATStopBits = SDRSerialPort.StringToStopBits(comboCATstopbits.Text);
        }

        private void comboCAT2stopbits_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboCAT2stopbits.SelectedIndex >= 0)
                console.CAT2StopBits = SDRSerialPort.StringToStopBits(comboCAT2stopbits.Text);
        }

        private void comboCAT3stopbits_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboCAT3stopbits.SelectedIndex >= 0)
                console.CAT3StopBits = SDRSerialPort.StringToStopBits(comboCAT3stopbits.Text);
        }

        private void comboCAT4stopbits_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboCAT4stopbits.SelectedIndex >= 0)
                console.CAT4StopBits = SDRSerialPort.StringToStopBits(comboCAT4stopbits.Text);
        }

        private void btnCATTest_Click(object sender, System.EventArgs e)
        {
            CATTester cat = new CATTester(console);
            cat.Show();
            cat.Focus();
        }

        //Modified 10/12/08 BT to change "SDR-1000" to "PowerSDR"
        private void comboCATRigType_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            switch (comboCATRigType.Text)
            {
                case "PowerSDR":
                    console.CATRigType = 900;
                    break;
                case "TS-2000":
                    console.CATRigType = 19;
                    break;
                case "TS-50S":
                    console.CATRigType = 13;
                    break;
                case "TS-440":
                    console.CATRigType = 20;
                    break;
                default:
                    console.CATRigType = 19;
                    break;
            }
        }

        #endregion

        #region Test Tab Event Handlers
        public bool TestIMD
        {
            set { chkTestIMD.Checked = value; }
            get { return chkTestIMD.Checked; }
        }



        private static bool ttgenrun = false;
        public bool TTgenrun
        {
            get { return chkTestIMD.Checked; }
            set
            {
                ttgenrun = value;
                if (ttgenrun && !chkTestIMD.Checked) chkTestIMD.Checked = true;
                if (!ttgenrun && chkTestIMD.Checked && console.MOX) chkTestIMD.Checked = false;
            }
        }

        private async void chkTestIMD_CheckedChanged(object sender, System.EventArgs e)
        {
            if (chkTestIMD.Checked)
            {
                udTestIMDFreq1.Enabled = false;
                udTestIMDFreq2.Enabled = false;
                udTwoToneLevel.Enabled = false;
                udTestIMDPower.Enabled = false;
                chkInvertTones.Enabled = false;
                udFreq2Delay.Enabled = false; //MW0LGE_21
                double ttfreq1 = (double)udTestIMDFreq1.Value;
                double ttfreq2 = (double)udTestIMDFreq2.Value;
                double ttmag = (double)udTwoToneLevel.Value;
                double ttmag1, ttmag2;
                ttmag1 = ttmag2 = 0.49999 * Math.Pow(10.0, ttmag / 20.0);
                DSPMode mode = console.radio.GetDSPTX(0).CurrentDSPMode;
                if (chkInvertTones.Checked && ((mode == DSPMode.CWL) || (mode == DSPMode.DIGL) || (mode == DSPMode.LSB)))
                {
                    ttfreq1 = -ttfreq1;
                    ttfreq2 = -ttfreq2;
                }
                if (!console.PowerOn)
                {
                    MessageBox.Show("Power must be on to run this test.",
                        "Power is off",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Hand);
                    chkTestIMD.Checked = false;
                    return;
                }
                if (console.MOX)
                {
                    Audio.MOX = false;
                    console.MOX = false;
                    await Task.Delay(200); //MW0LGE_21a
                }

                console.radio.GetDSPTX(0).TXPostGenMode = 1;
                console.radio.GetDSPTX(0).TXPostGenTTFreq1 = ttfreq1;
                console.radio.GetDSPTX(0).TXPostGenTTFreq2 = ttfreq2;
                console.radio.GetDSPTX(0).TXPostGenTTMag1 = ttmag1;

                //MW0LGE_21a change to delay Freq2 output. Fixes problems with some Amps frequency counters
                if ((int)udFreq2Delay.Value == 0)
                    console.radio.GetDSPTX(0).TXPostGenTTMag2 = ttmag2;
                else
                    console.radio.GetDSPTX(0).TXPostGenTTMag2 = 0.0;

                console.radio.GetDSPTX(0).TXPostGenRun = 1;

                //MW0LGE_22b
                // remember old power //MW0LGE_22b
                if (console.TwoToneDrivePowerOrigin == DrivePowerSource.FIXED)
                    console.PreviousPWR = console.PWR;
                // set power
                int new_pwr = console.SetPowerUsingTargetDBM(out bool bUseConstrain, out double targetdBm, true, true, true);
                //
                if (console.TwoToneDrivePowerOrigin == DrivePowerSource.FIXED)
                {
                    console.PWRSliderLimitEnabled = false;
                    console.PWR = new_pwr;
                }
                //

                console.ManualMox = true;
                console.Manual2Tone = true; // MW0LGE_21a
                Audio.MOX = true;//
                console.MOX = true;
                if (!console.MOX)
                {
                    chkTestIMD.Checked = false;
                    return;
                }

                if ((int)udFreq2Delay.Value > 0)
                {
                    // set magnitude after a delay for freq2 
                    await Task.Delay((int)udFreq2Delay.Value);
                    console.radio.GetDSPTX(0).TXPostGenTTMag2 = ttmag2;
                }

                chkTestIMD.BackColor = console.ButtonSelectedColor;
                console.psform.TTgenON = true;

                chkTestIMD.Text = "Stop"; //MW0LGE_22b
            }
            else
            {
                console.MOX = false;
                await Task.Delay(200); //MW0LGE_21a
                Audio.MOX = false;//
                console.ManualMox = false;
                console.Manual2Tone = false; // MW0LGE_21a

                //MW0LGE_22b
                if (console.TwoToneDrivePowerOrigin == DrivePowerSource.FIXED)
                {
                    console.PWRSliderLimitEnabled = true;
                    console.PWR = console.PreviousPWR;
                }

                chkTestIMD.BackColor = SystemColors.Control;
                console.psform.TTgenON = false;
                console.radio.GetDSPTX(0).TXPostGenRun = 0;
                udTestIMDFreq1.Enabled = true;
                udTestIMDFreq2.Enabled = true;
                udTwoToneLevel.Enabled = true;
                udTestIMDPower.Enabled = true;
                chkInvertTones.Enabled = true;
                udFreq2Delay.Enabled = true;

                chkTestIMD.Text = "Start";
            }
        }

        private void cmboSigGenRXMode_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (cmboSigGenRXMode.SelectedIndex < 0) return;
            console.radio.GetDSPRX(0, 0).RXPreGenRun = 0;
            console.radio.GetDSPRX(1, 0).RXPreGenRun = 0;
            for (int i = 0; i < 2; i++)
            {
                switch (cmboSigGenRXMode.Text)
                {
                    case "Radio":
                        break;
                    case "Tone":
                        console.radio.GetDSPRX(i, 0).RXPreGenMode = 0;
                        console.radio.GetDSPRX(i, 0).RXPreGenToneMag = Math.Pow(10, (double)udRXGenScale.Value / 20.0);
                        console.radio.GetDSPRX(i, 0).RXPreGenToneFreq = (double)udRXGenFreq.Value;
                        break;
                    case "Noise":
                        console.radio.GetDSPRX(i, 0).RXPreGenMode = 2;
                        console.radio.GetDSPRX(i, 0).RXPreGenNoiseMag = Math.Pow(10, (double)udRXGenScale.Value / 20.0);
                        break;
                    case "Sweep":
                        console.radio.GetDSPRX(i, 0).RXPreGenMode = 3;
                        console.radio.GetDSPRX(i, 0).RXPreGenSweepMag = Math.Pow(10, (double)udRXGenScale.Value / 20.0);
                        console.radio.GetDSPRX(i, 0).RXPreGenSweepFreq1 = (double)udRXGenSweepLow.Value;
                        console.radio.GetDSPRX(i, 0).RXPreGenSweepFreq2 = (double)udRXGenSweepHigh.Value;
                        console.radio.GetDSPRX(i, 0).RXPreGenSweepRate = (double)udRXGenSweepRate.Value;
                        break;
                    case "Silence":
                        console.radio.GetDSPRX(i, 0).RXPreGenMode = -1;
                        break;
                }
            }

            if (chkSigGenRX1.Checked && !(cmboSigGenRXMode.Text == "Radio"))
                console.radio.GetDSPRX(0, 0).RXPreGenRun = 1;

            if (chkSigGenRX2.Checked && !(cmboSigGenRXMode.Text == "Radio"))
                console.radio.GetDSPRX(1, 0).RXPreGenRun = 1;
        }

        private void chkSigGenRX2_CheckedChanged(object sender, System.EventArgs e)
        {
            cmboSigGenRXMode_SelectedIndexChanged(this, EventArgs.Empty);
        }

        private void cmboSigGenTXMode_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (cmboSigGenTXMode.SelectedIndex < 0) return;
            console.radio.GetDSPTX(0).TXPreGenRun = 0;

            switch (cmboSigGenTXMode.Text)
            {
                case "Radio":
                    break;
                case "Tone":
                    console.radio.GetDSPTX(0).TXPreGenMode = 0;
                    console.radio.GetDSPTX(0).TXPreGenToneMag = Math.Pow(10, (double)udTXGenScale.Value / 20.0);
                    console.radio.GetDSPTX(0).TXPreGenToneFreq = (double)udTXGenFreq.Value;
                    console.radio.GetDSPTX(0).TXPreGenRun = 1;
                    break;
                case "Noise":
                    console.radio.GetDSPTX(0).TXPreGenMode = 2;
                    console.radio.GetDSPTX(0).TXPreGenNoiseMag = Math.Pow(10, (double)udTXGenScale.Value / 20.0);
                    console.radio.GetDSPTX(0).TXPreGenRun = 1;
                    break;
                case "Sweep":
                    console.radio.GetDSPTX(0).TXPreGenMode = 3;
                    console.radio.GetDSPTX(0).TXPreGenSweepMag = Math.Pow(10, (double)udTXGenScale.Value / 20.0);
                    console.radio.GetDSPTX(0).TXPreGenSweepFreq1 = (double)udTXGenSweepLow.Value;
                    console.radio.GetDSPTX(0).TXPreGenSweepFreq2 = (double)udTXGenSweepHigh.Value;
                    console.radio.GetDSPTX(0).TXPreGenSweepRate = (double)udTXGenSweepRate.Value;
                    console.radio.GetDSPTX(0).TXPreGenRun = 1;
                    break;
                case "Sawtooth":
                    console.radio.GetDSPTX(0).TXPreGenMode = 4;
                    console.radio.GetDSPTX(0).TXPreGenSawtoothMag = Math.Pow(10, (double)udTXGenScale.Value / 20.0);
                    console.radio.GetDSPTX(0).TXPreGenSawtoothFreq = (double)udTXGenFreq.Value;
                    console.radio.GetDSPTX(0).TXPreGenRun = 1;
                    break;
                case "Triangle":
                    console.radio.GetDSPTX(0).TXPreGenMode = 5;
                    console.radio.GetDSPTX(0).TXPreGenTriangleMag = Math.Pow(10, (double)udTXGenScale.Value / 20.0);
                    console.radio.GetDSPTX(0).TXPreGenTriangleFreq = (double)udTXGenFreq.Value;
                    console.radio.GetDSPTX(0).TXPreGenRun = 1;
                    break;
                case "Pulse":
                    console.radio.GetDSPTX(0).TXPreGenMode = 6;
                    console.radio.GetDSPTX(0).TXPreGenPulseMag = Math.Pow(10, (double)udTXGenScale.Value / 20.0);
                    console.radio.GetDSPTX(0).TXPreGenPulseToneFreq = (double)udTXGenFreq.Value;
                    console.radio.GetDSPTX(0).TXPreGenPulseFreq = (double)udTXGenPulseFreq.Value;
                    console.radio.GetDSPTX(0).TXPreGenPulseDutyCycle = (double)udTXGenPulseDutyCycle.Value;
                    console.radio.GetDSPTX(0).TXPreGenPulseTransition = (double)udTXGenPulseTransition.Value;
                    console.radio.GetDSPTX(0).TXPreGenRun = 1;
                    break;
                case "Silence":
                    console.radio.GetDSPTX(0).TXPreGenMode = -1;
                    console.radio.GetDSPTX(0).TXPreGenRun = 1;
                    break;
            }
        }

        private void btnImpulse_Click(object sender, System.EventArgs e)
        {
            Thread t = new Thread(new ThreadStart(ImpulseFunction))
            {
                Name = "Impulse",
                Priority = ThreadPriority.Highest,
                IsBackground = true
            };
            t.Start();
        }

        private void ImpulseFunction()
        {
        }

        #endregion

        #region Other Event Handlers
        // ======================================================
        // Display Tab Event Handlers
        // ======================================================

        private void setButtonState(bool bSaving, bool bLoading)
        {
            if (m_bIgnoreButtonState) return; // not used after this is true, which is set in console_closing

            // prevent users from cancel when saving etc
            // give some feedback that save or load is occurring

            bool bEnabled = !(bSaving || bLoading);

            // disable/enable anything that can save/load settings
            btnOK.Enabled = bEnabled;
            btnApply.Enabled = bEnabled;
            btnCancel.Enabled = bEnabled;
            comboFRSRegion.Enabled = bEnabled;
            comboTXProfileName.Enabled = bEnabled;
            btnTXProfileSave.Enabled = bEnabled;
            btnTXProfileDelete.Enabled = bEnabled;
            btnTXProfileDefImport.Enabled = bEnabled;

            if (bLoading)
            {
                labelSavingLoading.Text = "LOADING";
                labelSavingLoading.Visible = true;
            }
            else if (bSaving)
            {
                labelSavingLoading.Text = "SAVING";
                labelSavingLoading.Visible = true;
            }
            else
            {
                labelSavingLoading.Text = "";
                labelSavingLoading.Visible = false;
            }
            labelSavingLoading.Refresh();
        }

        private Thread m_objSaveLoadThread = null;
        public bool StillWaitingForSaveLoad
        {
            get { return (m_objSaveLoadThread != null && m_objSaveLoadThread.IsAlive); }
        }
        private bool m_bIgnoreButtonState = false;
        public bool IgnoreButtonState
        {
            get { return m_bIgnoreButtonState; }
            set { m_bIgnoreButtonState = value; }
        }
        public void WaitForSaveLoad(int nWait = -1)
        {
            if (m_objSaveLoadThread != null && m_objSaveLoadThread.IsAlive)
            {
                if (nWait == -1)
                    m_objSaveLoadThread.Join();
                else
                    m_objSaveLoadThread.Join(nWait);
            }
        }

        private void btnOK_Click(object sender, System.EventArgs e)
        {
            setButtonState(true, false);
            console.SetFocusMaster(true);
            WaitForSaveLoad();
            m_objSaveLoadThread = null;

            this.Hide(); //MW0LGE_21d deadlock potential

            m_objSaveLoadThread = new Thread(new ThreadStart(PreSaveOptions))
            {
                Name = "Save Options Thread",
                IsBackground = true,
                Priority = ThreadPriority.Lowest
            };
            m_objSaveLoadThread.Start();
        }

        private void btnCancel_Click(object sender, System.EventArgs e)
        {
            setButtonState(false, true);

            console.SetFocusMaster(true);

            WaitForSaveLoad();
            m_objSaveLoadThread = null;

            removeSpecialCases();
#if DEBUG
            listClickedControls(); //MW0LGE_21d for testing
            listUpdatedControls();
#endif
            //make copy for the thread to use
            m_lstUpdatedControlsClone = new List<string>(m_lstUpdatedControls);

            m_objSaveLoadThread = new Thread(new ThreadStart(PreRestoreOptions))
            {
                Name = "Get Options Thread",
                IsBackground = true,
                Priority = ThreadPriority.Lowest
            };
            m_objSaveLoadThread.Start();
            this.Hide();
        }

        private void btnApply_Click(object sender, System.EventArgs e)
        {
            setButtonState(true, false);

            WaitForSaveLoad();
            m_objSaveLoadThread = null;

            clearUpdatedClickControlList(); //MW0LGE_21d

            m_objSaveLoadThread = new Thread(new ThreadStart(ApplyOptions))
            {
                Name = "Apply Options Thread",
                IsBackground = true,
                Priority = ThreadPriority.Lowest
            };
            m_objSaveLoadThread.Start();
        }

        private void PreRestoreOptions()
        {
            getOptions(m_lstUpdatedControlsClone);

            setButtonState(false, false);
        }
        private void PreSaveOptions()
        {
            SaveOptions();
            setButtonState(false, false);
        }
        private void ApplyOptions()
        {
            SaveOptions();
            setButtonState(false, false);
        }

        private void udGeneralLPTDelay_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
        }

        private void Setup_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            console.SetFocusMaster(true);
            this.Hide();
            e.Cancel = true;
        }

        private void btnImportDB_Click(object sender, System.EventArgs e)
        {            
        }

        private void openFileDialog1_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
        {
        }
        #endregion

        private bool shift_key = false;
        private bool ctrl_key = false;
        private bool alt_key = false;
        private bool windows_key = false;
        private bool menu_key = false;

        private void txtKB_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            Debug.WriteLine("KeyCode: " + e.KeyCode + " KeyData: " + e.KeyData + " KeyValue: " + e.KeyValue);
            shift_key = e.Shift;
            ctrl_key = e.Control;
            alt_key = e.Alt;

            if (e.KeyCode == Keys.LWin ||
                e.KeyCode == Keys.RWin)
                windows_key = true;

            if (e.KeyCode == Keys.Apps)
                menu_key = true;

            TextBoxTS txtbox = (TextBoxTS)sender;

            string s = "";

            if (ctrl_key) s += "Ctrl+";
            if (alt_key) s += "Alt+";
            if (shift_key) s += "Shift+";
            if (windows_key)
                s += "Win+";
            if (menu_key)
                s += "Menu+";

            if (e.KeyCode != Keys.ShiftKey &&
                e.KeyCode != Keys.ControlKey &&
                e.KeyCode != Keys.Menu &&
                e.KeyCode != Keys.RMenu &&
                e.KeyCode != Keys.LWin &&
                e.KeyCode != Keys.RWin &&
                e.KeyCode != Keys.Apps)
                s += KeyToString(e.KeyCode);

            txtbox.Text = s;
            e.Handled = true;
        }

        private void txtKB_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {
            e.Handled = true;
        }

        private void txtKB_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            shift_key = e.Shift;
            ctrl_key = e.Control;
            alt_key = e.Alt;

            if (e.KeyCode == Keys.LWin ||
                e.KeyCode == Keys.RWin)
                windows_key = false;

            if (e.KeyCode == Keys.Apps)
                menu_key = false;


            TextBoxTS txtbox = (TextBoxTS)sender;

            if (txtbox.Text.EndsWith("+"))
            {
                if (shift_key || ctrl_key || alt_key ||
                    windows_key || menu_key)
                {
                    string s = "";

                    if (ctrl_key) s += "Ctrl+";
                    if (alt_key) s += "Alt+";
                    if (shift_key) s += "Shift+";
                    if (windows_key)
                        s += "Win+";
                    if (menu_key)
                        s += "Menu+";

                    txtbox.Text = s;
                }
                else
                    txtbox.Text = "Not Assigned";
            }
        }

        private void clrbtnTXFilter_Changed(object sender, System.EventArgs e)
        {
            Display.DisplayFilterTXColor = clrbtnTXFilter.Color;
        }

        #region Lost Focus Event Handlers

        private void tbDSPAudRX1APFGain_LostFocus(object sender, EventArgs e)
        {
            tbDSPAudRX1APFGain.Value = tbDSPAudRX1APFGain.Value;
        }

        private void tbDSPAudRX1subAPFGain_LostFocus(object sender, EventArgs e)
        {
            tbDSPAudRX1subAPFGain.Value = tbDSPAudRX1subAPFGain.Value;
        }

        private void tbDSPAudRX2APFGain_LostFocus(object sender, EventArgs e)
        {
            tbDSPAudRX2APFGain.Value = tbDSPAudRX2APFGain.Value;
        }

        private void udGeneralCalFreq1_LostFocus(object sender, EventArgs e)
        {
            udGeneralCalFreq1.Value = udGeneralCalFreq1.Value;
        }

        private void udOptClickTuneOffsetDIGL_LostFocus(object sender, EventArgs e)
        {

        }

        private void udOptClickTuneOffsetDIGU_LostFocus(object sender, EventArgs e)
        {
            udOptClickTuneOffsetDIGU.Value = udOptClickTuneOffsetDIGU.Value;
        }

        private void udGeneralCalFreq3_LostFocus(object sender, EventArgs e)
        {
            udGeneralCalFreq3.Value = udGeneralCalFreq3.Value;
        }

        private void udGeneralCalLevel_LostFocus(object sender, EventArgs e)
        {
            udGeneralCalLevel.Value = udGeneralCalLevel.Value;
        }

        private void udGeneralCalFreq2_LostFocus(object sender, EventArgs e)
        {
            udGeneralCalFreq2.Value = udGeneralCalFreq2.Value;
        }

        private void udFilterDefaultLowCut_LostFocus(object sender, EventArgs e)
        {
            udFilterDefaultLowCut.Value = udFilterDefaultLowCut.Value;
        }

        private void udOptMaxFilterShift_LostFocus(object sender, EventArgs e)
        {
            udOptMaxFilterShift.Value = udOptMaxFilterShift.Value;
        }

        private void udOptMaxFilterWidth_LostFocus(object sender, EventArgs e)
        {
            udOptMaxFilterWidth.Value = udOptMaxFilterWidth.Value;
        }

        private void udAudioVACGainTX_LostFocus(object sender, EventArgs e)
        {
            udAudioVACGainTX.Value = udAudioVACGainTX.Value;
        }

        private void udAudioVACGainRX_LostFocus(object sender, EventArgs e)
        {
            udAudioVACGainRX.Value = udAudioVACGainRX.Value;
        }

        private void udAudioLatency2_LostFocus(object sender, EventArgs e)
        {
            udAudioLatency2.Value = udAudioLatency2.Value;
        }

        private void udDisplayScopeTime_LostFocus(object sender, EventArgs e)
        {
            udDisplayScopeTime.Value = udDisplayScopeTime.Value;
        }

        private void udDisplayMeterAvg_LostFocus(object sender, EventArgs e)
        {
            udDisplayMeterAvg.Value = udDisplayMeterAvg.Value;
        }

        private void udDisplayMultiTextHoldTime_LostFocus(object sender, EventArgs e)
        {
            udDisplayMultiTextHoldTime.Value = udDisplayMultiTextHoldTime.Value;
        }

        private void udDisplayMultiPeakHoldTime_LostFocus(object sender, EventArgs e)
        {
            udDisplayMultiPeakHoldTime.Value = udDisplayMultiPeakHoldTime.Value;
        }

        private void udDisplayWaterfallLowLevel_LostFocus(object sender, EventArgs e)
        {
            udDisplayWaterfallLowLevel.Value = udDisplayWaterfallLowLevel.Value;
        }

        private void udDisplayWaterfallHighLevel_LostFocus(object sender, EventArgs e)
        {
            udDisplayWaterfallHighLevel.Value = udDisplayWaterfallHighLevel.Value;
        }

        private void udDisplayCPUMeter_LostFocus(object sender, EventArgs e)
        {
            udDisplayCPUMeter.Value = udDisplayCPUMeter.Value;
        }

        private void udDisplayPeakText_LostFocus(object sender, EventArgs e)
        {
            udDisplayPeakText.Value = udDisplayPeakText.Value;
        }

        private void udDisplayMeterDelay_LostFocus(object sender, EventArgs e)
        {
            udDisplayMeterDelay.Value = udDisplayMeterDelay.Value;
        }

        private void udDisplayFPS_LostFocus(object sender, EventArgs e)
        {
            udDisplayFPS.Value = udDisplayFPS.Value;
        }

        private void udDisplayAVGTime_LostFocus(object sender, EventArgs e)
        {
            udDisplayAVGTime.Value = udDisplayAVGTime.Value;
        }

        private void udDisplayPhasePts_LostFocus(object sender, EventArgs e)
        {
            udDisplayPhasePts.Value = udDisplayPhasePts.Value;
        }

        private void udDisplayGridStep_LostFocus(object sender, EventArgs e)
        {
            udDisplayGridStep.Value = udDisplayGridStep.Value;
        }

        private void udTXGridMin_LostFocus(object sender, EventArgs e)
        {
            udTXGridMin.Value = udTXGridMin.Value;
        }

        private void udTXGridStep_LostFocus(object sender, EventArgs e)
        {
            udTXGridStep.Value = udTXGridStep.Value;
        }

        private void udDisplayGridMin_LostFocus(object sender, EventArgs e)
        {
            udDisplayGridMin.Value = udDisplayGridMin.Value;
        }

        private void udDSPNB_LostFocus(object sender, EventArgs e)
        {
            udDSPNB.Value = udDSPNB.Value;
        }

        private void udLMSNRgain_LostFocus(object sender, EventArgs e)
        {
            udLMSNRgain.Value = udLMSNRgain.Value;
        }

        private void udLMSNRdelay_LostFocus(object sender, EventArgs e)
        {
            udLMSNRdelay.Value = udLMSNRdelay.Value;
        }

        private void udLMSNRtaps_LostFocus(object sender, EventArgs e)
        {
            udLMSNRtaps.Value = udLMSNRtaps.Value;
        }

        private void udLMSANFgain_LostFocus(object sender, EventArgs e)
        {
            udLMSANFgain.Value = udLMSANFgain.Value;
        }

        private void udLMSANFdelay_LostFocus(object sender, EventArgs e)
        {
            udLMSANFdelay.Value = udLMSANFdelay.Value;
        }

        private void udLMSANFtaps_LostFocus(object sender, EventArgs e)
        {
            udLMSANFtaps.Value = udLMSANFtaps.Value;
        }

        private void udDSPCWPitch_LostFocus(object sender, EventArgs e)
        {
            udDSPCWPitch.Value = udDSPCWPitch.Value;
        }

        private void udCWKeyerWeight_LostFocus(object sender, EventArgs e)
        {
            udCWKeyerWeight.Value = udCWKeyerWeight.Value;
        }

        private void udCWBreakInDelay_LostFocus(object sender, EventArgs e)
        {
            udCWBreakInDelay.Value = udCWBreakInDelay.Value;
        }

        private void udDSPLevelerHangTime_LostFocus(object sender, EventArgs e)
        {
            udDSPLevelerHangTime.Value = udDSPLevelerHangTime.Value;
        }

        private void udDSPLevelerThreshold_LostFocus(object sender, EventArgs e)
        {
            udDSPLevelerThreshold.Value = udDSPLevelerThreshold.Value;
        }

        private void udDSPLevelerSlope_LostFocus(object sender, EventArgs e)
        {
            udDSPLevelerSlope.Value = udDSPLevelerSlope.Value;
        }

        private void udDSPLevelerDecay_LostFocus(object sender, EventArgs e)
        {
            udDSPLevelerDecay.Value = udDSPLevelerDecay.Value;
        }

        private void udDSPLevelerAttack_LostFocus(object sender, EventArgs e)
        {
            udDSPLevelerAttack.Value = udDSPLevelerAttack.Value;
        }

        private void udDSPALCHangTime_LostFocus(object sender, EventArgs e)
        {
            udDSPALCHangTime.Value = udDSPALCHangTime.Value;
        }

        private void udDSPALCThreshold_LostFocus(object sender, EventArgs e)
        {
            udDSPALCMaximumGain.Value = udDSPALCMaximumGain.Value;
        }

        private void udDSPALCSlope_LostFocus(object sender, EventArgs e)
        {
            udDSPALCSlope.Value = udDSPALCSlope.Value;
        }

        private void udDSPALCDecay_LostFocus(object sender, EventArgs e)
        {
            udDSPALCDecay.Value = udDSPALCDecay.Value;
        }

        private void udDSPALCAttack_LostFocus(object sender, EventArgs e)
        {
            udDSPALCAttack.Value = udDSPALCAttack.Value;
        }

        private void udDSPAGCHangTime_LostFocus(object sender, EventArgs e)
        {
            udDSPAGCHangTime.Value = udDSPAGCHangTime.Value;
        }

        private void udDSPAGCMaxGaindB_LostFocus(object sender, EventArgs e)
        {
            udDSPAGCMaxGaindB.Value = udDSPAGCMaxGaindB.Value;
        }

        private void udDSPAGCSlope_LostFocus(object sender, EventArgs e)
        {
            udDSPAGCSlope.Value = udDSPAGCSlope.Value;
        }

        private void udDSPAGCDecay_LostFocus(object sender, EventArgs e)
        {
            udDSPAGCDecay.Value = udDSPAGCDecay.Value;
        }

        private void udDSPAGCAttack_LostFocus(object sender, EventArgs e)
        {
            udDSPAGCAttack.Value = udDSPAGCAttack.Value;
        }

        private void udDSPAGCFixedGaindB_LostFocus(object sender, EventArgs e)
        {
            udDSPAGCFixedGaindB.Value = udDSPAGCFixedGaindB.Value;
        }

        private void udTXAMCarrierLevel_LostFocus(object sender, EventArgs e)
        {
            udTXAMCarrierLevel.Value = udTXAMCarrierLevel.Value;
        }

        private void udTXAF_LostFocus(object sender, EventArgs e)
        {
            udTXAF.Value = udTXAF.Value;
        }

        private void udTXTunePower_LostFocus(object sender, EventArgs e)
        {
            udTXTunePower.Value = udTXTunePower.Value;
        }

        private void udTXFilterLow_LostFocus(object sender, EventArgs e)
        {
            //udTXFilterLow.Value = udTXFilterLow.Value;
            udTXFilterLow_ValueChanged(sender, e); //[2.10.3.5]MW0LGE we want to validate even value doesnt change
        }

        private void udTXFilterHigh_LostFocus(object sender, EventArgs e)
        {
            //udTXFilterHigh.Value = udTXFilterHigh.Value;
            udTXFilterHigh_ValueChanged(sender, e); //[2.10.3.5]MW0LGE we want to validate even value doesnt change
        }

        private void udMicGainMax_LostFocus(object sender, EventArgs e)
        {
            udMicGainMax.Value = udMicGainMax.Value;
        }

        private void udMicGainMin_LostFocus(object sender, EventArgs e)
        {
            udMicGainMin.Value = udMicGainMin.Value;
        }

        private void udDisplayLineWidth_LostFocus(object sender, EventArgs e)
        {
            udDisplayLineWidth.Value = udDisplayLineWidth.Value;
        }

        private void udTXLineWidth_LostFocus(object sender, EventArgs e)
        {
            udTXLineWidth.Value = udTXLineWidth.Value;
        }

        private void udTXGenScale_LostFocus(object sender, EventArgs e)
        {
            udTXGenScale.Value = udTXGenScale.Value;
        }

        private void udTXGenSweepRate_LostFocus(object sender, EventArgs e)
        {
            udTXGenSweepRate.Value = udTXGenSweepRate.Value;
        }

        private void udTXGenSweepHigh_LostFocus(object sender, EventArgs e)
        {
            udTXGenSweepHigh.Value = udTXGenSweepHigh.Value;
        }

        private void udTXGenSweepLow_LostFocus(object sender, EventArgs e)
        {
            udTXGenSweepLow.Value = udTXGenSweepLow.Value;
        }

        private void udTestIMDFreq2_LostFocus(object sender, EventArgs e)
        {
            udTestIMDFreq2.Value = udTestIMDFreq2.Value;
        }

        private void udTestIMDPower_LostFocus(object sender, EventArgs e)
        {
            udTestIMDPower.Value = udTestIMDPower.Value;
        }

        private void udTestIMDFreq1_LostFocus(object sender, EventArgs e)
        {
            udTestIMDFreq1.Value = udTestIMDFreq1.Value;
        }

        private void udImpulseNum_LostFocus(object sender, EventArgs e)
        {
            udImpulseNum.Value = udImpulseNum.Value;
        }

        #endregion

        private void chkShowFreqOffset_CheckedChanged(object sender, System.EventArgs e)
        {
            Display.ShowFreqOffset = chkShowFreqOffset.Checked;
        }

        private void chkShowZeroLine_CheckedChanged(object sender, System.EventArgs e)
        {
            Display.ShowZeroLine = chkShowZeroLine.Checked;
        }

        private void clrbtnBandEdge_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Display.BandEdgeColor = clrbtnBandEdge.Color;
        }

        private void clrbtnTXBandEdge_Changed(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Display.TXBandEdgeColor = clrbtnTXBandEdge.Color;
        }

        private void comboMeterType_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            if (comboMeterType.Text == "") return;
            switch (comboMeterType.Text)
            {
                case "Original":
                    console.CurrentMeterDisplayMode = MultiMeterDisplayMode.Original;
                    break;
                case "Edge":
                    console.CurrentMeterDisplayMode = MultiMeterDisplayMode.Edge;
                    break;
                case "Analog":
                    console.CurrentMeterDisplayMode = MultiMeterDisplayMode.Analog;
                    break;
            }
        }

        private void clrbtnMeterEdgeLow_Changed(object sender, System.EventArgs e)
        {
            console.EdgeLowColor = clrbtnMeterEdgeLow.Color;
        }

        private void clrbtnMeterEdgeHigh_Changed(object sender, System.EventArgs e)
        {
            console.EdgeHighColor = clrbtnMeterEdgeHigh.Color;
        }

        private void clrbtnMeterEdgeBackground_Changed(object sender, System.EventArgs e)
        {
            console.EdgeMeterBackgroundColor = Color.FromArgb(tbMeterEdgeBackgroundAlpha.Value, clrbtnMeterEdgeBackground.Color);
        }

        private void clrbtnEdgeIndicator_Changed(object sender, System.EventArgs e)
        {
            console.EdgeAVGColor = clrbtnEdgeIndicator.Color;
        }

        private void clrbtnMeterDigText_Changed(object sender, System.EventArgs e)
        {
            console.MeterDigitalTextColor = clrbtnMeterDigText.Color;
        }

        private void clrbtnMeterDigBackground_Changed(object sender, System.EventArgs e)
        {
            console.MeterDigitalBackgroundColor = clrbtnMeterDigBackground.Color;
        }

        private void clrbtnSubRXFilter_Changed(object sender, System.EventArgs e)
        {
            Display.SubRXFilterColor = Color.FromArgb(tbMultiRXFilterAlpha.Value, clrbtnSubRXFilter.Color);
        }

        private void clrbtnSubRXZero_Changed(object sender, System.EventArgs e)
        {
            Display.SubRXZeroLine = clrbtnSubRXZero.Color;
        }

        private void chkCWKeyerMode_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;

            if (chkCWKeyerMode.Checked)
                NetworkIO.SetCWKeyerMode(1); // mode b
            else
                NetworkIO.SetCWKeyerMode(0); // mode a
        }

        private void chkDisableToolTips_CheckedChanged(object sender, System.EventArgs e)
        {
            toolTip1.Active = !chkDisableToolTips.Checked;
            console.DisableToolTips = chkDisableToolTips.Checked;
        }

        private void comboColorPalette_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboColorPalette.Text == "original")
            {
                console.color_sheme = ColorSheme.original;
                clrbtnWaterfallLow.Visible = true;
            }
            if (comboColorPalette.Text == "Enhanced")
            {
                console.color_sheme = ColorSheme.enhanced;
                clrbtnWaterfallLow.Visible = true;
            }
            if (comboColorPalette.Text == "Spectran")
            {
                clrbtnWaterfallLow.Visible = false;
                console.color_sheme = ColorSheme.SPECTRAN;
            }
            if (comboColorPalette.Text == "BlackWhite")
            {
                console.color_sheme = ColorSheme.BLACKWHITE;
                clrbtnWaterfallLow.Visible = false;
            }
            if (comboColorPalette.Text == "LinLog")
            {
                console.color_sheme = ColorSheme.LinLog;
                clrbtnWaterfallLow.Visible = false;
            }
            if (comboColorPalette.Text == "LinRad")
            {
                console.color_sheme = ColorSheme.LinRad;
                clrbtnWaterfallLow.Visible = false;
            }
            if (comboColorPalette.Text == "LinAuto")
            {
                console.color_sheme = ColorSheme.LinAuto;
                clrbtnWaterfallLow.Visible = false;
            }
        }

        private void comboRX2ColorPalette_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboRX2ColorPalette.Text == "original")
            {
                console.rx2_color_sheme = ColorSheme.original;
                clrbtnRX2WaterfallLow.Visible = true;
            }
            if (comboRX2ColorPalette.Text == "Enhanced")
            {
                console.rx2_color_sheme = ColorSheme.enhanced;
                clrbtnRX2WaterfallLow.Visible = true;
            }
            if (comboRX2ColorPalette.Text == "Spectran")
            {
                console.rx2_color_sheme = ColorSheme.SPECTRAN;
                clrbtnRX2WaterfallLow.Visible = false;
            }
            if (comboRX2ColorPalette.Text == "BlackWhite")
            {
                console.rx2_color_sheme = ColorSheme.BLACKWHITE;
                clrbtnRX2WaterfallLow.Visible = false;
            }
            if (comboRX2ColorPalette.Text == "LinLog")
            {
                console.rx2_color_sheme = ColorSheme.LinLog;
                clrbtnRX2WaterfallLow.Visible = false;
            }
            if (comboRX2ColorPalette.Text == "LinRad")
            {
                console.rx2_color_sheme = ColorSheme.LinRad;
                clrbtnRX2WaterfallLow.Visible = false;
            }
            if (comboRX2ColorPalette.Text == "LinAuto")
            {
                console.rx2_color_sheme = ColorSheme.LinAuto;
                clrbtnRX2WaterfallLow.Visible = false;
            }
        }

        private void setWaterFallCalculatedDelayText()
        {
            lblRX1WaterFallCalulatedDelayMS.Text = ((1000f / console.DisplayFPS) * Display.WaterfallUpdatePeriod).ToString("f2") + " (ms)";
            lblRX2WaterFallCalulatedDelayMS.Text = ((1000f / console.DisplayFPS) * Display.RX2WaterfallUpdatePeriod).ToString("f2") + " (ms)";
        }

        private void udDisplayWaterfallUpdatePeriod_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Display.WaterfallUpdatePeriod = (int)udDisplayWaterfallUpdatePeriod.Value;
            setWaterFallCalculatedDelayText();
        }

        private void udRX2DisplayWaterfallUpdatePeriod_ValueChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Display.RX2WaterfallUpdatePeriod = (int)udRX2DisplayWaterfallUpdatePeriod.Value;
            setWaterFallCalculatedDelayText();
        }

        private void chkSnapClickTune_CheckedChanged(object sender, System.EventArgs e)
        {
            console.SnapToClickTuning = chkSnapClickTune.Checked;
        }

        private void chkClickTuneFilter_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.ClickTuneFilter = chkClickTuneFilter.Checked;
            Display.ClickTuneFilter = chkClickTuneFilter.Checked;
        }

        private void chkShowCTHLine_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            Display.ShowCTHLine = chkShowCTHLine.Checked;
        }

        private void radPACalAllBands_CheckedChanged(object sender, System.EventArgs e)
        {
            foreach (Control c in panelAutoPACalibrate.Controls)
            {
                if (c.Name.StartsWith("chkPA") || c.Name.StartsWith("chkBy"))
                {
                    c.Visible = !radPACalAllBands.Checked;
                }
            }
        }

        private void chkZeroBeatRIT_CheckedChanged(object sender, System.EventArgs e)
        {
            console.ZeroBeatRIT = chkZeroBeatRIT.Checked;
        }

        private void chkPANewCal_CheckedChanged(object sender, System.EventArgs e)
        {
            bool b = chkPANewCal.Checked;

            console.NewPowerCal = b;

            //MW0LGE_22b
            nud160M.Visible = !b;
            nud80M.Visible = !b;
            nud60M.Visible = !b;
            nud40M.Visible = !b;
            nud30M.Visible = !b;
            nud20M.Visible = !b;
            nud17M.Visible = !b;
            nud15M.Visible = !b;
            nud12M.Visible = !b;
            nud10M.Visible = !b;
            nud6M.Visible = !b;

            // if (!radGenModelFLEX5000.Checked)
            {
                lblPACalTarget.Visible = !b;
                udPACalPower.Visible = !b;

                //MW0LGE_22b
                btnResetPAProfile.Visible = !b;
            }
        }

        private void udMeterDigitalDelay_ValueChanged(object sender, System.EventArgs e)
        {
            console.MeterDigDelay = (int)udMeterDigitalDelay.Value;
        }

        private void chkMouseTuneStep_CheckedChanged(object sender, System.EventArgs e)
        {
            console.MouseTuneStep = chkMouseTuneStep.Checked;
        }

        private void chkWheelReverse_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.WheelReverse = chkWheelReverse.Checked;
        }

        public string CustomTitle
        {
            get { return txtGenCustomTitle.Text; }
        }

        private void txtGenCustomTitle_TextChanged(object sender, System.EventArgs e)
        {
            console.CustomTitle = txtGenCustomTitle.Text;
        }

        private void chkGenAllModeMicPTT_CheckedChanged(object sender, System.EventArgs e)
        {
            console.AllModeMicPTT = chkGenAllModeMicPTT.Checked;
        }

        private void chkKWAI_CheckedChanged(object sender, System.EventArgs e)
        {
            AllowFreqBroadcast = chkKWAI.Checked;
        }

        private void chkSplitOff_CheckedChanged(object sender, System.EventArgs e)
        {
            console.DisableSplitOnBandchange = chkSplitOff.Checked;
        }

        public bool RFE_PA_TR
        {
            get { return chkEnableRFEPATR.Checked; }
            set { chkEnableRFEPATR.Checked = value; }
        }

        private void chkEnableRFEPATR_CheckedChanged(object sender, System.EventArgs e)
        {
            console.RFE_PA_TR_enable = chkEnableRFEPATR.Checked;
        }

        private void chkVACAllowBypass_CheckedChanged(object sender, System.EventArgs e)
        {
            console.AllowVACBypass = chkVACAllowBypass.Checked;
        }

        private void chkSPACEAllowBypass_CheckedChanged(object sender, System.EventArgs e)
        {
            console.AllowSPACEBypass = chkSPACEAllowBypass.Checked;
        }

        private void chkMOXAllowBypass_CheckedChanged(object sender, System.EventArgs e)
        {
            console.AllowMOXBypass = chkMOXAllowBypass.Checked;
        }

        private void chkDSPTXMeterPeak_CheckedChanged(object sender, System.EventArgs e)
        {
            console.PeakTXMeter = chkDSPTXMeterPeak.Checked;
        }

        private void chkVACCombine_CheckedChanged(object sender, System.EventArgs e)
        {
            Audio.VACCombineInput = chkVACCombine.Checked;
        }

        private void chkCWAutoSwitchMode_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            console.CWAutoModeSwitch = chkCWAutoSwitchMode.Checked;
            setEnabledAutoModeSwitchCWReturn(chkCWAutoSwitchMode.Checked);
        }

        private void clrbtnGenBackground_Changed(object sender, System.EventArgs e)//k6jca 1/13/08
        {

        }

        public MeterTXMode TuneMeterTXMode
        {
            //NOTE: check isMeterModeAvailableWhenTune in console
            set
            {
                switch (value)
                {
                    case MeterTXMode.FORWARD_POWER:
                        comboTXTUNMeter.Text = "Fwd Pwr";
                        break;
                    case MeterTXMode.REVERSE_POWER:
                        comboTXTUNMeter.Text = "Ref Pwr";
                        break;
                    case MeterTXMode.SWR_POWER: // MW0LGE re-added 
                        comboTXTUNMeter.Text = "Fwd SWR";
                        break;
                    case MeterTXMode.SWR:
                        comboTXTUNMeter.Text = "SWR";
                        break;
                    case MeterTXMode.OFF:
                        comboTXTUNMeter.Text = "Off";
                        break;
                }
            }
        }

        private void comboTXTUNMeter_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            switch (comboTXTUNMeter.Text)
            {
                case "Fwd Pwr":
                    console.TuneTXMeterMode = MeterTXMode.FORWARD_POWER;
                    break;
                case "Ref Pwr":
                    console.TuneTXMeterMode = MeterTXMode.REVERSE_POWER;
                    break;
                case "Fwd SWR": //MW0LGE re-added
                    console.TuneTXMeterMode = MeterTXMode.SWR_POWER;
                    break;
                case "SWR":
                    console.TuneTXMeterMode = MeterTXMode.SWR;
                    break;
                case "Off":
                    console.TuneTXMeterMode = MeterTXMode.OFF;
                    break;
            }
        }

        private void btnResetDB_Click(object sender, System.EventArgs e)
        {
        }

        private void chkDisplayMeterShowDecimal_CheckedChanged(object sender, System.EventArgs e)
        {
            console.MeterDetail = chkDisplayMeterShowDecimal.Checked;
        }

        private void chkRTTYOffsetEnableA_CheckedChanged(object sender, System.EventArgs e)
        {
            rtty_offset_enabled_a = chkRTTYOffsetEnableA.Checked;
        }

        private void chkRTTYOffsetEnableB_CheckedChanged(object sender, System.EventArgs e)
        {
            rtty_offset_enabled_b = chkRTTYOffsetEnableB.Checked;
        }

        private void udRTTYL_ValueChanged(object sender, System.EventArgs e)
        {
            rtty_offset_low = (int)udRTTYL.Value;
        }

        private void udRTTYU_ValueChanged(object sender, System.EventArgs e)
        {
            rtty_offset_high = (int)udRTTYU.Value;
        }

        private void chkRX2AutoMuteTX_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;

            console.MuteRX2OnVFOATX = chkRX2AutoMuteTX.Checked;
        }

        private void chkAudioIQtoVAC_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            bool power = console.PowerOn;
            if (power && chkAudioEnableVAC.Checked)
            {
                Audio.EnableVAC1(false);
            }

            Audio.VACOutputIQ = chkAudioIQtoVAC.Checked;

            if (power && chkAudioEnableVAC.Checked)
            {
                Audio.VACEnabled = chkAudioEnableVAC.Checked;
            }

            chkAudioCorrectIQ.Enabled = chkAudioIQtoVAC.Checked;
            chkAudioRX2toVAC.Enabled = chkAudioIQtoVAC.Checked;
            chkSwapIQVac1.Enabled = chkAudioIQtoVAC.Checked;
        }

        private void chkVAC2DirectIQ_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            bool power = console.PowerOn;
            if (power && chkVAC2Enable.Checked)
            {
                Audio.EnableVAC2(false);
            }

            Audio.VAC2OutputIQ = chkVAC2DirectIQ.Checked;

            if (power && chkVAC2Enable.Checked)
            {
                Audio.VAC2Enabled = chkVAC2Enable.Checked;
            }

            chkVAC2DirectIQCal.Enabled = chkVAC2DirectIQ.Checked;
            chkSwapIQVac2.Enabled = chkVAC2DirectIQ.Checked;
        }

        private void chkAudioCorrectIQ_CheckChanged(object sender, System.EventArgs e)
        {
            Audio.VACCorrectIQ = chkAudioCorrectIQ.Checked;
        }

        private void chkVAC2IQCal_CheckChanged(object sender, System.EventArgs e)
        {
            Audio.VAC2CorrectIQ = chkVAC2DirectIQCal.Checked;
        }

        private void chkRX2AutoMuteRX1OnVFOBTX_CheckedChanged(object sender, System.EventArgs e)
        {
            console.MuteRX1OnVFOBTX = chkRX2AutoMuteRX1OnVFOBTX.Checked;
        }

        private void chkRX1BlankDisplayOnVFOBTX_CheckedChanged(object sender, System.EventArgs e)
        {
            console.BlankRX1OnVFOBTX = chkRX1BlankDisplayOnVFOBTX.Checked;
        }

        private void chkRX2BlankDisplayOnVFOATX_CheckedChanged(object sender, System.EventArgs e)
        {
            console.BlankRX2OnVFOATX = chkRX2BlankDisplayOnVFOATX.Checked;
        }

        private void chkTXExpert_CheckedChanged(object sender, System.EventArgs e)
        {
            grpTXProfileDef.Visible = chkTXExpert.Checked;
        }

        private void btnTXProfileDefImport_Click(object sender, System.EventArgs e)
        {
            if (lstTXProfileDef.SelectedIndex < 0) return;

            DialogResult result = MessageBox.Show("Include this Additional TX profile in your profiles list?",
                "Include?",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Question);

            if (result == DialogResult.No)
                return;

            string name = lstTXProfileDef.Text;
            DataRow[] rows = DB.ds.Tables["TxProfileDef"].Select("Name = '" + name.Replace("'", "''") + "'"); //MW0LGE_21k9rc6 replace ' for ''

            if (rows.Length != 1)
            {
                MessageBox.Show("Database error reading TXProfileDef Table.",
                    "Database error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return;
            }

            DataRow dr = null;
            if (comboTXProfileName.Items.Contains(name))
            {
                result = MessageBox.Show(
                    "Are you sure you want to overwrite the " + name + " TX Profile?",
                    "Overwrite Profile?",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question);

                if (result == DialogResult.No)
                    return;

                foreach (DataRow d in DB.ds.Tables["TXProfile"].Rows)
                {
                    if ((string)d["Name"] == name)
                    {
                        dr = d;
                        break;
                    }
                }
            }
            else
            {
                dr = DB.ds.Tables["TXProfile"].NewRow();
                dr["Name"] = name;
            }

            for (int i = 0; i < dr.ItemArray.Length; i++)
                dr[i] = rows[0][i];

            if (!comboTXProfileName.Items.Contains(name))
            {
                DB.ds.Tables["TXProfile"].Rows.Add(dr);
                comboTXProfileName.Items.Add(name);
                comboTXProfileName.Text = name;
            }

            console.UpdateTXProfile(name);
        }

        //-W2PA Export a single TX Profile to send to someone else for importing.
        private void ExportCurrentTxProfile()
        {
            string fileName = current_profile;

            string invalid = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());
            foreach (char c in invalid)
            {
                fileName = fileName.Replace(c.ToString(), "_");  // Remove profile name chars that are invalid in filenames.
            }

            fileName = console.AppDataPath + fileName;

            int i = 1;
            string tempFN = fileName;
            while (File.Exists(tempFN + ".xml"))
            {
                tempFN = fileName + Convert.ToString(i);  // Get a slightly different file name if it already exists.
                i++;
            }
            fileName = tempFN + ".xml";

            DataRow[] rows = getDataRowsForTXProfile(current_profile);// DB.ds.Tables["TXProfile"].Select("Name = '" + current_profile.Replace("'", "''") + "'"); //MW0LGE_21k9rc6 replace ' for ''
            DataRow exportRow = null;
            if (rows.Length > 0)
            {
                exportRow = rows[0];
            }
            else
            {
                MessageBox.Show("Can not locate " + current_profile + ".",  // This should never happen.
                    "Profile error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return;
            }

            DataSet exDS = DB.ds.Clone();

            //[2.10.3.6]MW0LGE drop all non important table schema
            List<string> table_names = new List<string>();
            foreach (DataTable dt in exDS.Tables) 
            {
                if(dt.TableName != "TXProfile")
                    table_names.Add(dt.TableName);
            }
            foreach(string table_name in table_names)
            {
                exDS.Tables.Remove(table_name);
            }
            //

            DataTable pTable = pTable = DB.ds.Tables["TXProfile"].Clone();
            pTable.ImportRow(exportRow);
            exDS.Merge(pTable);

            try
            {
                exDS.WriteXml(fileName, XmlWriteMode.WriteSchema); // Writing with schema is necessary for import
            }
            catch
            {
                MessageBox.Show("Can not write " + fileName + ".",
                    "Export error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return;
            }

            MessageBox.Show("Profile" + current_profile + " has been saved in file " + fileName,
                    "Done",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
        }

        private void Setup_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (e.Control == true && e.Alt == true)
            {
                switch (e.KeyCode)
                {
                    case Keys.A:
                        chkPANewCal.Visible = true;
                        chkAutoPACalibrate.Visible = true; //MW0LGE_22b
                        break;
                    case Keys.O:
                        break;
                    case Keys.P:
                        chkAutoPACalibrate.Visible = true;
                        break;
                }
            }
        }
        public bool DisplayPanFill
        {
            get { return chkDisplayPanFill.Checked; }
            set { chkDisplayPanFill.Checked = value; }
        }
        private void chkDisplayPanFill_CheckedChanged(object sender, System.EventArgs e)
        {
            Display.PanFill = chkDisplayPanFill.Checked;

            console.SetupInfoBarButton(ucInfoBar.ActionTypes.DisplayFill, Display.PanFill);
        }

        private void chkTXPanFill_CheckedChanged(object sender, System.EventArgs e)
        {
            Display.TXPanFill = chkTXPanFill.Checked;
        }

        private bool _skinChanging = false;
        private void comboAppSkin_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing || _skinChanging) return;  // prevents call on getoptions, need to force call after options loaded MW0LGE 

            _skinChanging = true;

            Cursor c = Cursor.Current;
            Cursor.Current = Cursors.WaitCursor;

            string path = ".\\Skins\\";
            if (!Directory.Exists(path + comboAppSkin.Text))
                path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
                        "\\OpenHPSDR\\Skins";

            if (_skinPath == "") _skinPath = path;

            if (Directory.Exists(_skinPath + "\\" + comboAppSkin.Text))
            {
                Skin.Restore(comboAppSkin.Text, _skinPath, console);
                console.UpdateAndromedaSkins();
            }

            console.CurrentSkin = comboAppSkin.Text;
            console.RadarColorUpdate = true;
            MeterManager.CurrentSkin = comboAppSkin.Text;

#if SNOWFALL
            string sSkinNameLower = comboAppSkin.Text.ToLower();
            Display.SnowFall = sSkinNameLower.Contains("xmas") || sSkinNameLower.Contains("christmas") || sSkinNameLower.Contains("x-mas") ||
                               sSkinNameLower.Contains("snow") || sSkinNameLower.Contains("flakes") || sSkinNameLower.Contains("winter");
#endif

            Cursor.Current = c;

            _skinChanging = false;
        }

        private void btnSkinExport_Click(object sender, EventArgs e)
        {

            string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
                    "\\OpenHPSDR\\Skins\\";

            if (Directory.Exists(path + comboAppSkin.Text))
                Skin.Save(comboAppSkin.Text, path, console);
        }

        private void chkCWDisableUI_CheckedChanged(object sender, EventArgs e)
        {
            console.DisableUIMOXChanges = chkCWDisableUI.Checked;
        }

        private void chkAudioRX2toVAC_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Audio.VACOutputRX2 = chkAudioRX2toVAC.Checked;
        }

        private void chkVAC2UseRX2_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.VAC2RX2 = chkVAC2UseRX2.Checked;
        }

        private void tbRX1FilterAlpha_Scroll(object sender, EventArgs e)
        {
            clrbtnFilter_Changed(this, EventArgs.Empty);
            toolTip1.SetToolTip(tbRX1FilterAlpha, tbRX1FilterAlpha.Value.ToString());
        }

        private void tbTXFilterAlpha_Scroll(object sender, EventArgs e)
        {
            clrbtnGridTXFilter_Changed(this, EventArgs.Empty);
            toolTip1.SetToolTip(tbTXFilterAlpha, tbTXFilterAlpha.Value.ToString());
        }

        private void tbMultiRXFilterAlpha_Scroll(object sender, EventArgs e)
        {
            clrbtnSubRXFilter_Changed(this, EventArgs.Empty);
            toolTip1.SetToolTip(tbMultiRXFilterAlpha, tbMultiRXFilterAlpha.Value.ToString());
        }

        public static Color DisplayGrayLineColor = Color.FromArgb(70, Color.Black); // ke9ns add default value
        public void clrbtnGrayLine_Changed(object sender, EventArgs e)
        {
            DisplayGrayLineColor = Color.FromArgb(tbGrayLineAlpha.Value, clrbtnGrayLine.Color);

        }

        public void tbGrayLineAlpha_Scroll(object sender, EventArgs e)
        {
            clrbtnGrayLine_Changed(this, EventArgs.Empty);
        }

        private void chkWheelTuneVFOB_CheckedChanged(object sender, EventArgs e)
        {
            console.WheelTunesVFOB = chkWheelTuneVFOB.Checked;
        }
        private void chkPennyLane_CheckedChanged(object sender, System.EventArgs e)
        {
        }

        private void chkPennyPresent_CheckedChanged(object sender, System.EventArgs e)
        {
        }

        private void checkHPSDRDefaults(object sender, System.EventArgs e)
        {
        }

        private void chkMercuryPresent_CheckedChanged(object sender, System.EventArgs e)
        {
            console.MercuryPresent = true;
        }

        private void chkAlexPresent_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            if (chkAlexPresent.Checked)
            {
                chkAlexAntCtrl.Enabled = true;
                chkAlexAntCtrl.Checked = true;
                grpAlexAntCtrl.Enabled = true; //MW0LGE_21a

                if (chkApolloPresent.Checked) chkApolloPresent.Checked = false;
            }
            else
            {
                chkAlexAntCtrl.Checked = false;
                chkAlexAntCtrl.Enabled = false;
                grpAlexAntCtrl.Enabled = false;
            }

            console.AlexPresent = chkAlexPresent.Checked;
            console.SetComboPreampForHPSDR();

            udHermesStepAttenuatorData_ValueChanged(this, EventArgs.Empty);
        }

        public byte BandBBitMask = 0x70; // 4x3 split
        private void UpdateOCBits()
        {
            chkPenOCrcv160_CheckedChanged(this, EventArgs.Empty);
            chkPenOCxmit160_CheckedChanged(this, EventArgs.Empty);
            chkPenOCrcv80_CheckedChanged(this, EventArgs.Empty);
            chkPenOCxmit80_CheckedChanged(this, EventArgs.Empty);
            chkPenOCrcv60_CheckedChanged(this, EventArgs.Empty);
            chkPenOCxmit60_CheckedChanged(this, EventArgs.Empty);
            chkPenOCrcv40_CheckedChanged(this, EventArgs.Empty);
            chkPenOCxmit40_CheckedChanged(this, EventArgs.Empty);
            chkPenOCrcv30_CheckedChanged(this, EventArgs.Empty);
            chkPenOCxmit30_CheckedChanged(this, EventArgs.Empty);
            chkPenOCrcv20_CheckedChanged(this, EventArgs.Empty);
            chkPenOCxmit20_CheckedChanged(this, EventArgs.Empty);
            chkPenOCrcv17_CheckedChanged(this, EventArgs.Empty);
            chkPenOCxmit17_CheckedChanged(this, EventArgs.Empty);
            chkPenOCrcv15_CheckedChanged(this, EventArgs.Empty);
            chkPenOCxmit15_CheckedChanged(this, EventArgs.Empty);
            chkPenOCrcv12_CheckedChanged(this, EventArgs.Empty);
            chkPenOCxmit12_CheckedChanged(this, EventArgs.Empty);
            chkPenOCrcv10_CheckedChanged(this, EventArgs.Empty);
            chkPenOCxmit10_CheckedChanged(this, EventArgs.Empty);
            chkPenOCrcv6_CheckedChanged(this, EventArgs.Empty);
            chkPenOCxmit6_CheckedChanged(this, EventArgs.Empty);
            chkPenOCrcv2_CheckedChanged(this, EventArgs.Empty);
            chkPenOCxmit2_CheckedChanged(this, EventArgs.Empty);
        }

        private void chkPenOCrcv160_CheckedChanged(object sender, System.EventArgs e)
        {
            int val = 0;
            if (chkPenOCrcv1601.Checked) val += 1 << 0;
            if (chkPenOCrcv1602.Checked) val += 1 << 1;
            if (chkPenOCrcv1603.Checked) val += 1 << 2;
            if (chkPenOCrcv1604.Checked) val += 1 << 3;
            if (chkPenOCrcv1605.Checked) val += 1 << 4;
            if (chkPenOCrcv1606.Checked) val += 1 << 5;
            if (chkPenOCrcv1607.Checked) val += 1 << 6;

            Penny.getPenny().setBandABitMask(Band.B160M, (byte)val, false);
            Penny.getPenny().setBandBBitMask(Band.B160M, (byte)(val & BandBBitMask), false); // 000 xxxx 0x70  000 0xxx 0x78
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCxmit160_CheckedChanged(object sender, System.EventArgs e)
        {
            int val = 0;
            if (chkPenOCxmit1601.Checked) val += 1 << 0;
            if (chkPenOCxmit1602.Checked) val += 1 << 1;
            if (chkPenOCxmit1603.Checked) val += 1 << 2;
            if (chkPenOCxmit1604.Checked) val += 1 << 3;
            if (chkPenOCxmit1605.Checked) val += 1 << 4;
            if (chkPenOCxmit1606.Checked) val += 1 << 5;
            if (chkPenOCxmit1607.Checked) val += 1 << 6;

            Penny.getPenny().setBandABitMask(Band.B160M, (byte)val, true);
            Penny.getPenny().setBandBBitMask(Band.B160M, (byte)(val & BandBBitMask), true); // 0000xxx
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCrcv80_CheckedChanged(object sender, System.EventArgs e)
        {
            int val = 0;
            if (chkPenOCrcv801.Checked) val += 1 << 0;
            if (chkPenOCrcv802.Checked) val += 1 << 1;
            if (chkPenOCrcv803.Checked) val += 1 << 2;
            if (chkPenOCrcv804.Checked) val += 1 << 3;
            if (chkPenOCrcv805.Checked) val += 1 << 4;
            if (chkPenOCrcv806.Checked) val += 1 << 5;
            if (chkPenOCrcv807.Checked) val += 1 << 6;

            Penny.getPenny().setBandABitMask(Band.B80M, (byte)val, false);
            Penny.getPenny().setBandBBitMask(Band.B80M, (byte)(val & BandBBitMask), false); // 0000xxx
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCxmit80_CheckedChanged(object sender, System.EventArgs e)
        {
            int val = 0;
            if (chkPenOCxmit801.Checked) val += 1 << 0;
            if (chkPenOCxmit802.Checked) val += 1 << 1;
            if (chkPenOCxmit803.Checked) val += 1 << 2;
            if (chkPenOCxmit804.Checked) val += 1 << 3;
            if (chkPenOCxmit805.Checked) val += 1 << 4;
            if (chkPenOCxmit806.Checked) val += 1 << 5;
            if (chkPenOCxmit807.Checked) val += 1 << 6;

            Penny.getPenny().setBandABitMask(Band.B80M, (byte)val, true);
            Penny.getPenny().setBandBBitMask(Band.B80M, (byte)(val & BandBBitMask), true); // 0000xxx
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCrcv60_CheckedChanged(object sender, System.EventArgs e)
        {
            int val = 0;
            if (chkPenOCrcv601.Checked) val += 1 << 0;
            if (chkPenOCrcv602.Checked) val += 1 << 1;
            if (chkPenOCrcv603.Checked) val += 1 << 2;
            if (chkPenOCrcv604.Checked) val += 1 << 3;
            if (chkPenOCrcv605.Checked) val += 1 << 4;
            if (chkPenOCrcv606.Checked) val += 1 << 5;
            if (chkPenOCrcv607.Checked) val += 1 << 6;

            Penny.getPenny().setBandABitMask(Band.B60M, (byte)val, false);
            Penny.getPenny().setBandBBitMask(Band.B60M, (byte)(val & BandBBitMask), false); // 0000xxx
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCxmit60_CheckedChanged(object sender, System.EventArgs e)
        {
            int val = 0;
            if (chkPenOCxmit601.Checked) val += 1 << 0;
            if (chkPenOCxmit602.Checked) val += 1 << 1;
            if (chkPenOCxmit603.Checked) val += 1 << 2;
            if (chkPenOCxmit604.Checked) val += 1 << 3;
            if (chkPenOCxmit605.Checked) val += 1 << 4;
            if (chkPenOCxmit606.Checked) val += 1 << 5;
            if (chkPenOCxmit607.Checked) val += 1 << 6;

            Penny.getPenny().setBandABitMask(Band.B60M, (byte)val, true);
            Penny.getPenny().setBandBBitMask(Band.B60M, (byte)(val & BandBBitMask), true); // 0000xxx
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCrcv40_CheckedChanged(object sender, System.EventArgs e)
        {

            int val = 0;
            if (chkPenOCrcv401.Checked) val += 1 << 0;
            if (chkPenOCrcv402.Checked) val += 1 << 1;
            if (chkPenOCrcv403.Checked) val += 1 << 2;
            if (chkPenOCrcv404.Checked) val += 1 << 3;
            if (chkPenOCrcv405.Checked) val += 1 << 4;
            if (chkPenOCrcv406.Checked) val += 1 << 5;
            if (chkPenOCrcv407.Checked) val += 1 << 6;

            Penny.getPenny().setBandABitMask(Band.B40M, (byte)val, false);
            Penny.getPenny().setBandBBitMask(Band.B40M, (byte)(val & BandBBitMask), false); // 0000xxx
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCxmit40_CheckedChanged(object sender, System.EventArgs e)
        {

            int val = 0;
            if (chkPenOCxmit401.Checked) val += 1 << 0;
            if (chkPenOCxmit402.Checked) val += 1 << 1;
            if (chkPenOCxmit403.Checked) val += 1 << 2;
            if (chkPenOCxmit404.Checked) val += 1 << 3;
            if (chkPenOCxmit405.Checked) val += 1 << 4;
            if (chkPenOCxmit406.Checked) val += 1 << 5;
            if (chkPenOCxmit407.Checked) val += 1 << 6;

            Penny.getPenny().setBandABitMask(Band.B40M, (byte)val, true);
            Penny.getPenny().setBandBBitMask(Band.B40M, (byte)(val & BandBBitMask), true); // 0000xxx
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCrcv30_CheckedChanged(object sender, System.EventArgs e)
        {

            int val = 0;
            if (chkPenOCrcv301.Checked) val += 1 << 0;
            if (chkPenOCrcv302.Checked) val += 1 << 1;
            if (chkPenOCrcv303.Checked) val += 1 << 2;
            if (chkPenOCrcv304.Checked) val += 1 << 3;
            if (chkPenOCrcv305.Checked) val += 1 << 4;
            if (chkPenOCrcv306.Checked) val += 1 << 5;
            if (chkPenOCrcv307.Checked) val += 1 << 6;

            Penny.getPenny().setBandABitMask(Band.B30M, (byte)val, false);
            Penny.getPenny().setBandBBitMask(Band.B30M, (byte)(val & BandBBitMask), false); // 0000xxx
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCxmit30_CheckedChanged(object sender, System.EventArgs e)
        {

            int val = 0;
            if (chkPenOCxmit301.Checked) val += 1 << 0;
            if (chkPenOCxmit302.Checked) val += 1 << 1;
            if (chkPenOCxmit303.Checked) val += 1 << 2;
            if (chkPenOCxmit304.Checked) val += 1 << 3;
            if (chkPenOCxmit305.Checked) val += 1 << 4;
            if (chkPenOCxmit306.Checked) val += 1 << 5;
            if (chkPenOCxmit307.Checked) val += 1 << 6;

            Penny.getPenny().setBandABitMask(Band.B30M, (byte)val, true);
            Penny.getPenny().setBandBBitMask(Band.B30M, (byte)(val & BandBBitMask), true); // 0000xxx
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCrcv20_CheckedChanged(object sender, System.EventArgs e)
        {

            int val = 0;
            if (chkPenOCrcv201.Checked) val += 1 << 0;
            if (chkPenOCrcv202.Checked) val += 1 << 1;
            if (chkPenOCrcv203.Checked) val += 1 << 2;
            if (chkPenOCrcv204.Checked) val += 1 << 3;
            if (chkPenOCrcv205.Checked) val += 1 << 4;
            if (chkPenOCrcv206.Checked) val += 1 << 5;
            if (chkPenOCrcv207.Checked) val += 1 << 6;

            Penny.getPenny().setBandABitMask(Band.B20M, (byte)val, false);
            Penny.getPenny().setBandBBitMask(Band.B20M, (byte)(val & BandBBitMask), false); // 0000xxx
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCxmit20_CheckedChanged(object sender, System.EventArgs e)
        {

            int val = 0;
            if (chkPenOCxmit201.Checked) val += 1 << 0;
            if (chkPenOCxmit202.Checked) val += 1 << 1;
            if (chkPenOCxmit203.Checked) val += 1 << 2;
            if (chkPenOCxmit204.Checked) val += 1 << 3;
            if (chkPenOCxmit205.Checked) val += 1 << 4;
            if (chkPenOCxmit206.Checked) val += 1 << 5;
            if (chkPenOCxmit207.Checked) val += 1 << 6;

            Penny.getPenny().setBandABitMask(Band.B20M, (byte)val, true);
            Penny.getPenny().setBandBBitMask(Band.B20M, (byte)(val & BandBBitMask), true); // 0000xxx
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCrcv17_CheckedChanged(object sender, System.EventArgs e)
        {

            int val = 0;
            if (chkPenOCrcv171.Checked) val += 1 << 0;
            if (chkPenOCrcv172.Checked) val += 1 << 1;
            if (chkPenOCrcv173.Checked) val += 1 << 2;
            if (chkPenOCrcv174.Checked) val += 1 << 3;
            if (chkPenOCrcv175.Checked) val += 1 << 4;
            if (chkPenOCrcv176.Checked) val += 1 << 5;
            if (chkPenOCrcv177.Checked) val += 1 << 6;

            Penny.getPenny().setBandABitMask(Band.B17M, (byte)val, false);
            Penny.getPenny().setBandBBitMask(Band.B17M, (byte)(val & BandBBitMask), false); // 0000xxx
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCxmit17_CheckedChanged(object sender, System.EventArgs e)
        {

            int val = 0;
            if (chkPenOCxmit171.Checked) val += 1 << 0;
            if (chkPenOCxmit172.Checked) val += 1 << 1;
            if (chkPenOCxmit173.Checked) val += 1 << 2;
            if (chkPenOCxmit174.Checked) val += 1 << 3;
            if (chkPenOCxmit175.Checked) val += 1 << 4;
            if (chkPenOCxmit176.Checked) val += 1 << 5;
            if (chkPenOCxmit177.Checked) val += 1 << 6;

            Penny.getPenny().setBandABitMask(Band.B17M, (byte)val, true);
            Penny.getPenny().setBandBBitMask(Band.B17M, (byte)(val & BandBBitMask), true); // 0000xxx
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCrcv15_CheckedChanged(object sender, System.EventArgs e)
        {

            int val = 0;
            if (chkPenOCrcv151.Checked) val += 1 << 0;
            if (chkPenOCrcv152.Checked) val += 1 << 1;
            if (chkPenOCrcv153.Checked) val += 1 << 2;
            if (chkPenOCrcv154.Checked) val += 1 << 3;
            if (chkPenOCrcv155.Checked) val += 1 << 4;
            if (chkPenOCrcv156.Checked) val += 1 << 5;
            if (chkPenOCrcv157.Checked) val += 1 << 6;

            Penny.getPenny().setBandABitMask(Band.B15M, (byte)val, false);
            Penny.getPenny().setBandBBitMask(Band.B15M, (byte)(val & BandBBitMask), false); // 0000xxx
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCxmit15_CheckedChanged(object sender, System.EventArgs e)
        {
            int val = 0;
            if (chkPenOCxmit151.Checked) val += 1 << 0;
            if (chkPenOCxmit152.Checked) val += 1 << 1;
            if (chkPenOCxmit153.Checked) val += 1 << 2;
            if (chkPenOCxmit154.Checked) val += 1 << 3;
            if (chkPenOCxmit155.Checked) val += 1 << 4;
            if (chkPenOCxmit156.Checked) val += 1 << 5;
            if (chkPenOCxmit157.Checked) val += 1 << 6;

            Penny.getPenny().setBandABitMask(Band.B15M, (byte)val, true);
            Penny.getPenny().setBandBBitMask(Band.B15M, (byte)(val & BandBBitMask), true); // 0000xxx
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 

        }


        private void chkPenOCrcv12_CheckedChanged(object sender, System.EventArgs e)
        {

            int val = 0;
            if (chkPenOCrcv121.Checked) val += 1 << 0;
            if (chkPenOCrcv122.Checked) val += 1 << 1;
            if (chkPenOCrcv123.Checked) val += 1 << 2;
            if (chkPenOCrcv124.Checked) val += 1 << 3;
            if (chkPenOCrcv125.Checked) val += 1 << 4;
            if (chkPenOCrcv126.Checked) val += 1 << 5;
            if (chkPenOCrcv127.Checked) val += 1 << 6;

            Penny.getPenny().setBandABitMask(Band.B12M, (byte)val, false);
            Penny.getPenny().setBandBBitMask(Band.B12M, (byte)(val & BandBBitMask), false); // 0000xxx
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCxmit12_CheckedChanged(object sender, System.EventArgs e)
        {

            int val = 0;
            if (chkPenOCxmit121.Checked) val += 1 << 0;
            if (chkPenOCxmit122.Checked) val += 1 << 1;
            if (chkPenOCxmit123.Checked) val += 1 << 2;
            if (chkPenOCxmit124.Checked) val += 1 << 3;
            if (chkPenOCxmit125.Checked) val += 1 << 4;
            if (chkPenOCxmit126.Checked) val += 1 << 5;
            if (chkPenOCxmit127.Checked) val += 1 << 6;

            Penny.getPenny().setBandABitMask(Band.B12M, (byte)val, true);
            Penny.getPenny().setBandBBitMask(Band.B12M, (byte)(val & BandBBitMask), true); // 0000xxx
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCrcv10_CheckedChanged(object sender, System.EventArgs e)
        {

            int val = 0;
            if (chkPenOCrcv101.Checked) val += 1 << 0;
            if (chkPenOCrcv102.Checked) val += 1 << 1;
            if (chkPenOCrcv103.Checked) val += 1 << 2;
            if (chkPenOCrcv104.Checked) val += 1 << 3;
            if (chkPenOCrcv105.Checked) val += 1 << 4;
            if (chkPenOCrcv106.Checked) val += 1 << 5;
            if (chkPenOCrcv107.Checked) val += 1 << 6;

            Penny.getPenny().setBandABitMask(Band.B10M, (byte)val, false);
            Penny.getPenny().setBandBBitMask(Band.B10M, (byte)(val & BandBBitMask), false); // 0000xxx
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCxmit10_CheckedChanged(object sender, System.EventArgs e)
        {

            int val = 0;
            if (chkPenOCxmit101.Checked) val += 1 << 0;
            if (chkPenOCxmit102.Checked) val += 1 << 1;
            if (chkPenOCxmit103.Checked) val += 1 << 2;
            if (chkPenOCxmit104.Checked) val += 1 << 3;
            if (chkPenOCxmit105.Checked) val += 1 << 4;
            if (chkPenOCxmit106.Checked) val += 1 << 5;
            if (chkPenOCxmit107.Checked) val += 1 << 6;

            Penny.getPenny().setBandABitMask(Band.B10M, (byte)val, true);
            Penny.getPenny().setBandBBitMask(Band.B10M, (byte)(val & BandBBitMask), true); // 0000xxx
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }


        private void chkPenOCrcv6_CheckedChanged(object sender, System.EventArgs e)
        {

            int val = 0;
            if (chkPenOCrcv61.Checked) val += 1 << 0;
            if (chkPenOCrcv62.Checked) val += 1 << 1;
            if (chkPenOCrcv63.Checked) val += 1 << 2;
            if (chkPenOCrcv64.Checked) val += 1 << 3;
            if (chkPenOCrcv65.Checked) val += 1 << 4;
            if (chkPenOCrcv66.Checked) val += 1 << 5;
            if (chkPenOCrcv67.Checked) val += 1 << 6;

            Penny.getPenny().setBandABitMask(Band.B6M, (byte)val, false);
            Penny.getPenny().setBandBBitMask(Band.B6M, (byte)(val & BandBBitMask), false); // 0000xxx
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCxmit6_CheckedChanged(object sender, System.EventArgs e)
        {

            int val = 0;
            if (chkPenOCxmit61.Checked) val += 1 << 0;
            if (chkPenOCxmit62.Checked) val += 1 << 1;
            if (chkPenOCxmit63.Checked) val += 1 << 2;
            if (chkPenOCxmit64.Checked) val += 1 << 3;
            if (chkPenOCxmit65.Checked) val += 1 << 4;
            if (chkPenOCxmit66.Checked) val += 1 << 5;
            if (chkPenOCxmit67.Checked) val += 1 << 6;

            Penny.getPenny().setBandABitMask(Band.B6M, (byte)val, true);
            Penny.getPenny().setBandBBitMask(Band.B6M, (byte)(val & BandBBitMask), true); // 0000xxx
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCrcv2_CheckedChanged(object sender, System.EventArgs e)
        {

            int val = 0;
            if (chkPenOCrcv21.Checked) val += 1 << 0;
            if (chkPenOCrcv22.Checked) val += 1 << 1;
            if (chkPenOCrcv23.Checked) val += 1 << 2;
            if (chkPenOCrcv24.Checked) val += 1 << 3;
            if (chkPenOCrcv25.Checked) val += 1 << 4;
            if (chkPenOCrcv26.Checked) val += 1 << 5;
            if (chkPenOCrcv27.Checked) val += 1 << 6;

            Penny.getPenny().setBandABitMask(Band.B2M, (byte)val, false);
            Penny.getPenny().setBandBBitMask(Band.B2M, (byte)(val & BandBBitMask), false); // 0000xxx
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCxmit2_CheckedChanged(object sender, System.EventArgs e)
        {

            int val = 0;
            if (chkPenOCxmit21.Checked) val += 1 << 0;
            if (chkPenOCxmit22.Checked) val += 1 << 1;
            if (chkPenOCxmit23.Checked) val += 1 << 2;
            if (chkPenOCxmit24.Checked) val += 1 << 3;
            if (chkPenOCxmit25.Checked) val += 1 << 4;
            if (chkPenOCxmit26.Checked) val += 1 << 5;
            if (chkPenOCxmit27.Checked) val += 1 << 6;

            Penny.getPenny().setBandABitMask(Band.B2M, (byte)val, true);
            Penny.getPenny().setBandBBitMask(Band.B2M, (byte)(val & BandBBitMask), true); // 0000xxx
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPennyExtCtrl_CheckedChanged(object sender, System.EventArgs e)
        {
            grpPennyExtCtrl.Enabled = chkPennyExtCtrl.Checked;
            grpPennyExtCtrlVHF.Enabled = chkPennyExtCtrl.Checked;
            grpExtCtrlSWL.Enabled = chkPennyExtCtrl.Checked;
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;
        }

        private void chkAlexAntCtrl_CheckedChanged(object sender, System.EventArgs e)
        {
            grpAlexAntCtrl.Enabled = true;
            console.AlexAntCtrlEnabled = chkAlexAntCtrl.Checked;

            panelAlexRXAntControl.Enabled = true;
        }

        private void chkMercDither_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            int v = chkMercDither.Checked ? 1 : 0;
            NetworkIO.SetADCDither(v);
        }

        private void chkMercRandom_CheckedChanged(object sender, System.EventArgs e)
        {
            if (initializing) return;
            int v = chkMercRandom.Checked ? 1 : 0;
            NetworkIO.SetADCRandom(v);
        }

        private RadioButtonTS[][] _AlexRxAntButtons = null;
        private RadioButtonTS[][] _AlexTxAntButtons = null;
        private CheckBoxTS[][] _AlexRxOnlyAntCheckBoxes = null;

        private bool[][] _AlexRxAntButtons_old = null;
        private bool[][] _AlexTxAntButtons_old = null;
        private bool[][] _AlexRxOnlyAntCheckBoxes_old = null;
        private bool _tx_antenna_2_old;
        private bool _tx_antenna_3_old;

        private void InitAlexAntTables()
        {
            _tx_antenna_2_old = false;
            _tx_antenna_3_old = false;

            _AlexRxOnlyAntCheckBoxes = new[] { new CheckBoxTS[]  { chkAlex160R1, chkAlex160R2, chkAlex160XV },
                                                            new[] { chkAlex80R1, chkAlex80R2, chkAlex80XV },
                                                            new[] { chkAlex60R1, chkAlex60R2, chkAlex60XV },
                                                            new[] { chkAlex40R1, chkAlex40R2, chkAlex40XV },
                                                            new[] { chkAlex30R1, chkAlex30R2, chkAlex30XV },
                                                            new[] { chkAlex20R1, chkAlex20R2, chkAlex20XV },
                                                            new[] { chkAlex17R1, chkAlex17R2, chkAlex17XV },
                                                            new[] { chkAlex15R1, chkAlex15R2, chkAlex15XV },
                                                            new[] { chkAlex12R1, chkAlex12R2, chkAlex12XV },
                                                            new[] { chkAlex10R1, chkAlex10R2, chkAlex10XV },
                                                            new[] { chkAlex6R1, chkAlex6R2, chkAlex6XV }
                                                     };


            _AlexRxAntButtons = new[] { new RadioButtonTS[] { radAlexR1_160,  radAlexR2_160, radAlexR3_160 },
                                                         new[] { radAlexR1_80,  radAlexR2_80, radAlexR3_80 },
                                                         new[] { radAlexR1_60,  radAlexR2_60, radAlexR3_60 },
                                                         new[] { radAlexR1_40,  radAlexR2_40, radAlexR3_40 },
                                                         new[] { radAlexR1_30,  radAlexR2_30, radAlexR3_30 },
                                                         new[] { radAlexR1_20,  radAlexR2_20, radAlexR3_20 },
                                                         new[] { radAlexR1_17,  radAlexR2_17, radAlexR3_17 },
                                                         new[] { radAlexR1_15,  radAlexR2_15, radAlexR3_15 },
                                                         new[] { radAlexR1_12,  radAlexR2_12, radAlexR3_12 },
                                                         new[] { radAlexR1_10,  radAlexR2_10, radAlexR3_10 },
                                                         new[] { radAlexR1_6,  radAlexR2_6, radAlexR3_6 }
                                                     };

            _AlexTxAntButtons = new[] { new RadioButtonTS[] { radAlexT1_160, radAlexT2_160, radAlexT3_160 },
                                                         new[] { radAlexT1_80,  radAlexT2_80, radAlexT3_80 },
                                                         new[] { radAlexT1_60,  radAlexT2_60, radAlexT3_60 },
                                                         new[] { radAlexT1_40,  radAlexT2_40, radAlexT3_40 },
                                                         new[] { radAlexT1_30,  radAlexT2_30, radAlexT3_30 },
                                                         new[] { radAlexT1_20,  radAlexT2_20, radAlexT3_20 },
                                                         new[] { radAlexT1_17,  radAlexT2_17, radAlexT3_17 },
                                                         new[] { radAlexT1_15,  radAlexT2_15, radAlexT3_15 },
                                                         new[] { radAlexT1_12,  radAlexT2_12, radAlexT3_12 },
                                                         new[] { radAlexT1_10,  radAlexT2_10, radAlexT3_10 },
                                                         new[] { radAlexT1_6,  radAlexT2_6, radAlexT3_6 }
                                                     };

            // old state copy
            _AlexRxOnlyAntCheckBoxes_old = new[] { new bool[]  { false, false, false },
                                                            new bool[] { false, false, false },
                                                            new bool[] { false, false, false },
                                                            new bool[] { false, false, false },
                                                            new bool[] { false, false, false },
                                                            new bool[] { false, false, false },
                                                            new bool[] { false, false, false },
                                                            new bool[] { false, false, false },
                                                            new bool[] { false, false, false },
                                                            new bool[] { false, false, false },
                                                            new bool[] { false, false, false }
                                                     };


            _AlexRxAntButtons_old = new[] { new bool[]  { false, false, false },
                                                            new bool[] { false, false, false },
                                                            new bool[] { false, false, false },
                                                            new bool[] { false, false, false },
                                                            new bool[] { false, false, false },
                                                            new bool[] { false, false, false },
                                                            new bool[] { false, false, false },
                                                            new bool[] { false, false, false },
                                                            new bool[] { false, false, false },
                                                            new bool[] { false, false, false },
                                                            new bool[] { false, false, false }
                                                     };

            _AlexTxAntButtons_old = new[] { new bool[]  { false, false, false },
                                                            new bool[] { false, false, false },
                                                            new bool[] { false, false, false },
                                                            new bool[] { false, false, false },
                                                            new bool[] { false, false, false },
                                                            new bool[] { false, false, false },
                                                            new bool[] { false, false, false },
                                                            new bool[] { false, false, false },
                                                            new bool[] { false, false, false },
                                                            new bool[] { false, false, false },
                                                            new bool[] { false, false, false }
                                                     };
        }

        public bool SetAlexAntEnabled(bool state)
        {
            bool orig_state = grpAlexAntCtrl.Enabled;
            grpAlexAntCtrl.Enabled = state;
            return orig_state;
        }

        private void radAlexR_160_CheckedChanged(object sender, System.EventArgs e)
        {
            if (radAlexR2_160.Checked)
            {
                if (chkBlockTxAnt2.Checked)
                {
                    if (radAlexT2_160.Checked) radAlexT1_160.Checked = true;
                    radAlexT2_160.Enabled = false;
                }
                else radAlexT2_160.Enabled = true;
            }
            else radAlexT2_160.Enabled = true;

            if (radAlexR3_160.Checked)
            {
                if (chkBlockTxAnt3.Checked)
                {
                    if (radAlexT3_160.Checked) radAlexT1_160.Checked = true;
                    radAlexT3_160.Enabled = false;
                }
                else radAlexT3_160.Enabled = true;
            }
            else radAlexT3_160.Enabled = true;

            ProcessAlexAntRadioButton(sender, Band.B160M, false);
        }

        private void radAlexR_80_CheckedChanged(object sender, System.EventArgs e)
        {
            if (radAlexR2_80.Checked)
            {
                if (chkBlockTxAnt2.Checked)
                {
                    if (radAlexT2_80.Checked) radAlexT1_80.Checked = true;
                    radAlexT2_80.Enabled = false;
                }
                else radAlexT2_80.Enabled = true;
            }
            else radAlexT2_80.Enabled = true;

            if (radAlexR3_80.Checked)
            {
                if (chkBlockTxAnt3.Checked)
                {
                    if (radAlexT3_80.Checked) radAlexT1_80.Checked = true;
                    radAlexT3_80.Enabled = false;
                }
                else radAlexT3_80.Enabled = true;
            }
            else radAlexT3_80.Enabled = true;

            ProcessAlexAntRadioButton(sender, Band.B80M, false);
        }

        private void radAlexR_60_CheckedChanged(object sender, System.EventArgs e)
        {
            if (radAlexR2_60.Checked)
            {
                if (chkBlockTxAnt2.Checked)
                {
                    if (radAlexT2_60.Checked) radAlexT1_60.Checked = true;
                    radAlexT2_60.Enabled = false;
                }
                else radAlexT2_60.Enabled = true;
            }
            else radAlexT2_60.Enabled = true;

            if (radAlexR3_60.Checked)
            {
                if (chkBlockTxAnt3.Checked)
                {
                    if (radAlexT3_60.Checked) radAlexT1_60.Checked = true;
                    radAlexT3_60.Enabled = false;
                }
                else radAlexT3_60.Enabled = true;
            }
            else radAlexT3_60.Enabled = true;

            ProcessAlexAntRadioButton(sender, Band.B60M, false);
        }

        private void radAlexR_40_CheckedChanged(object sender, System.EventArgs e)
        {
            if (radAlexR2_40.Checked)
            {
                if (chkBlockTxAnt2.Checked)
                {
                    if (radAlexT2_40.Checked) radAlexT1_40.Checked = true;
                    radAlexT2_40.Enabled = false;
                }
                else radAlexT2_40.Enabled = true;
            }
            else radAlexT2_40.Enabled = true;

            if (radAlexR3_40.Checked)
            {
                if (chkBlockTxAnt3.Checked)
                {
                    if (radAlexT3_40.Checked) radAlexT1_40.Checked = true;
                    radAlexT3_40.Enabled = false;
                }
                else radAlexT3_40.Enabled = true;
            }
            else radAlexT3_40.Enabled = true;

            ProcessAlexAntRadioButton(sender, Band.B40M, false);
        }

        private void radAlexR_30_CheckedChanged(object sender, System.EventArgs e)
        {
            if (radAlexR2_30.Checked)
            {
                if (chkBlockTxAnt2.Checked)
                {
                    if (radAlexT2_30.Checked) radAlexT1_30.Checked = true;
                    radAlexT2_30.Enabled = false;
                }
                else radAlexT2_30.Enabled = true;
            }
            else radAlexT2_30.Enabled = true;

            if (radAlexR3_30.Checked)
            {
                if (chkBlockTxAnt3.Checked)
                {
                    if (radAlexT3_30.Checked) radAlexT1_30.Checked = true;
                    radAlexT3_30.Enabled = false;
                }
                else radAlexT3_30.Enabled = true;
            }
            else radAlexT3_30.Enabled = true;

            ProcessAlexAntRadioButton(sender, Band.B30M, false);
        }

        private void radAlexR_20_CheckedChanged(object sender, System.EventArgs e)
        {
            if (radAlexR2_20.Checked)
            {
                if (chkBlockTxAnt2.Checked)
                {
                    if (radAlexT2_20.Checked) radAlexT1_20.Checked = true;
                    radAlexT2_20.Enabled = false;
                }
                else radAlexT2_20.Enabled = true;
            }
            else radAlexT2_20.Enabled = true;

            if (radAlexR3_20.Checked)
            {
                if (chkBlockTxAnt3.Checked)
                {
                    if (radAlexT3_20.Checked) radAlexT1_20.Checked = true;
                    radAlexT3_20.Enabled = false;
                }
                else radAlexT3_20.Enabled = true;
            }
            else radAlexT3_20.Enabled = true;

            ProcessAlexAntRadioButton(sender, Band.B20M, false);
        }

        private void radAlexR_17_CheckedChanged(object sender, System.EventArgs e)
        {
            if (radAlexR2_17.Checked)
            {
                if (chkBlockTxAnt2.Checked)
                {
                    if (radAlexT2_17.Checked) radAlexT1_17.Checked = true;
                    radAlexT2_17.Enabled = false;
                }
                else radAlexT2_17.Enabled = true;
            }
            else radAlexT2_17.Enabled = true;

            if (radAlexR3_17.Checked)
            {
                if (chkBlockTxAnt3.Checked)
                {
                    if (radAlexT3_17.Checked) radAlexT1_17.Checked = true;
                    radAlexT3_17.Enabled = false;
                }
                else radAlexT3_17.Enabled = true;
            }
            else radAlexT3_17.Enabled = true;

            ProcessAlexAntRadioButton(sender, Band.B17M, false);
        }

        private void radAlexR_15_CheckedChanged(object sender, System.EventArgs e)
        {
            if (radAlexR2_15.Checked)
            {
                if (chkBlockTxAnt2.Checked)
                {
                    if (radAlexT2_15.Checked) radAlexT1_15.Checked = true;
                    radAlexT2_15.Enabled = false;
                }
                else radAlexT2_15.Enabled = true;
            }
            else radAlexT2_15.Enabled = true;

            if (radAlexR3_15.Checked)
            {
                if (chkBlockTxAnt3.Checked)
                {
                    if (radAlexT3_15.Checked) radAlexT1_15.Checked = true;
                    radAlexT3_15.Enabled = false;
                }
                else radAlexT3_15.Enabled = true;
            }
            else radAlexT3_15.Enabled = true;

            ProcessAlexAntRadioButton(sender, Band.B15M, false);
        }

        private void radAlexR_12_CheckedChanged(object sender, System.EventArgs e)
        {
            if (radAlexR2_12.Checked)
            {
                if (chkBlockTxAnt2.Checked)
                {
                    if (radAlexT2_12.Checked) radAlexT1_12.Checked = true;
                    radAlexT2_12.Enabled = false;
                }
                else radAlexT2_12.Enabled = true;
            }
            else radAlexT2_12.Enabled = true;

            if (radAlexR3_12.Checked)
            {
                if (chkBlockTxAnt3.Checked)
                {
                    if (radAlexT3_12.Checked) radAlexT1_12.Checked = true;
                    radAlexT3_12.Enabled = false;
                }
                else radAlexT3_12.Enabled = true;
            }
            else radAlexT3_12.Enabled = true;

            ProcessAlexAntRadioButton(sender, Band.B12M, false);
        }

        private void radAlexR_10_CheckedChanged(object sender, System.EventArgs e)
        {
            if (radAlexR2_10.Checked)
            {
                if (chkBlockTxAnt2.Checked)
                {
                    if (radAlexT2_10.Checked) radAlexT1_10.Checked = true;
                    radAlexT2_10.Enabled = false;
                }
                else radAlexT2_10.Enabled = true;
            }
            else radAlexT2_10.Enabled = true;

            if (radAlexR3_10.Checked)
            {
                if (chkBlockTxAnt3.Checked)
                {
                    if (radAlexT3_10.Checked) radAlexT1_10.Checked = true;
                    radAlexT3_10.Enabled = false;
                }
                else radAlexT3_10.Enabled = true;
            }
            else radAlexT3_10.Enabled = true;

            ProcessAlexAntRadioButton(sender, Band.B10M, false);
        }

        private void radAlexR_6_CheckedChanged(object sender, System.EventArgs e)
        {
            if (radAlexR2_6.Checked)
            {
                if (chkBlockTxAnt2.Checked)
                {
                    if (radAlexT2_6.Checked) radAlexT1_6.Checked = true;
                    radAlexT2_6.Enabled = false;
                }
                else radAlexT2_6.Enabled = true;
            }
            else radAlexT2_6.Enabled = true;

            if (radAlexR3_6.Checked)
            {
                if (chkBlockTxAnt3.Checked)
                {
                    if (radAlexT3_6.Checked) radAlexT1_6.Checked = true;
                    radAlexT3_6.Enabled = false;
                }
                else radAlexT3_6.Enabled = true;
            }
            else radAlexT3_6.Enabled = true;

            ProcessAlexAntRadioButton(sender, Band.B6M, false);
        }

        private void radAlexT_160_CheckedChanged(object sender, System.EventArgs e)
        {
            ProcessAlexAntRadioButton(sender, Band.B160M, true);
        }

        private void radAlexT_80_CheckedChanged(object sender, System.EventArgs e)
        {
            ProcessAlexAntRadioButton(sender, Band.B80M, true);
        }

        private void radAlexT_60_CheckedChanged(object sender, System.EventArgs e)
        {
            ProcessAlexAntRadioButton(sender, Band.B60M, true);
        }

        private void radAlexT_40_CheckedChanged(object sender, System.EventArgs e)
        {
            ProcessAlexAntRadioButton(sender, Band.B40M, true);
        }

        private void radAlexT_30_CheckedChanged(object sender, System.EventArgs e)
        {
            ProcessAlexAntRadioButton(sender, Band.B30M, true);
        }

        private void radAlexT_20_CheckedChanged(object sender, System.EventArgs e)
        {
            ProcessAlexAntRadioButton(sender, Band.B20M, true);
        }

        private void radAlexT_17_CheckedChanged(object sender, System.EventArgs e)
        {
            ProcessAlexAntRadioButton(sender, Band.B17M, true);
        }

        private void radAlexT_15_CheckedChanged(object sender, System.EventArgs e)
        {
            ProcessAlexAntRadioButton(sender, Band.B15M, true);
        }

        private void radAlexT_12_CheckedChanged(object sender, System.EventArgs e)
        {
            ProcessAlexAntRadioButton(sender, Band.B12M, true);
        }

        private void radAlexT_10_CheckedChanged(object sender, System.EventArgs e)
        {
            ProcessAlexAntRadioButton(sender, Band.B10M, true);
        }

        private void radAlexT_6_CheckedChanged(object sender, System.EventArgs e)
        {
            ProcessAlexAntRadioButton(sender, Band.B6M, true);
        }

        private void chkAlex160R_CheckedChanged(object sender, System.EventArgs e)
        {
            ProcessAlexAntCheckBox(sender, Band.B160M);
        }

        private void chkAlex80R_CheckedChanged(object sender, System.EventArgs e)
        {
            ProcessAlexAntCheckBox(sender, Band.B80M);
        }

        private void chkAlex60R_CheckedChanged(object sender, System.EventArgs e)
        {
            ProcessAlexAntCheckBox(sender, Band.B60M);
        }

        private void chkAlex40R_CheckedChanged(object sender, System.EventArgs e)
        {
            ProcessAlexAntCheckBox(sender, Band.B40M);
        }

        private void chkAlex30R_CheckedChanged(object sender, System.EventArgs e)
        {
            ProcessAlexAntCheckBox(sender, Band.B30M);
        }

        private void chkAlex20R_CheckedChanged(object sender, System.EventArgs e)
        {
            ProcessAlexAntCheckBox(sender, Band.B20M);
        }

        private void chkAlex17R_CheckedChanged(object sender, System.EventArgs e)
        {
            ProcessAlexAntCheckBox(sender, Band.B17M);
        }

        private void chkAlex15R_CheckedChanged(object sender, System.EventArgs e)
        {
            ProcessAlexAntCheckBox(sender, Band.B15M);
        }

        private void chkAlex12R_CheckedChanged(object sender, System.EventArgs e)
        {
            ProcessAlexAntCheckBox(sender, Band.B12M);
        }

        private void chkAlex10R_CheckedChanged(object sender, System.EventArgs e)
        {
            ProcessAlexAntCheckBox(sender, Band.B10M);
        }

        private void chkAlex6R_CheckedChanged(object sender, System.EventArgs e)
        {
            ProcessAlexAntCheckBox(sender, Band.B6M);
        }

        private void chkAlex2R_CheckedChanged(object sender, System.EventArgs e)
        {
            ProcessAlexAntCheckBox(sender, Band.B2M);
        }

        private void ProcessAlexAntCheckBox(object sender, Band band)
        {
            string Name = "";
            if (sender == null) return;
            if (sender.GetType() != typeof(CheckBoxTS)) return;

            int idx = (int)band - (int)Band.B160M;

            CheckBoxTS[] cboxes = _AlexRxOnlyAntCheckBoxes[idx];

            int ant = 0;
            int i;

            // find which button was changed 
            for (i = 0; i < 2; i++)
            {
                if (sender.Equals(cboxes[i]))
                {
                    if (cboxes[i].Checked)
                    {
                        ant = i + 1;
                    }
                    break;
                }
            }

            if (ant != 0)
            {
                // turn off unselected antenna 
                for (i = 1; i <= 2; i++)
                {
                    if (ant != i)
                    {
                        cboxes[i - 1].Checked = false;
                    }
                }
            }

            ant = 0;
            for (i = 0; i < 3; i++)
            {
                if (cboxes[i].Checked)
                {
                    ant += i + 1;
                }
            }

            // find a name for the "winning" check box. In some radios the signals add, so multiple selections would be bad.
            if (cboxes[2].Checked)
                Name = RXAntChk3Name;
            else if (cboxes[1].Checked)
                Name = RXAntChk2Name;
            else if (cboxes[0].Checked)
                Name = RXAntChk1Name;

            bool IsExtAntenna = false;
            if (ant != 0)
                IsExtAntenna = true;

            Alex.getAlex().setRxOnlyAnt(band, (byte)ant);
            console.SetAriesRXAuxAntenna(IsExtAntenna, band);
            console.SetAriesRXAntennaName(Name, band);

            if (console.path_Illustrator != null)
                console.path_Illustrator.pi_Changed();

            console.AlexAntCtrlEnabled = true; // need side effect of prop set to push data down to C code 

            handleRXAntennaChangeForNF(band);

            // changed notification
            for (int n = 0; n < 3; n++)
            {
                if(_AlexRxOnlyAntCheckBoxes_old[idx][n] != _AlexRxOnlyAntCheckBoxes[idx][n].Checked)
                {
                    //Debug.Print($"====> AntCheckBoxes Changed : band={band.ToString()} button={n.ToString()} from={_AlexRxOnlyAntCheckBoxes_old[idx][n].ToString()} to={_AlexRxOnlyAntCheckBoxes[idx][n].Checked.ToString()}");
                    string btn_text = "";
                    switch(n)
                    {
                        case 0:
                            btn_text = RXAntChk1Name;
                            break;
                        case 1:
                            btn_text = RXAntChk2Name;
                            break;
                        case 2:
                            btn_text = RXAntChk3Name;
                            break;
                    }
                    console.AntennaAuxChangedHandlers?.Invoke(band, n, _AlexRxOnlyAntCheckBoxes_old[idx][n], _AlexRxOnlyAntCheckBoxes[idx][n].Checked, btn_text);

                    _AlexRxOnlyAntCheckBoxes_old[idx][n] = _AlexRxOnlyAntCheckBoxes[idx][n].Checked;
                }
            }
            //
        }


        private void ProcessAlexAntRadioButton(object sender, Band band, bool is_xmit)
        {
            if (sender == null) return;
            if (sender.GetType() != typeof(RadioButtonTS)) return;
            RadioButtonTS radBtnTS = (RadioButtonTS)sender;
            if (!radBtnTS.Checked) return;

            int idx = (int)band - (int)Band.B160M;

            RadioButtonTS[] buttons = is_xmit ? _AlexTxAntButtons[idx] : _AlexRxAntButtons[idx];

            int ant = 0;

            // find which button was changed 
            for (int i = 0; i < 3; i++)
            {
                if (!sender.Equals(buttons[i])) continue;
                ant = i + 1;
                break;
            }

            if (ant == 0)
            {
                int i = 0;
                foreach (RadioButtonTS b in buttons)
                {
                    if (b.Checked)
                    {
                        ant = i + 1;
                        break;
                    }
                    i++;
                }
            }

            if (is_xmit)
            {
                Alex.getAlex().setTxAnt(band, (byte)ant);
                pi_TxAnt = ant;                                 // Path_Illustrator support
                console.SetAriesTXAntenna(ant, band); // temporaily disable needs more work
            }
            else
            {
                Alex.getAlex().setRxAnt(band, (byte)ant);
                pi_RxAnt = ant;                                 // Path_Illustrator support
                console.SetAriesRXAntenna(ant, band); // temporaily disable needs more work

                handleRXAntennaChangeForNF(band);
            }

            console.AlexAntCtrlEnabled = true; // need side effect of prop set to push data down to C code 

            // changed notification
            updateChangedAntAlexButton(is_xmit, idx, band);
            //
        }
        private void updateChangedAntAlexButton(bool is_xmit, int idx, Band band)
        {
            for (int n = 0; n < 3; n++)
            {
                if (is_xmit)
                {
                    if (_AlexTxAntButtons_old[idx][n] != _AlexTxAntButtons[idx][n].Checked)
                    {
                        //Debug.Print($"====> TxRad Changed : band={band.ToString()} button={n.ToString()} from={_AlexTxAntButtons_old[idx][n].ToString()} to={_AlexTxAntButtons[idx][n].Checked.ToString()}");
                        console.AntennaTXChangedHandlers?.Invoke(band, n, _AlexTxAntButtons_old[idx][n], _AlexTxAntButtons[idx][n].Checked);

                        _AlexTxAntButtons_old[idx][n] = _AlexTxAntButtons[idx][n].Checked;
                    }
                }
                else
                {
                    if (_AlexRxAntButtons_old[idx][n] != _AlexRxAntButtons[idx][n].Checked)
                    {
                        //Debug.Print($"====> RxRad Changed : band={band.ToString()} button={n.ToString()} from={_AlexRxAntButtons_old[idx][n].ToString()} to={_AlexRxAntButtons[idx][n].Checked.ToString()}");
                        console.AntennaRXChangedHandlers?.Invoke(band, n, _AlexRxAntButtons_old[idx][n], _AlexRxAntButtons[idx][n].Checked);

                        _AlexRxAntButtons_old[idx][n] = _AlexRxAntButtons[idx][n].Checked;
                    }
                }
            }
        }

        // get RX antenna in use for band
        // this must also ignores ext input check boxes
        public int GetRXAntenna(Band band)
        {
            int antInUse = 0; //0 none, 1-3 valid
            if ((band >= Band.B160M) && (band <= Band.B6M))
            {
                int idx = (int)band - (int)Band.B160M;
                int Btn;
                // change to new radio button and clear all ext input checkboxes
                RadioButtonTS[] buttons = _AlexRxAntButtons[idx];
                for (Btn = 0; Btn < 3; Btn++)
                {
                    if (buttons[Btn].Checked) antInUse = Btn + 1;
                }
            }
            return antInUse;
        }
        // get TX antenna in use for band
        public int GetTXAntenna(Band band)
        {
            int antInUse = 0; //0 none, 1-3 valid
            if ((band >= Band.B160M) && (band <= Band.B6M))
            {
                int idx = (int)band - (int)Band.B160M;
                int Btn;
                RadioButtonTS[] buttons = _AlexTxAntButtons[idx];
                for (Btn = 0; Btn < 3; Btn++)
                {
                    if (buttons[Btn].Checked)
                    {
                        if (Btn == 1 && chkBlockTxAnt2.Checked)
                        {
                            antInUse = Btn + 1;
                        }
                        if (Btn == 2 && chkBlockTxAnt3.Checked)
                        {
                            antInUse = Btn + 1;
                        }
                        else
                            antInUse = Btn + 1;
                    }
                }
            }
            return antInUse;
        }

        // set RX antenna to new antenna 1-3
        // this must also cancel any ext input check boxes
        public void SetRXAntenna(int Antenna, Band band)
        {
            if ((band >= Band.B160M) && (band <= Band.B6M))
            {
                int idx = (int)band - (int)Band.B160M;
                int Btn;
                // change to new radio button and clear all ext input checkboxes
                RadioButtonTS[] buttons = _AlexRxAntButtons[idx];
                for (Btn = 0; Btn < 3; Btn++)
                {
                    if (Btn == Antenna - 1)
                        buttons[Btn].Checked = true;
                    else
                        buttons[Btn].Checked = false;
                }

                CheckBoxTS[] cboxes = _AlexRxOnlyAntCheckBoxes[idx];
                for (Btn = 0; Btn < 3; Btn++)
                {
                    cboxes[Btn].Checked = false;
                }
            }
        }

        // set RX antenna to new byp/ext1
        // this must also cancel the other
        public void SetAuxAntenna(int Antenna, Band band, bool byp, bool ext1)
        {
            if (byp && ext1) return; // can't both be on
            if ((band >= Band.B160M) && (band <= Band.B6M))
            {
                int idx = (int)band - (int)Band.B160M;

                CheckBoxTS[] cboxes = _AlexRxOnlyAntCheckBoxes[idx];

                cboxes[0].Checked = byp;
                cboxes[1].Checked = ext1;
            }
        }

        // set TX antenna to new antenna 1-3
        // only select antennas 2 or 3 if not blocked by "do not TX" check boxes
        public void SetTXAntenna(int Antenna, Band band)
        {
            if ((band >= Band.B160M) && (band <= Band.B6M))
            {
                int idx = (int)band - (int)Band.B160M;
                int Btn;
                bool TXAllowed = true;

                if (Antenna == 2)
                {
                    if (chkBlockTxAnt2.Checked)
                        TXAllowed = false;
                }
                else if (Antenna == 3)
                {
                    if (chkBlockTxAnt3.Checked)
                        TXAllowed = false;
                }

                RadioButtonTS[] buttons = _AlexTxAntButtons[idx];
                if (TXAllowed)
                {
                    for (Btn = 0; Btn < 3; Btn++)
                    {
                        if (Btn == Antenna - 1)
                            buttons[Btn].Checked = true;
                        else
                            buttons[Btn].Checked = false;
                    }
                }
            }
        }

        private void handleRXAntennaChangeForNF(Band band)
        {
            // antenna change should cause noise floor to go into fast attack

            int rx1 = -1, rx2 = -1, sync1 = -1, sync2 = -1, psrx = -1, pstx = -1;
            console.GetDDC(out rx1, out rx2, out sync1, out sync2, out psrx, out pstx);
            int nRX1ADCinUse = console.GetADCInUse(rx1);
            int nRX2ADCinUse = console.GetADCInUse(rx2);

            if (nRX1ADCinUse == 0 && console.RX1Band == band)
                Display.FastAttackNoiseFloorRX1 = true;

            if (nRX2ADCinUse == 0 && (console.RX2Enabled && console.RX2Band == band)) // also if adc0 for rx2 then we need to fast attack
                Display.FastAttackNoiseFloorRX2 = true;
        }

        private void btnHPSDRFreqCalReset_Click(object sender, System.EventArgs e)
        {
            udHPSDRFreqCorrectFactor.Value = (decimal)1.0;
            udHPSDRFreqCorrectFactor_ValueChanged(this, EventArgs.Empty);
        }

        private void tpHPSDR_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            if (console.PowerOn && console.CurrentHPSDRModel == HPSDRModel.HPSDR)
            {
                grpVersion.Visible = true;
                lblMercury2FWVer.Visible = console.RX2PreampPresent;

                lblOzyFX2.Text = "";
            }
            else grpVersion.Visible = false;
        }

        private void tpGeneralHardware_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            lblMetisIP.Text = NetworkIO.HpSdrHwIpAddress;
            lblMetisMAC.Text = NetworkIO.HpSdrHwMacAddress;

            string sProtocolInfo = "Protocol ?";
            string sMetisCodeVersion = "?.?";
            string sBoard = "?";

            if (NetworkIO.getHaveSync() == 1)
            {
                //MW0LGE_21d
                if (NetworkIO.CurrentRadioProtocol == RadioProtocol.ETH)
                {
                    sProtocolInfo = "Protocol 2 (v" + NetworkIO.ProtocolSupported.ToString("0\\.0") + ")";
                    sMetisCodeVersion = NetworkIO.FWCodeVersion.ToString("0\\.0") + "." + NetworkIO.BetaVersion.ToString();
                }
                else
                {
                    sProtocolInfo = "Protocol 1";
                    sMetisCodeVersion = NetworkIO.FWCodeVersion.ToString("0\\.0");
                }

                sBoard = NetworkIO.BoardID.ToString();
            }

            lblProtocolInfo.Text = sProtocolInfo;
            lblMetisCodeVersion.Text = sMetisCodeVersion;
            lblMetisBoardID.Text = sBoard;

            return;
        }

        //MW0LGE_21g
        public string GetFirmwareCodeVersionString()
        {
            string sRet = "";

            if (NetworkIO.getHaveSync() == 1)
            {
                if (NetworkIO.CurrentRadioProtocol == RadioProtocol.ETH)
                {
                    sRet = "FW v" + NetworkIO.FWCodeVersion.ToString("0\\.0") + "." + NetworkIO.BetaVersion.ToString() + " Protocol 2";
                }
                else
                {
                    sRet = "FW v" + NetworkIO.FWCodeVersion.ToString("0\\.0") + " Protocol 1";
                }
            }

            return sRet;
        }

        public void UpdateGeneraHardware()
        {
            tpGeneralHardware.Invalidate();
        }

        private void udMaxFreq_ValueChanged(object sender, System.EventArgs e)
        {
            console.MaxFreq = (double)udMaxFreq.Value;
        }

        private void udHPSDRFreqCorrectFactor_ValueChanged(object sender, System.EventArgs e)
        {
            if (_freqCorrectFactorChangedViaAutoCalibration || !chkUsing10MHzRef.Checked)
            {
                NetworkIO.FreqCorrectionFactor = (double)udHPSDRFreqCorrectFactor.Value;
                _freqCorrectFactorChangedViaAutoCalibration = false;
            }
            else if (chkUsing10MHzRef.Checked)
            {
                NetworkIO.FreqCorrectionFactor = (double)udHPSDRFreqCorrectFactor10MHz.Value;
            }
        }

        private void chkHERCULES_CheckedChanged(object sender, EventArgs e)
        {
            switch (chkHERCULES.Checked)
            {
                case true:
                    foreach (Control c in grpPennyExtCtrl.Controls)
                    {
                        if (c.Name.StartsWith("chkPenOC"))
                        {
                            ((CheckBoxTS)c).Checked = false;
                        }
                    }

                    chkPenOCrcv1601.Checked = true;
                    chkPenOCxmit1601.Checked = true;
                    chkPenOCrcv802.Checked = true;
                    chkPenOCxmit802.Checked = true;
                    chkPenOCrcv601.Checked = true;
                    chkPenOCxmit601.Checked = true;
                    chkPenOCrcv602.Checked = true;
                    chkPenOCxmit602.Checked = true;
                    chkPenOCrcv403.Checked = true;
                    chkPenOCxmit403.Checked = true;
                    chkPenOCrcv301.Checked = true;
                    chkPenOCxmit301.Checked = true;
                    chkPenOCrcv303.Checked = true;
                    chkPenOCxmit303.Checked = true;
                    chkPenOCrcv202.Checked = true;
                    chkPenOCxmit202.Checked = true;
                    chkPenOCrcv203.Checked = true;
                    chkPenOCxmit203.Checked = true;
                    chkPenOCrcv171.Checked = true;
                    chkPenOCxmit171.Checked = true;
                    chkPenOCrcv172.Checked = true;
                    chkPenOCxmit172.Checked = true;
                    chkPenOCrcv173.Checked = true;
                    chkPenOCxmit173.Checked = true;
                    chkPenOCrcv154.Checked = true;
                    chkPenOCxmit154.Checked = true;
                    chkPenOCrcv121.Checked = true;
                    chkPenOCxmit121.Checked = true;
                    chkPenOCrcv124.Checked = true;
                    chkPenOCxmit124.Checked = true;
                    chkPenOCrcv102.Checked = true;
                    chkPenOCxmit102.Checked = true;
                    chkPenOCrcv104.Checked = true;
                    chkPenOCxmit104.Checked = true;
                    chkPenOCrcv61.Checked = true;
                    chkPenOCxmit61.Checked = true;
                    chkPenOCrcv62.Checked = true;
                    chkPenOCxmit62.Checked = true;
                    chkPenOCrcv64.Checked = true;
                    chkPenOCxmit64.Checked = true;
                    chkPenOCrcv66.Checked = true;
                    break;
                case false:
                    foreach (Control c in grpPennyExtCtrl.Controls)
                    {
                        if (c.Name.StartsWith("chkPenOC"))
                        {
                            ((CheckBoxTS)c).Checked = false;
                        }
                    }
                    break;
            }
        }

        private void btnPennyCtrlReset_Click(object sender, EventArgs e)
        {
            switch (chkHERCULES.Checked)
            {
                case false:
                    foreach (Control c in grpPennyExtCtrl.Controls)
                    {
                        if (c.Name.StartsWith("chkPenOC"))
                        {
                            ((CheckBoxTS)c).Checked = false;
                        }
                    }
                    break;
            }
        }

        private void btnPennyCtrlVHFReset_Click(object sender, EventArgs e)
        {
            foreach (Control c in grpPennyExtCtrlVHF.Controls)
            {
                if (c.Name.StartsWith("chkPenOC"))
                {
                    ((CheckBoxTS)c).Checked = false;
                }
            }
        }

        private void btnCtrlSWLReset_Click(object sender, EventArgs e)
        {
            foreach (Control c in grpExtCtrlSWL.Controls)
            {
                if (c.Name.StartsWith("chkOC"))
                {
                    ((CheckBoxTS)c).Checked = false;
                }
            }
        }

        private void comboFRSRegion_SelectedIndexChanged(object sender, EventArgs e) //w5wc
        {
            if (comboFRSRegion.Text == "") return;

            FRSRegion region = console.CurrentRegion;
            switch (comboFRSRegion.Text)
            {
                case "Australia":
                    region = FRSRegion.Australia;
                    break;
                case "Europe":
                    region = FRSRegion.Europe;
                    break;
                case "India":
                    region = FRSRegion.India;
                    break;
                case "Italy":
                    region = FRSRegion.Italy_Plus;
                    break;
                case "Spain":
                    region = FRSRegion.Spain;
                    break;
                case "Japan":
                    region = FRSRegion.Japan;
                    break;
                case "United Kingdom":
                    region = FRSRegion.UK;
                    break;
                case "United States":
                    region = FRSRegion.US;
                    break;
                case "Norway":
                    region = FRSRegion.Norway;
                    break;
                case "Denmark":
                    region = FRSRegion.Denmark;
                    break;
                case "Latvia":
                    region = FRSRegion.Latvia;
                    break;
                case "Slovakia":
                    region = FRSRegion.Slovakia;
                    break;
                case "Bulgaria":
                    region = FRSRegion.Bulgaria;
                    break;
                case "Greece":
                    region = FRSRegion.Greece;
                    break;
                case "Hungary":
                    region = FRSRegion.Hungary;
                    break;
                case "Netherlands":
                    region = FRSRegion.Netherlands;
                    break;
                case "France":
                    region = FRSRegion.France;
                    break;
                case "Israel":
                    region = FRSRegion.Israel;
                    break;
                case "Russia":
                    region = FRSRegion.Russia;
                    break;
                case "Sweden":
                    region = FRSRegion.Sweden;
                    break;
                case "Region1":
                    region = FRSRegion.Region1;
                    break;
                case "Region2":
                    region = FRSRegion.Region2;
                    break;
                case "Region3":
                    region = FRSRegion.Region3;
                    break;
                case "Germany":
                    region = FRSRegion.Germany;
                    break;
            }

            if (!console.initializing)
            {
                //MW0LGE_21d
                // needs to happen before region assign
                BandStackManager.RegionReset();
            }

            if (console.CurrentRegion != region)
                console.CurrentRegion = region;

            if (!console.initializing)
            {
                setButtonState(true, false);  // MW0LGE this causes an update of the whole DB, so disable buttons while happening                                
                DB.UpdateRegion(console.CurrentRegion);
                setButtonState(false, false);
            }
            if (console.CurrentRegion == FRSRegion.UK || console.CurrentRegion == FRSRegion.US)
            {
                console.Init60mChannels();
            }
        }

        private void radMicIn_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (!radMicIn.Checked) return;
            console.LineIn = false;
            radLineIn.Checked = false;
            chk20dbMicBoost.Visible = true;
            chk20dbMicBoost.Enabled = true;
            lblLineInBoost.Visible = false;
            udLineInBoost.Visible = false;
        }

        private void radLineIn_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (!radLineIn.Checked) return;
            console.LineIn = true;
            radMicIn.Checked = false;
            chk20dbMicBoost.Visible = false;
            chk20dbMicBoost.Enabled = false;
            lblLineInBoost.Visible = true;
            udLineInBoost.Visible = true;
        }

        private string IPStringFromInt(Int32 addr, StringBuilder sb)
        {
            sb.Length = 0;
            for (int i = 0; i < 4; i++)
            {
                int j = addr & 0xff;
                addr = addr >> 8;
                sb.Append(j);
                if (i != 3)
                {
                    sb.Append(".");
                }
            }
            return sb.ToString();
        }

        private string IPStringFromInt(Int32 addr)
        {
            return IPStringFromInt(addr, new StringBuilder());
        }

        private void udGenPTTOutDelay_ValueChanged(object sender, EventArgs e)
        {
            console.PTTOutDelay = (int)udGenPTTOutDelay.Value;
        }

        private void udMoxDelay_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.MoxDelay = (int)udMoxDelay.Value;
        }

        private void udCWKeyUpDelay_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.KeyUpDelay = (int)udCWKeyUpDelay.Value;
            udCWKeyerSemiBreakInDelay_ValueChanged(this, EventArgs.Empty);
        }

        private void udRFDelay_ValueChanged(object sender, EventArgs e)
        {
            console.RFDelay = (int)udRFDelay.Value;
        }

        private void udTXDisplayCalOffset_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.TXDisplayCalOffset = (float)udTXDisplayCalOffset.Value;
        }

        private void udTXDisplayCalOffset_LostFocus(object sender, EventArgs e)
        {
            udTXDisplayCalOffset.Value = udTXDisplayCalOffset.Value;
        }

        private void udTwoToneLevel_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (chkTestIMD.Checked)
            {
                Audio.SourceScale = Math.Pow(10.0, (double)udTwoToneLevel.Value / 20.0);
            }
        }

        private void clrbtnGridFine_Changed(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.GridPenDark = Color.FromArgb(tbGridFineAlpha.Value, clrbtnGridFine.Color);
        }

        private void clrbtnTXVGridFine_Changed(object sender, EventArgs e)
        {
            Display.TXVGridPenFine = Color.FromArgb(tbTXVGridFineAlpha.Value, clrbtnTXVGridFine.Color);
        }

        private void tbBackgroundAlpha_Scroll(object sender, EventArgs e)
        {
            clrbtnBackground_Changed(this, EventArgs.Empty);
            toolTip1.SetToolTip(tbBackgroundAlpha, tbBackgroundAlpha.Value.ToString());
        }

        private void tbTXBackgroundAlpha_Scroll(object sender, EventArgs e)
        {
            clrbtnTXBackground_Changed(this, EventArgs.Empty);
            toolTip1.SetToolTip(tbTXBackgroundAlpha, tbTXBackgroundAlpha.Value.ToString());
        }

        private void tbGridCourseAlpha_Scroll(object sender, EventArgs e)
        {
            clrbtnGrid_Changed(this, EventArgs.Empty);
            toolTip1.SetToolTip(tbGridCourseAlpha, tbGridCourseAlpha.Value.ToString());
        }

        private void tbTXVGridCourseAlpha_Scroll(object sender, EventArgs e)
        {
            clrbtnTXVGrid_Changed(this, EventArgs.Empty);
            toolTip1.SetToolTip(tbTXVGridCourseAlpha, tbTXVGridCourseAlpha.Value.ToString());
        }

        private void tbGridFineAlpha_Scroll(object sender, EventArgs e)
        {
            clrbtnGridFine_Changed(this, EventArgs.Empty);
            toolTip1.SetToolTip(tbGridFineAlpha, tbGridFineAlpha.Value.ToString());
        }

        private void tbTXVGridFineAlpha_Scroll(object sender, EventArgs e)
        {
            clrbtnTXVGridFine_Changed(this, EventArgs.Empty);
            toolTip1.SetToolTip(tbTXVGridFineAlpha, tbTXVGridFineAlpha.Value.ToString());
        }

        private void clrbtnHGridColor_Changed(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.HGridColor = Color.FromArgb(tbHGridColorAlpha.Value, clrbtnHGridColor.Color);
        }

        private void clrbtnTXHGridColor_Changed(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.TXHGridColor = Color.FromArgb(tbTXHGridColorAlpha.Value, clrbtnTXHGridColor.Color);
        }

        private void tbHGridColorAlpha_Scroll(object sender, EventArgs e)
        {
            clrbtnHGridColor_Changed(this, EventArgs.Empty);
            toolTip1.SetToolTip(tbHGridColorAlpha, tbHGridColorAlpha.Value.ToString());
        }

        private void tbMeterEdgeBackgroundAlpha_Scroll(object sender, EventArgs e)
        {
            clrbtnMeterEdgeBackground_Changed(this, EventArgs.Empty);
            toolTip1.SetToolTip(tbMeterEdgeBackgroundAlpha, tbMeterEdgeBackgroundAlpha.Value.ToString());
        }

        private void tbTXHGridColorAlpha_Scroll(object sender, EventArgs e)
        {
            clrbtnTXHGridColor_Changed(this, EventArgs.Empty);
            toolTip1.SetToolTip(tbTXHGridColorAlpha, tbTXHGridColorAlpha.Value.ToString());
        }

        private void tbTXZeroLineAlpha_Scroll(object sender, EventArgs e)
        {
            clrbtnTXZeroLine_Changed(this, EventArgs.Empty);
            toolTip1.SetToolTip(tbTXZeroLineAlpha, tbTXZeroLineAlpha.Value.ToString());
        }

        private void tbTXTextAlpha_Scroll(object sender, EventArgs e)
        {
            clrbtnTXText_Changed(this, EventArgs.Empty);
            toolTip1.SetToolTip(tbTXTextAlpha, tbTXTextAlpha.Value.ToString());
        }

        private void chkGridControl_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.GridControl = chkGridControl.Checked;
        }

        private void chkTXGridControl_CheckedChanged(object sender, EventArgs e)
        {
            Display.TXGridControl = chkTXGridControl.Checked;
        }

        private void radSpaceBarLastBtn_CheckedChanged(object sender, EventArgs e)
        {
            console.SpaceBarLastBtn = radSpaceBarLastBtn.Checked;
        }

        private void radSpaceBarPTT_CheckedChanged(object sender, EventArgs e)
        {
            console.SpaceBarPTT = radSpaceBarPTT.Checked;
        }

        private void radSpaceBarVOX_CheckedChanged(object sender, EventArgs e)
        {
            console.SpaceBarVOX = radSpaceBarVOX.Checked;
        }

        private void radSpaceBarMicMute_CheckedChanged(object sender, EventArgs e)
        {
            console.SpaceBarMicMute = radSpaceBarMicMute.Checked;
        }

        private void chkPenOCrcvVHF0_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkPenOCrcvVHF01.Checked) val += 1 << 0;
            if (chkPenOCrcvVHF02.Checked) val += 1 << 1;
            if (chkPenOCrcvVHF03.Checked) val += 1 << 2;
            if (chkPenOCrcvVHF04.Checked) val += 1 << 3;
            if (chkPenOCrcvVHF05.Checked) val += 1 << 4;
            if (chkPenOCrcvVHF06.Checked) val += 1 << 5;
            if (chkPenOCrcvVHF07.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.VHF0, (byte)(val & 0x70), false); // 0000xxx
            Penny.getPenny().setBandABitMask(Band.VHF0, (byte)val, false);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCrcvVHF1_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkPenOCrcvVHF11.Checked) val += 1 << 0;
            if (chkPenOCrcvVHF12.Checked) val += 1 << 1;
            if (chkPenOCrcvVHF13.Checked) val += 1 << 2;
            if (chkPenOCrcvVHF14.Checked) val += 1 << 3;
            if (chkPenOCrcvVHF15.Checked) val += 1 << 4;
            if (chkPenOCrcvVHF16.Checked) val += 1 << 5;
            if (chkPenOCrcvVHF17.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.VHF1, (byte)(val & 0x70), false);
            Penny.getPenny().setBandABitMask(Band.VHF1, (byte)val, false);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCrcvVHF2_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkPenOCrcvVHF21.Checked) val += 1 << 0;
            if (chkPenOCrcvVHF22.Checked) val += 1 << 1;
            if (chkPenOCrcvVHF23.Checked) val += 1 << 2;
            if (chkPenOCrcvVHF24.Checked) val += 1 << 3;
            if (chkPenOCrcvVHF25.Checked) val += 1 << 4;
            if (chkPenOCrcvVHF26.Checked) val += 1 << 5;
            if (chkPenOCrcvVHF27.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.VHF2, (byte)(val & 0x70), false);
            Penny.getPenny().setBandABitMask(Band.VHF2, (byte)val, false);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCrcvVHF3_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkPenOCrcvVHF31.Checked) val += 1 << 0;
            if (chkPenOCrcvVHF32.Checked) val += 1 << 1;
            if (chkPenOCrcvVHF33.Checked) val += 1 << 2;
            if (chkPenOCrcvVHF34.Checked) val += 1 << 3;
            if (chkPenOCrcvVHF35.Checked) val += 1 << 4;
            if (chkPenOCrcvVHF36.Checked) val += 1 << 5;
            if (chkPenOCrcvVHF37.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.VHF3, (byte)(val & 0x70), false);
            Penny.getPenny().setBandABitMask(Band.VHF3, (byte)val, false);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCrcvVHF4_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkPenOCrcvVHF41.Checked) val += 1 << 0;
            if (chkPenOCrcvVHF42.Checked) val += 1 << 1;
            if (chkPenOCrcvVHF43.Checked) val += 1 << 2;
            if (chkPenOCrcvVHF44.Checked) val += 1 << 3;
            if (chkPenOCrcvVHF45.Checked) val += 1 << 4;
            if (chkPenOCrcvVHF46.Checked) val += 1 << 5;
            if (chkPenOCrcvVHF47.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.VHF4, (byte)(val & 0x70), false);
            Penny.getPenny().setBandABitMask(Band.VHF4, (byte)val, false);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCrcvVHF5_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkPenOCrcvVHF51.Checked) val += 1 << 0;
            if (chkPenOCrcvVHF52.Checked) val += 1 << 1;
            if (chkPenOCrcvVHF53.Checked) val += 1 << 2;
            if (chkPenOCrcvVHF54.Checked) val += 1 << 3;
            if (chkPenOCrcvVHF55.Checked) val += 1 << 4;
            if (chkPenOCrcvVHF56.Checked) val += 1 << 5;
            if (chkPenOCrcvVHF57.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.VHF5, (byte)(val & 0x70), false);
            Penny.getPenny().setBandABitMask(Band.VHF5, (byte)val, false);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCrcvVHF6_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkPenOCrcvVHF61.Checked) val += 1 << 0;
            if (chkPenOCrcvVHF62.Checked) val += 1 << 1;
            if (chkPenOCrcvVHF63.Checked) val += 1 << 2;
            if (chkPenOCrcvVHF64.Checked) val += 1 << 3;
            if (chkPenOCrcvVHF65.Checked) val += 1 << 4;
            if (chkPenOCrcvVHF66.Checked) val += 1 << 5;
            if (chkPenOCrcvVHF67.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.VHF6, (byte)(val & 0x70), false);
            Penny.getPenny().setBandABitMask(Band.VHF6, (byte)val, false);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCrcvVHF7_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkPenOCrcvVHF71.Checked) val += 1 << 0;
            if (chkPenOCrcvVHF72.Checked) val += 1 << 1;
            if (chkPenOCrcvVHF73.Checked) val += 1 << 2;
            if (chkPenOCrcvVHF74.Checked) val += 1 << 3;
            if (chkPenOCrcvVHF75.Checked) val += 1 << 4;
            if (chkPenOCrcvVHF76.Checked) val += 1 << 5;
            if (chkPenOCrcvVHF77.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.VHF7, (byte)(val & 0x70), false);
            Penny.getPenny().setBandABitMask(Band.VHF7, (byte)val, false);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCrcvVHF8_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkPenOCrcvVHF81.Checked) val += 1 << 0;
            if (chkPenOCrcvVHF82.Checked) val += 1 << 1;
            if (chkPenOCrcvVHF83.Checked) val += 1 << 2;
            if (chkPenOCrcvVHF84.Checked) val += 1 << 3;
            if (chkPenOCrcvVHF85.Checked) val += 1 << 4;
            if (chkPenOCrcvVHF86.Checked) val += 1 << 5;
            if (chkPenOCrcvVHF87.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.VHF8, (byte)(val & 0x70), false);
            Penny.getPenny().setBandABitMask(Band.VHF8, (byte)val, false);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code  
        }

        private void chkPenOCrcvVHF9_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkPenOCrcvVHF91.Checked) val += 1 << 0;
            if (chkPenOCrcvVHF92.Checked) val += 1 << 1;
            if (chkPenOCrcvVHF93.Checked) val += 1 << 2;
            if (chkPenOCrcvVHF94.Checked) val += 1 << 3;
            if (chkPenOCrcvVHF95.Checked) val += 1 << 4;
            if (chkPenOCrcvVHF96.Checked) val += 1 << 5;
            if (chkPenOCrcvVHF97.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.VHF9, (byte)(val & 0x70), false);
            Penny.getPenny().setBandABitMask(Band.VHF9, (byte)val, false);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code  
        }

        private void chkPenOCrcvVHF10_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkPenOCrcvVHF101.Checked) val += 1 << 0;
            if (chkPenOCrcvVHF102.Checked) val += 1 << 1;
            if (chkPenOCrcvVHF103.Checked) val += 1 << 2;
            if (chkPenOCrcvVHF104.Checked) val += 1 << 3;
            if (chkPenOCrcvVHF105.Checked) val += 1 << 4;
            if (chkPenOCrcvVHF106.Checked) val += 1 << 5;
            if (chkPenOCrcvVHF107.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.VHF10, (byte)(val & 0x70), false);
            Penny.getPenny().setBandABitMask(Band.VHF10, (byte)val, false);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code  
        }

        private void chkPenOCrcvVHF11_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkPenOCrcvVHF111.Checked) val += 1 << 0;
            if (chkPenOCrcvVHF112.Checked) val += 1 << 1;
            if (chkPenOCrcvVHF113.Checked) val += 1 << 2;
            if (chkPenOCrcvVHF114.Checked) val += 1 << 3;
            if (chkPenOCrcvVHF115.Checked) val += 1 << 4;
            if (chkPenOCrcvVHF116.Checked) val += 1 << 5;
            if (chkPenOCrcvVHF117.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.VHF11, (byte)(val & 0x70), false);
            Penny.getPenny().setBandABitMask(Band.VHF11, (byte)val, false);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkPenOCxmitVHF0_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkPenOCxmitVHF01.Checked) val += 1 << 0;
            if (chkPenOCxmitVHF02.Checked) val += 1 << 1;
            if (chkPenOCxmitVHF03.Checked) val += 1 << 2;
            if (chkPenOCxmitVHF04.Checked) val += 1 << 3;
            if (chkPenOCxmitVHF05.Checked) val += 1 << 4;
            if (chkPenOCxmitVHF06.Checked) val += 1 << 5;
            if (chkPenOCxmitVHF07.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.VHF0, (byte)(val & 0x70), true);
            Penny.getPenny().setBandABitMask(Band.VHF0, (byte)val, true);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code
        }

        private void chkPenOCxmitVHF1_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkPenOCxmitVHF11.Checked) val += 1 << 0;
            if (chkPenOCxmitVHF12.Checked) val += 1 << 1;
            if (chkPenOCxmitVHF13.Checked) val += 1 << 2;
            if (chkPenOCxmitVHF14.Checked) val += 1 << 3;
            if (chkPenOCxmitVHF15.Checked) val += 1 << 4;
            if (chkPenOCxmitVHF16.Checked) val += 1 << 5;
            if (chkPenOCxmitVHF17.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.VHF1, (byte)(val & 0x70), true);
            Penny.getPenny().setBandABitMask(Band.VHF1, (byte)val, true);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code
        }

        private void chkPenOCxmitVHF2_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkPenOCxmitVHF21.Checked) val += 1 << 0;
            if (chkPenOCxmitVHF22.Checked) val += 1 << 1;
            if (chkPenOCxmitVHF23.Checked) val += 1 << 2;
            if (chkPenOCxmitVHF24.Checked) val += 1 << 3;
            if (chkPenOCxmitVHF25.Checked) val += 1 << 4;
            if (chkPenOCxmitVHF26.Checked) val += 1 << 5;
            if (chkPenOCxmitVHF27.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.VHF2, (byte)(val & 0x70), true);
            Penny.getPenny().setBandABitMask(Band.VHF2, (byte)val, true);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code
        }

        private void chkPenOCxmitVHF3_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkPenOCxmitVHF31.Checked) val += 1 << 0;
            if (chkPenOCxmitVHF32.Checked) val += 1 << 1;
            if (chkPenOCxmitVHF33.Checked) val += 1 << 2;
            if (chkPenOCxmitVHF34.Checked) val += 1 << 3;
            if (chkPenOCxmitVHF35.Checked) val += 1 << 4;
            if (chkPenOCxmitVHF36.Checked) val += 1 << 5;
            if (chkPenOCxmitVHF37.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.VHF3, (byte)(val & 0x70), true);
            Penny.getPenny().setBandABitMask(Band.VHF3, (byte)val, true);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code
        }

        private void chkPenOCxmitVHF4_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkPenOCxmitVHF41.Checked) val += 1 << 0;
            if (chkPenOCxmitVHF42.Checked) val += 1 << 1;
            if (chkPenOCxmitVHF43.Checked) val += 1 << 2;
            if (chkPenOCxmitVHF44.Checked) val += 1 << 3;
            if (chkPenOCxmitVHF45.Checked) val += 1 << 4;
            if (chkPenOCxmitVHF46.Checked) val += 1 << 5;
            if (chkPenOCxmitVHF47.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.VHF4, (byte)(val & 0x70), true);
            Penny.getPenny().setBandABitMask(Band.VHF4, (byte)val, true);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code
        }

        private void chkPenOCxmitVHF5_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkPenOCxmitVHF51.Checked) val += 1 << 0;
            if (chkPenOCxmitVHF52.Checked) val += 1 << 1;
            if (chkPenOCxmitVHF53.Checked) val += 1 << 2;
            if (chkPenOCxmitVHF54.Checked) val += 1 << 3;
            if (chkPenOCxmitVHF55.Checked) val += 1 << 4;
            if (chkPenOCxmitVHF56.Checked) val += 1 << 5;
            if (chkPenOCxmitVHF57.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.VHF5, (byte)(val & 0x70), true);
            Penny.getPenny().setBandABitMask(Band.VHF5, (byte)val, true);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code
        }

        private void chkPenOCxmitVHF6_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkPenOCxmitVHF61.Checked) val += 1 << 0;
            if (chkPenOCxmitVHF62.Checked) val += 1 << 1;
            if (chkPenOCxmitVHF63.Checked) val += 1 << 2;
            if (chkPenOCxmitVHF64.Checked) val += 1 << 3;
            if (chkPenOCxmitVHF65.Checked) val += 1 << 4;
            if (chkPenOCxmitVHF66.Checked) val += 1 << 5;
            if (chkPenOCxmitVHF67.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.VHF6, (byte)(val & 0x70), true);
            Penny.getPenny().setBandABitMask(Band.VHF6, (byte)val, true);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code
        }

        private void chkPenOCxmitVHF7_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkPenOCxmitVHF71.Checked) val += 1 << 0;
            if (chkPenOCxmitVHF72.Checked) val += 1 << 1;
            if (chkPenOCxmitVHF73.Checked) val += 1 << 2;
            if (chkPenOCxmitVHF74.Checked) val += 1 << 3;
            if (chkPenOCxmitVHF75.Checked) val += 1 << 4;
            if (chkPenOCxmitVHF76.Checked) val += 1 << 5;
            if (chkPenOCxmitVHF77.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.VHF7, (byte)(val & 0x70), true);
            Penny.getPenny().setBandABitMask(Band.VHF7, (byte)val, true);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code
        }

        private void chkPenOCxmitVHF8_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkPenOCxmitVHF81.Checked) val += 1 << 0;
            if (chkPenOCxmitVHF82.Checked) val += 1 << 1;
            if (chkPenOCxmitVHF83.Checked) val += 1 << 2;
            if (chkPenOCxmitVHF84.Checked) val += 1 << 3;
            if (chkPenOCxmitVHF85.Checked) val += 1 << 4;
            if (chkPenOCxmitVHF86.Checked) val += 1 << 5;
            if (chkPenOCxmitVHF87.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.VHF8, (byte)(val & 0x70), true);
            Penny.getPenny().setBandABitMask(Band.VHF8, (byte)val, true);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code
        }

        private void chkPenOCxmitVHF9_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkPenOCxmitVHF91.Checked) val += 1 << 0;
            if (chkPenOCxmitVHF92.Checked) val += 1 << 1;
            if (chkPenOCxmitVHF93.Checked) val += 1 << 2;
            if (chkPenOCxmitVHF94.Checked) val += 1 << 3;
            if (chkPenOCxmitVHF95.Checked) val += 1 << 4;
            if (chkPenOCxmitVHF96.Checked) val += 1 << 5;
            if (chkPenOCxmitVHF97.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.VHF9, (byte)(val & 0x70), true);
            Penny.getPenny().setBandABitMask(Band.VHF9, (byte)val, true);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code
        }

        private void chkPenOCxmitVHF10_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkPenOCxmitVHF101.Checked) val += 1 << 0;
            if (chkPenOCxmitVHF102.Checked) val += 1 << 1;
            if (chkPenOCxmitVHF103.Checked) val += 1 << 2;
            if (chkPenOCxmitVHF104.Checked) val += 1 << 3;
            if (chkPenOCxmitVHF105.Checked) val += 1 << 4;
            if (chkPenOCxmitVHF106.Checked) val += 1 << 5;
            if (chkPenOCxmitVHF107.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.VHF10, (byte)(val & 0x70), true);
            Penny.getPenny().setBandABitMask(Band.VHF10, (byte)val, true);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code
        }

        private void chkPenOCxmitVHF11_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkPenOCxmitVHF111.Checked) val += 1 << 0;
            if (chkPenOCxmitVHF112.Checked) val += 1 << 1;
            if (chkPenOCxmitVHF113.Checked) val += 1 << 2;
            if (chkPenOCxmitVHF114.Checked) val += 1 << 3;
            if (chkPenOCxmitVHF115.Checked) val += 1 << 4;
            if (chkPenOCxmitVHF116.Checked) val += 1 << 5;
            if (chkPenOCxmitVHF117.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.VHF11, (byte)(val & 0x70), true);
            Penny.getPenny().setBandABitMask(Band.VHF11, (byte)val, true);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code
        }

        private void chkOCrcvLMW_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCrcvLMW1.Checked) val += 1 << 0;
            if (chkOCrcvLMW2.Checked) val += 1 << 1;
            if (chkOCrcvLMW3.Checked) val += 1 << 2;
            if (chkOCrcvLMW4.Checked) val += 1 << 3;
            if (chkOCrcvLMW5.Checked) val += 1 << 4;
            if (chkOCrcvLMW6.Checked) val += 1 << 5;
            if (chkOCrcvLMW7.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.BLMF, (byte)(val & 0x70), false); // 0000xxx
            Penny.getPenny().setBandABitMask(Band.BLMF, (byte)val, false);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkOCrcv120_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCrcv1201.Checked) val += 1 << 0;
            if (chkOCrcv1202.Checked) val += 1 << 1;
            if (chkOCrcv1203.Checked) val += 1 << 2;
            if (chkOCrcv1204.Checked) val += 1 << 3;
            if (chkOCrcv1205.Checked) val += 1 << 4;
            if (chkOCrcv1206.Checked) val += 1 << 5;
            if (chkOCrcv1207.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.B120M, (byte)(val & 0x70), false);
            Penny.getPenny().setBandABitMask(Band.B120M, (byte)val, false);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkOCrcv90_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCrcv901.Checked) val += 1 << 0;
            if (chkOCrcv902.Checked) val += 1 << 1;
            if (chkOCrcv903.Checked) val += 1 << 2;
            if (chkOCrcv904.Checked) val += 1 << 3;
            if (chkOCrcv905.Checked) val += 1 << 4;
            if (chkOCrcv906.Checked) val += 1 << 5;
            if (chkOCrcv907.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.B90M, (byte)(val & 0x70), false);
            Penny.getPenny().setBandABitMask(Band.B90M, (byte)val, false);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkOCrcv61_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCrcv611.Checked) val += 1 << 0;
            if (chkOCrcv612.Checked) val += 1 << 1;
            if (chkOCrcv613.Checked) val += 1 << 2;
            if (chkOCrcv614.Checked) val += 1 << 3;
            if (chkOCrcv615.Checked) val += 1 << 4;
            if (chkOCrcv616.Checked) val += 1 << 5;
            if (chkOCrcv617.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.B61M, (byte)(val & 0x70), false);
            Penny.getPenny().setBandABitMask(Band.B61M, (byte)val, false);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkOCrcv49_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCrcv491.Checked) val += 1 << 0;
            if (chkOCrcv492.Checked) val += 1 << 1;
            if (chkOCrcv493.Checked) val += 1 << 2;
            if (chkOCrcv494.Checked) val += 1 << 3;
            if (chkOCrcv495.Checked) val += 1 << 4;
            if (chkOCrcv496.Checked) val += 1 << 5;
            if (chkOCrcv497.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.B49M, (byte)(val & 0x70), false);
            Penny.getPenny().setBandABitMask(Band.B49M, (byte)val, false);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkOCrcv41_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCrcv411.Checked) val += 1 << 0;
            if (chkOCrcv412.Checked) val += 1 << 1;
            if (chkOCrcv413.Checked) val += 1 << 2;
            if (chkOCrcv414.Checked) val += 1 << 3;
            if (chkOCrcv415.Checked) val += 1 << 4;
            if (chkOCrcv416.Checked) val += 1 << 5;
            if (chkOCrcv417.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.B41M, (byte)(val & 0x70), false);
            Penny.getPenny().setBandABitMask(Band.B41M, (byte)val, false);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkOCrcv31_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCrcv311.Checked) val += 1 << 0;
            if (chkOCrcv312.Checked) val += 1 << 1;
            if (chkOCrcv313.Checked) val += 1 << 2;
            if (chkOCrcv314.Checked) val += 1 << 3;
            if (chkOCrcv315.Checked) val += 1 << 4;
            if (chkOCrcv316.Checked) val += 1 << 5;
            if (chkOCrcv317.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.B31M, (byte)(val & 0x70), false);
            Penny.getPenny().setBandABitMask(Band.B31M, (byte)val, false);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkOCrcv25_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCrcv251.Checked) val += 1 << 0;
            if (chkOCrcv252.Checked) val += 1 << 1;
            if (chkOCrcv253.Checked) val += 1 << 2;
            if (chkOCrcv254.Checked) val += 1 << 3;
            if (chkOCrcv255.Checked) val += 1 << 4;
            if (chkOCrcv256.Checked) val += 1 << 5;
            if (chkOCrcv257.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.B25M, (byte)(val & 0x70), false);
            Penny.getPenny().setBandABitMask(Band.B25M, (byte)val, false);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkOCrcv22_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCrcv221.Checked) val += 1 << 0;
            if (chkOCrcv222.Checked) val += 1 << 1;
            if (chkOCrcv223.Checked) val += 1 << 2;
            if (chkOCrcv224.Checked) val += 1 << 3;
            if (chkOCrcv225.Checked) val += 1 << 4;
            if (chkOCrcv226.Checked) val += 1 << 5;
            if (chkOCrcv227.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.B22M, (byte)(val & 0x70), false);
            Penny.getPenny().setBandABitMask(Band.B22M, (byte)val, false);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code  
        }

        private void chkOCrcv19_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCrcv191.Checked) val += 1 << 0;
            if (chkOCrcv192.Checked) val += 1 << 1;
            if (chkOCrcv193.Checked) val += 1 << 2;
            if (chkOCrcv194.Checked) val += 1 << 3;
            if (chkOCrcv195.Checked) val += 1 << 4;
            if (chkOCrcv196.Checked) val += 1 << 5;
            if (chkOCrcv197.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.B19M, (byte)(val & 0x70), false);
            Penny.getPenny().setBandABitMask(Band.B19M, (byte)val, false);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code  
        }

        private void chkOCrcv16_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCrcv161.Checked) val += 1 << 0;
            if (chkOCrcv162.Checked) val += 1 << 1;
            if (chkOCrcv163.Checked) val += 1 << 2;
            if (chkOCrcv164.Checked) val += 1 << 3;
            if (chkOCrcv165.Checked) val += 1 << 4;
            if (chkOCrcv166.Checked) val += 1 << 5;
            if (chkOCrcv167.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.B16M, (byte)(val & 0x70), false);
            Penny.getPenny().setBandABitMask(Band.B16M, (byte)val, false);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code  
        }

        private void chkOCrcv14_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCrcv141.Checked) val += 1 << 0;
            if (chkOCrcv142.Checked) val += 1 << 1;
            if (chkOCrcv143.Checked) val += 1 << 2;
            if (chkOCrcv144.Checked) val += 1 << 3;
            if (chkOCrcv145.Checked) val += 1 << 4;
            if (chkOCrcv146.Checked) val += 1 << 5;
            if (chkOCrcv147.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.B14M, (byte)(val & 0x70), false);
            Penny.getPenny().setBandABitMask(Band.B14M, (byte)val, false);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkOCrcv13_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCrcv131.Checked) val += 1 << 0;
            if (chkOCrcv132.Checked) val += 1 << 1;
            if (chkOCrcv133.Checked) val += 1 << 2;
            if (chkOCrcv134.Checked) val += 1 << 3;
            if (chkOCrcv135.Checked) val += 1 << 4;
            if (chkOCrcv136.Checked) val += 1 << 5;
            if (chkOCrcv137.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.B13M, (byte)(val & 0x70), false);
            Penny.getPenny().setBandABitMask(Band.B13M, (byte)val, false);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code  
        }

        private void chkOCrcv11_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCrcv111.Checked) val += 1 << 0;
            if (chkOCrcv112.Checked) val += 1 << 1;
            if (chkOCrcv113.Checked) val += 1 << 2;
            if (chkOCrcv114.Checked) val += 1 << 3;
            if (chkOCrcv115.Checked) val += 1 << 4;
            if (chkOCrcv116.Checked) val += 1 << 5;
            if (chkOCrcv117.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.B11M, (byte)(val & 0x70), false);
            Penny.getPenny().setBandABitMask(Band.B11M, (byte)val, false);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
        }

        private void chkOCxmitLMW_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCxmitLMW1.Checked) val += 1 << 0;
            if (chkOCxmitLMW2.Checked) val += 1 << 1;
            if (chkOCxmitLMW3.Checked) val += 1 << 2;
            if (chkOCxmitLMW4.Checked) val += 1 << 3;
            if (chkOCxmitLMW5.Checked) val += 1 << 4;
            if (chkOCxmitLMW6.Checked) val += 1 << 5;
            if (chkOCxmitLMW7.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.BLMF, (byte)(val & 0x70), true);
            Penny.getPenny().setBandABitMask(Band.BLMF, (byte)val, true);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code
        }

        private void chkOCxmit120_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCxmit1201.Checked) val += 1 << 0;
            if (chkOCxmit1202.Checked) val += 1 << 1;
            if (chkOCxmit1203.Checked) val += 1 << 2;
            if (chkOCxmit1204.Checked) val += 1 << 3;
            if (chkOCxmit1205.Checked) val += 1 << 4;
            if (chkOCxmit1206.Checked) val += 1 << 5;
            if (chkOCxmit1207.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.B120M, (byte)(val & 0x70), true);
            Penny.getPenny().setBandABitMask(Band.B120M, (byte)val, true);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code
        }

        private void chkOCxmit90_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCxmit901.Checked) val += 1 << 0;
            if (chkOCxmit902.Checked) val += 1 << 1;
            if (chkOCxmit903.Checked) val += 1 << 2;
            if (chkOCxmit904.Checked) val += 1 << 3;
            if (chkOCxmit905.Checked) val += 1 << 4;
            if (chkOCxmit906.Checked) val += 1 << 5;
            if (chkOCxmit907.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.B90M, (byte)(val & 0x70), true);
            Penny.getPenny().setBandABitMask(Band.B90M, (byte)val, true);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code
        }

        private void chkOCxmit61_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCxmit611.Checked) val += 1 << 0;
            if (chkOCxmit612.Checked) val += 1 << 1;
            if (chkOCxmit613.Checked) val += 1 << 2;
            if (chkOCxmit614.Checked) val += 1 << 3;
            if (chkOCxmit615.Checked) val += 1 << 4;
            if (chkOCxmit616.Checked) val += 1 << 5;
            if (chkOCxmit617.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.B61M, (byte)(val & 0x70), true);
            Penny.getPenny().setBandABitMask(Band.B61M, (byte)val, true);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code
        }

        private void chkOCxmit49_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCxmit491.Checked) val += 1 << 0;
            if (chkOCxmit492.Checked) val += 1 << 1;
            if (chkOCxmit493.Checked) val += 1 << 2;
            if (chkOCxmit494.Checked) val += 1 << 3;
            if (chkOCxmit495.Checked) val += 1 << 4;
            if (chkOCxmit496.Checked) val += 1 << 5;
            if (chkOCxmit497.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.B49M, (byte)(val & 0x70), true);
            Penny.getPenny().setBandABitMask(Band.B49M, (byte)val, true);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code
        }

        private void chkOCxmit41_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCxmit411.Checked) val += 1 << 0;
            if (chkOCxmit412.Checked) val += 1 << 1;
            if (chkOCxmit413.Checked) val += 1 << 2;
            if (chkOCxmit414.Checked) val += 1 << 3;
            if (chkOCxmit415.Checked) val += 1 << 4;
            if (chkOCxmit416.Checked) val += 1 << 5;
            if (chkOCxmit417.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.B41M, (byte)(val & 0x70), true);
            Penny.getPenny().setBandABitMask(Band.B41M, (byte)val, true);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code
        }

        private void chkOCxmit31_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCxmit311.Checked) val += 1 << 0;
            if (chkOCxmit312.Checked) val += 1 << 1;
            if (chkOCxmit313.Checked) val += 1 << 2;
            if (chkOCxmit314.Checked) val += 1 << 3;
            if (chkOCxmit315.Checked) val += 1 << 4;
            if (chkOCxmit316.Checked) val += 1 << 5;
            if (chkOCxmit317.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.B31M, (byte)(val & 0x70), true);
            Penny.getPenny().setBandABitMask(Band.B31M, (byte)val, true);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code
        }

        private void chkOCxmit25_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCxmit251.Checked) val += 1 << 0;
            if (chkOCxmit252.Checked) val += 1 << 1;
            if (chkOCxmit253.Checked) val += 1 << 2;
            if (chkOCxmit254.Checked) val += 1 << 3;
            if (chkOCxmit255.Checked) val += 1 << 4;
            if (chkOCxmit256.Checked) val += 1 << 5;
            if (chkOCxmit257.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.B25M, (byte)(val & 0x70), true);
            Penny.getPenny().setBandABitMask(Band.B25M, (byte)val, true);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code
        }

        private void chkOCxmit22_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCxmit221.Checked) val += 1 << 0;
            if (chkOCxmit222.Checked) val += 1 << 1;
            if (chkOCxmit223.Checked) val += 1 << 2;
            if (chkOCxmit224.Checked) val += 1 << 3;
            if (chkOCxmit225.Checked) val += 1 << 4;
            if (chkOCxmit226.Checked) val += 1 << 5;
            if (chkOCxmit227.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.B22M, (byte)(val & 0x70), true);
            Penny.getPenny().setBandABitMask(Band.B22M, (byte)val, true);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code
        }

        private void chkOCxmit19_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCxmit191.Checked) val += 1 << 0;
            if (chkOCxmit192.Checked) val += 1 << 1;
            if (chkOCxmit193.Checked) val += 1 << 2;
            if (chkOCxmit194.Checked) val += 1 << 3;
            if (chkOCxmit195.Checked) val += 1 << 4;
            if (chkOCxmit196.Checked) val += 1 << 5;
            if (chkOCxmit197.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.B19M, (byte)(val & 0x70), true);
            Penny.getPenny().setBandABitMask(Band.B19M, (byte)val, true);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code
        }

        private void chkOCxmit16_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCxmit161.Checked) val += 1 << 0;
            if (chkOCxmit162.Checked) val += 1 << 1;
            if (chkOCxmit163.Checked) val += 1 << 2;
            if (chkOCxmit164.Checked) val += 1 << 3;
            if (chkOCxmit165.Checked) val += 1 << 4;
            if (chkOCxmit166.Checked) val += 1 << 5;
            if (chkOCxmit167.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.B16M, (byte)(val & 0x70), true);
            Penny.getPenny().setBandABitMask(Band.B16M, (byte)val, true);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code
        }

        private void chkOCxmit14_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCxmit141.Checked) val += 1 << 0;
            if (chkOCxmit142.Checked) val += 1 << 1;
            if (chkOCxmit143.Checked) val += 1 << 2;
            if (chkOCxmit144.Checked) val += 1 << 3;
            if (chkOCxmit145.Checked) val += 1 << 4;
            if (chkOCxmit146.Checked) val += 1 << 5;
            if (chkOCxmit147.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.B14M, (byte)(val & 0x70), true);
            Penny.getPenny().setBandABitMask(Band.B14M, (byte)val, true);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code
        }

        private void chkOCxmit13_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCxmit131.Checked) val += 1 << 0;
            if (chkOCxmit132.Checked) val += 1 << 1;
            if (chkOCxmit133.Checked) val += 1 << 2;
            if (chkOCxmit134.Checked) val += 1 << 3;
            if (chkOCxmit135.Checked) val += 1 << 4;
            if (chkOCxmit136.Checked) val += 1 << 5;
            if (chkOCxmit137.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.B13M, (byte)(val & 0x70), true);
            Penny.getPenny().setBandABitMask(Band.B13M, (byte)val, true);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code
        }

        private void chkOCxmit11_CheckedChanged(object sender, EventArgs e)
        {
            int val = 0;
            if (chkOCxmit111.Checked) val += 1 << 0;
            if (chkOCxmit112.Checked) val += 1 << 1;
            if (chkOCxmit113.Checked) val += 1 << 2;
            if (chkOCxmit114.Checked) val += 1 << 3;
            if (chkOCxmit115.Checked) val += 1 << 4;
            if (chkOCxmit116.Checked) val += 1 << 5;
            if (chkOCxmit117.Checked) val += 1 << 6;

            Penny.getPenny().setBandBBitMask(Band.B11M, (byte)(val & 0x70), true);
            Penny.getPenny().setBandABitMask(Band.B11M, (byte)val, true);
            console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code
        }

        private void chkDisable6mLNAonTX_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.Disable6mLNAonTX = chkDisable6mLNAonTX.Checked;
        }

        private void chkDisable6mLNAonRX_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.Disable6mLNAonRX = chkDisable6mLNAonRX.Checked;
        }

        private void chkDisableHPFonTX_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.DisableHPFonTX = chkDisableHPFonTX.Checked;
            if (console.path_Illustrator != null)
                console.path_Illustrator.pi_Changed();
        }

        public bool AlexHPFBypass
        {
            get
            {
                if (chkAlexHPFBypass != null) return chkAlexHPFBypass.Checked;
                else return false;

            }
            set
            {
                if (chkAlexHPFBypass != null) chkAlexHPFBypass.Checked = value;
            }
        }

        private void chkAlexHPFBypass_CheckedChanged(object sender, EventArgs e)
        {
            console.AlexHPFBypass = chkAlexHPFBypass.Checked;
            if (console.path_Illustrator != null)
                console.path_Illustrator.pi_Changed();
        }

        public bool Alex2HPFBypass
        {
            get
            {
                if (chkAlex2HPFBypass != null) return chkAlex2HPFBypass.Checked;
                else return false;

            }
            set
            {
                if (chkAlex2HPFBypass != null) chkAlex2HPFBypass.Checked = value;
            }
        }

        private void chkAlex2HPFBypass_CheckedChanged(object sender, EventArgs e)
        {
            console.Alex2HPFBypass = chkAlex2HPFBypass.Checked;
        }

        private void tpGeneralCalibration_Paint(object sender, PaintEventArgs e)
        {
            panelRX2LevelCal.Visible = false;
        }

        private void chkShowAGC_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.ShowAGC = chkShowAGC.Checked;
        }

        private void chkSpectrumLine_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.SpectrumLine = chkSpectrumLine.Checked;
        }

        private void chkAGCDisplayHangLine_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.DisplayAGCHangLine = chkAGCDisplayHangLine.Checked;
        }

        private void chkAGCHangSpectrumLine_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.RX1HangSpectrumLine = chkAGCHangSpectrumLine.Checked;
        }

        private void chkDisplayRX2GainLine_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.DisplayRX2GainLine = chkDisplayRX2GainLine.Checked;
        }

        private void chkRX2GainSpectrumLine_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.RX2GainSpectrumLine = chkRX2GainSpectrumLine.Checked;
        }

        private void chkDisplayRX2HangLine_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.DisplayRX2HangLine = chkDisplayRX2HangLine.Checked;
        }

        private void chkRX2HangSpectrumLine_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.RX2HangSpectrumLine = chkRX2HangSpectrumLine.Checked;
        }

        private void chkFirmwareByp_CheckedChanged(object sender, EventArgs e)
        {
            firmware_bypass = chkFirmwareByp.Checked;
        }

        private void chkFullDiscovery_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (chkFullDiscovery.Checked) chkEnableStaticIP.Checked = false;

            NetworkIO.FastConnect = chkFullDiscovery.Checked;
        }

        private void chkStrictCharSpacing_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            NetworkIO.EnableCWKeyerSpacing(Convert.ToInt32(chkStrictCharSpacing.Checked));
        }

        private void chkRxOutOnTx_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (chkRxOutOnTx.Checked)
            {
                chkEXT1OutOnTx.Checked = false;
                chkEXT2OutOnTx.Checked = false;
            }
            Alex.RxOutOnTx = chkRxOutOnTx.Checked;
            if (console.path_Illustrator != null)
                console.path_Illustrator.pi_Changed();
        }

        private void chkSWRProtection_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.SWRProtection = chkSWRProtection.Checked;
            udSwrProtectionLimit.Enabled = chkSWRProtection.Checked;
        }

        public bool ATTOnTXChecked
        {
            get { return chkATTOnTX.Checked; }
            set { }
        }
        private void chkATTOnTX_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.ATTOnTX = chkATTOnTX.Checked;
        }

        private void chkAlex1_5BPHPF_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.Alex1_5BPHPFBypass = chkAlex1_5BPHPF.Checked;
        }

        private void chkAlex6_5BPHPF_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.Alex6_5BPHPFBypass = chkAlex6_5BPHPF.Checked;
        }

        private void chkAlex9_5BPHPF_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.Alex9_5BPHPFBypass = chkAlex9_5BPHPF.Checked;
        }

        private void chkAlex13BPHPF_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.Alex13BPHPFBypass = chkAlex13BPHPF.Checked;
        }

        private void chkAlex20BPHPF_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.Alex20BPHPFBypass = chkAlex20BPHPF.Checked;
        }

        private void chkAlex6BPHPF_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.Alex6BPHPFBypass = chkAlex6BPHPF.Checked;
        }

        private void chkAlex21_5BPHPF_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.Alex21_5BPHPFBypass = chkAlex21_5BPHPF.Checked;
        }

        private void chkAlex26_5BPHPF_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.Alex26_5BPHPFBypass = chkAlex26_5BPHPF.Checked;
        }

        private void chkAlex29_5BPHPF_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.Alex29_5BPHPFBypass = chkAlex29_5BPHPF.Checked;
        }

        private void chkAlex213BPHPF_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.Alex213BPHPFBypass = chkAlex213BPHPF.Checked;
        }

        private void chkAlex220BPHPF_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.Alex220BPHPFBypass = chkAlex220BPHPF.Checked;
        }

        private void chkAlex26BPHPF_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.Alex26BPHPFBypass = chkAlex26BPHPF.Checked;
        }

        private void tpPennyCtrl_Paint(object sender, PaintEventArgs e)
        {
            switch (console.CurrentHPSDRModel)
            {
                case HPSDRModel.HPSDR:
                    lblHFRxControl.Text = "J6 Receive Pins";
                    lblHFTxControl.Text = "J6 Transmit Pins";
                    lblVHFRxControl.Text = "J6 Receive Pins";
                    lblVHFTxControl.Text = "J6 Transmit Pins";
                    lblSWLRxControl.Text = "J6 Receive Pins";
                    lblSWLTxControl.Text = "J6 Transmit Pins";
                    break;
                case HPSDRModel.ANAN7000D:
                case HPSDRModel.ANAN8000D:
                case HPSDRModel.ANAN_G2:
                case HPSDRModel.ANAN_G2_1K:
                    lblHFRxControl.Text = "OC Receive Pins";
                    lblHFTxControl.Text = "OC Transmit Pins";
                    lblVHFRxControl.Text = "OC Receive Pins";
                    lblVHFTxControl.Text = "OC Transmit Pins";
                    lblSWLRxControl.Text = "OC Receive Pins";
                    lblSWLTxControl.Text = "OC Transmit Pins";
                    break;
                default:
                    lblHFRxControl.Text = "J16 Receive Pins";
                    lblHFTxControl.Text = "J16 Transmit Pins";
                    lblVHFRxControl.Text = "J16 Receive Pins";
                    lblVHFTxControl.Text = "J16 Transmit Pins";
                    lblSWLRxControl.Text = "J16 Receive Pins";
                    lblSWLTxControl.Text = "J16 Transmit Pins";
                    break;
            }
        }

        private void chkApolloPresent_CheckedChanged(object sender, EventArgs e)
        {
            if (chkApolloPresent.Checked)
            {
                if (chkAlexPresent.Checked) chkAlexPresent.Checked = false;

                NetworkIO.SelectApolloFilter(1);
                chkApolloFilter_CheckedChanged(this, EventArgs.Empty);
                chkApolloTuner_CheckedChanged(this, EventArgs.Empty);
            }
            else
                NetworkIO.SelectApolloFilter(0);

            console.ApolloPresent = chkApolloPresent.Checked;
        }

        private void chkApolloFilter_CheckedChanged(object sender, EventArgs e)
        {
            if (chkApolloFilter.Checked) NetworkIO.EnableApolloFilter(1);
            else NetworkIO.EnableApolloFilter(0);
        }

        private void chkApolloTuner_CheckedChanged(object sender, EventArgs e)
        {
            console.ApolloTunerEnabled = chkApolloTuner.Checked;
        }

        private void chkLevelFades_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (chkLevelFades.Checked)
            {
                console.radio.GetDSPRX(0, 0).RXAMDFadeLevel = 1;
                console.radio.GetDSPRX(0, 1).RXAMDFadeLevel = 1;
            }
            else
            {
                console.radio.GetDSPRX(0, 0).RXAMDFadeLevel = 0;
                console.radio.GetDSPRX(0, 1).RXAMDFadeLevel = 0;
            }
        }

        private void radLSBUSB_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (radLSBUSB.Checked)
            {
                console.radio.GetDSPRX(0, 0).RXAMDSBMode = 0;
                console.radio.GetDSPRX(0, 1).RXAMDSBMode = 0;
            }
        }

        private void radLSB_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (radLSB.Checked)
            {
                console.radio.GetDSPRX(0, 0).RXAMDSBMode = 1;
                console.radio.GetDSPRX(0, 1).RXAMDSBMode = 1;
            }
        }

        private void radUSB_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (radUSB.Checked)
            {
                console.radio.GetDSPRX(0, 0).RXAMDSBMode = 2;
                console.radio.GetDSPRX(0, 1).RXAMDSBMode = 2;
            }
        }

        private void chkRX2LevelFades_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (chkRX2LevelFades.Checked)
            {
                console.radio.GetDSPRX(1, 0).RXAMDFadeLevel = 1;
                console.radio.GetDSPRX(1, 1).RXAMDFadeLevel = 1;
            }
            else
            {
                console.radio.GetDSPRX(1, 0).RXAMDFadeLevel = 0;
                console.radio.GetDSPRX(1, 1).RXAMDFadeLevel = 0;
            }
        }

        private void radRX2LSBUSB_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (radRX2LSBUSB.Checked)
            {
                console.radio.GetDSPRX(1, 0).RXAMDSBMode = 0;
                console.radio.GetDSPRX(1, 1).RXAMDSBMode = 0;
            }
        }

        private void radRX2LSB_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (radRX2LSB.Checked)
            {
                console.radio.GetDSPRX(1, 0).RXAMDSBMode = 1;
                console.radio.GetDSPRX(1, 1).RXAMDSBMode = 1;
            }
        }

        private void radRX2USB_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (radRX2USB.Checked)
            {
                console.radio.GetDSPRX(1, 0).RXAMDSBMode = 2;
                console.radio.GetDSPRX(1, 1).RXAMDSBMode = 2;
            }
        }
        private string _sAutoCailbratePAOldSelectedProfile = "";
        private void chkAutoPACalibrate_CheckedChanged(object sender, EventArgs e)
        {
            if (chkAutoPACalibrate.Checked)
            {
                panelAutoPACalibrate.Visible = true;

                _sAutoCailbratePAOldSelectedProfile = comboPAProfile.Text;
                updatePAProfileCombo(_sPA_PROFILE_BYPASS); //MW0LGE_22b
            }
            else
            {
                panelAutoPACalibrate.Visible = false;

                updatePAProfileCombo(_sAutoCailbratePAOldSelectedProfile); //MW0LGE_22b
            }
        }
        //MW0LGE_22b
        private bool ADCsLinked
        {
            set { lblADCLinked.Visible = value; }
        }

        private void updateConsoleWithAttenuationInfo()
        {
            if (initializing) return;

            chkHermesStepAttenuator_CheckedChanged(this, EventArgs.Empty);
            udHermesStepAttenuatorData_ValueChanged(this, EventArgs.Empty);

            chkRX2StepAtt_CheckedChanged(this, EventArgs.Empty);
            udHermesStepAttenuatorDataRX2_ValueChanged(this, EventArgs.Empty);
        }

        private void chkHermesStepAttenuator_CheckedChanged(object sender, EventArgs e)
        {
            console.RX1StepAttPresent = chkHermesStepAttenuator.Checked;

            if (chkHermesStepAttenuator.Checked)
            {
                udHermesStepAttenuatorData_ValueChanged(this, EventArgs.Empty);
            }

            CheckBoxTS chk = sender as CheckBoxTS;
            if (chk != null) // only if we click it //MW0LGE [2.9.0.6]
            {
                int rx1 = -1, rx2 = -1, sync1 = -1, sync2 = -1, psrx = -1, pstx = -1;
                console.GetDDC(out rx1, out rx2, out sync1, out sync2, out psrx, out pstx);

                int nRX1ADCinUse = console.GetADCInUse(rx1);
                int nRX2ADCinUse = console.GetADCInUse(rx2);
                if (nRX1ADCinUse == nRX2ADCinUse && chkRX2StepAtt.Checked != chkHermesStepAttenuator.Checked) chkRX2StepAtt.Checked = chkHermesStepAttenuator.Checked;
            }

            //wd5y
            if (console.sliderForm != null)
            {
                console.sliderForm.chkATT1.Checked = chkHermesStepAttenuator.Checked;
            }
            //wd5y
        }

        private bool _updatingRX1HermiesStepAttData = false;
        private void udHermesStepAttenuatorData_ValueChanged(object sender, EventArgs e)
        {
            if (_updatingRX1HermiesStepAttData) return;
            _updatingRX1HermiesStepAttData = true;
            console.RX1AttenuatorData = (int)udHermesStepAttenuatorData.Value;

            //MW0LGE_21f
            if (AlexPresent &&
                console.CurrentHPSDRModel != HPSDRModel.ANAN10 &&
                console.CurrentHPSDRModel != HPSDRModel.ANAN10E &&
                console.CurrentHPSDRModel != HPSDRModel.ANAN7000D &&
                console.CurrentHPSDRModel != HPSDRModel.ANAN8000D &&
                console.CurrentHPSDRModel != HPSDRModel.ORIONMKII &&
                console.CurrentHPSDRModel != HPSDRModel.ANAN_G2 &&
                console.CurrentHPSDRModel != HPSDRModel.ANAN_G2_1K)
                udHermesStepAttenuatorData.Maximum = (decimal)61;
            else udHermesStepAttenuatorData.Maximum = (decimal)31;
            _updatingRX1HermiesStepAttData = false;
        }

        private void chkRX2StepAtt_CheckedChanged(object sender, EventArgs e)
        {
            console.RX2StepAttPresent = chkRX2StepAtt.Checked;

            if (chkRX2StepAtt.Checked)
            {
                udHermesStepAttenuatorDataRX2_ValueChanged(this, EventArgs.Empty);
            }

            CheckBoxTS chk = sender as CheckBoxTS;
            if (chk != null) // only if we click it //MW0LGE [2.9.0.6]
            {
                int rx1 = -1, rx2 = -1, sync1 = -1, sync2 = -1, psrx = -1, pstx = -1;
                console.GetDDC(out rx1, out rx2, out sync1, out sync2, out psrx, out pstx);

                int nRX1ADCinUse = console.GetADCInUse(rx1);
                int nRX2ADCinUse = console.GetADCInUse(rx2);
                if (nRX1ADCinUse == nRX2ADCinUse && chkHermesStepAttenuator.Checked != chkRX2StepAtt.Checked) chkHermesStepAttenuator.Checked = chkRX2StepAtt.Checked;
            }

            //wd5y
            if (console.sliderForm != null)
            {
                console.sliderForm.chkATT2.Checked = chkRX2StepAtt.Checked;
            }
            //wd5y
        }
        private bool _updatingRX2HermiesStepAttData = false;
        private void udHermesStepAttenuatorDataRX2_ValueChanged(object sender, EventArgs e)
        {
            if (_updatingRX2HermiesStepAttData) return;
            _updatingRX2HermiesStepAttData = true;
            console.RX2AttenuatorData = (int)udHermesStepAttenuatorDataRX2.Value;

            //MW0LGE_21f
            if (AlexPresent &&
                console.CurrentHPSDRModel != HPSDRModel.ANAN10 &&
                console.CurrentHPSDRModel != HPSDRModel.ANAN10E &&
                console.CurrentHPSDRModel != HPSDRModel.ANAN7000D &&
                console.CurrentHPSDRModel != HPSDRModel.ANAN8000D &&
                console.CurrentHPSDRModel != HPSDRModel.ORIONMKII &&
                console.CurrentHPSDRModel != HPSDRModel.ANAN_G2 &&
                console.CurrentHPSDRModel != HPSDRModel.ANAN_G2_1K)
                udHermesStepAttenuatorDataRX2.Maximum = (decimal)61;
            else udHermesStepAttenuatorDataRX2.Maximum = (decimal)31;
            _updatingRX2HermiesStepAttData = false;
        }

        private void udAlex160mLPFStart_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex160mLPFStart.Value >= udAlex160mLPFEnd.Value + (decimal)0.000001)
            {
                udAlex160mLPFEnd.Value = udAlex160mLPFStart.Value + (decimal)0.000001;
            }
        }

        private void udAlex160mLPFEnd_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex160mLPFEnd.Value <= udAlex160mLPFStart.Value)
            {
                udAlex160mLPFStart.Value = udAlex160mLPFEnd.Value - (decimal)0.000001;
            }
            else if (udAlex160mLPFEnd.Value >= udAlex80mLPFStart.Value)
            {
                udAlex80mLPFStart.Value = udAlex160mLPFEnd.Value + (decimal)0.000001;
            }
        }

        private void udAlex80mLPFStart_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex80mLPFStart.Value <= udAlex160mLPFEnd.Value)
            {
                udAlex160mLPFEnd.Value = udAlex80mLPFStart.Value - (decimal)0.000001;
            }
        }

        private void udAlex80mLPFEnd_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex80mLPFEnd.Value >= udAlex40mLPFStart.Value)
            {
                udAlex40mLPFStart.Value = udAlex80mLPFEnd.Value + (decimal)0.000001;
            }
        }

        private void udAlex40mLPFStart_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex40mLPFStart.Value <= udAlex80mLPFEnd.Value)
            {
                udAlex80mLPFEnd.Value = udAlex40mLPFStart.Value - (decimal)0.000001;
            }
        }

        private void udAlex40mLPFEnd_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex40mLPFEnd.Value >= udAlex20mLPFStart.Value)
            {
                udAlex20mLPFStart.Value = udAlex40mLPFEnd.Value + (decimal)0.000001;
            }
        }

        private void udAlex20mLPFStart_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex20mLPFStart.Value <= udAlex40mLPFEnd.Value)
            {
                udAlex40mLPFEnd.Value = udAlex20mLPFStart.Value - (decimal)0.000001;
            }
        }

        private void udAlex20mLPFEnd_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex20mLPFEnd.Value >= udAlex15mLPFStart.Value)
            {
                udAlex15mLPFStart.Value = udAlex20mLPFEnd.Value + (decimal)0.000001;
            }
        }

        private void udAlex15mLPFStart_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex15mLPFStart.Value <= udAlex20mLPFEnd.Value)
            {
                udAlex20mLPFEnd.Value = udAlex15mLPFStart.Value - (decimal)0.000001;
            }
        }

        private void udAlex15mLPFEnd_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex15mLPFEnd.Value >= udAlex10mLPFStart.Value)
            {
                udAlex10mLPFStart.Value = udAlex15mLPFEnd.Value + (decimal)0.000001;
            }
        }

        private void udAlex10mLPFStart_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex10mLPFStart.Value <= udAlex15mLPFEnd.Value)
            {
                udAlex15mLPFEnd.Value = udAlex10mLPFStart.Value - (decimal)0.000001;
            }
        }

        private void udAlex10mLPFEnd_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex10mLPFEnd.Value >= udAlex6mLPFStart.Value)
            {
                udAlex6mLPFStart.Value = udAlex10mLPFEnd.Value + (decimal)0.000001;
            }
        }

        private void udAlex6mLPFStart_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex6mLPFStart.Value <= udAlex10mLPFEnd.Value)
            {
                udAlex10mLPFEnd.Value = udAlex6mLPFStart.Value - (decimal)0.000001;
            }
        }

        private void udAlex1_5HPFStart_ValueChanged(object sender, EventArgs e)
        {

        }

        private void udAlex1_5HPFEnd_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex1_5HPFEnd.Value >= udAlex6_5HPFStart.Value)
            {
                udAlex6_5HPFStart.Value = udAlex1_5HPFEnd.Value + (decimal)0.000001;
            }
        }

        private void udAlex6_5HPFStart_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex6_5HPFStart.Value <= udAlex1_5HPFEnd.Value)
            {
                udAlex1_5HPFEnd.Value = udAlex6_5HPFStart.Value - (decimal)0.000001;
            }
        }

        private void udAlex6_5HPFEnd_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex6_5HPFEnd.Value >= udAlex9_5HPFStart.Value)
            {
                udAlex9_5HPFStart.Value = udAlex6_5HPFEnd.Value + (decimal)0.000001;
            }
        }

        private void udAlex9_5HPFStart_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex9_5HPFStart.Value <= udAlex6_5HPFEnd.Value)
            {
                udAlex6_5HPFEnd.Value = udAlex9_5HPFStart.Value - (decimal)0.000001;
            }
        }

        private void udAlex9_5HPFEnd_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex9_5HPFEnd.Value >= udAlex13HPFStart.Value)
            {
                udAlex13HPFStart.Value = udAlex9_5HPFEnd.Value + (decimal)0.000001;
            }
        }

        private void udAlex13HPFStart_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex13HPFStart.Value <= udAlex9_5HPFEnd.Value)
            {
                udAlex9_5HPFEnd.Value = udAlex13HPFStart.Value - (decimal)0.000001;
            }
        }

        private void udAlex13HPFEnd_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex13HPFEnd.Value >= udAlex20HPFStart.Value)
            {
                udAlex20HPFStart.Value = udAlex13HPFEnd.Value + (decimal)0.000001;
            }
        }

        private void udAlex20HPFStart_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex20HPFStart.Value <= udAlex13HPFEnd.Value)
            {
                udAlex13HPFEnd.Value = udAlex20HPFStart.Value - (decimal)0.000001;
            }
        }

        private void udAlex20HPFEnd_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex20HPFEnd.Value >= udAlex6BPFStart.Value)
            {
                udAlex6BPFStart.Value = udAlex20HPFEnd.Value + (decimal)0.000001;
            }
        }

        private void udAlex6BPFStart_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex6BPFStart.Value <= udAlex20HPFEnd.Value)
            {
                udAlex20HPFEnd.Value = udAlex6BPFStart.Value - (decimal)0.000001;
            }
        }

        private void udAlex6BPFEnd_ValueChanged(object sender, EventArgs e)
        {

        }

        private void udAlex21_5HPFStart_ValueChanged(object sender, EventArgs e)
        {

        }

        private void udAlex21_5HPFEnd_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex21_5HPFEnd.Value >= udAlex26_5HPFStart.Value)
            {
                udAlex26_5HPFStart.Value = udAlex21_5HPFEnd.Value + (decimal)0.000001;
            }
        }

        private void udAlex26_5HPFStart_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex26_5HPFStart.Value <= udAlex21_5HPFEnd.Value)
            {
                udAlex21_5HPFEnd.Value = udAlex26_5HPFStart.Value - (decimal)0.000001;
            }
        }

        private void udAlex26_5HPFEnd_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex26_5HPFEnd.Value >= udAlex29_5HPFStart.Value)
            {
                udAlex29_5HPFStart.Value = udAlex26_5HPFEnd.Value + (decimal)0.000001;
            }
        }

        private void udAlex29_5HPFStart_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex29_5HPFStart.Value <= udAlex26_5HPFEnd.Value)
            {
                udAlex26_5HPFEnd.Value = udAlex29_5HPFStart.Value - (decimal)0.000001;
            }
        }

        private void udAlex29_5HPFEnd_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex29_5HPFEnd.Value >= udAlex213HPFStart.Value)
            {
                udAlex213HPFStart.Value = udAlex29_5HPFEnd.Value + (decimal)0.000001;
            }
        }

        private void udAlex213HPFStart_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex213HPFStart.Value <= udAlex29_5HPFEnd.Value)
            {
                udAlex29_5HPFEnd.Value = udAlex213HPFStart.Value - (decimal)0.000001;
            }
        }

        private void udAlex213HPFEnd_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex213HPFEnd.Value >= udAlex220HPFStart.Value)
            {
                udAlex220HPFStart.Value = udAlex213HPFEnd.Value + (decimal)0.000001;
            }
        }

        private void udAlex220HPFStart_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex220HPFStart.Value <= udAlex213HPFEnd.Value)
            {
                udAlex213HPFEnd.Value = udAlex220HPFStart.Value - (decimal)0.000001;
            }
        }

        private void udAlex220HPFEnd_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex220HPFEnd.Value >= udAlex26BPFStart.Value)
            {
                udAlex26BPFStart.Value = udAlex220HPFEnd.Value + (decimal)0.000001;
            }
        }

        private void udAlex26BPFStart_ValueChanged(object sender, EventArgs e)
        {
            if (udAlex26BPFStart.Value <= udAlex220HPFEnd.Value)
            {
                udAlex220HPFEnd.Value = udAlex26BPFStart.Value - (decimal)0.000001;
            }
        }

        private void udAlex26BPFEnd_ValueChanged(object sender, EventArgs e)
        {

        }

        private void chkSWRTuneProtection_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.DisableSWRonTune = chkSWRTuneProtection.Checked;
            udTunePowerSwrIgnore.Enabled = chkSWRTuneProtection.Checked;
        }

        private void tbDisplayFFTSize_Scroll(object sender, EventArgs e)
        {
            if (initializing) return;
            if (console._spectrum_mutex != null) console._spectrum_mutex.WaitOne();

            console.specRX.GetSpecRX(0).FFTSize = (int)(4096 * Math.Pow(2, Math.Floor((double)(tbDisplayFFTSize.Value))));

            console.UpdateRXSpectrumDisplayVars();
            double bin_width = (double)Display.SampleRateRX1 / (double)console.specRX.GetSpecRX(0).FFTSize;
            lblDisplayBinWidth.Text = bin_width.ToString("N3");
            Display.RX1FFTSizeOffset = tbDisplayFFTSize.Value * 2;

            Display.FastAttackNoiseFloorRX1 = true;

            if (console._spectrum_mutex != null) console._spectrum_mutex.ReleaseMutex();

            console.InitFFTFillTime(1);//[2.10.1.0]MW0LGE
        }

        private void tbRX2DisplayFFTSize_Scroll(object sender, EventArgs e)
        {
            if (initializing) return;
            if (console._spectrum_mutex != null) console._spectrum_mutex.WaitOne();

            console.specRX.GetSpecRX(1).FFTSize = (int)(4096 * Math.Pow(2, Math.Floor((double)(tbRX2DisplayFFTSize.Value))));
            double bin_width = (double)Display.SampleRateRX2 / (double)console.specRX.GetSpecRX(1).FFTSize;
            lblRX2DisplayBinWidth.Text = bin_width.ToString("N3");

            Display.RX2FFTSizeOffset = tbRX2DisplayFFTSize.Value * 2;
            Display.FastAttackNoiseFloorRX2 = true;

            if (console._spectrum_mutex != null) console._spectrum_mutex.ReleaseMutex();

            console.InitFFTFillTime(2);//[2.10.1.0]MW0LGE
        }

        private void comboDispWinType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.specRX.GetSpecRX(0).WindowType = comboDispWinType.SelectedIndex;
            console.UpdateRXSpectrumDisplayVars();
            console.specRX.GetSpecRX(cmaster.inid(1, 0)).WindowType = comboDispWinType.SelectedIndex;
            console.UpdateTXSpectrumDisplayVars();
        }

        private void comboRX2DispWinType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.specRX.GetSpecRX(1).WindowType = comboRX2DispWinType.SelectedIndex;
        }

        private void udDSPNBTransition_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(0, 0).NBTau = 0.001 * (double)udDSPNBTransition.Value;
            console.radio.GetDSPRX(1, 0).NBTau = 0.001 * (double)udDSPNBTransition.Value;
        }

        private void udDSPNBLead_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(0, 0).NBAdvTime = 0.001 * (double)udDSPNBLead.Value;
            console.radio.GetDSPRX(1, 0).NBAdvTime = 0.001 * (double)udDSPNBLead.Value;
        }

        private void udDSPNBLag_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(0, 0).NBHangTime = 0.001 * (double)udDSPNBLag.Value;
            console.radio.GetDSPRX(1, 0).NBHangTime = 0.001 * (double)udDSPNBLag.Value;
        }

        private void chkCBlock_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (chkCBlock.Checked)
            {
                console.radio.GetDSPRX(0, 0).RXCBLRun = true;
                console.radio.GetDSPRX(0, 1).RXCBLRun = true;
            }
            else
            {
                console.radio.GetDSPRX(0, 0).RXCBLRun = false;
                console.radio.GetDSPRX(0, 1).RXCBLRun = false;
            }
        }

        private void chkRX2CBlock_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (chkRX2CBlock.Checked)
            {
                console.radio.GetDSPRX(1, 0).RXCBLRun = true;
                console.radio.GetDSPRX(1, 1).RXCBLRun = true;
            }
            else
            {
                console.radio.GetDSPRX(1, 0).RXCBLRun = false;
                console.radio.GetDSPRX(1, 1).RXCBLRun = false;
            }
        }

        private void btnConfigure_Click(object sender, EventArgs e)
        {
            if (ConfigMidi2Cat == null)
            {
                console.Midi2Cat.CloseMidi2Cat();
                ConfigMidi2Cat = new Midi2Cat.Midi2CatSetupForm(console.Midi2Cat.Midi2CatDbFile);
                ConfigMidi2Cat.Show();
                ConfigMidi2Cat.Focus();
                ConfigMidi2Cat.FormClosed += new FormClosedEventHandler(ConfigMidi2CatSetupClosed);
            }
        }

        private void ConfigMidi2CatSetupClosed(object sender, FormClosedEventArgs e)
        {
            if (ConfigMidi2Cat != null)
            {
                ConfigMidi2Cat.Dispose();
                ConfigMidi2Cat = null;
                console.Midi2Cat.OpenMidi2Cat();
            }
        }

        private void btnSetIPAddr_Click(object sender, EventArgs e)
        {
            if (initializing) return;
            if (radStaticIP1.Checked)
            {
                console.HPSDRNetworkIPAddr = udStaticIP1.Text + "." + udStaticIP2.Text + "." +
                                             udStaticIP3.Text + "." + udStaticIP4.Text;
            }
            if (radStaticIP2.Checked)
            {
                console.HPSDRNetworkIPAddr = udStaticIP5.Text + "." + udStaticIP6.Text + "." +
                                             udStaticIP7.Text + "." + udStaticIP8.Text;
            }
            if (radStaticIP3.Checked)
            {
                console.HPSDRNetworkIPAddr = udStaticIP9.Text + "." + udStaticIP10.Text + "." +
                                             udStaticIP11.Text + "." + udStaticIP12.Text;
            }
            if (radStaticIP4.Checked)
            {
                console.HPSDRNetworkIPAddr = udStaticIP13.Text + "." + udStaticIP14.Text + "." +
                                             udStaticIP15.Text + "." + udStaticIP16.Text;
            }
        }

        private void chkEnableStaticIP_CheckedChanged(object sender, EventArgs e)
        {
            if (chkEnableStaticIP.Checked) chkFullDiscovery.Checked = false;
            NetworkIO.enableStaticIP = chkEnableStaticIP.Checked;
        }

        private void chkRX1WaterfallAGC_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.RX1WaterfallAGC = chkRX1WaterfallAGC.Checked;
            udDisplayWaterfallLowLevel.Enabled = !chkRX1WaterfallAGC.Checked;
            lblWaterfallAGCOffsetRX1.Enabled = chkRX1WaterfallAGC.Checked;
            udWaterfallAGCOffsetRX1.Enabled = chkRX1WaterfallAGC.Checked;
            chkWaterfallUseNFForAGCRX1.Enabled = chkRX1WaterfallAGC.Checked;
        }

        private void chkRX2WaterfallAGC_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.RX2WaterfallAGC = chkRX2WaterfallAGC.Checked;
            udRX2DisplayWaterfallLowLevel.Enabled = !chkRX2WaterfallAGC.Checked;
            lblWaterfallAGCOffsetRX2.Enabled = chkRX2WaterfallAGC.Checked;
            udWaterfallAGCOffsetRX2.Enabled = chkRX2WaterfallAGC.Checked;
            chkWaterfallUseNFForAGCRX2.Enabled = chkRX2WaterfallAGC.Checked;
        }

        private void chkPAValues_CheckedChanged(object sender, EventArgs e)
        {
            panelPAValues.Visible = chkPAValues.Checked;
            console.PAValues = chkPAValues.Checked;
        }

        private void btnResetPAValues_Click(object sender, EventArgs e)
        {
            textDCVolts.Text = "";
            textFwdADCValue.Text = "";
            textDriveFwdADCValue.Text = "";
            textFwdVoltage.Text = "";
            textDrivePower.Text = "";
            textPAFwdPower.Text = "";
            textPARevPower.Text = "";
            textRevADCValue.Text = "";
            textRevVoltage.Text = "";
        }

        private void btnResetWattMeterValues_Click(object sender, EventArgs e)
        {
            switch (console.CurrentHPSDRModel)              // G8NJJ will need more work for ANAN_G2_1K (1KW PA)
            {
                case HPSDRModel.ANAN10:
                case HPSDRModel.ANAN10E:
                    ud10PA1W.Value = 1;
                    ud10PA2W.Value = 2;
                    ud10PA3W.Value = 3;
                    ud10PA4W.Value = 4;
                    ud10PA5W.Value = 5;
                    ud10PA6W.Value = 6;
                    ud10PA7W.Value = 7;
                    ud10PA8W.Value = 8;
                    ud10PA9W.Value = 9;
                    ud10PA10W.Value = 10;
                    ud10PA11W.Value = 11;
                    ud10PA12W.Value = 12;
                    ud10PA13W.Value = 13;
                    ud10PA14W.Value = 14;
                    break;
                case HPSDRModel.ANAN8000D:
                    ud200PA20W.Value = 20;
                    ud200PA40W.Value = 40;
                    ud200PA60W.Value = 60;
                    ud200PA80W.Value = 80;
                    ud200PA100W.Value = 100;
                    ud200PA120W.Value = 120;
                    ud200PA140W.Value = 140;
                    ud200PA160W.Value = 160;
                    ud200PA180W.Value = 180;
                    ud200PA200W.Value = 200;
                    ud200PA220W.Value = 220;
                    ud200PA240W.Value = 240;
                    ud200PA260W.Value = 260;
                    ud200PA280W.Value = 280;
                    break;
                default:
                    ud100PA10W.Value = 10;
                    ud100PA20W.Value = 20;
                    ud100PA30W.Value = 30;
                    ud100PA40W.Value = 40;
                    ud100PA50W.Value = 50;
                    ud100PA60W.Value = 60;
                    ud100PA70W.Value = 70;
                    ud100PA80W.Value = 80;
                    ud100PA90W.Value = 90;
                    ud100PA100W.Value = 100;
                    ud100PA110W.Value = 110;
                    ud100PA120W.Value = 120;
                    ud100PA130W.Value = 130;
                    ud100PA140W.Value = 140;
                    break;
            }
        }

        private void comboDSPRxWindow_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            int wintype = comboDSPRxWindow.SelectedIndex;
            if (wintype < 0)
            {
                wintype = 1;
                comboDSPRxWindow.Text = "BH - 7";
            }
            console.radio.GetDSPRX(0, 0).RXBandpassWindow = wintype;
            console.radio.GetDSPRX(0, 1).RXBandpassWindow = wintype;
            console.radio.GetDSPRX(1, 0).RXBandpassWindow = wintype;

            Display.UpdateMNFminWidth(); //[2.10.3.4]MW0LGE
        }

        private void comboDSPTxWindow_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            int wintype = comboDSPTxWindow.SelectedIndex;
            if (wintype < 0)
            {
                wintype = 1;
                comboDSPTxWindow.Text = "BH - 7";
            }
            console.radio.GetDSPTX(0).TXBandpassWindow = wintype;
        }

        private void radSaturn3p5mm_CheckedChanged(object sender, EventArgs e)
        {
            if (radSaturn3p5mm.Checked)
                NetworkIO.SetMicXlr(0);
            else NetworkIO.SetMicXlr(1);
        }

        private void radOrionPTTOff_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.MicPTTDisabled = radOrionPTTOff.Checked;
        }

        private void radOrionMicTip_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (radOrionMicTip.Checked)
                NetworkIO.SetMicTipRing(0);
            else NetworkIO.SetMicTipRing(1);
        }

        private void radOrionBiasOn_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (radOrionBiasOn.Checked)
                NetworkIO.SetMicBias(1);
            else NetworkIO.SetMicBias(0);
        }

        private void chkEXT1OutOnTx_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (chkEXT1OutOnTx.Checked)
            {
                chkRxOutOnTx.Checked = false;
                chkEXT2OutOnTx.Checked = false;
            }
            Alex.Ext1OutOnTx = chkEXT1OutOnTx.Checked;
            if (console.path_Illustrator != null)
                console.path_Illustrator.pi_Changed();
        }

        private void chkEXT2OutOnTx_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (chkEXT2OutOnTx.Checked)
            {
                chkRxOutOnTx.Checked = false;
                chkEXT1OutOnTx.Checked = false;
            }
            Alex.Ext2OutOnTx = chkEXT2OutOnTx.Checked;
            if (console.path_Illustrator != null)
                console.path_Illustrator.pi_Changed();
        }

        private void udTXGenScale_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            switch (cmboSigGenTXMode.Text)
            {
                case "Tone":
                    console.radio.GetDSPTX(0).TXPreGenToneMag = Math.Pow(10, (double)udTXGenScale.Value / 20.0);
                    break;
                case "Noise":
                    console.radio.GetDSPTX(0).TXPreGenNoiseMag = Math.Pow(10, (double)udTXGenScale.Value / 20.0);
                    break;
                case "Sweep":
                    console.radio.GetDSPTX(0).TXPreGenSweepMag = Math.Pow(10, (double)udTXGenScale.Value / 20.0);
                    break;
                case "Sawtooth":
                    console.radio.GetDSPTX(0).TXPreGenSawtoothMag = Math.Pow(10, (double)udTXGenScale.Value / 20.0);
                    break;
                case "Triangle":
                    console.radio.GetDSPTX(0).TXPreGenTriangleMag = Math.Pow(10, (double)udTXGenScale.Value / 20.0);
                    break;
                case "Pulse":
                    console.radio.GetDSPTX(0).TXPreGenPulseMag = Math.Pow(10, (double)udTXGenScale.Value / 20.0);
                    break;
            }
        }

        private void udTXGenFreq_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            switch (cmboSigGenTXMode.Text)
            {
                case "Tone":
                    console.radio.GetDSPTX(0).TXPreGenToneFreq = (double)udTXGenFreq.Value;
                    break;
                case "Sawtooth":
                    console.radio.GetDSPTX(0).TXPreGenSawtoothFreq = (double)udTXGenFreq.Value;
                    break;
                case "Triangle":
                    console.radio.GetDSPTX(0).TXPreGenTriangleFreq = (double)udTXGenFreq.Value;
                    break;
                case "Pulse":
                    console.radio.GetDSPTX(0).TXPreGenPulseToneFreq = (double)udTXGenFreq.Value;
                    break;
            }
        }

        private void udTXGenSweepLow_ValueChanged(object sender, EventArgs e)
        {
            console.radio.GetDSPTX(0).TXPreGenSweepFreq1 = (double)udTXGenSweepLow.Value;
        }

        private void udTXGenSweepHigh_ValueChanged(object sender, EventArgs e)
        {
            console.radio.GetDSPTX(0).TXPreGenSweepFreq2 = (double)udTXGenSweepHigh.Value;
        }

        private void udTXGenSweepRate_ValueChanged(object sender, EventArgs e)
        {
            console.radio.GetDSPTX(0).TXPreGenSweepRate = (double)udTXGenSweepRate.Value;
        }

        private void chkSigGenRX1_CheckedChanged(object sender, EventArgs e)
        {
            cmboSigGenRXMode_SelectedIndexChanged(this, EventArgs.Empty);
        }

        private void udRXGenScale_ValueChanged(object sender, EventArgs e)
        {
            switch (cmboSigGenRXMode.Text)
            {
                case "Tone":
                    console.radio.GetDSPRX(0, 0).RXPreGenToneMag = Math.Pow(10, (double)udRXGenScale.Value / 20.0);
                    console.radio.GetDSPRX(1, 0).RXPreGenToneMag = Math.Pow(10, (double)udRXGenScale.Value / 20.0);
                    break;
                case "Noise":
                    console.radio.GetDSPRX(0, 0).RXPreGenNoiseMag = Math.Pow(10, (double)udRXGenScale.Value / 20.0);
                    console.radio.GetDSPRX(1, 0).RXPreGenNoiseMag = Math.Pow(10, (double)udRXGenScale.Value / 20.0);
                    break;
                case "Sweep":
                    console.radio.GetDSPRX(0, 0).RXPreGenSweepMag = Math.Pow(10, (double)udRXGenScale.Value / 20.0);
                    console.radio.GetDSPRX(1, 0).RXPreGenSweepMag = Math.Pow(10, (double)udRXGenScale.Value / 20.0);
                    break;
            }
        }

        private void udRXGenFreq_ValueChanged(object sender, EventArgs e)
        {
            switch (cmboSigGenRXMode.Text)
            {
                case "Tone":
                    console.radio.GetDSPRX(0, 0).RXPreGenToneFreq = (double)udRXGenFreq.Value;
                    console.radio.GetDSPRX(1, 0).RXPreGenToneFreq = (double)udRXGenFreq.Value;
                    break;
            }
        }

        private void udRXGenSweepLow_ValueChanged(object sender, EventArgs e)
        {
            console.radio.GetDSPRX(0, 0).RXPreGenSweepFreq1 = (double)udRXGenSweepLow.Value;
            console.radio.GetDSPRX(1, 0).RXPreGenSweepFreq1 = (double)udRXGenSweepLow.Value;
        }

        private void udRXGenSweepHigh_ValueChanged(object sender, EventArgs e)
        {
            console.radio.GetDSPRX(0, 0).RXPreGenSweepFreq2 = (double)udRXGenSweepHigh.Value;
            console.radio.GetDSPRX(1, 0).RXPreGenSweepFreq2 = (double)udRXGenSweepHigh.Value;
        }

        private void udRXGenSweepRate_ValueChanged(object sender, EventArgs e)
        {
            console.radio.GetDSPRX(0, 0).RXPreGenSweepRate = (double)udRXGenSweepRate.Value;
            console.radio.GetDSPRX(1, 0).RXPreGenSweepRate = (double)udRXGenSweepRate.Value;
        }

        private void chkTXInhibit_CheckedChanged(object sender, EventArgs e)
        {
            console.UseTxInhibit = chkTXInhibit.Checked;
        }
        private void chkTXInhibitReverse_CheckedChanged(object sender, EventArgs e)
        {
            console.ReverseTxInhibit = chkTXInhibitReverse.Checked;
        }
        private void udTXGenPulseFreq_ValueChanged(object sender, EventArgs e)
        {
            console.radio.GetDSPTX(0).TXPreGenPulseFreq = (double)udTXGenPulseFreq.Value;
        }

        private void udTXGenPulseDutyCycle_ValueChanged(object sender, EventArgs e)
        {
            console.radio.GetDSPTX(0).TXPreGenPulseDutyCycle = (double)udTXGenPulseDutyCycle.Value;
        }

        private void udTXGenPulseTransition_ValueChanged(object sender, EventArgs e)
        {
            console.radio.GetDSPTX(0).TXPreGenPulseTransition = (double)udTXGenPulseTransition.Value;
        }

        private void chkEmphPos_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPTX(0).TXFMEmphOn = !chkEmphPos.Checked;
        }

        private void chkRemoveTone_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(0, 0).RXFMCTCSSFilter = chkRemoveTone.Checked;
            console.radio.GetDSPRX(0, 1).RXFMCTCSSFilter = chkRemoveTone.Checked;
            console.radio.GetDSPRX(1, 0).RXFMCTCSSFilter = chkRemoveTone.Checked;
        }

        private void chkFMDetLimON_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(0, 0).RXFMDETLIMRUN = chkFMDetLimON.Checked;
            console.radio.GetDSPRX(0, 1).RXFMDETLIMRUN = chkFMDetLimON.Checked;
            console.radio.GetDSPRX(1, 0).RXFMDETLIMRUN = chkFMDetLimON.Checked;
        }

        private void tbDSPDetLimGain_Scroll(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(0, 0).RXFMDETLIMGAIN = (double)tbDSPFMDetLimGain.Value;
            console.radio.GetDSPRX(0, 1).RXFMDETLIMGAIN = (double)tbDSPFMDetLimGain.Value;
            console.radio.GetDSPRX(1, 0).RXFMDETLIMGAIN = (double)tbDSPFMDetLimGain.Value;
        }

        private void chkDSPEERon_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (chkDSPEERon.Checked)
            {
                console.radio.GetDSPTX(0).TXEERModeRun = true;
            }
            else
            {
                console.radio.GetDSPTX(0).TXEERModeRun = false;
            }
        }

        private void udDSPEERmgain_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPTX(0).TXEERModeMgain = (double)udDSPEERmgain.Value;
        }

        private void udDSPEERpgain_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPTX(0).TXEERModePgain = (double)udDSPEERpgain.Value;
        }

        private void udDSPEERmdelay_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPTX(0).TXEERModeMdelay = (double)udDSPEERmdelay.Value / 1.0e+06;
        }

        private void chkDSPEERamIQ_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPTX(0).TXEERModeAMIQ = chkDSPEERamIQ.Checked;
        }

        private void chkHFTRRelay_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.HFTRRelay = chkHFTRRelay.Checked;
        }

        private void udHWKeyDownDelay_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            NetworkIO.SetCWPTTDelay((int)udHWKeyDownDelay.Value);
        }

        // Path_Illustrator Properties added

        public bool RadBPHPFled
        {
            get { return radBPHPFled.Checked; }
        }

        public bool ChkDisableHPFOnTx
        {
            get { return chkDisableHPFonTX.Checked; }
        }
        public bool ChkDisableHPFOnPs
        {
            get { return chkDisableHPFonPSb.Checked; }
        }
        public bool RadRX1ADC1
        {
            get { return radDDC0ADC0.Checked; }
        }

        public bool RadRX1ADC2
        {
            get { return radDDC0ADC1.Checked; }
        }

        public bool RadRX1ADC3
        {
            get { return radDDC0ADC2.Checked; }
        }

        public bool RadRX2ADC1
        {
            get { return radDDC1ADC0.Checked; }
        }

        public bool RadRX2ADC2
        {
            get { return radDDC1ADC1.Checked; }
        }

        public bool RadRX2ADC3
        {
            get { return radDDC1ADC2.Checked; }
        }

        public bool RadRX3ADC1
        {
            get { return radDDC2ADC0.Checked; }
        }

        public bool RadRX3ADC2
        {
            get { return radDDC2ADC1.Checked; }
        }

        public bool RadRX3ADC3
        {
            get { return radDDC2ADC2.Checked; }
        }

        public bool RadRX4ADC1
        {
            get { return radDDC3ADC0.Checked; }
        }

        public bool RadRX4ADC2
        {
            get { return radDDC3ADC1.Checked; }
        }

        public bool RadRX4ADC3
        {
            get { return radDDC3ADC2.Checked; }
        }

        public bool RadRX5ADC1
        {
            get { return radDDC4ADC0.Checked; }
        }

        public bool RadRX5ADC2
        {
            get { return radDDC4ADC1.Checked; }
        }

        public bool RadRX5ADC3
        {
            get { return radDDC4ADC2.Checked; }
        }

        public bool RadRX6ADC1
        {
            get { return radDDC5ADC0.Checked; }
        }

        public bool RadRX6ADC2
        {
            get { return radDDC5ADC1.Checked; }
        }

        public bool RadRX6ADC3
        {
            get { return radDDC5ADC2.Checked; }
        }

        public bool RadRX7ADC1
        {
            get { return radDDC6ADC0.Checked; }
        }

        public bool RadRX7ADC2
        {
            get { return radDDC6ADC1.Checked; }
        }

        public bool RadRX7ADC3
        {
            get { return radDDC6ADC2.Checked; }
        }

        private int pi_RxAnt;
        public int PI_RxAnt
        {
            get { return pi_RxAnt; }
        }

        private int pi_TxAnt;
        public int PI_TxAnt
        {
            get { return pi_TxAnt; }
        }

        private int alex_EXT2EXT1XVTR = 0;
        public int Alex_EXT2EXT1XVTR
        {
            get { return alex_EXT2EXT1XVTR; }
        }


        public bool ChkDisableRXOut
        {
            get { return chkDisableRXOut.Checked; }
        }

        public bool ChkRxOutOnTx
        {
            get { return chkRxOutOnTx.Checked; }
        }

        public bool ChkRx1InOnTx
        {
            get { return chkEXT2OutOnTx.Checked; }
        }

        public bool ChkRx2InOnTx
        {
            get { return chkEXT1OutOnTx.Checked; }
        }

        // end of Path_Illustrator Properties support

        private void radDDCADC_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            int val = 0;

            //DDC0 ADC control: bits 1 & 0
            if (radDDC0ADC0.Checked) val += 0; //bits 1 & 0 set to 00 => DDC0 to ADC0
            if (radDDC0ADC1.Checked) val += 1 << 0; //bits 1 & 0 set to 01 => DDC0 to ADC1
            if (radDDC0ADC2.Checked) val += 1 << 1; //bits 1 & 0 set to 10 => DDC0 to ADC2
            //DDC1 ADC control: bits 3 & 2
            if (radDDC1ADC0.Checked) val += 0; // bits 3 & 2 set to 00 => DDC1 to ADC0
            if (radDDC1ADC1.Checked) val += 1 << 2; // bits 3 & 2 set to 01 => DDC1 to ADC1
            if (radDDC1ADC2.Checked) val += 1 << 3; // bits 3 & 2 set to 10 => DDC1 to ADC2
            //DDC2 ADC control: bits 5 & 4
            if (radDDC2ADC0.Checked) val += 0; // bits 5 & 4 set to 00 => DDC2 to ADC0
            if (radDDC2ADC1.Checked) val += 1 << 4; // bits 5 & 4 set to 01 => DDC2 to ADC1
            if (radDDC2ADC2.Checked) val += 1 << 5; // bits 5 & 4 set to 10 => DDC2 to ADC2
            //DDC3 ADC control: bits 7 & 6
            if (radDDC3ADC0.Checked) val += 0; // bits 7 & 6 set to 00 => DDC3 to ADC0
            if (radDDC3ADC1.Checked) val += 1 << 6; // bits 7 & 6 set to 01 => DDC3 to ADC1
            if (radDDC3ADC2.Checked) val += 1 << 7;  // bits 7 & 6 set to 10 => DDC3 to ADC2

            console.RXADCCtrl1 = val;

            val = 0;

            //DDC4 ADC control: bits 1 & 0
            if (radDDC4ADC0.Checked) val += 0; //bits 1 & 0 set to 00 => DDC4 to ADC0
            if (radDDC4ADC1.Checked) val += 1 << 0; //bits 1 & 0 set to 01 => DDC4 to ADC1
            if (radDDC4ADC2.Checked) val += 1 << 1; //bits 1 & 0 set to 10 => DDC4 to ADC2
            //DDC5 ADC control: bits 3 & 2
            if (radDDC5ADC0.Checked) val += 0; // bits 3 & 2 set to 00 => DDC5 to ADC0
            if (radDDC5ADC1.Checked) val += 1 << 2; // bits 3 & 2 set to 01 => DDC5 to ADC1
            if (radDDC5ADC2.Checked) val += 1 << 3; // bits 3 & 2 set to 10 => DDC5 to ADC2
            //DDC6 ADC control: bits 5 & 4
            if (radDDC6ADC0.Checked) val += 0; // bits 5 & 4 set to 00 => DDC6 to ADC0
            if (radDDC6ADC1.Checked) val += 1 << 4; // bits 5 & 4 set to 01 => DDC6 to ADC1
            if (radDDC6ADC2.Checked) val += 1 << 5; // bits 5 & 4 set to 10 => DDC6 to ADC2

            console.RXADCCtrl2 = val;

            if (console.path_Illustrator != null)
                console.path_Illustrator.pi_Changed();
        }

        private void radP1DDCADC_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            int val = 0;

            //protocol 1 DDC0 ADC control: bits 1 & 0
            if (radP1DDC0ADC0.Checked) val += 0; //bits 1 & 0 set to 00 => DDC0 to ADC0
            if (radP1DDC0ADC1.Checked) val += 1 << 0; //bits 1 & 0 set to 01 => DDC0 to ADC1
            if (radP1DDC0ADC2.Checked) val += 1 << 1; //bits 1 & 0 set to 10 => DDC0 to ADC2
            //protocol 1 DDC1 ADC control: bits 3 & 2
            if (radP1DDC1ADC0.Checked) val += 0; // bits 3 & 2 set to 00 => DDC1 to ADC0
            if (radP1DDC1ADC1.Checked) val += 1 << 2; // bits 3 & 2 set to 01 => DDC1 to ADC1
            if (radP1DDC1ADC2.Checked) val += 1 << 3; // bits 3 & 2 set to 10 => DDC1 to ADC2
            //protocol 1 DDC2 ADC control: bits 5 & 4
            if (radP1DDC2ADC0.Checked) val += 0; // bits 5 & 4 set to 00 => DDC2 to ADC0
            if (radP1DDC2ADC1.Checked) val += 1 << 4; // bits 5 & 4 set to 01 => DDC2 to ADC1
            if (radP1DDC2ADC2.Checked) val += 1 << 5; // bits 5 & 4 set to 10 => DDC2 to ADC2
            //protocol 1 DDC3 ADC control: bits 7 & 6
            if (radP1DDC3ADC0.Checked) val += 0; // bits 7 & 6 set to 00 => DDC3 to ADC0
            if (radP1DDC3ADC1.Checked) val += 1 << 6; // bits 7 & 6 set to 01 => DDC3 to ADC1
            if (radP1DDC3ADC2.Checked) val += 1 << 7;  // bits 7 & 6 set to 10 => DDC3 to ADC2
            //protocol 1 DDC4 ADC control: bits 1 & 0
            if (radP1DDC4ADC0.Checked) val += 0; //bits 9 & 8 set to 00 => DDC4 to ADC0
            if (radP1DDC4ADC1.Checked) val += 1 << 8; //bits 9 & 8 set to 01 => DDC4 to ADC1
            if (radP1DDC4ADC2.Checked) val += 1 << 9; //bits 9 & 8 set to 10 => DDC4 to ADC2
            //protocol 1 DDC5 ADC control: bits 3 & 2
            if (radP1DDC5ADC0.Checked) val += 0; // bits 11 & 10 set to 00 => DDC5 to ADC0
            if (radP1DDC5ADC1.Checked) val += 1 << 10; // bits 11 & 10 set to 01 => DDC5 to ADC1
            if (radP1DDC5ADC2.Checked) val += 1 << 11; // bits 11 & 10 set to 10 => DDC5 to ADC2
            //protocol 1 DDC6 ADC control: bits 5 & 4
            if (radP1DDC6ADC0.Checked) val += 0; // bits 13 & 12 set to 00 => DDC6 to ADC0
            if (radP1DDC6ADC1.Checked) val += 1 << 12; // bits 13 & 12 set to 01 => DDC6 to ADC1
            if (radP1DDC6ADC2.Checked) val += 1 << 13; // bits 13 & 12 set to 10 => DDC6 to ADC2

            console.RXADCCtrl_P1 = val;
            if (console.path_Illustrator != null)
                console.path_Illustrator.pi_Changed();
        }

        private void comboDSPNOBmode_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            int nbmode = comboDSPNOBmode.SelectedIndex;
            if (nbmode < 0)
            {
                nbmode = 0;
                comboDSPNOBmode.Text = "Zero";
                comboDSPNOBmode.SelectedIndex = nbmode;
            }
            console.radio.GetDSPRX(0, 0).NBMode = nbmode;
            console.radio.GetDSPRX(1, 0).NBMode = nbmode;
        }

        private void chkClickTuneDrag_CheckedChanged(object sender, EventArgs e)
        {
            chkCTLimitDragToSpectral.Enabled = chkClickTuneDrag.Checked; //MW0LGE_21k9
            chkCTLimitDragMouseOnly.Enabled = chkClickTuneDrag.Checked && chkCTLimitDragToSpectral.Checked;

            console.ClickTuneDrag = chkClickTuneDrag.Checked;
        }

        // APF

        private void chkDSPRX1APFEnable_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (console.RX1DSPMode == DSPMode.CWL ||
                console.RX1DSPMode == DSPMode.CWU)
                console.radio.GetDSPRX(0, 0).RXAPFRun = chkDSPRX1APFEnable.Checked;

            if (radDSPRX1APFControls.Checked)
                console.APFEnabled = chkDSPRX1APFEnable.Checked;

            if (chkDSPRX1APFEnable.Checked)
            {
                if (chkDSPRX1subAPFEnable.Checked) console.RX1APFlabel = "APFb";
                else console.RX1APFlabel = "APFm";
            }
            else if (chkDSPRX1subAPFEnable.Checked) console.RX1APFlabel = "APFs";
            else console.RX1APFlabel = "";
        }

        private void chkDSPRX1subAPFEnable_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (console.RX1DSPMode == DSPMode.CWL ||
                console.RX1DSPMode == DSPMode.CWU)
                console.radio.GetDSPRX(0, 1).RXAPFRun = chkDSPRX1subAPFEnable.Checked;

            if (radDSPRX1subAPFControls.Checked)
                console.APFEnabled = chkDSPRX1subAPFEnable.Checked;

            if (chkDSPRX1subAPFEnable.Checked)
            {
                if (chkDSPRX1APFEnable.Checked) console.RX1APFlabel = "APFb";
                else console.RX1APFlabel = "APFs";
            }
            else if (chkDSPRX1APFEnable.Checked) console.RX1APFlabel = "APFm";
            else console.RX1APFlabel = "";

        }

        private void chkDSPRX2APFEnable_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (console.RX2DSPMode == DSPMode.CWL ||
                 console.RX2DSPMode == DSPMode.CWU)
                console.radio.GetDSPRX(1, 0).RXAPFRun = chkDSPRX2APFEnable.Checked;

            if (radDSPRX2APFControls.Checked)
                console.APFEnabled = chkDSPRX2APFEnable.Checked;

            if (chkDSPRX2APFEnable.Checked) console.RX2APFlabel = "APF";
            else console.RX2APFlabel = "";

        }

        private void tbDSPAudRX1APFGain_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(0, 0).RXAPFGain = Math.Pow(10.0, (double)tbDSPAudRX1APFGain.Value / 200.0);
            if (radDSPRX1APFControls.Checked)
                console.APFGain = tbDSPAudRX1APFGain.Value;
        }

        private void tbDSPAudRX1subAPFGain_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(0, 1).RXAPFGain = Math.Pow(10.0, (double)tbDSPAudRX1subAPFGain.Value / 200.0);
            if (radDSPRX1subAPFControls.Checked)
                console.APFGain = tbDSPAudRX1subAPFGain.Value;
        }

        private void tbDSPAudRX2APFGain_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(1, 0).RXAPFGain = Math.Pow(10.0, (double)tbDSPAudRX2APFGain.Value / 200.0);
            if (radDSPRX2APFControls.Checked)
                console.APFGain = tbDSPAudRX2APFGain.Value;
        }

        private void tbRX1APFTune_Scroll(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(0, 0).RXAPFFreq = console.CWPitch + (double)tbRX1APFTune.Value;
            if (radDSPRX1APFControls.Checked)
                console.APFFreq = tbRX1APFTune.Value;
        }

        private void tbRX1subAPFTune_Scroll(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(0, 1).RXAPFFreq = console.CWPitch + (double)tbRX1subAPFTune.Value;
            if (radDSPRX1subAPFControls.Checked)
                console.APFFreq = tbRX1subAPFTune.Value;
        }

        private void tbRX2APFTune_Scroll(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(1, 0).RXAPFFreq = console.CWPitch + (double)tbRX2APFTune.Value;
            if (radDSPRX2APFControls.Checked)
                console.APFFreq = tbRX2APFTune.Value;
        }

        private void tbRX1APFBW_Scroll(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(0, 0).RXAPFBw = (double)tbRX1APFBW.Value;
            if (radDSPRX1APFControls.Checked)
                console.APFBandwidth = tbRX1APFBW.Value;
        }

        private void tbRX1subAPFBW_Scroll(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(0, 1).RXAPFBw = (double)tbRX1subAPFBW.Value;
            if (radDSPRX1subAPFControls.Checked)
                console.APFBandwidth = tbRX1subAPFBW.Value;
        }

        private void tbRX2APFBW_Scroll(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(1, 0).RXAPFBw = (double)tbRX2APFBW.Value;
            if (radDSPRX2APFControls.Checked)
                console.APFBandwidth = tbRX2APFBW.Value;
        }

        private void radDSPRX1APFControls_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (radDSPRX1APFControls.Checked)
            {
                chkDSPRX1APFEnable.Checked = console.APFEnabled;
                if (console.RX1DSPMode == DSPMode.CWL ||
                    console.RX1DSPMode == DSPMode.CWU)
                    console.radio.GetDSPRX(0, 0).RXAPFRun = chkDSPRX1APFEnable.Checked;
                tbDSPAudRX1APFGain.Value = console.APFGain;
                console.radio.GetDSPRX(0, 0).RXAPFGain = Math.Pow(10.0, (double)tbDSPAudRX1APFGain.Value / 200.0);
                tbRX1APFTune.Value = console.APFFreq;
                console.radio.GetDSPRX(0, 0).RXAPFFreq = console.CWPitch + (double)tbRX1APFTune.Value;
                tbRX1APFBW.Value = console.APFBandwidth;
                console.radio.GetDSPRX(0, 0).RXAPFBw = (double)tbRX1APFBW.Value;
                console.APFbtn = "RX1";
            }
        }

        private void radDSPRX1subAPFControls_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (radDSPRX1subAPFControls.Checked)
            {
                chkDSPRX1subAPFEnable.Checked = console.APFEnabled;
                if (console.RX1DSPMode == DSPMode.CWL ||
                    console.RX1DSPMode == DSPMode.CWU)
                    console.radio.GetDSPRX(0, 1).RXAPFRun = chkDSPRX1subAPFEnable.Checked;
                tbDSPAudRX1subAPFGain.Value = console.APFGain;
                console.radio.GetDSPRX(0, 1).RXAPFGain = Math.Pow(10.0, (double)tbDSPAudRX1subAPFGain.Value / 200.0);
                tbRX1subAPFTune.Value = console.APFFreq;
                console.radio.GetDSPRX(0, 1).RXAPFFreq = console.CWPitch + (double)tbRX1subAPFTune.Value;
                tbRX1subAPFBW.Value = console.APFBandwidth;
                console.radio.GetDSPRX(0, 1).RXAPFBw = (double)tbRX1subAPFBW.Value;
                console.APFbtn = "SUB";
            }
        }

        private void radDSPRX2APFControls_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (radDSPRX2APFControls.Checked)
            {
                chkDSPRX2APFEnable.Checked = console.APFEnabled;
                if (console.RX2DSPMode == DSPMode.CWL ||
                    console.RX2DSPMode == DSPMode.CWU)
                    console.radio.GetDSPRX(1, 0).RXAPFRun = chkDSPRX2APFEnable.Checked;
                tbDSPAudRX2APFGain.Value = console.APFGain;
                console.radio.GetDSPRX(1, 0).RXAPFGain = Math.Pow(10.0, (double)tbDSPAudRX2APFGain.Value / 200.0);
                tbRX2APFTune.Value = console.APFFreq;
                console.radio.GetDSPRX(1, 0).RXAPFFreq = console.CWPitch + (double)tbRX2APFTune.Value;
                tbRX2APFBW.Value = console.APFBandwidth;
                console.radio.GetDSPRX(1, 0).RXAPFBw = (double)tbRX2APFBW.Value;
                console.APFbtn = "RX2";
            }
        }

        private void chkDSPRX1DollyEnable_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(0, 0).RXADollyRun = chkDSPRX1DollyEnable.Checked;
        }

        private void chkDSPRX1DollySubEnable_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(0, 1).RXADollyRun = chkDSPRX1SubDollyEnable.Checked;
        }

        private void chkDSPRX2DollyEnable_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(1, 0).RXADollyRun = chkDSPRX2DollyEnable.Checked;
        }

        private void udDSPRX1DollyF0_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(0, 0).RXADollyFreq0 = (double)udDSPRX1DollyF0.Value;
        }

        private void udDSPRX1SubDollyF0_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(0, 1).RXADollyFreq0 = (double)udDSPRX1SubDollyF0.Value;
        }

        private void udDSPRX2DollyF0_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(1, 0).RXADollyFreq0 = (double)udDSPRX2DollyF0.Value;
        }

        private void udDSPRX1DollyF1_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(0, 0).RXADollyFreq1 = (double)udDSPRX1DollyF1.Value;
        }

        private void udDSPRX2DollyF1_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(1, 0).RXADollyFreq1 = (double)udDSPRX2DollyF1.Value;
        }

        private void udDSPRX1SubDollyF1_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(0, 1).RXADollyFreq1 = (double)udDSPRX1SubDollyF1.Value;
        }
        private void udATTOnTX_ValueChanged(object sender, EventArgs e)
        {
            console.TxAttenData = (int)udATTOnTX.Value;
        }

        private void ud6mLNAGainOffset_ValueChanged(object sender, EventArgs e)
        {
            console.RX6mGainOffset = (float)ud6mLNAGainOffset.Value;
        }

        private void udDSPEERpdelay_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPTX(0).TXEERModePdelay = (double)udDSPEERpdelay.Value / 1.0e+06;
        }

        private void chkDSPEERRunDelays_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPTX(0).TXEERModeRunDelays = chkDSPEERRunDelays.Checked;
        }

        private void udDSPEERpwmMax_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            NetworkIO.SetEERPWMmax((int)udDSPEERpwmMax.Value);
        }

        private void udDSPEERpwmMin_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            NetworkIO.SetEERPWMmin((int)udDSPEERpwmMin.Value);
        }

        private void comboKeyerConnSecondary_MouseClick(object sender, MouseEventArgs e)
        {
            string[] com_ports = SerialPort.GetPortNames();
            comboKeyerConnSecondary.Items.Clear();
            comboKeyerConnSecondary.Items.Add("None");
            comboKeyerConnSecondary.Items.Add("CAT");
            comboKeyerConnSecondary.Items.AddRange(com_ports);
        }

        private void comboCATPort_Click(object sender, EventArgs e)
        {
            string[] com_ports = SerialPort.GetPortNames();
            comboCATPort.Items.Clear();
            comboCATPort.Items.Add("None");
            comboCATPort.Items.AddRange(com_ports);
        }

        private void comboCAT2Port_Click(object sender, EventArgs e)
        {
            string[] com_ports = SerialPort.GetPortNames();
            comboCAT2Port.Items.Clear();
            comboCAT2Port.Items.Add("None");
            comboCAT2Port.Items.AddRange(com_ports);
        }

        private void comboCAT3Port_Click(object sender, EventArgs e)
        {
            string[] com_ports = SerialPort.GetPortNames();
            comboCAT3Port.Items.Clear();
            comboCAT3Port.Items.Add("None");
            comboCAT3Port.Items.AddRange(com_ports);
        }

        private void comboCAT4Port_Click(object sender, EventArgs e)
        {
            string[] com_ports = SerialPort.GetPortNames();
            comboCAT4Port.Items.Clear();
            comboCAT4Port.Items.Add("None");
            comboCAT4Port.Items.AddRange(com_ports);
        }

        private void comboCATPTTPort_Click(object sender, EventArgs e)
        {
            string[] com_ports = SerialPort.GetPortNames();
            comboCATPTTPort.Items.Clear();
            comboCATPTTPort.Items.Add("None");
            comboCATPTTPort.Items.Add("CAT");
            comboCATPTTPort.Items.AddRange(com_ports);
        }
        private void ComboAndromedaCATPort_Click(object sender, EventArgs e)
        {
            string[] com_ports = SerialPort.GetPortNames();
            comboAndromedaCATPort.Items.Clear();
            comboAndromedaCATPort.Items.Add("None");
            comboAndromedaCATPort.Items.AddRange(com_ports);
        }


        private void chkDSPCESSB_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.TxOsctrl = chkDSPCESSB.Checked;
            if (chkDSPCESSB.Checked)
            {
                if (console.radio.GetDSPTX(0).TXCompandOn)
                    console.radio.GetDSPTX(0).TXOsctrlOn = true;
            }
            else
            {
                console.radio.GetDSPTX(0).TXOsctrlOn = false;
            }
        }

        private void udRXAMSQMaxTail_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.radio.GetDSPRX(0, 0).RXAMSquelchMaxTail = (double)udRXAMSQMaxTail.Value;
            console.radio.GetDSPRX(0, 1).RXAMSquelchMaxTail = (double)udRXAMSQMaxTail.Value;
            console.radio.GetDSPRX(1, 0).RXAMSquelchMaxTail = (double)udRXAMSQMaxTail.Value;
            console.radio.GetDSPRX(1, 1).RXAMSquelchMaxTail = (double)udRXAMSQMaxTail.Value;
        }

        private void radDSPNR2Linear_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (radDSPNR2Linear.Checked)
            {
                console.radio.GetDSPRX(0, 0).RXANR2GainMethod = 0;
                console.radio.GetDSPRX(0, 1).RXANR2GainMethod = 0;
            }
        }

        private void radDSPNR2Log_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (radDSPNR2Log.Checked)
            {
                console.radio.GetDSPRX(0, 0).RXANR2GainMethod = 1;
                console.radio.GetDSPRX(0, 1).RXANR2GainMethod = 1;
            }
        }

        private void radDSPNR2OSMS_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (radDSPNR2OSMS.Checked)
            {
                console.radio.GetDSPRX(0, 0).RXANR2NPEMethod = 0;
                console.radio.GetDSPRX(0, 1).RXANR2NPEMethod = 0;
            }
        }

        private void radDSPNR2MMSE_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (radDSPNR2MMSE.Checked)
            {
                console.radio.GetDSPRX(0, 0).RXANR2NPEMethod = 1;
                console.radio.GetDSPRX(0, 1).RXANR2NPEMethod = 1;
            }
        }

        private void chkDSPNR2AE_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            int run;
            if (chkDSPNR2AE.Checked)
                run = 1;
            else
                run = 0;
            console.radio.GetDSPRX(0, 0).RXANR2AERun = run;
            console.radio.GetDSPRX(0, 1).RXANR2AERun = run;
        }

        private void radDSPNR2LinearRX2_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (radDSPNR2LinearRX2.Checked)
            {
                console.radio.GetDSPRX(1, 0).RXANR2GainMethod = 0;
                console.radio.GetDSPRX(1, 1).RXANR2GainMethod = 0;
            }
        }

        private void radDSPNR2LogRX2_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (radDSPNR2LogRX2.Checked)
            {
                console.radio.GetDSPRX(1, 0).RXANR2GainMethod = 1;
                console.radio.GetDSPRX(1, 1).RXANR2GainMethod = 1;
            }
        }

        private void radDSPNR2OSMSRX2_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (radDSPNR2OSMSRX2.Checked)
            {
                console.radio.GetDSPRX(1, 0).RXANR2NPEMethod = 0;
                console.radio.GetDSPRX(1, 1).RXANR2NPEMethod = 0;
            }
        }

        private void radDSPNR2MMSERX2_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (radDSPNR2MMSERX2.Checked)
            {
                console.radio.GetDSPRX(1, 0).RXANR2NPEMethod = 1;
                console.radio.GetDSPRX(1, 1).RXANR2NPEMethod = 1;
            }
        }

        private void chkDSPNR2AERX2_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            int run;
            if (chkDSPNR2AERX2.Checked)
                run = 1;
            else
                run = 0;
            console.radio.GetDSPRX(1, 0).RXANR2AERun = run;
            console.radio.GetDSPRX(1, 1).RXANR2AERun = run;
        }

        private void radDSPNR2Gamma_CheckedChanged(object sender, EventArgs e)
        {
            console.radio.GetDSPRX(0, 0).RXANR2GainMethod = 2;
            console.radio.GetDSPRX(0, 1).RXANR2GainMethod = 2;
        }

        private void radDSPNR2GammaRX2_CheckedChanged(object sender, EventArgs e)
        {
            console.radio.GetDSPRX(1, 0).RXANR2GainMethod = 2;
            console.radio.GetDSPRX(1, 1).RXANR2GainMethod = 2;
        }

        private void chkLimitExtAmpOnOverload_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.AmpProtect = chkLimitExtAmpOnOverload.Checked;
            if (chkLimitExtAmpOnOverload.Checked)
                cmaster.SetAmpProtectRun(0, 1);
            else
                cmaster.SetAmpProtectRun(0, 0);
        }

        private void comboFocusMasterMode_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            switch (comboFocusMasterMode.Text)
            {
                case "N1MM+ Logger":
                    txtFocusMasterWinTitle.Enabled = true;
                    txtFocusMasterWinTitle.Text = "";
                    txtFocusMasterDelay.Enabled = false;
                    txtFocusMasterUDPPort.Enabled = false;
                    txtFocusMasterDelay_TextChanged(this, EventArgs.Empty);
                    txtFocusMasterUDPPort_TextChanged(this, EventArgs.Empty);
                    console.FocusMasterMode = FocusMasterMode.Logger;
                    break;

                case "Select by Click":
                    txtFocusMasterWinTitle.Enabled = false;
                    txtFocusMasterWinTitle.Text = "";
                    txtFocusMasterDelay.Enabled = false;
                    txtFocusMasterUDPPort.Enabled = true;
                    console.FocusMasterMode = FocusMasterMode.Click;
                    break;

                case "Enter Window Title":
                    txtFocusMasterDelay.Enabled = true;
                    txtFocusMasterUDPPort.Enabled = true;
                    txtFocusMasterWinTitle.Enabled = true;
                    txtFocusMasterWinTitle.Text = "Enter Window Title and Press Enter";
                    txtFocusMasterWinTitle.Focus();
                    break;

                case "None":
                    txtFocusMasterDelay.Enabled = true;
                    txtFocusMasterUDPPort.Enabled = true;
                    txtFocusMasterWinTitle.Enabled = true;
                    txtFocusMasterWinTitle.Text = "";
                    console.FocusMasterMode = FocusMasterMode.None;
                    break;
            }
        }

        private void txtFocusMasterUDPPort_TextChanged(object sender, EventArgs e)
        {
            console.FocusMasterUDPPort = int.Parse(txtFocusMasterUDPPort.Text);
        }

        private void txtFocusMasterDelay_TextChanged(object sender, EventArgs e)
        {
            console.FocusMasterDelay = int.Parse(txtFocusMasterDelay.Text);
        }

        private void txtFocusMasterWinTitle_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                IntPtr hwtemp = IntPtr.Zero;
                foreach (Process pList in Process.GetProcesses())
                {
                    if (pList.MainWindowTitle.Equals(txtFocusMasterWinTitle.Text))
                    {
                        hwtemp = pList.MainWindowHandle;
                    }
                }

                if (hwtemp != IntPtr.Zero)
                {
                    txtFocusMasterDelay.Enabled = false;
                    txtFocusMasterWinTitle.Enabled = false;
                    console.FocusMasterWinTitle = txtFocusMasterWinTitle.Text;
                    console.FocusMasterMode = FocusMasterMode.Title;
                    console.N1MMHandle = hwtemp;
                    comboFocusMasterMode.Focus();
                }
                else
                {
                    txtFocusMasterDelay.Enabled = true;
                    txtFocusMasterWinTitle.Enabled = true;
                    txtFocusMasterWinTitle.Text = "Window not found!";
                    txtFocusMasterWinTitle.Focus();
                }
            }
        }

        private void chkEnableLEDFont_CheckedChanged(object sender, EventArgs e)
        {
            console.EnableLEDFont = chkEnableLEDFont.Checked;
        }

        private void chkDisableRXOut_CheckedChanged(object sender, EventArgs e)
        {
            console.RxOutOverride = chkDisableRXOut.Checked;
            if (console.path_Illustrator != null)
                console.path_Illustrator.pi_Changed();
        }

        private void chkSplitPins_CheckedChanged(object sender, EventArgs e)
        {
            Penny.getPenny().SplitPins = chkSplitPins.Checked;
            if (chkSplitPins.Checked)
            {
                radSplitPins4x3_CheckedChanged(this, EventArgs.Empty);
                radSplitPins3x4_CheckedChanged(this, EventArgs.Empty);
            }
            else console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;
        }

        private void radSplitPins4x3_CheckedChanged(object sender, EventArgs e)
        {
            if (radSplitPins4x3.Checked && chkSplitPins.Checked)
            {
                BandBBitMask = 0x70;
                Penny.getPenny().RxABitMask = 0xf;
                UpdateOCBits();
            }
        }

        private void radSplitPins3x4_CheckedChanged(object sender, EventArgs e)
        {
            if (radSplitPins3x4.Checked && chkSplitPins.Checked)
            {
                BandBBitMask = 0x78;
                Penny.getPenny().RxABitMask = 0x7;
                UpdateOCBits();
            }
        }

        private void udDSPSNBThresh1_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            WDSP.SetRXASNBAk1(WDSP.id(0, 0), (double)udDSPSNBThresh1.Value);
            WDSP.SetRXASNBAk1(WDSP.id(0, 1), (double)udDSPSNBThresh1.Value);
            WDSP.SetRXASNBAk1(WDSP.id(2, 0), (double)udDSPSNBThresh1.Value);
        }

        private void udDSPSNBThresh2_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            WDSP.SetRXASNBAk2(WDSP.id(0, 0), (double)udDSPSNBThresh2.Value);
            WDSP.SetRXASNBAk2(WDSP.id(0, 1), (double)udDSPSNBThresh2.Value);
            WDSP.SetRXASNBAk2(WDSP.id(2, 0), (double)udDSPSNBThresh2.Value);
        }

        #region MultiNotchFilter

        int numnotches = 0;
        bool AddActive = false;
        bool EditActive = false;

        // On the Console
        // 'OFF/ON' button for Multi Notch Filter
        private void btnMNFRun_Click(object sender, EventArgs e)
        {
        }

        private void chkMNFRun_CheckedChanged(object sender, EventArgs e)
        {
        }

        // accept input for a notch to be added
        private void btnMNFAdd_Click(object sender, EventArgs e)
        {
            btnMNFAdd.BackColor = Color.Bisque;
            udMNFFreq.BackColor = Color.Bisque;
            udMNFWidth.BackColor = Color.Bisque;
            chkMNFActive.BackColor = Color.Bisque;
            udMNFFreq.Enabled = true;
            udMNFWidth.Enabled = true;
            chkMNFActive.Enabled = true;
            AddActive = true;
            btnMNFEdit.Enabled = false;
            if (EditActive)
            {
                EditActive = false;
                btnMNFEdit.BackColor = SystemColors.Control;
            }
            // get the current number of notches
            unsafe
            {
                int nn;
                WDSP.RXANBPGetNumNotches(WDSP.id(0, 0), &nn);
                numnotches = nn;
            }
            // if there are any notches already
            if (numnotches > 0)
            {
                // increase the control maximum and the notch number by 1
                udMNFNotch.Maximum += 1;
                udMNFNotch.Value += 1;
            }
            // the new notch will be inserted just after the previous one being viewed
            // zero/initialize the values in preparation for input
            udMNFFreq.Value = 0;
            udMNFWidth.Value = 0;
            chkMNFActive.Checked = true;
        }

        // accept input for editing a notch
        private void btnMNFEdit_Click(object sender, EventArgs e)
        {
            btnMNFEdit.BackColor = Color.Bisque;
            udMNFNotch.BackColor = Color.Bisque;
            udMNFFreq.BackColor = Color.Bisque;
            udMNFWidth.BackColor = Color.Bisque;
            chkMNFActive.BackColor = Color.Bisque;
            udMNFFreq.Enabled = true;
            udMNFWidth.Enabled = true;
            chkMNFActive.Enabled = true;
            EditActive = true;
            btnMNFAdd.Enabled = false;

            if (AddActive)
            {
                AddActive = false;
                btnMNFAdd.BackColor = SystemColors.Control;
            }
        }

        public bool NotchAdminBusy
        {
            // returns true if in middle of edit or add MW0LGE
            get
            {
                return AddActive | EditActive;
            }
        }

        // store the values from an Add or Edit operation
        private void btnMNFEnter_Click(object sender, EventArgs e)
        {
            if (AddActive)
            {
                AddActive = false;
                btnMNFAdd.BackColor = SystemColors.Control;
                udMNFFreq.BackColor = SystemColors.Control;
                udMNFWidth.BackColor = SystemColors.Control;
                chkMNFActive.BackColor = SystemColors.Control;
                WDSP.RXANBPAddNotch(WDSP.id(0, 0), (int)udMNFNotch.Value, 1.0e6 * (double)udMNFFreq.Value, (double)udMNFWidth.Value, chkMNFActive.Checked);
                WDSP.RXANBPAddNotch(WDSP.id(0, 1), (int)udMNFNotch.Value, 1.0e6 * (double)udMNFFreq.Value, (double)udMNFWidth.Value, chkMNFActive.Checked);
                WDSP.RXANBPAddNotch(WDSP.id(2, 0), (int)udMNFNotch.Value, 1.0e6 * (double)udMNFFreq.Value, (double)udMNFWidth.Value, chkMNFActive.Checked);
                // we have at least one notch; enable the 'Delete' button
                btnMNFDelete.Enabled = true;
            }
            if (EditActive)
            {
                EditActive = false;
                btnMNFEdit.BackColor = SystemColors.Control;
                udMNFNotch.BackColor = SystemColors.Control;
                udMNFFreq.BackColor = SystemColors.Control;
                udMNFWidth.BackColor = SystemColors.Control;
                chkMNFActive.BackColor = SystemColors.Control;
                WDSP.RXANBPEditNotch(WDSP.id(0, 0), (int)udMNFNotch.Value, 1.0e6 * (double)udMNFFreq.Value, (double)udMNFWidth.Value, chkMNFActive.Checked);
                WDSP.RXANBPEditNotch(WDSP.id(0, 1), (int)udMNFNotch.Value, 1.0e6 * (double)udMNFFreq.Value, (double)udMNFWidth.Value, chkMNFActive.Checked);
                WDSP.RXANBPEditNotch(WDSP.id(2, 0), (int)udMNFNotch.Value, 1.0e6 * (double)udMNFFreq.Value, (double)udMNFWidth.Value, chkMNFActive.Checked);
            }
            // no longer accepting input; disable entry of values
            udMNFFreq.Enabled = false;
            udMNFWidth.Enabled = false;
            chkMNFActive.Enabled = false;
            btnMNFAdd.Enabled = true;
            btnMNFEdit.Enabled = true;

            SaveNotchesToDatabase(); // aligns notch db with what has actually happened MW0LGE
        }

        // cancel the Add or Edit operation
        unsafe private void btnMNFCancel_Click(object sender, EventArgs e)
        {
            int nn;
            WDSP.RXANBPGetNumNotches(WDSP.id(0, 0), &nn);
            numnotches = nn;
            if (AddActive)
            {
                AddActive = false;
                if (numnotches > 0)
                {
                    // Add had potentially increased these values ... put them back the way they were
                    udMNFNotch.Value -= 1;
                    udMNFNotch.Maximum -= 1;
                }
            }
            EditActive = false;
            // reset the controls to the values for the displayed notch, if any
            if (numnotches > 0)
            {
                double fcenter, fwidth;
                int active;
                WDSP.RXANBPGetNotch(WDSP.id(0, 0), (int)udMNFNotch.Value, &fcenter, &fwidth, &active);
                udMNFFreq.Value = (decimal)(fcenter / 1.0e6);
                udMNFWidth.Value = (decimal)fwidth;
                if (active != 0)
                    chkMNFActive.Checked = true;
                else
                    chkMNFActive.Checked = false;
            }
            btnMNFEdit.BackColor = SystemColors.Control;
            btnMNFAdd.BackColor = SystemColors.Control;
            udMNFNotch.BackColor = SystemColors.Control;
            udMNFFreq.BackColor = SystemColors.Control;
            udMNFWidth.BackColor = SystemColors.Control;
            chkMNFActive.BackColor = SystemColors.Control;
            udMNFFreq.Enabled = false;
            udMNFWidth.Enabled = false;
            chkMNFActive.Enabled = false;
            btnMNFAdd.Enabled = true;
            btnMNFEdit.Enabled = true;
        }

        // delete a notch
        private void btnMNFDelete_Click(object sender, EventArgs e)
        {
            // delete the notch
            WDSP.RXANBPDeleteNotch(WDSP.id(0, 0), (int)udMNFNotch.Value);
            WDSP.RXANBPDeleteNotch(WDSP.id(0, 1), (int)udMNFNotch.Value);
            WDSP.RXANBPDeleteNotch(WDSP.id(2, 0), (int)udMNFNotch.Value);
            // get the number of remaining notches, 'numnotches'
            unsafe
            {
                int nn;
                WDSP.RXANBPGetNumNotches(WDSP.id(0, 0), &nn);
                numnotches = nn;
            }
            // if the notch number still points to a valid notch, get the notch information
            if ((int)udMNFNotch.Value < numnotches)
            {
                unsafe
                {
                    double fcenter, fwidth;
                    int active;
                    WDSP.RXANBPGetNotch(WDSP.id(0, 0), (int)udMNFNotch.Value, &fcenter, &fwidth, &active);
                    udMNFFreq.Value = (decimal)(fcenter / 1.0e6);
                    udMNFWidth.Value = (decimal)fwidth;
                    if (active != 0)
                        chkMNFActive.Checked = true;
                    else
                        chkMNFActive.Checked = false;
                }
            }
            // if the deleted notch was the 'top' notch, get the next notch moving down
            else if (numnotches > 0)
            {
                unsafe
                {
                    double fcenter, fwidth;
                    int active;
                    WDSP.RXANBPGetNotch(WDSP.id(0, 0), (int)udMNFNotch.Value - 1, &fcenter, &fwidth, &active);
                    udMNFNotch.Value -= 1;
                    udMNFFreq.Value = (decimal)(fcenter / 1.0e6);
                    udMNFWidth.Value = (decimal)fwidth;
                    if (active != 0)
                        chkMNFActive.Checked = true;
                    else
                        chkMNFActive.Checked = false;
                }
            }
            // if there are no remaining notches
            else
            {
                udMNFNotch.Value = 0;
                udMNFFreq.Value = 0;
                udMNFWidth.Value = 0;
                chkMNFActive.Checked = true;
                btnMNFDelete.Enabled = false;
                btnMNFEdit.Enabled = false; //MW0LGE
            }
            // set the Maximum for the 'Notch' control
            if (numnotches > 0)
                udMNFNotch.Maximum = numnotches - 1;
            else
                udMNFNotch.Maximum = 0;

            SaveNotchesToDatabase(); // aligns notch db with what has actually happened MW0LGE
        }

        private void udMNFNotch_ValueChanged(object sender, EventArgs e)
        {
            unsafe
            {
                int nn;
                WDSP.RXANBPGetNumNotches(WDSP.id(0, 0), &nn);
                numnotches = nn;
                // if there's a valid notch at the new value, restore it
                if ((int)udMNFNotch.Value < numnotches)
                {
                    double fcenter, fwidth;
                    int active;
                    WDSP.RXANBPGetNotch(WDSP.id(0, 0), (int)udMNFNotch.Value, &fcenter, &fwidth, &active);
                    udMNFFreq.Value = (decimal)(fcenter / 1.0e6);
                    udMNFWidth.Value = (decimal)fwidth;
                    if (active != 0)
                        chkMNFActive.Checked = true;
                    else
                        chkMNFActive.Checked = false;
                }
                // else, this must be an Add operation
                else
                {
                    udMNFFreq.Value = 0;
                    udMNFWidth.Value = 0;
                    chkMNFActive.Checked = true;
                }
            }
        }


        private void chkMNFAutoIncrease_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            WDSP.RXANBPSetAutoIncrease(WDSP.id(0, 0), chkMNFAutoIncrease.Checked);
            WDSP.RXANBPSetAutoIncrease(WDSP.id(0, 1), chkMNFAutoIncrease.Checked);
            WDSP.RXANBPSetAutoIncrease(WDSP.id(2, 0), chkMNFAutoIncrease.Checked);
        }

        private Object _notchLock = new Object();
        unsafe public void SaveNotchesToDatabase()
        {
            lock (_notchLock)
            {
                // get the number of notches that exist
                int nn;
                WDSP.RXANBPGetNumNotches(WDSP.id(0, 0), &nn);
                numnotches = nn;
                // HERE:  SAVE 'numnotches', THE NUMBER OF NOTCHES, TO THE DATABASE
                MNotchDB.Clear();
                for (int i = 0; i < numnotches; i++)
                {
                    double fcenter, fwidth;
                    int active;
                    // get fcenter, fwidth, and active for a notch
                    WDSP.RXANBPGetNotch(WDSP.id(0, 0), i, &fcenter, &fwidth, &active);
                    // HERE:  SAVE fcenter, fwidth, and active FOR THIS NOTCH TO THE DATABASE
                    MNotchDB.Add(new MNotch(fcenter, fwidth, Convert.ToBoolean(active)));
                }
            }
        }

        unsafe public void UpdateNotchDisplay()
        {
            // sets max limits, and selects first notch if one exists
            numnotches = MNotchDB.Count;
            udMNFNotch.Value = 0;
            udMNFNotch.Maximum = 0;
            if (numnotches > 0)
            {
                udMNFNotch.Maximum = numnotches - 1;
                double fcenter, fwidth;
                int active;
                WDSP.RXANBPGetNotch(WDSP.id(0, 0), (int)udMNFNotch.Value, &fcenter, &fwidth, &active);
                udMNFFreq.Value = (decimal)(fcenter / 1.0e6);
                udMNFWidth.Value = (decimal)fwidth;
                if (active != 0)
                    chkMNFActive.Checked = true;
                else
                    chkMNFActive.Checked = false;

                btnMNFDelete.Enabled = true;
                btnMNFEdit.Enabled = true; //MW0LGE
            }
            else
            {
                // MW0LGE added because udMNFFreq could be set to some value even though no MNotchDB entries
                // this caused by generic form save, saving out the control value
                udMNFFreq.Value = 0;
                udMNFWidth.Value = 0;
                btnMNFDelete.Enabled = false;
                btnMNFEdit.Enabled = false;
            }
        }

        unsafe public void RestoreNotchesFromDatabase()
        {
            // HERE:  Read the number of notches, 'numnotches' from the database
            for (int i = 0; i < MNotchDB.Count; i++)
            {
                double fcenter = 0.0, fwidth = 0.0;
                bool active = false;

                // HERE:  READ VALUES OF fcenter, fwidth, and active FOR NOTCH[i] FROM THE DATABASE
                fcenter = MNotchDB.NotchFromIndex(i).FCenter;
                fwidth = MNotchDB.NotchFromIndex(i).FWidth;
                active = MNotchDB.NotchFromIndex(i).Active;

                WDSP.RXANBPAddNotch(WDSP.id(0, 0), i, fcenter, fwidth, active);
                WDSP.RXANBPAddNotch(WDSP.id(0, 1), i, fcenter, fwidth, active);
                WDSP.RXANBPAddNotch(WDSP.id(2, 0), i, fcenter, fwidth, active);
            }

            UpdateNotchDisplay(); // sets max limits, and selects first notch if one exists MW0LGE
        }

        #endregion

        private void btnVFOFreq_Click(object sender, EventArgs e)
        {
            double vfo = console.VFOAFreq;
            if (console.RITOn) vfo += (double)console.RITValue * 1e-6; // check for RIT
            udMNFFreq.Value = (decimal)vfo;
        }

        private void chkAudioExpert_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void chkNetworkWDT_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            NetworkIO.SetWatchdogTimer(Convert.ToInt32(chkNetworkWDT.Checked));
        }

        private void comboRX2DispPanDetector_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.specRX.GetSpecRX(1).DetTypePan = comboRX2DispPanDetector.SelectedIndex;

            //[2.10.3.5]MW0LGE note: see updateNormalizePan() in specHPSDR as it only applies to pan detector type 2,3,4
            chkDispRX2Normalize.Enabled = console.specRX.GetSpecRX(1).DetTypePan >= 2;
        }

        private void comboRX2DispPanAveraging_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.specRX.GetSpecRX(1).AverageMode = comboRX2DispPanAveraging.SelectedIndex;
        }

        private void comboRX2DispWFDetector_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.specRX.GetSpecRX(1).DetTypeWF = comboRX2DispWFDetector.SelectedIndex;
        }

        private void comboRX2DispWFAveraging_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.specRX.GetSpecRX(1).AverageModeWF = comboRX2DispWFAveraging.SelectedIndex;
        }

        private void udRX2DisplayWFAVTime_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.specRX.GetSpecRX(1).AvTauWF = 0.001 * (double)udRX2DisplayWFAVTime.Value;
        }

        private void comboDispPanDetector_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.specRX.GetSpecRX(0).DetTypePan = comboDispPanDetector.SelectedIndex;

            //[2.10.3.5]MW0LGE note: see updateNormalizePan() in specHPSDR as it only applies to pan detector type 2,3,4
            chkDispNormalize.Enabled = console.specRX.GetSpecRX(0).DetTypePan >= 2;
        }

        private void comboDispWFDetector_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.specRX.GetSpecRX(0).DetTypeWF = comboDispWFDetector.SelectedIndex;
        }

        private void comboDispPanAveraging_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.specRX.GetSpecRX(0).AverageMode = comboDispPanAveraging.SelectedIndex;
            console.UpdateRXSpectrumDisplayVars();
            console.UpdateTXSpectrumDisplayVars();
        }

        private void comboDispWFAveraging_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.specRX.GetSpecRX(0).AverageModeWF = comboDispWFAveraging.SelectedIndex;
        }

        private void udDisplayAVTimeWF_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.specRX.GetSpecRX(0).AvTauWF = 0.001 * (double)udDisplayAVTimeWF.Value;
        }

        private void chkDispRX2Normalize_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.specRX.GetSpecRX(1).NormOneHzPan = chkDispRX2Normalize.Checked;
        }

        private void chkDispNormalize_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.specRX.GetSpecRX(0).NormOneHzPan = chkDispNormalize.Checked;
        }

        private void comboTXDispPanDetector_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.specRX.GetSpecRX(cmaster.inid(1, 0)).DetTypePan = comboTXDispPanDetector.SelectedIndex;
            console.UpdateTXSpectrumDisplayVars();

            //[2.10.3.5]MW0LGE note: see updateNormalizePan() in specHPSDR as it only applies to pan detector type 2,3,4
            chkDispTXNormalize.Enabled = console.specRX.GetSpecRX(cmaster.inid(1, 0)).DetTypePan >= 2;
        }

        private void comboTXDispPanAveraging_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.specRX.GetSpecRX(cmaster.inid(1, 0)).AverageMode = comboTXDispPanAveraging.SelectedIndex;
            console.UpdateTXSpectrumDisplayVars();
        }

        private void udTXDisplayAVGTime_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.specRX.GetSpecRX(cmaster.inid(1, 0)).AvTau = 0.001 * (double)udTXDisplayAVGTime.Value;
            console.UpdateTXSpectrumDisplayVars();
        }

        private void chkDispTXNormalize_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.specRX.GetSpecRX(cmaster.inid(1, 0)).NormOneHzPan = chkDispTXNormalize.Checked;
            console.UpdateTXSpectrumDisplayVars();
        }

        private void tbTXDisplayFFTSize_Scroll(object sender, EventArgs e)
        {
            console.specRX.GetSpecRX(cmaster.inid(1, 0)).FFTSize = (int)(4096 * Math.Pow(2, Math.Floor((double)(tbTXDisplayFFTSize.Value))));
            console.UpdateTXSpectrumDisplayVars();
            double bin_width = (double)console.specRX.GetSpecRX(cmaster.inid(1, 0)).SampleRate / (double)console.specRX.GetSpecRX(cmaster.inid(1, 0)).FFTSize;
            lblTXDispBinWidth.Text = bin_width.ToString("N3");
        }

        private void comboTXDispWinType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.specRX.GetSpecRX(cmaster.inid(1, 0)).WindowType = comboTXDispWinType.SelectedIndex;
            console.UpdateTXSpectrumDisplayVars();
        }

        private void comboTXDispWFDetector_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.specRX.GetSpecRX(cmaster.inid(1, 0)).DetTypeWF = comboTXDispWFDetector.SelectedIndex;
            console.UpdateTXSpectrumDisplayVars();
        }

        private void comboTXDispWFAveraging_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.specRX.GetSpecRX(cmaster.inid(1, 0)).AverageModeWF = comboTXDispWFAveraging.SelectedIndex;
            console.UpdateTXSpectrumDisplayVars();
        }

        private void udTXDisplayAVTime_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.specRX.GetSpecRX(cmaster.inid(1, 0)).AvTauWF = 0.001 * (double)udTXDisplayAVTime.Value;
            console.UpdateTXSpectrumDisplayVars();
        }

        private void chkBPF2Gnd_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.BPF2Gnd = chkBPF2Gnd.Checked;
        }

        private void ud1_5BPF1Start_ValueChanged(object sender, EventArgs e)
        {

        }

        private void ud1_5BPF1End_ValueChanged(object sender, EventArgs e)
        {
            if (ud1_5BPF1End.Value >= ud6_5BPF1Start.Value)
            {
                ud6_5BPF1Start.Value = ud1_5BPF1End.Value + (decimal)0.000001;
                return;
            }
        }

        private void ud6_5BPF1Start_ValueChanged(object sender, EventArgs e)
        {
            if (ud6_5BPF1Start.Value <= ud1_5BPF1End.Value)
            {
                ud1_5BPF1End.Value = ud6_5BPF1Start.Value - (decimal)0.000001;
                return;
            }
        }

        private void ud6_5BPF1End_ValueChanged(object sender, EventArgs e)
        {
            if (ud6_5BPF1End.Value >= ud9_5BPF1Start.Value)
            {
                ud9_5BPF1Start.Value = ud6_5BPF1End.Value + (decimal)0.000001;
                return;
            }
        }

        private void ud9_5BPF1Start_ValueChanged(object sender, EventArgs e)
        {
            if (ud9_5BPF1Start.Value <= ud6_5BPF1End.Value)
            {
                ud6_5BPF1End.Value = ud9_5BPF1Start.Value - (decimal)0.000001;
                return;
            }
        }

        private void ud9_5BPF1End_ValueChanged(object sender, EventArgs e)
        {
            if (ud9_5BPF1End.Value >= ud13BPF1Start.Value)
            {
                ud13BPF1Start.Value = ud9_5BPF1End.Value + (decimal)0.000001;
                return;
            }
        }

        private void ud13BPF1Start_ValueChanged(object sender, EventArgs e)
        {
            if (ud13BPF1Start.Value <= ud9_5BPF1End.Value)
            {
                ud9_5BPF1End.Value = ud13BPF1Start.Value - (decimal)0.000001;
                return;
            }
        }

        private void ud13BPF1End_ValueChanged(object sender, EventArgs e)
        {
            if (ud13BPF1End.Value >= ud20BPF1Start.Value)
            {
                ud20BPF1Start.Value = ud13BPF1End.Value + (decimal)0.000001;
                return;
            }
        }

        private void ud20BPF1Start_ValueChanged(object sender, EventArgs e)
        {
            if (ud20BPF1Start.Value <= ud13BPF1End.Value)
            {
                ud13BPF1End.Value = ud20BPF1Start.Value - (decimal)0.000001;
                return;
            }
        }

        private void ud20BPF1End_ValueChanged(object sender, EventArgs e)
        {
            if (ud20BPF1End.Value >= ud6BPF1Start.Value)
            {
                ud6BPF1Start.Value = ud20BPF1End.Value + (decimal)0.000001;
                return;
            }
        }

        private void ud6BPF1Start_ValueChanged(object sender, EventArgs e)
        {
            if (ud6BPF1Start.Value <= ud20BPF1End.Value)
            {
                ud20BPF1End.Value = ud6BPF1Start.Value - (decimal)0.000001;
                return;
            }
        }

        private void ud6BPF1End_ValueChanged(object sender, EventArgs e)
        {

        }

        private void chkBPF1_1_5BP_CheckedChanged(object sender, EventArgs e)
        {
            console.BPF1_1_5BPBypass = chkBPF1_1_5BP.Checked;
        }

        private void chkBPF1_6_5BP_CheckedChanged(object sender, EventArgs e)
        {
            console.BPF1_6_5BPBypass = chkBPF1_6_5BP.Checked;
        }

        private void chkBPF1_9_5BP_CheckedChanged(object sender, EventArgs e)
        {
            console.BPF1_9_5BPBypass = chkBPF1_9_5BP.Checked;
        }

        private void chkBPF1_13BP_CheckedChanged(object sender, EventArgs e)
        {
            console.BPF1_13BPBypass = chkBPF1_13BP.Checked;
        }

        private void chkBPF1_20BP_CheckedChanged(object sender, EventArgs e)
        {
            console.BPF1_20BPBypass = chkBPF1_20BP.Checked;
        }

        private void chkBPF1_6BP_CheckedChanged(object sender, EventArgs e)
        {
            console.BPF1_6BPBypass = chkBPF1_6BP.Checked;
        }

        private void chkANAN8000DLEDisplayVoltsAmps_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.ANAN8000DLEDisplayVoltsAmps = chkANAN8000DLEDisplayVoltsAmps.Checked;
        }

        private void ud6mRx2LNAGainOffset_ValueChanged(object sender, EventArgs e)
        {
            console.RX6mGainOffsetRx2 = (float)ud6mRx2LNAGainOffset.Value;
        }

        private void chkEnableXVTRHF_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.EnableXVTRHF = chkEnableXVTRHF.Checked;
        }

        private bool _oldCFCState = false; // is false in frm design
        private void chkCFCEnable_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            int run;
            if (chkCFCEnable.Checked) run = 1;
            else run = 0;
            WDSP.SetTXACFCOMPRun(WDSP.id(1, 0), run);

            //
            console.SetupInfoBarButton(ucInfoBar.ActionTypes.CFC, chkCFCEnable.Checked);

            if (_oldCFCState != chkCFCEnable.Checked)
            {
                console.CFCChangedHandlers?.Invoke(_oldCFCState, chkCFCEnable.Checked);
                _oldCFCState = chkCFCEnable.Checked;
            }
        }

        private void setCFCProfile(object sender, EventArgs e)
        {
            if (initializing) return;
            const int nfreqs = 10;
            double[] F = new double[nfreqs];
            double[] G = new double[nfreqs];
            double[] E = new double[nfreqs];
            F[0] = (double)udCFC0.Value;
            F[1] = (double)udCFC1.Value;
            F[2] = (double)udCFC2.Value;
            F[3] = (double)udCFC3.Value;
            F[4] = (double)udCFC4.Value;
            F[5] = (double)udCFC5.Value;
            F[6] = (double)udCFC6.Value;
            F[7] = (double)udCFC7.Value;
            F[8] = (double)udCFC8.Value;
            F[9] = (double)udCFC9.Value;
            G[0] = (double)tbCFC0.Value;
            G[1] = (double)tbCFC1.Value;
            G[2] = (double)tbCFC2.Value;
            G[3] = (double)tbCFC3.Value;
            G[4] = (double)tbCFC4.Value;
            G[5] = (double)tbCFC5.Value;
            G[6] = (double)tbCFC6.Value;
            G[7] = (double)tbCFC7.Value;
            G[8] = (double)tbCFC8.Value;
            G[9] = (double)tbCFC9.Value;
            E[0] = (double)tbCFCEQ0.Value;
            E[1] = (double)tbCFCEQ1.Value;
            E[2] = (double)tbCFCEQ2.Value;
            E[3] = (double)tbCFCEQ3.Value;
            E[4] = (double)tbCFCEQ4.Value;
            E[5] = (double)tbCFCEQ5.Value;
            E[6] = (double)tbCFCEQ6.Value;
            E[7] = (double)tbCFCEQ7.Value;
            E[8] = (double)tbCFCEQ8.Value;
            E[9] = (double)tbCFCEQ9.Value;
            unsafe
            {
                fixed (double* Fptr = &F[0], Gptr = &G[0], Eptr = &E[0])
                {
                    WDSP.SetTXACFCOMPprofile(WDSP.id(1, 0), nfreqs, Fptr, Gptr, Eptr);
                }
            }

            setDBtip(sender);

            picCFC.Invalidate();
        }

        private void tbCFCPRECOMP_Scroll(object sender, EventArgs e)
        {
            if (initializing) return;
            WDSP.SetTXACFCOMPPrecomp(WDSP.id(1, 0), (double)tbCFCPRECOMP.Value);

            setDBtip(sender);

            picCFC.Invalidate();
        }

        private void chkCFCPeqEnable_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            int run;
            if (chkCFCPeqEnable.Checked) run = 1;
            else run = 0;
            WDSP.SetTXACFCOMPPeqRun(WDSP.id(1, 0), run);

            //
            console.SetupInfoBarButton(ucInfoBar.ActionTypes.CFCeq, chkCFCPeqEnable.Checked);
        }

        private void chkPHROTEnable_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            int run;
            if (chkPHROTEnable.Checked) run = 1;
            else run = 0;
            WDSP.SetTXAPHROTRun(WDSP.id(1, 0), run);
        }

        private void udPhRotFreq_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            WDSP.SetTXAPHROTCorner(WDSP.id(1, 0), (double)udPhRotFreq.Value);
        }

        private void udPHROTStages_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            WDSP.SetTXAPHROTNstages(WDSP.id(1, 0), (int)udPHROTStages.Value);
        }

        private void tbCFCPEG_Scroll(object sender, EventArgs e)
        {
            if (initializing) return;
            WDSP.SetTXACFCOMPPrePeq(WDSP.id(1, 0), (double)tbCFCPEQGAIN.Value);

            setDBtip(sender);
        }

        private void radTXDSB_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            int value = 0;
            if (radTXDSB.Checked)
                value = 0;
            else if (radTXLSB.Checked)
                value = 1;
            else if (radTXUSB.Checked)
                value = 2;
            console.radio.GetDSPTX(0).SubAMMode = value;
        }

        private void btnExportCurrentTXProfile_Click(object sender, EventArgs e)
        {
            ExportCurrentTxProfile();
        }

        private double m_dVAC1Perc1 = 0;
        private double m_dVAC1Perc2 = 0;
        private double m_dVAC2Perc1 = 0;
        private double m_dVAC2Perc2 = 0;
        private int m_nAverageCount = 0;

        private int _oldVAC1OutOverflows = 0;
        private int _oldVAC1OutUnderflows = 0;
        private int _oldVAC1InOverflows = 0;
        private int _oldVAC1InUnderflows = 0;

        private int _oldVAC2OutOverflows = 0;
        private int _oldVAC2OutUnderflows = 0;
        private int _oldVAC2InOverflows = 0;
        private int _oldVAC2InUnderflows = 0;

        private void timer_VAC_Monitor_Tick(object sender, EventArgs e)
        {
            bool updateUI = true;

            if (!lblVAC1ovfl.Visible && !lblVAC2ovfl.Visible && !lblAdvancedAudioWarning.Visible)
            {
                timer_VAC_Monitor.Interval = 100;
                updateUI = false;
            }
            else
            {
                timer_VAC_Monitor.Interval = 50;
            }

            int underflows, overflows, ringsize, nring;
            double var, dP;

            unsafe
            {
                ivac.getIVACdiags(0, 0, &underflows, &overflows, &var, &ringsize, &nring);
            }

            // front end isplay of overflow/underflow MW0LGE_21k9rc5
            if (overflows != _oldVAC1OutOverflows)
            {
                if (overflows != 0) console.VAC1UnderOver.OutOverflow = true;
                _oldVAC1OutOverflows = overflows;
            }
            if (underflows != _oldVAC1OutUnderflows)
            {
                if (underflows != 0) console.VAC1UnderOver.OutUnderflow = true;
                _oldVAC1OutUnderflows = underflows;
            }
            //

            if (updateUI)
            {
                lblVAC1ovfl.Text = overflows.ToString();
                lblVAC1unfl.Text = underflows.ToString();
                lblVAC1var.Text = var.ToString("F6");
                lblVAC1NRing1.Text = nring.ToString("00000");
                lblVAC1RingSize1.Text = ringsize.ToString("00000");
                dP = (nring / (double)ringsize) * 100.0;
                m_dVAC1Perc1 += dP;
                lblVAC1RingPerc1.Text = dP.ToString("000");
                if (chkAudioEnableVAC.Checked) ucVAC1VARGrapherOut.AddDataPoint(var - 1f);
            }
            if (Audio.VAC1ControlFlagOut)
                txtVAC1OldVarOut.Text = var.ToString("F6");

            unsafe
            {
                ivac.getIVACdiags(0, 1, &underflows, &overflows, &var, &ringsize, &nring);
            }

            // front end isplay of overflow/underflow MW0LGE_21k9rc5
            if (overflows != _oldVAC1InOverflows)
            {
                if (overflows != 0) console.VAC1UnderOver.InOverflow = true;
                _oldVAC1InOverflows = overflows;
            }
            if (underflows != _oldVAC1InUnderflows)
            {
                if (underflows != 0) console.VAC1UnderOver.InUnderflow = true;
                _oldVAC1InUnderflows = underflows;
            }
            //

            if (updateUI)
            {
                lblVAC1ovfl2.Text = overflows.ToString();
                lblVAC1unfl2.Text = underflows.ToString();
                lblVAC1var2.Text = var.ToString("F6");
                lblVAC1NRing2.Text = nring.ToString("00000");
                lblVAC1RingSize2.Text = ringsize.ToString("00000");
                dP = (nring / (double)ringsize) * 100.0;
                m_dVAC1Perc2 += dP;
                lblVAC1RingPerc2.Text = dP.ToString("000");
                if (chkAudioEnableVAC.Checked) ucVAC1VARGrapherIn.AddDataPoint(var - 1f);
            }
            if (Audio.VAC1ControlFlagIn)
                txtVAC1OldVarIn.Text = var.ToString("F6");

            unsafe
            {
                ivac.getIVACdiags(1, 0, &underflows, &overflows, &var, &ringsize, &nring);
            }

            // front end isplay of overflow/underflow MW0LGE_21k9rc5
            if (overflows != _oldVAC2OutOverflows)
            {
                if (overflows != 0) console.VAC2UnderOver.OutOverflow = true;
                _oldVAC2OutOverflows = overflows;
            }
            if (underflows != _oldVAC2OutUnderflows)
            {
                if (underflows != 0) console.VAC2UnderOver.OutUnderflow = true;
                _oldVAC2OutUnderflows = underflows;
            }
            //

            if (updateUI)
            {
                lblVAC2ovfl.Text = overflows.ToString();
                lblVAC2unfl.Text = underflows.ToString();
                lblVAC2var.Text = var.ToString("F6");
                lblVAC2NRing1.Text = nring.ToString("00000");
                lblVAC2RingSize1.Text = ringsize.ToString("00000");
                dP = (nring / (double)ringsize) * 100.0;
                m_dVAC2Perc1 += dP;
                lblVAC2RingPerc1.Text = dP.ToString("000");
                if (chkVAC2Enable.Checked) ucVAC2VARGrapherOut.AddDataPoint(var - 1f);
            }

            unsafe
            {
                ivac.getIVACdiags(1, 1, &underflows, &overflows, &var, &ringsize, &nring);
            }

            // front end isplay of overflow/underflow MW0LGE_21k9rc5
            if (overflows != _oldVAC2InOverflows)
            {
                if (overflows != 0) console.VAC2UnderOver.InOverflow = true;
                _oldVAC2InOverflows = overflows;
            }
            if (underflows != _oldVAC2InUnderflows)
            {
                if (underflows != 0) console.VAC2UnderOver.InUnderflow = true;
                _oldVAC2InUnderflows = underflows;
            }
            //

            if (updateUI)
            {
                lblVAC2ovfl2.Text = overflows.ToString();
                lblVAC2unfl2.Text = underflows.ToString();
                lblVAC2var2.Text = var.ToString("F6");
                lblVAC2NRing2.Text = nring.ToString("00000");
                lblVAC2RingSize2.Text = ringsize.ToString("00000");
                dP = (nring / (double)ringsize) * 100.0;
                m_dVAC2Perc2 += dP;
                lblVAC2RingPerc2.Text = dP.ToString("000");
                if (chkVAC2Enable.Checked) ucVAC2VARGrapherIn.AddDataPoint(var - 1f);
            }

            if (updateUI)
            {
                m_nAverageCount++;
                if (m_nAverageCount > 9)
                {
                    m_dVAC1Perc1 /= (m_nAverageCount + 1);
                    m_dVAC1Perc2 /= (m_nAverageCount + 1);
                    m_dVAC2Perc1 /= (m_nAverageCount + 1);
                    m_dVAC2Perc2 /= (m_nAverageCount + 1);

                    lblVAC1RingPercAV1.Text = m_dVAC1Perc1.ToString("000");
                    lblVAC1RingPercAV2.Text = m_dVAC1Perc2.ToString("000");
                    lblVAC2RingPercAV1.Text = m_dVAC2Perc1.ToString("000");
                    lblVAC2RingPercAV2.Text = m_dVAC2Perc2.ToString("000");

                    if (chkAudioEnableVAC.Checked)
                    {
                        ucVAC1VARGrapherOut.RingBufferPerc = m_dVAC1Perc1;
                        ucVAC1VARGrapherIn.RingBufferPerc = m_dVAC1Perc2;
                    }
                    if (chkVAC2Enable.Checked)
                    {
                        ucVAC2VARGrapherOut.RingBufferPerc = m_dVAC2Perc1;
                        ucVAC2VARGrapherIn.RingBufferPerc = m_dVAC2Perc2;
                    }

                    m_nAverageCount = 0;
                }
            }
        }

        private void chkVAC1_Force_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            bool force = chkVAC1_Force.Checked;
            double fvar = (double)udVAC1_Force.Value;
            ivac.forceIVACvar(0, 0, force, fvar);
        }

        private void chkVAC1_Force2_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            bool force = chkVAC1_Force2.Checked;
            double fvar = (double)udVAC1_Force2.Value;
            ivac.forceIVACvar(0, 1, force, fvar);
        }

        private void chkVAC2_Force_CheckedChanged(object sender, EventArgs e)
        {
            bool force = chkVAC2_Force.Checked;
            double fvar = (double)udVAC2_Force.Value;
            ivac.forceIVACvar(1, 0, force, fvar);
        }

        private void chkVAC2_Force2_CheckedChanged(object sender, EventArgs e)
        {
            bool force = chkVAC2_Force2.Checked;
            double fvar = (double)udVAC2_Force2.Value;
            ivac.forceIVACvar(1, 1, force, fvar);
        }

        private void chkBlockTxAnt2_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            radAlexR_160_CheckedChanged(this, EventArgs.Empty);
            radAlexR_80_CheckedChanged(this, EventArgs.Empty);
            radAlexR_60_CheckedChanged(this, EventArgs.Empty);
            radAlexR_40_CheckedChanged(this, EventArgs.Empty);
            radAlexR_30_CheckedChanged(this, EventArgs.Empty);
            radAlexR_20_CheckedChanged(this, EventArgs.Empty);
            radAlexR_17_CheckedChanged(this, EventArgs.Empty);
            radAlexR_15_CheckedChanged(this, EventArgs.Empty);
            radAlexR_12_CheckedChanged(this, EventArgs.Empty);
            radAlexR_10_CheckedChanged(this, EventArgs.Empty);
            radAlexR_6_CheckedChanged(this, EventArgs.Empty);
            console.AlexANT2RXOnly = chkBlockTxAnt2.Checked; // G8NJJ_21h

            if (chkBlockTxAnt2.Checked != _tx_antenna_2_old)
            {
                console.AntennaDoNotTXHandlers?.Invoke(1, _tx_antenna_2_old, chkBlockTxAnt2.Checked);
                _tx_antenna_2_old = chkBlockTxAnt2.Checked;
            }
        }

        private void chkBlockTxAnt3_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            radAlexR_160_CheckedChanged(this, EventArgs.Empty);
            radAlexR_80_CheckedChanged(this, EventArgs.Empty);
            radAlexR_60_CheckedChanged(this, EventArgs.Empty);
            radAlexR_40_CheckedChanged(this, EventArgs.Empty);
            radAlexR_30_CheckedChanged(this, EventArgs.Empty);
            radAlexR_20_CheckedChanged(this, EventArgs.Empty);
            radAlexR_17_CheckedChanged(this, EventArgs.Empty);
            radAlexR_15_CheckedChanged(this, EventArgs.Empty);
            radAlexR_12_CheckedChanged(this, EventArgs.Empty);
            radAlexR_10_CheckedChanged(this, EventArgs.Empty);
            radAlexR_6_CheckedChanged(this, EventArgs.Empty);
            console.AlexANT3RXOnly = chkBlockTxAnt3.Checked; // G8NJJ_21h
            if (chkBlockTxAnt3.Checked != _tx_antenna_3_old)
            {
                console.AntennaDoNotTXHandlers?.Invoke(2, _tx_antenna_3_old, chkBlockTxAnt3.Checked);
                _tx_antenna_3_old = chkBlockTxAnt3.Checked;
            }

        }

        private void chkLPFBypass_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.LPFBypass = chkLPFBypass.Checked;
        }

        private void lblVAC1ovfl_Click(object sender, EventArgs e)
        {
            ivac.resetIVACdiags(0, 0);
        }

        private void lblVAC1unfl_Click(object sender, EventArgs e)
        {
            ivac.resetIVACdiags(0, 0);
        }

        private void lblVAC1ovfl2_Click(object sender, EventArgs e)
        {
            ivac.resetIVACdiags(0, 1);
        }

        private void lblVAC1unfl2_Click(object sender, EventArgs e)
        {
            ivac.resetIVACdiags(0, 1);
        }

        private void lblVAC2ovfl_Click(object sender, EventArgs e)
        {
            ivac.resetIVACdiags(1, 0);
        }

        private void lblVAC2unfl_Click(object sender, EventArgs e)
        {
            ivac.resetIVACdiags(1, 0);
        }

        private void lblVAC2ovfl2_Click(object sender, EventArgs e)
        {
            ivac.resetIVACdiags(1, 1);
        }

        private void lblVAC2unfl2_Click(object sender, EventArgs e)
        {
            ivac.resetIVACdiags(1, 1);
        }

        private void timer_LED_Mirror_Tick(object sender, EventArgs e)
        {
            if (!lblLED01.Visible) //MW0LGE who cares if we cant see it?
            {
                timer_LED_Mirror.Interval = 500; // slow down
                return;
            }
            timer_LED_Mirror.Interval = 10;

            int LED_data = 0;
            LED_data = cmaster.getLEDs();
            Color[] LEDColor = new Color[10];
            for (int i = 0; i < 10; i++)
                if (((LED_data >> i) & 1) == 1)
                    LEDColor[i] = Color.Red;
                else
                    LEDColor[i] = Color.Black;
            lblLED01.BackColor = LEDColor[0];
            lblLED02.BackColor = LEDColor[1];
            lblLED03.BackColor = LEDColor[2];
            lblLED04.BackColor = LEDColor[3];
            lblLED05.BackColor = LEDColor[4];
            lblLED06.BackColor = LEDColor[5];
            lblLED07.BackColor = LEDColor[6];
            lblLED08.BackColor = LEDColor[7];
            lblLED09.BackColor = LEDColor[8];
            lblLED10.BackColor = LEDColor[9];
        }

        private void chkVAC2onSplit_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.VAC2onSplit = chkVAC2onSplit.Checked;
        }

        // DEXP-VOX

        private void chkVOXEnable_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Audio.VOXEnabled = chkVOXEnable.Checked;
            console.VOXEnable = chkVOXEnable.Checked;
            chkDEXPLookAheadEnable_CheckedChanged(this, EventArgs.Empty);
        }

        private void chkDEXPEnable_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            cmaster.SetDEXPRun(0, chkDEXPEnable.Checked);
            console.NoiseGateEnabled = chkDEXPEnable.Checked;
            chkDEXPLookAheadEnable_CheckedChanged(this, EventArgs.Empty);
        }

        private void udDEXPAttack_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            cmaster.SetDEXPAttackTime(0, (double)udDEXPAttack.Value / 1000.0);
        }

        private void udDEXPHold_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            cmaster.SetDEXPHoldTime(0, (double)udDEXPHold.Value / 1000.0);
        }

        private void udDEXPRelease_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            cmaster.SetDEXPReleaseTime(0, (double)udDEXPRelease.Value / 1000.0);
        }

        private void udDEXPThreshold_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            cmaster.CMSetTXAVoxThresh(0, Math.Pow(10.0, (double)udDEXPThreshold.Value / 20.0));
            console.VOXSens = (int)udDEXPThreshold.Value;
        }

        private void udDEXPExpansionRatio_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            cmaster.SetDEXPExpansionRatio(0, Math.Pow(10.0, (double)udDEXPExpansionRatio.Value / 20.0));
        }

        private void udDEXPHysteresisRatio_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            cmaster.SetDEXPHysteresisRatio(0, Math.Pow(10.0, -(double)udDEXPHysteresisRatio.Value / 20.0));
        }

        private void udDEXPDetTau_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            cmaster.SetDEXPDetectorTau(0, (double)udDEXPDetTau.Value / 1000.0);
        }

        private void chkSCFEnable_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            cmaster.SetDEXPRunSideChannelFilter(0, chkSCFEnable.Checked);
        }

        private void udSCFLowCut_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            cmaster.SetDEXPLowCut(0, (double)udSCFLowCut.Value);
        }

        private void udSCFHighCut_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            cmaster.SetDEXPHighCut(0, (double)udSCFHighCut.Value);
        }

        private void chkDEXPLookAheadEnable_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            bool enable = chkDEXPLookAheadEnable.Checked && (chkVOXEnable.Checked || chkDEXPEnable.Checked);
            cmaster.SetDEXPRunAudioDelay(0, enable);
        }

        private void udDEXPLookAhead_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            cmaster.SetDEXPAudioDelay(0, (double)udDEXPLookAhead.Value / 1000.0);
        }

        private void udUpdatesPerStepMax_ValueChanged(object sender, EventArgs e)
        {
            decimal currMin = udUpdatesPerStepMin.Value;
            decimal selectedMax = udUpdatesPerStepMax.Value;
            if (selectedMax <= currMin) udUpdatesPerStepMin.Value = selectedMax - 1; // keep min and max sensible and separated by at least 1
            console.MaxMIDIMessagesPerTuneStep = Convert.ToInt32(selectedMax);
        }

        private void udUpdatesPerStepMin_ValueChanged(object sender, EventArgs e)
        {
            decimal currMax = udUpdatesPerStepMax.Value;
            decimal selectedMin = udUpdatesPerStepMin.Value;
            if (selectedMin >= currMax) udUpdatesPerStepMax.Value = selectedMin + 1;  // keep min and max sensible and separated by at least 1
            console.MinMIDIMessagesPerTuneStep = Convert.ToInt32(selectedMin);
        }

        private void chkAntiVoxEnable_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            cmaster.SetAntiVOXRun(0, chkAntiVoxEnable.Checked);
        }

        private void udAntiVoxGain_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            cmaster.SetAntiVOXGain(0, Math.Pow(10.0, (double)udAntiVoxGain.Value / 20.0));
        }

        private void udAntiVoxTau_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            cmaster.SetAntiVOXDetectorTau(0, (double)udAntiVoxTau.Value / 1000.0);
        }

        private void chkAntiVoxSource_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Audio.AntiVOXSourceVAC = chkAntiVoxSource.Checked;
        }

        private void chkITSync_CheckedChanged(object sender, EventArgs e)
        {
            console.RITXITSync = chkITSync.Checked;
        }

        ///
        ///MW0LGE
        ///
        private void chkDisablePicDisplayBackgroundImage_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return; // ignore until we force call this after init MW0LGE
            console.DisableBackgroundImage = chkDisablePicDisplayBackgroundImage.Checked;
        }

        private void clrbtnDataFill_Changed(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.DataFillColor = Color.FromArgb(tbDataFillAlpha.Value, clrbtnDataFill.Color);
        }

        private void TbDataFillAlpha_Scroll(object sender, EventArgs e)
        {
            toolTip1.SetToolTip(tbDataFillAlpha, tbDataFillAlpha.Value.ToString());
            clrbtnDataFill_Changed(this, EventArgs.Empty);
            if (!initializing) lgLinearGradientRX1.ApplyGlobalAlpha(tbDataFillAlpha.Value); // also adjust LG alpha values, always do this even if disabled MW0LGE_21a
        }
        #region RawInput
        ///--- RAWINPUT
        private void chkWheelTunesOutsideSpectral_CheckedChanged(object sender, EventArgs e)
        {
            console.WheelTunesOutsideSpectral = chkWheelTunesOutsideSpectral.Checked;
        }

        private void ComboHIDMouseWheel_SelectedIndexChanged(object sender, EventArgs e)
        {
            lblRawHIDWarning.Visible = false;

            if (!(comboHIDMouseWheel.SelectedItem is HIDComboItem)) return;

            HIDComboItem objItem = comboHIDMouseWheel.SelectedItem as HIDComboItem;

            if (objItem != null)
            {
                console.SpecificMouseDeviceID = objItem.DeviceID;
                console.SpecificMouseDeviceHandle = objItem.DeviceHandle;
                lblDeviceHID.Text = objItem.DeviceID;
                txtDeviceHID_hidden.Text = objItem.DeviceID; // this control will be saved out

                lblRawHIDWarning.Visible = objItem.source.Contains("_01");
            }
        }
        private void ChkGlobalListenForMouseWheel_CheckedChanged(object sender, EventArgs e)
        {
            console.GlobalListenForMouseWheel = chkGlobalListenForMouseWheel.Checked;
        }

        private void ChkWheelOnlyAdjustsVFO_CheckedChanged(object sender, EventArgs e)
        {
            console.WheelOnlyAdjustsVFO = chkWheelOnlyAdjustsVFO.Checked;
        }

        private void setupHIDControls(bool bEnabled)
        {
            lblRawHIDWarning.Enabled = bEnabled;
            comboHIDMouseWheel.Enabled = bEnabled;
            lblDeviceHID.Enabled = bEnabled;
            chkGlobalListenForMouseWheel.Enabled = bEnabled;
            chkWheelOnlyAdjustsVFO.Enabled = bEnabled;
            lblWheelActive.Enabled = bEnabled;
        }

        private void ChkAlsoUseSpecificMouseWheel_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.AlsoUseSpecificMouseWheel = chkAlsoUseSpecificMouseWheel.Checked;
            setupHIDControls(console.AlsoUseSpecificMouseWheel);
        }

        public void UpdateRawInputMouseDevices(Dictionary<IntPtr, MouseEvent> mouseDevices)
        {
            comboHIDMouseWheel.Items.Clear();

            foreach (KeyValuePair<IntPtr, MouseEvent> entry in mouseDevices)
            {
                MouseEvent me = entry.Value;

                HIDComboItem objItem = new HIDComboItem(me.Name, me.DeviceHandle, me.DeviceName, me.Source);
                int nIndex = comboHIDMouseWheel.Items.Add(objItem);

                if (me.DeviceName == txtDeviceHID_hidden.Text) comboHIDMouseWheel.SelectedIndex = nIndex;
            }
        }

        public void WheelChangeNotify()
        {
            lblWheelActive.BackColor = Color.Green;
            timer_RawInputMouseWheel.Stop();
            timer_RawInputMouseWheel.Start();
        }

        private class HIDComboItem : object
        {
            protected String m_sName;
            protected IntPtr m_nValue;
            protected String m_sID;
            protected string _source;

            public HIDComboItem(String sName, IntPtr nValue, String sID, string source)
            {
                _source = source;
                m_sName = sName;
                m_nValue = nValue;
                m_sID = sID;
            }
            public override string ToString()
            {
                return m_sName;
            }

            public IntPtr DeviceHandle
            {
                get
                {
                    return m_nValue;
                }
                private set
                {

                }
            }
            public String DeviceID
            {
                get
                {
                    return m_sID;
                }
                private set
                {

                }
            }
            public string source
            {
                get { return _source; }
                set { }
            }
        }

        private void Timer_RawInputMouseWheel_Tick(object sender, EventArgs e)
        {
            timer_RawInputMouseWheel.Stop();
            lblWheelActive.BackColor = Color.Red;
        }

        private void TxtDeviceHID_hidden_TextChanged(object sender, EventArgs e)
        {
            foreach (HIDComboItem item in comboHIDMouseWheel.Items)
            {
                if (item.DeviceID == txtDeviceHID_hidden.Text)
                {
                    comboHIDMouseWheel.SelectedItem = item;
                    break;
                }
            }
        }
        #endregion

        private void chkShowRXFilterOnWaterfall_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.ShowRXFilterOnWaterfall = chkShowRXFilterOnWaterfall.Checked;
        }

        private void ChkShowTXFilterOnWaterfall_CheckedChanged(object sender, EventArgs e)
        {
            Display.ShowTXFilterOnWaterfall = chkShowTXFilterOnWaterfall.Checked;
        }

        private void chkShowRXZeroLineOnWaterfall_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.ShowRXZeroLineOnWaterfall = chkShowRXZeroLineOnWaterfall.Checked;
        }

        private void ChkShowTXZeroLineOnWaterfall_CheckedChanged(object sender, EventArgs e)
        {
            Display.ShowTXZeroLineOnWaterfall = chkShowTXZeroLineOnWaterfall.Checked;
        }

        private void chkShowTXFilterOnRXWaterfall_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.ShowTXFilterOnRXWaterfall = chkShowTXFilterOnRXWaterfall.Checked;
        }

        private void ChkZoomShiftModifier_CheckedChanged(object sender, EventArgs e)
        {
            console.ZoomShiftModifier = chkZoomShiftModifier.Checked;
            chkReverseShiftZoomModifier.Enabled = chkZoomShiftModifier.Checked;
        }

        private void ChkReverseShiftZoomModifier_CheckedChanged(object sender, EventArgs e)
        {
            console.ZoomShiftModifierReverse = chkReverseShiftZoomModifier.Checked;
        }

        private void ChkExtended_CheckedChanged(object sender, EventArgs e)
        {
            //MW0LGE_21d
            if (!console.initializing)
            {
                BandStackManager.RegionReset();
            }

            console.Extended = chkExtended.Checked;
        }

        private void chkWaterfallUseRX1SpectrumMinMax_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (chkWaterfallUseRX1SpectrumMinMax.Checked)
            {
                chkRX1WaterfallAGC.Enabled = false;
                udDisplayWaterfallLowLevel.Enabled = false;
                udDisplayWaterfallHighLevel.Enabled = false;
                lblWaterfallAGCOffsetRX1.Enabled = false;
                udWaterfallAGCOffsetRX1.Enabled = false;
                chkWaterfallUseNFForAGCRX1.Enabled = false;
            }
            else
            {
                chkRX1WaterfallAGC.Enabled = true;
                udDisplayWaterfallLowLevel.Enabled = !chkRX1WaterfallAGC.Checked;
                udDisplayWaterfallHighLevel.Enabled = true;
                lblWaterfallAGCOffsetRX1.Enabled = chkRX1WaterfallAGC.Checked;
                udWaterfallAGCOffsetRX1.Enabled = chkRX1WaterfallAGC.Checked;
                chkWaterfallUseNFForAGCRX1.Enabled = chkRX1WaterfallAGC.Checked;
            }

            console.WaterfallUseRX1SpectrumMinMax = chkWaterfallUseRX1SpectrumMinMax.Checked;
        }

        private void chkWaterfallUseRX2SpectrumMinMax_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (chkWaterfallUseRX2SpectrumMinMax.Checked)
            {
                chkRX2WaterfallAGC.Enabled = false;
                udRX2DisplayWaterfallLowLevel.Enabled = false;
                udRX2DisplayWaterfallHighLevel.Enabled = false;
                lblWaterfallAGCOffsetRX2.Enabled = false;
                udWaterfallAGCOffsetRX2.Enabled = false;
                chkWaterfallUseNFForAGCRX2.Enabled = false;
            }
            else
            {
                chkRX2WaterfallAGC.Enabled = true;
                udRX2DisplayWaterfallLowLevel.Enabled = !chkRX2WaterfallAGC.Checked;
                udRX2DisplayWaterfallHighLevel.Enabled = true;
                lblWaterfallAGCOffsetRX2.Enabled = chkRX2WaterfallAGC.Checked;
                udWaterfallAGCOffsetRX2.Enabled = chkRX2WaterfallAGC.Checked;
                chkWaterfallUseNFForAGCRX2.Enabled = chkRX2WaterfallAGC.Checked;
            }

            console.WaterfallUseRX2SpectrumMinMax = chkWaterfallUseRX2SpectrumMinMax.Checked;
        }

        private void chkRecenterOnZZFx_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.CATChangesCenterFreq = chkRecenterOnZZFx.Checked;
        }

        private void udDisplayPhasePtSize_ValueChanged(object sender, EventArgs e)
        {
            Display.PhasePointSize = (int)udDisplayPhasePtSize.Value;
        }

        private void chkShowFPS_CheckedChanged(object sender, EventArgs e)
        {
            Display.ShowFPS = chkShowFPS.Checked;
        }

        private void chkSmallModeFilteronVFOs_CheckedChanged(object sender, EventArgs e)
        {
            console.ShowSmallModeFilterOnVFOs = chkSmallModeFilteronVFOs.Checked;
        }

        private void comboDisplayThreadPriority_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Below Normal
            //Normal
            //Above Normal
            //High

            //ThreadPriority.Lowest         0
            //ThreadPriority.BelowNormal    1
            //ThreadPriority.Normal         2
            //ThreadPriority.AboveNormal    3
            //ThreadPriority.Highest        4

            if (comboDisplayThreadPriority.SelectedIndex < 0) return; // ignore 0 or not selected

            console.DisplayThreadPriority = (ThreadPriority)comboDisplayThreadPriority.SelectedIndex;
        }

        private void btnShowSeqLog_Click(object sender, EventArgs e)
        {
            console.ShowSEQLog();
        }

        private void radSReading_CheckedChanged(object sender, EventArgs e)
        {
            console.MMMeasureMode = MultiMeterMeasureMode.SMeter;
        }

        private void radDBM_CheckedChanged(object sender, EventArgs e)
        {
            console.MMMeasureMode = MultiMeterMeasureMode.DBM;
        }

        private void radUV_CheckedChanged(object sender, EventArgs e)
        {
            console.MMMeasureMode = MultiMeterMeasureMode.UV;
        }

        private void chkAntiAlias_CheckedChanged(object sender, EventArgs e)
        {
            console.AntiAlias = chkAntiAlias.Checked;
        }

        private void clrbtnStatusBarBackground_Changed(object sender, EventArgs e)
        {
            console.StatusBarBackColour = clrbtnStatusBarBackground.Color;
        }

        private void clrbtnStatusBarText_Changed(object sender, EventArgs e)
        {
            console.StatusBarTextColour = clrbtnStatusBarText.Color;
        }

        private void chkAccurateFrameTiming_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.UseAccurateFramingTiming = chkAccurateFrameTiming.Checked;
        }

        public bool PeakBlobsEnabled
        {
            get { return chkPeakBlobsEnabled.Checked; }
            set { chkPeakBlobsEnabled.Checked = value; }
        }

        public bool ActivePeakHoldsEnabled
        {
            get
            {
                return chkActivePeakHoldRX1.Checked || (chkActivePeakHoldRX2.Checked && console.RX2Enabled);
            }
            set
            {
                chkActivePeakHoldRX1.Checked = value;
                if (console.RX2Enabled) chkActivePeakHoldRX2.Checked = value;
            }
        }
        private void chkPeakBlobsEnabled_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            bool bEnabled = chkPeakBlobsEnabled.Checked;
            udPeakBlobs.Enabled = bEnabled;
            chkPeakBlobInsideFilterOnly.Enabled = bEnabled;
            lblBlobMS.Enabled = bEnabled;
            chkBlobPeakHold.Enabled = bEnabled;
            udBlobPeakHoldMS.Enabled = bEnabled && chkBlobPeakHold.Checked;
            chkPeakHoldDrop.Enabled = bEnabled && chkBlobPeakHold.Checked;
            lblPeakBlobDropDBMs.Enabled = bEnabled && chkPeakHoldDrop.Checked;
            udPeakBlobDropDBMs.Enabled = bEnabled && chkPeakHoldDrop.Checked;

            Display.ShowPeakBlobs = bEnabled;

            console.SetupInfoBarButton(ucInfoBar.ActionTypes.Blobs, bEnabled);
        }

        private void udPeakBlobs_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.NumberOfPeakBlobs = (int)udPeakBlobs.Value;
        }

        private void chkPeakBlobInsideFilterOnly_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.ShowPeakBlobsInsideFilterOnly = chkPeakBlobInsideFilterOnly.Checked;
        }

        private void chkSignalHistory_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.UseSignalHistory = chkSignalHistory.Checked;
            udSignalHistoryDuration.Enabled = chkSignalHistory.Checked;
            lblSignalHistoryDurationMS.Enabled = chkSignalHistory.Checked;
        }

        private void clrbtnSignalHistoryColour_Changed(object sender, EventArgs e)
        {
            if (initializing) return;
            console.SignalHistoryColour = Color.FromArgb(tbSignalHistoryAlpha.Value, clrbtnSignalHistoryColour.Color);
        }

        private void tbSignalHistoryAlpha_Scroll(object sender, EventArgs e)
        {
            clrbtnSignalHistoryColour_Changed(this, EventArgs.Empty);
            toolTip1.SetToolTip(tbSignalHistoryAlpha, tbSignalHistoryAlpha.Value.ToString());
        }

        private void chkVSyncDX_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (chkVSyncDX.Checked)
            {
                Display.VerticalBlanks = 1;
                MeterManager.SetVsync(true);
            }
            else
            {
                Display.VerticalBlanks = 0;
                MeterManager.SetVsync(false);
            }
        }

        private void chkBlobPeakHold_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            chkPeakHoldDrop.Enabled = chkBlobPeakHold.Checked && chkBlobPeakHold.Enabled;
            udBlobPeakHoldMS.Enabled = chkBlobPeakHold.Checked && chkBlobPeakHold.Enabled;

            Display.BlobPeakHold = chkBlobPeakHold.Checked;
        }

        private void udBlobPeakHoldMS_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.BlobPeakHoldMS = (double)udBlobPeakHoldMS.Value;
        }

        private void udSignalHistoryDuration_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.SignalHistoryDuration = (int)udSignalHistoryDuration.Value;
        }

        private void udSpaceMoxDelay_ValueChanged(object sender, EventArgs e)
        {
            console.SpaceMoxDelay = (int)udSpaceMoxDelay.Value;
        }

        private void chkBypassVACPlayingRecording_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.BypassVACWhenPlayingRecording = chkBypassVACPlayingRecording.Checked;
        }

        private void ButtonAndromeda_Click(object sender, EventArgs e)
        {
            console.EditAndromedaDataSet();
        }

        private void LabelTS528_Click(object sender, EventArgs e)
        {

        }


        private void ComboGanymedeCATPort_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboGanymedeCATPort.Text == "None")
            {
                if (chkEnableGanymede.Checked)
                {
                    if (comboGanymedeCATPort.Focused)
                        chkEnableGanymede.Checked = false;
                }

                chkEnableGanymede.Enabled = false;
            }
            else chkEnableGanymede.Enabled = true;

            if (comboGanymedeCATPort.Text.StartsWith("COM"))
                console.GanymedeCATPort = Int32.Parse(comboGanymedeCATPort.Text.Substring(3));
        }

        private void ComboAriesCATPort_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboAriesCATPort.Text == "None")
            {
                if (chkEnableAries.Checked)
                {
                    if (comboAriesCATPort.Focused)
                        chkEnableAries.Checked = false;
                }

                chkEnableAries.Enabled = false;
            }
            else chkEnableAries.Enabled = true;

            if (comboAriesCATPort.Text.StartsWith("COM"))
                console.AriesCATPort = Int32.Parse(comboAriesCATPort.Text.Substring(3));
        }

        private void ChkEnableGanymede_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;

            if (comboGanymedeCATPort.Text == "" || !comboGanymedeCATPort.Text.StartsWith("COM"))
            {
                if (chkEnableGanymede.Focused)
                {
                    if (chkEnableGanymede.Checked)
                    {
                        MessageBox.Show("The CAT port \"" + comboGanymedeCATPort.Text + "\" is not a valid port.\n" +
                            "Please select another port.");
                        chkEnableGanymede.Checked = false;
                    }
                }
                return;
            }

            // make sure we're not using the same comm port as the bit banger
            if (chkEnableGanymede.Checked && console.PTTBitBangEnabled &&
                (comboGanymedeCATPort.Text == comboCATPTTPort.Text))
            {
                MessageBox.Show("Ganymede CAT port cannot be the same as Bit Bang Port", "Port Selection Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST); //MW0LGE_[2.9.0.7]
                chkEnableGanymede.Checked = false;
            }

            // if enabled, disable changing of serial port
            bool enable_sub_fields = !chkEnableGanymede.Checked;
            comboGanymedeCATPort.Enabled = enable_sub_fields;

            if (chkEnableGanymede.Checked)
            {
                try
                {
                    console.GanymedeCATEnabled = true;
                }
                catch (Exception ex)
                {
                    console.GanymedeCATEnabled = false;
                    chkEnableGanymede.Checked = false;
                    MessageBox.Show("Could not initialize Ganymede control.  Exception was:\n\n " + ex.Message +
                        "\n\nGanymede control has been disabled.", "Error Initializing Ganymede control",
                        MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST); //MW0LGE_[2.9.0.7]
                }
            }
            else
                console.GanymedeCATEnabled = false;
        }

        private void ChkEnableAries_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;

            if (comboAriesCATPort.Text == "" || !comboAriesCATPort.Text.StartsWith("COM"))
            {
                if (chkEnableAries.Focused)
                {
                    if (chkEnableAries.Checked)
                    {
                        MessageBox.Show("The CAT port \"" + comboAriesCATPort.Text + "\" is not a valid port.\n" +
                            "Please select another port.");
                        chkEnableAries.Checked = false;
                    }
                }
                return;
            }

            // make sure we're not using the same comm port as the bit banger
            if (chkEnableAries.Checked && console.PTTBitBangEnabled &&
                (comboAriesCATPort.Text == comboCATPTTPort.Text))
            {
                MessageBox.Show("Aries CAT port cannot be the same as Bit Bang Port", "Port Selection Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST); //MW0LGE_[2.9.0.7]
                chkEnableAries.Checked = false;
            }

            // if enabled, disable changing of serial port
            bool enable_sub_fields = !chkEnableAries.Checked;
            comboAriesCATPort.Enabled = enable_sub_fields;

            if (chkEnableAries.Checked)
            {
                try
                {
                    console.AriesCATEnabled = true;
                }
                catch (Exception ex)
                {
                    console.AriesCATEnabled = false;
                    chkEnableAries.Checked = false;
                    MessageBox.Show("Could not initialize Aries control.  Exception was:\n\n " + ex.Message +
                        "\n\nAries control has been disabled.", "Error Initializing Aries control",
                        MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST); //MW0LGE_[2.9.0.7]
                }
            }
            else
                console.AriesCATEnabled = false;
        }

        private void ComboGanymedeCATPort_Click(object sender, EventArgs e)
        {
            string[] com_ports = SerialPort.GetPortNames();
            comboGanymedeCATPort.Items.Clear();
            comboGanymedeCATPort.Items.Add("None");
            comboGanymedeCATPort.Items.AddRange(com_ports);
        }

        private void ComboAriesCATPort_Click(object sender, EventArgs e)
        {
            string[] com_ports = SerialPort.GetPortNames();
            comboAriesCATPort.Items.Clear();
            comboAriesCATPort.Items.Add("None");
            comboAriesCATPort.Items.AddRange(com_ports);
        }

        private void BtnGanymedeReset_Click(object sender, EventArgs e)
        {
            console.GanymedeResetPressed();
        }

        private void BtnAriesErase1_Click(object sender, EventArgs e)
        {
            console.AriesErasePressed(1);
        }

        private void BtnAriesErase2_Click(object sender, EventArgs e)
        {
            console.AriesErasePressed(2);
        }

        private void BtnAriesErase3_Click(object sender, EventArgs e)
        {
            console.AriesErasePressed(3);
        }

        private void ChkAries1_CheckedChanged(object sender, EventArgs e)
        {
            console.AriesANT1Enabled = chkAries1.Checked;
        }

        private void ChkAries2_CheckedChanged(object sender, EventArgs e)
        {
            console.AriesANT2Enabled = chkAries2.Checked;
        }

        private void ChkAries3_CheckedChanged(object sender, EventArgs e)
        {
            console.AriesANT3Enabled = chkAries3.Checked;
        }

        // set an aries enabled button for 1 of the 3 antennas
        public void SetAriesEnabledButton(int Antenna, bool State)
        {
            if (Antenna == 1)
                chkAries1.Checked = State;
            else if (Antenna == 2)
                chkAries2.Checked = State;
            else if (Antenna == 3)
                chkAries3.Checked = State;
        }

        private void checkEnableAriesQuickTune_CheckedChanged(object sender, EventArgs e)
        {
            console.AriesQuickTuneEnabled = checkEnableAriesQuickTune.Checked;
        }

        private void chkQSOTimerEnabled_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            bool bEnabled = chkQSOTimerEnabled.Checked;

            chkQSOTimerOnlyDuringMOX.Enabled = bEnabled;
            chkQSOTimerPlaySoundOnExpiry.Enabled = bEnabled;
            chkQSOTimerResetOnMOX.Enabled = bEnabled;

            chkQSOTimerPlaySoundOnExpiry_CheckedChanged(this, EventArgs.Empty);

            chkQSOTimerResetOnExpiry.Enabled = bEnabled;
            chkQSOTimerResetOnExpiry_CheckedChanged(this, EventArgs.Empty);

            udQSOTimerMinutes.Enabled = bEnabled;
            udQSOTimerSeconds.Enabled = bEnabled;
            lblQSOTimerMins.Enabled = bEnabled;
            lblQSOTimerSecs.Enabled = bEnabled;

            console.QSOTimerEnabled = bEnabled;
        }

        private void chkQSOTimerOnlyDuringMOX_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.QSOTimerDuringMoxOnly = chkQSOTimerOnlyDuringMOX.Checked;
        }

        private void chkQSOTimerPlaySoundOnExpiry_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            bool bEnabled = chkQSOTimerEnabled.Checked && chkQSOTimerPlaySoundOnExpiry.Checked;

            btnQSOTimerSelectWAV.Enabled = bEnabled;
            btnQSOTimerPlaySelectedWAV.Enabled = bEnabled && console.QSOTimerAudioPlayer.IsReady;

            console.QSOTimerPlayOnExpiry = bEnabled;
        }

        private void btnQSOTimerSelectWAV_Click(object sender, EventArgs e)
        {
            console.QSOTimerAudioPlayer.Stop();

            using (OpenFileDialog fd = new OpenFileDialog())
            {
                fd.Filter = "wav files(*.wav)|*.wav";
                if (fd.ShowDialog() == DialogResult.OK)
                {
                    console.QSOTimerAudioPlayer.LoadSound(fd.FileName);
                }
            }
        }

        private void btnQSOTimerPlaySelectedWAV_Click(object sender, EventArgs e)
        {
            console.QSOTimerAudioPlayer.Play();
        }

        private void audioFileLoaded(bool bOk)
        {
            btnQSOTimerPlaySelectedWAV.Enabled = chkQSOTimerPlaySoundOnExpiry.Checked && bOk;
        }

        private void udQSOTimerMinutes_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            setQSOTimerDuration();
        }

        private void udQSOTimerSeconds_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            setQSOTimerDuration();
        }

        private void chkQSOTimerResetOnMOX_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.QSOTimerResetOnMox = chkQSOTimerResetOnMOX.Checked;
        }

        private void setQSOTimerDuration()
        {
            if (initializing) return;
            int nDurationSecs = ((int)udQSOTimerMinutes.Value * 60) + (int)udQSOTimerSeconds.Value;
            if (nDurationSecs < 5)
            {
                nDurationSecs = 5;
                udQSOTimerMinutes.Value = 0;
                udQSOTimerSeconds.Value = nDurationSecs;
            }

            console.QSOTimerDuration = nDurationSecs;
        }

        private void chkQSOTimerResetOnExpiry_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.QSOTimerResetOnExpiry = chkQSOTimerResetOnExpiry.Checked;

            chkQSOTimerFlashTimerIfResetOnExpiry.Enabled = chkQSOTimerResetOnExpiry.Enabled && chkQSOTimerResetOnExpiry.Checked;

            chkQSOTimerFlashTimerIfResetOnExpiry_CheckedChanged(this, EventArgs.Empty);
        }

        private void chkQSOTimerFlashTimerIfResetOnExpiry_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.QSOTimerFlashAfterAutoReset = chkQSOTimerFlashTimerIfResetOnExpiry.Checked;
        }
        private bool _firstRadioModelChange = true;
        private void comboRadioModel_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return; // forceallevents will call this  // [2.10.1.0] MW0LGE renabled

            bool power = console.PowerOn;

            HPSDRModel old_model;
            if (_firstRadioModelChange) // unset state // [2.10.1.0] MW0LGE
                old_model = Common.StringModelToEnum(comboRadioModel.Text);
            else
                old_model = console.CurrentHPSDRModel;

            comboAudioSampleRateRX2.Enabled = true;

            switch (Common.StringModelToEnum(comboRadioModel.Text))
            {
                case HPSDRModel.HERMES:
                    console.CurrentHPSDRModel = HPSDRModel.HERMES;
                    chkAlexPresent.Enabled = true;
                    chkApolloPresent.Enabled = true;
                    chkApolloPresent.Visible = true;
                    chkGeneralRXOnly.Visible = true;
                    chkHermesStepAttenuator.Enabled = false; // turn this off MW0LGE_21d
                    udHermesStepAttenuatorData.Enabled = false;
                    chkRX2StepAtt.Checked = false;
                    chkRX2StepAtt.Enabled = false;
                    udHermesStepAttenuatorDataRX2.Enabled = false;
                    groupBoxRXOptions.Text = "Hermes Options";
                    grpMetisAddr.Text = "Hermes Address";
                    grpHermesStepAttenuator.Text = "Hermes Step Attenuator";
                    chkAutoPACalibrate.Checked = false;
                    chkAutoPACalibrate.Visible = false;
                    labelRXAntControl.Text = "  RX1   RX2    XVTR";
                    RXAntChk1Name = "RX1";
                    RXAntChk2Name = "RX2";
                    RXAntChk3Name = "XVTR";
                    labelATTOnTX.Visible = true;
                    udATTOnTX.Visible = true;
                    chkRxOutOnTx.Text = "RX 1 OUT on Tx";
                    chkEXT1OutOnTx.Text = "RX 2 IN on Tx";
                    chkEXT2OutOnTx.Text = "RX 1 IN on Tx";
                    chkEXT2OutOnTx.Visible = true;
                    groupBoxHPSDRHW.Visible = true;
                    chkDisableRXOut.Visible = false;
                    chkBPF2Gnd.Visible = false;
                    chkAutoATTRx1.Enabled = false;
                    chkAutoATTRx2.Enabled = false;
                    setupAttRXControls(1);
                    setupAttRXControls(2);
                    break;

                case HPSDRModel.ANAN10:
                    console.CurrentHPSDRModel = HPSDRModel.ANAN10;
                    chkPennyPresent.Checked = false;
                    chkPennyPresent.Enabled = false;
                    chkMercuryPresent.Checked = true;
                    chkMercuryPresent.Enabled = false;
                    chkPennyLane.Checked = true;
                    chkPennyLane.Enabled = false;
                    chkAlexPresent.Checked = true;
                    chkAlexPresent.Enabled = false;
                    chkApolloPresent.Visible = false;
                    chkApolloPresent.Enabled = false;
                    chkApolloPresent.Checked = false;
                    chkGeneralRXOnly.Visible = true;
                    chkHermesStepAttenuator.Enabled = true;
                    udHermesStepAttenuatorData.Enabled = true;
                    chkRX2StepAtt.Checked = false;
                    chkRX2StepAtt.Enabled = false;
                    udHermesStepAttenuatorDataRX2.Enabled = false;
                    groupBoxRXOptions.Text = "ANAN Options";
                    grpMetisAddr.Text = "ANAN Address";
                    grpHermesStepAttenuator.Text = "ANAN Step Attenuator";
                    tpAlexControl.Text = "Ant/Filters";
                    chkAutoPACalibrate.Checked = false;
                    chkAutoPACalibrate.Visible = false;
                    labelRXAntControl.Text = "  RX1   RX2    XVTR";
                    RXAntChk1Name = "RX1";
                    RXAntChk2Name = "RX2";
                    RXAntChk3Name = "XVTR";
                    chkEXT2OutOnTx.Visible = false;
                    labelATTOnTX.Visible = true;
                    udATTOnTX.Visible = true;
                    groupBoxHPSDRHW.Visible = false;
                    chkDisableRXOut.Visible = false;
                    chkBPF2Gnd.Visible = false;
                    chkAlexPresent_CheckedChanged(this, EventArgs.Empty);
                    chkAlexAntCtrl_CheckedChanged(this, EventArgs.Empty);
                    chkAutoATTRx1.Enabled = true;
                    chkAutoATTRx2.Enabled = false;
                    setupAttRXControls(1);
                    setupAttRXControls(2);
                    break;

                case HPSDRModel.ANAN10E:
                    // set RX2 sample_rate equal to RX1 rate
                    console.CurrentHPSDRModel = HPSDRModel.ANAN10E;
                    comboAudioSampleRateRX2.SelectedIndex = comboAudioSampleRate1.SelectedIndex;
                    comboAudioSampleRateRX2_SelectedIndexChanged(this, e);
                    comboAudioSampleRateRX2.Enabled = false;
                    chkPennyPresent.Checked = false;
                    chkPennyPresent.Enabled = false;
                    chkMercuryPresent.Checked = true;
                    chkMercuryPresent.Enabled = false;
                    chkPennyLane.Checked = true;
                    chkPennyLane.Enabled = false;
                    chkAlexPresent.Checked = true;
                    chkAlexPresent.Enabled = false;
                    chkApolloPresent.Visible = false;
                    chkApolloPresent.Enabled = false;
                    chkApolloPresent.Checked = false;
                    chkGeneralRXOnly.Visible = true;
                    chkHermesStepAttenuator.Enabled = true;
                    udHermesStepAttenuatorData.Enabled = true;
                    chkRX2StepAtt.Checked = false;
                    chkRX2StepAtt.Enabled = false;
                    udHermesStepAttenuatorDataRX2.Enabled = false;
                    groupBoxRXOptions.Text = "ANAN Options";
                    grpMetisAddr.Text = "ANAN Address";
                    grpHermesStepAttenuator.Text = "ANAN Step Attenuator";
                    tpAlexControl.Text = "Ant/Filters";
                    chkAutoPACalibrate.Checked = false;
                    chkAutoPACalibrate.Visible = false;
                    labelRXAntControl.Text = "  RX1   RX2    XVTR";
                    RXAntChk1Name = "RX1";
                    RXAntChk2Name = "RX2";
                    RXAntChk3Name = "XVTR";
                    chkEXT2OutOnTx.Visible = false;
                    labelATTOnTX.Visible = true;
                    udATTOnTX.Visible = true;
                    groupBoxHPSDRHW.Visible = false;
                    chkDisableRXOut.Visible = false;
                    chkBPF2Gnd.Visible = false;
                    chkAlexPresent_CheckedChanged(this, EventArgs.Empty);
                    chkAlexAntCtrl_CheckedChanged(this, EventArgs.Empty);
                    chkAutoATTRx1.Enabled = true;
                    chkAutoATTRx2.Enabled = false;
                    setupAttRXControls(1);
                    setupAttRXControls(2);
                    break;

                case HPSDRModel.ANAN100:
                    console.CurrentHPSDRModel = HPSDRModel.ANAN100;
                    chkPennyPresent.Checked = false;
                    chkPennyPresent.Enabled = false;
                    chkMercuryPresent.Checked = true;
                    chkMercuryPresent.Enabled = false;
                    chkPennyLane.Checked = true;
                    chkPennyLane.Enabled = false;
                    chkAlexPresent.Checked = true;
                    chkAlexPresent.Enabled = true;
                    chkApolloPresent.Visible = false;
                    chkApolloPresent.Enabled = false;
                    chkApolloPresent.Checked = false;
                    chkGeneralRXOnly.Visible = true;
                    chkHermesStepAttenuator.Enabled = true;
                    udHermesStepAttenuatorData.Enabled = true;
                    chkRX2StepAtt.Checked = false;
                    chkRX2StepAtt.Enabled = false;
                    udHermesStepAttenuatorDataRX2.Enabled = false;
                    groupBoxRXOptions.Text = "ANAN Options";
                    grpMetisAddr.Text = "ANAN Address";
                    grpHermesStepAttenuator.Text = "ANAN Step Attenuator";
                    chkAlexPresent_CheckedChanged(this, EventArgs.Empty);
                    chkAlexAntCtrl_CheckedChanged(this, EventArgs.Empty);
                    chkAutoPACalibrate.Checked = false;
                    chkAutoPACalibrate.Visible = false;
                    labelRXAntControl.Text = " EXT2  EXT1  XVTR";
                    RXAntChk1Name = "EXT2";
                    RXAntChk2Name = "EXT1";
                    RXAntChk3Name = "XVTR";
                    labelATTOnTX.Visible = true;
                    udATTOnTX.Visible = true;
                    chkRxOutOnTx.Text = "BYPASS on Tx";
                    chkEXT1OutOnTx.Text = "Ext 1 on Tx";
                    chkEXT2OutOnTx.Text = "Ext 2 on Tx";
                    chkEXT2OutOnTx.Visible = true;
                    groupBoxHPSDRHW.Visible = false;
                    chkDisableRXOut.Visible = true;
                    chkBPF2Gnd.Visible = false;
                    chkAutoATTRx1.Enabled = true;
                    chkAutoATTRx2.Enabled = false;
                    setupAttRXControls(1);
                    setupAttRXControls(2);
                    break;

                case HPSDRModel.ANAN100B:
                    console.CurrentHPSDRModel = HPSDRModel.ANAN100B;
                    comboAudioSampleRateRX2.SelectedIndex = comboAudioSampleRate1.SelectedIndex;
                    comboAudioSampleRateRX2_SelectedIndexChanged(this, e);
                    comboAudioSampleRateRX2.Enabled = false;
                    chkPennyPresent.Checked = false;
                    chkPennyPresent.Enabled = false;
                    chkPennyPresent.Visible = false;
                    chkMercuryPresent.Checked = true;
                    chkMercuryPresent.Enabled = false;
                    chkMercuryPresent.Visible = false;
                    chkPennyLane.Checked = true;
                    chkPennyLane.Enabled = false;
                    chkPennyLane.Visible = false;
                    chkAlexPresent.Checked = true;
                    chkAlexPresent.Enabled = false;
                    chkApolloPresent.Visible = false;
                    chkApolloPresent.Enabled = false;
                    chkApolloPresent.Checked = false;
                    chkGeneralRXOnly.Visible = true;
                    chkHermesStepAttenuator.Enabled = true;
                    udHermesStepAttenuatorData.Enabled = true;
                    chkRX2StepAtt.Checked = false;
                    chkRX2StepAtt.Enabled = false;
                    udHermesStepAttenuatorDataRX2.Enabled = false;
                    groupBoxRXOptions.Text = "ANAN Options";
                    grpMetisAddr.Text = "ANAN Address";
                    grpHermesStepAttenuator.Text = "ANAN Step Attenuator";
                    chkAlexPresent_CheckedChanged(this, EventArgs.Empty);
                    chkAlexAntCtrl_CheckedChanged(this, EventArgs.Empty);
                    chkAutoPACalibrate.Checked = false;
                    chkAutoPACalibrate.Visible = false;
                    labelRXAntControl.Text = " EXT2  EXT1  XVTR";
                    RXAntChk1Name = "EXT2";
                    RXAntChk2Name = "EXT1";
                    RXAntChk3Name = "XVTR";
                    labelATTOnTX.Visible = true;
                    udATTOnTX.Visible = true;
                    chkRxOutOnTx.Text = "BYPASS on Tx";
                    chkEXT1OutOnTx.Text = "Ext 1 on Tx";
                    chkEXT2OutOnTx.Text = "Ext 2 on Tx";
                    chkEXT2OutOnTx.Visible = true;
                    groupBoxHPSDRHW.Visible = false;
                    chkDisableRXOut.Visible = true;
                    chkBPF2Gnd.Visible = false;
                    chkAutoATTRx1.Enabled = true;
                    chkAutoATTRx2.Enabled = false;
                    setupAttRXControls(1);
                    setupAttRXControls(2);
                    break;

                case HPSDRModel.ANAN100D:
                    console.CurrentHPSDRModel = HPSDRModel.ANAN100D;
                    chkPennyPresent.Checked = false;
                    chkPennyPresent.Enabled = false;
                    chkPennyPresent.Visible = false;
                    chkMercuryPresent.Checked = true;
                    chkMercuryPresent.Enabled = false;
                    chkMercuryPresent.Visible = false;
                    chkPennyLane.Checked = true;
                    chkPennyLane.Enabled = false;
                    chkPennyLane.Visible = false;
                    chkAlexPresent.Enabled = true;
                    chkApolloPresent.Visible = false;
                    chkApolloPresent.Enabled = false;
                    chkApolloPresent.Checked = false;
                    chkGeneralRXOnly.Visible = true;
                    chkHermesStepAttenuator.Enabled = true;
                    udHermesStepAttenuatorData.Enabled = true;
                    chkRX2StepAtt.Enabled = true;
                    udHermesStepAttenuatorDataRX2.Enabled = true;
                    groupBoxRXOptions.Text = "ANAN Options";
                    grpMetisAddr.Text = "ANAN Address";
                    grpHermesStepAttenuator.Text = "ANAN Step Attenuator";
                    chkAlexPresent_CheckedChanged(this, EventArgs.Empty);
                    chkAlexAntCtrl_CheckedChanged(this, EventArgs.Empty);
                    chkAutoPACalibrate.Checked = false;
                    chkAutoPACalibrate.Visible = false;
                    chkBypassANANPASettings.Visible = true;
                    labelRXAntControl.Text = " EXT2  EXT1  XVTR";
                    RXAntChk1Name = "EXT2";
                    RXAntChk2Name = "EXT1";
                    RXAntChk3Name = "XVTR";
                    labelATTOnTX.Visible = true;
                    udATTOnTX.Visible = true;
                    chkRX2StepAtt_CheckedChanged(this, EventArgs.Empty);
                    chkRxOutOnTx.Text = "BYPASS on Tx";
                    chkEXT1OutOnTx.Text = "Ext 1 on Tx";
                    chkEXT2OutOnTx.Text = "Ext 2 on Tx";
                    chkEXT2OutOnTx.Visible = true;
                    groupBoxHPSDRHW.Visible = true;
                    chkDisableRXOut.Visible = true;
                    chkBPF2Gnd.Visible = false;
                    radDDC0ADC2.Enabled = false;
                    radDDC1ADC2.Enabled = false;
                    radDDC2ADC2.Enabled = false;
                    radDDC3ADC2.Enabled = false;
                    radDDC4ADC2.Enabled = false;
                    radDDC5ADC2.Enabled = false;
                    radDDC6ADC2.Enabled = false;
                    if (radDDC0ADC2.Checked) radDDC0ADC0.Checked = true;
                    if (radDDC1ADC2.Checked) radDDC1ADC1.Checked = true;
                    if (radDDC2ADC2.Checked) radDDC2ADC0.Checked = true;
                    if (radDDC3ADC2.Checked) radDDC3ADC0.Checked = true;
                    if (radDDC4ADC2.Checked) radDDC4ADC0.Checked = true;
                    if (radDDC5ADC2.Checked) radDDC5ADC0.Checked = true;
                    if (radDDC6ADC2.Checked) radDDC6ADC0.Checked = true;
                    chkAutoATTRx1.Enabled = true;
                    chkAutoATTRx2.Enabled = true;
                    setupAttRXControls(1);
                    setupAttRXControls(2);
                    break;

                case HPSDRModel.ANAN200D:
                    console.CurrentHPSDRModel = HPSDRModel.ANAN200D;
                    chkApolloPresent.Visible = false;
                    chkApolloPresent.Enabled = false;
                    chkApolloPresent.Checked = false;
                    chkGeneralRXOnly.Visible = true;
                    chkHermesStepAttenuator.Enabled = true;
                    udHermesStepAttenuatorData.Enabled = true;
                    chkRX2StepAtt.Enabled = true;
                    udHermesStepAttenuatorDataRX2.Enabled = true;
                    groupBoxRXOptions.Text = "ANAN Options";
                    grpMetisAddr.Text = "ANAN Address";
                    grpHermesStepAttenuator.Text = "ANAN Step Attenuator";
                    chkAutoPACalibrate.Checked = false;
                    chkAutoPACalibrate.Visible = false;
                    chkBypassANANPASettings.Visible = true;
                    chkDisableRXOut.Visible = true;
                    chkBPF2Gnd.Visible = false;
                    labelRXAntControl.Text = " EXT2  EXT1  XVTR";
                    RXAntChk1Name = "EXT2";
                    RXAntChk2Name = "EXT1";
                    RXAntChk3Name = "XVTR";
                    labelATTOnTX.Visible = true;
                    udATTOnTX.Visible = true;
                    chkRX2StepAtt_CheckedChanged(this, EventArgs.Empty);
                    chkRxOutOnTx.Text = "BYPASS on Tx";
                    chkEXT1OutOnTx.Text = "Ext 1 on Tx";
                    chkEXT2OutOnTx.Text = "Ext 2 on Tx";
                    chkEXT2OutOnTx.Visible = true;
                    chkAlexPresent.Parent = grpGeneralHardwareORION;
                    chkAlexPresent.Location = new Point(43, 120);
                    radDDC0ADC2.Enabled = true;
                    radDDC1ADC2.Enabled = true;
                    radDDC2ADC2.Enabled = true;
                    radDDC3ADC2.Enabled = true;
                    radDDC4ADC2.Enabled = true;
                    radDDC5ADC2.Enabled = true;
                    radDDC6ADC2.Enabled = true;
                    chkAutoATTRx1.Enabled = true;
                    chkAutoATTRx2.Enabled = true;
                    setupAttRXControls(1);
                    setupAttRXControls(2);
                    break;

                case HPSDRModel.ANAN7000D:
                    console.CurrentHPSDRModel = HPSDRModel.ANAN7000D;
                    chkPennyPresent.Checked = false;
                    chkPennyPresent.Enabled = false;
                    chkMercuryPresent.Checked = true;
                    chkMercuryPresent.Enabled = false;
                    chkPennyLane.Checked = true;
                    chkPennyLane.Enabled = false;
                    chkAlexPresent.Enabled = true;
                    chkApolloPresent.Visible = false;
                    chkApolloPresent.Enabled = false;
                    chkApolloPresent.Checked = false;
                    chkGeneralRXOnly.Visible = true;
                    chkHermesStepAttenuator.Enabled = true;
                    udHermesStepAttenuatorData.Enabled = true;
                    chkRX2StepAtt.Enabled = true;
                    udHermesStepAttenuatorDataRX2.Enabled = true;
                    groupBoxRXOptions.Text = "ANAN Options";
                    grpMetisAddr.Text = "ANAN Address";
                    grpHermesStepAttenuator.Text = "ANAN Step Attenuator";
                    chkAlexPresent_CheckedChanged(this, EventArgs.Empty);
                    chkAlexAntCtrl_CheckedChanged(this, EventArgs.Empty);
                    chkAutoPACalibrate.Checked = false;
                    chkAutoPACalibrate.Visible = false;
                    chkBypassANANPASettings.Visible = true;
                    labelRXAntControl.Text = "  BYPS  EXT1  XVTR";
                    RXAntChk1Name = "BYPS";
                    RXAntChk2Name = "EXT1";
                    RXAntChk3Name = "XVTR";
                    labelATTOnTX.Visible = true;
                    udATTOnTX.Visible = true;
                    chkRX2StepAtt_CheckedChanged(this, EventArgs.Empty);
                    chkEXT1OutOnTx.Text = "Ext 1 on Tx";
                    chkEXT2OutOnTx.Text = "Rx BYPASS on Tx";
                    chkAlexPresent.Parent = grpGeneralHardwareORION;
                    chkAlexPresent.Location = new Point(43, 120);
                    chkApolloPresent.Parent = grpGeneralHardwareORION;
                    chkApolloPresent.Location = new Point(43, 140);
                    panelAlex1HPFControl.Visible = false;
                    panelBPFControl.Visible = true;
                    chkDisable6mLNAonRX.Parent = panelBPFControl;
                    chkDisable6mLNAonRX.Location = new Point(16, 208);
                    chkDisable6mLNAonTX.Parent = panelBPFControl;
                    chkDisable6mLNAonTX.Location = new Point(63, 208);
                    chkAlexHPFBypass.Parent = panelBPFControl;
                    chkAlexHPFBypass.Location = new Point(140, 185);
                    chkDisableHPFonTX.Parent = panelBPFControl;
                    chkDisableHPFonTX.Location = new Point(140, 213);
                    chkDisableHPFonPSb.Parent = panelBPFControl;
                    chkDisableHPFonPSb.Location = new Point(140, 241);
                    radDDC0ADC2.Enabled = true;
                    radDDC1ADC2.Enabled = true;
                    radDDC2ADC2.Enabled = true;
                    radDDC3ADC2.Enabled = true;
                    radDDC4ADC2.Enabled = true;
                    radDDC5ADC2.Enabled = true;
                    radDDC6ADC2.Enabled = true;
                    chkAutoATTRx1.Enabled = true;
                    chkAutoATTRx2.Enabled = true;
                    setupAttRXControls(1);
                    setupAttRXControls(2);
                    break;

                case HPSDRModel.ANAN8000D:
                    console.CurrentHPSDRModel = HPSDRModel.ANAN8000D;
                    chkPennyPresent.Checked = false;
                    chkPennyPresent.Enabled = false;
                    chkMercuryPresent.Checked = true;
                    chkMercuryPresent.Enabled = false;
                    chkPennyLane.Checked = true;
                    chkPennyLane.Enabled = false;
                    chkAlexPresent.Enabled = true;
                    chkApolloPresent.Visible = false;
                    chkApolloPresent.Enabled = false;
                    chkApolloPresent.Checked = false;
                    chkGeneralRXOnly.Visible = true;
                    chkHermesStepAttenuator.Enabled = true;
                    udHermesStepAttenuatorData.Enabled = true;
                    chkRX2StepAtt.Enabled = true;
                    udHermesStepAttenuatorDataRX2.Enabled = true;
                    groupBoxRXOptions.Text = "ANAN Options";
                    grpMetisAddr.Text = "ANAN Address";
                    grpHermesStepAttenuator.Text = "ANAN Step Attenuator";
                    chkAlexPresent_CheckedChanged(this, EventArgs.Empty);
                    chkAlexAntCtrl_CheckedChanged(this, EventArgs.Empty);
                    chkAutoPACalibrate.Checked = false;
                    chkAutoPACalibrate.Visible = false;
                    chkBypassANANPASettings.Visible = true;
                    labelRXAntControl.Text = "  BYPS  EXT1  XVTR";
                    RXAntChk1Name = "BYPS";
                    RXAntChk2Name = "EXT1";
                    RXAntChk3Name = "XVTR";
                    labelATTOnTX.Visible = true;
                    udATTOnTX.Visible = true;
                    chkRX2StepAtt_CheckedChanged(this, EventArgs.Empty);
                    chkRxOutOnTx.Text = "BYPASS on Tx";
                    chkEXT1OutOnTx.Text = "Ext 1 on Tx";
                    chkEXT2OutOnTx.Visible = false;
                    chkAlexPresent.Parent = grpGeneralHardwareORION;
                    chkAlexPresent.Location = new Point(43, 120);
                    chkApolloPresent.Parent = grpGeneralHardwareORION;
                    chkApolloPresent.Location = new Point(43, 140);
                    panelAlex1HPFControl.Visible = false;
                    panelBPFControl.Visible = true;
                    chkDisable6mLNAonRX.Parent = panelBPFControl;
                    chkDisable6mLNAonRX.Location = new Point(16, 208);
                    chkDisable6mLNAonTX.Parent = panelBPFControl;
                    chkDisable6mLNAonTX.Location = new Point(63, 208);
                    chkAlexHPFBypass.Parent = panelBPFControl;
                    chkAlexHPFBypass.Location = new Point(140, 185);
                    chkDisableHPFonTX.Parent = panelBPFControl;
                    chkDisableHPFonTX.Location = new Point(140, 213);
                    chkDisableHPFonPSb.Parent = panelBPFControl;
                    chkDisableHPFonPSb.Location = new Point(140, 241);
                    radDDC0ADC2.Enabled = true;
                    radDDC1ADC2.Enabled = true;
                    radDDC2ADC2.Enabled = true;
                    radDDC3ADC2.Enabled = true;
                    radDDC4ADC2.Enabled = true;
                    radDDC5ADC2.Enabled = true;
                    radDDC6ADC2.Enabled = true;
                    chkDisableRXOut.Visible = false;
                    chkBPF2Gnd.Visible = true;
                    chkAutoATTRx1.Enabled = true;
                    chkAutoATTRx2.Enabled = true;
                    setupAttRXControls(1);
                    setupAttRXControls(2);
                    break;

                case HPSDRModel.ANAN_G2:                 // added G8NJJ
                    console.CurrentHPSDRModel = HPSDRModel.ANAN_G2;
                    chkPennyPresent.Checked = false;
                    chkPennyPresent.Enabled = false;
                    chkMercuryPresent.Checked = true;
                    chkMercuryPresent.Enabled = false;
                    chkPennyLane.Checked = true;
                    chkPennyLane.Enabled = false;
                    chkAlexPresent.Enabled = true;
                    chkApolloPresent.Visible = false;
                    chkApolloPresent.Enabled = false;
                    chkApolloPresent.Checked = false;
                    chkGeneralRXOnly.Visible = true;
                    chkHermesStepAttenuator.Enabled = true;
                    udHermesStepAttenuatorData.Enabled = true;
                    chkRX2StepAtt.Enabled = true;
                    udHermesStepAttenuatorDataRX2.Enabled = true;
                    groupBoxRXOptions.Text = "ANAN Options";
                    grpMetisAddr.Text = "ANAN Address";
                    grpHermesStepAttenuator.Text = "ANAN Step Attenuator";
                    chkAlexPresent_CheckedChanged(this, EventArgs.Empty);
                    chkAlexAntCtrl_CheckedChanged(this, EventArgs.Empty);
                    chkAutoPACalibrate.Checked = false;
                    chkAutoPACalibrate.Visible = false;
                    chkBypassANANPASettings.Visible = true;
                    labelRXAntControl.Text = "  BYPS  EXT1  XVTR";
                    RXAntChk1Name = "BYPS";
                    RXAntChk2Name = "EXT1";
                    RXAntChk3Name = "XVTR";
                    labelATTOnTX.Visible = true;
                    udATTOnTX.Visible = true;
                    chkRX2StepAtt_CheckedChanged(this, EventArgs.Empty);
                    chkEXT1OutOnTx.Text = "Ext 1 on Tx";
                    chkEXT2OutOnTx.Text = "Rx BYPASS on Tx";
                    chkAlexPresent.Parent = grpGeneralHardwareORION;
                    chkAlexPresent.Location = new Point(43, 120);
                    chkApolloPresent.Parent = grpGeneralHardwareORION;
                    chkApolloPresent.Location = new Point(43, 140);
                    panelAlex1HPFControl.Visible = false;
                    panelBPFControl.Visible = true;
                    chkDisable6mLNAonRX.Parent = panelBPFControl;
                    chkDisable6mLNAonRX.Location = new Point(16, 208);
                    chkDisable6mLNAonTX.Parent = panelBPFControl;
                    chkDisable6mLNAonTX.Location = new Point(63, 208);
                    chkAlexHPFBypass.Parent = panelBPFControl;
                    chkAlexHPFBypass.Location = new Point(140, 185);
                    chkDisableHPFonTX.Parent = panelBPFControl;
                    chkDisableHPFonTX.Location = new Point(140, 213);
                    chkDisableHPFonPSb.Parent = panelBPFControl;
                    chkDisableHPFonPSb.Location = new Point(140, 241);
                    radDDC0ADC2.Enabled = true;
                    radDDC1ADC2.Enabled = true;
                    radDDC2ADC2.Enabled = true;
                    radDDC3ADC2.Enabled = true;
                    radDDC4ADC2.Enabled = true;
                    radDDC5ADC2.Enabled = true;
                    radDDC6ADC2.Enabled = true;
                    chkAutoATTRx1.Enabled = true;
                    chkAutoATTRx2.Enabled = true;
                    setupAttRXControls(1);
                    setupAttRXControls(2);
                    break;

                case HPSDRModel.ANAN_G2_1K:              // added G8NJJ
                    console.CurrentHPSDRModel = HPSDRModel.ANAN_G2_1K;
                    chkPennyPresent.Checked = false;
                    chkPennyPresent.Enabled = false;
                    chkMercuryPresent.Checked = true;
                    chkMercuryPresent.Enabled = false;
                    chkPennyLane.Checked = true;
                    chkPennyLane.Enabled = false;
                    chkAlexPresent.Enabled = true;
                    chkApolloPresent.Visible = false;
                    chkApolloPresent.Enabled = false;
                    chkApolloPresent.Checked = false;
                    chkGeneralRXOnly.Visible = true;
                    chkHermesStepAttenuator.Enabled = true;
                    udHermesStepAttenuatorData.Enabled = true;
                    chkRX2StepAtt.Enabled = true;
                    udHermesStepAttenuatorDataRX2.Enabled = true;
                    groupBoxRXOptions.Text = "ANAN Options";
                    grpMetisAddr.Text = "ANAN Address";
                    grpHermesStepAttenuator.Text = "ANAN Step Attenuator";
                    chkAlexPresent_CheckedChanged(this, EventArgs.Empty);
                    chkAlexAntCtrl_CheckedChanged(this, EventArgs.Empty);
                    chkAutoPACalibrate.Checked = false;
                    chkAutoPACalibrate.Visible = false;
                    chkBypassANANPASettings.Visible = true;
                    labelRXAntControl.Text = "  BYPS  EXT1  XVTR";
                    RXAntChk1Name = "BYPS";
                    RXAntChk2Name = "EXT1";
                    RXAntChk3Name = "XVTR";
                    labelATTOnTX.Visible = true;
                    udATTOnTX.Visible = true;
                    chkRX2StepAtt_CheckedChanged(this, EventArgs.Empty);
                    chkEXT1OutOnTx.Text = "Ext 1 on Tx";
                    chkEXT2OutOnTx.Text = "Rx BYPASS on Tx";
                    chkAlexPresent.Parent = grpGeneralHardwareORION;
                    chkAlexPresent.Location = new Point(43, 120);
                    chkApolloPresent.Parent = grpGeneralHardwareORION;
                    chkApolloPresent.Location = new Point(43, 140);
                    panelAlex1HPFControl.Visible = false;
                    panelBPFControl.Visible = true;
                    chkDisable6mLNAonRX.Parent = panelBPFControl;
                    chkDisable6mLNAonRX.Location = new Point(16, 208);
                    chkDisable6mLNAonTX.Parent = panelBPFControl;
                    chkDisable6mLNAonTX.Location = new Point(63, 208);
                    chkAlexHPFBypass.Parent = panelBPFControl;
                    chkAlexHPFBypass.Location = new Point(140, 185);
                    chkDisableHPFonTX.Parent = panelBPFControl;
                    chkDisableHPFonTX.Location = new Point(140, 213);
                    chkDisableHPFonPSb.Parent = panelBPFControl;
                    chkDisableHPFonPSb.Location = new Point(140, 241);
                    radDDC0ADC2.Enabled = true;
                    radDDC1ADC2.Enabled = true;
                    radDDC2ADC2.Enabled = true;
                    radDDC3ADC2.Enabled = true;
                    radDDC4ADC2.Enabled = true;
                    radDDC5ADC2.Enabled = true;
                    radDDC6ADC2.Enabled = true;
                    chkAutoATTRx1.Enabled = true;
                    chkAutoATTRx2.Enabled = true;
                    setupAttRXControls(1);
                    setupAttRXControls(2);
                    break;
            }

            if (old_model != console.CurrentHPSDRModel)
            {
                setupADCRadioButtions();
                btnResetP2ADC_Click(this, EventArgs.Empty);
                btnResetP1ADC_Click(this, EventArgs.Empty);
            }

            if (_firstRadioModelChange || old_model != console.CurrentHPSDRModel)
            {
                if (!initializing)
                {
                    string sCurrentPAProfile = comboPAProfile.Text;

                    updatePAProfileCombo("Default - " + console.CurrentHPSDRModel.ToString()); //MW0LGE_22b

                    //[2.10.1.0] MW0LGE
                    //re-assign the current if it still exists, this needed because on a DB import, we are changing from HERMES to whatever is set in the DB
                    //and if the PA profile is in the new rebuilt list, let us use it instead of the radio Default
                    for (int n = 0; n < comboPAProfile.Items.Count; n++)
                    {
                        string sName = (string)comboPAProfile.Items[n];

                        if (sName == sCurrentPAProfile)
                        {
                            comboPAProfile.SelectedIndex = n;
                            break;
                        }
                    }
                }
            }

            InitHPSDR();

            if (power && (old_model != console.CurrentHPSDRModel))
            {
                console.PowerOn = false;
                Thread.Sleep(100);
            }
            cmaster.CMLoadRouterAll(console.CurrentHPSDRModel);

            if (power && (old_model != console.CurrentHPSDRModel))
            {
                console.PowerOn = true;
            }

            _firstRadioModelChange = false;

            MeterManager.SetAntennaAuxText(RXAntChk1Name, RXAntChk2Name, RXAntChk3Name);
        }
        private void setupADCRadioButtions()
        {
            bool bADC0 = false;
            bool bADC1 = false;
            bool bADC2 = false;

            switch (console.CurrentHPSDRModel)
            {
                case HPSDRModel.HERMES:
                case HPSDRModel.ANAN10:
                case HPSDRModel.ANAN10E:
                case HPSDRModel.ANAN100:
                case HPSDRModel.ANAN100B:
                    bADC0 = true;
                    break;
                default:
                    bADC0 = true;
                    bADC1 = true;
                    break;
            }

            setADCVisible(tpADC, bADC0, bADC1, bADC2);
        }
        private void setADCVisible(Control cc, bool bADC0, bool bADC1, bool bADC2)
        {
            foreach (Control c in cc.Controls)
            {
                if (c.GetType() == typeof(RadioButtonTS))
                {
                    RadioButtonTS rb = c as RadioButtonTS;
                    if (rb.Name.EndsWith("ADC0"))
                    {
                        rb.Visible = bADC0;
                        // check if ADC1 and ADC2 are false, if so then this will be an 10,10E,100 or 100B, so select this ADC
                        if (!bADC1 && !bADC2) rb.Checked = true;
                    }
                    if (rb.Name.EndsWith("ADC1")) rb.Visible = bADC1;
                    if (rb.Name.EndsWith("ADC2")) rb.Visible = bADC2;
                }
                else if (c.GetType() == typeof(GroupBoxTS))
                {
                    setADCVisible(c, bADC0, bADC1, bADC2);
                }
            }
        }
        public enum SetupTab
        {
            ALCAGC_Tab = 0,
            Transmit_Tab,
            NR_Tab,
            NB_Tab,
            CW_Tab,
            AM_Tab,
            FM_Tab,
            DSPAudio_Tab,
            MNF_Tab,
            VOXDE_Tab,
            CFC_Tab,
            VAC1_Tab,
            VAC2_Tab,
            TEST_Tab,
            OC_Tab,
            DISPGEN_Tab,
            DISPRX1_Tab,
            DISPRX2_Tab,
            SpotTCI,
            OPTIONS2_Tab,
            PA_Tab
        }
        public void ShowSetupTab(SetupTab eTab)
        {
            Show();
            Focus();
            WindowState = FormWindowState.Normal;

            switch (eTab)
            {
                case SetupTab.ALCAGC_Tab:
                    TabSetup.SelectedIndex = 3;
                    TabDSP.SelectedIndex = 2; // select AGC/ALC tab
                    break;
                case SetupTab.Transmit_Tab:
                    TabSetup.SelectedIndex = 4; // select Transmit tab
                    break;
                case SetupTab.NR_Tab:
                    TabSetup.SelectedIndex = 3;
                    TabDSP.SelectedIndex = 7; // select NR tab
                    break;
                case SetupTab.NB_Tab:
                    TabSetup.SelectedIndex = 3;
                    TabDSP.SelectedIndex = 9; // select NB tab
                    break;
                case SetupTab.CW_Tab:
                    TabSetup.SelectedIndex = 3;
                    TabDSP.SelectedIndex = 1; // select CW tab
                    break;
                case SetupTab.AM_Tab:
                    TabSetup.SelectedIndex = 3;
                    TabDSP.SelectedIndex = 3; // select AM tab
                    break;
                case SetupTab.FM_Tab:
                    TabSetup.SelectedIndex = 3;
                    TabDSP.SelectedIndex = 4; // select FM tab
                    break;
                case SetupTab.DSPAudio_Tab:
                    TabSetup.SelectedIndex = 3;
                    TabDSP.SelectedIndex = 5; // select DSP/Audio tab
                    break;
                case SetupTab.MNF_Tab:
                    TabSetup.SelectedIndex = 3;
                    TabDSP.SelectedIndex = 8; // select MNF tab
                    break;
                case SetupTab.VOXDE_Tab:
                    TabSetup.SelectedIndex = 3;
                    TabDSP.SelectedIndex = 10; // select VOX/DE tab
                    break;
                case SetupTab.CFC_Tab:
                    TabSetup.SelectedIndex = 3;
                    TabDSP.SelectedIndex = 11; // select CFC tab
                    break;
                case SetupTab.VAC1_Tab:
                    TabSetup.SelectedIndex = 1; // vac1
                    TabAudio.SelectedIndex = 0;
                    break;
                case SetupTab.VAC2_Tab:
                    TabSetup.SelectedIndex = 1; // vac2
                    TabAudio.SelectedIndex = 1;
                    break;
                case SetupTab.OC_Tab:
                    TabSetup.SelectedIndex = 0; // general
                    TabGeneral.SelectedIndex = 5; // OC pins
                    break;
                case SetupTab.TEST_Tab:
                    TabSetup.SelectedIndex = 9; // tests
                    break;
                case SetupTab.DISPGEN_Tab:
                    TabSetup.SelectedIndex = 2; // display
                    TabDisplay.SelectedIndex = 0; // general
                    break;
                case SetupTab.DISPRX1_Tab:
                    TabSetup.SelectedIndex = 2; // display
                    TabDisplay.SelectedIndex = 1; // rx1
                    break;
                case SetupTab.DISPRX2_Tab:
                    TabSetup.SelectedIndex = 2; // display
                    TabDisplay.SelectedIndex = 2; // rx2
                    break;
                case SetupTab.SpotTCI:
                    TabSetup.SelectedIndex = 8; // cat
                    TabCAT.SelectedIndex = 2; // user
                    break;
                case SetupTab.OPTIONS2_Tab:
                    TabSetup.SelectedIndex = 0; // general
                    TabGeneral.SelectedIndex = 2; // options
                    TabOptions.SelectedIndex = 1; // options2
                    break;
                case SetupTab.PA_Tab:
                    TabSetup.SelectedIndex = 5; // pa
                    TabPowerAmplifier.SelectedIndex = 0; // gains
                    break;
            }
        }

        public static RadioProtocol RadioProtocolSelected { get; set; } = RadioProtocol.ETH;

        private void btnResetP2ADC_Click(object sender, EventArgs e)
        {
            switch (console.CurrentHPSDRModel)
            {
                case HPSDRModel.ANAN10:
                case HPSDRModel.ANAN10E:
                case HPSDRModel.ANAN100:
                case HPSDRModel.ANAN100B:
                    radDDC0ADC0.Checked = true;
                    radDDC1ADC0.Checked = true;
                    radDDC2ADC0.Checked = true;
                    radDDC3ADC0.Checked = true;
                    radDDC4ADC0.Checked = true;
                    radDDC5ADC0.Checked = true;
                    radDDC6ADC0.Checked = true;
                    break;
                default:
                    radDDC0ADC0.Checked = true;
                    radDDC1ADC1.Checked = true;
                    radDDC2ADC0.Checked = true;
                    radDDC3ADC1.Checked = true;
                    radDDC4ADC0.Checked = true;
                    radDDC5ADC0.Checked = true;
                    radDDC6ADC0.Checked = true;
                    break;
            }
        }

        private void btnResetP1ADC_Click(object sender, EventArgs e)
        {
            switch (console.CurrentHPSDRModel)
            {
                case HPSDRModel.ANAN10:
                case HPSDRModel.ANAN10E:
                case HPSDRModel.ANAN100:
                case HPSDRModel.ANAN100B:
                    radP1DDC0ADC0.Checked = true;
                    radP1DDC1ADC0.Checked = true;
                    radP1DDC2ADC0.Checked = true;
                    radP1DDC3ADC0.Checked = true;
                    radP1DDC4ADC0.Checked = true;
                    radP1DDC5ADC0.Checked = true;
                    radP1DDC6ADC0.Checked = true;
                    break;
                default:
                    radP1DDC0ADC0.Checked = true;
                    radP1DDC1ADC1.Checked = true;
                    radP1DDC2ADC1.Checked = true;
                    radP1DDC3ADC0.Checked = true;
                    radP1DDC4ADC0.Checked = true;
                    radP1DDC5ADC0.Checked = true;
                    radP1DDC6ADC0.Checked = true;
                    break;
            }
        }

        private void chkAndrG2Panel_CheckedChanged(object sender, EventArgs e)
        {
            if (chkAndrG2Panel.Checked)
            {
                chkEnableAndromeda.Checked = false;
                chkEnableAndromeda.Enabled = false;
                console.AndromedaG2Enabled = true;
            }
            else
            {
                chkEnableAndromeda.Enabled = true;
                console.AndromedaG2Enabled = false;
            }
        }

        private void checkAriesStandalone_CheckedChanged(object sender, EventArgs e)
        {
            console.AriesStandalone = checkAriesStandalone.Checked;
        }

        private void chkAndrBandBtnDefault_CheckedChanged(object sender, EventArgs e)
        {
            console.AndromedaBandButtonIsDefault = chkAndrBandBtnDefault.Checked;
        }

        private void chkAndrStickyShift_CheckedChanged(object sender, EventArgs e)
        {
            console.AndromedaStickyShift = chkAndrStickyShift.Checked;
        }

        private void chkAndrStickyMenus_CheckedChanged(object sender, EventArgs e)
        {
            console.AndromedaStickyMenus = chkAndrStickyMenus.Checked;
        }

        //private bool m_bIncludeOtherSampleRates = false;
        private void chkIncludeOtherSampleRates_CheckedChanged(object sender, EventArgs e)
        {
            //MW0LGE_21a disabled for now until decision regarding 384k made
            //m_bIncludeOtherSampleRates = chkIncludeOtherSampleRates.Checked;
            //InitAudioTab();
        }

        private void chkActivePeakHoldRX1_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            lblActivePeakHoldRX1.Enabled = chkActivePeakHoldRX1.Checked;
            udActivePeakHoldDurationRX1.Enabled = chkActivePeakHoldRX1.Checked;
            lblActivePeakHoldDropRX1.Enabled = chkActivePeakHoldRX1.Checked;
            udActivePeakHoldDropRX1.Enabled = chkActivePeakHoldRX1.Checked;
            chkFillActivePeakHoldRX1.Enabled = chkActivePeakHoldRX1.Checked;

            Display.SpectralPeakHoldRX1 = chkActivePeakHoldRX1.Checked;
            //
            console.SetupInfoBarButton(ucInfoBar.ActionTypes.ActivePeaks, chkActivePeakHoldRX1.Checked || (console.RX2Enabled && chkActivePeakHoldRX2.Checked));
        }

        private void udActivePeakHoldDurationRX1_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.SpectralPeakHoldDelayRX1 = (double)udActivePeakHoldDurationRX1.Value;
        }

        private void chkActivePeakHoldRX2_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            lblActivePeakHoldRX1.Enabled = chkActivePeakHoldRX2.Checked;
            udActivePeakHoldDurationRX2.Enabled = chkActivePeakHoldRX2.Checked;
            lblActivePeakHoldDropRX2.Enabled = chkActivePeakHoldRX2.Checked;
            udActivePeakHoldDropRX2.Enabled = chkActivePeakHoldRX2.Checked;
            chkFillActivePeakHoldRX2.Enabled = chkActivePeakHoldRX2.Checked;

            Display.SpectralPeakHoldRX2 = chkActivePeakHoldRX2.Checked;

            console.SetupInfoBarButton(ucInfoBar.ActionTypes.ActivePeaks, chkActivePeakHoldRX1.Checked || (console.RX2Enabled && chkActivePeakHoldRX2.Checked));
        }

        private void udActivePeakHoldDurationRX2_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.SpectralPeakHoldDelayRX2 = (double)udActivePeakHoldDurationRX2.Value;
        }

        private void clrbtnActiveSpectralPeak_Changed(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.DataPeaksFillColor = Color.FromArgb(tbActiveSpectralPeakAlpha.Value, clrbtnActiveSpectralPeak.Color);
        }

        private void tbActiveSpectralPeakAlpha_Scroll(object sender, EventArgs e)
        {
            clrbtnActiveSpectralPeak_Changed(this, EventArgs.Empty);
            toolTip1.SetToolTip(tbActiveSpectralPeakAlpha, tbActiveSpectralPeakAlpha.Value.ToString());
        }

        //LG
        public ucLGPicker RX1GradPicker
        {
            get { return lgLinearGradientRX1; }
            set { }
        }

        private void lgPickerRX1_Changed(object sender, EventArgs e)
        {
            rebuildLGBrushes();
        }

        private void btnDeleteColourGripper_Click(object sender, EventArgs e)
        {
            lgLinearGradientRX1.RemoveSelectedGripper(true);
            btnDeleteColourGripper.Enabled = false;
        }

        private void btnClearColourGrippers_Click(object sender, EventArgs e)
        {
            lgLinearGradientRX1.Clear();
        }

        private void lgPickerRX1_GripperSelected(object sender, ColourEventArgs e)
        {
            btnDeleteColourGripper.Enabled = true;
            clrbtnGripperColour.Color = Color.FromArgb(255, e.Colour);
        }

        private void clrbtnGripperColour_Changed(object sender, EventArgs e)
        {
            if (initializing) return;
            lgLinearGradientRX1.ColourForSelectedGripper = clrbtnGripperColour.Color;// c;
            lgLinearGradientRX1.ApplyGlobalAlpha(tbDataFillAlpha.Value);
        }

        private void chkPanadpatorGradient_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            lgLinearGradientRX1.Enabled = chkPanadpatorGradient.Checked;
            btnClearColourGrippers.Enabled = chkPanadpatorGradient.Checked;
            btnDeleteColourGripper.Enabled = chkPanadpatorGradient.Checked;
            clrbtnGripperColour.Enabled = chkPanadpatorGradient.Checked;
            btnDefaultGradient.Enabled = chkPanadpatorGradient.Checked;
            chkDataLineGradient.Enabled = chkPanadpatorGradient.Checked;
            btnLoadGradient.Enabled = chkPanadpatorGradient.Checked;
            btnSaveGradient.Enabled = chkPanadpatorGradient.Checked;

            clrbtnDataFill.Enabled = !chkPanadpatorGradient.Checked;
            lblDisplayDataFill.Enabled = !chkPanadpatorGradient.Checked;

            clrbtnDataLine.Enabled = !chkPanadpatorGradient.Checked || !(chkPanadpatorGradient.Checked && chkDataLineGradient.Checked);

            Display.UseLinearGradient = chkPanadpatorGradient.Checked;
            Display.UseLinearGradientForDataLine = chkDataLineGradient.Checked;
        }

        private void chkSpecWarningLEDRenderDelay_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.ShowFrameRateIssue = chkSpecWarningLEDRenderDelay.Checked;
        }

        private void chkSpecWarningLEDGetPixels_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.ShowGetPixelsIssue = chkSpecWarningLEDGetPixels.Checked;
        }

        private void btnDefaultGradient_Click(object sender, EventArgs e)
        {
            lgLinearGradientRX1.Text = s_DEFAULT_GRADIENT;
            lgLinearGradientRX1.ApplyGlobalAlpha(tbDataFillAlpha.Value);
        }

        private void tbDataLineAlpha_Scroll(object sender, EventArgs e)
        {
            toolTip1.SetToolTip(tbDataLineAlpha, tbDataLineAlpha.Value.ToString());
            clrbtnDataLine_Changed(this, EventArgs.Empty);
        }

        private void chkPeakHoldDrop_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            lblPeakBlobDropDBMs.Enabled = chkPeakHoldDrop.Checked;
            udPeakBlobDropDBMs.Enabled = chkPeakHoldDrop.Checked;

            Display.BlobPeakHoldDrop = chkPeakHoldDrop.Checked;
        }

        private void chkVFOSyncLinksCTUN_CheckedChanged(object sender, EventArgs e)
        {
            console.LinkCTUNonVFOSync = chkVFOSyncLinksCTUN.Checked;
        }

        private void chkDataLineGradient_CheckedChanged(object sender, EventArgs e)
        {
            clrbtnDataLine.Enabled = !chkPanadpatorGradient.Checked || !(chkPanadpatorGradient.Checked && chkDataLineGradient.Checked);

            Display.UseLinearGradientForDataLine = chkDataLineGradient.Checked;
        }

        private void lgPickerRX1_GripperDBMChanged(object sender, GripperEventArgs e)
        {
            toolTip1.SetToolTip(lgLinearGradientRX1, e.DBM.ToString());
        }

        private void lgPickerRX1_GripperMouseLeave(object sender, GripperEventArgs e)
        {
            toolTip1.SetToolTip(lgLinearGradientRX1, "");
        }

        private void lgPickerRX1_GripperMouseEnter(object sender, GripperEventArgs e)
        {
            toolTip1.SetToolTip(lgLinearGradientRX1, e.DBM.ToString());
        }

        private void tmrPLLLockChecker_Tick(object sender, EventArgs e)
        {
            if (NetworkIO.CurrentRadioProtocol == RadioProtocol.ETH && NetworkIO.getHaveSync() == 1)
            {
                lblPLLLock.Text = NetworkIO.GetPLLLock() ? "PLL Locked" : "PLL Not Locked";
            }
            else
            {
                lblPLLLock.Text = "";
            }
        }

        private void comboFRSRegion_MouseEnter(object sender, EventArgs e)
        {
            showRegionBandstackWarning(true);
        }
        private void showRegionBandstackWarning(bool bShow)
        {
            lblWarningRegionExtended.Visible = bShow;
            picWarningRegionExtended.Visible = bShow;
            if (bShow)
            {
                grpFRSRegion.Size = new Size(150, 136);
            }
            else
            {
                grpFRSRegion.Size = new Size(150, 75);
            }
        }

        private void comboFRSRegion_MouseLeave(object sender, EventArgs e)
        {
            showRegionBandstackWarning(false);
        }

        private void chkExtended_MouseEnter(object sender, EventArgs e)
        {
            showRegionBandstackWarning(true);
        }

        private void chkExtended_MouseLeave(object sender, EventArgs e)
        {
            showRegionBandstackWarning(false);
        }

        private void comboFRSRegion_MouseClick(object sender, MouseEventArgs e)
        {
            showRegionBandstackWarning(false);
        }

        private void comboFRSRegion_MouseHover(object sender, EventArgs e)
        {
            showRegionBandstackWarning(true);
        }

        private void chkN1MMEnableRX1_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;

            N1MM.SetEnabled(1, chkN1MMEnableRX1.Checked);
            udN1MMRX1Scaling.Enabled = chkN1MMEnableRX1.Checked;

            N1MM.Resize(1);

            stopStartN1MMSpectrum();

            console.UpdateStatusBarStatusIcons(StatusBarIconGroup.N1MM);
        }

        private void stopStartN1MMSpectrum()
        {
            if (!N1MM.IsStarted && (chkN1MMEnableRX1.Checked || chkN1MMEnableRX2.Checked))
            {
                N1MM.Start();
            }
            else if (N1MM.IsStarted && (!chkN1MMEnableRX1.Checked && !chkN1MMEnableRX2.Checked))
            {
                N1MM.Stop();
            }
        }
        private void chkN1MMEnableRX2_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;

            N1MM.SetEnabled(2, chkN1MMEnableRX2.Checked);
            udN1MMRX2Scaling.Enabled = chkN1MMEnableRX2.Checked;

            N1MM.Resize(2);

            stopStartN1MMSpectrum();

            console.UpdateStatusBarStatusIcons(StatusBarIconGroup.N1MM);
        }

        private void txtN1MMSendTo_TextChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            N1MM.DestinationIP = txtN1MMSendTo.Text;
        }

        private void udN1MMSendRate_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            N1MM.SendRate = (int)udN1MMSendRate.Value;
        }

        private void udN1MMRX1Scaling_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            N1MM.SetScale(1, (float)udN1MMRX1Scaling.Value);
        }

        private void udN1MMRX2Scaling_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            N1MM.SetScale(2, (float)udN1MMRX2Scaling.Value);
        }

        private void tbRX1WaterfallOpacity_Scroll(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.RX1WaterfallOpacity = tbRX1WaterfallOpacity.Value / 100f;
            toolTip1.SetToolTip(tbRX1WaterfallOpacity, tbRX1WaterfallOpacity.Value.ToString() + "% opacity");
        }

        private void tbRX2WaterfallOpacity_Scroll(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.RX2WaterfallOpacity = tbRX2WaterfallOpacity.Value / 100f;
            toolTip1.SetToolTip(tbRX2WaterfallOpacity, tbRX2WaterfallOpacity.Value.ToString() + "% opacity");
        }

        private void chkShowControlDebug_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (chkShowControlDebug.Checked) chkShowDisplayDebug.Checked = false;

            console.EnableControlDebug = chkShowControlDebug.Checked;
        }

        public void UpdateDDCTab()
        {
            lblRxDDC0.Text = "";
            lblRxDDC1.Text = "";
            lblRxDDC2.Text = "";
            lblRxDDC3.Text = "";
            lblRxDDC4.Text = "";
            lblRxDDC5.Text = "";
            lblRxDDC6.Text = "";

            int rx1 = -1, rx2 = -1, sync1 = -1, sync2 = -1, psrx = -1, pstx = -1;
            console.GetDDC(out rx1, out rx2, out sync1, out sync2, out psrx, out pstx);

            int nRX1ADCinUse = console.GetADCInUse(rx1);
            int nRX2ADCinUse = console.GetADCInUse(rx2);
            ADCsLinked = nRX1ADCinUse == nRX2ADCinUse;

            if (NetworkIO.CurrentRadioProtocol == RadioProtocol.ETH) // P2
            {
                lblP1assignment.ForeColor = SystemColors.ControlText;
                lblP1assignment.Font = new Font(lblP1assignment.Font, FontStyle.Regular);

                lblP2assignment.ForeColor = Color.LimeGreen;
                lblP2assignment.Font = new Font(lblP2assignment.Font, FontStyle.Bold);
            }
            else if (NetworkIO.CurrentRadioProtocol == RadioProtocol.USB) // P1
            {
                lblP2assignment.ForeColor = SystemColors.ControlText;
                lblP2assignment.Font = new Font(lblP2assignment.Font, FontStyle.Regular);

                lblP1assignment.ForeColor = Color.LimeGreen;
                lblP1assignment.Font = new Font(lblP1assignment.Font, FontStyle.Bold);
            }

            bool bUpdate = rx1 != -1 || rx2 != -1 || sync1 != -1 || sync2 != -1 || psrx != -1 || pstx != -1;

            if (bUpdate)
            {
                foreach (Control c in tpADC.Controls)
                {
                    LabelTS l = c as LabelTS;
                    if (l != null)
                    {
                        if (l.Name.StartsWith("lblRxDDC") && l.Name.EndsWith(rx1.ToString()))
                        {
                            l.Text = "RX1";
                            l.BackColor = SystemColors.ControlDark;
                        }
                        else if (l.Name.StartsWith("lblRxDDC") && l.Name.EndsWith(rx2.ToString()))
                        {
                            l.Text = "RX2";
                            l.BackColor = SystemColors.ControlDark;
                        }
                        else if (l.Name.StartsWith("lblRxDDC") && l.Name.EndsWith(sync1.ToString()))
                        {
                            l.Text = "RX1 Sync1";
                            l.BackColor = SystemColors.ControlDark;
                        }
                        else if (l.Name.StartsWith("lblRxDDC") && l.Name.EndsWith(sync2.ToString()))
                        {
                            l.Text = "RX1 Sync2";
                            l.BackColor = SystemColors.ControlDark;
                        }
                        else if (l.Name.StartsWith("lblRxDDC") && l.Name.EndsWith(psrx.ToString()))
                        {
                            l.Text = "PS-rx";
                            l.BackColor = SystemColors.ControlDark;
                        }
                        else if (l.Name.StartsWith("lblRxDDC") && l.Name.EndsWith(pstx.ToString()))
                        {
                            l.Text = "PS-tx";
                            l.BackColor = SystemColors.ControlDark;
                        }
                        else
                        {
                            l.BackColor = Color.Transparent;
                        }
                    }
                }
            }
        }

        private void chkHighlightTXProfileSaveItems_CheckedChanged(object sender, EventArgs e)
        {
            highlightTXProfileSaveItems(chkHighlightTXProfileSaveItems.Checked);
        }

        private void btnN1MMDefault_Click(object sender, EventArgs e)
        {
            txtN1MMSendTo.Text = "127.0.0.1:13064";
        }

        //MW0LGE_21h resampler advanced settings
        private void btnVAC1AdvancedDefault_Click(object sender, EventArgs e)
        {
            udVAC1FeedbackGainIn.Value = udVAC1FeedbackGainOut.Value = (decimal)4.0e-6;
            udVAC1SlewTimeIn.Value = udVAC1SlewTimeOut.Value = (decimal)0.003;

            udVAC1PropMinIn.Value = udVAC1PropMinOut.Value = 4096;
            udVAC1PropMaxIn.Value = udVAC1PropMaxOut.Value = 16384;
            udVAC1FFMinIn.Value = udVAC1FFMinOut.Value = 4096;
            udVAC1FFMaxIn.Value = udVAC1FFMaxOut.Value = 262144;

            udVAC1FFAlphaIn.Value = udVAC1FFAlphaOut.Value = (decimal)0.01;

            chkVAC1OldVarIn.Checked = chkVAC1OldVarOut.Checked = false;
        }

        private void udVAC1FeedbackGainIn_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Audio.VAC1FeedbackGainIn = (double)udVAC1FeedbackGainIn.Value;
        }

        private void udVAC1SlewTimeIn_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Audio.VAC1SlewTimeIn = (double)udVAC1SlewTimeIn.Value;
        }
        private void udVAC1FeedbackGainOut_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Audio.VAC1FeedbackGainOut = (double)udVAC1FeedbackGainOut.Value;
        }

        private void udVAC1SlewTimeOut_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Audio.VAC1SlewTimeOut = (double)udVAC1SlewTimeOut.Value;
        }

        private void btnVAC2AdvancedDefault_Click(object sender, EventArgs e)
        {
            udVAC2FeedbackGainIn.Value = udVAC2FeedbackGainOut.Value = (decimal)4.0e-6;
            udVAC2SlewTimeIn.Value = udVAC2SlewTimeOut.Value = (decimal)0.003;

            udVAC2PropMinIn.Value = udVAC2PropMinOut.Value = 4096;
            udVAC2PropMaxIn.Value = udVAC2PropMaxOut.Value = 16384;
            udVAC2FFMinIn.Value = udVAC2FFMinOut.Value = 4096;
            udVAC2FFMaxIn.Value = udVAC2FFMaxOut.Value = 262144;

            udVAC2FFAlphaIn.Value = udVAC2FFAlphaOut.Value = (decimal)0.01;

            chkVAC2OldVarIn.Checked = chkVAC2OldVarOut.Checked = false;
        }

        private void udVAC2FeedbackGainIn_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Audio.VAC2FeedbackGainIn = (double)udVAC2FeedbackGainIn.Value;
        }

        private void udVAC2SlewTimeIn_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Audio.VAC2SlewTimeIn = (double)udVAC2SlewTimeIn.Value;
        }
        private void udVAC2FeedbackGainOut_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Audio.VAC2FeedbackGainOut = (double)udVAC2FeedbackGainOut.Value;
        }

        private void udVAC2SlewTimeOut_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Audio.VAC2SlewTimeOut = (double)udVAC2SlewTimeOut.Value;
        }
        private void pbVAC1FeedbackGainInfo_Click(object sender, EventArgs e)
        {
            toolTip1.Show(toolTip1.GetToolTip(pbVAC1FeedbackGainInfo), pbVAC1FeedbackGainInfo, 10 * 1000);
        }

        private void pbVAC1SlewTimeInfo_Click(object sender, EventArgs e)
        {
            toolTip1.Show(toolTip1.GetToolTip(pbVAC1SlewTimeInfo), pbVAC1SlewTimeInfo, 10 * 1000);
        }
        // end resampler advanced settings

        private void chkNetworkThrottleIndexTweak_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;

            bool bNetworkThrottleIndex = NetworkThrottle.GetNetworkThrottle(out int throttle, false);

            bool bOK = false;
            if (bNetworkThrottleIndex)
            {
                if (chkNetworkThrottleIndexTweak.Checked)
                {
                    if (throttle != unchecked((int)0xffffffffu))
                    {
                        bOK = NetworkThrottle.SetNetworkThrottle(unchecked((int)0xffffffffu));
                    }
                }
                else
                {
                    if (throttle != 0xa)
                    {
                        bOK = NetworkThrottle.SetNetworkThrottle(0xa);
                    }
                }
            }
            if (bOK)
            {
                MessageBox.Show("NetworkThrottleIndex has been changed. You need to restart/reboot for this to take effect.",
                    "Reboot",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST);
            }
            updateNetworkThrottleCheckBox();
        }
        private void updateNetworkThrottleCheckBox()
        {
            // disable the checkbox if there is some issue reading the setting
            bool bNetworkThrottleIndex = NetworkThrottle.GetNetworkThrottle(out int throttle, false);
            chkNetworkThrottleIndexTweak.Enabled = bNetworkThrottleIndex;

            if (bNetworkThrottleIndex)
            {
                chkNetworkThrottleIndexTweak.Checked = throttle == unchecked((int)0xffffffffu);
            }
        }

        private void tbBandstackOverlayAlpha_Scroll(object sender, EventArgs e)
        {
            toolTip1.SetToolTip(tbBandstackOverlayAlpha, tbBandstackOverlayAlpha.Value.ToString());
            clrbtnBandstackOverlay_Changed(this, EventArgs.Empty);
        }

        private void clrbtnBandstackOverlay_Changed(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.BandstackOverlayColor = Color.FromArgb(tbBandstackOverlayAlpha.Value, clrbtnBandstackOverlay.Color);
        }

        private void udVAC1GrapherSwing_ValueChanged(object sender, EventArgs e)
        {
            ucVAC1VARGrapherOut.PlusMinusSwing = ucVAC1VARGrapherIn.PlusMinusSwing = (double)udVAC1GrapherSwing.Value;
        }

        private void chkVAC1GrapherAuto_CheckedChanged(object sender, EventArgs e)
        {
            udVAC1GrapherSwing.Enabled = !chkVAC1GrapherAuto.Checked;
            ucVAC1VARGrapherOut.AutoSwing = ucVAC1VARGrapherIn.AutoSwing = chkVAC1GrapherAuto.Checked;
        }

        private void chkVAC2GrapherAuto_CheckedChanged(object sender, EventArgs e)
        {
            udVAC2GrapherSwing.Enabled = !chkVAC2GrapherAuto.Checked;
            ucVAC2VARGrapherOut.AutoSwing = ucVAC2VARGrapherIn.AutoSwing = chkVAC2GrapherAuto.Checked;
        }

        private void udVAC2GrapherSwing_ValueChanged(object sender, EventArgs e)
        {
            ucVAC2VARGrapherOut.PlusMinusSwing = ucVAC2VARGrapherIn.PlusMinusSwing = (double)udVAC2GrapherSwing.Value;
        }

        private bool isPowerOfTwo(int x)
        {
            return (x != 0) && ((x & (x - 1)) == 0);
        }

        private void udVAC1PropMinIn_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Audio.VAC1PropRingMinIn = (int)udVAC1PropMinIn.Value;
        }

        private void udVAC1PropMaxIn_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            int tmp = (int)udVAC1PropMaxIn.Value;
            int old = Audio.VAC1PropRingMaxIn;

            if (!isPowerOfTwo(tmp))
            {
                if (tmp > old)
                {
                    // inc
                    tmp = Common.FindNextPowerOf2(tmp);
                    udVAC1PropMaxIn.Value = tmp;
                    return;
                }
                else if (tmp < old)
                {
                    // dec
                    tmp = Common.FindPreviousPowerOf2(tmp);
                    udVAC1PropMaxIn.Value = tmp;
                    return;
                }
            }
            Audio.VAC1PropRingMaxIn = (int)udVAC1PropMaxIn.Value;
        }

        private void udVAC1FFMinIn_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Audio.VAC1FFRingMinIn = (int)udVAC1FFMinIn.Value;
        }

        private void udVAC1FFMaxIn_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            int tmp = (int)udVAC1FFMaxIn.Value;
            int old = Audio.VAC1FFRingMaxIn;

            if (!isPowerOfTwo(tmp))
            {
                if (tmp > old)
                {
                    // inc
                    tmp = Common.FindNextPowerOf2(tmp);
                    udVAC1FFMaxIn.Value = tmp;
                    return;
                }
                else if (tmp < old)
                {
                    // dec
                    tmp = Common.FindPreviousPowerOf2(tmp);
                    udVAC1FFMaxIn.Value = tmp;
                    return;
                }
            }
            Audio.VAC1FFRingMaxIn = (int)udVAC1FFMaxIn.Value;
        }

        private void udVAC1FFAlphaIn_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Audio.VAC1FFAlphaIn = (double)udVAC1FFAlphaIn.Value;
        }

        private void chkVAC1OldVarIn_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            txtVAC1OldVarIn_TextChanged(this, EventArgs.Empty);
        }

        private void udVAC1PropMinOut_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Audio.VAC1PropRingMinOut = (int)udVAC1PropMinOut.Value;
        }

        private void udVAC1PropMaxOut_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            int tmp = (int)udVAC1PropMaxOut.Value;
            int old = Audio.VAC1PropRingMaxOut;

            if (!isPowerOfTwo(tmp))
            {
                if (tmp > old)
                {
                    // inc
                    tmp = Common.FindNextPowerOf2(tmp);
                    udVAC1PropMaxOut.Value = tmp;
                    return;
                }
                else if (tmp < old)
                {
                    // dec
                    tmp = Common.FindPreviousPowerOf2(tmp);
                    udVAC1PropMaxOut.Value = tmp;
                    return;
                }
            }
            Audio.VAC1PropRingMaxOut = (int)udVAC1PropMaxOut.Value;
        }

        private void udVAC1FFMinOut_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Audio.VAC1FFRingMinOut = (int)udVAC1FFMinOut.Value;
        }

        private void udVAC1FFMaxOut_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            int tmp = (int)udVAC1FFMaxOut.Value;
            int old = Audio.VAC1FFRingMaxOut;

            if (!isPowerOfTwo(tmp))
            {
                if (tmp > old)
                {
                    // inc
                    tmp = Common.FindNextPowerOf2(tmp);
                    udVAC1FFMaxOut.Value = tmp;
                    return;
                }
                else if (tmp < old)
                {
                    // dec
                    tmp = Common.FindPreviousPowerOf2(tmp);
                    udVAC1FFMaxOut.Value = tmp;
                    return;
                }
            }
            Audio.VAC1FFRingMaxOut = (int)udVAC1FFMaxOut.Value;
        }

        private void udVAC1FFAlphaOut_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Audio.VAC1FFAlphaOut = (double)udVAC1FFAlphaOut.Value;
        }

        private void chkVAC1OldVarOut_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            txtVAC1OldVarOut_TextChanged(this, EventArgs.Empty);
        }

        private void txtVAC1OldVarIn_TextChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            bool bOk = double.TryParse(txtVAC1OldVarIn.Text, out double tmp);
            Audio.VAC1OldVarIn = bOk && chkVAC1OldVarIn.Checked ? tmp : 1.0;
        }

        private void txtVAC1OldVarOut_TextChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            bool bOk = double.TryParse(txtVAC1OldVarOut.Text, out double tmp);
            Audio.VAC1OldVarOut = bOk && chkVAC1OldVarOut.Checked ? tmp : 1.0;
        }

        private void udVAC2PropMinIn_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Audio.VAC2PropRingMinIn = (int)udVAC2PropMinIn.Value;
        }

        private void udVAC2PropMaxIn_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            int tmp = (int)udVAC2PropMaxIn.Value;
            int old = Audio.VAC2PropRingMaxIn;

            if (!isPowerOfTwo(tmp))
            {
                if (tmp > old)
                {
                    // inc
                    tmp = Common.FindNextPowerOf2(tmp);
                    udVAC2PropMaxIn.Value = tmp;
                    return;
                }
                else if (tmp < old)
                {
                    // dec
                    tmp = Common.FindPreviousPowerOf2(tmp);
                    udVAC2PropMaxIn.Value = tmp;
                    return;
                }
            }
            Audio.VAC2PropRingMaxIn = (int)udVAC2PropMaxIn.Value;
        }

        private void udVAC2FFMinIn_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Audio.VAC2FFRingMinIn = (int)udVAC2FFMinIn.Value;
        }

        private void udVAC2FFMaxIn_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            int tmp = (int)udVAC2FFMaxIn.Value;
            int old = Audio.VAC2FFRingMaxIn;

            if (!isPowerOfTwo(tmp))
            {
                if (tmp > old)
                {
                    // inc
                    tmp = Common.FindNextPowerOf2(tmp);
                    udVAC2FFMaxIn.Value = tmp;
                    return;
                }
                else if (tmp < old)
                {
                    // dec
                    tmp = Common.FindPreviousPowerOf2(tmp);
                    udVAC2FFMaxIn.Value = tmp;
                    return;
                }
            }
            Audio.VAC2FFRingMaxIn = (int)udVAC2FFMaxIn.Value;
        }

        private void udVAC2FFAlphaIn_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Audio.VAC2FFAlphaIn = (double)udVAC2FFAlphaIn.Value;
        }

        private void chkVAC2OldVarIn_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            txtVAC2OldVarIn_TextChanged(this, EventArgs.Empty);
        }

        private void udVAC2PropMinOut_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Audio.VAC2PropRingMinOut = (int)udVAC2PropMinOut.Value;
        }

        private void udVAC2PropMaxOut_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            int tmp = (int)udVAC2PropMaxOut.Value;
            int old = Audio.VAC2PropRingMaxOut;

            if (!isPowerOfTwo(tmp))
            {
                if (tmp > old)
                {
                    // inc
                    tmp = Common.FindNextPowerOf2(tmp);
                    udVAC2PropMaxOut.Value = tmp;
                    return;
                }
                else if (tmp < old)
                {
                    // dec
                    tmp = Common.FindPreviousPowerOf2(tmp);
                    udVAC2PropMaxOut.Value = tmp;
                    return;
                }
            }
            Audio.VAC2PropRingMaxOut = (int)udVAC2PropMaxOut.Value;
        }

        private void udVAC2FFMinOut_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Audio.VAC2FFRingMinOut = (int)udVAC2FFMinOut.Value;
        }

        private void udVAC2FFMaxOut_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            int tmp = (int)udVAC2FFMaxOut.Value;
            int old = Audio.VAC2FFRingMaxOut;

            if (!isPowerOfTwo(tmp))
            {
                if (tmp > old)
                {
                    // inc
                    tmp = Common.FindNextPowerOf2(tmp);
                    udVAC2FFMaxOut.Value = tmp;
                    return;
                }
                else if (tmp < old)
                {
                    // dec
                    tmp = Common.FindPreviousPowerOf2(tmp);
                    udVAC2FFMaxOut.Value = tmp;
                    return;
                }
            }
            Audio.VAC2FFRingMaxOut = (int)udVAC2FFMaxOut.Value;
        }

        private void udVAC2FFAlphaOut_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Audio.VAC2FFAlphaOut = (double)udVAC2FFAlphaOut.Value;
        }

        private void chkVAC2OldVarOut_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            txtVAC2OldVarOut_TextChanged(this, EventArgs.Empty);
        }

        private void txtVAC2OldVarIn_TextChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            bool bOk = double.TryParse(txtVAC2OldVarIn.Text, out double tmp);
            Audio.VAC2OldVarIn = bOk && chkVAC2OldVarIn.Checked ? tmp : 1.0;
        }

        private void txtVAC2OldVarOut_TextChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            bool bOk = double.TryParse(txtVAC2OldVarOut.Text, out double tmp);
            Audio.VAC2OldVarOut = bOk && chkVAC2OldVarOut.Checked ? tmp : 1.0;
        }

        private void pbVAC1PropFeedbackMinInfo_Click(object sender, EventArgs e)
        {
            toolTip1.Show(toolTip1.GetToolTip(pbVAC1PropFeedbackMinInfo), pbVAC1PropFeedbackMinInfo, 10 * 1000);
        }

        private void pbVAC1PropFeedbackMaxInfo_Click(object sender, EventArgs e)
        {
            toolTip1.Show(toolTip1.GetToolTip(pbVAC1PropFeedbackMaxInfo), pbVAC1PropFeedbackMaxInfo, 10 * 1000);
        }

        private void pbVAC1FFMinInfo_Click(object sender, EventArgs e)
        {
            toolTip1.Show(toolTip1.GetToolTip(pbVAC1FFMinInfo), pbVAC1FFMinInfo, 10 * 1000);
        }

        private void pbVAC1FFMaxInfo_Click(object sender, EventArgs e)
        {
            toolTip1.Show(toolTip1.GetToolTip(pbVAC1FFMaxInfo), pbVAC1FFMaxInfo, 10 * 1000);
        }

        private void pbVAC1FFAlphaInfo_Click(object sender, EventArgs e)
        {
            toolTip1.Show(toolTip1.GetToolTip(pbVAC1FFAlphaInfo), pbVAC1FFAlphaInfo, 10 * 1000);
        }

        private void comboPin1TXActionHF_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (sender is ComboBoxTS)
            {
                ComboBoxTS combo = sender as ComboBoxTS;
                bool bOk = int.TryParse(combo.Name.Substring(8, 1), out int pin);
                if (bOk)
                    Penny.getPenny().setTXPinAction(0, pin, (TXPinActions)combo.SelectedIndex);
            }
        }

        private void comboPin1TXActionVHF_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (sender is ComboBoxTS)
            {
                ComboBoxTS combo = sender as ComboBoxTS;
                bool bOk = int.TryParse(combo.Name.Substring(8, 1), out int pin);
                if (bOk)
                    Penny.getPenny().setTXPinAction(1, pin, (TXPinActions)combo.SelectedIndex);
            }
        }

        private void comboPin1TXActionSWL_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (sender is ComboBoxTS)
            {
                ComboBoxTS combo = sender as ComboBoxTS;
                bool bOk = int.TryParse(combo.Name.Substring(8, 1), out int pin);
                if (bOk)
                    Penny.getPenny().setTXPinAction(2, pin, (TXPinActions)combo.SelectedIndex);
            }
        }

        public void UpdateOCLedStrip(bool tx, int bits)
        {
            ucOCPinsLedStripHF.TX = tx;
            ucOCPinsLedStripHF.Bits = bits;
        }

        private void tcOCControl_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (grpTransmitPinActionSWL.SelectedIndex)
            {
                case 0:
                    //tpOCHFControl
                    grpOCPinState.Parent = tpOCHFControl;
                    break;
                case 1:
                    //tbOCVHFControl
                    grpOCPinState.Parent = tbOCVHFControl;  //note tb and not tp
                    break;
                case 2:
                    //tpOCSWLControl
                    grpOCPinState.Parent = tpOCSWLControl;
                    break;
            }
        }

        private void chkPin1TXPAHF_CheckedChanged(object sender, EventArgs e)
        {
            if (sender is CheckBoxTS)
            {
                CheckBoxTS chkbox = sender as CheckBoxTS;
                bool bOk = int.TryParse(chkbox.Name.Substring(6, 1), out int pin);
                if (bOk)
                {
                    Penny.getPenny().setTXPinPA(0, pin, chkbox.Checked);
                    console.RepositionExternalPAButton(chkbox.Checked || CheckForAnyExternalPACheckBoxes());
                    console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
                }
            }
        }

        private void chkPin1TXPAVHF_CheckedChanged(object sender, EventArgs e)
        {
            if (sender is CheckBoxTS)
            {
                CheckBoxTS chkbox = sender as CheckBoxTS;
                bool bOk = int.TryParse(chkbox.Name.Substring(6, 1), out int pin);
                if (bOk)
                {
                    Penny.getPenny().setTXPinPA(1, pin, chkbox.Checked);
                    console.RepositionExternalPAButton(chkbox.Checked || CheckForAnyExternalPACheckBoxes());
                    console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
                }
            }
        }

        private void chkPin1TXPASWL_CheckedChanged(object sender, EventArgs e)
        {
            if (sender is CheckBoxTS)
            {
                CheckBoxTS chkbox = sender as CheckBoxTS;
                bool bOk = int.TryParse(chkbox.Name.Substring(6, 1), out int pin);
                if (bOk)
                {
                    Penny.getPenny().setTXPinPA(2, pin, chkbox.Checked);
                    console.RepositionExternalPAButton(chkbox.Checked || CheckForAnyExternalPACheckBoxes());
                    console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
                }
            }
        }

        public bool CheckForAnyExternalPACheckBoxes()
        {
            bool bAtLeastOneChecked = false;

            foreach (Control c in grpExtPAControlHF.Controls)
            {
                if (c is CheckBoxTS)
                {
                    CheckBoxTS cb = c as CheckBoxTS;
                    if (cb != null && cb.Checked)
                    {
                        bAtLeastOneChecked = true;
                        break;
                    }
                }
            }
            foreach (Control c in grpExtPAControlVHF.Controls)
            {
                if (c is CheckBoxTS)
                {
                    CheckBoxTS cb = c as CheckBoxTS;
                    if (cb != null && cb.Checked)
                    {
                        bAtLeastOneChecked = true;
                        break;
                    }
                }
            }
            foreach (Control c in grpExtPAControlSWL.Controls)
            {
                if (c is CheckBoxTS)
                {
                    CheckBoxTS cb = c as CheckBoxTS;
                    if (cb != null && cb.Checked)
                    {
                        bAtLeastOneChecked = true;
                        break;
                    }
                }
            }

            return bAtLeastOneChecked;
        }

        private void chkTuneStepPerModeRX1_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.TuneStepPerModeRX1 = chkTuneStepPerModeRX1.Checked;
        }

        private void chkVAC1WillMute_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.MuteWillMuteVAC1 = chkVAC1WillMute.Checked;
        }

        private void chkVAC2WillMute_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.MuteWillMuteVAC2 = chkVAC2WillMute.Checked;
        }

        private void chkAllowHotSwitching_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.AllowHotSwitchingForOCTXPins = chkAllowHotSwitching.Checked;
        }

        public void UpdateForHotSwitch(bool tx)
        {
            bool enable = !tx || (tx && chkAllowHotSwitching.Checked);

            chkPennyExtCtrl.Enabled = enable;

            foreach (Control c in grpPennyExtCtrl.Controls)
            {
                CheckBox cb = c as CheckBoxTS;
                if (cb != null)
                    if (cb.Name.Length >= 12 && cb.Name.Substring(0, 12) == "chkPenOCxmit") cb.Enabled = enable;
            }
            foreach (Control c in grpPennyExtCtrlVHF.Controls)
            {
                CheckBox cb = c as CheckBoxTS;
                if (cb != null)
                    if (cb.Name.Length >= 12 && cb.Name.Substring(0, 12) == "chkPenOCxmit") cb.Enabled = enable;
            }
            foreach (Control c in grpExtCtrlSWL.Controls)
            {
                CheckBox cb = c as CheckBoxTS;
                if (cb != null)
                    if (cb.Name.Length >= 9 && cb.Name.Substring(0, 9) == "chkOCxmit") cb.Enabled = enable;
            }
        }

        private void chkShowRX1NoiseFloor_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.ShowRX1NoiseFloor = chkShowRX1NoiseFloor.Checked;
        }

        private void chkShowRX2NoiseFloor_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.ShowRX2NoiseFloor = chkShowRX2NoiseFloor.Checked;
        }

        private void chkAutoAGCRX1_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.AutoAGCRX1 = chkAutoAGCRX1.Checked;
        }

        private void chkAutoAGCRX2_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.AutoAGCRX2 = chkAutoAGCRX2.Checked;
        }

        public bool AutoAGCRX1
        {
            get { return chkAutoAGCRX1.Checked; }
            set
            {
                chkAutoAGCRX1.Checked = value;
            }
        }
        public bool AutoAGCRX2
        {
            get { return chkAutoAGCRX2.Checked; }
            set
            {
                chkAutoAGCRX2.Checked = value;
            }
        }
        private void udRX1AutoAGCOffset_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.AutoAGCOffsetRX1 = (double)udRX1AutoAGCOffset.Value;
        }

        private void udRX2AutoAGCOffset_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.AutoAGCOffsetRX2 = (double)udRX2AutoAGCOffset.Value;
        }

        private void chkPin1RXPAHF_CheckedChanged(object sender, EventArgs e)
        {
            if (sender is CheckBoxTS)
            {
                CheckBoxTS chkbox = sender as CheckBoxTS;
                bool bOk = int.TryParse(chkbox.Name.Substring(6, 1), out int pin);
                if (bOk)
                {
                    Penny.getPenny().setRXPinPA(0, pin, chkbox.Checked);
                    console.RepositionExternalPAButton(chkbox.Checked || CheckForAnyExternalPACheckBoxes());
                    console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
                }
            }
        }

        private void chkPin1RXPAVHF_CheckedChanged(object sender, EventArgs e)
        {
            if (sender is CheckBoxTS)
            {
                CheckBoxTS chkbox = sender as CheckBoxTS;
                bool bOk = int.TryParse(chkbox.Name.Substring(6, 1), out int pin);
                if (bOk)
                {
                    Penny.getPenny().setRXPinPA(1, pin, chkbox.Checked);
                    console.RepositionExternalPAButton(chkbox.Checked || CheckForAnyExternalPACheckBoxes());
                    console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
                }
            }
        }

        private void chkPin1RXPASWL_CheckedChanged(object sender, EventArgs e)
        {
            if (sender is CheckBoxTS)
            {
                CheckBoxTS chkbox = sender as CheckBoxTS;
                bool bOk = int.TryParse(chkbox.Name.Substring(6, 1), out int pin);
                if (bOk)
                {
                    Penny.getPenny().setRXPinPA(2, pin, chkbox.Checked);
                    console.RepositionExternalPAButton(chkbox.Checked || CheckForAnyExternalPACheckBoxes());
                    console.PennyExtCtrlEnabled = chkPennyExtCtrl.Checked;  // need side effect of this to push change to native code 
                }
            }
        }

        private void udNoiseFloorAttackRX1_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.AttackTimeInMSForRX1 = (float)udNoiseFloorAttackRX1.Value;
        }

        private void udNoiseFloorAttackRX2_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.AttackTimeInMSForRX2 = (float)udNoiseFloorAttackRX2.Value;
        }

        private void clrbtnNoiseFloor_Changed(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.NoiseFloorColor = clrbtnNoiseFloor.Color;
        }

        private void chkNoiseFloorShowDBM_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.ShowNoiseFloorDBM = chkNoiseFloorShowDBM.Checked;
        }

        private void udNoiseFloorLineWidth_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.NoiseFloorLineWidth = (float)udNoiseFloorLineWidth.Value;
        }

        private void udWaterfallAGCOffsetRX1_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.WaterfallAGCOffsetRX1 = (float)udWaterfallAGCOffsetRX1.Value;
        }

        private void chkWaterfallUseNFForAGCRX1_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.WaterfallUseNFForACGRX1 = chkWaterfallUseNFForAGCRX1.Checked;
        }

        private void udWaterfallAGCOffsetRX2_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.WaterfallAGCOffsetRX2 = (float)udWaterfallAGCOffsetRX2.Value;
        }

        private void chkWaterfallUseNFForAGCRX2_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.WaterfallUseNFForACGRX2 = chkWaterfallUseNFForAGCRX2.Checked;
        }

        private object _cfcValueLock = new object();
        private static double[] _CFCCompValues = new double[1025];
        private bool m_bShowingCFC = false;

        private void tmrCFCOMPGain_Tick(object sender, EventArgs e)
        {
            if (!picCFC.Visible || !chkCFCEnable.Checked || !console.MOX)
            {
                tmrCFCOMPGain.Interval = 1000;
                if (m_bShowingCFC)
                {
                    m_bShowingCFC = false;
                    picCFC.Invalidate();
                }
                return;
            }
            else
            {
                tmrCFCOMPGain.Interval = 32;
            }

            int ready = 0;
            unsafe
            {
                fixed (double* ptrCompValues = &_CFCCompValues[0])
                    WDSP.GetTXACFCOMPDisplayCompression(WDSP.id(1, 0), ptrCompValues, &ready);
            }

            if (ready == 1)
            {
                m_bShowingCFC = true;
                picCFC.Invalidate();
            }
        }

        private void picCFC_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            g.Clear(Color.Black);

            Point[] linePoints;
            int height = picCFC.Height;
            float binsPerHz = 1025 / 48000f;
            int endFreqIndex = (int)((double)udCFC9.Value * binsPerHz);
            int startFreqIndex = (int)((double)udCFC0.Value * binsPerHz);
            int span = endFreqIndex - startFreqIndex;
            float step = picCFC.Width / (float)span;
            double max = (int)udCFCPicDBPerLine.Value - 10;
            int tenDBs = (int)Math.Floor(max / 10f) + 1;
            float penWidth = (float)Math.Ceiling((double)step);

            float scale = height / (tenDBs * 10f);

            if (console.MOX && chkCFCEnable.Checked && span > 0 && m_bShowingCFC)
            {
                // the cfc data
                linePoints = new Point[span + 1];
                using (Pen p = new Pen(Brushes.Red, penWidth))
                {
                    for (int n = startFreqIndex; n <= endFreqIndex; n++)
                    {
                        double dbm = _CFCCompValues[n];

                        int x = (int)((n - startFreqIndex) * step);
                        x += (int)(penWidth / 2);
                        g.DrawLine(p, x, height - 1, x, height - (int)(dbm * scale) - 1);

                        linePoints[n - startFreqIndex] = new Point(x, height - (int)(dbm * scale) - 1);
                    }

                    using (Pen p2 = new Pen(Brushes.White, 2f))
                        g.DrawCurve(p2, linePoints);
                }
            }

            // scale lines
            for (int n = 0; n < tenDBs + 1; n++)
            {
                int y = (int)(n * (scale * 10f));
                g.DrawLine(Pens.White, 0, y, picCFC.Width - 1, y);
            }

            //
            float fLow = (float)udCFC0.Value;
            float fHigh = (float)udCFC9.Value;
            float fWidth = fHigh - fLow;
            float fHzPerPizel = picCFC.Width / fWidth;
            int pre = tbCFCPRECOMP.Value;
            if ((int)(scale * 26f) > height)
                scale = height / 26f; // shrink to view so that it is usable, unless we have more dB height than needed 
                                      // 26f; // where 26 = 16 preamp + 10db slider
            linePoints = new Point[10];
            for (int n = 0; n < 10; n++)
            {
                switch (n)
                {
                    case 0:
                        linePoints[n] = new Point((int)(((float)udCFC0.Value - fLow) * fHzPerPizel), height - (int)((pre + tbCFC0.Value) * scale));
                        break;
                    case 1:
                        linePoints[n] = new Point((int)(((float)udCFC1.Value - fLow) * fHzPerPizel), height - (int)((pre + tbCFC1.Value) * scale));
                        break;
                    case 2:
                        linePoints[n] = new Point((int)(((float)udCFC2.Value - fLow) * fHzPerPizel), height - (int)((pre + tbCFC2.Value) * scale));
                        break;
                    case 3:
                        linePoints[n] = new Point((int)(((float)udCFC3.Value - fLow) * fHzPerPizel), height - (int)((pre + tbCFC3.Value) * scale));
                        break;
                    case 4:
                        linePoints[n] = new Point((int)(((float)udCFC4.Value - fLow) * fHzPerPizel), height - (int)((pre + tbCFC4.Value) * scale));
                        break;
                    case 5:
                        linePoints[n] = new Point((int)(((float)udCFC5.Value - fLow) * fHzPerPizel), height - (int)((pre + tbCFC5.Value) * scale));
                        break;
                    case 6:
                        linePoints[n] = new Point((int)(((float)udCFC6.Value - fLow) * fHzPerPizel), height - (int)((pre + tbCFC6.Value) * scale));
                        break;
                    case 7:
                        linePoints[n] = new Point((int)(((float)udCFC7.Value - fLow) * fHzPerPizel), height - (int)((pre + tbCFC7.Value) * scale));
                        break;
                    case 8:
                        linePoints[n] = new Point((int)(((float)udCFC8.Value - fLow) * fHzPerPizel), height - (int)((pre + tbCFC8.Value) * scale));
                        break;
                    case 9:
                        linePoints[n] = new Point((int)(((float)udCFC9.Value - fLow) * fHzPerPizel), height - (int)((pre + tbCFC9.Value) * scale));
                        break;
                }
            }

            using (Pen p = new Pen(Brushes.White, 2f))
            {
                g.DrawCurve(p, linePoints);
            }
            Rectangle[] rectangles = new Rectangle[10];
            using (Brush b = new SolidBrush(Color.White))
            {
                for (int i = 0; i < linePoints.Length; i++)
                {
                    rectangles[i] = new Rectangle(linePoints[i].X - 2, linePoints[i].Y - 2, 5, 5);
                }
                g.FillRectangles(b, rectangles);
            }
            //
        }

        private void picCFC_Click(object sender, EventArgs e)
        {

        }

        private void chkCFCDisplayAutoScale_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            picCFC.Invalidate();
        }

        private void udCFCPicDBPerLine_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            udCFCPicDBPerLine.Value = (int)(udCFCPicDBPerLine.Value / 10) * 10;
            picCFC.Invalidate();
        }

        private void chkShowDisplayDebug_CheckedChanged(object sender, EventArgs e)
        {
            if (chkShowDisplayDebug.Checked) chkShowControlDebug.Checked = false;

            console.EnableDisplayDebug = chkShowDisplayDebug.Checked;
        }

        private void chkCTLimitDragToSpectral_CheckedChanged(object sender, EventArgs e)
        {
            chkCTLimitDragMouseOnly.Enabled = chkCTLimitDragToSpectral.Checked;
            console.LimitCTUNToSpectralArea = chkCTLimitDragToSpectral.Checked;
        }

        private void chkCTLimitDragMouseOnly_CheckedChanged(object sender, EventArgs e)
        {
            console.LimitCTMouseOnly = chkCTLimitDragMouseOnly.Checked;
        }

        private void udActivePeakHoldDropRX1_ValueChanged(object sender, EventArgs e)
        {
            Display.SpectralPeakFallRX1 = (float)udActivePeakHoldDropRX1.Value;
        }

        private void udActivePeakHoldDropRX2_ValueChanged(object sender, EventArgs e)
        {
            Display.SpectralPeakFallRX2 = (float)udActivePeakHoldDropRX2.Value;
        }

        private void udPeakBlobDropDBMs_ValueChanged(object sender, EventArgs e)
        {
            Display.PeakBlobFall = (float)udPeakBlobDropDBMs.Value;
        }

        private void chkFillActivePeakHoldRX1_CheckedChanged(object sender, EventArgs e)
        {
            Display.ActivePeakFillRX1 = chkFillActivePeakHoldRX1.Checked;
        }

        private void chkFillActivePeakHoldRX2_CheckedChanged(object sender, EventArgs e)
        {
            Display.ActivePeakFillRX2 = chkFillActivePeakHoldRX2.Checked;
        }

        private void chkAFSlidersMute_CheckedChanged(object sender, EventArgs e)
        {
            console.RXAFSlidersWillUnmute = chkAFSlidersMute.Checked;
        }

        private void chkIgnoreMasterAFChangeForMonitor_CheckedChanged(object sender, EventArgs e)
        {
            console.IgnoreAFChangeForMonitor = chkIgnoreMasterAFChangeForMonitor.Checked;
        }

        public bool ShowDisplayMHzCursorInfo
        {
            get { return chkShowMHzOnCursor.Checked; }
            set
            {
                chkShowMHzOnCursor.Checked = value;
            }
        }
        private void chkShowMHzOnCursor_CheckedChanged(object sender, EventArgs e)
        {
            Display.AlwaysShowCursorInfo = chkShowMHzOnCursor.Checked;

            console.SetupInfoBarButton(ucInfoBar.ActionTypes.CursorInfo, chkShowMHzOnCursor.Checked);
        }

        private void chkLimitFilterEdgesToSidebands_CheckedChanged(object sender, EventArgs e)
        {
            console.LimitFiltersToSideBands = chkLimitFilterEdgesToSidebands.Checked;
        }

        private void udDisplayDecimation_ValueChanged(object sender, EventArgs e)
        {
            Display.Decimation = (int)udDisplayDecimation.Value;
            console.SetupDisplayEngine();
        }

        private void chkShowPhaseAngularMean_CheckedChanged(object sender, EventArgs e)
        {
            Display.ShowPhaseAngularMean = chkShowPhaseAngularMean.Checked;
        }

        private void btnDefaultBindPortForTCPIPCat_Click(object sender, EventArgs e)
        {
            txtTCPIPCATServerBindIPPort.Text = "127.0.0.1:13013";
            updateTCPIPPort();
        }
        private void updateTCPIPPort()
        {
            string sValue = txtTCPIPCATServerBindIPPort.Text;

            string[] parts = sValue.Split(':');
            string sTmp = "";
            bool bPortOk = false;
            bool bIPOk = false;
            int port = 13013;
            IPAddress address;

            if (parts.Length == 1) sTmp = sValue;
            else if (parts.Length > 1)
            {
                sTmp = parts[0];
                bPortOk = int.TryParse(parts[1], out port);

                if (bPortOk && (port < 0 || port > 65535)) bPortOk = false;
            }

            //check ip is valid
            bIPOk = IPAddress.TryParse(sTmp, out address);

            if (bIPOk && bPortOk)
            {
                txtTCPIPCATServerBindIPPort.BackColor = SystemColors.Window;
                console.TCPIPCatPort = port;
                console.TCPIPCatIP = address.ToString();
            }
            else
            {
                txtTCPIPCATServerBindIPPort.BackColor = Color.Red;
                lblToggleToUse.Visible = false;
            }
        }

        private void txtTCPIPCATServerBindIPPort_TextChanged(object sender, EventArgs e)
        {
            if (!initializing && chkTCPIPCatServerListening.Checked) lblToggleToUse.Visible = true;

            updateTCPIPPort();
        }

        private void chkTCPIPCatServerListening_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            // this is setup in init, after the ip and port have been recovered and inializing is false
            btnShowTCPIPCatLog.Enabled = chkTCPIPCatServerListening.Checked;
            lblToggleToUse.Visible = false;
            console.SetupTCPIPCat(chkTCPIPCatServerListening.Checked);
        }

        private void chkZTBIsRecallStore_CheckedChanged(object sender, EventArgs e)
        {
            console.ZTBisRecallStore = chkZTBIsRecallStore.Checked;
            chkZTBstoreLock.Enabled = chkZTBIsRecallStore.Checked;
        }

        private void chkZTBstoreLock_CheckedChanged(object sender, EventArgs e)
        {
            console.ZTBstoreLock = chkZTBstoreLock.Checked;
        }

        public void DisableTCPIPCatServerDueToError()
        {
            chkTCPIPCatServerListening.Checked = false;
            btnShowTCPIPCatLog.Enabled = false;
        }
        public void DisableTCIServerDueToError()
        {
            chkTCIServerListening.Checked = false;
            btnShowLog.Enabled = false;
        }

        private void chkCTUNignore0beat_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.CTUNputsZeroOnMouse = !chkCTUNignore0beat.Checked;
        }

        public void SetupDSPWarnings(bool bufferSizeDifferentRX, bool filterSizeDifferentRX, bool filterTypeDifferentRX, bool bufferSizeDifferentTX, bool filterSizeDifferentTX, bool filterTypeDifferentTX)
        {
            pbWarningBufferSize.Visible = bufferSizeDifferentRX || bufferSizeDifferentTX;
            lblWarningBufferSize.Visible = bufferSizeDifferentRX || bufferSizeDifferentTX;

            pbWarningFilterSize.Visible = filterSizeDifferentRX || filterSizeDifferentTX;
            lblWarningFilterSize.Visible = filterSizeDifferentRX || filterSizeDifferentTX;

            pbWarningBufferType.Visible = filterTypeDifferentRX || filterTypeDifferentTX;
            lblWarningBufferType.Visible = filterTypeDifferentRX || filterTypeDifferentTX;
        }
        public long DSPChangeDuration
        {
            set
            {
                lblTimeToMakeDSPChange.Text = value.ToString() + " ms @ " + DateTime.UtcNow.ToString() + " utc";
            }
        }

        private void txtTCIServerBindIPPort_TextChanged(object sender, EventArgs e)
        {
            if (!initializing && chkTCIServerListening.Checked) lblToggleToUseTCI.Visible = true;

            updateTCIPort();
        }

        private void btnDefaultBindPortForTCI_Click(object sender, EventArgs e)
        {
            txtTCIServerBindIPPort.Text = "127.0.0.1:50001";
            updateTCIPort();
        }

        private void chkTCIServerListening_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            // this is setup in init, after the ip and port have been recovered and inializing is false
            btnShowLog.Enabled = chkTCIServerListening.Checked;
            lblToggleToUseTCI.Visible = false;
            console.SetupTCI(chkTCIServerListening.Checked, (int)udTCIRateLimit.Value);
        }
        public void StartupTCIServer()
        {
            chkTCIServerListening_CheckedChanged(this, EventArgs.Empty);
        }
        public void StartupTCPIPcatServer()
        {
            chkTCPIPCatServerListening_CheckedChanged(this, EventArgs.Empty);
        }
        private void updateTCIPort()
        {
            string sValue = txtTCIServerBindIPPort.Text;

            string[] parts = sValue.Split(':');
            string sTmp = "";
            bool bPortOk = false;
            bool bIPOk = false;
            int port = 13013;
            IPAddress address;

            if (parts.Length == 1) sTmp = sValue;
            else if (parts.Length > 1)
            {
                sTmp = parts[0];
                bPortOk = int.TryParse(parts[1], out port);

                if (bPortOk && (port < 0 || port > 65535)) bPortOk = false;
            }

            //check ip is valid
            bIPOk = IPAddress.TryParse(sTmp, out address);

            if (bIPOk && bPortOk)
            {
                txtTCIServerBindIPPort.BackColor = SystemColors.Window;
                console.TCIport = port;
                console.TCIip = address.ToString();
            }
            else
            {
                txtTCIServerBindIPPort.BackColor = Color.Red;
                lblToggleToUseTCI.Visible = false;
            }
        }

        private void udTCIRateLimit_ValueChanged(object sender, EventArgs e)
        {
            if (!initializing && chkTCIServerListening.Checked) lblToggleToUseTCI.Visible = true;
        }

        private void chkCopyRX2VFObToVFOa_CheckedChanged(object sender, EventArgs e)
        {
            console.TCIcopyRX2VFObToVFOa = chkCopyRX2VFObToVFOa.Checked;
        }

        private void chkUseRX1vfoaForRX2vfoa_CheckedChanged(object sender, EventArgs e)
        {
            console.TCIuseRX1vfoaForRX2vfoa = chkUseRX1vfoaForRX2vfoa.Checked;
        }

        private void chkTCIsendInitialStateOnConnect_CheckedChanged(object sender, EventArgs e)
        {
            console.TCIsendInitialStateOnConnect = chkTCIsendInitialStateOnConnect.Checked;
        }

        private void chkWelcomeMessageTCPIPCat_CheckedChanged(object sender, EventArgs e)
        {
            console.TCPIPcatWelcomeMessage = chkWelcomeMessageTCPIPCat.Checked;
        }

        private void udMaxTCISpots_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            SpotManager2.MaxNumber = (int)udMaxTCISpots.Value;
        }

        private void udTCISpotLifetime_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            SpotManager2.LifeTime = (int)udTCISpotLifetime.Value;
        }

        private void chkShowTCISpots_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.ShowTCISpots = chkShowTCISpots.Checked;

            //
            console.SetupInfoBarButton(ucInfoBar.ActionTypes.ShowSpots, chkShowTCISpots.Checked/* || console.SpotForm*/);
        }
        public bool ShowTCISpots
        {
            get { return chkShowTCISpots.Checked; }
            set { chkShowTCISpots.Checked = value; }
        }
        private void chkLegacyDXBuffers_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void chkSpotOwnCallAppearance_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            txtOwnCallsign.Enabled = chkSpotOwnCallAppearance.Checked;
            clrbtnOwnCallApearance.Enabled = chkSpotOwnCallAppearance.Checked;

            SpotManager2.OwnCallApearance(chkSpotOwnCallAppearance.Checked, txtOwnCallsign.Text, clrbtnOwnCallApearance.Color);
        }

        private void txtOwnCallsign_TextChanged(object sender, EventArgs e)
        {
            SpotManager2.OwnCallApearance(chkSpotOwnCallAppearance.Checked, txtOwnCallsign.Text, clrbtnOwnCallApearance.Color);
        }

        private void clrbtnOwnCallApearance_Changed(object sender, EventArgs e)
        {
            SpotManager2.OwnCallApearance(chkSpotOwnCallAppearance.Checked, txtOwnCallsign.Text, clrbtnOwnCallApearance.Color);
        }

        private void chkCWLUbecomesCW_CheckedChanged(object sender, EventArgs e)
        {
            console.TCICWLUbecomesCW = chkCWLUbecomesCW.Checked;
        }

        private void btnShowLog_Click(object sender, EventArgs e)
        {
            console.ShowTCILog();
        }

        private void btnShowTCPIPCatLog_Click(object sender, EventArgs e)
        {
            console.ShowTCPIPCatLog();
        }

        private void setDBtip(object sender)
        {
            if (sender.GetType() != typeof(TrackBarTS)) return;
            TrackBarTS tb = (TrackBarTS)sender;

            double db;

            switch (tb.Name)
            {
                case "tbCFCPRECOMP":
                    db = tbCFCPRECOMP.Value;
                    break;
                case "tbCFC0":
                    db = tbCFC0.Value;
                    break;
                case "tbCFC1":
                    db = tbCFC1.Value;
                    break;
                case "tbCFC2":
                    db = tbCFC2.Value;
                    break;
                case "tbCFC3":
                    db = tbCFC3.Value;
                    break;
                case "tbCFC4":
                    db = tbCFC4.Value;
                    break;
                case "tbCFC5":
                    db = tbCFC5.Value;
                    break;
                case "tbCFC6":
                    db = tbCFC6.Value;
                    break;
                case "tbCFC7":
                    db = tbCFC7.Value;
                    break;
                case "tbCFC8":
                    db = tbCFC8.Value;
                    break;
                case "tbCFC9":
                    db = tbCFC9.Value;
                    break;
                //EQ
                case "tbCFCPEQGAIN":
                    db = tbCFCPEQGAIN.Value;
                    break;
                case "tbCFCEQ0":
                    db = tbCFCEQ0.Value;
                    break;
                case "tbCFCEQ1":
                    db = tbCFCEQ1.Value;
                    break;
                case "tbCFCEQ2":
                    db = tbCFCEQ2.Value;
                    break;
                case "tbCFCEQ3":
                    db = tbCFCEQ3.Value;
                    break;
                case "tbCFCEQ4":
                    db = tbCFCEQ4.Value;
                    break;
                case "tbCFCEQ5":
                    db = tbCFCEQ5.Value;
                    break;
                case "tbCFCEQ6":
                    db = tbCFCEQ6.Value;
                    break;
                case "tbCFCEQ7":
                    db = tbCFCEQ7.Value;
                    break;
                case "tbCFCEQ8":
                    db = tbCFCEQ8.Value;
                    break;
                case "tbCFCEQ9":
                    db = tbCFCEQ9.Value;
                    break;

                default:
                    return;
            }
            toolTip1.SetToolTip(tb, ((int)db).ToString() + " dB");
        }

        private void chkNoFadeOverUnderWarning_CheckedChanged(object sender, EventArgs e)
        {
            console.VAC1UnderOver.NoFade = chkNoFadeOverUnderWarning.Checked;
            console.VAC2UnderOver.NoFade = chkNoFadeOverUnderWarning.Checked;
        }

        private void chkUseOutlinedCross_CheckedChanged(object sender, EventArgs e)
        {
            console.UseOutlinedCrossCursor = chkUseOutlinedCross.Checked;
        }

        private void chkSwapREDBluePSAColours_CheckedChanged(object sender, EventArgs e)
        {
            console.SwapRedBlue = chkSwapREDBluePSAColours.Checked;
        }

        private void chkHideFeebackLevel_CheckedChanged(object sender, EventArgs e)
        {
            console.HideFeebackLevel = chkHideFeebackLevel.Checked;
        }
        public bool HideFeebbackChanged
        {
            get { return chkHideFeebackLevel.Checked; }
            set { chkHideFeebackLevel.Checked = value; }
        }
        public void SwapRedBlueChanged()
        {
            chkSwapREDBluePSAColours.Checked = puresignal.InvertRedBlue;
        }

        private void chkFirewallCheck_Click(object sender, EventArgs e)
        {
            Firewall.Setup();
        }

        private void chkUsing10MHzRef_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            btnGeneralCalFreqStart.Enabled = !chkUsing10MHzRef.Checked;
            udHPSDRFreqCorrectFactor10MHz.Enabled = chkUsing10MHzRef.Checked;

            udHPSDRFreqCorrectFactor_ValueChanged(this, EventArgs.Empty);
        }

        private void btnHPSDRFreqCalReset10MHz_Click(object sender, EventArgs e)
        {
            udHPSDRFreqCorrectFactor10MHz.Value = (decimal)1.0;
        }

        private void udHPSDRFreqCorrectFactor10MHz_ValueChanged(object sender, EventArgs e)
        {
            udHPSDRFreqCorrectFactor_ValueChanged(this, EventArgs.Empty);
        }

        private async void btnLoadGradient_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                ofd.Filter = "Gradient|*.grad";
                ofd.Title = "Load Gradient File";
                ofd.FilterIndex = 1;
                ofd.RestoreDirectory = true;
                DialogResult dr = ofd.ShowDialog();

                if (ofd.FileName != "" && dr == DialogResult.OK)
                {
                    if (File.Exists(ofd.FileName))
                    {
                        await Task.Run(() => lgLinearGradientRX1.EncodedText = File.ReadAllText(ofd.FileName, Encoding.UTF8));
                    }
                }
            }
        }

        private async void btnSaveGradient_Click(object sender, EventArgs e)
        {
            using (SaveFileDialog sfd = new SaveFileDialog())
            {
                sfd.Filter = "Gradient|*.grad";
                sfd.Title = "Save Gradient File";
                DialogResult dr = sfd.ShowDialog();

                if (sfd.FileName != "" && dr == DialogResult.OK)
                {
                    await Task.Run(() => File.WriteAllText(sfd.FileName, lgLinearGradientRX1.EncodedText, Encoding.UTF8));
                }
            }
        }

        private void chkIgnoreSeqErrors_CheckedChanged(object sender, EventArgs e)
        {
            console.InfoBarShowSeqErrors = !chkIgnoreSeqErrors.Checked;
        }

        private void btnIPv4TCI_Click(object sender, EventArgs e)
        {
            frmIPv4Picker f = new frmIPv4Picker();
            f.Init(txtTCIServerBindIPPort.Text);
            DialogResult dr = f.ShowDialog(this);

            if (dr == DialogResult.OK)
            {
                string sTmp = f.IP;
                if (sTmp == "") sTmp = "127.0.0.1:50001";
                txtTCIServerBindIPPort.Text = sTmp;
            }
        }

        private void btnIPv4N1MM_Click(object sender, EventArgs e)
        {
            frmIPv4Picker f = new frmIPv4Picker();
            f.Init(txtN1MMSendTo.Text, true);
            DialogResult dr = f.ShowDialog(this);

            if (dr == DialogResult.OK)
            {
                string sTmp = f.IP;
                if (sTmp == "") sTmp = "127.0.0.1:13064";
                txtN1MMSendTo.Text = sTmp;
            }
        }

        private void btnIPv4TCPCat_Click(object sender, EventArgs e)
        {
            frmIPv4Picker f = new frmIPv4Picker();
            f.Init(txtTCPIPCATServerBindIPPort.Text);
            DialogResult dr = f.ShowDialog(this);

            if (dr == DialogResult.OK)
            {
                string sTmp = f.IP;
                if (sTmp == "") sTmp = "127.0.0.1:13013";
                txtTCPIPCATServerBindIPPort.Text = sTmp;
            }
        }

        private void chkEmulateSunSDR2Pro_CheckedChanged(object sender, EventArgs e)
        {
            console.EmulateSunSDR2Pro = chkEmulateSunSDR2Pro.Checked;
        }

        private void chkEmulateExpertSDR3Protocol_CheckedChanged(object sender, EventArgs e)
        {
            console.EmulateExpertSDR3Protocol = chkEmulateExpertSDR3Protocol.Checked;
        }
        public bool DisableAudioAmplifier
        {
            set
            {
                if (chkDisableRearSpeakerJacksAudioAmplifier.Checked != value)
                    chkDisableRearSpeakerJacksAudioAmplifier.Checked = value;
            }
        }
        private void chkDisableRearSpeakerJacksAudioAmplifier_CheckedChanged(object sender, EventArgs e)
        {
            console.EnableAudioAmplifier = !chkDisableRearSpeakerJacksAudioAmplifier.Checked;
        }

        private void radUseDriveSliderTune_CheckedChanged(object sender, EventArgs e)
        {
            if (radUseDriveSliderTune.Checked) console.TuneDrivePowerOrigin = DrivePowerSource.DRIVE_SLIDER;
        }

        private void radUseTuneSliderTune_CheckedChanged(object sender, EventArgs e)
        {
            if (radUseTuneSliderTune.Checked) console.TuneDrivePowerOrigin = DrivePowerSource.TUNE_SLIDER;
        }

        private void radUseFixedDriveTune_CheckedChanged(object sender, EventArgs e)
        {
            if (radUseFixedDriveTune.Checked) console.TuneDrivePowerOrigin = DrivePowerSource.FIXED;
        }

        private void udTestIMDPower_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.TwoToneTunePower = (int)udTestIMDPower.Value;
        }
        private void setupTuneAnd2ToneRadios()
        {
            if (initializing) return;
            switch (console.TuneDrivePowerOrigin)
            {
                case DrivePowerSource.DRIVE_SLIDER:
                    radUseDriveSliderTune.Checked = true;
                    break;
                case DrivePowerSource.TUNE_SLIDER:
                    radUseTuneSliderTune.Checked = true;
                    break;
                case DrivePowerSource.FIXED:
                    radUseFixedDriveTune.Checked = true;
                    break;
            }

            switch (console.TwoToneDrivePowerOrigin)
            {
                case DrivePowerSource.DRIVE_SLIDER:
                    radUseDriveSlider2Tone.Checked = true;
                    break;
                case DrivePowerSource.TUNE_SLIDER:
                    radUseTuneSlider2Tone.Checked = true;
                    break;
                case DrivePowerSource.FIXED:
                    radUseFixedDrive2Tone.Checked = true; //MW0LGE_[2.9.0.7] fixed, was setting incorrect radio button
                    break;
            }
        }

        private void radUseDriveSlider2Tone_CheckedChanged(object sender, EventArgs e)
        {
            if (radUseDriveSlider2Tone.Checked) console.TwoToneDrivePowerOrigin = DrivePowerSource.DRIVE_SLIDER;
        }

        private void radUseTuneSlider2Tone_CheckedChanged(object sender, EventArgs e)
        {
            if (radUseTuneSlider2Tone.Checked) console.TwoToneDrivePowerOrigin = DrivePowerSource.TUNE_SLIDER;
        }

        private void radUseFixedDrive2Tone_CheckedChanged(object sender, EventArgs e)
        {
            if (radUseFixedDrive2Tone.Checked) console.TwoToneDrivePowerOrigin = DrivePowerSource.FIXED;
        }
        private void chkLimitPowerCATTCIMsgs_CheckedChanged(object sender, EventArgs e)
        {
            console.SendLimitedPowerLevels = chkLimitPowerCATTCIMsgs.Checked;
        }

        private const string _sPA_PROFILE_BYPASS = "Default - PA BYPASS";
        private void updatePAControls(PAProfile p)
        {
            if (p == null) return;

            if (p.IsDefault && p.Model != HPSDRModel.FIRST)
                grpGainByBandPA.Text = p.Model.ToString() + " - PA Gain By Band (dB)";
            else
                grpGainByBandPA.Text = p.ProfileName + " - PA Gain By Band (dB)";

            btnDeletePAProfile.Enabled = p.ProfileName.StartsWith("Default") ? false : true; // unable to delete Default

            if (p.ProfileName == _sPA_PROFILE_BYPASS)
            {
                btnNewPAProfile.Enabled = false;
                btnCopyPAProfile.Enabled = false;
            }
            else
            {
                btnNewPAProfile.Enabled = true;
                btnCopyPAProfile.Enabled = true;
            }
        }
        private string _old_pa_profile_name = "";
        private void comboPAProfile_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return; //[2.10.1.0] MW0LGE only want to apply this at the forceallevents stage

            PAProfile p = getPAProfile(comboPAProfile.Text);

            if (p != null)
            {
                updatePAControls(p);
                updateNUDgains(p);
                updateNUDAdjustgains(p);
                updateMaxPower(p);
                updateDriveLabels(p);

                console.PAProfile = p.ProfileName;

                if(p.ProfileName != _old_pa_profile_name)
                {
                    if (console != null)
                    {
                        console.PAProfileNameChangedHandlers?.Invoke(_old_pa_profile_name, p.ProfileName);
                        _old_pa_profile_name = p.ProfileName;
                    }
                }
            }
        }
        public string PAProfileName
        {
            get
            {
                PAProfile p = getPAProfile(comboPAProfile.Text);
                if (p != null)
                    return p.ProfileName;
                else
                    return "";
            }
        }
        private bool validatePAProfileName(string sProfileName)
        {
            if (sProfileName.StartsWith("Default"))
            {
                DialogResult dr = MessageBox.Show(
                    "The PA profile name " + sProfileName + " can not start with 'Default'.",
                    "PA Profile Name",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);
                return false;
            }
            if (_PAProfiles.ContainsKey(sProfileName))
            {
                DialogResult dr = MessageBox.Show(
                    "The PA profile name " + sProfileName + " already exists.",
                    "PA Profile Name",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);
                return false;
            }

            return true;
        }
        private void btnCopyPAProfile_Click(object sender, EventArgs e)
        {
            PAProfile curP = getPAProfile(comboPAProfile.Text);
            if (curP == null) return;

            string sProfileName = InputBox.Show("Copy Profile - " + curP.ProfileName, "Please enter a profile name:", "");

            if (sProfileName == "") return;
            if (!validatePAProfileName(sProfileName)) return;

            PAProfile newP = new PAProfile(sProfileName, HPSDRModel.FIRST, false); // we dont really want it associated with a model
            newP.CopySettings(curP);

            _PAProfiles.Add(sProfileName, newP);

            updatePAProfileCombo(sProfileName);
        }
        private void btnNewPAProfile_Click(object sender, EventArgs e)
        {
            string sProfileName = InputBox.Show("New Profile", "Please enter a profile name:", "");

            if (sProfileName == "") return;
            if (!validatePAProfileName(sProfileName)) return;

            PAProfile p = new PAProfile(sProfileName, console.CurrentHPSDRModel/*HPSDRModel.FIRST*/, false); // set the initial values based on current model, all we can do

            _PAProfiles.Add(sProfileName, p);

            updatePAProfileCombo(sProfileName);
        }

        private void btnDeletePAProfile_Click(object sender, EventArgs e)
        {
            PAProfile p = getPAProfile(comboPAProfile.Text);
            if (p == null) return;

            DialogResult dr = MessageBox.Show(
                "Are you sure you want to delete the " + comboPAProfile.Text + " PA Profile?\n\n" +
                "The Default profile will be selected if you do.",
                "Delete Profile?",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Warning);

            if (dr == DialogResult.No) return;

            _PAProfiles.Remove(p.ProfileName);

            updatePAProfileCombo();

            for (int n = 0; n < comboPAProfile.Items.Count; n++)
            {
                string sName = (string)comboPAProfile.Items[n];
                if (sName.StartsWith("Default"))
                {
                    comboPAProfile.SelectedIndex = n;
                    break;
                }
            }
        }
        private bool _bIgnoreNUDGainUpdate = false;
        private void updateNUDgains(PAProfile p)
        {
            if (p == null)
                p = getPAProfile(comboPAProfile.Text);

            if (p == null) return;
            // set every nud
            _bIgnoreNUDGainUpdate = true; // stop the valuechanged event on these nuds

            nud160M.Value = (decimal)p.GetGainForBand(Band.B160M);
            nud80M.Value = (decimal)p.GetGainForBand(Band.B80M);
            nud60M.Value = (decimal)p.GetGainForBand(Band.B60M);
            nud40M.Value = (decimal)p.GetGainForBand(Band.B40M);
            nud30M.Value = (decimal)p.GetGainForBand(Band.B30M);
            nud20M.Value = (decimal)p.GetGainForBand(Band.B20M);
            nud17M.Value = (decimal)p.GetGainForBand(Band.B17M);
            nud15M.Value = (decimal)p.GetGainForBand(Band.B15M);
            nud12M.Value = (decimal)p.GetGainForBand(Band.B12M);
            nud10M.Value = (decimal)p.GetGainForBand(Band.B10M);
            nud6M.Value = (decimal)p.GetGainForBand(Band.B6M);

            nudVHF0.Value = (decimal)p.GetGainForBand(Band.VHF0);
            nudVHF1.Value = (decimal)p.GetGainForBand(Band.VHF1);
            nudVHF2.Value = (decimal)p.GetGainForBand(Band.VHF2);
            nudVHF3.Value = (decimal)p.GetGainForBand(Band.VHF3);
            nudVHF4.Value = (decimal)p.GetGainForBand(Band.VHF4);
            nudVHF5.Value = (decimal)p.GetGainForBand(Band.VHF5);
            nudVHF6.Value = (decimal)p.GetGainForBand(Band.VHF6);
            nudVHF7.Value = (decimal)p.GetGainForBand(Band.VHF7);
            nudVHF8.Value = (decimal)p.GetGainForBand(Band.VHF8);
            nudVHF9.Value = (decimal)p.GetGainForBand(Band.VHF9);
            nudVHF10.Value = (decimal)p.GetGainForBand(Band.VHF10);
            nudVHF11.Value = (decimal)p.GetGainForBand(Band.VHF11);
            nudVHF12.Value = (decimal)p.GetGainForBand(Band.VHF12);
            nudVHF13.Value = (decimal)p.GetGainForBand(Band.VHF13);

            _bIgnoreNUDGainUpdate = false;

            console.PWR = console.PWR; // force the use of these new values;
        }
        //
        private Dictionary<string, LabelTS> _PADriveLabels = new Dictionary<string, LabelTS>();
        private bool _bIgnoreNUDAdjustUpdate = false;
        private void updateNUDAdjustgains(PAProfile p = null)
        {
            if (_adjustingBand == Band.FIRST) return;
            if (p == null)
                p = getPAProfile(comboPAProfile.Text);

            if (p == null) return;
            // set every nud
            _bIgnoreNUDAdjustUpdate = true; // stop the valuechanged event on these nuds

            nudAdjustGain10.Value = (decimal)p.GetAdjust(_adjustingBand, 0);
            nudAdjustGain20.Value = (decimal)p.GetAdjust(_adjustingBand, 1);
            nudAdjustGain30.Value = (decimal)p.GetAdjust(_adjustingBand, 2);
            nudAdjustGain40.Value = (decimal)p.GetAdjust(_adjustingBand, 3);
            nudAdjustGain50.Value = (decimal)p.GetAdjust(_adjustingBand, 4);
            nudAdjustGain60.Value = (decimal)p.GetAdjust(_adjustingBand, 5);
            nudAdjustGain70.Value = (decimal)p.GetAdjust(_adjustingBand, 6);
            nudAdjustGain80.Value = (decimal)p.GetAdjust(_adjustingBand, 7);
            nudAdjustGain90.Value = (decimal)p.GetAdjust(_adjustingBand, 8);

            _bIgnoreNUDAdjustUpdate = false;

            console.PWR = console.PWR; // force the use of these new values;
        }
        private void updateDriveLabels(PAProfile p = null)
        {
            if (_adjustingBand == Band.FIRST) return;
            if (p == null)
                p = getPAProfile(comboPAProfile.Text);

            // populate dict first time, it never gets cleared
            if (_PADriveLabels.Count == 0)
            {
                foreach (Control c in panelAdjustGain.Controls)
                {
                    LabelTS lbl = c as LabelTS;
                    if (lbl != null && lbl.Name.StartsWith("lblPAAdjust")) _PADriveLabels.Add(lbl.Name, lbl);
                }
            }

            //update drive/watts display
            if (p.GetMaxPowerUse(_adjustingBand))
            {
                // using watts
                lblDriveHeader.TextAlign = ContentAlignment.MiddleRight;
                for (int n = 0; n < 9; n++)
                {
                    int num = (n * 10) + 10;
                    string slblName = "lblPAAdjust" + num.ToString();
                    if (_PADriveLabels.ContainsKey(slblName))
                    {
                        LabelTS lbl = _PADriveLabels[slblName];
                        float watts = (num / 100f) * p.GetMaxPower(_adjustingBand);
                        lbl.Text = watts.ToString("0.0") + "w";
                        lbl.TextAlign = ContentAlignment.MiddleRight;
                    }
                }
            }
            else
            {
                //using drive
                lblDriveHeader.TextAlign = ContentAlignment.MiddleCenter;
                for (int n = 0; n < 9; n++)
                {
                    int num = (n * 10) + 10;
                    string slblName = "lblPAAdjust" + num.ToString();
                    if (_PADriveLabels.ContainsKey(slblName))
                    {
                        LabelTS lbl = _PADriveLabels[slblName];
                        lbl.Text = num.ToString();
                        lbl.TextAlign = ContentAlignment.MiddleCenter;
                    }
                }
            }
        }
        private void updateMaxPower(PAProfile p = null)
        {
            if (_adjustingBand == Band.FIRST) return;
            if (p == null)
                p = getPAProfile(comboPAProfile.Text);

            if (p == null) return;

            nudMaxPowerForBandPA.Value = (decimal)p.GetMaxPower(_adjustingBand);

            updateMaxPowerCheckbox(p);

            console.UpdateDriveLabel(false, EventArgs.Empty);
            console.UpdateTuneLabel(false, EventArgs.Empty);
        }
        //
        private void btnResetPAProfile_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show(
                "Are you sure you want to reset the " + comboPAProfile.Text + " PA Profile?\n\n" +
                "The Default settings for this radio model will be applied if you do.",
                "Reset Profile?",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Warning);

            if (dr == DialogResult.No) return;

            PAProfile p = getPAProfile(comboPAProfile.Text);
            if (p == null) return;

            p.ResetGainDefaultsForModel(p.Model);

            updateNUDgains(p);
            updateNUDAdjustgains(p);
            updateMaxPower(p);
            updateDriveLabels(p);
        }
        private int mapBandMetersToIndex(int nMeters)
        {
            switch (nMeters)
            {
                case 160:
                    return 0;
                case 80:
                    return 1;
                case 60:
                    return 2;
                case 40:
                    return 3;
                case 30:
                    return 4;
                case 20:
                    return 5;
                case 17:
                    return 6;
                case 15:
                    return 7;
                case 12:
                    return 8;
                case 10:
                    return 9;
                case 6:
                    return 10;
            }
            return 0;
        }
        private int mapBandToMeters(Band b)
        {
            switch (b)
            {
                case Band.B160M:
                    return 160;
                case Band.B80M:
                    return 80;
                case Band.B60M:
                    return 60;
                case Band.B40M:
                    return 40;
                case Band.B30M:
                    return 30;
                case Band.B20M:
                    return 20;
                case Band.B17M:
                    return 17;
                case Band.B15M:
                    return 15;
                case Band.B12M:
                    return 12;
                case Band.B10M:
                    return 10;
                case Band.B6M:
                    return 6;
            }
            return 0;
        }
        private void nudPAProfileGain_ValueChanged(object sender, EventArgs e)
        {
            if (_bIgnoreNUDGainUpdate || initializing || _PAProfiles == null) return;

            NumericUpDownTS nud = sender as NumericUpDownTS;
            if (nud == null) return;

            //nud160M
            //nudVHF0

            bool bVHF = nud.Name.StartsWith("nudVHF");
            int nNumber = bVHF ? int.Parse(nud.Name.Substring(6)) : int.Parse(nud.Name.Substring(3, nud.Name.Length - 4));

            PAProfile p = getPAProfile(comboPAProfile.Text);
            if (p == null) return;

            Band b;
            if (bVHF)
                b = (Band)((int)Band.VHF0 + nNumber);
            else
                b = (Band)((int)Band.B160M + mapBandMetersToIndex(nNumber));

            float fOld = p.GetGainForBand(b);
            p.SetGainForBand(b, (float)nud.Value);

            if (p.GetGainForBand(b) != fOld) console.PWR = console.PWR; // update the power, which causes these gain values to be queried
        }
        public float GetPAGain(Band b, int nDriveValue)
        {
            if (_PAProfiles == null) return 1000;

            PAProfile p = getPAProfile(comboPAProfile.Text);
            if (p == null) return 1000;

            return p.GetGainForBand(b, nDriveValue);
        }
        public bool GetPABandUsesMaxPower(Band b)
        {
            if (_PAProfiles == null) return false;

            PAProfile p = getPAProfile(comboPAProfile.Text);
            if (p == null) return false;

            return p.GetMaxPowerUse(b) && p.GetMaxPower(b) != 0;
        }
        public float GetPABandMaxPower(Band b)
        {
            if (_PAProfiles == null) return 0;

            PAProfile p = getPAProfile(comboPAProfile.Text);
            if (p == null) return 0;

            return p.GetMaxPower(b);
        }

        private Dictionary<string, PAProfile> _PAProfiles;
        private void initPAProfiles()
        {
            if (_PAProfiles == null)
                _PAProfiles = new Dictionary<string, PAProfile>();
            else
                _PAProfiles.Clear();

            PAProfile p;

            // add a default profile for every radio model
            for (int n = 0; n < (int)HPSDRModel.LAST; n++)
            {
                HPSDRModel model = (HPSDRModel)n;
                p = new PAProfile("Default - " + model.ToString(), model, true);
                _PAProfiles.Add(p.ProfileName, p);
            }

            // add a bypass default, which is used when in pa bypass (part of calibrate)
            p = new PAProfile(_sPA_PROFILE_BYPASS, HPSDRModel.FIRST, true); // no specific model for this, FIRST is handled ResetGainDefaultsForModel called in constructor

            _PAProfiles.Add(p.ProfileName, p);
        }
        private PAProfile getPAProfile(string sName)
        {
            if (_PAProfiles == null || _PAProfiles.Count == 0 || !_PAProfiles.ContainsKey(sName)) return null;

            return _PAProfiles[sName];
        }
        private void updatePAProfileCombo(string sSelectProfile = "")
        {
            if (_PAProfiles == null) return;

            // update combo
            comboPAProfile.Items.Clear();

            foreach (KeyValuePair<string, PAProfile> pair in _PAProfiles)
            {
                PAProfile p = pair.Value;

                if (sSelectProfile == _sPA_PROFILE_BYPASS)
                {
                    if (p.ProfileName == _sPA_PROFILE_BYPASS)
                        comboPAProfile.Items.Add(p.ProfileName);
                }
                else
                {
                    if ((p.IsDefault && p.Model == console.CurrentHPSDRModel) || !p.IsDefault) // add any that are default for this current model, or are not default, ie user added
                        comboPAProfile.Items.Add(p.ProfileName);
                }
            }

            // 
            bool bSelected = false;
            if (sSelectProfile != "")
            {
                for (int n = 0; n < comboPAProfile.Items.Count; n++)
                {
                    string sName = (string)comboPAProfile.Items[n];
                    if (sSelectProfile == sName)
                    {
                        bSelected = true;
                        comboPAProfile.SelectedIndex = n;
                        break;
                    }
                }
            }
            if (!bSelected && comboPAProfile.Text == "")
            {
                for (int n = 0; n < comboPAProfile.Items.Count; n++)
                {
                    string sName = (string)comboPAProfile.Items[n];

                    if (sName.StartsWith("Default"))
                    {
                        //bSelected = true;
                        comboPAProfile.SelectedIndex = n;
                        break;
                    }
                }
            }
        }
        public float GetBypassGain(Band b)
        {
            PAProfile p = getPAProfile(_sPA_PROFILE_BYPASS);
            if (p == null) return 1000;

            return p.GetGainForBand(b);
        }
        public void SetBypassGain(Band b, float gain)
        {
            PAProfile p = getPAProfile(_sPA_PROFILE_BYPASS);
            if (p == null) return;

            p.SetGainForBand(b, gain);
        }
        private void PAProfileEnableControls(bool tx)
        {
            //prevent profile switch during a tx
            //user can only tweak the NUD's

            //TODO: swap to delegate for mox, but not used at all in setup yet
            //
            if (_PAProfiles == null) return;

            comboPAProfile.Enabled = !tx;
            btnNewPAProfile.Enabled = !tx;

            if (tx)
            {
                btnDeletePAProfile.Enabled = false;
                btnResetPAProfile.Enabled = false;
                btnCopyPAProfile.Enabled = false;
            }
            else
            {
                PAProfile p = getPAProfile(comboPAProfile.Text);
                if (p == null)
                {
                    btnDeletePAProfile.Enabled = false;
                    btnResetPAProfile.Enabled = false;
                    btnCopyPAProfile.Enabled = false;
                }
                else
                {
                    btnDeletePAProfile.Enabled = p.ProfileName.StartsWith("Default") ? false : true; // unable to delete Default
                    if (p.ProfileName == _sPA_PROFILE_BYPASS)
                    {
                        btnNewPAProfile.Enabled = false;
                        btnCopyPAProfile.Enabled = false;
                    }
                    else
                    {
                        btnNewPAProfile.Enabled = true;
                        btnCopyPAProfile.Enabled = true;
                    }
                    btnResetPAProfile.Enabled = true;
                }
            }
        }
        private float getOldVariablePAgain(string sKey, ref Dictionary<string, string> getDict)
        {
            if (!getDict.ContainsKey(sKey)) return 1000;
            return float.Parse(getDict[sKey]);
        }
        private void removeOldPASetting(string sSetting)
        {
            if (!_oldSettings.Contains(sSetting)) _oldSettings.Add(sSetting);
        }
        private void handleOldPAGainSettings(ref Dictionary<string, string> getDict)
        {
            if (getDict == null) return;
            // here we have to map all the old settings, ~200 variables into the new profile system, and remove them

            // use the existance of ProfileCount as a check to see we have already done this
            if (getDict.ContainsKey("PAProfileCount")) return;

            bool bRemoveOld = true; // set to true if you want the old variables removed from the db

            foreach (KeyValuePair<string, PAProfile> kvp in _PAProfiles)
            {
                PAProfile p = kvp.Value;
                switch (p.Model)
                {
                    case HPSDRModel.ANAN10:
                    case HPSDRModel.ANAN10E:
                        for (int n = (int)Band.B160M; n <= (int)Band.B6M; n++)
                        {
                            Band b = (Band)n;
                            string sSetting = "udANAN10PAGain" + mapBandToMeters(b).ToString();
                            float g = getOldVariablePAgain(sSetting, ref getDict);
                            if (g != 1000) p.SetGainForBand(b, g);
                            if (g != 1000 && bRemoveOld) removeOldPASetting(sSetting);
                        }
                        for (int n = (int)Band.VHF0; n <= (int)Band.VHF13; n++)
                        {
                            Band b = (Band)n;
                            string sSetting = "udANAN10PAGainVHF" + (n - (int)Band.VHF0).ToString();
                            float g = getOldVariablePAgain(sSetting, ref getDict);
                            if (g != 1000) p.SetGainForBand(b, g);
                            if (g != 1000 && bRemoveOld) removeOldPASetting(sSetting);
                        }
                        break;
                    case HPSDRModel.ANAN100:
                        for (int n = (int)Band.B160M; n <= (int)Band.B6M; n++)
                        {
                            Band b = (Band)n;
                            string sSetting = "udANAN100PAGain" + mapBandToMeters(b).ToString();
                            float g = getOldVariablePAgain(sSetting, ref getDict);
                            if (g != 1000) p.SetGainForBand(b, g);
                            if (g != 1000 && bRemoveOld) removeOldPASetting(sSetting);
                        }
                        for (int n = (int)Band.VHF0; n <= (int)Band.VHF13; n++)
                        {
                            Band b = (Band)n;
                            string sSetting = "udANAN100PAGainVHF" + (n - (int)Band.VHF0).ToString();
                            float g = getOldVariablePAgain(sSetting, ref getDict);
                            if (g != 1000) p.SetGainForBand(b, g);
                            if (g != 1000 && bRemoveOld) removeOldPASetting(sSetting);
                        }
                        break;
                    case HPSDRModel.ANAN100B:
                        for (int n = (int)Band.B160M; n <= (int)Band.B6M; n++)
                        {
                            Band b = (Band)n;
                            string sSetting = "udANAN100BPAGain" + mapBandToMeters(b).ToString();
                            float g = getOldVariablePAgain(sSetting, ref getDict);
                            if (g != 1000) p.SetGainForBand(b, g);
                            if (g != 1000 && bRemoveOld) removeOldPASetting(sSetting);
                        }
                        for (int n = (int)Band.VHF0; n <= (int)Band.VHF13; n++)
                        {
                            Band b = (Band)n;
                            string sSetting = "udANAN100BPAGainVHF" + (n - (int)Band.VHF0).ToString();
                            float g = getOldVariablePAgain(sSetting, ref getDict);
                            if (g != 1000) p.SetGainForBand(b, g);
                            if (g != 1000 && bRemoveOld) removeOldPASetting(sSetting);
                        }
                        break;
                    case HPSDRModel.ANAN100D:
                        for (int n = (int)Band.B160M; n <= (int)Band.B6M; n++)
                        {
                            Band b = (Band)n;
                            string sSetting = "udANANPAGain" + mapBandToMeters(b).ToString();
                            float g = getOldVariablePAgain(sSetting, ref getDict);
                            if (g != 1000) p.SetGainForBand(b, g);
                            if (g != 1000 && bRemoveOld) removeOldPASetting(sSetting);
                        }
                        for (int n = (int)Band.VHF0; n <= (int)Band.VHF13; n++)
                        {
                            Band b = (Band)n;
                            string sSetting = "udANANPAGainVHF" + (n - (int)Band.VHF0).ToString();
                            float g = getOldVariablePAgain(sSetting, ref getDict);
                            if (g != 1000) p.SetGainForBand(b, g);
                            if (g != 1000 && bRemoveOld) removeOldPASetting(sSetting);
                        }
                        break;
                    case HPSDRModel.ANAN200D:
                        for (int n = (int)Band.B160M; n <= (int)Band.B6M; n++)
                        {
                            Band b = (Band)n;
                            string sSetting = "udOrionPAGain" + mapBandToMeters(b).ToString();
                            float g = getOldVariablePAgain(sSetting, ref getDict);
                            if (g != 1000) p.SetGainForBand(b, g);
                            if (g != 1000 && bRemoveOld) removeOldPASetting(sSetting);
                        }
                        for (int n = (int)Band.VHF0; n <= (int)Band.VHF13; n++)
                        {
                            Band b = (Band)n;
                            string sSetting = "udOrionPAGainVHF" + (n - (int)Band.VHF0).ToString();
                            float g = getOldVariablePAgain(sSetting, ref getDict);
                            if (g != 1000) p.SetGainForBand(b, g);
                            if (g != 1000 && bRemoveOld) removeOldPASetting(sSetting);
                        }
                        break;
                    case HPSDRModel.ANAN7000D:
                        for (int n = (int)Band.B160M; n <= (int)Band.B6M; n++)
                        {
                            Band b = (Band)n;
                            string sSetting = "udANAN7000DPAGain" + mapBandToMeters(b).ToString();
                            float g = getOldVariablePAgain(sSetting, ref getDict);
                            if (g != 1000) p.SetGainForBand(b, g);
                            if (g != 1000 && bRemoveOld) removeOldPASetting(sSetting);
                        }
                        for (int n = (int)Band.VHF0; n <= (int)Band.VHF13; n++)
                        {
                            Band b = (Band)n;
                            string sSetting = "udANAN7000DPAGainVHF" + (n - (int)Band.VHF0).ToString();
                            float g = getOldVariablePAgain(sSetting, ref getDict);
                            if (g != 1000) p.SetGainForBand(b, g);
                            if (g != 1000 && bRemoveOld) removeOldPASetting(sSetting);
                        }
                        break;
                    case HPSDRModel.ANAN_G2:
                        for (int n = (int)Band.B160M; n <= (int)Band.B6M; n++)
                        {
                            Band b = (Band)n;
                            string sSetting = "udANAN_G2PAGain" + mapBandToMeters(b).ToString();
                            float g = getOldVariablePAgain(sSetting, ref getDict);
                            if (g != 1000) p.SetGainForBand(b, g);
                            if (g != 1000 && bRemoveOld) removeOldPASetting(sSetting);
                        }
                        for (int n = (int)Band.VHF0; n <= (int)Band.VHF13; n++)
                        {
                            Band b = (Band)n;
                            string sSetting = "udANAN_G2PAGainVHF" + (n - (int)Band.VHF0).ToString();
                            float g = getOldVariablePAgain(sSetting, ref getDict);
                            if (g != 1000) p.SetGainForBand(b, g);
                            if (g != 1000 && bRemoveOld) removeOldPASetting(sSetting);
                        }
                        break;
                    case HPSDRModel.ANAN8000D:
                        for (int n = (int)Band.B160M; n <= (int)Band.B6M; n++)
                        {
                            Band b = (Band)n;
                            string sSetting = "udANAN8000DPAGain" + mapBandToMeters(b).ToString();
                            float g = getOldVariablePAgain(sSetting, ref getDict);
                            if (g != 1000) p.SetGainForBand(b, g);
                            if (g != 1000 && bRemoveOld) removeOldPASetting(sSetting);
                        }
                        for (int n = (int)Band.VHF0; n <= (int)Band.VHF13; n++)
                        {
                            Band b = (Band)n;
                            string sSetting = "udANAN8000DPAGainVHF" + (n - (int)Band.VHF0).ToString();
                            float g = getOldVariablePAgain(sSetting, ref getDict);
                            if (g != 1000) p.SetGainForBand(b, g);
                            if (g != 1000 && bRemoveOld) removeOldPASetting(sSetting);
                        }
                        break;
                    case HPSDRModel.ANAN_G2_1K:                         // will need more work for 1KW PA
                        for (int n = (int)Band.B160M; n <= (int)Band.B6M; n++)
                        {
                            Band b = (Band)n;
                            string sSetting = "udANAN_G2_1KPAGain" + mapBandToMeters(b).ToString();
                            float g = getOldVariablePAgain(sSetting, ref getDict);
                            if (g != 1000) p.SetGainForBand(b, g);
                            if (g != 1000 && bRemoveOld) removeOldPASetting(sSetting);
                        }
                        for (int n = (int)Band.VHF0; n <= (int)Band.VHF13; n++)
                        {
                            Band b = (Band)n;
                            string sSetting = "udANAN_G2_1KPAGainVHF" + (n - (int)Band.VHF0).ToString();
                            float g = getOldVariablePAgain(sSetting, ref getDict);
                            if (g != 1000) p.SetGainForBand(b, g);
                            if (g != 1000 && bRemoveOld) removeOldPASetting(sSetting);
                        }
                        break;
                    case HPSDRModel.HERMES:
                        for (int n = (int)Band.B160M; n <= (int)Band.B6M; n++)
                        {
                            Band b = (Band)n;
                            string sSetting = "udHermesPAGain" + mapBandToMeters(b).ToString();
                            float g = getOldVariablePAgain(sSetting, ref getDict);
                            if (g != 1000) p.SetGainForBand(b, g);
                            if (g != 1000 && bRemoveOld) removeOldPASetting(sSetting);
                        }
                        for (int n = (int)Band.VHF0; n <= (int)Band.VHF13; n++)
                        {
                            Band b = (Band)n;
                            string sSetting = "udHermesPAGainVHF" + (n - (int)Band.VHF0).ToString();
                            float g = getOldVariablePAgain(sSetting, ref getDict);
                            if (g != 1000) p.SetGainForBand(b, g);
                            if (g != 1000 && bRemoveOld) removeOldPASetting(sSetting);
                        }
                        break;
                    case HPSDRModel.FIRST: // special case for bypass
                    case HPSDRModel.HPSDR:
                        if (p.Model == HPSDRModel.HPSDR || (p.Model == HPSDRModel.FIRST && p.ProfileName == _sPA_PROFILE_BYPASS))
                        {
                            for (int n = (int)Band.B160M; n <= (int)Band.B6M; n++)
                            {
                                Band b = (Band)n;
                                string sSetting = "udPAGain" + mapBandToMeters(b).ToString();
                                float g = getOldVariablePAgain(sSetting, ref getDict);
                                if (g != 1000) p.SetGainForBand(b, g);
                                if (g != 1000 && bRemoveOld) removeOldPASetting(sSetting);
                            }
                            for (int n = (int)Band.VHF0; n <= (int)Band.VHF13; n++)
                            {
                                Band b = (Band)n;
                                string sSetting = "udPAGainVHF" + (n - (int)Band.VHF0).ToString();
                                float g = getOldVariablePAgain(sSetting, ref getDict);
                                if (g != 1000) p.SetGainForBand(b, g);
                                if (g != 1000 && bRemoveOld) removeOldPASetting(sSetting);
                            }
                        }
                        break;
                    case HPSDRModel.ORIONMKII:
                        for (int n = (int)Band.B160M; n <= (int)Band.B6M; n++)
                        {
                            Band b = (Band)n;
                            string sSetting = "udORIONMKIIPAGain" + mapBandToMeters(b).ToString();
                            float g = getOldVariablePAgain(sSetting, ref getDict);
                            if (g != 1000) p.SetGainForBand(b, g);
                            if (g != 1000 && bRemoveOld) removeOldPASetting(sSetting);
                        }
                        for (int n = (int)Band.VHF0; n <= (int)Band.VHF13; n++)
                        {
                            Band b = (Band)n;
                            string sSetting = "udORIONMKIIPAGainVHF" + (n - (int)Band.VHF0).ToString();
                            float g = getOldVariablePAgain(sSetting, ref getDict);
                            if (g != 1000) p.SetGainForBand(b, g);
                            if (g != 1000 && bRemoveOld) removeOldPASetting(sSetting);
                        }
                        break;
                }
            }
        }

        private void OnMoxChangeHandler(int rx, bool oldMox, bool newMox)
        {
            PAProfileEnableControls(newMox);

            if (newMox)
                enabledAllPAnuds(false);
            else
                enabledAllPAnuds(true);
        }
        private void OnTXBandChanged(Band oldBand, Band newBand, double tx_frequency)
        {
            setAdjustingBand(newBand);
            lblTXattBand.Text = newBand.ToString(); //[2.3.10.6]MW0LGE added (also in ATTOnTX)
        }
        private void setAdjustingBand(Band b)
        {
            string sBand = b.ToString();
            if (sBand.EndsWith("M"))
            {
                if (sBand.StartsWith("B")) sBand = sBand.Remove(0, 1);
            }

            if (!((b >= Band.B160M && b <= Band.B6M) || (b >= Band.VHF0 && b <= Band.VHF13)))
            {
                _adjustingBand = Band.FIRST; // MW0LGE_[2.9.0.7] reset
                enabledPAAdjust(false);
                lblAdjustBand.Text = "Ignore for : " + sBand;
                lblMaxPowerForBandPA.Text = "Ignore for : " + sBand;
                return;
            }
            else
            {
                enabledPAAdjust(true);
                lblAdjustBand.Text = "Offset for : " + sBand;
                lblMaxPowerForBandPA.Text = "Actual Power @ 100% slider for : " + sBand;
            }

            _adjustingBand = b;

            updateNUDAdjustgains();
            updateMaxPower();
            updateDriveLabels();
        }
        public class PAProfile
        {
            private string _sName = "";
            private HPSDRModel _model;
            private bool _default;

            public string ProfileName
            {
                get { return _sName; }
            }
            public bool IsDefault
            {
                get { return _default; }
            }
            public HPSDRModel Model
            {
                get { return _model; }
            }
            private float[] _gainValues;
            private float[,] _gainAdjust;
            private float[] _maxPower;
            private bool[] _bUseMaxPower;

            public PAProfile(string sName, HPSDRModel model, bool isDefault)
            {
                _sName = sName;
                _model = model;
                _default = isDefault;
                _gainValues = new float[(int)Band.LAST];
                _gainAdjust = new float[(int)Band.LAST, 9];
                _maxPower = new float[(int)Band.LAST];
                _bUseMaxPower = new bool[(int)Band.LAST];

                // setup
                for (int n = 0; n < (int)Band.LAST; n++)
                {
                    for (int i = 0; i < 9; i++)
                    {
                        _gainAdjust[n, i] = 0;
                    }

                    _gainValues[n] = 100;
                    _maxPower[n] = 0;
                    _bUseMaxPower[n] = false;
                }

                ResetGainDefaultsForModel(_model);
            }
            private string base64Encode(string plainText)
            {
                try
                {
                    byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
                    return Convert.ToBase64String(plainTextBytes);
                }
                catch
                {
                    return "";
                }
            }
            private string base64Decode(string base64EncodedData)
            {
                try
                {
                    byte[] base64EncodedBytes = Convert.FromBase64String(base64EncodedData);
                    return Encoding.UTF8.GetString(base64EncodedBytes);
                }
                catch
                {
                    return "";
                }
            }
            public void DataFromString(string sData)
            {
                string[] sSplit = sData.Split('|');
                if ((sSplit.Length == (int)Band.LAST + 3) || (sSplit.Length == (int)Band.LAST + 3 + 378) || (sSplit.Length == (int)Band.LAST + 3 + 378 + 84))
                // + 3 = 3 initial settings
                // + 378 = the new offsets
                // + 84 = the new max power and in use
                {
                    if (base64Encode(base64Decode(sSplit[0])) == sSplit[0])
                    {
                        _sName = base64Decode(sSplit[0]);
                    }
                    else
                        _sName = sSplit[0];

                    _model = (HPSDRModel)Enum.Parse(typeof(HPSDRModel), sSplit[1]);
                    _default = bool.Parse(sSplit[2]);

                    // gains
                    for (int n = 0; n < (int)Band.LAST; n++)
                        _gainValues[n] = float.Parse(sSplit[n + 3]);  // +3 as we have 3 previous settings, name, model, default

                    if (sSplit.Length > 45)
                    {
                        // we have the gain adjust
                        int index = 0;
                        for (int n = 0; n < (int)Band.LAST; n++)
                        {
                            for (int i = 0; i < 9; i++)
                            {
                                _gainAdjust[n, i] = float.Parse(sSplit[index + 45]); // +45 to skip everything before
                                index++;
                            }
                        }

                        if (sSplit.Length > 423)
                        {
                            // we have max power
                            index = 0;
                            for (int n = 0; n < (int)Band.LAST; n++)
                            {
                                _bUseMaxPower[n] = bool.Parse(sSplit[index + 423]);
                                _maxPower[n] = float.Parse(sSplit[index + 423 + 1]);
                                index += 2;
                            }
                        }
                    }
                }
            }
            public string DataToString()
            {
                string sData = base64Encode(_sName) + "|";
                sData += ((int)_model).ToString() + "|";
                sData += _default.ToString() + "|";

                // gains
                for (int n = 0; n < (int)Band.LAST; n++)
                    sData += _gainValues[n].ToString("0.0") + "|";

                // gain adjust
                for (int n = 0; n < (int)Band.LAST; n++)
                {
                    for (int i = 0; i < 9; i++)
                    {
                        sData += _gainAdjust[n, i].ToString("0.0") + "|";
                    }
                }

                // max power
                for (int n = 0; n < (int)Band.LAST; n++)
                {
                    sData += _bUseMaxPower[n].ToString() + "|";
                    sData += _maxPower[n].ToString("0.0") + "|";
                }

                sData = sData.TrimEnd('|');

                return sData;
            }
            public float GetGainForBand(Band b, int nDriveValue = -1)
            {
                if (!((int)b > (int)Band.FIRST && (int)b < (int)Band.LAST)) return 1000;

                if (nDriveValue == -1)
                    return _gainValues[(int)b];
                else
                    return _gainValues[(int)b] - calcDriveAdjust(b, nDriveValue);
            }
            private float calcDriveAdjust(Band b, int nDriveValue)
            {
                int nBand = (int)b;
                int nLIndex = nDriveValue / 10;

                if (nDriveValue % 10 == 0)
                {
                    if (nLIndex == 0 || nLIndex == 10) return 0;
                    // exact
                    return _gainAdjust[nBand, nLIndex - 1];
                }
                else
                {
                    float low;
                    float high;

                    if (nLIndex == 0)
                    {
                        low = 0;
                        high = _gainAdjust[nBand, 0];
                    }
                    else if (nLIndex == 9)
                    {
                        low = _gainAdjust[nBand, 8];
                        high = 0;
                    }
                    else
                    {
                        low = _gainAdjust[nBand, nLIndex - 1];
                        high = _gainAdjust[nBand, nLIndex];
                    }

                    float frac = (nDriveValue - (nLIndex * 10)) / 10f;

                    return lerp(low, high, frac);
                }
            }
            private float lerp(float a, float b, float frac)
            {
                return a + frac * (b - a);
            }
            public void SetMaxPower(Band b, float maxPower)
            {
                if (!((int)b > (int)Band.FIRST && (int)b < (int)Band.LAST)) return;
                _maxPower[(int)b] = maxPower;
            }
            public float GetMaxPower(Band b)
            {
                if (!((int)b > (int)Band.FIRST && (int)b < (int)Band.LAST)) return 0;
                return _maxPower[(int)b];
            }
            public void SetMaxPowerUse(Band b, bool bUse)
            {
                if (!((int)b > (int)Band.FIRST && (int)b < (int)Band.LAST)) return;
                _bUseMaxPower[(int)b] = bUse;
            }
            public bool GetMaxPowerUse(Band b)
            {
                if (!((int)b > (int)Band.FIRST && (int)b < (int)Band.LAST)) return false;
                return _bUseMaxPower[(int)b];
            }
            public void SetAdjust(Band b, int stepIndex, float gain)
            {
                if (!((int)b > (int)Band.FIRST && (int)b < (int)Band.LAST)) return;
                if (stepIndex < 0 || stepIndex > 8) return;

                _gainAdjust[(int)b, stepIndex] = gain;
            }
            public float GetAdjust(Band b, int stepIndex)
            {
                if (!((int)b > (int)Band.FIRST && (int)b < (int)Band.LAST)) return 0;
                if (stepIndex < 0 || stepIndex > 8) return 0;

                return _gainAdjust[(int)b, stepIndex];
            }
            public void SetGainForBand(Band b, float gain)
            {
                if (!((int)b > (int)Band.FIRST && (int)b < (int)Band.LAST)) return;

                _gainValues[(int)b] = gain;
            }
            public void CopySettings(PAProfile sourceProfile)
            {
                if (sourceProfile == null) return;

                for (int n = 0; n < (int)Band.LAST; n++)
                {
                    _gainValues[n] = sourceProfile._gainValues[n];
                }
                // adjusts
                for (int n = 0; n < (int)Band.LAST; n++)
                {
                    for (int i = 0; i < 9; i++)
                    {
                        _gainAdjust[n, i] = sourceProfile._gainAdjust[n, i];
                    }
                }
                // max power
                for (int n = 0; n < (int)Band.LAST; n++)
                {
                    _maxPower[n] = sourceProfile._maxPower[n];
                    _bUseMaxPower[n] = sourceProfile._bUseMaxPower[n];
                }
            }
            public void ResetGainDefaultsForModel(HPSDRModel model)
            {
                _model = model;

                //reset
                for (int n = 0; n < (int)Band.LAST; n++)
                {
                    for (int i = 0; i < 9; i++)
                    {
                        _gainAdjust[n, i] = 0;
                    }

                    _maxPower[n] = 0;
                    _bUseMaxPower[n] = false;
                }
                //

                if (model == HPSDRModel.FIRST || model == HPSDRModel.HERMES || model == HPSDRModel.HPSDR || model == HPSDRModel.ORIONMKII) //note: first is special case for the pa bypass (part of calibrate)
                {
                    SetGainForBand(Band.B160M, 41.0f);
                    SetGainForBand(Band.B80M, 41.2f);
                    SetGainForBand(Band.B60M, 41.3f);
                    SetGainForBand(Band.B40M, 41.3f);
                    SetGainForBand(Band.B30M, 41.0f);
                    SetGainForBand(Band.B20M, 40.5f);
                    SetGainForBand(Band.B17M, 39.9f);
                    SetGainForBand(Band.B15M, 38.8f);
                    SetGainForBand(Band.B12M, 38.8f);
                    SetGainForBand(Band.B10M, 38.8f);
                    SetGainForBand(Band.B6M, 38.8f);

                    SetGainForBand(Band.VHF0, 56.2f);
                    SetGainForBand(Band.VHF1, 56.2f);
                    SetGainForBand(Band.VHF2, 56.2f);
                    SetGainForBand(Band.VHF3, 56.2f);
                    SetGainForBand(Band.VHF4, 56.2f);
                    SetGainForBand(Band.VHF5, 56.2f);
                    SetGainForBand(Band.VHF6, 56.2f);
                    SetGainForBand(Band.VHF7, 56.2f);
                    SetGainForBand(Band.VHF8, 56.2f);
                    SetGainForBand(Band.VHF9, 56.2f);
                    SetGainForBand(Band.VHF10, 56.2f);
                    SetGainForBand(Band.VHF11, 56.2f);
                    SetGainForBand(Band.VHF12, 56.2f);
                    SetGainForBand(Band.VHF13, 56.2f);

                    return;
                }

                if (model == HPSDRModel.ANAN10 || model == HPSDRModel.ANAN10E)
                {
                    SetGainForBand(Band.B160M, 41.0f);
                    SetGainForBand(Band.B80M, 41.2f);
                    SetGainForBand(Band.B60M, 41.3f);
                    SetGainForBand(Band.B40M, 41.3f);
                    SetGainForBand(Band.B30M, 41.0f);
                    SetGainForBand(Band.B20M, 40.5f);
                    SetGainForBand(Band.B17M, 39.9f);
                    SetGainForBand(Band.B15M, 38.8f);
                    SetGainForBand(Band.B12M, 38.8f);
                    SetGainForBand(Band.B10M, 38.8f);
                    SetGainForBand(Band.B6M, 38.8f);

                    SetGainForBand(Band.VHF0, 56.2f);
                    SetGainForBand(Band.VHF1, 56.2f);
                    SetGainForBand(Band.VHF2, 56.2f);
                    SetGainForBand(Band.VHF3, 56.2f);
                    SetGainForBand(Band.VHF4, 56.2f);
                    SetGainForBand(Band.VHF5, 56.2f);
                    SetGainForBand(Band.VHF6, 56.2f);
                    SetGainForBand(Band.VHF7, 56.2f);
                    SetGainForBand(Band.VHF8, 56.2f);
                    SetGainForBand(Band.VHF9, 56.2f);
                    SetGainForBand(Band.VHF10, 56.2f);
                    SetGainForBand(Band.VHF11, 56.2f);
                    SetGainForBand(Band.VHF12, 56.2f);
                    SetGainForBand(Band.VHF13, 56.2f);

                    return;
                }

                if (model == HPSDRModel.ANAN100)
                {
                    SetGainForBand(Band.B160M, 50.0f);
                    SetGainForBand(Band.B80M, 50.5f);
                    SetGainForBand(Band.B60M, 50.5f);
                    SetGainForBand(Band.B40M, 50.0f);
                    SetGainForBand(Band.B30M, 49.5f);
                    SetGainForBand(Band.B20M, 48.5f);
                    SetGainForBand(Band.B17M, 48.0f);
                    SetGainForBand(Band.B15M, 47.5f);
                    SetGainForBand(Band.B12M, 46.5f);
                    SetGainForBand(Band.B10M, 42.0f);
                    SetGainForBand(Band.B6M, 43.0f);

                    SetGainForBand(Band.VHF0, 56.2f);
                    SetGainForBand(Band.VHF1, 56.2f);
                    SetGainForBand(Band.VHF2, 56.2f);
                    SetGainForBand(Band.VHF3, 56.2f);
                    SetGainForBand(Band.VHF4, 56.2f);
                    SetGainForBand(Band.VHF5, 56.2f);
                    SetGainForBand(Band.VHF6, 56.2f);
                    SetGainForBand(Band.VHF7, 56.2f);
                    SetGainForBand(Band.VHF8, 56.2f);
                    SetGainForBand(Band.VHF9, 56.2f);
                    SetGainForBand(Band.VHF10, 56.2f);
                    SetGainForBand(Band.VHF11, 56.2f);
                    SetGainForBand(Band.VHF12, 56.2f);
                    SetGainForBand(Band.VHF13, 56.2f);

                    return;
                }

                if (model == HPSDRModel.ANAN100B)
                {
                    SetGainForBand(Band.B160M, 50.0f);
                    SetGainForBand(Band.B80M, 50.5f);
                    SetGainForBand(Band.B60M, 50.5f);
                    SetGainForBand(Band.B40M, 50.0f);
                    SetGainForBand(Band.B30M, 49.5f);
                    SetGainForBand(Band.B20M, 48.5f);
                    SetGainForBand(Band.B17M, 48.0f);
                    SetGainForBand(Band.B15M, 47.5f);
                    SetGainForBand(Band.B12M, 46.5f);
                    SetGainForBand(Band.B10M, 42.0f);
                    SetGainForBand(Band.B6M, 43.0f);

                    SetGainForBand(Band.VHF0, 56.2f);
                    SetGainForBand(Band.VHF1, 56.2f);
                    SetGainForBand(Band.VHF2, 56.2f);
                    SetGainForBand(Band.VHF3, 56.2f);
                    SetGainForBand(Band.VHF4, 56.2f);
                    SetGainForBand(Band.VHF5, 56.2f);
                    SetGainForBand(Band.VHF6, 56.2f);
                    SetGainForBand(Band.VHF7, 56.2f);
                    SetGainForBand(Band.VHF8, 56.2f);
                    SetGainForBand(Band.VHF9, 56.2f);
                    SetGainForBand(Band.VHF10, 56.2f);
                    SetGainForBand(Band.VHF11, 56.2f);
                    SetGainForBand(Band.VHF12, 56.2f);
                    SetGainForBand(Band.VHF13, 56.2f);

                    return;
                }

                if (model == HPSDRModel.ANAN100D)// && !bypasPASettings)
                {
                    SetGainForBand(Band.B160M, 49.5f);
                    SetGainForBand(Band.B80M, 50.5f);
                    SetGainForBand(Band.B60M, 50.5f);
                    SetGainForBand(Band.B40M, 50.0f);
                    SetGainForBand(Band.B30M, 49.0f);
                    SetGainForBand(Band.B20M, 48.0f);
                    SetGainForBand(Band.B17M, 47.0f);
                    SetGainForBand(Band.B15M, 46.5f);
                    SetGainForBand(Band.B12M, 46.0f);
                    SetGainForBand(Band.B10M, 43.5f);
                    SetGainForBand(Band.B6M, 43.0f);

                    SetGainForBand(Band.VHF0, 56.2f);
                    SetGainForBand(Band.VHF1, 56.2f);
                    SetGainForBand(Band.VHF2, 56.2f);
                    SetGainForBand(Band.VHF3, 56.2f);
                    SetGainForBand(Band.VHF4, 56.2f);
                    SetGainForBand(Band.VHF5, 56.2f);
                    SetGainForBand(Band.VHF6, 56.2f);
                    SetGainForBand(Band.VHF7, 56.2f);
                    SetGainForBand(Band.VHF8, 56.2f);
                    SetGainForBand(Band.VHF9, 56.2f);
                    SetGainForBand(Band.VHF10, 56.2f);
                    SetGainForBand(Band.VHF11, 56.2f);
                    SetGainForBand(Band.VHF12, 56.2f);
                    SetGainForBand(Band.VHF13, 56.2f);

                    return;
                }

                if (model == HPSDRModel.ANAN200D)// && !bypasPASettings)
                {
                    SetGainForBand(Band.B160M, 49.5f);
                    SetGainForBand(Band.B80M, 50.5f);
                    SetGainForBand(Band.B60M, 50.5f);
                    SetGainForBand(Band.B40M, 50.0f);
                    SetGainForBand(Band.B30M, 49.0f);
                    SetGainForBand(Band.B20M, 48.0f);
                    SetGainForBand(Band.B17M, 47.0f);
                    SetGainForBand(Band.B15M, 46.5f);
                    SetGainForBand(Band.B12M, 46.0f);
                    SetGainForBand(Band.B10M, 43.5f);
                    SetGainForBand(Band.B6M, 43.0f);

                    SetGainForBand(Band.VHF0, 56.2f);
                    SetGainForBand(Band.VHF1, 56.2f);
                    SetGainForBand(Band.VHF2, 56.2f);
                    SetGainForBand(Band.VHF3, 56.2f);
                    SetGainForBand(Band.VHF4, 56.2f);
                    SetGainForBand(Band.VHF5, 56.2f);
                    SetGainForBand(Band.VHF6, 56.2f);
                    SetGainForBand(Band.VHF7, 56.2f);
                    SetGainForBand(Band.VHF8, 56.2f);
                    SetGainForBand(Band.VHF9, 56.2f);
                    SetGainForBand(Band.VHF10, 56.2f);
                    SetGainForBand(Band.VHF11, 56.2f);
                    SetGainForBand(Band.VHF12, 56.2f);
                    SetGainForBand(Band.VHF13, 56.2f);

                    return;
                }

                if (model == HPSDRModel.ANAN8000D)
                {
                    SetGainForBand(Band.B160M, 50.0f);
                    SetGainForBand(Band.B80M, 50.5f);
                    SetGainForBand(Band.B60M, 50.5f);
                    SetGainForBand(Band.B40M, 50.0f);
                    SetGainForBand(Band.B30M, 49.5f);
                    SetGainForBand(Band.B20M, 48.5f);
                    SetGainForBand(Band.B17M, 48.0f);
                    SetGainForBand(Band.B15M, 47.5f);
                    SetGainForBand(Band.B12M, 46.5f);
                    SetGainForBand(Band.B10M, 42.0f);
                    SetGainForBand(Band.B6M, 43.0f);

                    SetGainForBand(Band.VHF0, 56.2f);
                    SetGainForBand(Band.VHF1, 56.2f);
                    SetGainForBand(Band.VHF2, 56.2f);
                    SetGainForBand(Band.VHF3, 56.2f);
                    SetGainForBand(Band.VHF4, 56.2f);
                    SetGainForBand(Band.VHF5, 56.2f);
                    SetGainForBand(Band.VHF6, 56.2f);
                    SetGainForBand(Band.VHF7, 56.2f);
                    SetGainForBand(Band.VHF8, 56.2f);
                    SetGainForBand(Band.VHF9, 56.2f);
                    SetGainForBand(Band.VHF10, 56.2f);
                    SetGainForBand(Band.VHF11, 56.2f);
                    SetGainForBand(Band.VHF12, 56.2f);
                    SetGainForBand(Band.VHF13, 56.2f);

                    return;
                }

                if (model == HPSDRModel.ANAN7000D || model == HPSDRModel.ANAN_G2)
                {
                    SetGainForBand(Band.B160M, 47.9f);
                    SetGainForBand(Band.B80M, 50.5f);
                    SetGainForBand(Band.B60M, 50.8f);
                    SetGainForBand(Band.B40M, 50.8f);
                    SetGainForBand(Band.B30M, 50.9f);
                    SetGainForBand(Band.B20M, 50.9f);
                    SetGainForBand(Band.B17M, 50.5f);
                    SetGainForBand(Band.B15M, 47.0f);
                    SetGainForBand(Band.B12M, 47.9f);
                    SetGainForBand(Band.B10M, 46.5f);
                    SetGainForBand(Band.B6M, 44.6f);

                    SetGainForBand(Band.VHF0, 63.1f);
                    SetGainForBand(Band.VHF1, 63.1f);
                    SetGainForBand(Band.VHF2, 63.1f);
                    SetGainForBand(Band.VHF3, 63.1f);
                    SetGainForBand(Band.VHF4, 63.1f);
                    SetGainForBand(Band.VHF5, 63.1f);
                    SetGainForBand(Band.VHF6, 63.1f);
                    SetGainForBand(Band.VHF7, 63.1f);
                    SetGainForBand(Band.VHF8, 63.1f);
                    SetGainForBand(Band.VHF9, 63.1f);
                    SetGainForBand(Band.VHF10, 63.1f);
                    SetGainForBand(Band.VHF11, 63.1f);
                    SetGainForBand(Band.VHF12, 63.1f);
                    SetGainForBand(Band.VHF13, 63.1f);

                    return;
                }

                if (model == HPSDRModel.ANAN_G2_1K)                 // G8NJJ will need changing when PA detail known
                {
                    SetGainForBand(Band.B160M, 47.9f);
                    SetGainForBand(Band.B80M, 50.5f);
                    SetGainForBand(Band.B60M, 50.8f);
                    SetGainForBand(Band.B40M, 50.8f);
                    SetGainForBand(Band.B30M, 50.9f);
                    SetGainForBand(Band.B20M, 50.9f);
                    SetGainForBand(Band.B17M, 50.5f);
                    SetGainForBand(Band.B15M, 47.0f);
                    SetGainForBand(Band.B12M, 47.9f);
                    SetGainForBand(Band.B10M, 46.5f);
                    SetGainForBand(Band.B6M, 44.6f);

                    SetGainForBand(Band.VHF0, 63.1f);
                    SetGainForBand(Band.VHF1, 63.1f);
                    SetGainForBand(Band.VHF2, 63.1f);
                    SetGainForBand(Band.VHF3, 63.1f);
                    SetGainForBand(Band.VHF4, 63.1f);
                    SetGainForBand(Band.VHF5, 63.1f);
                    SetGainForBand(Band.VHF6, 63.1f);
                    SetGainForBand(Band.VHF7, 63.1f);
                    SetGainForBand(Band.VHF8, 63.1f);
                    SetGainForBand(Band.VHF9, 63.1f);
                    SetGainForBand(Band.VHF10, 63.1f);
                    SetGainForBand(Band.VHF11, 63.1f);
                    SetGainForBand(Band.VHF12, 63.1f);
                    SetGainForBand(Band.VHF13, 63.1f);

                    return;
                }
            }
        }
        private void enabledPAAdjust(bool bEnabled)
        {
            foreach (Control c in panelAdjustGain.Controls)
            {
                NumericUpDownTS nud = c as NumericUpDownTS;
                if (c != null)
                {
                    if (c.Name.StartsWith("nudAdjustGain"))
                        c.Enabled = bEnabled;
                }
            }

            chkUsePowerOnDrvTunPA.Enabled = bEnabled;
            nudMaxPowerForBandPA.Enabled = bEnabled;
        }
        private void enabledAllPAnuds(bool bEnabled)
        {
            foreach (Control c in grpGainByBandPA.Controls)
            {
                NumericUpDownTS nud = c as NumericUpDownTS;
                if (c != null)
                {
                    if (c.Name.StartsWith("nud"))
                    {
                        bool bVHF = nud.Name.StartsWith("nudVHF");
                        int nNumber = bVHF ? int.Parse(nud.Name.Substring(6)) : int.Parse(nud.Name.Substring(3, nud.Name.Length - 4));
                        Band b;
                        if (bVHF)
                            b = (Band)((int)Band.VHF0 + nNumber);
                        else
                            b = (Band)((int)Band.B160M + mapBandMetersToIndex(nNumber));

                        if (!bEnabled)
                        {
                            // ignore current band
                            if (b != _adjustingBand) c.Enabled = false;
                        }
                        else
                            c.Enabled = true;
                    }
                }
            }
        }

        private Band _adjustingBand = Band.FIRST;
        private void nudAdjustGain_ValueChanged(object sender, EventArgs e)
        {
            if (_bIgnoreNUDAdjustUpdate || initializing || _PAProfiles == null) return;
            if (_adjustingBand == Band.FIRST) return;

            NumericUpDownTS nud = sender as NumericUpDownTS;
            if (nud == null) return;

            PAProfile p = getPAProfile(comboPAProfile.Text);
            if (p == null) return;

            int nNumber = int.Parse(nud.Name.Substring(13)) - 10;

            p.SetAdjust(_adjustingBand, nNumber / 10, (float)nud.Value);

            if (console.MOX)
            {
                switch (console.TuneDrivePowerOrigin)
                {
                    case DrivePowerSource.DRIVE_SLIDER:
                        console.PWR = nNumber + 10; // set drive to the value we are adjusting
                        break;
                    case DrivePowerSource.TUNE_SLIDER:
                        console.TunePWR = nNumber + 10;
                        break;
                }
            }
        }
        private void updateMaxPowerCheckbox(PAProfile p = null)
        {
            if (_adjustingBand == Band.FIRST) return;
            if (p == null)
                p = getPAProfile(comboPAProfile.Text);

            if (p == null) return;

            if (nudMaxPowerForBandPA.Value == 0)
            {
                chkUsePowerOnDrvTunPA.Enabled = false;
                _bIgnoreNUDAdjustUpdate = true; // prevent _checked event
                chkUsePowerOnDrvTunPA.Checked = false;
                _bIgnoreNUDAdjustUpdate = false;
            }
            else
            {
                chkUsePowerOnDrvTunPA.Enabled = true;
                chkUsePowerOnDrvTunPA.Checked = p.GetMaxPowerUse(_adjustingBand);
            }
        }
        private void nudMaxPowerForBandPA_ValueChanged(object sender, EventArgs e)
        {
            if (_bIgnoreNUDAdjustUpdate || initializing || _PAProfiles == null) return;
            if (_adjustingBand == Band.FIRST) return;

            PAProfile p = getPAProfile(comboPAProfile.Text);
            if (p == null) return;

            updateMaxPowerCheckbox(p);

            p.SetMaxPower(_adjustingBand, (float)nudMaxPowerForBandPA.Value);

            updateDriveLabels();

            console.UpdateDriveLabel(false, EventArgs.Empty);
            console.UpdateTuneLabel(false, EventArgs.Empty);
        }

        private void chkUsePowerOnDrvTunPA_CheckedChanged(object sender, EventArgs e)
        {
            if (_bIgnoreNUDAdjustUpdate || initializing || _PAProfiles == null) return;
            if (_adjustingBand == Band.FIRST) return;

            PAProfile p = getPAProfile(comboPAProfile.Text);
            if (p == null) return;

            p.SetMaxPowerUse(_adjustingBand, chkUsePowerOnDrvTunPA.Checked);

            updateDriveLabels(p);

            console.UpdateDriveLabel(false, EventArgs.Empty);
            console.UpdateTuneLabel(false, EventArgs.Empty);
        }

        private void clrbtnSliderLimitBar_Changed(object sender, EventArgs e)
        {
            if (initializing) return;
            console.LimitSliderColor = clrbtnSliderLimitBar.Color;
        }

        private void chkUseSUnitsForPBNPPBSNR_CheckedChanged(object sender, EventArgs e)
        {
            console.UseSUnitsForPBNPPBSNR = chkUseSUnitsForPBNPPBSNR.Checked;
        }

        private void nudNFsensitivity_ValueChanged(object sender, EventArgs e)
        {
            Display.NFsensitivity = (int)nudNFsensitivity.Value;
        }

        private void nudNFshift_ValueChanged(object sender, EventArgs e)
        {
            Display.NFshiftDBM = (float)nudNFshift.Value;
        }

        private void chkNFShowDecimal_CheckedChanged(object sender, EventArgs e)
        {
            Display.NoiseFloorDecimal = chkNFShowDecimal.Checked;
        }

        private void chkAdjustGridMinToNFRX1_CheckedChanged(object sender, EventArgs e)
        {
            console.GridMinFollowsNFRX1 = chkAdjustGridMinToNFRX1.Checked;
            nudRX1NFoffsetGridFollow.Enabled = chkAdjustGridMinToNFRX1.Checked;
            chkMaintainNFAdjustDeltaRX1.Enabled = chkAdjustGridMinToNFRX1.Checked;
        }

        private void chkAdjustGridMinToNFRX2_CheckedChanged(object sender, EventArgs e)
        {
            console.GridMinFollowsNFRX2 = chkAdjustGridMinToNFRX2.Checked;
            nudRX2NFoffsetGridFollow.Enabled = chkAdjustGridMinToNFRX2.Checked;
            chkMaintainNFAdjustDeltaRX2.Enabled = chkAdjustGridMinToNFRX2.Checked;
        }

        private void nudRX2NFoffsetGridFollow_ValueChanged(object sender, EventArgs e)
        {
            console.RX2NFoffsetGridFollow = (float)nudRX2NFoffsetGridFollow.Value;
        }

        private void nudRX1NFoffsetGridFollow_ValueChanged(object sender, EventArgs e)
        {
            console.RX1NFoffsetGridFollow = (float)nudRX1NFoffsetGridFollow.Value;
        }

        private void btnResetLevelCal_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show(
                "Do you want to reset Level Calibration back to defaults ?",
                "Level Defaults",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, Common.MB_TOPMOST);

            if (dr == DialogResult.Yes)
                console.ResetLevelCalibration();
        }

        private bool _bVoffSet = false;
        private bool _bSensSet = false;
        private void btnAmpDefault_Click(object sender, EventArgs e)
        {
            float voff = 360.0f, sens = 120.0f;
            if (console.CurrentHPSDRModel == HPSDRModel.ANAN7000D || console.CurrentHPSDRModel == HPSDRModel.ANAN_G2)
            {
                voff = 340.0f;
                sens = 88.0f;
            }

            udAmpVoff.Value = (decimal)voff;
            udAmpSens.Value = (decimal)sens;
        }
        private void udAmpVoff_ValueChanged(object sender, EventArgs e)
        {
            //note: do not check for initalizing here
            console.AmpVoff = (float)udAmpVoff.Value;
            _bVoffSet = true;
        }
        private void udAmpSens_ValueChanged(object sender, EventArgs e)
        {
            //note: do not check for initalizing here
            console.AmpSens = (float)udAmpSens.Value;
            _bSensSet = true;
        }
        private void initVoltsAmpsCalibration()
        {
            if (!_bSensSet || !_bVoffSet) btnAmpDefault_Click(this, EventArgs.Empty);
        }

        private void chkForceATTwhenPSAoff_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.ForceATTwhenPSAoff = chkForceATTwhenPSAoff.Checked;
        }

        private void chkVisualNotch_CheckedChanged(object sender, EventArgs e)
        {
            Display.ShowVisualNotch = chkVisualNotch.Checked;
        }

        private void btnRX1PBsnr_Click(object sender, EventArgs e)
        {
            float snr = console.RXPBsnr(1);
            if (snr == -999) return;

            float t = (float)nudPBsnrShiftRx1.Value - snr;

            // limit to 24 for the shift
            if (t < -24) t = -24;
            if (t > 24) t = 24;

            nudPBsnrShiftRx1.Value = (decimal)t;
        }

        private void btnRX2PBsnr_Click(object sender, EventArgs e)
        {
            float snr = console.RXPBsnr(2);
            if (snr == -999) return;

            float t = (float)nudPBsnrShiftRx2.Value - snr;

            // limit to 12 for the shift
            if (t < -24) t = -24;
            if (t > 24) t = 24;

            nudPBsnrShiftRx2.Value = (decimal)t;
        }

        private void btnResetNFShift_Click(object sender, EventArgs e)
        {
            nudNFshift.Value = (decimal)0f;
        }
        private void chkPreventTXonDifferentBandToRX_CheckedChanged(object sender, EventArgs e)
        {
            console.PreventTXonDifferentBandToRXband = chkPreventTXonDifferentBandToRX.Checked;
        }
        #region MultiMeter2
        // multimeter 2
        private const int MAX_CONTAINERS = 50;

        private class clsContainerComboboxItem
        {
            public string Text { get; set; }
            public string ID { get; set; }

            public override string ToString()
            {
                return Text;
            }
        }
        private class clsMeterTypeComboboxItem
        {
            private MeterType _meterType;
            private int _order;
            public clsMeterTypeComboboxItem(MeterType mt, int nOrder)
            {
                _meterType = mt;
                _order = nOrder;
            }
            public MeterType MeterType
            {
                get { return _meterType; }
                set { _meterType = value; }
            }
            public int Order
            {
                get { return _order; }
                set { _order = value; }
            }
            public override string ToString()
            {
                return MeterManager.MeterName(_meterType);
            }
        }
        private MeterManager.clsMeter meterFromSelectedContainer()
        {
            clsContainerComboboxItem cci = comboContainerSelect.SelectedItem as clsContainerComboboxItem;
            if (cci == null) return null;

            return MeterManager.MeterFromId(cci.ID);
        }
        private void btnAddRX1Container_Click(object sender, EventArgs e)
        {
            if (MeterManager.TotalMeterContainers < MAX_CONTAINERS)
            {
                string sId = MeterManager.AddMeterContainer(1, false);
                updateMeter2Controls(sId);
            }
        }

        private void btnAddRX2Container_Click(object sender, EventArgs e)
        {
            if (MeterManager.TotalMeterContainers < MAX_CONTAINERS)
            {
                string sId = MeterManager.AddMeterContainer(2, false);
                updateMeter2Controls(sId);
            }
        }
        private void updateMeter2Controls(string sId = "")
        {
            bool bEnableAdd = MeterManager.TotalMeterContainers < MAX_CONTAINERS;

            btnAddRX1Container.Enabled = bEnableAdd;
            btnAddRX2Container.Enabled = bEnableAdd && console.RX2Enabled;

            comboContainerSelect.Text = "";
            comboContainerSelect.Items.Clear();
            int i = 0;
            int nSelect = 0;

            // add the containers to the list
            foreach (KeyValuePair<string, ucMeter> kvp in MeterManager.MeterContainers)
            {
                clsContainerComboboxItem cci = new clsContainerComboboxItem();
                cci.Text = "Container " + (i + 1).ToString() + " TRX" + kvp.Value.RX.ToString();
                cci.ID = kvp.Value.ID;

                comboContainerSelect.Items.Add(cci);

                if (cci.ID == sId && nSelect == 0) nSelect = i;

                i++;
            }

            bool bEnableControls = false;

            if (comboContainerSelect.Items.Count > 0)
            {
                comboContainerSelect.SelectedIndex = nSelect;

                bEnableControls = true;
            }
            else
            {
                comboContainerSelect.Text = "";
            }

            bool locked = chkLockContainer.Checked;

            btnContainerDelete.Enabled = bEnableControls && !locked;
            chkContainerHighlight.Enabled = bEnableControls;
            comboContainerSelect.Enabled = bEnableControls;
            clrbtnContainerBackground.Enabled = bEnableControls;
            chkContainerBorder.Enabled = bEnableControls;
            chkContainerNoTitle.Enabled = bEnableControls;
            chkMultiMeter_auto_container_height.Enabled = bEnableControls;
            chkLockContainer.Enabled = bEnableControls;
            chkContainerShowRX.Enabled = bEnableControls;
            chkContainerShowTX.Enabled = bEnableControls;
            chkContainerMinimises.Enabled = bEnableControls;
            txtContainerNotes.Enabled = bEnableControls;
            lblMMContainerBackground.Enabled = bEnableControls;
            lblMMContainerNotes.Enabled = bEnableControls;
            lstMetersAvailable.Enabled = bEnableControls;
            lstMetersInUse.Enabled = bEnableControls;
            btnAddMeterItem.Enabled = bEnableControls && !locked;
            btnRemoveMeterItem.Enabled = bEnableControls && !locked;
            btnMeterUp.Enabled = bEnableControls && !locked && lstMetersInUse.Items.Count > 0;
            btnMeterDown.Enabled = bEnableControls && !locked && lstMetersInUse.Items.Count > 0;

            btnMeterCopySettings.Enabled = bEnableControls && lstMetersInUse.Items.Count > 0;
            btnMeterPasteSettings.Enabled = bEnableControls && lstMetersInUse.Items.Count > 0;

            if (!bEnableControls) txtContainerNotes.Text = "";
            if (!bEnableControls) comboContainerSelect.Text = "";

            updateMeterLists();
        }
        private void updateMeterLists()
        {
            //lstMetersInUse.BeginUpdate();
            //lstMetersAvailable.BeginUpdate();

            //lstMetersInUse.SuspendLayout();
            //lstMetersAvailable.SuspendLayout();

            lstMetersInUse.Items.Clear();
            lstMetersAvailable.Items.Clear();

            MeterManager.clsMeter m = meterFromSelectedContainer();
            if (m == null) return;

            List<clsMeterTypeComboboxItem> inuse = new List<clsMeterTypeComboboxItem>();
            List<clsMeterTypeComboboxItem> notinuse = new List<clsMeterTypeComboboxItem>();

            for (int n = 1; n < (int)MeterType.LAST; n++)
            {
                MeterType mt = (MeterType)n;

                if (m.HasMeterType(mt))
                {
                    List<int> orders = m.GetOrderForMeterType(mt); // can be muliple orders
                    foreach (int order in orders)
                    {
                        clsMeterTypeComboboxItem mtci = new clsMeterTypeComboboxItem(mt, order);
                        inuse.Add(mtci);
                    }
                }
                //else
                //{
                //if (mt != MeterType.SPACER && mt != MeterType.TEXT_OVERLAY)
                //{
                clsMeterTypeComboboxItem mtci2 = new clsMeterTypeComboboxItem(mt, -1);
                notinuse.Add(mtci2);
                //}
                //}
            }
            //// add spacer and overlay here always to notinuse
            //clsMeterTypeComboboxItem mtci_tmp = new clsMeterTypeComboboxItem(MeterType.SPACER, -1);
            //notinuse.Add(mtci_tmp);
            //mtci_tmp = new clsMeterTypeComboboxItem(MeterType.TEXT_OVERLAY, -1);
            //notinuse.Add(mtci_tmp);

            foreach (clsMeterTypeComboboxItem mtci in notinuse)
            {
                lstMetersAvailable.Items.Add(mtci);
            }
            foreach (clsMeterTypeComboboxItem mtci in inuse.OrderBy(o => o.Order))
            {
                lstMetersInUse.Items.Add(mtci);
            }

            lstMetersAvailable_SelectedIndexChanged(this, EventArgs.Empty);
            lstMetersInUse_SelectedIndexChanged(this, EventArgs.Empty);
        }

        private void btnContainerDelete_Click(object sender, EventArgs e)
        {
            if (chkLockContainer.Checked) return;
            clsContainerComboboxItem cci = (clsContainerComboboxItem)comboContainerSelect.SelectedItem;

            if (cci != null)
            {
                MeterManager.RemoveMeterContainer(cci.ID);
                comboContainerSelect.Items.Remove(cci);

                updateMeter2Controls();
            }
        }

        private void comboContainerSelect_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;

            clsContainerComboboxItem cci = (clsContainerComboboxItem)comboContainerSelect.SelectedItem;
            if (cci == null) return;

            if (chkContainerHighlight.Checked)
            {
                MeterManager.HighlightContainer(cci.ID);
            }

            chkContainerBorder.Checked = MeterManager.ContainerHasBorder(cci.ID);
            clrbtnContainerBackground.Color = MeterManager.GetContainerBackgroundColour(cci.ID);
            chkContainerNoTitle.Checked = MeterManager.ContainerNoTitleBar(cci.ID);

            chkLockContainer.Checked = MeterManager.ContainerLocked(cci.ID);
            chkLockContainer_CheckedChanged(this, EventArgs.Empty); // force it

            chkContainerShowRX.Checked = MeterManager.ContainerShowOnRX(cci.ID);
            chkContainerShowTX.Checked = MeterManager.ContainerShowOnTX(cci.ID);
            chkContainerMinimises.Checked = MeterManager.ContainerMinimises(cci.ID);
            txtContainerNotes.Text = MeterManager.GetContainerNotes(cci.ID);
            chkMultiMeter_auto_container_height.Checked = MeterManager.ContainerAutoHeight(cci.ID);

            updateMeterLists();
        }

        private void chkContainerHighlight_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (chkContainerHighlight.Checked)
            {
                clsContainerComboboxItem cci = (clsContainerComboboxItem)comboContainerSelect.SelectedItem;
                if (cci != null)
                {
                    MeterManager.HighlightContainer(cci.ID);
                }
            }
            else
            {
                MeterManager.HighlightContainer("");
            }
        }
        private void chkContainerShowRX_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            clsContainerComboboxItem cci = (clsContainerComboboxItem)comboContainerSelect.SelectedItem;
            if (cci != null)
            {
                MeterManager.ShowContainerOnRX(cci.ID, chkContainerShowRX.Checked);
            }
        }
        private void chkContainerShowTX_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            clsContainerComboboxItem cci = (clsContainerComboboxItem)comboContainerSelect.SelectedItem;
            if (cci != null)
            {
                MeterManager.ShowContainerOnTX(cci.ID, chkContainerShowTX.Checked);
            }
        }
        private void txtContainerNotes_TextChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            clsContainerComboboxItem cci = (clsContainerComboboxItem)comboContainerSelect.SelectedItem;
            if (cci != null)
            {
                string sTmp = MeterManager.GetContainerNotes(cci.ID);
                if (txtContainerNotes.Text != sTmp)
                    MeterManager.ContainerNotes(cci.ID, txtContainerNotes.Text);
            }
        }
        private void btnAddMeterItem_Click(object sender, EventArgs e)
        {
            if (chkLockContainer.Checked) return;
            clsMeterTypeComboboxItem mti = lstMetersAvailable.SelectedItem as clsMeterTypeComboboxItem;
            if (mti == null) return;

            MeterManager.clsMeter m = meterFromSelectedContainer();
            if (m == null) return;

            m.AddMeter(mti.MeterType);
            m.ZeroOut(true, true);
            m.Rebuild();
            updateMeterLists();

            lstMetersAvailable_SelectedIndexChanged(sender, e);
        }

        private void lstMetersAvailable_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;            
            btnAddMeterItem.Enabled = !chkLockContainer.Checked && lstMetersAvailable.SelectedIndex >= 0;
        }

        private void lstMetersInUse_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;

            bool bEnabled = lstMetersInUse.SelectedIndex >= 0;

            if (bEnabled)
                updateItemSettingsControlsForSelected();
            else
                setupMMSettingsGroupBoxes(MeterType.NONE);

            btnRemoveMeterItem.Enabled = !chkLockContainer.Checked && bEnabled;
            btnMeterUp.Enabled = !chkLockContainer.Checked && bEnabled;
            btnMeterDown.Enabled = !chkLockContainer.Checked && bEnabled;

            btnMeterCopySettings.Enabled = bEnabled;
            btnMeterPasteSettings.Enabled = bEnabled && canPasteSettings();
        }

        private void btnRemoveMeterItem_Click(object sender, EventArgs e)
        {
            if (chkLockContainer.Checked) return;
            clsMeterTypeComboboxItem mti = lstMetersInUse.SelectedItem as clsMeterTypeComboboxItem;
            if (mti == null) return;

            MeterManager.clsMeter m = meterFromSelectedContainer();
            if (m == null) return;

            m.RemoveMeterType(mti.MeterType, mti.Order, true);

            updateMeterLists();

            lstMetersInUse_SelectedIndexChanged(sender, e);
        }

        private void btnMeterUp_Click(object sender, EventArgs e)
        {
            if (chkLockContainer.Checked) return;
            MeterManager.clsMeter m = meterFromSelectedContainer();
            if (m == null) return;

            clsMeterTypeComboboxItem mtci = lstMetersInUse.SelectedItem as clsMeterTypeComboboxItem;
            if (mtci == null) return;

            int n = lstMetersInUse.SelectedIndex - 1;
            if (n < 0) return;

            m.SetOrderForMeterType(mtci.MeterType, n, true, true, mtci.Order);

            updateMeterLists();

            lstMetersInUse.SelectedIndex = n;
        }

        private void btnMeterDown_Click(object sender, EventArgs e)
        {
            if (chkLockContainer.Checked) return;
            MeterManager.clsMeter m = meterFromSelectedContainer();
            if (m == null) return;

            clsMeterTypeComboboxItem mtci = lstMetersInUse.SelectedItem as clsMeterTypeComboboxItem;
            if (mtci == null) return;

            int n = lstMetersInUse.SelectedIndex + 1;
            if (n > lstMetersInUse.Items.Count - 1) return;

            m.SetOrderForMeterType(mtci.MeterType, n, true, false, mtci.Order);

            updateMeterLists();

            lstMetersInUse.SelectedIndex = n;
        }

        private void lstMetersAvailable_DoubleClick(object sender, EventArgs e)
        {
            btnAddMeterItem_Click(sender, e);
        }

        private void lstMetersInUse_DoubleClick(object sender, EventArgs e)
        {
            btnRemoveMeterItem_Click(sender, e);
        }

        private void lstMetersAvailable_DrawItem(object sender, DrawItemEventArgs e)
        {
            lstMetersInUse_DrawItem(sender, e);
        }

        private void lstMetersInUse_DrawItem(object sender, DrawItemEventArgs e)
        {
            e.DrawBackground();

            Graphics g = e.Graphics;

            if (e.Index >= 0)
            {
                clsMeterTypeComboboxItem mtci = (clsMeterTypeComboboxItem)((ListBox)sender).Items[e.Index];
                if (mtci != null)
                {
                    SolidBrush sb;

                    int n = MeterManager.GetMeterTXRXType(mtci.MeterType);
                    switch (n)
                    {
                        case 0: //rx
                            sb = new SolidBrush(Color.PaleGreen);
                            break;
                        case 1: //tx
                            sb = new SolidBrush(Color.PaleVioletRed);
                            break;
                        default: //other
                            sb = new SolidBrush(Color.CornflowerBlue);
                            break;
                    }

                    Rectangle r = new Rectangle(e.Bounds.X, e.Bounds.Y, 4, e.Bounds.Height);

                    g.FillRectangle(sb, r);
                    sb.Dispose();
                }
                SolidBrush sbt;
                if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                    sbt = new SolidBrush(Color.White);
                else
                    sbt = new SolidBrush(Color.Black);
                g.DrawString(" " + ((ListBox)sender).Items[e.Index].ToString(), e.Font, sbt, e.Bounds, StringFormat.GenericDefault);
                sbt.Dispose();

                e.DrawFocusRectangle();
            }
        }
        private string meterItemGroupIDfromSelected()
        {
            MeterManager.clsMeter m = meterFromSelectedContainer();
            if (m == null) return "";

            clsMeterTypeComboboxItem mtci = lstMetersInUse.SelectedItem as clsMeterTypeComboboxItem;
            if (mtci == null) return "";
            if (!m.HasMeterType(mtci.MeterType)) return "";

            return m.MeterGroupID(mtci.MeterType, mtci.Order);
        }
        private MeterType meterItemGroupTypefromSelected()
        {
            MeterManager.clsMeter m = meterFromSelectedContainer();
            if (m == null) return MeterType.NONE;

            clsMeterTypeComboboxItem mtci = lstMetersInUse.SelectedItem as clsMeterTypeComboboxItem;
            if (mtci == null) return MeterType.NONE;
            if (!m.HasMeterType(mtci.MeterType)) return MeterType.NONE;

            return mtci.MeterType;
        }
        private void chkMeterItemHistory_CheckedChanged(object sender, EventArgs e)
        {
            bool bEnabled = chkMeterItemHistory.Checked;

            updateHistoryControls(bEnabled, Color.Red, false);

            updateMeterType();
        }
        private MeterManager.clsIGSettings updateMeterType()
        {
            if (initializing || _ignoreMeterItemChangeEvents) return null;

            string mgID = meterItemGroupIDfromSelected();
            if (mgID == "") return null;

            clsMeterTypeComboboxItem mtci = lstMetersInUse.SelectedItem as clsMeterTypeComboboxItem;
            if (mtci == null) return null;
            
            MeterManager.clsMeter m = meterFromSelectedContainer();
            if (m == null) return null;

            MeterType mt = meterItemGroupTypefromSelected();
            if (mt == MeterType.NONE) return null;

            MeterManager.clsIGSettings igs = m.GetSettingsForMeterGroup(mt, mtci.Order);
            if (igs == null) return null;

            if (mt == MeterType.HISTORY)
            {
                igs.SetSetting<float>("history_vertical_ratio", (float)nudHistory_vertical_ratio.Value);
                igs.SetSetting<System.Drawing.Color>("history_background_colour", clrbtnHistory_background.Color);
                igs.SetSetting<float>("history_update", (float)nudHistory_update.Value);
                igs.SetSetting<float>("history_keep_for", (float)nudHistory_keep_for.Value);
                
                clsComboHistoryItem chi = comboHistory_reading_0.SelectedItem as clsComboHistoryItem;
                if(chi != null)
                    igs.SetSetting<Reading>("history_reading_0", chi.Reading);
                else
                    igs.SetSetting<Reading>("history_reading_0", Reading.SIGNAL_STRENGTH);

                chi = comboHistory_reading_1.SelectedItem as clsComboHistoryItem;
                if (chi != null)
                    igs.SetSetting<Reading>("history_reading_1", chi.Reading);
                else
                    igs.SetSetting<Reading>("history_reading_1", Reading.SIGNAL_STRENGTH);

                igs.SetSetting<bool>("history_auto_scale_0", chkHistory_auto_0_scale.Checked);
                igs.SetSetting<float>("history_min_0", (float)nudHistory_axis0_min.Value);
                igs.SetSetting<float>("history_max_0", (float)nudHistory_axis0_max.Value);

                igs.SetSetting<bool>("history_show_scale_1", chkHistory_1_show_axis.Checked);
                igs.SetSetting<bool>("history_auto_scale_1", chkHistory_auto_1_scale.Checked);
                igs.SetSetting<float>("history_min_1", (float)nudHistory_axis1_min.Value);
                igs.SetSetting<float>("history_max_1", (float)nudHistory_axis1_max.Value);

                igs.SetSetting<System.Drawing.Color>("history_colour_0", clrbtnHistory_colour_0.Color);
                igs.SetSetting<System.Drawing.Color>("history_colour_1", clrbtnHistory_colour_1.Color);

                igs.SetSetting<System.Drawing.Color>("history_colour_lines", clrbtnHistory_lines.Color);
                igs.SetSetting<System.Drawing.Color>("history_colour_time", clrbtnHistory_time.Color);

                igs.FadeOnRx = chkHistory_fade_rx.Checked;
                igs.FadeOnTx = chkHistory_fade_tx.Checked;
            }
            else if (mt == MeterType.BAND_BUTTONS || mt == MeterType.MODE_BUTTONS || mt == MeterType.FILTER_BUTTONS || mt == MeterType.ANTENNA_BUTTONS || mt == MeterType.TUNESTEP_BUTTONS || mt == MeterType.DISCORD_BUTTONS)
            {
                if (mt == MeterType.TUNESTEP_BUTTONS)
                {
                    igs.SetSetting<int>("buttonbox_tunestep_bitfield", ucTunestepOptionsGrid_buttons.Bitfield);
                }
                else if (mt == MeterType.ANTENNA_BUTTONS)
                {
                    igs.SetSetting<bool>("buttonbox_rx1", chkButtonBox_antenna_rx1.Checked);
                    igs.SetSetting<bool>("buttonbox_rx2", chkButtonBox_antenna_rx2.Checked);
                    igs.SetSetting<bool>("buttonbox_rx3", chkButtonBox_antenna_rx3.Checked);
                    igs.SetSetting<bool>("buttonbox_tx1", chkButtonBox_antenna_tx1.Checked);
                    igs.SetSetting<bool>("buttonbox_tx2", chkButtonBox_antenna_tx2.Checked);
                    igs.SetSetting<bool>("buttonbox_tx3", chkButtonBox_antenna_tx3.Checked);
                    igs.SetSetting<bool>("buttonbox_byp", chkButtonBox_antenna_byp.Checked);
                    igs.SetSetting<bool>("buttonbox_ext1", chkButtonBox_antenna_ext1.Checked);
                    igs.SetSetting<bool>("buttonbox_xvtr", chkButtonBox_antenna_xvtr.Checked);
                    igs.SetSetting<bool>("buttonbox_rxtxant", chkButtonBox_antenna_rxtxant.Checked);
                }

                if (mt == MeterType.TUNESTEP_BUTTONS)
                {
                    int max_buttons = ucTunestepOptionsGrid_buttons.GetCheckedCount();
                    max_buttons = Math.Max(1, max_buttons);
                    if (nudBandButtons_columns.Value > max_buttons) nudBandButtons_columns.Value = max_buttons;
                    if (nudBandButtons_columns.Maximum != max_buttons) nudBandButtons_columns.Maximum = max_buttons;
                }
                else if (mt == MeterType.ANTENNA_BUTTONS)
                {
                    int max_buttons = getTotalColumnsNeededForAntennaButtons();
                    max_buttons = Math.Max(1, max_buttons);
                    if (nudBandButtons_columns.Value > max_buttons) nudBandButtons_columns.Value = max_buttons;
                    if (nudBandButtons_columns.Maximum != max_buttons) nudBandButtons_columns.Maximum = max_buttons;
                }

                igs.SetSetting<int>("buttonbox_columns", (int)nudBandButtons_columns.Value);
                igs.SetSetting<float>("buttonbox_border", (float)nudBandButtons_border.Value);
                igs.SetSetting<float>("buttonbox_margin", (float)nudBandButtons_margin.Value);
                igs.SetSetting<float>("buttonbox_radius", (float)nudBandButtons_radius.Value);
                igs.SetSetting<float>("buttonbox_height_ratio", (float)nudBandButtons_height_ratio.Value);

                igs.SetSetting<bool>("buttonbox_use_indicator", chkBandButtons_use_indicator.Checked);
                igs.SetSetting<float>("buttonbox_indicator_border", (float)nudBandButtons_indicator_border.Value);
                igs.SetSetting<System.Drawing.Color>("buttonbox_on_colour", clrbtnBandButtons_indicator_on.Color);
                igs.SetSetting<System.Drawing.Color>("buttonbox_off_colour", clrbtnBandButtons_indicator_off.Color);

                igs.SetSetting<System.Drawing.Color>("buttonbox_fill_colour", clrbtnBandButtons_fill.Color);
                igs.SetSetting<System.Drawing.Color>("buttonbox_hover_colour", clrbtnBandButtons_hover.Color);
                igs.SetSetting<System.Drawing.Color>("buttonbox_border_colour", clrbtnBandButtons_border.Color);

                igs.SetSetting<System.Drawing.Color>("buttonbox_click_colour", clrbtnButonBox_click.Color);
                igs.SetSetting<System.Drawing.Color>("buttonbox_font_colour", clrbtnButonBox_fontcolour.Color);

                igs.SetSetting<bool>("buttonbox_use_off_colour", chkBandButtons_band_inactive_use.Checked);

                igs.SetSetting<MeterManager.clsButtonBox.IndicatorType>("buttonbox_indicator_type", (MeterManager.clsButtonBox.IndicatorType)((int)nudBandButtons_indicator_style.Value));

                igs.SetSetting<float>("buttonbox_font_scale", (float)nudButtonBox_font_scale.Value);
                igs.SetSetting<float>("buttonbox_font_shift_x", (float)nudButtonBox_font_x_shift.Value);
                igs.SetSetting<float>("buttonbox_font_shift_y", (float)nudButtonBox_font_y_shift.Value);

                if (_bandButtons_font != null)
                {
                    igs.FontFamily1 = _bandButtons_font.FontFamily.Name;
                    igs.FontStyle1 = _bandButtons_font.Style;
                    //igs.FontSize1 = _bandButtons_font.Size; size not used
                }

                igs.FadeOnRx = chkBandButtons_fade_rx.Checked;
                igs.FadeOnTx = chkBandButtons_fade_tx.Checked;
            }
            else if (mt == MeterType.WEB_IMAGE)
            {
                igs.UpdateInterval = (int)nudWebImage_update_interval.Value;
                igs.EyeScale = (float)nudWebImage_width_scale.Value;
                igs.FadeOnRx = chkWebImage_fade_rx.Checked;
                igs.FadeOnTx = chkWebImage_fade_tx.Checked;
                igs.Text1 = txtWebImage_url.Text;
                igs.DarkMode = chkWebImage_bypass_cache.Checked;
            }
            else if(mt == MeterType.ROTATOR)
            {
                igs.UpdateInterval = (int)nudMeterItemUpdateRateRotator.Value;
                igs.Colour = Color.FromArgb(255, clrbtnMeterItemHBackgroundRotator.Color);
                igs.TitleColor = clrbtnMeterItemRotatorArrow.Color;
                igs.MarkerColour = clrbtnMeterItemRotatorLargeDot.Color;
                igs.SubMarkerColour = clrbtnMeterItemRotatorSmallDot.Color;
                igs.ShowMarker = chkMeterItemRotatorShowBeamWidth.Checked;
                igs.LowColor = clrbtnMeterItemRotatorBeamWidth.Color;
                igs.HighColor = clrbtnMeterItemRotatorText.Color;
                igs.ShowHistory = chkMeterItemRotatorCardinals.Checked;
                igs.FadeOnRx = chkMeterItemFadeOnRxRotator.Checked;
                igs.FadeOnTx = chkMeterItemFadeOnTxRotator.Checked;
                igs.DarkMode = chkMeterItemDarkModeRotator.Checked;
                igs.AttackRatio = (float)nudMeterItemRotatorBeamWidth.Value;
                igs.EyeScale = (float)nudMeterItemRotator_padding.Value;

                //
                if (radMeterItemRotator_show_az.Checked)
                    igs.HistoryDuration = (int)MeterManager.clsRotatorItem.RotatorMode.AZ;
                else if (radMeterItemRotator_show_ele.Checked)
                    igs.HistoryDuration = (int)MeterManager.clsRotatorItem.RotatorMode.ELE;
                else if (radMeterItemRotator_show_both.Checked)
                    igs.HistoryDuration = (int)MeterManager.clsRotatorItem.RotatorMode.BOTH;
                //

                igs.ShowType = chkMeterItemRotatorAllowControl.Checked;
                igs.HistoryColor = clrbtnMeterItemRotatorControlColour.Color;
                igs.Text1 = txtMeterItemRotatorAZcommand.Text;
                igs.Text2 = txtMeterItemRotatorELEcommand.Text;
                igs.FontFamily1 = txtMeterItemRotatorSTOPcommand.Text;

                Guid guid = MultiMeterIO.GuidfromFourChar(txtRotator_4charID.Text);
                if (guid != Guid.Empty)
                {
                    igs.SetMMIOGuid(2, guid);
                }
                else
                {
                    igs.SetMMIOGuid(2, Guid.Empty);
                }

                igs.SetSetting<float>("rotator_beamwidth_alpha", (float)nudMeterItemRotatorBeamWidth_alpha.Value);
            }
            else if (mt == MeterType.DATA_OUT)
            {
                Guid guid = MultiMeterIO.GuidfromFourChar(txtDataOutNode_4charID.Text);
                if (guid != Guid.Empty)
                {
                    igs.SetMMIOGuid(0, guid);
                    igs.UpdateInterval = (int)nudDataOutNode_sendinterval.Value;
                }
                else
                {
                    igs.SetMMIOGuid(0, Guid.Empty);
                    igs.UpdateInterval = 500;
                }
            }
            else if (mt == MeterType.SIGNAL_TEXT)
            {
                igs.UpdateInterval = (int)nudMeterItemUpdateRate.Value;
                igs.AttackRatio = (float)nudMeterItemAttackRate.Value;
                igs.DecayRatio = (float)nudMeterItemDecayRate.Value;
                igs.FadeOnRx = chkMeterItemFadeOnRx.Checked;
                igs.FadeOnTx = chkMeterItemFadeOnTx.Checked;
                igs.Colour = clrbtnMeterItemHBackground.Color;
                igs.MarkerColour = clrbtnMeterItemIndicator.Color;
                igs.SubMarkerColour = clrbtnMeterItemSubIndicator.Color;
                igs.ShowSubMarker = chkMeterItemShowSubIndicator.Checked;
                igs.PeakValueColour = clrbtnMeterItemPeakValueColour.Color;
                igs.PeakValue = chkMeterItemPeakValue.Checked;
                igs.Average = chkMeterItemSignalAverage.Checked;
                igs.HistoryDuration = (int)nudMeterItemHistoryDuration.Value;
                igs.IgnoreHistoryDuration = (int)nudMeterItemIgnoreHistoryDuration.Value;
            }
            else if (mt == MeterType.VFO_DISPLAY)
            {
                igs.Colour = clrbtnMMVfoDisplayBackground.Color;
                igs.TitleColor = clrbtnMMVfoDisplayTitle.Color;

                //using exisinng igs settings
                igs.MarkerColour = clrbtnMMVfoDisplayFrequency.Color;
                igs.SubMarkerColour = clrbtnMMVfoDisplayMode.Color;
                igs.LowColor = clrbtnMMVfoDisplaySplitBack.Color;
                igs.HighColor = clrbtnMMVfoDisplaySplit.Color;
                igs.PeakValueColour = clrbtnMMVfoDisplayRx.Color;
                igs.PeakHoldMarkerColor = clrbtnMMVfoDisplayTx.Color;
                igs.HistoryColor = clrbtnMMVfoDisplayFilter.Color;
                igs.SegmentedSolidLowColour = clrbtnMMVfoDisplayBand.Color;
                igs.PowerScaleColour = clrbtnMMVfoDigitHighlight.Color;

                igs.SetSetting<bool>("vfo_showbandtext", chkMultiMeter_vfo_show_bandtext.Checked);
                igs.SetSetting<System.Drawing.Color>("vfo_showbandtext_colour", clrbtnMultiMeter_vfo_show_bandtext.Color);
                igs.SetSetting<System.Drawing.Color>("vfo_frequency_small_numbers_colour", clrbtnMMVfoDisplayFrequency_small.Color);

                igs.SetSetting<System.Drawing.Color>("vfo_lock_colour", clrbtnMultiMeter_vfo_lock.Color);
                igs.SetSetting<System.Drawing.Color>("vfo_sync_colour", clrbtnMultiMeter_vfo_sync.Color);

                if (radMultiMeter_vfo_display_both.Checked)
                    igs.HistoryDuration = (int)MeterManager.clsVfoDisplay.VFODisplayMode.VFO_BOTH;
                else if (radMultiMeter_vfo_display_vfoa.Checked)
                    igs.HistoryDuration = (int)MeterManager.clsVfoDisplay.VFODisplayMode.VFO_A;
                else if (radMultiMeter_vfo_display_vfob.Checked)
                    igs.HistoryDuration = (int)MeterManager.clsVfoDisplay.VFODisplayMode.VFO_B;
            }
            else if (mt == MeterType.CLOCK)
            {
                igs.Colour = clrbtnMMClockBackground.Color;
                igs.ShowType = chkMMClockTitle.Checked;
                igs.TitleColor = clrbtnMMClockTitle.Color;
                igs.MarkerColour = clrbtnMMTime.Color;
                igs.SubMarkerColour = clrbtnMMDate.Color;
                igs.ShowMarker = radMM24Clock.Checked; // use the show marker bool for this                
            }
            else if (mt == MeterType.LED)
            {
                igs.FadeOnRx = chkLedIndicator_FadeOnRX.Checked;
                igs.FadeOnTx = chkLedIndicator_FadeOnTX.Checked;
                igs.Colour = clrbtnLedIndicator_true.Color;
                igs.MarkerColour = clrbtnLedIndicator_false.Color;

                igs.TitleColor = clrbtnLedIndicator_PanelBackground.Color;
                igs.HistoryColor = clrbtnLedIndicator_PanelBackgroundTX.Color;
                igs.ShowSubMarker = chkLedIndicator_ShowPanel.Checked;

                igs.EyeScale = (float)nudLedIndicator_xOffset.Value;
                igs.EyeBezelScale = (float)nudLedIndicator_yOffset.Value;
                igs.AttackRatio = (float)nudLedIndicator_xSize.Value;
                igs.DecayRatio = (float)nudLedIndicator_ySize.Value;
                igs.UpdateInterval = (int)nudLedIndicator_UpdateInterval.Value;

                igs.Text1 = txtLedIndicator_condition.Text;

                igs.SpacerPadding = (float)nudLedIndicator_PanelPadding.Value;

                igs.PeakHold = chkLed_show_true.Checked;
                igs.ShowMarker = chkLed_show_false.Checked;
                if (radLed_light_on_off.Checked)
                    igs.IgnoreHistoryDuration = 0;
                else if (radLed_light_blink.Checked)
                    igs.IgnoreHistoryDuration = 1;
                else if (radLed_light_pulsate.Checked)
                    igs.IgnoreHistoryDuration = 2;
                // also showhistory + showtype are return states for valid/error

                igs.SetSetting<bool>("led_notx_true", chkLed_notx_true.Checked);
                igs.SetSetting<bool>("led_notx_false", chkLed_notx_false.Checked);
            }
            else if (mt == MeterType.TEXT_OVERLAY)
            {
                igs.FadeOnRx = chkTextOverlay_FadeOnRX.Checked;
                igs.FadeOnTx = chkTextOverlay_FadeOnTX.Checked;
                igs.Colour = clrbtnTextOverlay_TextColour1.Color;
                igs.MarkerColour = clrbtnTextOverlay_TextColour2.Color;
                igs.SubMarkerColour = clrbtnTextOverlay_TextBackColour1.Color;
                igs.ShowMarker = chkTextOverlay_textback1.Checked;
                igs.PeakValueColour = clrbtnTextOverlay_TextBackColour2.Color;
                igs.ShowType = chkTextOverlay_textback2.Checked;

                igs.TitleColor = clrbtnTextOverlay_PanelBackground.Color;
                igs.HistoryColor = clrbtnTextOverlay_PanelBackgroundTX.Color;
                igs.ShowSubMarker = chkTextOverlay_ShowPanel.Checked;

                igs.EyeScale = (float)nudTextOverlay_RXxOffset.Value;
                igs.EyeBezelScale = (float)nudTextOverlay_RXyOffset.Value;
                igs.AttackRatio = (float)nudTextOverlay_TXxOffset.Value;
                igs.DecayRatio = (float)nudTextOverlay_TXyOffset.Value;

                igs.Text1 = txtTextOverlay_RXText.Text;
                igs.Text2 = txtTextOverlay_TXText.Text;

                if (_textOverlayFont1 != null)
                {
                    igs.FontFamily1 = _textOverlayFont1.FontFamily.Name;
                    igs.FontStyle1 = _textOverlayFont1.Style;
                    igs.FontSize1 = _textOverlayFont1.Size;
                }
                if (_textOverlayFont2 != null)
                {
                    igs.FontFamily2 = _textOverlayFont2.FontFamily.Name;
                    igs.FontStyle2 = _textOverlayFont2.Style;
                    igs.FontSize2 = _textOverlayFont2.Size;
                }

                igs.SpacerPadding = (float)nudTextOverlay_PanelPadding.Value;
            }
            else if (mt == MeterType.SPACER)
            {
                igs.Colour = clrbtnMeterItemHBackgroundSpacerRX.Color;
                igs.MarkerColour = clrbtnMeterItemHBackgroundSpacerTX.Color;
                igs.FadeOnRx = chkMeterItemFadeOnRxSpacer.Checked;
                igs.FadeOnTx = chkMeterItemFadeOnTxSpacer.Checked;
                igs.SpacerPadding = (float)nudMeterItemSpacerPadding.Value;
            }
            else
            {
                igs.LowColor = Color.FromArgb(255, clrbtnMeterItemLow.Color);
                igs.HighColor = Color.FromArgb(255, clrbtnMeterItemHigh.Color);
                igs.MarkerColour = Color.FromArgb(255, clrbtnMeterItemIndicator.Color);
                igs.SubMarkerColour = Color.FromArgb(255, clrbtnMeterItemSubIndicator.Color);
                igs.ShowMarker = chkMeterItemShowIndicator.Checked;
                igs.ShowSubMarker = chkMeterItemShowSubIndicator.Checked;
                igs.Colour = Color.FromArgb(255, clrbtnMeterItemHBackground.Color);
                igs.UpdateInterval = (int)nudMeterItemUpdateRate.Value;
                igs.AttackRatio = (float)nudMeterItemAttackRate.Value;
                igs.DecayRatio = (float)nudMeterItemDecayRate.Value;
                igs.ShowHistory = chkMeterItemHistory.Checked;
                igs.HistoryColor = Color.FromArgb(tbMeterItemHistoryAlpha.Value, clrbtnMeterItemHistory.Color);
                igs.Shadow = chkMeterItemShadow.Checked;
                igs.HistoryDuration = (int)nudMeterItemHistoryDuration.Value;
                igs.IgnoreHistoryDuration = (int)nudMeterItemIgnoreHistoryDuration.Value;

                if (chkMeterItemSegmented.Checked)
                    igs.BarStyle = MeterManager.clsBarItem.BarStyle.Segments;
                else if (chkMeterItemSolid.Checked)
                    igs.BarStyle = MeterManager.clsBarItem.BarStyle.SolidFilled;
                else
                    igs.BarStyle = MeterManager.clsBarItem.BarStyle.Line;

                igs.SegmentedSolidLowColour = clrbtnMeterItemSegmentedSolidColourLow.Color;
                igs.SegmentedSolidHighColour = clrbtnMeterItemSegmentedSolidColourHigh.Color;

                igs.PeakHold = chkMeterItemPeakHold.Checked;
                igs.PeakHoldMarkerColor = Color.FromArgb(255, clrbtnMeterItemPeakHold.Color);
                igs.HistoryDuration = (int)nudMeterItemHistoryDuration.Value;
                igs.FadeOnRx = chkMeterItemFadeOnRx.Checked;
                igs.FadeOnTx = chkMeterItemFadeOnTx.Checked;
                igs.ShowType = chkMeterItemTitle.Checked;
                igs.TitleColor = clrbtnMeterItemMeterTitle.Color;
                igs.PeakValue = chkMeterItemPeakValue.Checked;
                igs.PeakValueColour = clrbtnMeterItemPeakValueColour.Color;
                igs.EyeScale = (float)nudMeterItemEyeScale.Value;
                igs.EyeBezelScale = (float)nudMeterItemEyeBezelScale.Value;
                igs.MaxPower = (float)nudMeterItemsPowerLimit.Value;
                igs.PowerScaleColour = clrbtnMeterItemPowerScale.Color;

                if (mt == MeterType.ANANMM || mt == MeterType.MAGIC_EYE) igs.Average = chkMeterItemSignalAverage.Checked;
                if (mt == MeterType.ANANMM || mt == MeterType.CROSS) igs.DarkMode = chkMeterItemDarkMode.Checked;
            }

            m.ApplySettingsForMeterGroup(mt, igs, mtci.Order);

            updateLedValidControls();
            return igs;
        }
        private bool _ignoreMeterItemChangeEvents = false;
        private void updateItemSettingsControlsForSelected()
        {
            if (initializing) return;

            string mgID = meterItemGroupIDfromSelected();
            if (mgID == "") return;

            clsMeterTypeComboboxItem mtci = lstMetersInUse.SelectedItem as clsMeterTypeComboboxItem;
            if (mtci == null) return;

            MeterManager.clsMeter m = meterFromSelectedContainer();
            if (m == null) return;

            MeterType mt = meterItemGroupTypefromSelected();
            if (mt == MeterType.NONE) return;

            MeterManager.clsIGSettings igs = m.GetSettingsForMeterGroup(mt, mtci.Order);
            if (igs == null) return;

            _ignoreMeterItemChangeEvents = true;

            // setup any meter that has variable % buttons, ignore those that do not
            if (mt != MeterType.ROTATOR && mt != MeterType.SIGNAL_TEXT && mt != MeterType.VFO_DISPLAY && mt != MeterType.CLOCK && 
                mt != MeterType.TEXT_OVERLAY && mt != MeterType.SPACER && mt != MeterType.LED &&
                mt != MeterType.BAND_BUTTONS && mt != MeterType.MODE_BUTTONS && mt != MeterType.FILTER_BUTTONS && mt != MeterType.ANTENNA_BUTTONS &&
                mt != MeterType.HISTORY && mt != MeterType.TUNESTEP_BUTTONS && mt != MeterType.DISCORD_BUTTONS
                )
            {
                switch (m.MeterVariables(mt))
                {
                    case 1:
                        btnMMIO_variable.Enabled = true;
                        btnMMIO_variable_2.Enabled = false;
                        toolTip1.SetToolTip(btnMMIO_variable, m.MeterVariablesReadingString(mt, 0));
                        pnlVariableInUse_1.Visible = variableInUse(0);
                        pnlVariableInUse_2.Visible = false;
                        break;
                    case 2:
                        btnMMIO_variable.Enabled = true;
                        btnMMIO_variable_2.Enabled = true;
                        toolTip1.SetToolTip(btnMMIO_variable, m.MeterVariablesReadingString(mt, 0));
                        toolTip1.SetToolTip(btnMMIO_variable_2, m.MeterVariablesReadingString(mt, 1));
                        pnlVariableInUse_1.Visible = variableInUse(0);
                        pnlVariableInUse_2.Visible = variableInUse(1);
                        break;
                    case 7:
                        //todo? anan mm
                        btnMMIO_variable.Enabled = false;
                        btnMMIO_variable_2.Enabled = false;
                        pnlVariableInUse_1.Visible = false;
                        pnlVariableInUse_2.Visible = false;
                        break;
                    default:
                        btnMMIO_variable.Enabled = false;
                        btnMMIO_variable_2.Enabled = false;
                        pnlVariableInUse_1.Visible = false;
                        pnlVariableInUse_2.Visible = false;
                        break;
                }
            }
            else if (mt == MeterType.ROTATOR)
            {
                // unique controls for rotator as own setting grp
                switch (m.MeterVariables(mt))
                {
                    case 2:
                        btnMMIO_variable_rotator.Enabled = true;
                        btnMMIO_variable_2_rotator.Enabled = true;
                        toolTip1.SetToolTip(btnMMIO_variable_rotator, m.MeterVariablesReadingString(mt, 0));
                        toolTip1.SetToolTip(btnMMIO_variable_2_rotator, m.MeterVariablesReadingString(mt, 1));
                        pnlVariableInUse_1_rotator.Visible = variableInUse(0);
                        pnlVariableInUse_2_rotator.Visible = variableInUse(1);
                        break;
                }
            }
            else if (mt == MeterType.HISTORY)
            {
                // unique controls for history as own setting grp
                switch (m.MeterVariables(mt))
                {
                    case 2:
                        btnMMIO_variable_history.Enabled = true;
                        btnMMIO_variable_2_history.Enabled = true;
                        toolTip1.SetToolTip(btnMMIO_variable_history, m.MeterVariablesReadingString(mt, 0));
                        toolTip1.SetToolTip(btnMMIO_variable_2_history, m.MeterVariablesReadingString(mt, 1));
                        pnlVariableInUse_1_history.Visible = variableInUse(0);
                        pnlVariableInUse_2_history.Visible = variableInUse(1);
                        break;
                }
            }

            if (mt == MeterType.HISTORY)
            {
                nudHistory_vertical_ratio.Value = (decimal)igs.GetSetting<float>("history_vertical_ratio", true, 0.130f, 1f, 0.5f);
                clrbtnHistory_background.Color = igs.GetSetting<System.Drawing.Color>("history_background_colour", false, Color.Empty, Color.Empty, System.Drawing.Color.Black);
                nudHistory_update.Value = (decimal)igs.GetSetting<float>("history_update", true, 50f, 10000f, 0.5f);
                nudHistory_keep_for.Value = (decimal)igs.GetSetting<float>("history_keep_for", true, 1f, 86400f, 20f);
                Reading r = igs.GetSetting<Reading>("history_reading_0", false, Reading.NONE, Reading.NONE, Reading.SIGNAL_STRENGTH);
                foreach(clsComboHistoryItem chi in comboHistory_reading_0.Items)
                {
                    if (chi.Reading == r)
                    {
                        comboHistory_reading_0.SelectedItem = chi;
                        break;
                    }
                }
                r = igs.GetSetting<Reading>("history_reading_1", false, Reading.NONE, Reading.NONE, Reading.SIGNAL_STRENGTH);
                foreach (clsComboHistoryItem chi in comboHistory_reading_1.Items)
                {
                    if (chi.Reading == r)
                    {
                        comboHistory_reading_1.SelectedItem = chi;
                        break;
                    }
                }

                chkHistory_auto_0_scale.Checked = igs.GetSetting<bool>("history_auto_scale_0", false, false, false, true);
                nudHistory_axis0_min.Value = (decimal)igs.GetSetting<float>("history_min_0", true, -10000f, 10000f, -150f);
                nudHistory_axis0_max.Value = (decimal)igs.GetSetting<float>("history_max_0", true, -10000f, 10000f, 0f);

                chkHistory_1_show_axis.Checked = igs.GetSetting<bool>("history_show_scale_1", false, false, false, true);
                chkHistory_auto_1_scale.Checked = igs.GetSetting<bool>("history_auto_scale_1", false, false, false, true);
                nudHistory_axis1_min.Value = (decimal)igs.GetSetting<float>("history_min_1", true, -10000f, 10000f, -150f);
                nudHistory_axis1_max.Value = (decimal)igs.GetSetting<float>("history_max_1", true, -10000f, 10000f, 0f);

                clrbtnHistory_colour_0.Color = igs.GetSetting<System.Drawing.Color>("history_colour_0", false, Color.Empty, Color.Empty, System.Drawing.Color.Red);
                clrbtnHistory_colour_1.Color = igs.GetSetting<System.Drawing.Color>("history_colour_1", false, Color.Empty, Color.Empty, System.Drawing.Color.Yellow);

                clrbtnHistory_lines.Color = igs.GetSetting<System.Drawing.Color>("history_colour_lines", false, Color.Empty, Color.Empty, System.Drawing.Color.White);
                clrbtnHistory_time.Color = igs.GetSetting<System.Drawing.Color>("history_colour_time", false, Color.Empty, Color.Empty, System.Drawing.Color.Gray);

                chkHistory_fade_rx.Checked = igs.FadeOnRx;
                chkHistory_fade_tx.Checked = igs.FadeOnTx;
            }
            else if(mt == MeterType.BAND_BUTTONS || mt == MeterType.MODE_BUTTONS || mt == MeterType.FILTER_BUTTONS || mt == MeterType.ANTENNA_BUTTONS || mt == MeterType.TUNESTEP_BUTTONS || mt == MeterType.DISCORD_BUTTONS)
            {
                int columns = 1;
                int max_buttons = 1;

                if (mt == MeterType.TUNESTEP_BUTTONS)
                {
                    ucTunestepOptionsGrid_buttons.Bitfield = igs.GetSetting<int>("buttonbox_tunestep_bitfield", true, 0, int.MaxValue, 0);
                }
                else if (mt == MeterType.ANTENNA_BUTTONS)
                {
                    chkButtonBox_antenna_rx1.Checked = igs.GetSetting<bool>("buttonbox_rx1", false, false, false, true);
                    chkButtonBox_antenna_rx2.Checked = igs.GetSetting<bool>("buttonbox_rx2", false, false, false, true);
                    chkButtonBox_antenna_rx3.Checked = igs.GetSetting<bool>("buttonbox_rx3", false, false, false, true);
                    chkButtonBox_antenna_tx1.Checked = igs.GetSetting<bool>("buttonbox_tx1", false, false, false, true);
                    chkButtonBox_antenna_tx2.Checked = igs.GetSetting<bool>("buttonbox_tx2", false, false, false, true);
                    chkButtonBox_antenna_tx3.Checked = igs.GetSetting<bool>("buttonbox_tx3", false, false, false, true);
                    chkButtonBox_antenna_byp.Checked = igs.GetSetting<bool>("buttonbox_byp", false, false, false, true);
                    chkButtonBox_antenna_ext1.Checked = igs.GetSetting<bool>("buttonbox_ext1", false, false, false, true);
                    chkButtonBox_antenna_xvtr.Checked = igs.GetSetting<bool>("buttonbox_xvtr", false, false, false, true);
                    chkButtonBox_antenna_rxtxant.Checked = igs.GetSetting<bool>("buttonbox_rxtxant", false, false, false, true);
                }

                switch (mt)
                {
                    case MeterType.BAND_BUTTONS:
                        columns = igs.GetSetting<int>("buttonbox_columns", true, 1, 15, 15);
                        if (nudBandButtons_columns.Value > 15) nudBandButtons_columns.Value = 15;
                        if (nudBandButtons_columns.Maximum != 15) nudBandButtons_columns.Maximum = 15;
                        break;
                    case MeterType.MODE_BUTTONS:
                        columns = igs.GetSetting<int>("buttonbox_columns", true, 1, 12, 12);
                        if (nudBandButtons_columns.Value > 12) nudBandButtons_columns.Value = 12;
                        if (nudBandButtons_columns.Maximum != 12) nudBandButtons_columns.Maximum = 12;
                        break;
                    case MeterType.FILTER_BUTTONS:
                        max_buttons = m.RX == 1 ? 12 : 9; // rx2 only has 9 filter buttons
                        max_buttons = Math.Max(1, max_buttons);
                        columns = igs.GetSetting<int>("buttonbox_columns", true, 1, max_buttons, max_buttons);
                        if (nudBandButtons_columns.Value > max_buttons) nudBandButtons_columns.Value = max_buttons;
                        if (nudBandButtons_columns.Maximum != max_buttons) nudBandButtons_columns.Maximum = max_buttons;
                        break;
                    case MeterType.ANTENNA_BUTTONS:
                        max_buttons = getTotalColumnsNeededForAntennaButtons();
                        max_buttons = Math.Max(1, max_buttons);
                        columns = igs.GetSetting<int>("buttonbox_columns", true, 1, max_buttons, max_buttons);
                        if (nudBandButtons_columns.Value > max_buttons) nudBandButtons_columns.Value = max_buttons;
                        if (nudBandButtons_columns.Maximum != max_buttons) nudBandButtons_columns.Maximum = max_buttons;
                        break;
                    case MeterType.TUNESTEP_BUTTONS:
                        max_buttons = ucTunestepOptionsGrid_buttons.GetCheckedCount();
                        max_buttons = Math.Max(1, max_buttons);
                        columns = igs.GetSetting<int>("buttonbox_columns", true, 1, max_buttons, max_buttons);
                        if (nudBandButtons_columns.Value > max_buttons) nudBandButtons_columns.Value = max_buttons;
                        if (nudBandButtons_columns.Maximum != max_buttons) nudBandButtons_columns.Maximum = max_buttons;
                        break;
                    case MeterType.DISCORD_BUTTONS:
                        columns = igs.GetSetting<int>("buttonbox_columns", true, 1, 9, 9);
                        if (nudBandButtons_columns.Value > 9) nudBandButtons_columns.Value = 9;
                        if (nudBandButtons_columns.Maximum != 9) nudBandButtons_columns.Maximum = 9;
                        break;
                }
                nudBandButtons_columns.Value = columns;
                nudBandButtons_border.Value = (decimal)igs.GetSetting<float>("buttonbox_border", true, 0f, 1f, 0.05f);
                nudBandButtons_margin.Value = (decimal)igs.GetSetting<float>("buttonbox_margin", true, 0f, 1f, 0f);
                nudBandButtons_radius.Value = (decimal)igs.GetSetting<float>("buttonbox_radius", true, 0f, 2f, 0f);
                nudBandButtons_height_ratio.Value = (decimal)igs.GetSetting<float>("buttonbox_height_ratio", true, 0.01f, 2f, 0.5f);

                chkBandButtons_use_indicator.Checked = igs.GetSetting<bool>("buttonbox_use_indicator", false, false, false, false);
                nudBandButtons_indicator_border.Value = (decimal)igs.GetSetting<float>("buttonbox_indicator_border", true, 0f, 1f, 0.05f);
                clrbtnBandButtons_indicator_on.Color = igs.GetSetting<System.Drawing.Color>("buttonbox_on_colour", false, Color.Empty, Color.Empty, System.Drawing.Color.CornflowerBlue);
                clrbtnBandButtons_indicator_off.Color = igs.GetSetting<System.Drawing.Color>("buttonbox_off_colour", false, Color.Empty, Color.Empty, System.Drawing.Color.LightGray);

                clrbtnBandButtons_fill.Color = igs.GetSetting<System.Drawing.Color>("buttonbox_fill_colour", false, Color.Empty, Color.Empty, System.Drawing.Color.Black);
                clrbtnBandButtons_hover.Color = igs.GetSetting<System.Drawing.Color>("buttonbox_hover_colour", false, Color.Empty, Color.Empty, System.Drawing.Color.LightGray);
                clrbtnBandButtons_border.Color = igs.GetSetting<System.Drawing.Color>("buttonbox_border_colour", false, Color.Empty, Color.Empty, System.Drawing.Color.White);

                clrbtnButonBox_click.Color = igs.GetSetting<System.Drawing.Color>("buttonbox_click_colour", false, Color.Empty, Color.Empty, System.Drawing.Color.Orange);
                clrbtnButonBox_fontcolour.Color = igs.GetSetting<System.Drawing.Color>("buttonbox_font_colour", false, Color.Empty, Color.Empty, System.Drawing.Color.White);

                chkBandButtons_band_inactive_use.Checked = igs.GetSetting<bool>("buttonbox_use_off_colour", false, false, false, false);

                nudBandButtons_indicator_style.Value = (decimal)((int)igs.GetSetting<MeterManager.clsButtonBox.IndicatorType>("buttonbox_indicator_type", true, MeterManager.clsButtonBox.IndicatorType.RING, MeterManager.clsButtonBox.IndicatorType.LAST, MeterManager.clsButtonBox.IndicatorType.RING));

                nudButtonBox_font_scale.Value = (decimal)igs.GetSetting<float>("buttonbox_font_scale", true, 0.01f, 2f, 1f);
                nudButtonBox_font_x_shift.Value = (decimal)igs.GetSetting<float>("buttonbox_font_shift_x", true, -0.25f, 0.25f, 0f);
                nudButtonBox_font_y_shift.Value = (decimal)igs.GetSetting<float>("buttonbox_font_shift_y", true, -0.25f, 0.25f, 0f);

                _bandButtons_font = new Font(igs.FontFamily1, igs.FontSize1, igs.FontStyle1);
                chkBandButtons_fade_rx.Checked = igs.FadeOnRx;
                chkBandButtons_fade_tx.Checked = igs.FadeOnTx;

                updateButtonIndicatorControls();
            }
            else if (mt == MeterType.WEB_IMAGE)
            {
                nudWebImage_update_interval.Value = igs.UpdateInterval;
                nudWebImage_width_scale.Value = (decimal)igs.EyeScale;
                chkWebImage_fade_rx.Checked = igs.FadeOnRx;
                chkWebImage_fade_tx.Checked = igs.FadeOnTx;
                txtWebImage_url.Text = igs.Text1;
                chkWebImage_bypass_cache.Checked = igs.DarkMode;
                updateWebImageState((ImageFetcher.State)igs.HistoryDuration);
            }
            else if (mt == MeterType.ROTATOR)
            {
                nudMeterItemUpdateRateRotator.Value = igs.UpdateInterval;
                clrbtnMeterItemHBackgroundRotator.Color = igs.Colour;
                clrbtnMeterItemRotatorArrow.Color = igs.TitleColor;
                clrbtnMeterItemRotatorLargeDot.Color = igs.MarkerColour;
                clrbtnMeterItemRotatorSmallDot.Color = igs.SubMarkerColour;
                chkMeterItemRotatorShowBeamWidth.Checked = igs.ShowMarker;
                clrbtnMeterItemRotatorBeamWidth.Color = igs.LowColor;
                clrbtnMeterItemRotatorText.Color = igs.HighColor;
                chkMeterItemRotatorCardinals.Checked = igs.ShowHistory;
                chkMeterItemFadeOnRxRotator.Checked = igs.FadeOnRx;
                chkMeterItemFadeOnTxRotator.Checked = igs.FadeOnTx;
                chkMeterItemDarkModeRotator.Checked = igs.DarkMode;
                nudMeterItemRotatorBeamWidth.Value = (decimal)igs.AttackRatio;
                nudMeterItemRotator_padding.Value = (decimal)igs.EyeScale;
                updateShowBeamWidthControls();

                chkMeterItemRotatorAllowControl.Checked = igs.ShowType;
                clrbtnMeterItemRotatorControlColour.Color = igs.HistoryColor;
                txtMeterItemRotatorAZcommand.Text = igs.Text1;
                txtMeterItemRotatorELEcommand.Text = igs.Text2;
                txtMeterItemRotatorSTOPcommand.Text = igs.FontFamily1;
                updateRotatorControlControls();

                //
                switch ((MeterManager.clsRotatorItem.RotatorMode)igs.HistoryDuration)
                {
                    case MeterManager.clsRotatorItem.RotatorMode.AZ:
                        radMeterItemRotator_show_az.Checked = true;
                        break;
                    case MeterManager.clsRotatorItem.RotatorMode.ELE:
                        radMeterItemRotator_show_ele.Checked = true;
                        break;
                    case MeterManager.clsRotatorItem.RotatorMode.BOTH:
                        radMeterItemRotator_show_both.Checked = true;
                        break;
                    default:
                        break;
                }
                //

                Guid guid = igs.GetMMIOGuid(2);
                if (MultiMeterIO.Data.ContainsKey(guid))
                {
                    MultiMeterIO.clsMMIO mmio = MultiMeterIO.Data[guid];
                    txtRotator_4charID.Text = mmio.FourChar;
                }
                else
                {
                    txtRotator_4charID.Text = "";
                }

                nudMeterItemRotatorBeamWidth_alpha.Value = (decimal)igs.GetSetting<float>("rotator_beamwidth_alpha", true, 0, 1f, 0.6f);
            }
            else if (mt == MeterType.DATA_OUT)
            {
                Guid guid = igs.GetMMIOGuid(0);
                if (MultiMeterIO.Data.ContainsKey(guid))
                {
                    MultiMeterIO.clsMMIO mmio = MultiMeterIO.Data[guid];
                    txtDataOutNode_4charID.Text = mmio.FourChar;
                    nudDataOutNode_sendinterval.Value = (decimal)igs.UpdateInterval;
                }
                else
                {
                    txtDataOutNode_4charID.Text = "";
                    nudDataOutNode_sendinterval.Value = 500;
                }
            }
            else if (mt == MeterType.SIGNAL_TEXT)
            {
                nudMeterItemUpdateRate.Value = igs.UpdateInterval < nudMeterItemUpdateRate.Minimum ? nudMeterItemUpdateRate.Minimum : igs.UpdateInterval;
                nudMeterItemAttackRate.Value = (decimal)igs.AttackRatio;
                nudMeterItemDecayRate.Value = (decimal)igs.DecayRatio;

                chkMeterItemFadeOnRx.Checked = igs.FadeOnRx;
                chkMeterItemFadeOnTx.Checked = igs.FadeOnTx;
                clrbtnMeterItemHBackground.Color = igs.Colour;
                clrbtnMeterItemIndicator.Color = igs.MarkerColour;
                clrbtnMeterItemSubIndicator.Color = igs.SubMarkerColour;
                clrbtnMeterItemPeakValueColour.Color = igs.PeakValueColour;
                chkMeterItemPeakValue.Checked = igs.PeakValue;
                chkMeterItemSignalAverage.Checked = igs.Average;
                chkMeterItemShowSubIndicator.Checked = igs.ShowSubMarker;

                nudMeterItemHistoryDuration.Value = igs.HistoryDuration < nudMeterItemHistoryDuration.Minimum ? nudMeterItemHistoryDuration.Minimum : igs.HistoryDuration;
                nudMeterItemIgnoreHistoryDuration.Value = igs.IgnoreHistoryDuration;

                lblMMLow.Enabled = false;
                lblMMHigh.Enabled = false;
                clrbtnMeterItemLow.Enabled = false;
                clrbtnMeterItemHigh.Enabled = false;

                lblMMIndicator.Enabled = true;
                clrbtnMeterItemIndicator.Enabled = true;
                chkMeterItemShowIndicator.Enabled = false;

                lblMMIndicatorSub.Enabled = true;
                clrbtnMeterItemSubIndicator.Enabled = true;
                chkMeterItemShowSubIndicator.Enabled = true;

                lblMMBackground.Enabled = true;
                clrbtnMeterItemHBackground.Enabled = true;
                chkMeterItemFadeOnRx.Enabled = true;
                chkMeterItemFadeOnTx.Enabled = true;
                chkMeterItemSegmented.Enabled = false;
                chkMeterItemSolid.Enabled = false;
                lblMMsegSolLow.Enabled = false;
                lblMMsegSolHigh.Enabled = false;
                clrbtnMeterItemSegmentedSolidColourLow.Enabled = false;
                clrbtnMeterItemSegmentedSolidColourHigh.Enabled = false;
                chkMeterItemTitle.Enabled = false;
                clrbtnMeterItemMeterTitle.Enabled = false;
                chkMeterItemPeakValue.Enabled = true;
                updatePeakValueControls();
                lblMMEyeSize.Enabled = false;
                lblMMEyeBezelSize.Enabled = false;
                nudMeterItemEyeScale.Enabled = false;
                nudMeterItemEyeBezelScale.Enabled = false;
                chkMeterItemShadow.Enabled = false;
                lblMMHistory.Enabled = true;
                lblMMHistoryIgnore.Enabled = true;
                nudMeterItemHistoryDuration.Enabled = true;
                nudMeterItemIgnoreHistoryDuration.Enabled = true;
                chkMeterItemHistory.Enabled = false;
                clrbtnMeterItemHistory.Enabled = false;
                chkMeterItemPeakHold.Enabled = false;
                clrbtnMeterItemPeakHold.Enabled = false;
                chkMeterItemSignalAverage.Enabled = true;
                chkMeterItemDarkMode.Enabled = false;
                lblMMPowerLimit.Enabled = false;
                nudMeterItemsPowerLimit.Enabled = false;
                clrbtnMeterItemPowerScale.Enabled = false;
            }
            else if (mt == MeterType.VFO_DISPLAY)
            {
                clrbtnMMVfoDisplayBackground.Color = igs.Colour;
                clrbtnMMVfoDisplayTitle.Color = igs.TitleColor;

                //using exisinng igs settings
                clrbtnMMVfoDisplayFrequency.Color = igs.MarkerColour;
                clrbtnMMVfoDisplayMode.Color = igs.SubMarkerColour;
                clrbtnMMVfoDisplaySplitBack.Color = igs.LowColor;
                clrbtnMMVfoDisplaySplit.Color = igs.HighColor;
                clrbtnMMVfoDisplayRx.Color = igs.PeakValueColour;
                clrbtnMMVfoDisplayTx.Color = igs.PeakHoldMarkerColor;
                clrbtnMMVfoDisplayFilter.Color = igs.HistoryColor;
                clrbtnMMVfoDisplayBand.Color = igs.SegmentedSolidLowColour;
                clrbtnMMVfoDigitHighlight.Color = igs.PowerScaleColour;

                chkMultiMeter_vfo_show_bandtext.Checked = igs.GetSetting<bool>("vfo_showbandtext", false, false, false, false);
                clrbtnMultiMeter_vfo_show_bandtext.Color = igs.GetSetting<System.Drawing.Color>("vfo_showbandtext_colour", false, Color.Empty, Color.Empty, System.Drawing.Color.LimeGreen);
                clrbtnMMVfoDisplayFrequency_small.Color = igs.GetSetting<System.Drawing.Color>("vfo_frequency_small_numbers_colour", false, Color.Empty, Color.Empty, System.Drawing.Color.Orange);

                clrbtnMultiMeter_vfo_lock.Color = igs.GetSetting<System.Drawing.Color>("vfo_lock_colour", false, Color.Empty, Color.Empty, System.Drawing.Color.LimeGreen);
                clrbtnMultiMeter_vfo_sync.Color = igs.GetSetting<System.Drawing.Color>("vfo_sync_colour", false, Color.Empty, Color.Empty, System.Drawing.Color.LimeGreen);


                switch ((MeterManager.clsVfoDisplay.VFODisplayMode)igs.HistoryDuration)
                {
                    case MeterManager.clsVfoDisplay.VFODisplayMode.VFO_BOTH:
                        radMultiMeter_vfo_display_both.Checked = true;
                        break;
                    case MeterManager.clsVfoDisplay.VFODisplayMode.VFO_A:
                        radMultiMeter_vfo_display_vfoa.Checked = true;
                        break;
                    case MeterManager.clsVfoDisplay.VFODisplayMode.VFO_B:
                        radMultiMeter_vfo_display_vfob.Checked = true;
                        break;
                }

                updateVfoShowBandtextColour();
            }
            else if (mt == MeterType.CLOCK)
            {
                clrbtnMMClockBackground.Color = igs.Colour;
                chkMMClockTitle.Checked = igs.ShowType;
                clrbtnMMClockTitle.Color = igs.TitleColor;
                clrbtnMMTime.Color = igs.MarkerColour;
                clrbtnMMDate.Color = igs.SubMarkerColour;
                radMM24Clock.Checked = igs.ShowMarker; // use the show marker bool for this
                if (!radMM24Clock.Checked && !radMM12Clock.Checked) radMM12Clock.Checked = true;
                updateTitleControlsClock();
            }
            else if (mt == MeterType.LED)
            {
                chkLedIndicator_FadeOnRX.Checked = igs.FadeOnRx;
                chkLedIndicator_FadeOnTX.Checked = igs.FadeOnTx;
                clrbtnLedIndicator_true.Color = igs.Colour;
                clrbtnLedIndicator_false.Color = igs.MarkerColour;

                clrbtnLedIndicator_PanelBackground.Color = igs.TitleColor;
                clrbtnLedIndicator_PanelBackgroundTX.Color = igs.HistoryColor;
                chkLedIndicator_ShowPanel.Checked = igs.ShowSubMarker;

                nudLedIndicator_xOffset.Value = (decimal)igs.EyeScale;
                nudLedIndicator_yOffset.Value = (decimal)igs.EyeBezelScale;
                nudLedIndicator_xSize.Value = (decimal)igs.AttackRatio;
                nudLedIndicator_ySize.Value = (decimal)igs.DecayRatio;
                nudLedIndicator_UpdateInterval.Value = (decimal)igs.UpdateInterval;

                txtLedIndicator_condition.Text = igs.Text1;

                nudLedIndicator_PanelPadding.Value = (decimal)igs.SpacerPadding;

                chkLed_show_true.Checked = igs.PeakHold;
                chkLed_show_false.Checked = igs.ShowMarker;
                switch(igs.IgnoreHistoryDuration)
                {
                    case 0:
                        radLed_light_on_off.Checked = true;
                        break;
                    case 1:
                        radLed_light_blink.Checked = true;
                        break;
                    case 2:
                        radLed_light_pulsate.Checked = true;
                        break;
                }

                chkLed_notx_true.Checked = igs.GetSetting<bool>("led_notx_true", false, false, false, false);
                chkLed_notx_false.Checked = igs.GetSetting<bool>("led_notx_false", false, false, false, false);

                updateLedIndicatorPanelControls();
                updateLedValidControls();
            }
            else if (mt == MeterType.TEXT_OVERLAY)
            {
                chkTextOverlay_FadeOnRX.Checked = igs.FadeOnRx;
                chkTextOverlay_FadeOnTX.Checked = igs.FadeOnTx;
                clrbtnTextOverlay_TextColour1.Color = igs.Colour;
                clrbtnTextOverlay_TextColour2.Color = igs.MarkerColour;
                clrbtnTextOverlay_TextBackColour1.Color = igs.SubMarkerColour;
                chkTextOverlay_textback1.Checked = igs.ShowMarker;
                clrbtnTextOverlay_TextBackColour2.Color = igs.PeakValueColour;
                chkTextOverlay_textback2.Checked = igs.ShowType;

                clrbtnTextOverlay_PanelBackground.Color = igs.TitleColor;
                clrbtnTextOverlay_PanelBackgroundTX.Color = igs.HistoryColor;
                chkTextOverlay_ShowPanel.Checked = igs.ShowSubMarker;

                nudTextOverlay_RXxOffset.Value = (decimal)igs.EyeScale;
                nudTextOverlay_RXyOffset.Value = (decimal)igs.EyeBezelScale;
                nudTextOverlay_TXxOffset.Value = (decimal)igs.AttackRatio;
                nudTextOverlay_TXyOffset.Value = (decimal)igs.DecayRatio;

                txtTextOverlay_RXText.Text = igs.Text1;
                txtTextOverlay_TXText.Text = igs.Text2;

                _textOverlayFont1 = new Font(igs.FontFamily1, igs.FontSize1, igs.FontStyle1);
                _textOverlayFont2 = new Font(igs.FontFamily2, igs.FontSize2, igs.FontStyle2);

                nudTextOverlay_PanelPadding.Value = (decimal)igs.SpacerPadding;

                updateTextOverlayPanelControls();
                updateTextOverlayBackTextControls();
            }
            else if (mt == MeterType.SPACER)
            {
                clrbtnMeterItemHBackgroundSpacerRX.Color = igs.Colour;
                clrbtnMeterItemHBackgroundSpacerTX.Color = igs.MarkerColour;
                chkMeterItemFadeOnRxSpacer.Checked = igs.FadeOnRx;
                chkMeterItemFadeOnTxSpacer.Checked = igs.FadeOnTx;
                nudMeterItemSpacerPadding.Value = (decimal)igs.SpacerPadding;
            }
            else
            {
                clrbtnMeterItemLow.Color = igs.LowColor;
                clrbtnMeterItemHigh.Color = igs.HighColor;
                clrbtnMeterItemIndicator.Color = igs.MarkerColour;
                clrbtnMeterItemSubIndicator.Color = igs.SubMarkerColour;
                chkMeterItemShowIndicator.Checked = igs.ShowMarker;
                chkMeterItemShowSubIndicator.Checked = igs.ShowSubMarker;
                clrbtnMeterItemHBackground.Color = igs.Colour;
                nudMeterItemUpdateRate.Value = igs.UpdateInterval < nudMeterItemUpdateRate.Minimum ? nudMeterItemUpdateRate.Minimum : igs.UpdateInterval;
                nudMeterItemAttackRate.Value = (decimal)igs.AttackRatio;
                nudMeterItemDecayRate.Value = (decimal)igs.DecayRatio;

                updateHistoryControls(igs.ShowHistory, igs.HistoryColor, igs.ShowHistory);
                nudMeterItemHistoryDuration.Value = igs.HistoryDuration < nudMeterItemHistoryDuration.Minimum ? nudMeterItemHistoryDuration.Minimum : igs.HistoryDuration;

                if (igs.BarStyle == MeterManager.clsBarItem.BarStyle.Segments)
                    chkMeterItemSegmented.Checked = true; // will cause solid to turn off
                else if (igs.BarStyle == MeterManager.clsBarItem.BarStyle.SolidFilled)
                    chkMeterItemSolid.Checked = true; // will cause segment to turn off
                else
                {
                    chkMeterItemSegmented.Checked = false;
                    chkMeterItemSolid.Checked = false;
                }

                clrbtnMeterItemSegmentedSolidColourLow.Color = igs.SegmentedSolidLowColour;
                clrbtnMeterItemSegmentedSolidColourHigh.Color = igs.SegmentedSolidHighColour;
                updateSegmentedSolidControls();

                updatePeakHoldControls(igs.PeakHold, igs.PeakHoldMarkerColor, igs.PeakHold);

                chkMeterItemShadow.Checked = igs.Shadow;
                chkMeterItemFadeOnRx.Checked = igs.FadeOnRx;
                chkMeterItemFadeOnTx.Checked = igs.FadeOnTx;
                chkMeterItemTitle.Checked = igs.ShowType;

                clrbtnMeterItemMeterTitle.Color = igs.TitleColor;
                updateTitleControls();

                chkMeterItemPeakValue.Checked = igs.PeakValue;
                clrbtnMeterItemPeakValueColour.Color = igs.PeakValueColour;
                updatePeakValueControls();

                if (mt == MeterType.CROSS || mt == MeterType.ANANMM || mt == MeterType.PWR || mt == MeterType.REVERSE_PWR) nudMeterItemsPowerLimit.Value = (decimal)igs.MaxPower;
                if (mt == MeterType.CROSS || mt == MeterType.ANANMM) clrbtnMeterItemPowerScale.Color = igs.PowerScaleColour;

                // specific to mt
                bool bMagicEye = mt == MeterType.MAGIC_EYE;
                if (bMagicEye)
                {
                    nudMeterItemEyeScale.Value = (decimal)igs.EyeScale; // prevents setting it to 0 as other items will have 0 //FIX THIS
                    nudMeterItemEyeBezelScale.Value = (decimal)igs.EyeBezelScale;
                }
                nudMeterItemEyeScale.Enabled = bMagicEye;
                nudMeterItemEyeBezelScale.Enabled = bMagicEye;
                lblMMEyeSize.Enabled = bMagicEye;
                lblMMEyeBezelSize.Enabled = bMagicEye;
                lblMMHistory.Enabled = !bMagicEye;
                nudMeterItemHistoryDuration.Enabled = !bMagicEye;
                lblMMHistoryIgnore.Enabled = !bMagicEye;
                nudMeterItemIgnoreHistoryDuration.Enabled = !bMagicEye;
                chkMeterItemHistory.Enabled = !bMagicEye;
                clrbtnMeterItemHistory.Enabled = !bMagicEye && chkMeterItemHistory.Checked;
                chkMeterItemPeakHold.Enabled = !(bMagicEye || mt == MeterType.CROSS);
                clrbtnMeterItemPeakHold.Enabled = !(bMagicEye || mt == MeterType.CROSS) && chkMeterItemPeakHold.Checked;

                chkMeterItemShadow.Enabled = mt == MeterType.ANANMM || mt == MeterType.CROSS;
                chkMeterItemDarkMode.Enabled = mt == MeterType.ANANMM || mt == MeterType.CROSS;

                lblMMPowerLimit.Enabled = mt == MeterType.ANANMM || mt == MeterType.CROSS;
                clrbtnMeterItemPowerScale.Enabled = mt == MeterType.ANANMM || mt == MeterType.CROSS;

                nudMeterItemsPowerLimit.Enabled = mt == MeterType.ANANMM || mt == MeterType.CROSS || mt == MeterType.PWR || mt == MeterType.REVERSE_PWR;

                bool bEnable = mt == MeterType.ANANMM || mt == MeterType.CROSS || mt == MeterType.MAGIC_EYE;
                chkMeterItemSegmented.Enabled = !bEnable;
                chkMeterItemSolid.Enabled = !bEnable;

                clrbtnMeterItemSegmentedSolidColourLow.Enabled = !bEnable && (chkMeterItemSegmented.Checked || chkMeterItemSolid.Checked);
                clrbtnMeterItemSegmentedSolidColourHigh.Enabled = !bEnable && (chkMeterItemSegmented.Checked || chkMeterItemSolid.Checked);
                lblMMsegSolLow.Enabled = !bEnable && (chkMeterItemSegmented.Checked || chkMeterItemSolid.Checked);
                lblMMsegSolHigh.Enabled = !bEnable && (chkMeterItemSegmented.Checked || chkMeterItemSolid.Checked);

                chkMeterItemTitle.Enabled = !bEnable;
                clrbtnMeterItemMeterTitle.Enabled = !bEnable;
                chkMeterItemPeakValue.Enabled = !bEnable;
                clrbtnMeterItemPeakValueColour.Enabled = !bEnable;
                lblMMLow.Enabled = !bEnable;
                lblMMHigh.Enabled = !bEnable;
                lblMMBackground.Enabled = !bEnable;
                clrbtnMeterItemLow.Enabled = !bEnable;
                clrbtnMeterItemHigh.Enabled = !bEnable;
                clrbtnMeterItemHBackground.Enabled = !bEnable;
                chkMeterItemShowIndicator.Enabled = !bEnable;
                //
                lblMMIndicatorSub.Enabled = igs.SubIndicators;
                clrbtnMeterItemSubIndicator.Enabled = igs.SubIndicators;
                chkMeterItemShowSubIndicator.Enabled = !bEnable && igs.SubIndicators;
                //

                chkMeterItemSignalAverage.Enabled = mt == MeterType.ANANMM || mt == MeterType.MAGIC_EYE;
                if (mt == MeterType.ANANMM || mt == MeterType.MAGIC_EYE) chkMeterItemSignalAverage.Checked = igs.Average;
                if (mt == MeterType.ANANMM || mt == MeterType.CROSS) chkMeterItemDarkMode.Checked = igs.DarkMode;
                //
            }
            
            setupMMSettingsGroupBoxes(mt);

            _ignoreMeterItemChangeEvents = false;
        }
        private void updateHistoryControls(bool showHistory, Color c, bool updateColor = false)
        {
            chkMeterItemHistory.Checked = showHistory;
            clrbtnMeterItemHistory.Enabled = showHistory;
            tbMeterItemHistoryAlpha.Enabled = showHistory;

            if (updateColor)
            {
                tbMeterItemHistoryAlpha.Value = c.A;
                clrbtnMeterItemHistory.Color = Color.FromArgb(255, c);
            }
        }
        private void updateSegmentedSolidControls()
        {
            bool bEnabled = chkMeterItemSegmented.Checked || chkMeterItemSolid.Checked;
            clrbtnMeterItemSegmentedSolidColourLow.Enabled = bEnabled;
            clrbtnMeterItemSegmentedSolidColourHigh.Enabled = bEnabled;
            lblMMsegSolLow.Enabled = bEnabled;
            lblMMsegSolHigh.Enabled = bEnabled;
        }
        private void updateTitleControls()
        {
            clrbtnMeterItemMeterTitle.Enabled = chkMeterItemTitle.Checked;
        }
        private void updateTitleControlsClock()
        {
            clrbtnMMClockTitle.Enabled = chkMMClockTitle.Checked;
        }
        private void updatePeakValueControls()
        {
            clrbtnMeterItemPeakValueColour.Enabled = chkMeterItemPeakValue.Checked;
        }
        private void updatePeakHoldControls(bool showPeakHold, Color c, bool updateColor = false)
        {
            chkMeterItemPeakHold.Checked = showPeakHold;
            clrbtnMeterItemPeakHold.Enabled = showPeakHold;

            if (updateColor)
            {
                clrbtnMeterItemPeakHold.Color = Color.FromArgb(255, c);
            }
        }

        private void clrbtnMeterItemHistory_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void tbMeterItemHistoryAlpha_Scroll(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkMeterItemFadeOnRx_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkMeterItemFadeOnTx_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkMeterItemSegmented_CheckedChanged(object sender, EventArgs e)
        {
            if (chkMeterItemSegmented.Checked) chkMeterItemSolid.Checked = false; // can only be one

            updateSegmentedSolidControls();
            updateMeterType();
        }

        private void chkMeterItemTitle_CheckedChanged(object sender, EventArgs e)
        {
            updateTitleControls();
            updateMeterType();
        }

        private void chkMeterItemPeakValue_CheckedChanged(object sender, EventArgs e)
        {
            updatePeakValueControls();
            updateMeterType();
        }

        private void chkMeterItemPeakHold_CheckedChanged(object sender, EventArgs e)
        {
            bool bEnabled = chkMeterItemPeakHold.Checked;

            updatePeakHoldControls(bEnabled, Color.Red, false);

            updateMeterType();
        }

        private void clrbtnMeterItemPeakHold_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudMeterItemHistoryDuration_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudMeterItemUpdateRate_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudMeterItemAttackRate_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudMeterItemDecayRate_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkMeterItemShadow_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMeterItemLow_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMeterItemHigh_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }
        private void clrbtnMeterItemHBackground_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }
        private void clrbtnMeterItemMeterTitle_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMeterItemPeakValueColour_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudMeterItemEyeScale_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkMeterItemSignalAverage_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkMeterItemDarkMode_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkMaintainNFAdjustDeltaRX2_CheckedChanged(object sender, EventArgs e)
        {
            console.MaintainNFAdjustDeltaRX2 = chkMaintainNFAdjustDeltaRX2.Checked;
        }

        private void chkMaintainNFAdjustDeltaRX1_CheckedChanged(object sender, EventArgs e)
        {
            console.MaintainNFAdjustDeltaRX1 = chkMaintainNFAdjustDeltaRX1.Checked;
        }

        private void chkContainerBorder_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            clsContainerComboboxItem cci = (clsContainerComboboxItem)comboContainerSelect.SelectedItem;
            if (cci != null)
            {
                MeterManager.ContainerBorder(cci.ID, chkContainerBorder.Checked);
            }
        }

        private void clrbtnContainerBackground_Changed(object sender, EventArgs e)
        {
            if (initializing) return;
            clsContainerComboboxItem cci = (clsContainerComboboxItem)comboContainerSelect.SelectedItem;
            if (cci != null)
            {
                MeterManager.ContainerBackgroundColour(cci.ID, clrbtnContainerBackground.Color);
            }
        }

        private void nudMeterItemsPowerLimit_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkMeterItemSolid_CheckedChanged(object sender, EventArgs e)
        {
            if (chkMeterItemSolid.Checked) chkMeterItemSegmented.Checked = false; // can only be one

            updateSegmentedSolidControls();
            updateMeterType();
        }

        private void clrbtnMeterItemSegmentedSolidColourHigh_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMeterItemSegmentedSolidColourLow_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkMeterItemShowIndicator_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkMeterItemShowSubIndicator_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }
        private void setupMMSettingsGroupBoxes(MeterType mt)
        {
            // grpMeterItemSettings defines the x,y used by all
            Point loc = grpMeterItemSettings.Location;

            grpMeterItemSettings.Visible = false;
            grpMeterItemClockSettings.Visible = false;
            grpMeterItemVfoDisplaySettings.Visible = false;
            grpMeterItemSpacerSettings.Visible = false;
            grpTextOverlay.Visible = false;
            grpMeterItemDataOutNode.Visible = false;
            grpMeterItemRotator.Visible = false;
            grpLedIndicator.Visible = false;
            grpWebImage.Visible = false;
            grpBandButtons.Visible = false;
            pnlButtonBox_antenna_toggles.Visible = false;
            grpHistoryItem.Visible = false;

            switch (mt)
            {
                case MeterType.NONE:
                    break;
                case MeterType.VFO_DISPLAY:
                    grpMeterItemVfoDisplaySettings.Parent = grpMultiMeterHolder;
                    grpMeterItemVfoDisplaySettings.Location = loc;
                    grpMeterItemVfoDisplaySettings.Visible = true;
                    break;
                case MeterType.CLOCK:
                    grpMeterItemClockSettings.Parent = grpMultiMeterHolder;
                    grpMeterItemClockSettings.Location = loc;
                    grpMeterItemClockSettings.Visible = true;
                    break;
                case MeterType.SPACER:
                    grpMeterItemSpacerSettings.Parent = grpMultiMeterHolder;
                    grpMeterItemSpacerSettings.Location = loc;
                    grpMeterItemSpacerSettings.Visible = true;
                    break;
                case MeterType.TEXT_OVERLAY:
                    grpTextOverlay.Parent = grpMultiMeterHolder;
                    grpTextOverlay.Location = loc;
                    grpTextOverlay.Visible = true;
                    break;
                case MeterType.DATA_OUT:
                    grpMeterItemDataOutNode.Parent = grpMultiMeterHolder;
                    grpMeterItemDataOutNode.Location = loc;
                    grpMeterItemDataOutNode.Visible = true;
                    break;
                case MeterType.ROTATOR:
                    grpMeterItemRotator.Parent = grpMultiMeterHolder;
                    grpMeterItemRotator.Location = loc;
                    grpMeterItemRotator.Visible = true;
                    break;
                case MeterType.LED:
                    grpLedIndicator.Parent = grpMultiMeterHolder;
                    grpLedIndicator.Location = loc;
                    grpLedIndicator.Visible = true;
                    break;
                case MeterType.WEB_IMAGE:
                    grpWebImage.Parent = grpMultiMeterHolder;
                    grpWebImage.Location = loc;
                    grpWebImage.Visible = true;
                    comboWebImage_HamQsl.SelectedIndex = 0;
                    comboWebImage_BsdWorld.SelectedIndex = 0;
                    comboWebImage_nasa.SelectedIndex = 0;
                    comboWebImage_noaa.SelectedIndex = 0;
                    break;
                case MeterType.TUNESTEP_BUTTONS:
                case MeterType.ANTENNA_BUTTONS:
                case MeterType.FILTER_BUTTONS:
                case MeterType.MODE_BUTTONS:
                case MeterType.BAND_BUTTONS:
                case MeterType.DISCORD_BUTTONS:
                    {
                        clrbtnButonBox_fontcolour.Visible = mt != MeterType.ANTENNA_BUTTONS;
                        grpBandButtons.Parent = grpMultiMeterHolder;
                        grpBandButtons.Location = loc;
                        grpBandButtons.Visible = true;

                        switch (mt)
                        {
                            case MeterType.ANTENNA_BUTTONS:
                                pnlButtonBox_antenna_toggles.Parent = grpBandButtons;
                                pnlButtonBox_antenna_toggles.Location = new Point(166, 194);
                                pnlButtonBox_antenna_toggles.Visible = true;
                                ucTunestepOptionsGrid_buttons.Visible = false;
                                break;
                            case MeterType.TUNESTEP_BUTTONS:
                                ucTunestepOptionsGrid_buttons.Parent = grpBandButtons;
                                ucTunestepOptionsGrid_buttons.Location = new Point(166, 194);
                                ucTunestepOptionsGrid_buttons.Visible = true;
                                pnlButtonBox_antenna_toggles.Visible = false;
                                if(console != null)
                                {
                                    ucTunestepOptionsGrid_buttons.Init(console.TuneStepList);
                                }
                                break;
                            default:
                                pnlButtonBox_antenna_toggles.Visible = false;
                                ucTunestepOptionsGrid_buttons.Visible = false;
                                break;
                        }
                    }
                    break;
                case MeterType.HISTORY:
                    grpHistoryItem.Parent = grpMultiMeterHolder;
                    grpHistoryItem.Location = loc;
                    grpHistoryItem.Visible = true;
                    break;
                default:
                    grpMeterItemSettings.Parent = grpMultiMeterHolder;
                    grpMeterItemSettings.Visible = true;
                    break;
            }
        }

        private void radMM12Clock_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void radMM24Clock_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkMMClockTitle_CheckedChanged(object sender, EventArgs e)
        {
            updateTitleControlsClock();
            updateMeterType();
        }

        private void clrbtnMMClockTitle_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMMTime_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMMDate_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMMClockBackground_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMMVfoDisplayBackground_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMMVfoDisplayTitle_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMMVfoDisplayFrequency_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMMVfoDisplayMode_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMMVfoDisplaySplitBack_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMMVfoDisplaySplit_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMMVfoDisplayRx_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMMVfoDisplayTx_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMMVfoDisplayFilter_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMMVfoDisplayBand_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudMeterItemEyeBezelScale_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMeterItemPowerScale_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudMeterItemIgnoreHistoryDuration_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private MeterManager.clsIGSettings _itemGroupSettings = null;
        private MeterType _itemGroupSettingsMeterType = MeterType.NONE;

        private void btnMeterCopySettings_Click(object sender, EventArgs e)
        {
            clsMeterTypeComboboxItem mtci = lstMetersInUse.SelectedItem as clsMeterTypeComboboxItem;
            if (mtci == null) return;

            MeterManager.clsMeter m = meterFromSelectedContainer();
            if (m == null) return;

            MeterType mt = meterItemGroupTypefromSelected();
            if (mt == MeterType.NONE) return;

            // copy settings into igs
            _itemGroupSettings = m.GetSettingsForMeterGroup(mt, mtci.Order);
            if (_itemGroupSettings != null)
                _itemGroupSettingsMeterType = meterItemGroupTypefromSelected();
            else
                _itemGroupSettingsMeterType = MeterType.NONE;
        }

        private void btnMeterPasteSettings_Click(object sender, EventArgs e)
        {
            if (_itemGroupSettings == null || _itemGroupSettingsMeterType == MeterType.NONE) return;

            clsMeterTypeComboboxItem mtci = lstMetersInUse.SelectedItem as clsMeterTypeComboboxItem;
            if (mtci == null) return;

            MeterManager.clsMeter m = meterFromSelectedContainer();
            if (m == null) return;

            MeterType mt = meterItemGroupTypefromSelected();
            if (mt == MeterType.NONE) return;

            if (canPasteSettings())
            {
                // ignore some things [2.10.1.0] MW0LGE - fixes issue where bar with change units is paste into new bar, and source bars have no sub indicator
                MeterManager.clsIGSettings currentSettings = m.GetSettingsForMeterGroup(mt, mtci.Order);

                // prevent overwrite of the following
                _itemGroupSettings.Unit = currentSettings.Unit;

                if (!_itemGroupSettings.SubIndicators)
                {
                    // no sub indicators on the source, replace with current so we end up with no change on the paste
                    _itemGroupSettings.ShowSubMarker = currentSettings.ShowMarker;
                    _itemGroupSettings.ShowSubMarker = currentSettings.ShowSubMarker;
                    _itemGroupSettings.SubMarkerColour = currentSettings.SubMarkerColour;
                }

                if(mt == MeterType.TUNESTEP_BUTTONS)
                {
                    _itemGroupSettings.SetSetting<int>("buttonbox_tunestep_bitfield", currentSettings.GetSetting<int>("buttonbox_tunestep_bitfield", true, 0, int.MaxValue, 0));
                }
                else if (mt == MeterType.ANTENNA_BUTTONS)
                {
                    _itemGroupSettings.SetSetting<bool>("buttonbox_rx1", currentSettings.GetSetting<bool>("buttonbox_rx1", false, false, false, true));
                    _itemGroupSettings.SetSetting<bool>("buttonbox_rx2", currentSettings.GetSetting<bool>("buttonbox_rx2", false, false, false, true));
                    _itemGroupSettings.SetSetting<bool>("buttonbox_rx3", currentSettings.GetSetting<bool>("buttonbox_rx3", false, false, false, true));
                    _itemGroupSettings.SetSetting<bool>("buttonbox_tx1", currentSettings.GetSetting<bool>("buttonbox_tx1", false, false, false, true));
                    _itemGroupSettings.SetSetting<bool>("buttonbox_tx2", currentSettings.GetSetting<bool>("buttonbox_tx2", false, false, false, true));
                    _itemGroupSettings.SetSetting<bool>("buttonbox_tx3", currentSettings.GetSetting<bool>("buttonbox_tx3", false, false, false, true));
                    _itemGroupSettings.SetSetting<bool>("buttonbox_byp", currentSettings.GetSetting<bool>("buttonbox_byp", false, false, false, true));
                    _itemGroupSettings.SetSetting<bool>("buttonbox_ext1", currentSettings.GetSetting<bool>("buttonbox_ext1", false, false, false, true));
                    _itemGroupSettings.SetSetting<bool>("buttonbox_xvtr", currentSettings.GetSetting<bool>("buttonbox_xvtr", false, false, false, true));
                    _itemGroupSettings.SetSetting<bool>("buttonbox_rxtxant", currentSettings.GetSetting<bool>("buttonbox_rxtxant", false, false, false, true));
                }
                //

                m.ApplySettingsForMeterGroup(mt, _itemGroupSettings, mtci.Order);
                updateItemSettingsControlsForSelected();
            }
        }
        private bool canPasteSettings()
        {
            if (_itemGroupSettings == null || _itemGroupSettingsMeterType == MeterType.NONE) return false;

            MeterManager.clsMeter m = meterFromSelectedContainer();
            if (m == null) return false;

            MeterType mt = meterItemGroupTypefromSelected();
            if (mt == MeterType.NONE) return false;

            bool bPaste;

            // only allow paste into matching
            if (mt == MeterType.MAGIC_EYE || mt == MeterType.CROSS ||
                mt == MeterType.ANANMM || mt == MeterType.SIGNAL_TEXT ||
                mt == MeterType.SPACER || mt == MeterType.TEXT_OVERLAY ||
                mt == MeterType.LED || mt == MeterType.ROTATOR || mt == MeterType.HISTORY ||
                mt == MeterType.VFO_DISPLAY || mt == MeterType.CLOCK
                )
            {
                bPaste = _itemGroupSettingsMeterType == mt;
            }
            else if (_itemGroupSettingsMeterType == MeterType.MAGIC_EYE || _itemGroupSettingsMeterType == MeterType.CROSS ||
                _itemGroupSettingsMeterType == MeterType.ANANMM || _itemGroupSettingsMeterType == MeterType.SIGNAL_TEXT ||
                _itemGroupSettingsMeterType == MeterType.SPACER || _itemGroupSettingsMeterType == MeterType.TEXT_OVERLAY ||
                _itemGroupSettingsMeterType == MeterType.LED || mt == MeterType.ROTATOR || mt == MeterType.HISTORY ||
                _itemGroupSettingsMeterType == MeterType.VFO_DISPLAY || _itemGroupSettingsMeterType == MeterType.CLOCK
                )
            {
                bPaste = mt == _itemGroupSettingsMeterType;
            }
            else
            {
                bPaste = true;
            }

            return bPaste;
        }
        public void ShowMultiMeterSetupTab(string sID = "")
        {
            // show multimeter tab, with meter container already selected if sID is provided
            if (sID != "" && comboContainerSelect.Items.Count > 0)
            {
                for (int n = 0; n < comboContainerSelect.Items.Count; n++)
                {
                    clsContainerComboboxItem cci = comboContainerSelect.Items[n] as clsContainerComboboxItem;
                    if (cci != null && cci.ID == sID)
                    {
                        comboContainerSelect.SelectedIndex = n;
                        break;
                    }
                }
            }

            Show();
            Focus();
            WindowState = FormWindowState.Normal;
            TabSetup.SelectedIndex = 6; // appearance
            TabAppearance.SelectedIndex = 3; // multimeter
        }
        #endregion

        #region VoiceSQL
        private void udVSQLMuteTimeConstant_ValueChanged(object sender, EventArgs e)
        {
            if (console == null || console.radio == null) return;

            float fSeconds = (float)udVSQLMuteTimeConstant.Value / 1000f;

            //rx1
            console.radio.GetDSPRX(0, 0).SqlMuteTimeConstant = fSeconds;
            console.radio.GetDSPRX(0, 1).SqlMuteTimeConstant = fSeconds;

            //rx2
            console.radio.GetDSPRX(1, 0).SqlMuteTimeConstant = fSeconds;
            console.radio.GetDSPRX(1, 1).SqlMuteTimeConstant = fSeconds;
        }

        private void udVSQLUnMuteTimeConstant_ValueChanged(object sender, EventArgs e)
        {
            if (console == null || console.radio == null) return;

            float fSeconds = (float)udVSQLUnMuteTimeConstant.Value / 1000f;

            //rx1
            console.radio.GetDSPRX(0, 0).SqlUnMuteTimeConstant = fSeconds;
            console.radio.GetDSPRX(0, 1).SqlUnMuteTimeConstant = fSeconds;

            //rx2
            console.radio.GetDSPRX(1, 0).SqlUnMuteTimeConstant = fSeconds;
            console.radio.GetDSPRX(1, 1).SqlUnMuteTimeConstant = fSeconds;
        }

        private void chkConsoleDarkModeTitleBar_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (console != null)
            {
                bool bOk = Common.UseImmersiveDarkMode(console.Handle, chkConsoleDarkModeTitleBar.Checked);
                if (sender != this && bOk) console.Invalidate();
            }
        }
        #endregion

        #region USB/BCD Cable
        //[2.10.3.5]MW0LGE re-write, fixes #222
        private UsbBCDDevices m_usbbcddevices;
        private bool m_bUsbBCD = false;
        private string m_sUsbBCDSerialNumber = "";
        private bool m_bUsbBCDdeviceOpen = false;
        public bool UsbBCD
        {
            get { return m_bUsbBCD; }
            set { m_bUsbBCD = value; }
        }
        private void OnBCDBandChangeHandler(int rx, Band old_band, Band new_band)
        {
            if (initializing) return;
            if (rx == 1) updateUsbBCDdevice(new_band);
        }
        private void updateUsbBCDdevice(Band rx1band)
        {
            try
            {
                if (m_bUsbBCD && m_usbbcddevices != null && m_sUsbBCDSerialNumber != "" && m_bUsbBCDdeviceOpen)
                    m_usbbcddevices.SetBCDbyBand(m_sUsbBCDSerialNumber, rx1band);
            }
            catch { }
        }
        private void chkUsbBCD_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            m_bUsbBCD = chkUsbBCD.Checked;
            comboUsbDevices.Enabled = m_bUsbBCD;

            if (!m_bUsbBCD)
            {
                // close current
                CloseUsbBcdDevice();

                // clear all
                comboUsbDevices.Items.Clear();
                m_sUsbBCDSerialNumber = "";
                m_usbbcddevices = null;

                return;
            }

            if (m_bUsbBCD)
            {
                if (m_usbbcddevices == null)
                {
                    comboUsbDevices.Items.Clear(); // not needed  but belts/braces
                    try
                    {
                        m_usbbcddevices = new UsbBCDDevices();

                        foreach (string s in m_usbbcddevices.DeviceSerialNumbers)
                        {
                            comboUsbDevices.Items.Add(s);
                        }

                        if (comboUsbDevices.Items.Contains(m_sUsbBCDSerialNumber))
                            comboUsbDevices.SelectedIndex = comboUsbDevices.Items.IndexOf(m_sUsbBCDSerialNumber);
                    }
                    catch
                    {
                        chkUsbBCD.Checked = false;
                        return;
                    }
                }
            }
        }
        public void CloseUsbBcdDevice()
        {
            if (m_usbbcddevices != null && m_sUsbBCDSerialNumber != "" && m_bUsbBCDdeviceOpen)
            {
                try
                {
                    m_usbbcddevices.SetRelays(m_sUsbBCDSerialNumber, 0);
                }
                catch { }
                try
                {
                    m_usbbcddevices.CloseDevice(m_sUsbBCDSerialNumber);
                }
                catch { }
            }
            m_bUsbBCDdeviceOpen = false;
        }
        private void comboUsbDevices_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (m_usbbcddevices == null) return;

            if (m_bUsbBCDdeviceOpen && comboUsbDevices.Text != m_sUsbBCDSerialNumber)
            {
                // a device is open, but the one we now want is different, close current
                CloseUsbBcdDevice();
            }

            m_sUsbBCDSerialNumber = comboUsbDevices.Text;

            if (m_sUsbBCDSerialNumber != "")
            {
                bool bOk = true;

                if (!m_bUsbBCDdeviceOpen)
                {
                    try
                    {
                        m_usbbcddevices.OpenDevice(m_sUsbBCDSerialNumber);
                        m_bUsbBCDdeviceOpen = true;
                    }
                    catch { bOk = false; }
                }

                if (bOk && m_bUsbBCDdeviceOpen)
                {
                    try
                    {
                        byte values = m_usbbcddevices.GetRelays(m_sUsbBCDSerialNumber);
                    }
                    catch { bOk = false; }

                    try
                    {
                        m_usbbcddevices.SetBCDbyBand(m_sUsbBCDSerialNumber, console.RX1Band);
                    }
                    catch { bOk = false; }
                }

                if (!bOk)
                {
                    chkUsbBCD.Checked = false;
                    return;
                }
            }
        }
        #endregion

        private bool _timerCheckingTXProfile = false; //[2.10.3.5]MW0LGE used to bypass changed events caused
                                                      //by checkTXProfileChanged2() in tmrCheckProfile_Tick() reading values fix #301
        private void tmrCheckProfile_Tick(object sender, EventArgs e)
        {
            if (!this.Visible || _savingOptions || _gettingOptions) return;

            tmrCheckProfile.Enabled = false;

            _timerCheckingTXProfile = true;
            bool bChanged = checkTXProfileChanged2();
            _timerCheckingTXProfile = false;

            lblTXProfileWarning.Visible = !console.RXOnly && bChanged;

            if (bChanged && txtboxTXProfileChangedReport.Visible)
                lblTXProfileWarning_Click(this, e);
            else
                txtboxTXProfileChangedReport.Visible = false;

            tmrCheckProfile.Enabled = true;
        }

        private void btnClearTCISpots_Click(object sender, EventArgs e)
        {
            SpotManager2.ClearAllSpots();
        }

        public bool QuickSplitEnabled
        {
            get { return chkQuickSplit.Checked; }
            set { chkQuickSplit.Checked = value; }
        }
        public int QuickSplitShiftHz
        {
            get { return (int)nudQuickSplitShift.Value; }
            set { nudQuickSplitShift.Value = (decimal)value; }
        }
        public bool QuickSplitZoom
        {
            get { return chkQuickSplitZoom.Checked; }
        }
        public bool QuickSplitMultiRX
        {
            get { return chkQuickSplitMultiRX.Checked; }
        }
        public bool QuickSplitFL
        {
            get { return chkQuickSplitFL.Checked; }
        }
        public bool QuickSplitSwapVFOWheels
        {
            get { return chkQuickSplitSwapVFOWheels.Checked; }
        }
        public bool QuickSplitPanAudio
        {
            get { return chkQuickSplitPanAudio.Checked; }
        }
        public bool QuickSplitPanAudioFlip
        {
            get { return chkQuickSplitPanAudio.Checked && chkQuickSplitPanAudioFlip.Checked; }
        }
        public bool SplitFromCATorTCIcancelsQSPLIT
        {
            get { return chkCancelQSplitOnCatTCIsplit.Checked; }
        }
        private void chkQuickSplit_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;

            grpQuickSplit.Enabled = chkQuickSplit.Checked;
            console.SetQuickSplit();
        }

        private void btnQuickSplitDown5_Click(object sender, EventArgs e)
        {
            QuickSplitShiftHz = -5000;
        }

        private void btnQuickSplitUp5_Click(object sender, EventArgs e)
        {
            QuickSplitShiftHz = 5000;
        }

        private void chkLinkRX0AF_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;

            console.SetAFLinks(1, chkLinkRX0AF.Checked);
        }

        private void chkLinkRX1AF_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;

            console.SetAFLinks(2, chkLinkRX1AF.Checked);
        }

        private void chkLinkRX2AF_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;

            console.SetAFLinks(3, chkLinkToRX2AF.Checked);
        }

        private void chkLinkMaster_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;

            console.SetAFLinks(0, chkLinkMaster.Checked);
        }

        private void chkLegacyMeters_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;

            console.UseLegacyMeters = chkLegacyMeters.Checked;
        }

        private void radSpaceBarVFOBTX_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;

            console.SpaceBarVFOBTX = radSpaceBarVFOBTX.Checked;
        }

        private void lblTXProfileWarning_Click(object sender, EventArgs e)
        {
            if (_savingOptions || _gettingOptions) return;
            if (e != EventArgs.Empty && txtboxTXProfileChangedReport.Visible)
            {
                txtboxTXProfileChangedReport.Visible = false;
                return;
            }

            string sReport = getTXProfileChangeReport();
            if (sReport != "")
            {
                txtboxTXProfileChangedReport.Text = "Modifications" + Environment.NewLine + Environment.NewLine + sReport;
                txtboxTXProfileChangedReport.Width = getTextBoxWidthForReport();
                txtboxTXProfileChangedReport.Location = new Point(this.ClientSize.Width - txtboxTXProfileChangedReport.Size.Width, 34);
                txtboxTXProfileChangedReport.Visible = true;
            }
            else
                txtboxTXProfileChangedReport.Visible = false;
        }

        private void chkQuickSplitPanAudio_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;

            chkQuickSplitPanAudioFlip.Enabled = chkQuickSplitPanAudio.Checked;
        }

        private int getTextBoxWidthForReport()
        {
            int maxWidth = 0;

            foreach (string line in txtboxTXProfileChangedReport.Lines)
            {
                int lineWidth = TextRenderer.MeasureText(line, txtboxTXProfileChangedReport.Font).Width;
                if (lineWidth > maxWidth)
                    maxWidth = lineWidth;
            }

            return maxWidth + SystemInformation.VerticalScrollBarWidth + 4;
        }

        private void chkJoinBandEdges_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;

            Display.JoinBandEdges = chkJoinBandEdges.Checked;
        }

        private void chkContainerNoTitle_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            clsContainerComboboxItem cci = (clsContainerComboboxItem)comboContainerSelect.SelectedItem;
            if (cci != null)
            {
                MeterManager.NoTitle(cci.ID, chkContainerNoTitle.Checked);
            }
        }

        private void chkAutoModeSwitchCWReturn_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            nudAutoModeSwitchCWReturn.Enabled = chkAutoModeSwitchCWReturn.Checked;
            lblAutoModeSwitchCWms.Enabled = chkAutoModeSwitchCWReturn.Checked;

            console.AutoModeSwitchCWReturn = chkAutoModeSwitchCWReturn.Checked;
            nudAutoModeSwitchCWReturn_ValueChanged(this, e);
        }
        private void setEnabledAutoModeSwitchCWReturn(bool bEnable)
        {
            chkAutoModeSwitchCWReturn.Enabled = bEnable;
            nudAutoModeSwitchCWReturn.Enabled = chkAutoModeSwitchCWReturn.Checked;
            lblAutoModeSwitchCWms.Enabled = chkAutoModeSwitchCWReturn.Checked;
        }
        private void nudAutoModeSwitchCWReturn_ValueChanged(object sender, EventArgs e)
        {
            console.AutoModeSwitchCWReturnMs = (int)nudAutoModeSwitchCWReturn.Value;
        }
        private void btnZipDebug_Click(object sender, EventArgs e)
        {
            buildZipFile(console.ProductVersion + "\n" + console.BasicTitleBar, console.AppDataPath);
        }
        private void buildZipFile(string version, string sourceDirectory)
        {
            string[] filesToZip = { "ErrorLog.txt", "VALog.txt" };
            string myDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.InitialDirectory = myDocumentsPath;
            saveFileDialog.Filter = "ZIP Files (*.zip)|*.zip";
            DateTime now = DateTime.Now;
            string formattedDate = now.ToString("MM-dd-yy_HHmmss");

            saveFileDialog.FileName = formattedDate + "_database_logs.zip";

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                string zipFilePath = saveFileDialog.FileName;

                try
                {
                    if (File.Exists(zipFilePath))
                        File.Delete(zipFilePath);

                    // Create the zip file
                    using (FileStream zipToOpen = new FileStream(zipFilePath, FileMode.Create))
                    {
                        using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Update))
                        {
                            // Add each file to the zip
                            foreach (string fileName in filesToZip)
                            {
                                string filePath = Path.Combine(sourceDirectory, fileName);

                                if (File.Exists(filePath))
                                {
                                    archive.CreateEntryFromFile(filePath, fileName);
                                }
                            }

                            // and now the db
                            string fullpath = DB.FileName;
                            if (File.Exists(fullpath))
                            {
                                string file_name = Path.GetFileName(fullpath);
                                archive.CreateEntryFromFile(fullpath, file_name);
                            }

                            // Add the version.txt entry
                            ZipArchiveEntry versionEntry = archive.CreateEntry("version.txt");

                            using (StreamWriter writer = new StreamWriter(versionEntry.Open()))
                            {
                                writer.Write(version);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Error: {ex.Message}", "Error building zip", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST);
                }
            }
        }
        public bool LogVA
        {
            get { return chkLogVoltsAmps.Checked; }
            set { chkLogVoltsAmps.Checked = value; }
        }
        private void chkLogVoltsAmps_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.LogVA = chkLogVoltsAmps.Checked;
        }
        public bool LinkAFSlidersOnlyIfCtrlHeld
        {
            get { return chkLinkIfCtrlHeld.Checked; }
            set
            {
                chkLinkIfCtrlHeld.Checked = value;
            }
        }

        private void tcAppearance_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;

            if (isSkinServerTabVisible())
            {
                getSkinServers();
            }
            else
            {
                hideAllSkinServerRelatedControls();
                ThetisSkinService.CancelDownload();
            }
        }
        private bool isSkinServerTabVisible(bool checkFormVisible = true)
        {
            if (checkFormVisible && !this.Visible) return false;
            int sel = tcSetup.SelectedIndex;
            if (sel == -1) return false;
            TabPage selectedTab = tcSetup.TabPages[sel];
            if (selectedTab.Name != "tpAppearance") return false;
            sel = tcAppearance.SelectedIndex;
            if (sel == -1) return false;
            selectedTab = tcAppearance.TabPages[sel];
            if (selectedTab.Name != "tpSkinServers") return false;

            return true;
        }
        private void getSkinServers()
        {
            hideAllSkinServerRelatedControls();
            panelGetServerList.Visible = true;

            comboSkinServerList.DataSource = null; // this will release server list objects from belonging to this control
                                                   // as it cant be cleared unless this happens
            comboSkinServerList.Items.Clear();
            lstAvailableSkins.DataSource = null; // this will release server list objects from belonging to this control
            lstAvailableSkins.Items.Clear();

            ThetisSkinService.GetSkinServers("https://raw.githubusercontent.com/ramdor/Thetis/master/skin_servers.json");
        }
        private void hideAllSkinServerRelatedControls()
        {
            // hides everything for the skin server tab
            panelSkinServerControls.Visible = false;
            panelGetServerList.Visible = false;
            gtpAvailableSkins.Visible = false;
            grpAuthorDetails.Visible = false;
            picSkinThumbnail.Image = null;
            prgSkinDownload.Visible = false;
        }
        private void skinDataReceivedHandler(object sender, SkinsData e)
        {
            if (e != null)
            {
                gtpAvailableSkins.Visible = true;
                grpAuthorDetails.Visible = true;

                lstAvailableSkins.DisplayMember = "SkinName";
                lstAvailableSkins.DataSource = e.ThetisSkins;

                if (e.AuthorNickname == "")
                    lblAuthorDetails1.Text = "Skins By " + e.AuthorName.Left(50);
                else
                    lblAuthorDetails1.Text = "Skins By " + e.AuthorNickname.Left(50);

                if (e.AuthorCallsign != "")
                    lblAuthorDetails2.Text = "Callsign : " + e.AuthorCallsign.Left(20);
                else
                    lblAuthorDetails2.Text = "";

                if (e.SkinsHomepageUrl != "" && Common.IsValidUri(e.SkinsHomepageUrl))
                {
                    btnSkinsHomepage.Visible = true;
                    btnSkinsHomepage.Tag = e.SkinsHomepageUrl.Left(1024);
                }
                else
                    btnSkinsHomepage.Visible = false;

                if (e.DonateUrl != "" && Common.IsValidUri(e.DonateUrl))
                {
                    btnSkinsDonate.Visible = true;
                    btnSkinsDonate.Tag = e.DonateUrl.Left(1024);
                }
                else
                    btnSkinsDonate.Visible = false;
            }
            else
            {
                grpAuthorDetails.Visible = false;
                gtpAvailableSkins.Visible = false;
                Debug.Print("no skins");
            }
        }
        private void updateSelectedSkin()
        {
            if (lstAvailableSkins.Items.Count == 0) return;

            chkReplaceCurrentMeterInSelectedSkin.Enabled = false;

            int sel = comboSkinServerList.SelectedIndex;
            if (sel == -1) return;

            SkinServer ss = comboSkinServerList.SelectedItem as SkinServer;
            if (ss == null) return;

            sel = lstAvailableSkins.SelectedIndex;
            if (sel == -1) return;

            ThetisSkin ts = lstAvailableSkins.Items[sel] as ThetisSkin;
            if (ts == null) return;

            if (ts.ThumbnailUrl != "" && Common.IsValidUri(ts.ThumbnailUrl))
            {
                if (Common.IsValidUri(ts.ThumbnailUrl))
                {
                    ThetisSkinService.LoadImageFromUrl(ts.ThumbnailUrl, "[" + ss.SkinServerUrl + "]_[" + ts.SkinName + "]");
                }
            }
            else
                picSkinThumbnail.Image = null;

            lblSkinVersion.Text = "Version: " + validateVersion(ts.SkinVersion);
            lblSkinThetisVersion.Text = "Min Thetis Version: " + validateVersion(ts.FromThetisVersion);
            lblSkinDateReleased.Text = "Release Date: " + validateDate(ts.DateReleased).Left(14);
            lblSkinOverview.Text = ts.SkinName + Environment.NewLine + ts.Overview.Left(1024);
            lblSkinMeters.Text = "Type: " + (ts.IsMeterSkin ? "MultiMeter Skin" : "Console Skin");

            chkReplaceCurrentMeterInSelectedSkin.Enabled = ts.IsMeterSkin;

            if (ts.SkinHomepageUrl != "" && Common.IsValidUri(ts.SkinHomepageUrl))
            {
                btnSkinHomepage.Visible = true;
                btnSkinHomepage.Tag = ts.SkinHomepageUrl.Left(1024);
            }
            else
                btnSkinHomepage.Visible = false;

            if (ts.SkinUrl != "" && Common.IsValidUri(ts.SkinUrl))
            {
                btnDownloadSkin.Tag = ts.SkinUrl.Left(1024);
                btnDownloadSkin.Enabled = Common.CompareVersions(ts.FromThetisVersion, Common.GetFileVersion()) <= 0;
            }
            else
            {
                btnDownloadSkin.Enabled = false;
            }
            btnDownloadSkin.Text = "Download";
        }
        private string validateDate(string sDate)
        {
            bool bOk = DateTime.TryParse(sDate, out DateTime tmp);

            return bOk ? sDate : "__/__/__";
        }
        private string validateVersion(string sVersion)
        {
            // can be X.X, X.X.X, or X.X.X.X  where X is +ve int
            string[] ss = sVersion.Split('.');

            if (ss.Length >= 2 && ss.Length <= 4)
            {
                bool bAllNums = true;
                foreach (string s in ss)
                {
                    if (!int.TryParse(s, out int tmp))
                    {
                        if (tmp >= 0)
                        {
                            bAllNums = false;
                            break;
                        }
                    }
                }
                if (bAllNums) return sVersion;
            }
            return "?";
        }
        private void skinServersDataReceivedHandler(object sender, SkinServersData e)
        {
            if (!isSkinServerTabVisible()) return;

            if (e != null)
            {
                if (e.SkinServers.Count > 0) {
                    panelGetServerList.Visible = false;
                    panelSkinServerControls.Visible = true;
                    grpAuthorDetails.Visible = false;

                    bIgnoreSkinServerListUpdate = true;
                    comboSkinServerList.DisplayMember = "Description";
                    comboSkinServerList.DataSource = e.SkinServers;
                    bIgnoreSkinServerListUpdate = false;
                    Debug.Print($"{e.SkinServers.Count} skin servers");
                }
                else
                {
                    grpAuthorDetails.Visible = false;
                    panelSkinServerControls.Visible = false;
                    panelGetServerList.Visible = true;
                    lblSkinServersInfo.Text = "No skin servers in the list\nfrom Github.";
                    Debug.Print("no skins in the list on github");
                }
            }
            else
            {
                grpAuthorDetails.Visible = false;
                panelSkinServerControls.Visible = false;
                panelGetServerList.Visible = true;
                lblSkinServersInfo.Text = "Unable to retrieve skin server list\nfrom Github at this time.";
                Debug.Print("no servers");
            }
        }
        private void imageLoadedHandler(object sender, SkinHttpImage e)
        {
            // all these checks because the image could finish downloading when were are somewhere else
            int sel = comboSkinServerList.SelectedIndex;
            if (sel == -1) return;

            SkinServer ss = comboSkinServerList.SelectedItem as SkinServer;
            if (ss == null) return;

            sel = lstAvailableSkins.SelectedIndex;
            if (sel == -1) return;

            ThetisSkin ts = lstAvailableSkins.Items[sel] as ThetisSkin;
            if (ts == null) return;

            if (e != null)
            {
                //this id is built on the donwload request, so when we get the event here we can check that it belongs to the skin we are viewing
                if (e.ID != "[" + ss.SkinServerUrl + "]_[" + ts.SkinName + "]") return;

                if (e.Image.Width == picSkinThumbnail.Width && e.Image.Height == picSkinThumbnail.Height)
                    picSkinThumbnail.SizeMode = PictureBoxSizeMode.CenterImage;
                else
                    picSkinThumbnail.SizeMode = PictureBoxSizeMode.Zoom;

                picSkinThumbnail.Image = e.Image;
            }
            else
                picSkinThumbnail.Image = null;
        }
        private void btnRefreshSkinsForServer_Click(object sender, EventArgs e)
        {
            if (comboSkinServerList.Items.Count == 0 || comboSkinServerList.SelectedIndex == -1) return;

            SkinServer ss = comboSkinServerList.SelectedItem as SkinServer;
            if (ss == null) return;

            // start the query of the specific server
            ThetisSkinService.GetThetisSkinsData(ss.SkinServerUrl);
        }

        private void btnSkinsHomepage_Click(object sender, EventArgs e)
        {
            Common.OpenUri(btnSkinsHomepage.Tag.ToString());
        }

        private void btnSkinsDonate_Click(object sender, EventArgs e)
        {
            Common.OpenUri(btnSkinsDonate.Tag.ToString());
        }

        private void btnSkinHomepage_Click(object sender, EventArgs e)
        {
            Common.OpenUri(btnSkinHomepage.Tag.ToString());
        }
        private void fileDownloadHandler(object sender, SkinFileDownload e)
        {
            if (e != null)
            {
                if (e.Complete)
                {
                    bool bExtract = false;
                    bool bExpandedMeterSkins = false;
                    string sRootFolder = "";

                    prgSkinDownload.Value = 100;

                    Debug.Print(e.BytesDownloaded.ToString() + " - " + e.TotalBytes.ToString());

                    string sFile = getFileFromUrl(e.Url);
                    if (sFile == "")
                        sFile = getFileFromUrl(e.FinalUri);

                    if (isSkinZipFile(e.Path, sFile, out bool bUsesFileInRoot, out bool bMeterFolderFound, e.BypassRootFolderCheck || e.IsMeterSkin))
                    {
                        string sOutputPath = "";

                        if (bUsesFileInRoot || (e.BypassRootFolderCheck && !bMeterFolderFound))
                        {
                            //expand into OpenHPSDR\Skins
                            sOutputPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\OpenHPSDR\\Skins";
                            bExtract = true;
                        }
                        else if (bMeterFolderFound || e.IsMeterSkin)
                        {
                            if (chkReplaceCurrentMeterInSelectedSkin.Checked)
                            {
                                if (Directory.Exists(_skinPath + "\\" + comboAppSkin.Text))
                                {
                                    if (bMeterFolderFound)
                                        sOutputPath = _skinPath + "\\" + comboAppSkin.Text;
                                    else
                                        sOutputPath = _skinPath + "\\" + comboAppSkin.Text + "\\Meters";

                                    bExtract = true;
                                }
                            }
                            else
                            {
                                if (bMeterFolderFound)
                                    sOutputPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\OpenHPSDR";
                                else
                                    sOutputPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\OpenHPSDR\\Meters";
                                bExtract = true;
                            }
                            bExpandedMeterSkins = true;
                        }
                        else
                        {
                            //expand into OpenHPSDR\
                            sOutputPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\OpenHPSDR";
                            bExtract = true;
                        }

                        if (bExtract)
                        {
                            Cursor c = Cursor.Current;
                            Cursor.Current = Cursors.WaitCursor;
                            sRootFolder = extractImagesFilesFromZip(e.Path, sOutputPath);
                            Cursor.Current = c;
                        }
                        else
                            MessageBox.Show(
                                "Nothing was found in the skin download that could be used. Please contact the creator.",
                                "Skin of my teeth !",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST);
                    }
                    else
                    {
                        MessageBox.Show(
                            "This does not seem to be a valid skin. Please contact the creator.",
                            "Very dry skin !",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST);
                    }

                    tryRemoveDownload(e.Path);

                    if (bExtract)
                    {
                        Cursor c = Cursor.Current;
                        Cursor.Current = Cursors.WaitCursor;

                        if (bExpandedMeterSkins)
                        {
                            MeterManager.RefreshAllImages();
                        }
                        else
                        {
                            RefreshSkinList();

                            string sCurrentSkin;
                            if (sRootFolder != "")
                                sCurrentSkin = sRootFolder;
                            else
                                sCurrentSkin = comboAppSkin.Text;

                            MeterManager.AlwaysUpdateSkin = true; // cause everything to update even if same skin name
                            if (comboAppSkin.Items.Contains(sCurrentSkin))
                                comboAppSkin.Text = sCurrentSkin;
                            MeterManager.AlwaysUpdateSkin = false;
                        }

                        Cursor.Current = c;
                    }

                    btnDownloadSkin.Text = "Download";
                    prgSkinDownload.Visible = false;
                }
                else if (e.Cancelled)
                {
                    prgSkinDownload.Visible = false;
                    btnDownloadSkin.Text = "Download";
                }
                else
                {
                    if (e.TotalBytes != -1)
                    {
                        if (!prgSkinDownload.Visible) prgSkinDownload.Visible = true;

                        int perc = e.PercentageDownloaded;
                        if (perc < 0) perc = 0;
                        if (perc > 100) perc = 100;
                        prgSkinDownload.Value = perc;
                    }
                    else
                    {
                        if (prgSkinDownload.Visible)
                            prgSkinDownload.Visible = false;
                    }
                }
            }
            else
            {
                MessageBox.Show(
                    "There was an issue downloading. Please try again or contact the creator.",
                    "No skin off my nose !",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST);
                // aborted or error
                prgSkinDownload.Visible = false;
                btnDownloadSkin.Text = "Download";
            }
        }
        private void tryRemoveDownload(string path)
        {
            try
            {
                if (File.Exists(path))
                    File.Delete(path);
            }
            catch { }
        }
        private string getFileFromUrl(string sUrl, bool bWithoutExtenstion = true)
        {
            string sFilename = "";
            try
            {
                if (bWithoutExtenstion)
                    sFilename = Path.GetFileNameWithoutExtension(new Uri(sUrl).LocalPath);
                else
                    sFilename = Path.GetFileName(new Uri(sUrl).LocalPath);
            }
            catch { }
            return sFilename;
        }
        private void btnDownloadSkin_Click(object sender, EventArgs e)
        {
            downloadSkin(false);
        }
        private void downloadSkin(bool bUseAfterDownload)
        {
            if (btnDownloadSkin.Text == "Cancel")
            {
                ThetisSkinService.CancelDownload();
            }
            else
            {
                int sel = comboSkinServerList.SelectedIndex;
                if (sel == -1) return;

                SkinServer ss = comboSkinServerList.SelectedItem as SkinServer;
                if (ss == null) return;

                sel = lstAvailableSkins.SelectedIndex;
                if (sel == -1) return;

                ThetisSkin ts = lstAvailableSkins.Items[sel] as ThetisSkin;
                if (ts == null) return;

                btnDownloadSkin.Text = "Cancel";

                string tempFilePath = Path.GetTempFileName();
                ThetisSkinService.DownloadFile(btnDownloadSkin.Tag.ToString(), tempFilePath, ss.BypassRootFolderCheck, ts.IsMeterSkin);
            }
        }
        private void lstAvailableSkins_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lstAvailableSkins.Items.Count == 0 || lstAvailableSkins.SelectedIndex == -1) return;

            ThetisSkinService.CancelDownload();

            updateSelectedSkin();
        }
        private bool isSkinZipFile(string filePath, string sFilename, out bool usesFilenameInRoot, out bool isMeterSkin, bool bypassRootFolderCheck)
        {
            bool bOk = false;
            usesFilenameInRoot = false;
            isMeterSkin = false;

            try
            {
                using (ZipArchive zipFile = ZipFile.OpenRead(filePath))
                {
                    // Check if there is a directory entry starting with "Meters/"
                    if (zipFile.Entries.Any(entry => entry.FullName.StartsWith("Meters/") && entry.FullName.EndsWith("/")))
                    {
                        bOk = true;
                        isMeterSkin = true;
                    }

                    if (!bOk)
                    {
                        if (!bypassRootFolderCheck)
                        {
                            // Check for "Skins/" directory
                            if (!bOk && zipFile.Entries.Any(entry => entry.FullName.StartsWith("Skins/") && entry.FullName.EndsWith("/")))
                            {
                                bOk = true;
                            }

                            if (!bOk && !string.IsNullOrEmpty(sFilename))
                            {
                                // Different filename checks
                                string sReplacedWithSpaces = sFilename.Replace("_", " ");
                                string sReplacedWithoutSpaces = sFilename.Replace(" ", "_");
                                string sReplacedWithMinus = sFilename.Replace(" ", "-");
                                string sReplacedWithoutMinus = sFilename.Replace("-", " ");

                                if (zipFile.Entries.Any(entry =>
                                    (entry.FullName.StartsWith(sFilename + "/") ||
                                     entry.FullName.StartsWith(sReplacedWithSpaces + "/") ||
                                     entry.FullName.StartsWith(sReplacedWithoutSpaces + "/") ||
                                     entry.FullName.StartsWith(sReplacedWithMinus + "/") ||
                                     entry.FullName.StartsWith(sReplacedWithoutMinus + "/")) &&
                                     entry.FullName.EndsWith("/")))
                                {
                                    usesFilenameInRoot = true;
                                    bOk = true;
                                }
                            }
                        }
                        else
                        {
                            bOk = true;
                        }
                    }
                }
            }
            catch (InvalidDataException)
            {
                // Handle invalid ZIP file
            }
            catch (Exception ex)
            {
                // Handle other exceptions
            }

            return bOk;
        }
        private bool doesFolderExistInZip(string zipFilePath, string folderName)
        {
            using (ZipArchive zipArchive = ZipFile.OpenRead(zipFilePath))
            {
                return zipArchive.Entries.Any(entry =>
                    entry.FullName.StartsWith(folderName + "/") && entry.FullName.EndsWith("/"));
            }
        }
        private static string extractImagesFilesFromZip(string sourceZipFilePath, string outputPath)
        {
            string sRootFolder = "";
            try
            {
                sourceZipFilePath = sourceZipFilePath.Replace('/', '\\');
                outputPath = outputPath.Replace('/', '\\');

                using (ZipArchive zip = ZipFile.OpenRead(sourceZipFilePath))
                {
                    foreach (ZipArchiveEntry entry in zip.Entries.Where(e => e.FullName.EndsWith(".png", StringComparison.OrdinalIgnoreCase) ||
                                                                             e.FullName.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase) ||
                                                                             e.FullName.EndsWith(".jpeg", StringComparison.OrdinalIgnoreCase) ||
                                                                             e.FullName.EndsWith(".bmp", StringComparison.OrdinalIgnoreCase)))
                    {
                        // Normalize the entry path for file system usage
                        string entryPath = Path.Combine(outputPath, entry.FullName.Replace('/', '\\'));
                        string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(entryPath);

                        // Create the directory structure if it doesn't exist
                        Directory.CreateDirectory(Path.GetDirectoryName(entryPath));

                        // remove any .* files that match
                        string[] filesToDelete = Directory.GetFiles(outputPath, fileNameWithoutExtension + ".*");
                        // Delete each found file
                        foreach (string file in filesToDelete)
                        {
                            try
                            {
                                File.Delete(file);
                            }
                            catch { }
                        }

                        // Extract the entry
                        entry.ExtractToFile(entryPath, true); // true to overwrite existing files

                        if (sRootFolder == "")
                        {
                            // Get the root folder name from the entry's path
                            int index = entry.FullName.IndexOf('/');
                            if (index > 0) sRootFolder = entry.FullName.Substring(0, index);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    "There was an issue extracting the .png file(s) from the download.\n\nSome/all of the images may be missing. The error is as follows :\n\n" + ex.ToString(),
                    "Skin download issue",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
            }
            return sRootFolder;
        }
        private bool bIgnoreSkinServerListUpdate = false;
        private void comboSkinServerList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing || bIgnoreSkinServerListUpdate) return;

            hideAllSkinServerRelatedControls();
            panelSkinServerControls.Visible = true;
        }

        private void btnRemoveSkin_Click(object sender, EventArgs e)
        {
            if (comboAppSkin.SelectedIndex == -1 || comboAppSkin.Items.Count <= 1 || _skinPath == "")
            {
                btnRemoveSkin.Enabled = comboAppSkin.Items.Count > 1; // some reason it was enabled

                return;
            }

            btnRemoveSkin.Enabled = false;

            string sSelectedSkin = comboAppSkin.Text;
            int nSelected = comboAppSkin.SelectedIndex;

            DialogResult dres = MessageBox.Show(
            "Do you want to remove the skin [" + sSelectedSkin + "] from the available skins?\n\nThis will permanently remove it from the Skins folder.\n\nTo do so another skin will be selected instead.",
            "Skin removal",
            MessageBoxButtons.YesNo,
            MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, Common.MB_TOPMOST);

            if (dres == DialogResult.Yes)
            {
                int nToSelect;
                if (nSelected == comboAppSkin.Items.Count - 1)
                {
                    // selected last in the list, select previous
                    nToSelect = nSelected - 1;
                }
                else
                {
                    //select next
                    nToSelect = nSelected + 1;
                }

                // change skin
                comboAppSkin.SelectedIndex = nToSelect;

                string sSkinPath = _skinPath + "\\" + sSelectedSkin;

                try
                {
                    if (Directory.Exists(sSkinPath))
                        Directory.Delete(sSkinPath, true);
                }
                catch (Exception ex)
                {
                    dres = MessageBox.Show(
                                "There was an isssue deleting [" + sSelectedSkin + "] from the skin folder.\n\nSome files would not delete.\n\nPlease remove manually.",
                                "Skin removal issue",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST);
                }

                string sSkinBeforeRefresh = comboAppSkin.Text;
                RefreshSkinList();
                if (comboAppSkin.Items.Contains(sSkinBeforeRefresh) && comboAppSkin.Text != sSkinBeforeRefresh)
                    comboAppSkin.Text = sSkinBeforeRefresh;
            }

            btnRemoveSkin.Enabled = comboAppSkin.Items.Count > 1;
        }

        private void btnOpenSkinsFolder_Click(object sender, EventArgs e)
        {
            try
            {
                if (_skinPath != "")
                    Process.Start("explorer.exe", _skinPath);
            }
            catch (Exception ex)
            {
            }
        }

        private void chkPurgeBuffers_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.WDSPMOXTransitionBufferClear = chkPurgeBuffers.Checked;
        }

        private void tcSetup_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (isSkinServerTabVisible()) getSkinServers();
            if (tcSetup.SelectedTab == tpCATControl && tcCAT.SelectedTab == tpMultiMetersIO) updateVariableList();
        }

        private void udFMLowCutRX_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (udFMLowCutRX.Value > udFMHighCutRX.Value) return;
            console.radio.GetDSPRX(0, 0).RXFMLowCut = (double)udFMLowCutRX.Value; //main rx1
            console.radio.GetDSPRX(0, 1).RXFMLowCut = (double)udFMLowCutRX.Value; //sub rx1
            console.radio.GetDSPRX(1, 0).RXFMLowCut = (double)udFMLowCutRX.Value; //rx2
            if (console.RX1DSPMode == DSPMode.FM)
                console.UpdateRX1Filters((int)console.radio.GetDSPRX(0, 0).RXFMLowCut, (int)console.radio.GetDSPTX(0).TXFMHighCut);
            if (console.RX2DSPMode == DSPMode.FM)
                console.UpdateRX2Filters((int)console.radio.GetDSPRX(1, 0).RXFMLowCut, (int)console.radio.GetDSPTX(0).TXFMHighCut);
        }

        private void udFMHighCutRX_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (udFMHighCutRX.Value < udFMLowCutRX.Value) return;
            console.radio.GetDSPRX(0, 0).RXFMHighCut = (double)udFMHighCutRX.Value;
            console.radio.GetDSPRX(0, 1).RXFMHighCut = (double)udFMHighCutRX.Value;
            console.radio.GetDSPRX(1, 0).RXFMHighCut = (double)udFMHighCutRX.Value;
            if (console.RX1DSPMode == DSPMode.FM)
                console.UpdateRX1Filters((int)console.radio.GetDSPRX(0, 0).RXFMLowCut, (int)console.radio.GetDSPTX(0).TXFMHighCut);
            if (console.RX2DSPMode == DSPMode.FM)
                console.UpdateRX2Filters((int)console.radio.GetDSPRX(1, 0).RXFMLowCut, (int)console.radio.GetDSPTX(0).TXFMHighCut);
        }

        private void udFMLowCutTX_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (udFMLowCutTX.Value > udFMHighCutTX.Value) return;
            console.radio.GetDSPTX(0).TXFMLowCut = (double)udFMLowCutTX.Value;
            if (console.RX1DSPMode == DSPMode.FM)
                console.SetTXFilters(DSPMode.FM, (int)console.radio.GetDSPTX(0).TXFMLowCut, (int)console.radio.GetDSPTX(0).TXFMHighCut);
        }

        private void udFMHighCutTX_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (udFMHighCutTX.Value < udFMLowCutTX.Value) return;
            console.radio.GetDSPTX(0).TXFMHighCut = (double)udFMHighCutTX.Value;
            if (console.RX1DSPMode == DSPMode.FM)
                console.SetTXFilters(DSPMode.FM, (int)console.radio.GetDSPTX(0).TXFMLowCut, (int)console.radio.GetDSPTX(0).TXFMHighCut);
        }

        private void chkSwapIQVac1_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Audio.VAC1SwapIQ = chkSwapIQVac1.Checked ? 1 : 0;
        }

        private void chkSwapIQVac2_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Audio.VAC2SwapIQ = chkSwapIQVac2.Checked ? 1 : 0;
        }

        public ToolTip ToolTip
        {
            get
            {
                return toolTip1;
            }
        }

        private void chkPHROTReverse_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            int run = chkPHROTReverse.Checked ? 1 : 0;
            WDSP.SetTXAPHROTReverse(WDSP.id(1, 0), run);
        }

        private void chkRecoverPAProfileFromTXProfile_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;

            if (sender == chkRecoverPAProfileFromTXProfile && chkRecoverPAProfileFromTXProfile.Checked)
            {
                // manually clicked, warning
                DialogResult dres = MessageBox.Show(
                    "Warning: Modes will recover TX profiles that are associated with them. Please ensure the TX profile assocated with a specific mode has the correct PA profile stored against it. Failure to do so may result in unexpected results and/or overdrive issues.\n\nDo you want to enable this?",
                    "PA Profile recovery from TX Profile",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, Common.MB_TOPMOST);

                if (dres == DialogResult.No)
                    chkRecoverPAProfileFromTXProfile.Checked = false;
            }

            lblPAProfileWarning.Visible = chkRecoverPAProfileFromTXProfile.Checked;
            pbPAProfileWarning.Visible = chkRecoverPAProfileFromTXProfile.Checked;
        }
        private void chkVAC1ExclusiveOut_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;

            if (console.PowerOn && chkAudioEnableVAC.Checked)
            {
                Audio.EnableVAC1(false);
            }

            Audio.VAC1ExclusiveOut = chkVAC1ExclusiveOut.Checked ? 1 : 0;

            if (console.PowerOn && chkAudioEnableVAC.Checked)
            {
                Audio.EnableVAC1(true);
            }
        }

        private void chkVAC2ExclusiveOut_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;

            if (console.PowerOn && chkVAC2Enable.Checked)
            {
                Audio.EnableVAC2(false);
            }

            Audio.VAC2ExclusiveOut = chkVAC2ExclusiveOut.Checked ? 1 : 0;

            if (console.PowerOn && chkVAC2Enable.Checked)
            {
                Audio.EnableVAC2(true);
            }
        }

        private void chkVAC1ExclusiveIn_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;

            if (console.PowerOn && chkAudioEnableVAC.Checked)
            {
                Audio.EnableVAC1(false);
            }

            Audio.VAC1ExclusiveIn = chkVAC1ExclusiveIn.Checked ? 1 : 0;

            if (console.PowerOn && chkAudioEnableVAC.Checked)
            {
                Audio.EnableVAC1(true);
            }
        }

        private void chkVAC2ExclusiveIn_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;

            if (console.PowerOn && chkVAC2Enable.Checked)
            {
                Audio.EnableVAC2(false);
            }

            Audio.VAC2ExclusiveIn = chkVAC2ExclusiveIn.Checked ? 1 : 0;

            if (console.PowerOn && chkVAC2Enable.Checked)
            {
                Audio.EnableVAC2(true);
            }
        }

        private void btnReleaseNotes_Click(object sender, EventArgs e)
        {
            console.ShowReleaseNotes();
        }

        private void chkIgnore14bitMidiMessages_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            MidiDevice.Ignore14bitMessages = chkIgnore14bitMidiMessages.Checked;
        }

        private void chkMidiControlIDincludesChannel_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            MidiDevice.BuildIDFromControlIDAndChannel = chkMidiControlIDincludesChannel.Checked;
            MidiDevice.IncludeStatusInControlID = chkMidiControlIDincludesChannel.Checked && chkMidiControlIDincludesStatus.Checked;
            chkMidiControlIDincludesStatus.Enabled = chkMidiControlIDincludesChannel.Checked;
        }

        private void chkMidiControlIDincludesStatus_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            MidiDevice.IncludeStatusInControlID = chkMidiControlIDincludesChannel.Checked && chkMidiControlIDincludesStatus.Checked;
        }

        private void chkForceATTwhenOutPowerChanges_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.ForceATTwhenOutputPowerChangesWhenPSAon = chkForceATTwhenOutPowerChanges.Checked;
        }

        private void chkToTMox_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            udMoxToTSeconds.Enabled = chkToTMox.Checked;
            lblMoxTotSec.Enabled = chkToTMox.Checked;
            TimeOutTimerManager.MoxTimeOut((int)udMoxToTSeconds.Value, chkToTMox.Checked);
        }

        private void udMoxToTSeconds_ValueChanged(object sender, EventArgs e)
        {
            chkToTMox_CheckedChanged(this, EventArgs.Empty);
        }

        private void chkToTPing_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            udPingToTSeconds.Enabled = chkToTPing.Checked;
            txtToTPingIP.Enabled = chkToTPing.Checked;
            btnPingDef.Enabled = chkToTPing.Checked;
            lblPingTotSec.Enabled = chkToTPing.Checked;

            bool bIPOk = IPAddress.TryParse(txtToTPingIP.Text, out IPAddress address);
            if (bIPOk)
            {
                txtToTPingIP.BackColor = SystemColors.Window;
                TimeOutTimerManager.PingTimeOut(txtToTPingIP.Text, (int)udPingToTSeconds.Value, chkToTPing.Checked);
            }
            else
                txtToTPingIP.BackColor = Color.Red;
        }

        private void udPingToTSeconds_ValueChanged(object sender, EventArgs e)
        {
            chkToTPing_CheckedChanged(this, EventArgs.Empty);
        }

        private void txtToTPingIP_TextChanged(object sender, EventArgs e)
        {
            chkToTPing_CheckedChanged(this, EventArgs.Empty);
        }

        private void btnPingDef_Click(object sender, EventArgs e)
        {
            txtToTPingIP.Text = "8.8.8.8";
        }

        private void clrbtnNoiseFloorText_Changed(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.NoiseFloorColorText = clrbtnNoiseFloorText.Color;
        }

        private void radRadioProtocolSelect_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            //note: all 3 radio buttons for radio protocol call this on change

            if (radRadioProtocol1Select.Checked)
            {
                RadioProtocolSelected = RadioProtocol.USB;
                NetworkIO.RadioProtocolSelected = RadioProtocol.USB;
            }
            else if (radRadioProtocol2Select.Checked)
            {
                RadioProtocolSelected = RadioProtocol.ETH;
                NetworkIO.RadioProtocolSelected = RadioProtocol.ETH;
            }
            else if (radRadioProtocolAutoSelect.Checked)
            {
                RadioProtocolSelected = RadioProtocol.Auto;
                NetworkIO.RadioProtocolSelected = RadioProtocol.Auto;
            }
            else
            {
                //default to auto
                radRadioProtocolAutoSelect.Checked = true;
                return;
            }

            InitAudioTab();
        }

        //[2.10.3.5]W4WMT implements #87
        private void chkMICVOXAllowBypass_CheckedChanged(object sender, EventArgs e)
        {
            console.AllowMICVOXBypass = chkMICVOXAllowBypass.Checked;
        }

        //[2.10.3.5]MW0LGE implements #306
        private void chkStopRX1WaterfallOnTx_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.StopRX1WaterfallOnTx = chkStopRX1WaterfallOnTx.Checked;
        }

        private void chkStopRX2WaterfallOnTx_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            Display.StopRX2WaterfallOnTx = chkStopRX2WaterfallOnTx.Checked;
        }
        //

        public int[] SerialCatState()
        {
            //used to obtain cat state for the status bar icon in console
            //0 = not in use, 1 = in use not enabled, 2 = in use and enabled
            int[] nState = new int[4];

            nState[0] = !chkCATEnable.Enabled ? 0 : !chkCATEnable.Checked ? 1 : 2;
            nState[1] = !chkCAT2Enable.Enabled ? 0 : !chkCAT2Enable.Checked ? 1 : 2;
            nState[2] = !chkCAT3Enable.Enabled ? 0 : !chkCAT3Enable.Checked ? 1 : 2;
            nState[3] = !chkCAT4Enable.Enabled ? 0 : !chkCAT4Enable.Checked ? 1 : 2;

            return nState;
        }

        private void chkAutoPowerOn_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.AutoPowerOn = chkAutoPowerOn.Checked;
        }

        private void btnRX1CopyLowHighWaterfall_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show(
                "Do you want to copy the current low/high values to all bands?",
                "Low/High copy",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, Common.MB_TOPMOST);
            if (dr == DialogResult.No) return;

            float low;
            float high;

            switch (console.RX1Band)
            {
                case Band.B160M:
                    low = console.WaterfallLowThreshold160m;
                    high = console.WaterfallHighThreshold160m;
                    break;
                case Band.B80M:
                    low = console.WaterfallLowThreshold80m;
                    high = console.WaterfallHighThreshold80m;
                    break;
                case Band.B60M:
                    low = console.WaterfallLowThreshold60m;
                    high = console.WaterfallHighThreshold60m;
                    break;
                case Band.B40M:
                    low = console.WaterfallLowThreshold40m;
                    high = console.WaterfallHighThreshold40m;
                    break;
                case Band.B30M:
                    low = console.WaterfallLowThreshold30m;
                    high = console.WaterfallHighThreshold30m;
                    break;
                case Band.B20M:
                    low = console.WaterfallLowThreshold20m;
                    high = console.WaterfallHighThreshold20m;
                    break;
                case Band.B17M:
                    low = console.WaterfallLowThreshold17m;
                    high = console.WaterfallHighThreshold17m;
                    break;
                case Band.B15M:
                    low = console.WaterfallLowThreshold15m;
                    high = console.WaterfallHighThreshold15m;
                    break;
                case Band.B12M:
                    low = console.WaterfallLowThreshold12m;
                    high = console.WaterfallHighThreshold12m;
                    break;
                case Band.B10M:
                    low = console.WaterfallLowThreshold10m;
                    high = console.WaterfallHighThreshold10m;
                    break;
                case Band.B6M:
                    low = console.WaterfallLowThreshold6m;
                    high = console.WaterfallHighThreshold6m;
                    break;
                case Band.WWV:
                    low = console.WaterfallLowThresholdWWV;
                    high = console.WaterfallHighThresholdWWV;
                    break;
                case Band.GEN:
                    low = console.WaterfallLowThresholdGEN;
                    high = console.WaterfallHighThresholdGEN;
                    break;
                default:
                    low = console.WaterfallLowThresholdXVTR;
                    high = console.WaterfallHighThresholdXVTR;
                    break;
            }

            for (int nBand = (int)Band.FIRST; nBand <= (int)Band.WWV; nBand++) //note FIRST will cause xvtr update
            {
                switch ((Band)nBand)
                {
                    case Band.B160M:
                        console.WaterfallLowThreshold160m = low;
                        console.WaterfallHighThreshold160m = high;
                        break;
                    case Band.B80M:
                        console.WaterfallLowThreshold80m = low;
                        console.WaterfallHighThreshold80m = high;
                        break;
                    case Band.B60M:
                        console.WaterfallLowThreshold60m = low;
                        console.WaterfallHighThreshold60m = high;
                        break;
                    case Band.B40M:
                        console.WaterfallLowThreshold40m = low;
                        console.WaterfallHighThreshold40m = high;
                        break;
                    case Band.B30M:
                        console.WaterfallLowThreshold30m = low;
                        console.WaterfallHighThreshold30m = high;
                        break;
                    case Band.B20M:
                        console.WaterfallLowThreshold20m = low;
                        console.WaterfallHighThreshold20m = high;
                        break;
                    case Band.B17M:
                        console.WaterfallLowThreshold17m = low;
                        console.WaterfallHighThreshold17m = high;
                        break;
                    case Band.B15M:
                        console.WaterfallLowThreshold15m = low;
                        console.WaterfallHighThreshold15m = high;
                        break;
                    case Band.B12M:
                        console.WaterfallLowThreshold12m = low;
                        console.WaterfallHighThreshold12m = high;
                        break;
                    case Band.B10M:
                        console.WaterfallLowThreshold10m = low;
                        console.WaterfallHighThreshold10m = high;
                        break;
                    case Band.B6M:
                        console.WaterfallLowThreshold6m = low;
                        console.WaterfallHighThreshold6m = high;
                        break;
                    case Band.WWV:
                        console.WaterfallLowThresholdWWV = low;
                        console.WaterfallHighThresholdWWV = high;
                        break;
                    case Band.GEN:
                        console.WaterfallLowThresholdGEN = low;
                        console.WaterfallHighThresholdGEN = high;
                        break;
                    default:
                        console.WaterfallLowThresholdXVTR = low;
                        console.WaterfallHighThresholdXVTR = high;
                        break;
                }
            }
        }

        private void btnRX1CopyMinMaxSpectrumGrid_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show(
            "Do you want to copy the current min/max values to all bands?",
            "Min/Max copy",
            MessageBoxButtons.YesNo,
            MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, Common.MB_TOPMOST);
            if (dr == DialogResult.No) return;

            float min;
            float max;

            switch (console.RX1Band)
            {
                case Band.B160M:
                    min = console.DisplayGridMin160m;
                    max = console.DisplayGridMax160m;
                    break;
                case Band.B80M:
                    min = console.DisplayGridMin80m;
                    max = console.DisplayGridMax80m;
                    break;
                case Band.B60M:
                    min = console.DisplayGridMin60m;
                    max = console.DisplayGridMax60m;
                    break;
                case Band.B40M:
                    min = console.DisplayGridMin40m;
                    max = console.DisplayGridMax40m;
                    break;
                case Band.B30M:
                    min = console.DisplayGridMin30m;
                    max = console.DisplayGridMax30m;
                    break;
                case Band.B20M:
                    min = console.DisplayGridMin20m;
                    max = console.DisplayGridMax20m;
                    break;
                case Band.B17M:
                    min = console.DisplayGridMin17m;
                    max = console.DisplayGridMax17m;
                    break;
                case Band.B15M:
                    min = console.DisplayGridMin15m;
                    max = console.DisplayGridMax15m;
                    break;
                case Band.B12M:
                    min = console.DisplayGridMin12m;
                    max = console.DisplayGridMax12m;
                    break;
                case Band.B10M:
                    min = console.DisplayGridMin10m;
                    max = console.DisplayGridMax10m;
                    break;
                case Band.B6M:
                    min = console.DisplayGridMin6m;
                    max = console.DisplayGridMax6m;
                    break;
                case Band.WWV:
                    min = console.DisplayGridMinWWV;
                    max = console.DisplayGridMaxWWV;
                    break;
                case Band.GEN:
                    min = console.DisplayGridMinGEN;
                    max = console.DisplayGridMaxGEN;
                    break;
                default:
                    min = console.DisplayGridMinXVTR;
                    max = console.DisplayGridMaxXVTR;
                    break;
            }

            for (int nBand = (int)Band.FIRST; nBand <= (int)Band.WWV; nBand++) //note FIRST will cause xvtr update
            {
                switch ((Band)nBand)
                {
                    case Band.B160M:
                        console.DisplayGridMin160m = min;
                        console.DisplayGridMax160m = max;
                        break;
                    case Band.B80M:
                        console.DisplayGridMin80m = min;
                        console.DisplayGridMax80m = max;
                        break;
                    case Band.B60M:
                        console.DisplayGridMin60m = min;
                        console.DisplayGridMax60m = max;
                        break;
                    case Band.B40M:
                        console.DisplayGridMin40m = min;
                        console.DisplayGridMax40m = max;
                        break;
                    case Band.B30M:
                        console.DisplayGridMin30m = min;
                        console.DisplayGridMax30m = max;
                        break;
                    case Band.B20M:
                        console.DisplayGridMin20m = min;
                        console.DisplayGridMax20m = max;
                        break;
                    case Band.B17M:
                        console.DisplayGridMin17m = min;
                        console.DisplayGridMax17m = max;
                        break;
                    case Band.B15M:
                        console.DisplayGridMin15m = min;
                        console.DisplayGridMax15m = max;
                        break;
                    case Band.B12M:
                        console.DisplayGridMin12m = min;
                        console.DisplayGridMax12m = max;
                        break;
                    case Band.B10M:
                        console.DisplayGridMin10m = min;
                        console.DisplayGridMax10m = max;
                        break;
                    case Band.B6M:
                        console.DisplayGridMin6m = min;
                        console.DisplayGridMax6m = max;
                        break;
                    case Band.WWV:
                        console.DisplayGridMinWWV = min;
                        console.DisplayGridMaxWWV = max;
                        break;
                    case Band.GEN:
                        console.DisplayGridMinGEN = min;
                        console.DisplayGridMaxGEN = max;
                        break;
                    default:
                        console.DisplayGridMinXVTR = min;
                        console.DisplayGridMaxXVTR = max;
                        break;
                }
            }
        }

        private void btnRX2CopyLowHighWaterfall_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show(
            "Do you want to copy the current low/high values to all bands?",
            "Low/High copy",
            MessageBoxButtons.YesNo,
            MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, Common.MB_TOPMOST);
            if (dr == DialogResult.No) return;

            float low;
            float high;

            switch (console.RX2Band)
            {
                case Band.B160M:
                    low = console.RX2WaterfallLowThreshold160m;
                    high = console.RX2WaterfallHighThreshold160m;
                    break;
                case Band.B80M:
                    low = console.RX2WaterfallLowThreshold80m;
                    high = console.RX2WaterfallHighThreshold80m;
                    break;
                case Band.B60M:
                    low = console.RX2WaterfallLowThreshold60m;
                    high = console.RX2WaterfallHighThreshold60m;
                    break;
                case Band.B40M:
                    low = console.RX2WaterfallLowThreshold40m;
                    high = console.RX2WaterfallHighThreshold40m;
                    break;
                case Band.B30M:
                    low = console.RX2WaterfallLowThreshold30m;
                    high = console.RX2WaterfallHighThreshold30m;
                    break;
                case Band.B20M:
                    low = console.RX2WaterfallLowThreshold20m;
                    high = console.RX2WaterfallHighThreshold20m;
                    break;
                case Band.B17M:
                    low = console.RX2WaterfallLowThreshold17m;
                    high = console.RX2WaterfallHighThreshold17m;
                    break;
                case Band.B15M:
                    low = console.RX2WaterfallLowThreshold15m;
                    high = console.RX2WaterfallHighThreshold15m;
                    break;
                case Band.B12M:
                    low = console.RX2WaterfallLowThreshold12m;
                    high = console.RX2WaterfallHighThreshold12m;
                    break;
                case Band.B10M:
                    low = console.RX2WaterfallLowThreshold10m;
                    high = console.RX2WaterfallHighThreshold10m;
                    break;
                case Band.B6M:
                    low = console.RX2WaterfallLowThreshold6m;
                    high = console.RX2WaterfallHighThreshold6m;
                    break;
                case Band.WWV:
                    low = console.RX2WaterfallLowThresholdWWV;
                    high = console.RX2WaterfallHighThresholdWWV;
                    break;
                case Band.GEN:
                    low = console.RX2WaterfallLowThresholdGEN;
                    high = console.RX2WaterfallHighThresholdGEN;
                    break;
                default:
                    low = console.RX2WaterfallLowThresholdXVTR;
                    high = console.RX2WaterfallHighThresholdXVTR;
                    break;
            }

            for (int nBand = (int)Band.FIRST; nBand <= (int)Band.WWV; nBand++) //note FIRST will cause xvtr update
            {
                switch ((Band)nBand)
                {
                    case Band.B160M:
                        console.RX2WaterfallLowThreshold160m = low;
                        console.RX2WaterfallHighThreshold160m = high;
                        break;
                    case Band.B80M:
                        console.RX2WaterfallLowThreshold80m = low;
                        console.RX2WaterfallHighThreshold80m = high;
                        break;
                    case Band.B60M:
                        console.RX2WaterfallLowThreshold60m = low;
                        console.RX2WaterfallHighThreshold60m = high;
                        break;
                    case Band.B40M:
                        console.RX2WaterfallLowThreshold40m = low;
                        console.RX2WaterfallHighThreshold40m = high;
                        break;
                    case Band.B30M:
                        console.RX2WaterfallLowThreshold30m = low;
                        console.RX2WaterfallHighThreshold30m = high;
                        break;
                    case Band.B20M:
                        console.RX2WaterfallLowThreshold20m = low;
                        console.RX2WaterfallHighThreshold20m = high;
                        break;
                    case Band.B17M:
                        console.RX2WaterfallLowThreshold17m = low;
                        console.RX2WaterfallHighThreshold17m = high;
                        break;
                    case Band.B15M:
                        console.RX2WaterfallLowThreshold15m = low;
                        console.RX2WaterfallHighThreshold15m = high;
                        break;
                    case Band.B12M:
                        console.RX2WaterfallLowThreshold12m = low;
                        console.RX2WaterfallHighThreshold12m = high;
                        break;
                    case Band.B10M:
                        console.RX2WaterfallLowThreshold10m = low;
                        console.RX2WaterfallHighThreshold10m = high;
                        break;
                    case Band.B6M:
                        console.RX2WaterfallLowThreshold6m = low;
                        console.RX2WaterfallHighThreshold6m = high;
                        break;
                    case Band.WWV:
                        console.RX2WaterfallLowThresholdWWV = low;
                        console.RX2WaterfallHighThresholdWWV = high;
                        break;
                    case Band.GEN:
                        console.RX2WaterfallLowThresholdGEN = low;
                        console.RX2WaterfallHighThresholdGEN = high;
                        break;
                    default:
                        console.RX2WaterfallLowThresholdXVTR = low;
                        console.RX2WaterfallHighThresholdXVTR = high;
                        break;
                }
            }
        }

        private void btnRX2CopyMinMaxSpectrumGrid_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show(
            "Do you want to copy the current min/max values to all bands?",
            "Min/Max copy",
            MessageBoxButtons.YesNo,
            MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, Common.MB_TOPMOST);
            if (dr == DialogResult.No) return;

            float min;
            float max;

            switch (console.RX2Band)
            {
                case Band.B160M:
                    min = console.RX2DisplayGridMin160m;
                    max = console.RX2DisplayGridMax160m;
                    break;
                case Band.B80M:
                    min = console.RX2DisplayGridMin80m;
                    max = console.RX2DisplayGridMax80m;
                    break;
                case Band.B60M:
                    min = console.RX2DisplayGridMin60m;
                    max = console.RX2DisplayGridMax60m;
                    break;
                case Band.B40M:
                    min = console.RX2DisplayGridMin40m;
                    max = console.RX2DisplayGridMax40m;
                    break;
                case Band.B30M:
                    min = console.RX2DisplayGridMin30m;
                    max = console.RX2DisplayGridMax30m;
                    break;
                case Band.B20M:
                    min = console.RX2DisplayGridMin20m;
                    max = console.RX2DisplayGridMax20m;
                    break;
                case Band.B17M:
                    min = console.RX2DisplayGridMin17m;
                    max = console.RX2DisplayGridMax17m;
                    break;
                case Band.B15M:
                    min = console.RX2DisplayGridMin15m;
                    max = console.RX2DisplayGridMax15m;
                    break;
                case Band.B12M:
                    min = console.RX2DisplayGridMin12m;
                    max = console.RX2DisplayGridMax12m;
                    break;
                case Band.B10M:
                    min = console.RX2DisplayGridMin10m;
                    max = console.RX2DisplayGridMax10m;
                    break;
                case Band.B6M:
                    min = console.RX2DisplayGridMin6m;
                    max = console.RX2DisplayGridMax6m;
                    break;
                case Band.WWV:
                    min = console.RX2DisplayGridMinWWV;
                    max = console.RX2DisplayGridMaxWWV;
                    break;
                case Band.GEN:
                    min = console.RX2DisplayGridMinGEN;
                    max = console.RX2DisplayGridMaxGEN;
                    break;
                default:
                    min = console.RX2DisplayGridMinXVTR;
                    max = console.RX2DisplayGridMaxXVTR;
                    break;
            }

            for (int nBand = (int)Band.FIRST; nBand <= (int)Band.WWV; nBand++) //note FIRST will cause xvtr update
            {
                switch ((Band)nBand)
                {
                    case Band.B160M:
                        console.RX2DisplayGridMin160m = min;
                        console.RX2DisplayGridMax160m = max;
                        break;
                    case Band.B80M:
                        console.RX2DisplayGridMin80m = min;
                        console.RX2DisplayGridMax80m = max;
                        break;
                    case Band.B60M:
                        console.RX2DisplayGridMin60m = min;
                        console.RX2DisplayGridMax60m = max;
                        break;
                    case Band.B40M:
                        console.RX2DisplayGridMin40m = min;
                        console.RX2DisplayGridMax40m = max;
                        break;
                    case Band.B30M:
                        console.RX2DisplayGridMin30m = min;
                        console.RX2DisplayGridMax30m = max;
                        break;
                    case Band.B20M:
                        console.RX2DisplayGridMin20m = min;
                        console.RX2DisplayGridMax20m = max;
                        break;
                    case Band.B17M:
                        console.RX2DisplayGridMin17m = min;
                        console.RX2DisplayGridMax17m = max;
                        break;
                    case Band.B15M:
                        console.RX2DisplayGridMin15m = min;
                        console.RX2DisplayGridMax15m = max;
                        break;
                    case Band.B12M:
                        console.RX2DisplayGridMin12m = min;
                        console.RX2DisplayGridMax12m = max;
                        break;
                    case Band.B10M:
                        console.RX2DisplayGridMin10m = min;
                        console.RX2DisplayGridMax10m = max;
                        break;
                    case Band.B6M:
                        console.RX2DisplayGridMin6m = min;
                        console.RX2DisplayGridMax6m = max;
                        break;
                    case Band.WWV:
                        console.RX2DisplayGridMinWWV = min;
                        console.RX2DisplayGridMaxWWV = max;
                        break;
                    case Band.GEN:
                        console.RX2DisplayGridMinGEN = min;
                        console.RX2DisplayGridMaxGEN = max;
                        break;
                    default:
                        console.RX2DisplayGridMinXVTR = min;
                        console.RX2DisplayGridMaxXVTR = max;
                        break;
                }
            }
        }

        private void btnRX1PBsnrReset_Click(object sender, EventArgs e)
        {
            nudPBsnrShiftRx1.Value = 0;
        }

        private void btnRX2PBsnrReset_Click(object sender, EventArgs e)
        {
            nudPBsnrShiftRx2.Value = 0;
        }

        private void nudPBsnrShiftRx1_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.RX1PBsnrShift = (double)nudPBsnrShiftRx1.Value;
        }

        private void nudPBsnrShiftRx2_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.RX2PBsnrShift = (double)nudPBsnrShiftRx2.Value;
        }

        private void chkCWbecomesCWUabove10mhz_CheckedChanged(object sender, EventArgs e)
        {
            console.TCICWbecomesCWUabove10mhz = chkCWbecomesCWUabove10mhz.Checked;
        }

        public readonly Dictionary<string, bool> KenwoodAISettings = new Dictionary<string, bool>(); // contains settings "enabled", "port1", "port2", "port3", "port4", "tcp", all as bools
        private void chkKWAI_port1_CheckedChanged(object sender, EventArgs e)
        {
            if (KenwoodAISettings.ContainsKey("port1"))
            {
                KenwoodAISettings["port1"] = chkKWAI_port1.Checked;
            }
            else
            {
                KenwoodAISettings.Add("port1", chkKWAI_port1.Checked);
            }
        }

        private void chkKWAI_port2_CheckedChanged(object sender, EventArgs e)
        {
            if (KenwoodAISettings.ContainsKey("port2"))
            {
                KenwoodAISettings["port2"] = chkKWAI_port2.Checked;
            }
            else
            {
                KenwoodAISettings.Add("port2", chkKWAI_port2.Checked);
            }
        }

        private void chkKWAI_port3_CheckedChanged(object sender, EventArgs e)
        {
            if (KenwoodAISettings.ContainsKey("port3"))
            {
                KenwoodAISettings["port3"] = chkKWAI_port3.Checked;
            }
            else
            {
                KenwoodAISettings.Add("port3", chkKWAI_port3.Checked);
            }
        }

        private void chkKWAI_port4_CheckedChanged(object sender, EventArgs e)
        {
            if (KenwoodAISettings.ContainsKey("port4"))
            {
                KenwoodAISettings["port4"] = chkKWAI_port4.Checked;
            }
            else
            {
                KenwoodAISettings.Add("port4", chkKWAI_port4.Checked);
            }
        }

        private void chkKWAI_tcp_CheckedChanged(object sender, EventArgs e)
        {
            if (KenwoodAISettings.ContainsKey("tcp"))
            {
                KenwoodAISettings["tcp"] = chkKWAI_tcp.Checked;
            }
            else
            {
                KenwoodAISettings.Add("tcp", chkKWAI_tcp.Checked);
            }
        }

        private void updatePortAIstate(bool enabled)
        {
            if (KenwoodAISettings.ContainsKey("enabled"))
            {
                KenwoodAISettings["enabled"] = chkKWAI.Checked;
            }
            else
            {
                KenwoodAISettings.Add("enabled", chkKWAI.Checked);
            }

            chkKWAI_port1.Enabled = enabled;
            chkKWAI_port2.Enabled = enabled;
            chkKWAI_port3.Enabled = enabled;
            chkKWAI_port4.Enabled = enabled;
            chkKWAI_tcp.Enabled = enabled;

            chkKWAI_port1_CheckedChanged(this, EventArgs.Empty);
            chkKWAI_port2_CheckedChanged(this, EventArgs.Empty);
            chkKWAI_port3_CheckedChanged(this, EventArgs.Empty);
            chkKWAI_port4_CheckedChanged(this, EventArgs.Empty);
            chkKWAI_tcp_CheckedChanged(this, EventArgs.Empty);
        }

        private void udCWEdgeLength_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;

            // for variable uncomment the two lines below, and comment the fixed DL1YCF and VE3NEA CW Edges
            // note: grpCWEdgeLength.Visible = false in the form design, and as this is called from ForceAllEvents()
            // we can make visible here to keep it all together
            //grpCWEdgeLength.Visible = true;            
            //NetworkIO.SetCWEdgeLength((int)udCWEdgeLength.Value);

            // for DL1YCF CW Edge
            NetworkIO.SetCWEdgeLength(9);

            // for VE3NEA CW Edge
            //NetworkIO.SetCWEdgeLength(15);
        }

        private void radDSPNR2TRND_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (radDSPNR2TRND.Checked)
            {
                console.radio.GetDSPRX(0, 0).RXANR2GainMethod = 3;
                console.radio.GetDSPRX(0, 1).RXANR2GainMethod = 3;
            }
        }

        private void radDSPNR2TRNDRX2_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (radDSPNR2TRNDRX2.Checked)
            {
                console.radio.GetDSPRX(1, 0).RXANR2GainMethod = 3;
                console.radio.GetDSPRX(1, 1).RXANR2GainMethod = 3;
            }
        }

        private void radDSPNR2NSTAT_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (radDSPNR2NSTAT.Checked)
            {
                console.radio.GetDSPRX(0, 0).RXANR2NPEMethod = 2;
                console.radio.GetDSPRX(0, 1).RXANR2NPEMethod = 2;
            }
        }

        private void radDSPNR2NSTATRX2_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (radDSPNR2NSTATRX2.Checked)
            {
                console.radio.GetDSPRX(1, 0).RXANR2NPEMethod = 2;
                console.radio.GetDSPRX(1, 1).RXANR2NPEMethod = 2;
            }
        }

        private void udDSPNR2trainThresh_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            WDSP.SetRXAEMNRtrainZetaThresh(WDSP.id(0, 0), (double)udDSPNR2trainThresh.Value);
            WDSP.SetRXAEMNRtrainZetaThresh(WDSP.id(0, 1), (double)udDSPNR2trainThresh.Value);
        }

        private void udDSPNR2trainThreshRX2_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            WDSP.SetRXAEMNRtrainZetaThresh(WDSP.id(2, 0), (double)udDSPNR2trainThreshRX2.Value);
            WDSP.SetRXAEMNRtrainZetaThresh(WDSP.id(2, 1), (double)udDSPNR2trainThreshRX2.Value);
        }

        private void radBelow30_CheckedChanged(object sender, EventArgs e)
        {
            if (radBelow30.Checked)
                console.S9Frequency = 30.0;
        }

        private void radBelow144_CheckedChanged(object sender, EventArgs e)
        {
            if (radBelow144.Checked)
                console.S9Frequency = 144.0;
        }

        private void udSwrProtectionLimit_ValueChanged(object sender, EventArgs e)
        {
            console.SwrProtectionLimit = (float)udSwrProtectionLimit.Value;
        }

        private void udTunePowerSwrIgnore_ValueChanged(object sender, EventArgs e)
        {
            console.TunePowerSwrIgnore = (float)udTunePowerSwrIgnore.Value;
        }

        private void chkShowFormStartup_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            CheckBoxTS chk = sender as CheckBoxTS;
            if (chk == null) return;

            string id = chk.Name.Substring(chk.Name.IndexOf("_") + 1).ToLower();

            console.SetAutoFormStartSetting(id, chk.Checked);
        }
        public void UpdateAutoStartForms()
        {
            foreach (Control c in chkShowFormStartup_setup.Parent.Controls)
            {
                CheckBox cc = c as CheckBoxTS;
                if (cc != null)
                {
                    string id = cc.Name.Substring(cc.Name.IndexOf("_") + 1).ToLower();
                    cc.Checked = console.GetAutoFormStartSetting(id);
                }
            }
        }

        private void chkDisableHPFonPS_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (sender == chkDisableHPFonPSb && !chkDisableHPFonPSb.Checked)
            {
                //msg to ask if user wants to do this
                DialogResult dr = MessageBox.Show("Including the BPFs during a PureSignal tranmission may produce passive Inter-Modulation Distortion in the inductors of the bandpass filters.\n\n" +
                    "You will NOT be able to observe this degraded performance on the panadapter because PS is correcting to the distorted feedback and the panadapter is \"seeing\" that same distorted feedback. " +
                    "It can only be observed with an external spectrum analyzer.\n\nPlease ensure you understand the implications of inlcuding the BPFs when transmitting a PureSignal based signal. It is not recommended.", "PureSignal Issue",
                    MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, Common.MB_TOPMOST);
                if (dr == DialogResult.Cancel)
                {
                    chkDisableHPFonPSb.Checked = true;
                    return;
                }
            }
            console.DisableHPFonPS = chkDisableHPFonPSb.Checked;
            if (console.path_Illustrator != null)
                console.path_Illustrator.pi_Changed();
        }

        private void txtAutoLaunchFile_TextChanged(object sender, EventArgs e)
        {

        }

        private void btnAutoLaunchSelectFile_Click(object sender, EventArgs e)
        {
            if (initializing) return;

            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.Filter = "Executable files (*.exe)|*.exe|Command files (*.cmd)|*.cmd|Batch files (*.bat)|*.bat|All files (*.*)|*.*";
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    ButtonTS bb = sender as ButtonTS;
                    if (bb != null)
                    {
                        string id = bb.Name.Substring(bb.Name.IndexOf("_") + 1).ToLower();
                        grpAutoLaunchFiles.Controls["txtAutoLaunchFile_" + id.ToString()].Text = openFileDialog.FileName;
                    }
                }
            }
        }

        private void chkAutoLaunch_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            CheckBoxTS cc = sender as CheckBoxTS;
            if (cc == null) return;
            string id = cc.Name.Substring(cc.Name.IndexOf("_") + 1).ToLower();
            //chkAutoLaunch_0
            //txtAutoLaunchFile_0
            //btnAutoLaunchSelectFile_0
            grpAutoLaunchFiles.Controls["txtAutoLaunchFile_" + id.ToString()].Enabled = cc.Checked;
            grpAutoLaunchFiles.Controls["btnAutoLaunchSelectFile_" + id.ToString()].Enabled = cc.Checked;
        }
        private void updateAutoLaunchControls()
        {
            bool old_init = initializing;
            initializing = false; // need this as chkAutoLaunch_CheckedChanged is protected
            for (int i = 0; i < 10; i++)
            {
                chkAutoLaunch_CheckedChanged(grpAutoLaunchFiles.Controls["chkAutoLaunch_" + i.ToString()], EventArgs.Empty);
            }
            initializing = old_init;
        }
        public string[] GetAutoLaunchFiles()
        {
            List<string> files = new List<string>();
            for (int i = 0; i < 10; i++)
            {
                CheckBoxTS cc = grpAutoLaunchFiles.Controls["chkAutoLaunch_" + i.ToString()] as CheckBoxTS;
                if (cc != null && cc.Checked)
                {
                    TextBoxTS ts = grpAutoLaunchFiles.Controls["txtAutoLaunchFile_" + i.ToString()] as TextBoxTS;
                    if (ts != null)
                    {
                        files.Add(ts.Text);
                    }
                }
            }
            return files.ToArray();
        }
        public bool AutoLaunchNoStartIfRunning
        {
            get { return chkAutoLaunchNoStartIfRunning.Checked; }
        }
        public bool AutoLaunchTryToClose
        {
            get { return chkAutoLaunchTryToClose.Checked; }
        }

        private void clrbtnTXAttenuationBackground_Changed(object sender, EventArgs e)
        {
            if (initializing) return;
            console.TxAttenuationBackgroundColour = Color.FromArgb(255, clrbtnTXAttenuationBackground.Color);
        }

        private void chkMeterItemFadeOnRxSpacer_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkMeterItemFadeOnTxSpacer_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMeterItemHBackgroundSpacerRX_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudMeterItemSpacerPadding_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMeterItemHBackgroundSpacerTX_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkTextOverlay_ShowPanel_CheckedChanged(object sender, EventArgs e)
        {
            updateTextOverlayPanelControls();
            updateMeterType();
        }
        private void updateTextOverlayPanelControls()
        {
            bool enabled = chkTextOverlay_ShowPanel.Checked;
            clrbtnTextOverlay_PanelBackground.Enabled = enabled;
            clrbtnTextOverlay_PanelBackgroundTX.Enabled = enabled;            
            nudTextOverlay_PanelPadding.Enabled = enabled;
            chkTextOverlay_FadeOnRX.Enabled = enabled;
            chkTextOverlay_FadeOnTX.Enabled = enabled;
            lblTextOverlay_panelbackground.Enabled = enabled;
            lblTextOverlay_panelbackgroundTX.Enabled = enabled;
            lblTextOverlay_panelpadding.Enabled = enabled;
        }
        private void clrbtnTextOverlay_PanelBackground_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudTextOverlay_PanelPadding_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void txtTextOverlay_RXText_TextChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void txtTextOverlay_TXText_TextChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }
        private Font _textOverlayFont1 = null;
        private Font _textOverlayFont2 = null;
        private void btnTextOverlay_Font1_Click(object sender, EventArgs e)
        {
            using (FontDialog fontDialog = new FontDialog())
            {
                fontDialog.Font = _textOverlayFont1;
                if (fontDialog.ShowDialog() == DialogResult.OK)
                {
                    if (!isFontTrueType(fontDialog.Font)) return;
                    _textOverlayFont1 = fontDialog.Font;
                    updateMeterType();
                }
            }
        }
        public bool isFontTrueType(Font f)
        {
            try
            {
                FontFamily ff = new FontFamily(f.Name);
            }
            catch (ArgumentException e)
            {
                if (e.Message.Contains("TrueType", StringComparison.OrdinalIgnoreCase))
                {
                    MessageBox.Show("This font is not a TrueType font and can not be used.",                    
                    "Font issue",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST);
                    return false;
                }                

                return false;// also if not found
            }
            return true;
        }
        private void btnTextOverlay_Font2_Click(object sender, EventArgs e)
        {
            using (FontDialog fontDialog = new FontDialog())
            {
                fontDialog.Font = _textOverlayFont2;
                if (fontDialog.ShowDialog() == DialogResult.OK)
                {
                    if (!isFontTrueType(fontDialog.Font)) return;
                    _textOverlayFont2 = fontDialog.Font;
                    updateMeterType();
                }
            }
        }

        private void clrbtnTextOverlay_TextColour1_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnTextOverlay_TextColour2_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudTextOverlay_RXxOffset_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudTextOverlay_RXyOffset_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudTextOverlay_TXxOffset_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudTextOverlay_TXyOffset_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkTextOverlay_FadeOnRX_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkTextOverlay_FadeOnTX_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void btnTextOverlay_copyoffsets_Click(object sender, EventArgs e)
        {
            nudTextOverlay_TXxOffset.Value = nudTextOverlay_RXxOffset.Value;
            nudTextOverlay_TXyOffset.Value = nudTextOverlay_RXyOffset.Value;
        }

        private void clrbtnTextOverlay_PanelBackgroundTX_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnTextOverlay_TextBackColour1_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnTextOverlay_TextBackColour2_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkTextOverlay_textback1_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
            updateTextOverlayBackTextControls();
        }

        private void chkTextOverlay_textback2_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
            updateTextOverlayBackTextControls();
        }

        private void updateTextOverlayBackTextControls()
        {
            clrbtnTextOverlay_TextBackColour1.Enabled = chkTextOverlay_textback1.Checked;
            clrbtnTextOverlay_TextBackColour2.Enabled = chkTextOverlay_textback2.Checked;
        }

        private void pbTextOverlay_variables_Click(object sender, EventArgs e)
        {
            toolTip1.Show(toolTip1.GetToolTip(pbTextOverlay_variables), pbTextOverlay_variables, 10 * 1000);
        }

        #region MultiMeter IO
        // Code for the multimeter IO - MW0LGE [2.10.3.6]
        private bool _MMIO_ignore_change_events = false;
        private void init_lstMMIO()
        {
            lstMMIO_network_list.Items.Clear();
            comboMMIO_network_format_in.Items.Clear();
            comboMMIO_network_terminator_in.Items.Clear();
            pnlMMIO_network_active.BackColor = Color.LightGray;
            pnlMMIO_network_rxdata.BackColor = Color.LightGray;
            pnlMMIO_network_txdata.BackColor = Color.LightGray;
            _light_gray_tx = 1;
            _light_gray_tx = 1;

            for (int i = (int)MultiMeterIO.MMIOFormat.JSON; i < (int)(int)MultiMeterIO.MMIOFormat.LAST; i++)
            {
                comboMMIO_network_format_in.Items.Add(((MultiMeterIO.MMIOFormat)i).ToString());
            }
            for (int i = (int)MultiMeterIO.MMIOTerminator.NONE; i < (int)(int)MultiMeterIO.MMIOTerminator.LAST; i++)
            {
                comboMMIO_network_terminator_in.Items.Add(((MultiMeterIO.MMIOTerminator)i).ToString());
            }

            _tmrRXupdate = new System.Timers.Timer(20);
            _tmrRXupdate.Elapsed += OnRxTimerTick;
            _tmrRXupdate.AutoReset = false;

            _tmrTXupdate = new System.Timers.Timer(20);
            _tmrTXupdate.Elapsed += OnTxTimerTick;
            _tmrTXupdate.AutoReset = false;

            MultiMeterIO.ClientConnected += MultiMeterIO_ClientConnected;
            MultiMeterIO.ClientDisconnected += MultiMeterIO_ClientDisconnected;
            MultiMeterIO.ReceivedDataString += MultiMeterIO_ReceivedDataString;
            MultiMeterIO.TransmittedData += MultiMeterIO_TransmittedData;
            MultiMeterIO.ConnectorRunning += MultiMeterIO_ListenerRunning;

            ConcurrentDictionary<Guid, MultiMeterIO.clsMMIO> data = MultiMeterIO.Data;
            foreach (KeyValuePair<Guid, MultiMeterIO.clsMMIO> kvp in data)
            {
                MultiMeterIO.clsMMIO mmio = kvp.Value;
                clsMultiMeterIOComboboxItem mmioci;
                if (mmio.Type == MultiMeterIO.MMIOType.SERIAL)
                {
                    mmioci = new clsMultiMeterIOComboboxItem(mmio.Guid, mmio.Type, mmio.ComPort, mmio.Direction);
                }
                else
                {
                    mmioci = new clsMultiMeterIOComboboxItem(mmio.Guid, mmio.Type, mmio.IP, mmio.Port, mmio.Direction, mmio.UdpEndpointIP, mmio.UdpEndpointPort);
                }
                int index = lstMMIO_network_list.Items.Add(mmioci);
            }
        }

        private void MultiMeterIO_ListenerRunning(Guid guid, MultiMeterIO.MMIOType type, bool enabled)
        {
            if (initializing || !lstMMIO_network_list.IsHandleCreated) return;
            try
            {
                lstMMIO_network_list.BeginInvoke(new MethodInvoker(() =>
                {
                    lstMMIO_network_list_SelectedIndexChanged(this, EventArgs.Empty);
                }));
            }
            catch { }
        }
        private void MultiMeterIO_ClientConnected(Guid guid)
        {
            if (initializing || !lstMMIO_network_list.IsHandleCreated) return;
            try
            {
                lstMMIO_network_list.BeginInvoke(new MethodInvoker(() =>
                {
                    lstMMIO_network_list_SelectedIndexChanged(this, EventArgs.Empty);
                }));
            }
            catch { }
        }

        private void MultiMeterIO_ClientDisconnected(Guid guid)
        {
            if (initializing || !lstMMIO_network_list.IsHandleCreated) return;
            try
            {
                lstMMIO_network_list.BeginInvoke(new MethodInvoker(() =>
                {
                    lstMMIO_network_list_SelectedIndexChanged(this, EventArgs.Empty);
                }));
            }
            catch { }
        }
        private System.Timers.Timer _tmrRXupdate;
        private System.Timers.Timer _tmrTXupdate;
        private double _light_gray_rx = 1f;
        private double _light_gray_tx = 1f;
        public void MultiMeterIOStopTimers()
        {
            if (_tmrRXupdate != null)
            {
                _tmrRXupdate.Stop();
                _tmrRXupdate.Elapsed -= OnRxTimerTick;
                _tmrRXupdate.Close();
                _tmrRXupdate = null;
            }
            if (_tmrTXupdate != null)
            {
                _tmrTXupdate.Stop();
                _tmrTXupdate.Elapsed -= OnTxTimerTick;
                _tmrTXupdate.Close();
                _tmrTXupdate = null;
            }
        }
        private void OnRxTimerTick(object sender, ElapsedEventArgs e)
        {
            try
            {
                _light_gray_rx += 0.08;
                if (_light_gray_rx > 1f)
                    _light_gray_rx = 1f;

                Color c = ColorInterpolator.InterpolateBetween(Color.LimeGreen, Color.LightGray, _light_gray_rx);
                pnlMMIO_network_rxdata.BackColor = c;

                if (_light_gray_rx < 1f && pnlMMIO_network_rxdata.Visible)
                    _tmrRXupdate.Start();
            }
            catch { }
        }
        private void OnTxTimerTick(object sender, ElapsedEventArgs e)
        {
            try
            {
                _light_gray_tx += 0.08;
                if (_light_gray_tx > 1f)
                    _light_gray_tx = 1f;

                Color c = ColorInterpolator.InterpolateBetween(Color.Red, Color.LightGray, _light_gray_tx);
                pnlMMIO_network_txdata.BackColor = c;

                if (_light_gray_tx < 1f && pnlMMIO_network_txdata.Visible)
                    _tmrTXupdate.Start();
            }
            catch { }
        }
        private void MultiMeterIO_ReceivedDataString(Guid guid, string dataString)
        {
            if (initializing || !lstMMIO_network_list.IsHandleCreated) return;
            try
            {
                lstMMIO_network_list.BeginInvoke(new MethodInvoker(() =>
                {
                    updateFromRecievedData(guid, dataString);
                }));
            }
            catch { }            
        }
        private void MultiMeterIO_TransmittedData(Guid guid)
        {
            if (initializing || !lstMMIO_network_list.IsHandleCreated) return;
            try
            {
                lstMMIO_network_list.BeginInvoke(new MethodInvoker(() =>
                {
                    updateFromTransmittedData(guid);
                }));
            }
            catch { }
        }
        private void updateFromRecievedData(Guid guid, string dataString)
        {
            if (!pnlMMIO_network_rxdata.Visible) return;
            clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
            if (mmioci == null) return;
            if (mmioci.Guid != guid) return;

            pnlMMIO_network_rxdata.BackColor = Color.LimeGreen;
            _light_gray_rx = 0f;
            _tmrRXupdate.Start();

            updateVariableList();
        }
        private void updateFromTransmittedData(Guid guid)
        {
            if (!pnlMMIO_network_rxdata.Visible) return;
            clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
            if (mmioci == null) return;
            if (mmioci.Guid != guid) return;

            pnlMMIO_network_txdata.BackColor = Color.Red;
            _light_gray_tx = 0f;
            _tmrTXupdate.Start();
        }
        private void updateVariableList()
        {
            clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
            if (mmioci == null) return;

            ListView.SelectedListViewItemCollection items = lstMMIO_network_variables.SelectedItems;
            string selectedKey = items.Count == 1 ? items[0].Text : "";

            btnMMIO_network_remove_variable.Enabled = items.Count > 0;
            btnMMIO_network_copyvariable_clipboard.Enabled = items.Count > 0;
            if (!MultiMeterIO.Data.ContainsKey(mmioci.Guid)) return;

            MultiMeterIO.clsMMIO mmio = MultiMeterIO.Data[mmioci.Guid];
            lstMMIO_network_variables.SuspendLayout();
            // remove any from list that are now not in variables
            List<ListViewItem> to_remove = new List<ListViewItem>();
            foreach (ListViewItem lvi in lstMMIO_network_variables.Items)
            {
                if (!mmio.Variables().ContainsKey(lvi.Text)) to_remove.Add(lvi);
            }
            foreach (ListViewItem lvi in to_remove)
            {
                lstMMIO_network_variables.Items.Remove(lvi);
            }
            to_remove.Clear();

            //add/update list
            foreach (KeyValuePair<string, object> kvp in mmio.Variables())
            {
                string type;
                if (kvp.Value is int)
                    type = "int";
                else if (kvp.Value is float)
                    type = "float";
                else if (kvp.Value is double)
                    type = "double";
                else if (kvp.Value is bool)
                    type = "bool";
                else
                    type = "string";

                ListViewItem lvi;
                if (!lstMMIO_network_variables.Items.ContainsKey(kvp.Key))
                {
                    lvi = lstMMIO_network_variables.Items.Add(kvp.Key, kvp.Key, null);
                    lvi.SubItems.Add(mmio.VariableValueType(kvp.Value));
                    lvi.SubItems.Add(type);
                }
                else
                {
                    lvi = lstMMIO_network_variables.Items[kvp.Key];
                    lvi.SubItems[1].Text = mmio.VariableValueType(kvp.Value);      //[1] bizzar that it is index 1 for the added subitem
                    lvi.SubItems[2].Text = type;
                }

                if (selectedKey != "" && kvp.Key == selectedKey)
                    lvi.Selected = true;
            }
            lstMMIO_network_variables.ResumeLayout(false);
            lstMMIO_network_variables.Invalidate();
            btnMMIO_network_remove_all_variables.Enabled = lstMMIO_network_variables.Items.Count > 0;
        }
        private void lstMMIO_network_list_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            int selected_index = lstMMIO_network_list.SelectedIndex;
            pnlMMIO_network_container.Enabled = selected_index != -1;
            btnMMIO_network_delete.Enabled = selected_index != -1;
            if (selected_index == -1)
            {
                pnlMMIO_network_rxdata.BackColor = Color.LightGray;
                pnlMMIO_network_txdata.BackColor = Color.LightGray;
                pnlMMIO_network_active.BackColor = Color.LightGray;
                lstMMIO_network_variables.Items.Clear();
                picMutliMeterIO_udp_out_warning.Visible = false;
                return;
            }

            clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
            if (mmioci == null) return;

            if (!MultiMeterIO.Data.ContainsKey(mmioci.Guid)) return;
            MultiMeterIO.clsMMIO mmio = MultiMeterIO.Data[mmioci.Guid];

            _MMIO_ignore_change_events = true;
            if (mmio.Type == MultiMeterIO.MMIOType.SERIAL)
            {
                txtMMIO_network_ip_port.Text = mmio.ComPort;
            }
            else
            {
                txtMMIO_network_ip_port.Text = mmio.IP + ":" + mmio.Port.ToString();
            }
            txtMMIO_network_4char.Text = mmio.FourChar;
            _MMIO_ignore_change_events = false;

            pnlMMIO_network_active.BackColor = mmio.Active ? Color.LimeGreen : Color.LightGray;
            pnlMMIO_network_rxdata.BackColor = Color.LightGray;
            pnlMMIO_network_txdata.BackColor = Color.LightGray;
            _light_gray_tx = 1;
            _light_gray_tx = 1;
            comboMMIO_network_format_in.SelectedIndex = (int)mmio.FormatIn;
            comboMMIO_network_terminator_in.SelectedIndex = (int)mmio.TerminatorIn;
            comboMMIO_network_format_out.SelectedIndex = (int)mmio.FormatOut;
            comboMMIO_network_terminator_out.SelectedIndex = (int)mmio.TerminatorOut;

            txtMMIO_network_udp_endpoint_ip_port.Text = mmio.UdpEndpointIP + ":" + mmio.UdpEndpointPort.ToString();

            _MMIO_ignore_change_events = true;
            txtMMIO_network_terminator_in_custom.Text = mmio.CustomTerminatorIn;
            txtMMIO_network_terminator_out_custom.Text = mmio.CustomTerminatorOut;
            _MMIO_ignore_change_events = false;

            switch (mmio.Direction)
            {
                case MultiMeterIO.MMIODirection.IN:
                    radMMIO_network_in.Checked = true;
                    break;
                case MultiMeterIO.MMIODirection.OUT:
                    radMMIO_network_out.Checked = true;
                    break;
                case MultiMeterIO.MMIODirection.BOTH:
                    radMMIO_network_both.Checked = true;
                    break;
            }

            _MMIO_ignore_change_events = true;
            chkMMIO_network_enabled.Checked = mmio.Enabled;
            _MMIO_ignore_change_events = false;

            updateVariableList();
            updateDirection(mmio);
            updateTerminators(mmio);
        }
        private void showSerialPortPicker(MultiMeterIO.MMIOType type, string existsing_com_port, int baud_rate, int data_bits, StopBits stop_bits, Parity parity)
        {
            bool adding = string.IsNullOrEmpty(existsing_com_port);
            bool stoppedConnection = false;

            //MultiMeterIO.clsMMIO mmio;
            //mmio = new MultiMeterIO.clsMMIO(MultiMeterIO.MMIOType.SERIAL, "com3", 38000, 8, StopBits.One, Parity.None, true);
            //MultiMeterIO.AddMMIO(mmio);

            //bool ok = mmio.StartConnection();

            //clsMultiMeterIOComboboxItem mmioci = new clsMultiMeterIOComboboxItem(mmio.Guid, MultiMeterIO.MMIOType.SERIAL, mmio.ComPort, mmio.Direction);
            //int index = lstMMIO_network_list.Items.Add(mmioci);
            //lstMMIO_network_list.SelectedIndex = index;

            frmSerialPortPicker sp = new frmSerialPortPicker();
            sp.ComPort = existsing_com_port;
            if (adding)
            {
                sp.BaudRate = 9600;
                sp.DataBits = 8;
                sp.StopBits  = StopBits.One;
                sp.Parity = Parity.None;
            }
            else
            {
                sp.BaudRate = baud_rate;
                sp.DataBits = data_bits;
                sp.StopBits = stop_bits;
                sp.Parity = parity;
            }
            // if edit, shut down com port
            if (!adding)
            {
                clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
                if (mmioci != null)
                {
                    if (MultiMeterIO.Data.ContainsKey(mmioci.Guid))
                    {
                        MultiMeterIO.clsMMIO mmio = MultiMeterIO.Data[mmioci.Guid];
                        mmio.StopConnection();
                        stoppedConnection = true;
                    }
                }
            }
            //
            sp.Init();
            DialogResult dr = sp.ShowDialog();
            if (dr == DialogResult.OK)
            {
                bool ok = false;
                MultiMeterIO.clsMMIO mmio = null;
                if (adding)
                {
                    mmio = new MultiMeterIO.clsMMIO(MultiMeterIO.MMIOType.SERIAL, sp.ComPort, sp.BaudRate, sp.DataBits, sp.StopBits, sp.Parity, true);
                    MultiMeterIO.AddMMIO(mmio);
                    ok = mmio.StartConnection();
                }
                else
                {
                    clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
                    if (mmioci != null)
                    {
                        if (MultiMeterIO.Data.ContainsKey(mmioci.Guid))
                        {
                            mmio = MultiMeterIO.Data[mmioci.Guid];
                            mmio.StopConnection();
                            mmio.ComPort = sp.ComPort;
                            mmio.BaudRate = sp.BaudRate;
                            mmio.DataBits = sp.DataBits;
                            mmio.StopBits = sp.StopBits;
                            mmio.Parity = sp.Parity;
                            ok = mmio.StartConnection();
                            stoppedConnection = false;
                        }
                    }
                }
                if (ok && mmio != null)
                {
                    if (adding)
                    {
                        clsMultiMeterIOComboboxItem mmioci = new clsMultiMeterIOComboboxItem(mmio.Guid, type, mmio.ComPort, mmio.Direction);
                        int index = lstMMIO_network_list.Items.Add(mmioci);
                        lstMMIO_network_list.SelectedIndex = index;
                    }
                    else
                    {
                        clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
                        if (mmioci != null)
                        {
                            mmioci.ComPort = mmio.ComPort;
                            lstMMIO_network_list.Items[lstMMIO_network_list.SelectedIndex] = mmioci;
                        }
                    }
                }
                else
                {
                    MultiMeterIO.RemoveMMIO(mmio.Guid);
                    MessageBox.Show("There was a problem starting the serial port connector.",
                    "Serial Start Problem",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST);
                }
            }
            if (stoppedConnection)
            {
                clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
                if (mmioci != null)
                {
                    if (MultiMeterIO.Data.ContainsKey(mmioci.Guid))
                    {
                        MultiMeterIO.clsMMIO mmio = MultiMeterIO.Data[mmioci.Guid];
                        mmio.StartConnection();
                    }
                }
            }
        }
        private void addEditConnector(MultiMeterIO.MMIOType type, bool check_same, string existing_ip_port = "", string existsing_com_port = "", int baud_rate = 0, int data_bits = 0, StopBits stop_bits = StopBits.One, Parity parity = Parity.None)
        {
            string protocol = "";
            string bind = "";
            switch (type)
            {
                case MultiMeterIO.MMIOType.UDP_LISTENER:
                    protocol = "UDP Listener";
                    bind = "bind";
                    break;
                case MultiMeterIO.MMIOType.TCPIP_LISTENER:
                    protocol = "TCP/IP Server";
                    bind = "bind";
                    break;
                case MultiMeterIO.MMIOType.TCPIP_CLIENT:
                    protocol = "TCP/IP Client";
                    bind = "destination";
                    break;
                case MultiMeterIO.MMIOType.SERIAL:
                    protocol = "SERIAL";
                    bind = "";
                    break;
            }

            if (type == MultiMeterIO.MMIOType.SERIAL)
            {
                showSerialPortPicker(type, existsing_com_port, baud_rate, data_bits, stop_bits, parity);
            }
            else
            {
                string ip_port;
                bool adding = string.IsNullOrEmpty(existing_ip_port);
                if (adding)
                    ip_port = InputBox.Show("Add " + protocol, "Please provide " + bind + " details:", "127.0.0.1:9000");
                else
                    ip_port = InputBox.Show("Edit " + protocol, "Please edit " + bind + " details:", existing_ip_port);
                if (string.IsNullOrEmpty(ip_port)) return;

                string[] parts = ip_port.Split(':');
                if (parts.Length == 2)
                {
                    string ip = parts[0];
                    string port = parts[1];

                    bool ok = int.TryParse(port, out int portInt);
                    if (ok)
                    {
                        if(portInt < 0 || portInt > 65535) // bad port
                        {
                            MessageBox.Show("The port needs to be in the range 0-65535",
                            "Listener Start Problem",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST);
                            return;
                        }
                        if (check_same && (ip + ":" + portInt.ToString() == existing_ip_port)) return; // same as input, forget it

                        if (!MultiMeterIO.AlreadyConfigured(ip, portInt, type))
                        {
                            MultiMeterIO.clsMMIO mmio;
                            if (adding)
                            {
                                mmio = new MultiMeterIO.clsMMIO(type, ip, portInt, true);
                                MultiMeterIO.AddMMIO(mmio);
                            }
                            else
                            {
                                //edit
                                clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
                                if (mmioci != null)
                                {
                                    if (MultiMeterIO.Data.ContainsKey(mmioci.Guid))
                                    {
                                        mmio = MultiMeterIO.Data[mmioci.Guid];
                                        mmio.StopConnection();
                                        mmio.IP = ip;
                                        mmio.Port = portInt;
                                    }
                                    else
                                        return;
                                }
                                else
                                    return;
                            }

                            ok = mmio.StartConnection();

                            if (ok)
                            {
                                if (adding)
                                {
                                    clsMultiMeterIOComboboxItem mmioci = new clsMultiMeterIOComboboxItem(mmio.Guid, type, ip, portInt, mmio.Direction, mmio.UdpEndpointIP, mmio.UdpEndpointPort);
                                    int index = lstMMIO_network_list.Items.Add(mmioci);
                                    lstMMIO_network_list.SelectedIndex = index;
                                }
                                else
                                {
                                    clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
                                    if (mmioci != null)
                                    {
                                        mmioci.IP = ip;
                                        mmioci.Port = portInt;
                                        lstMMIO_network_list.Items[lstMMIO_network_list.SelectedIndex] = mmioci;
                                    }
                                    else
                                        return;
                                }
                            }
                            else
                            {
                                MultiMeterIO.RemoveMMIO(mmio.Guid);
                                MessageBox.Show("There was a problem starting the " + protocol + ". Perhaps there is an ip:port conflict.",
                                "Listener Start Problem",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST);
                            }
                        }
                        else
                        {
                            if (!adding)
                            {
                                MessageBox.Show("This IP:PORT combination already has a " + protocol + ".\n\nThe edited IP/Port needs to be to a combination that is not already in use.",
                                    "Duplicate Listener",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST);
                            }
                            else
                            {
                                MessageBox.Show("This IP:PORT combination already has a " + protocol + ".",
                                    "Duplicate Listener",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST);
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Incorrect port format. Please use the following format.\n\nIP:PORT\n\nExample: 127.0.0.1:9000",
                            "Incorrect Format",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST);
                    }
                }
                else
                {
                    MessageBox.Show("Incorrect format. Please use the following format.\n\nIP:PORT\n\nExample: 127.0.0.1:9000",
                        "Incorrect Format",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST);
                }
            }
        }
        private void radMMIO_network_add_udp_Click(object sender, EventArgs e)
        {
            addEditConnector(MultiMeterIO.MMIOType.UDP_LISTENER, true);
        }

        private void btnMMIO_network_add_tcpip_Click(object sender, EventArgs e)
        {
            addEditConnector(MultiMeterIO.MMIOType.TCPIP_LISTENER, true);
        }

        private void btnMMIO_network_delete_Click(object sender, EventArgs e)
        {
            if (lstMMIO_network_list.SelectedIndex < 0) return;
            clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
            if (mmioci != null)
            {
                MultiMeterIO.RemoveMMIO(mmioci.Guid);
                lstMMIO_network_list.Items.Remove(mmioci);
            }
        }

        private void txtMMIO_network_ip_port_TextChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (_MMIO_ignore_change_events) return;
        }

        private void txtMMIO_network_ip_port_Click(object sender, EventArgs e)
        {
            pnlMMIO_network_container.Focus();
            clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
            if (mmioci == null) return;
            if (!MultiMeterIO.Data.ContainsKey(mmioci.Guid)) return;

            MultiMeterIO.clsMMIO mmio = MultiMeterIO.Data[mmioci.Guid];

            if (mmio.Type == MultiMeterIO.MMIOType.SERIAL)
            {
                addEditConnector(mmio.Type, true, "", txtMMIO_network_ip_port.Text, mmio.BaudRate, mmio.DataBits, mmio.StopBits, mmio.Parity);
            }
            else
            {
                addEditConnector(mmio.Type, true, txtMMIO_network_ip_port.Text);
            }
        }

        private void btnMMIO_network_ip_port_ip4_Click(object sender, EventArgs e)
        {
            clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
            if (mmioci == null) return;

            string orig = mmioci.IP + ":" + mmioci.Port.ToString();
            frmIPv4Picker f = new frmIPv4Picker();
            f.Init(orig);
            DialogResult dr = f.ShowDialog(this);

            if (dr == DialogResult.OK)
            {
                string sTmp = f.IP;
                if (sTmp == "") sTmp = "127.0.0.1:9000";
                
                if (sTmp != orig)
                    addEditConnector(mmioci.Type, false, sTmp);
            }
        }

        private void txtMMIO_network_4char_TextChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (_MMIO_ignore_change_events) return;
        }

        private void radMMIO_network_in_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (!radMMIO_network_in.Checked) return;
            clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
            if (mmioci == null) return;
            if (!MultiMeterIO.Data.ContainsKey(mmioci.Guid)) return;

            MultiMeterIO.Data[mmioci.Guid].Direction = MultiMeterIO.MMIODirection.IN;
            mmioci.Direction = MultiMeterIO.MMIODirection.IN;

            int i = lstMMIO_network_list.Items.IndexOf(mmioci);
            adjustHeightOfMMIOcomboItem(i,itemHeight(mmioci));
            lstMMIO_network_list.Invalidate();

            updateDirection(MultiMeterIO.Data[mmioci.Guid]);
            updateTerminators(MultiMeterIO.Data[mmioci.Guid]);
        }
        private const int LB_SETITEMHEIGHT = 0x01A0;

        [DllImport("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
        private void adjustHeightOfMMIOcomboItem(int i, int height)
        {
            //to fix issue where MesureItem although called and updates the height does not result in the
            //listbox item actually changing visually.
            //https://stackoverflow.com/questions/28490543/windows-forms-listbox-with-ownerdrawvariable-bug
            SendMessage((IntPtr)lstMMIO_network_list.Handle, LB_SETITEMHEIGHT, (IntPtr)i, (IntPtr)height);
        }
        private void radMMIO_network_out_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (!radMMIO_network_out.Checked) return;
            clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
            if (mmioci == null) return;
            if (!MultiMeterIO.Data.ContainsKey(mmioci.Guid)) return;

            MultiMeterIO.Data[mmioci.Guid].Direction = MultiMeterIO.MMIODirection.OUT;
            mmioci.Direction = MultiMeterIO.MMIODirection.OUT;

            int i = lstMMIO_network_list.Items.IndexOf(mmioci);
            adjustHeightOfMMIOcomboItem(i, itemHeight(mmioci));
            lstMMIO_network_list.Invalidate();

            updateDirection(MultiMeterIO.Data[mmioci.Guid]);
            updateTerminators(MultiMeterIO.Data[mmioci.Guid]);
        }

        private void radMMIO_network_both_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (!radMMIO_network_both.Checked) return;
            clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
            if (mmioci == null) return;
            if (!MultiMeterIO.Data.ContainsKey(mmioci.Guid)) return;

            MultiMeterIO.Data[mmioci.Guid].Direction = MultiMeterIO.MMIODirection.BOTH;
            mmioci.Direction = MultiMeterIO.MMIODirection.BOTH;

            int i = lstMMIO_network_list.Items.IndexOf(mmioci);
            adjustHeightOfMMIOcomboItem(i, itemHeight(mmioci));
            lstMMIO_network_list.Invalidate();

            updateDirection(MultiMeterIO.Data[mmioci.Guid]);
            updateTerminators(MultiMeterIO.Data[mmioci.Guid]);
        }
        private void updateTerminators(MultiMeterIO.clsMMIO mmio)
        {
            if (mmio == null) return;

            txtMMIO_network_terminator_in_custom.Visible = mmio.TerminatorIn == MultiMeterIO.MMIOTerminator.CUSTOM && mmio.Direction != MultiMeterIO.MMIODirection.OUT;
            txtMMIO_network_terminator_out_custom.Visible = mmio.TerminatorOut == MultiMeterIO.MMIOTerminator.CUSTOM && mmio.Direction != MultiMeterIO.MMIODirection.IN;
        }
        private void updateDirection(MultiMeterIO.clsMMIO mmio)
        {
            if (mmio == null) return;
            if (mmio.Type == MultiMeterIO.MMIOType.SERIAL)
            { 
                lblMMIO_network_ip_port.Text = "Com Port:";
                btnMMIO_network_ip_port_ip4.Visible = false;
            }
            else
            {
                if (mmio.Type == MultiMeterIO.MMIOType.TCPIP_CLIENT)
                {
                    lblMMIO_network_ip_port.Text = "Destination:";
                }
                else
                {
                    lblMMIO_network_ip_port.Text = "Bind IP:Port";
                }
                btnMMIO_network_ip_port_ip4.Visible = true;
            }
            switch (mmio.Direction)
            {
                case MultiMeterIO.MMIODirection.IN:
                    lblMMIO_network_format_in.Enabled = true;
                    comboMMIO_network_format_in.Enabled = true;
                    lblMMIO_network_format_out.Enabled = false;
                    comboMMIO_network_format_out.Enabled = false;

                    lblMMIO_network_terminator_in.Enabled = true;
                    comboMMIO_network_terminator_in.Enabled = true;
                    lblMMIO_network_terminator_out.Enabled = false;
                    comboMMIO_network_terminator_out.Enabled = false;

                    lblMMIO_network_rxdata.Enabled = true;
                    pnlMMIO_network_rxdata.Enabled = true;

                    lblMMIO_network_txdata.Enabled = false;
                    pnlMMIO_network_txdata.Enabled = false;

                    lblMMIO_network_udp_endpoint_ip_port.Enabled = false;
                    txtMMIO_network_udp_endpoint_ip_port.Enabled = false;
                    btnMMIO_network_udp_endpoint_ip_port.Enabled = false;

                    lblMMIO_network_ip_port.Enabled = true;
                    txtMMIO_network_ip_port.Enabled = true;
                    btnMMIO_network_ip_port_ip4.Enabled = true;

                    txtMMIO_network_udp_endpoint_ip_port.Text = "";
                    picMutliMeterIO_udp_out_warning.Visible = false;

                    break;
                case MultiMeterIO.MMIODirection.OUT:
                    lblMMIO_network_format_in.Enabled = false;
                    comboMMIO_network_format_in.Enabled = false;
                    lblMMIO_network_format_out.Enabled = true;
                    comboMMIO_network_format_out.Enabled = true;

                    lblMMIO_network_terminator_in.Enabled = false;
                    comboMMIO_network_terminator_in.Enabled = false;
                    lblMMIO_network_terminator_out.Enabled = true;
                    comboMMIO_network_terminator_out.Enabled = true;

                    lblMMIO_network_rxdata.Enabled = false;
                    pnlMMIO_network_rxdata.Enabled = false;

                    lblMMIO_network_txdata.Enabled = true;
                    pnlMMIO_network_txdata.Enabled = true;

                    lblMMIO_network_udp_endpoint_ip_port.Enabled = mmio.Type == MultiMeterIO.MMIOType.UDP_LISTENER;
                    txtMMIO_network_udp_endpoint_ip_port.Enabled = mmio.Type == MultiMeterIO.MMIOType.UDP_LISTENER;
                    btnMMIO_network_udp_endpoint_ip_port.Enabled = mmio.Type == MultiMeterIO.MMIOType.UDP_LISTENER;

                    if (mmio.Type == MultiMeterIO.MMIOType.UDP_LISTENER)
                    {
                        lblMMIO_network_ip_port.Enabled = false;
                        txtMMIO_network_ip_port.Enabled = false;
                        btnMMIO_network_ip_port_ip4.Enabled = false;
                        picMutliMeterIO_udp_out_warning.Visible = true;

                        txtMMIO_network_udp_endpoint_ip_port.Text = mmio.UdpEndpointIP + ":" + mmio.UdpEndpointPort.ToString();
                    }
                    else
                    {
                        lblMMIO_network_ip_port.Enabled = true;
                        txtMMIO_network_ip_port.Enabled = true;
                        btnMMIO_network_ip_port_ip4.Enabled = true;
                        picMutliMeterIO_udp_out_warning.Visible = false;

                        txtMMIO_network_udp_endpoint_ip_port.Text = "";
                    }

                    break;
                case MultiMeterIO.MMIODirection.BOTH:
                    lblMMIO_network_format_in.Enabled = true;
                    comboMMIO_network_format_in.Enabled = true;
                    lblMMIO_network_format_out.Enabled = true;
                    comboMMIO_network_format_out.Enabled = true;

                    lblMMIO_network_terminator_in.Enabled = true;
                    comboMMIO_network_terminator_in.Enabled = true;
                    lblMMIO_network_terminator_out.Enabled = true;
                    comboMMIO_network_terminator_out.Enabled = true;

                    lblMMIO_network_rxdata.Enabled = true;
                    pnlMMIO_network_rxdata.Enabled = true;

                    lblMMIO_network_txdata.Enabled = true;
                    pnlMMIO_network_txdata.Enabled = true;

                    lblMMIO_network_udp_endpoint_ip_port.Enabled = mmio.Type == MultiMeterIO.MMIOType.UDP_LISTENER;
                    txtMMIO_network_udp_endpoint_ip_port.Enabled = mmio.Type == MultiMeterIO.MMIOType.UDP_LISTENER;
                    btnMMIO_network_udp_endpoint_ip_port.Enabled = mmio.Type == MultiMeterIO.MMIOType.UDP_LISTENER;

                    lblMMIO_network_ip_port.Enabled = true;
                    txtMMIO_network_ip_port.Enabled = true;
                    btnMMIO_network_ip_port_ip4.Enabled = true;
                    picMutliMeterIO_udp_out_warning.Visible = false;

                    if (mmio.Type == MultiMeterIO.MMIOType.UDP_LISTENER)
                        txtMMIO_network_udp_endpoint_ip_port.Text = mmio.UdpEndpointIP + ":" + mmio.UdpEndpointPort.ToString();
                    else
                        txtMMIO_network_udp_endpoint_ip_port.Text = "";

                    break;
            }
        }
        private void comboMMIO_network_format_in_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
            if (mmioci == null) return;

            bool ok = Enum.TryParse<MultiMeterIO.MMIOFormat>(comboMMIO_network_format_in.Text, out MultiMeterIO.MMIOFormat fmt);

            if (ok) MultiMeterIO.Data[mmioci.Guid].FormatIn = fmt;
        }
        private class clsMultiMeterIOComboboxItem
        {
            private Guid _guid;
            private MultiMeterIO.MMIOType _type;
            private string _ip;
            private int _port;
            private MultiMeterIO.MMIODirection _direction;
            private string _udp_endpoint_ip;
            private int _udp_endpoint_port;
            private string _com_port;
            
            public clsMultiMeterIOComboboxItem(Guid guid, MultiMeterIO.MMIOType type, string ip, int port, MultiMeterIO.MMIODirection direction, string udp_endpoint_ip, int udp_endpoint_port)
            {
                _guid = guid;
                _type = type;
                _ip = ip;
                _port = port;
                _direction = direction;
                _udp_endpoint_ip = udp_endpoint_ip;
                _udp_endpoint_port = udp_endpoint_port;
                _com_port = "";
            }
            public clsMultiMeterIOComboboxItem(Guid guid, MultiMeterIO.MMIOType type, string com_port, MultiMeterIO.MMIODirection direction)
            {
                _guid = guid;
                _type = type;
                _ip = "";
                _port = 0;
                _direction = direction;
                _udp_endpoint_ip = "";
                _udp_endpoint_port = 0;
                _com_port = com_port;
            }
            public Guid Guid
            {
                get { return _guid; }
                set { _guid = value; }
            }
            public MultiMeterIO.MMIOType Type
            {
                get { return _type; }
                set { _type = value; }
            }
            public string ComPort
            {
                get { return _com_port; }
                set { _com_port = value; }
            }
            public string IP
            {
                get { return _ip; }
                set { _ip = value; }
            }
            public int Port
            {
                get { return _port; }
                set { _port = value; }
            }
            public string UDPEndpointIP
            {
                get { return _udp_endpoint_ip; }
                set { _udp_endpoint_ip = value; }
            }
            public int UDPEndpointPort
            {
                get { return _udp_endpoint_port; }
                set { _udp_endpoint_port = value; }
            }
            public MultiMeterIO.MMIODirection Direction
            {
                get { return _direction; }
                set { _direction = value; }
            }
            public override string ToString()
            {
                if (_type == MultiMeterIO.MMIOType.SERIAL)
                {
                    return _com_port;
                }
                else
                {
                    return _ip + ":" + _port;
                }
            }
        }
        private void lstMMIO_network_list_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index < 0) return;
            e.DrawBackground();

            Graphics g = e.Graphics;

            if (e.Index >= 0)
            {
                SolidBrush sbt;
                if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                    sbt = new SolidBrush(Color.White);
                else
                    sbt = new SolidBrush(Color.Black);

                clsMultiMeterIOComboboxItem mmioci = (clsMultiMeterIOComboboxItem)((ListBox)sender).Items[e.Index];
                if (mmioci != null)
                {
                    string type = "";
                    Font small = new Font(e.Font.FontFamily, e.Font.Size * 0.8f, FontStyle.Regular);
                    switch (mmioci.Type)
                    {
                        case MultiMeterIO.MMIOType.UDP_LISTENER:
                            type = "udp";
                            break;
                        case MultiMeterIO.MMIOType.TCPIP_LISTENER:
                            type = "tcp/ip server";
                            break;
                        case MultiMeterIO.MMIOType.TCPIP_CLIENT:
                            type = "tcp/ip client";
                            break;
                        case MultiMeterIO.MMIOType.SERIAL:
                            type = "serial";
                            break;
                    }
                    g.DrawString(type, small, sbt, e.Bounds, StringFormat.GenericDefault);

                    int offset;
                    Rectangle rect;

                    //in/out/both
                    Rectangle rect2 = new Rectangle(60, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);
                    g.DrawString(mmioci.Direction.ToString().ToLower(), small, sbt, rect2, StringFormat.GenericDefault);
                    small.Dispose();
                    
                    if (mmioci.Type == MultiMeterIO.MMIOType.SERIAL)
                    {
                        offset = (int)(lstMMIO_network_list.Font.Height * 0.8f);
                        rect = new Rectangle(e.Bounds.X, e.Bounds.Top + offset, e.Bounds.Width, e.Bounds.Height - offset);
                        g.DrawString(((ListBox)sender).Items[e.Index].ToString(), e.Font, sbt, rect, StringFormat.GenericDefault);
                    }
                    else
                    {                       
                        if (mmioci.Type == MultiMeterIO.MMIOType.UDP_LISTENER && mmioci.Direction != MultiMeterIO.MMIODirection.IN)
                        {
                            offset = (int)(lstMMIO_network_list.Font.Height * 1.8f);
                            rect = new Rectangle(e.Bounds.X, e.Bounds.Top + offset, e.Bounds.Width, e.Bounds.Height - offset);
                            g.DrawString(mmioci.UDPEndpointIP + ":" + mmioci.UDPEndpointPort.ToString(), e.Font, sbt, rect, StringFormat.GenericDefault);

                            if (mmioci.Direction == MultiMeterIO.MMIODirection.OUT)
                            {
                                sbt.Dispose();
                                sbt = new SolidBrush(Color.Gray);
                            }
                        }

                        offset = (int)(lstMMIO_network_list.Font.Height * 0.8f);
                        rect = new Rectangle(e.Bounds.X, e.Bounds.Top + offset, e.Bounds.Width, e.Bounds.Height - offset);
                        g.DrawString(((ListBox)sender).Items[e.Index].ToString(), e.Font, sbt, rect, StringFormat.GenericDefault);
                    }

                    sbt.Dispose();
                }

                e.DrawFocusRectangle();
            }
        }
        private int itemHeight(clsMultiMeterIOComboboxItem mmioci)
        {
            int ret = lstMMIO_network_list.Font.Height;
            switch (mmioci.Type)
            {
                case MultiMeterIO.MMIOType.UDP_LISTENER:
                    if (mmioci.Direction == MultiMeterIO.MMIODirection.IN)
                    {
                       ret = (int)(lstMMIO_network_list.Font.Height * 1.8f);
                    }
                    else
                    {
                        ret = (int)(lstMMIO_network_list.Font.Height * 2.8f);
                    }
                    break;
                default:
                    ret = (int)(lstMMIO_network_list.Font.Height * 1.8f);
                    break;
            }
            return ret;
        }
        private void lstMMIO_network_list_MeasureItem(object sender, MeasureItemEventArgs e)
        {
            if (e.Index < 0) return;
            clsMultiMeterIOComboboxItem mmioci = (clsMultiMeterIOComboboxItem)((ListBox)sender).Items[e.Index];
            int newHeight;
            if(mmioci != null)
                newHeight = itemHeight(mmioci);
            else
                newHeight = (int)(lstMMIO_network_list.Font.Height * 1.8f);

            if(newHeight != e.ItemHeight)
                e.ItemHeight = newHeight;
        }

        private void chkMMIO_network_enabled_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (_MMIO_ignore_change_events) return;
            if (lstMMIO_network_list.SelectedIndex < 0) return;
            clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
            if (mmioci == null) return;

            bool old_state = MultiMeterIO.Data[mmioci.Guid].Enabled;
            MultiMeterIO.Data[mmioci.Guid].Enabled = !old_state;
            if (!old_state)
            {
                // start
                MultiMeterIO.Data[mmioci.Guid].StartConnection();
            }
            else
            {
                // stop
                MultiMeterIO.StopConnection(MultiMeterIO.Data[mmioci.Guid].Guid);
            }
            _MMIO_ignore_change_events = true;
            chkMMIO_network_enabled.Checked = MultiMeterIO.Data[mmioci.Guid].Enabled;
            _MMIO_ignore_change_events = false;
        }
        private void txtMMIO_network_ip_port_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
        }

        private void txtMMIO_network_4char_Click(object sender, EventArgs e)
        {
            //pnlMMIO_network_container.Focus();
        }

        private void txtMMIO_network_4char_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
        }
        private void btnMMIO_network_copy4char_Click(object sender, EventArgs e)
        {
            Clipboard.SetText(txtMMIO_network_4char.Text);
        }
        private void btnMMIO_network_remove_variable_Click(object sender, EventArgs e)
        {
            ListView.SelectedListViewItemCollection items = lstMMIO_network_variables.SelectedItems;
            if (items.Count <= 0 || items.Count > 1)
            {
                btnMMIO_network_remove_variable.Enabled = false;
                btnMMIO_network_copyvariable_clipboard.Enabled = false;
                return;
            }
            clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
            if (mmioci == null) return;
            if (!MultiMeterIO.Data.ContainsKey(mmioci.Guid)) return;

            btnMMIO_network_remove_variable.Enabled = items.Count > 0;
            btnMMIO_network_copyvariable_clipboard.Enabled = items.Count > 0;

            MultiMeterIO.clsMMIO mmio = MultiMeterIO.Data[mmioci.Guid];
            if (mmio != null)
            {
                mmio.RemoveVariable(items[0].Text);
                lstMMIO_network_variables.Items.Remove(items[0]);
                updateVariableList();
            }
        }

        private void lstMMIO_network_variables_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            ListView.SelectedListViewItemCollection items = lstMMIO_network_variables.SelectedItems;
            if (items.Count <= 0 || items.Count > 1)
            {
                btnMMIO_network_remove_variable.Enabled = false;
                btnMMIO_network_copyvariable_clipboard.Enabled = false;
                return;
            }
            btnMMIO_network_remove_variable.Enabled = true;
            btnMMIO_network_copyvariable_clipboard.Enabled = true;
        }

        private void btnMMIO_network_copyvariable_clipboard_Click(object sender, EventArgs e)
        {
            ListView.SelectedListViewItemCollection items = lstMMIO_network_variables.SelectedItems;
            if (items.Count <= 0 || items.Count > 1) return;

            Clipboard.SetText("%" + items[0].Text + "%");
        }
        private void btnMMIO_variable_Click(object sender, EventArgs e)
        {
            mmioSetupVariable(0);
        }
        private void comboMMIO_network_terminator_in_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
            if (mmioci == null) return;

            bool ok = Enum.TryParse<MultiMeterIO.MMIOTerminator>(comboMMIO_network_terminator_in.Text, out MultiMeterIO.MMIOTerminator term);

            if (ok)
            {
                MultiMeterIO.Data[mmioci.Guid].TerminatorIn = term;
                updateTerminators(MultiMeterIO.Data[mmioci.Guid]);
            }
        }
        private void btnMMIO_variable_2_Click(object sender, EventArgs e)
        {
            mmioSetupVariable(1);
        }
        private bool variableInUse(int variable)
        {
            string mgID = meterItemGroupIDfromSelected();
            if (mgID == "") return false;

            clsMeterTypeComboboxItem mtci = lstMetersInUse.SelectedItem as clsMeterTypeComboboxItem;
            if (mtci == null) return false;

            MeterManager.clsMeter m = meterFromSelectedContainer();
            if (m == null) return false;

            MeterType mt = meterItemGroupTypefromSelected();
            if (mt == MeterType.NONE) return false;

            MeterManager.clsIGSettings igs = m.GetSettingsForMeterGroup(mt, mtci.Order);
            if (igs == null) return false;

            return igs.GetMMIOVariable(variable) == "--DEFAULT--" ? false : true;
        }
        private void mmioSetupVariable(int variable)
        {
            string mgID = meterItemGroupIDfromSelected();
            if (mgID == "") return;

            clsMeterTypeComboboxItem mtci = lstMetersInUse.SelectedItem as clsMeterTypeComboboxItem;
            if (mtci == null) return;

            MeterManager.clsMeter m = meterFromSelectedContainer();
            if (m == null) return;

            MeterType mt = meterItemGroupTypefromSelected();
            if (mt == MeterType.NONE) return;

            MeterManager.clsIGSettings igs = m.GetSettingsForMeterGroup(mt, mtci.Order);
            if (igs == null) return;

            frmVariablePicker f = new frmVariablePicker();
            f.Init(variable, igs.GetMMIOGuid(variable), igs.GetMMIOVariable(variable));
            DialogResult dr = f.ShowDialog(this);
            if (dr == DialogResult.OK || dr == DialogResult.Ignore)
            {
                igs.SetMMIOGuid(variable, f.Guid);
                igs.SetMMIOVariable(variable, f.Variable);

                m.ApplySettingsForMeterGroup(mt, igs, mtci.Order);

                switch(mt)
                {
                    case MeterType.HISTORY:
                        {
                            switch (variable)
                            {
                                case 0:
                                    pnlVariableInUse_1_history.Visible = variableInUse(0);
                                    break;
                                case 1:
                                    pnlVariableInUse_2_history.Visible = variableInUse(1);
                                    break;
                            }
                        }
                        break;
                    case MeterType.ROTATOR:
                        {
                            switch (variable)
                            {
                                case 0:
                                    pnlVariableInUse_1_rotator.Visible = variableInUse(0);
                                    break;
                                case 1:
                                    pnlVariableInUse_2_rotator.Visible = variableInUse(1);
                                    break;
                            }
                        }
                        break;
                    default:
                        {
                            switch (variable)
                            {
                                case 0:
                                    pnlVariableInUse_1.Visible = variableInUse(0);
                                    break;
                                case 1:
                                    pnlVariableInUse_2.Visible = variableInUse(1);
                                    break;
                            }
                        }
                        break;
                }
            }
        }

        private void comboMMIO_network_terminator_out_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
            if (mmioci == null) return;

            bool ok = Enum.TryParse<MultiMeterIO.MMIOTerminator>(comboMMIO_network_terminator_out.Text, out MultiMeterIO.MMIOTerminator term);

            if (ok)
            {
                MultiMeterIO.Data[mmioci.Guid].TerminatorOut = term;
                updateTerminators(MultiMeterIO.Data[mmioci.Guid]);
            }
        }
        private void comboMMIO_network_format_out_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
            if (mmioci == null) return;

            bool ok = Enum.TryParse<MultiMeterIO.MMIOFormat>(comboMMIO_network_format_out.Text, out MultiMeterIO.MMIOFormat fmt);

            if (ok) MultiMeterIO.Data[mmioci.Guid].FormatOut = fmt;
        }
        private void txtMMIO_network_terminator_in_custom_TextChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (_MMIO_ignore_change_events) return;
            clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
            if (mmioci == null) return;

            MultiMeterIO.Data[mmioci.Guid].CustomTerminatorIn = txtMMIO_network_terminator_in_custom.Text;
        }

        private void txtMMIO_network_terminator_out_custom_TextChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (_MMIO_ignore_change_events) return;
            clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
            if (mmioci == null) return;

            MultiMeterIO.Data[mmioci.Guid].CustomTerminatorOut = txtMMIO_network_terminator_out_custom.Text;
        }
        private void btnMMIO_network_udp_endpoint_ip_port_Click(object sender, EventArgs e)
        {
            clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
            if (mmioci == null) return;

            if (!MultiMeterIO.Data.ContainsKey(mmioci.Guid)) return;
            MultiMeterIO.clsMMIO mmio = MultiMeterIO.Data[mmioci.Guid];

            frmIPv4Picker f = new frmIPv4Picker();
            f.Init(mmio.UdpEndpointIP + ":" + mmio.UdpEndpointPort.ToString());
            DialogResult dr = f.ShowDialog(this);

            if (dr == DialogResult.OK)
            {
                string sTmp = f.IP;
                if (sTmp == "") sTmp = "127.0.0.1:9000";
                setupUDPEndpoint(sTmp);
            }
        }
        private void txtMMIO_network_udp_endpoint_ip_port_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
        }
        private bool setUDPEndpoint()
        {
            bool ret_ok = false;
            clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
            if (mmioci == null) return ret_ok;
            if (!MultiMeterIO.Data.ContainsKey(mmioci.Guid)) return ret_ok;

            string[] parts = txtMMIO_network_udp_endpoint_ip_port.Text.Split(':');
            if (parts.Length == 2)
            {
                string ip = parts[0];
                string port = parts[1];

                bool ok = int.TryParse(port, out int portInt);
                if (ok)
                {
                    if (portInt < 0 || portInt > 65535) // bad port
                    {
                        MessageBox.Show("The port needs to be in the range 0-65535",
                        "Listener Start Problem",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST);
                        return false;
                    }
                    MultiMeterIO.clsMMIO mmio = MultiMeterIO.Data[mmioci.Guid];
                    mmio.UdpEndpointIP = ip;
                    mmio.UdpEndpointPort = portInt;
                    ret_ok = true;
                }
            }
            return ret_ok;
        }
        private void setupUDPEndpoint(string existing_ip_port = "")
        {
            pnlMMIO_network_container.Focus();
            clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
            if (mmioci == null) return;

            string ip_port = InputBox.Show("Configure UDP Endpoint", "Provide UDP endpoint (outbound) details:", existing_ip_port);
            if (ip_port == null || ip_port == "") return;

            string[] parts = ip_port.Split(':');
            if (parts.Length == 2)
            {
                if (int.TryParse(parts[1], out int intPort))
                {
                    if (intPort < 0 || intPort > 65535) // bad port
                    {
                        MessageBox.Show("The port needs to be in the range 0-65535",
                        "Incorrect Format",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST);
                        return;
                    }
                    if (Common.IsIpv4Valid(parts[0], intPort))
                    {
                        string oldIpPort = txtMMIO_network_udp_endpoint_ip_port.Text;
                        _MMIO_ignore_change_events = true;
                        txtMMIO_network_udp_endpoint_ip_port.Text = parts[0] + ":" + intPort.ToString();
                        _MMIO_ignore_change_events = false;
                        bool ok = setUDPEndpoint();
                        if (ok)
                        {
                            mmioci.UDPEndpointIP = parts[0];
                            mmioci.UDPEndpointPort = intPort;
                            lstMMIO_network_list.Invalidate();
                        }
                        else
                        {
                            _MMIO_ignore_change_events = true;
                            txtMMIO_network_udp_endpoint_ip_port.Text = oldIpPort;
                            _MMIO_ignore_change_events = false;
                            MessageBox.Show("Incorrect ip/port format. Please use the following format.\n\nIP:PORT\n\nExample: 127.0.0.1:9000",
                                "Incorrect Format",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Incorrect ip/port format. Please use the following format.\n\nIP:PORT\n\nExample: 127.0.0.1:9000",
                            "Incorrect Format",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST);
                    }
                }
                else
                {
                    MessageBox.Show("Incorrect ip/port format. Please use the following format.\n\nIP:PORT\n\nExample: 127.0.0.1:9000",
                        "Incorrect Format",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST);
                }
            }
            else
            {
                MessageBox.Show("Incorrect ip/port format. Please use the following format.\n\nIP:PORT\n\nExample: 127.0.0.1:9000",
                    "Incorrect Format",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, Common.MB_TOPMOST);
            }
        }
        private void txtMMIO_network_udp_endpoint_ip_port_Click(object sender, EventArgs e)
        {
            setupUDPEndpoint(txtMMIO_network_udp_endpoint_ip_port.Text);
        }

        private void txtMMIO_network_udp_endpoint_ip_port_TextChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (_MMIO_ignore_change_events) return;
            setUDPEndpoint();
        }

        private void btnMMIO_network_remove_all_variables_Click(object sender, EventArgs e)
        {
            clsMultiMeterIOComboboxItem mmioci = lstMMIO_network_list.SelectedItem as clsMultiMeterIOComboboxItem;
            if (mmioci == null) return;

            if (!MultiMeterIO.Data.ContainsKey(mmioci.Guid)) return;
            MultiMeterIO.clsMMIO mmio = MultiMeterIO.Data[mmioci.Guid];

            foreach (ListViewItem lvi in lstMMIO_network_variables.Items)
            {
                if (mmio.Variables().ContainsKey(lvi.Text)) mmio.RemoveVariable(lvi.Text);
            }

            lstMMIO_network_variables.Items.Clear();
            btnMMIO_network_remove_all_variables.Enabled = false;
        }
        private void btnMMIO_network_add_tcpip_client_Click(object sender, EventArgs e)
        {
            addEditConnector(MultiMeterIO.MMIOType.TCPIP_CLIENT, true);
        }
        #endregion

        private void nudDataOutNode_sendinterval_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void txtDataOutNode_4charID_TextChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }        

        //rotator
        private void chkMeterItemRotatorCardinals_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkMeterItemFadeOnRxRotator_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkMeterItemFadeOnTxRotator_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkMeterItemDarkModeRotator_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudMeterItemUpdateRateRotator_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMeterItemHBackgroundRotator_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMeterItemRotatorArrow_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMeterItemRotatorLargeDot_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMeterItemRotatorSmallDot_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMeterItemRotatorBeamWidth_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkMeterItemRotatorShowBeamWidth_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
            updateShowBeamWidthControls();
        }
        private void updateShowBeamWidthControls()
        {
            bool en = chkMeterItemRotatorShowBeamWidth.Checked;
            clrbtnMeterItemRotatorBeamWidth.Enabled = en;
            lblMeterItemRotatorBeamWidth_degrees.Enabled = en;
            nudMeterItemRotatorBeamWidth.Enabled = en;
            lblMeterItemRotatorBeamWidth_alpha.Enabled = en;
            nudMeterItemRotatorBeamWidth_alpha.Enabled = en;
        }
        private void nudMeterItemRotatorBeamWidth_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMeterItemRotatorText_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void btnMMIO_variable_rotator_Click(object sender, EventArgs e)
        {
            mmioSetupVariable(0);
        }

        private void btnMMIO_variable_2_rotator_Click(object sender, EventArgs e)
        {
            mmioSetupVariable(1);
        }
        private void btnTextOverlay_copyfonts_Click(object sender, EventArgs e)
        {
            _textOverlayFont2 = new Font(_textOverlayFont1.FontFamily, _textOverlayFont1.Size, _textOverlayFont1.Style);
            clrbtnTextOverlay_TextColour2.Color = clrbtnTextOverlay_TextColour1.Color;
            clrbtnTextOverlay_TextBackColour2.Color = clrbtnTextOverlay_TextBackColour1.Color;
            chkTextOverlay_textback2.Checked = chkTextOverlay_textback1.Checked;

            updateMeterType();
        }

        private void chkMeterItemRotatorAllowControl_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
            updateRotatorControlControls();
        }

        private void clrbtnMeterItemRotatorControlColour_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void txtMeterItemRotatorAZcommand_TextChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void txtMeterItemRotatorELEcommand_TextChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }
        private void updateRotatorControlControls()
        {
            bool en = chkMeterItemRotatorAllowControl.Checked;
            clrbtnMeterItemRotatorControlColour.Enabled = en;
            txtMeterItemRotatorAZcommand.Enabled = en;
            txtMeterItemRotatorELEcommand.Enabled = en;
            txtMeterItemRotatorSTOPcommand.Enabled = en;
            picMultiMeterRotatorControlInfo.Enabled = en;
            lblMeterItemRotatorAZcommand.Enabled = en;
            lblMeterItemRotatorELEcommand.Enabled = en;
            picMultiMeterRotatorControlInfo.Enabled = en;
            bntMultiMeterItemRotator_default_pstRotator.Enabled = en;
            txtRotator_4charID.Enabled = en;
            lblRotator_4charID.Enabled = en;
        }

        private void bntMultiMeterItemRotator_default_pstRotator_Click(object sender, EventArgs e)
        {
            txtMeterItemRotatorAZcommand.Text = "<PST><AZIMUTH>%AZ%</AZIMUTH></PST>";
            txtMeterItemRotatorELEcommand.Text = "<PST><ELEVATION>%ELE%</ELEVATION></PST>";
            txtMeterItemRotatorSTOPcommand.Text = "<PST><STOP>1</STOP></PST>";
        }

        private void txtRotator_4charID_TextChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkLedIndicator_ShowPanel_CheckedChanged(object sender, EventArgs e)
        {
            updateLedIndicatorPanelControls();
            updateMeterType();
        }

        private void clrbtnLedIndicator_PanelBackground_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudLedIndicator_PanelPadding_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkLedIndicator_FadeOnRX_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkLedIndicator_FadeOnTX_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void txtLedIndicator_condition_TextChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnLedIndicator_true_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnLedIndicator_false_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void btnLedIndicator_copy_truefalse_colours_Click(object sender, EventArgs e)
        {
            clrbtnLedIndicator_false.Color = clrbtnLedIndicator_true.Color;
        }

        private void nudLedIndicator_xOffset_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudLedIndicator_yOffset_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudLedIndicator_xSize_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudLedIndicator_ySize_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void btnLedIndicator_copy_sizex_to_y_Click(object sender, EventArgs e)
        {
            nudLedIndicator_ySize.Value = nudLedIndicator_xSize.Value;
        }
        private void updateLedIndicatorPanelControls()
        {
            bool enabled = chkLedIndicator_ShowPanel.Checked;
            clrbtnLedIndicator_PanelBackground.Enabled = enabled;
            clrbtnLedIndicator_PanelBackgroundTX.Enabled = enabled;
            nudLedIndicator_PanelPadding.Enabled = enabled;
            chkLedIndicator_FadeOnRX.Enabled = enabled;
            chkLedIndicator_FadeOnTX.Enabled = enabled;
            lblLedIndicator_panelbackground.Enabled = enabled;
            lblLedIndicator_panelbackgroundTX.Enabled = enabled;
            nudLedIndicator_PanelPadding.Enabled = enabled;
        }
        private void updateLedValidControls()
        {
            MeterManager.clsMeter m = meterFromSelectedContainer();
            if (m == null) return;

            clsMeterTypeComboboxItem mtci = lstMetersInUse.SelectedItem as clsMeterTypeComboboxItem;
            if (mtci == null) return;

            MeterType mt = meterItemGroupTypefromSelected();
            if (mt == MeterType.NONE) return;

            if (mt == MeterType.LED)
            {
                MeterManager.clsIGSettings igs = m.GetSettingsForMeterGroup(mt, mtci.Order);
                if (igs == null) return;

                lblLed_Error.ForeColor = Color.Red;
                lblLed_Error.Visible = igs.ShowHistory;
                lblLed_Valid.Text = igs.ShowType ? "Valid" : "Invalid";
                lblLed_Valid.ForeColor = igs.ShowType ? Color.LimeGreen : Color.Red;

                tmrLedValid.Enabled = true;
            }            
        }

        private void chkLed_show_true_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkLed_show_false_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void radLed_light_on_off_CheckedChanged(object sender, EventArgs e)
        {
            if(radLed_light_on_off.Checked)
                updateMeterType();
        }

        private void radLed_light_blink_CheckedChanged(object sender, EventArgs e)
        {
            if(radLed_light_blink.Checked)
                updateMeterType();
        }

        private void radLed_light_pulsate_CheckedChanged(object sender, EventArgs e)
        {
            if(radLed_light_pulsate.Checked)
                updateMeterType();
        }

        private void clrbtnMMVfoDigitHighlight_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void btnMMIO_network_add_serial_Click(object sender, EventArgs e)
        {
            addEditConnector(MultiMeterIO.MMIOType.SERIAL, true);
        }

        private void txtWebImage_url_TextChanged(object sender, EventArgs e)
        {
            if (txtWebImage_url.Text.Contains("hamqsl.com", StringComparison.InvariantCultureIgnoreCase) ||
                txtWebImage_url.Text.Contains("bsdworld.org", StringComparison.InvariantCultureIgnoreCase) ||
                //txtWebImage_url.Text.Contains("nascom.nasa.gov", StringComparison.InvariantCultureIgnoreCase) ||
                //txtWebImage_url.Text.Contains("swpc.noaa.gov", StringComparison.InvariantCultureIgnoreCase) ||
                txtWebImage_url.Text.Contains("kc2g.com", StringComparison.InvariantCultureIgnoreCase)
                )
            {
                // for old bsdworld urls, insert -light or -dark
                string bsd = fixBSDWorldUrls(txtWebImage_url.Text);
                if (!string.IsNullOrEmpty(bsd))
                {
                    txtWebImage_url.Text = bsd;
                    return;
                }

                // lock and set the update interval
                nudWebImage_update_interval.Enabled = false;
                _ignoreMeterItemChangeEvents = true;
                nudWebImage_update_interval.Value = (decimal)600;
                _ignoreMeterItemChangeEvents = false;

                // lock and set the bypass cache
                chkWebImage_bypass_cache.Enabled = false;
                _ignoreMeterItemChangeEvents = true;
                chkWebImage_bypass_cache.Checked = false;
                _ignoreMeterItemChangeEvents = false;
            }
            else
            {
                if(!nudWebImage_update_interval.Enabled)
                    nudWebImage_update_interval.Enabled = true;
                if(!chkWebImage_bypass_cache.Enabled)
                    chkWebImage_bypass_cache.Enabled = true;
            }

            updateMeterType();
        }

        private void nudWebImage_width_scale_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudWebImage_update_interval_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkWebImage_fade_rx_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkWebImage_fade_tx_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void btnWebImage_hamqsl_donate_Click(object sender, EventArgs e)
        {
            Common.OpenUri("https://www.hamqsl.com/donate.html");
        }
        //
        private void setup_comboWebImage_HamQsl()
        {
            comboWebImage_HamQsl.Items.Clear();
            for(int i = 0; i < _hamqsl_urls.Length; i++)
            {
                KeyValuePair<string, string> kvp = _hamqsl_urls[i];
                comboWebImage_HamQsl.Items.Add(kvp.Key);
            }
        }
        private void setup_comboWebImage_BsdWorld()
        {
            comboWebImage_BsdWorld.Items.Clear();
            for (int i = 0; i < _bsdworld_urls.Length; i++)
            {
                KeyValuePair<string, string> kvp = _bsdworld_urls[i];
                comboWebImage_BsdWorld.Items.Add(kvp.Key);
            }
        }
        private void setup_comboWebImage_nasa()
        {
            comboWebImage_nasa.Items.Clear();
            for (int i = 0; i < _nasa_urls.Length; i++)
            {
                KeyValuePair<string, string> kvp = _nasa_urls[i];
                comboWebImage_nasa.Items.Add(kvp.Key);
            }
        }
        private void setup_comboWebImage_noaa()
        {
            comboWebImage_noaa.Items.Clear();
            for (int i = 0; i < _noaa_urls.Length; i++)
            {
                KeyValuePair<string, string> kvp = _noaa_urls[i];
                comboWebImage_noaa.Items.Add(kvp.Key);
            }
        }
        //
        private void comboWebImage_HamQsl_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (comboWebImage_HamQsl.SelectedIndex == -1) return;
            if (comboWebImage_HamQsl.SelectedIndex == 0) return;

            KeyValuePair<string, string> kvp = _hamqsl_urls[comboWebImage_HamQsl.SelectedIndex];
            txtWebImage_url.Text = kvp.Value;

            comboWebImage_HamQsl.SelectedIndex = 0;
        }
        private void updateWebImageState(ImageFetcher.State state, bool checkSelected = false, string id = "")
        {
            if (checkSelected)
            {
                string mgID = meterItemGroupIDfromSelected();
                if (mgID == "") return;
                if (mgID != id) return;

                MeterType mt = meterItemGroupTypefromSelected();
                if (mt == MeterType.NONE) return;
                if (mt != MeterType.WEB_IMAGE) return;
            }

            string txt;

            switch (state)
            {
                case ImageFetcher.State.IDLE:
                    txt = "idle";
                    break;
                case ImageFetcher.State.OK:
                    txt = "ok";
                    break;
                case ImageFetcher.State.ERROR_URL_ISSUE:
                    txt = "url issue";
                    break;
                case ImageFetcher.State.ERROR_IMAGE_CONVERSION_PROBLEM:
                    txt = "bad image";
                    break;
                case ImageFetcher.State.ERROR_NO_SUITABLE_IMAGE:
                    txt = "no image";
                    break;
                case ImageFetcher.State.WAITING:
                    txt = "waiting";
                    break;
                case ImageFetcher.State.GATHERING_IMAGES:
                    txt = "gathering";
                    break;
                default:
                    txt = "";
                    break;
            }
            lblWebImage_state.Text = txt;
        }
        public void SetWebImageState(string id, ImageFetcher.State state)
        {
            if (initializing) return;
            if (lstMetersInUse == null) return;
            if (!lstMetersInUse.Visible) return;

            if (this.InvokeRequired)
                this?.Invoke(new Action(() => updateWebImageState(state, true, id)));
            else
                updateWebImageState(state, true, id);
        }

        private void chkContainerMinimises_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            clsContainerComboboxItem cci = (clsContainerComboboxItem)comboContainerSelect.SelectedItem;
            if (cci != null)
            {
                MeterManager.ContainerMinimises(cci.ID, chkContainerMinimises.Checked);
            }
        }

        private void radMeterItemRotator_show_az_CheckedChanged(object sender, EventArgs e)
        {
            // only do the checked state for rad controls, as all the others in the group will fire as well
            if (radMeterItemRotator_show_az.Checked)
            {
                updateMeterType();
                nudMeterItemRotator_padding.Enabled = true;
            }
        }

        private void radMeterItemRotator_show_ele_CheckedChanged(object sender, EventArgs e)
        {
            if (radMeterItemRotator_show_ele.Checked)
            {
                updateMeterType();
                nudMeterItemRotator_padding.Enabled = true;
            }
        }

        private void radMeterItemRotator_show_both_CheckedChanged(object sender, EventArgs e)
        {
            if (radMeterItemRotator_show_both.Checked)
            {
                updateMeterType();
                nudMeterItemRotator_padding.Enabled = false;
            }
        }

        private void nudMeterItemRotator_padding_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        KeyValuePair<string, string>[] _hamqsl_urls =
{
            new KeyValuePair<string, string>("select one", ""),
            new KeyValuePair<string, string>("Layout 1 - sun", "https://www.hamqsl.com/solarn0nbh.php"),
            new KeyValuePair<string, string>("Layout 2 - sun", "https://www.hamqsl.com/solarpic.php"),
            new KeyValuePair<string, string>("Layout 3", "https://www.hamqsl.com/solarvhf.php"),
            new KeyValuePair<string, string>("Layout 4", "https://www.hamqsl.com/solar.php"),
            new KeyValuePair<string, string>("Layout 5", "https://www.hamqsl.com/solarsmall.php"),
            new KeyValuePair<string, string>("Layout 6", "https://www.hamqsl.com/solarbrief.php"),
            new KeyValuePair<string, string>("Layout 7", "https://www.hamqsl.com/solarbc.php"),
            new KeyValuePair<string, string>("Layout 8", "https://www.hamqsl.com/solar100sc.php"),
            new KeyValuePair<string, string>("Layout 9", "https://www.hamqsl.com/solar2.php"),
            new KeyValuePair<string, string>("Layout 10 - sun", "https://www.hamqsl.com/solarpich.php"),
            new KeyValuePair<string, string>("Layout 11 - sun", "https://www.hamqsl.com/solar101pic.php"),
            new KeyValuePair<string, string>("Layout 12", "https://www.hamqsl.com/solar101vhf.php"),
            new KeyValuePair<string, string>("Layout 13", "https://www.hamqsl.com/solar101vhfper.php"),
            new KeyValuePair<string, string>("Layout 14 - sun", "https://www.hamqsl.com/solar101vhfpic.php"),
            new KeyValuePair<string, string>("Layout 15", "https://www.hamqsl.com/solar101sc.php"),
            new KeyValuePair<string, string>("Layout 16 - sun", "https://www.hamqsl.com/solarsun.php"),
            new KeyValuePair<string, string>("Layout 17 - graphs", "https://www.hamqsl.com/solargraph.php"),
            new KeyValuePair<string, string>("Layout 18 - graphs", "https://www.hamqsl.com/marston.php"),
            new KeyValuePair<string, string>("Greyline 1", "https://www.hamqsl.com/solarmuf.php"),
            new KeyValuePair<string, string>("Greyline 2", "https://www.hamqsl.com/solarmap.php"),
            new KeyValuePair<string, string>("Earth 1", "https://www.hamqsl.com/solarglobe.php"),
            new KeyValuePair<string, string>("Earth 2", "https://www.hamqsl.com/moonglobe.php"),
            new KeyValuePair<string, string>("Planets", "https://www.hamqsl.com/solarsystem.php"),
        };

        private KeyValuePair<string, string>[] _bsdworld_urls =
        {
            new KeyValuePair<string, string>("select one", ""),
            new KeyValuePair<string, string>("NA Propagation All", "https://bsdworld.org/DXCC/continent/NA/latest<light_mode>.webp"),
            new KeyValuePair<string, string>("NA Propagation Zone 3", "https://bsdworld.org/DXCC/cqzone/3/latest<light_mode>.webp"),
            new KeyValuePair<string, string>("NA Propagation Zone 4", "https://bsdworld.org/DXCC/cqzone/4/latest<light_mode>.webp"),
            new KeyValuePair<string, string>("NA Propagation Zone 5", "https://bsdworld.org/DXCC/cqzone/5/latest<light_mode>.webp"),
            new KeyValuePair<string, string>("EU Propagation All", "https://bsdworld.org/DXCC/continent/EU/tn_latest<light_mode>.webp"),
            new KeyValuePair<string, string>("EU Propagation Zone 14", "https://bsdworld.org/DXCC/cqzone/14/latest<light_mode>.webp"),
            new KeyValuePair<string, string>("EU Propagation Zone 15", "https://bsdworld.org/DXCC/cqzone/15/latest<light_mode>.webp"),
            new KeyValuePair<string, string>("EU Propagation Zone 16", "https://bsdworld.org/DXCC/cqzone/16/latest<light_mode>.webp"),
            new KeyValuePair<string, string>("EU Propagation Zone 20", "https://bsdworld.org/DXCC/cqzone/20/latest<light_mode>.webp"),
            new KeyValuePair<string, string>("OC Propagation All", "https://bsdworld.org/DXCC/continent/OC/tn_latest<light_mode>.webp"),
            new KeyValuePair<string, string>("AS Propagation All", "https://bsdworld.org/DXCC/continent/AS/tn_latest<light_mode>.webp"),
            new KeyValuePair<string, string>("SA Propagation All", "https://bsdworld.org/DXCC/continent/SA/tn_latest<light_mode>.webp"),
            new KeyValuePair<string, string>("AF Propagation All", "https://bsdworld.org/DXCC/continent/AF/tn_latest<light_mode>.webp"),
            new KeyValuePair<string, string>("A-Index", "https://bsdworld.org/aindex<light_mode>.svgz"),
            new KeyValuePair<string, string>("PK Index", "https://bsdworld.org/pkindex<light_mode>.svgz"),
            new KeyValuePair<string, string>("PK Predictions", "https://bsdworld.org/pki-forecast<light_mode>.svgz"),
            new KeyValuePair<string, string>("Flux", "https://bsdworld.org/flux<light_mode>.svgz"),
            new KeyValuePair<string, string>("Outlook", "https://bsdworld.org/outlook<light_mode>.svgz"),
            new KeyValuePair<string, string>("Solar Wind", "https://bsdworld.org/solarwind<light_mode>.svgz"),
            new KeyValuePair<string, string>("SSN", "https://bsdworld.org/ssn<light_mode>.svgz"),
            new KeyValuePair<string, string>("SSN History", "https://bsdworld.org/ssnhist<light_mode>.svgz"),
            new KeyValuePair<string, string>("EISN", "https://bsdworld.org/eisn<light_mode>.svgz"),
            new KeyValuePair<string, string>("Proton Flux", "https://bsdworld.org/proton_flux<light_mode>.svgz"),
            new KeyValuePair<string, string>("X-Ray Flux", "https://bsdworld.org/xray_flux<light_mode>.svgz"),
            new KeyValuePair<string, string>("D-Layer", "https://bsdworld.org/d-rap/latest<light_mode>.svgz"),
        };

        private KeyValuePair<string, string>[] _nasa_urls =
        {
            new KeyValuePair<string, string>("select one", ""),
            new KeyValuePair<string, string>("SOHO EIT 171", "https://soho.nascom.nasa.gov/data/realtime/eit_171/512/latest.jpg"),
            new KeyValuePair<string, string>("SOHO EIT 195", "https://soho.nascom.nasa.gov/data/realtime/eit_195/512/latest.jpg"),
            new KeyValuePair<string, string>("SOHO EIT 284", "https://soho.nascom.nasa.gov/data/realtime/eit_284/512/latest.jpg"),
            new KeyValuePair<string, string>("SOHO EIT 304", "https://soho.nascom.nasa.gov/data/realtime/eit_304/512/latest.jpg"),
            new KeyValuePair<string, string>("SOHO SDO/HMI Continuum", "https://soho.nascom.nasa.gov/data/realtime/hmi_igr/512/latest.jpg"),
            new KeyValuePair<string, string>("SOHO SDO/HMI Magnetogram", "https://soho.nascom.nasa.gov/data/realtime/hmi_mag/512/latest.jpg"),
            new KeyValuePair<string, string>("SOHO LASCO C2", "https://soho.nascom.nasa.gov/data/realtime/c2/512/latest.jpg"),
            new KeyValuePair<string, string>("SOHO LASCO C3", "https://soho.nascom.nasa.gov/data/realtime/c3/512/latest.jpg")
        };
        private KeyValuePair<string, string>[] _noaa_urls =
        {
            new KeyValuePair<string, string>("select one", ""),
            new KeyValuePair<string, string>("Northern Aurora Latest", "https://services.swpc.noaa.gov/images/animations/ovation/north/latest.jpg"),
            new KeyValuePair<string, string>("Southern Aurora Latest", "https://services.swpc.noaa.gov/images/animations/ovation/south/latest.jpg"),
            new KeyValuePair<string, string>("Northern Aurora Forecast", "https://services.swpc.noaa.gov/images/aurora-forecast-northern-hemisphere.jpg"),
            new KeyValuePair<string, string>("Southern Aurora Forecast", "https://services.swpc.noaa.gov/images/aurora-forecast-southern-hemisphere.jpg"),
            new KeyValuePair<string, string>("SWX Solar Overiew", "https://services.swpc.noaa.gov/images/swx-overview-large.gif"),
            new KeyValuePair<string, string>("K Indicies", "https://services.swpc.noaa.gov/images/station-k-index.png"),
            new KeyValuePair<string, string>("D Region Absorption Map", "https://services.swpc.noaa.gov/images/animations/d-rap/global/d-rap/latest.png")
        };

        private string fixBSDWorldUrls(string url)
        {
            if (!url.Contains("bsdworld.org", StringComparison.OrdinalIgnoreCase)) return "";
            if (url.Contains("-light", StringComparison.OrdinalIgnoreCase) || url.Contains("-dark", StringComparison.OrdinalIgnoreCase)) return "";
            if (!_bsdworld_urls.Any(kvp => (url.Replace("<light_mode>", "")).Contains((kvp.Value).Replace("<light_mode>", "")))) return ""; // the url passed is not in _bsdworld_urls

            // insert before .webp or .svgz
            string mode = chkBSDWorldDarkMode.Checked ? "-dark" : "-light";
            int pos = url.IndexOf(".webp");
            if (pos != -1)
            {
                return url.Replace(".webp", $"{mode}.webp");
            }
            pos = url.IndexOf(".svgz");
            if (pos != -1)
            {
                return url.Replace(".svgz", $"{mode}.svgz");
            }
            return "";
        }
        private void comboWebImage_BsdWorld_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (comboWebImage_BsdWorld.SelectedIndex == -1) return;
            if (comboWebImage_BsdWorld.SelectedIndex == 0) return;

            KeyValuePair<string, string> kvp = _bsdworld_urls[comboWebImage_BsdWorld.SelectedIndex];
            string url = kvp.Value.Replace("<light_mode>", chkBSDWorldDarkMode.Checked ? "-dark" : "-light");
            txtWebImage_url.Text = url;

            comboWebImage_BsdWorld.SelectedIndex = 0;
        }

        private void btnWebImage_bsdworld_visit_Click(object sender, EventArgs e)
        {
            Common.OpenUri("https://bsdworld.org/help.html");
        }

        private void comboWebImage_nasa_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (comboWebImage_nasa.SelectedIndex == -1) return;
            if (comboWebImage_nasa.SelectedIndex == 0) return;

            KeyValuePair<string, string> kvp = _nasa_urls[comboWebImage_nasa.SelectedIndex];
            txtWebImage_url.Text = kvp.Value;

            comboWebImage_nasa.SelectedIndex = 0;
        }

        private void comboWebImage_noaa_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (comboWebImage_noaa.SelectedIndex == -1) return;
            if (comboWebImage_noaa.SelectedIndex == 0) return;

            KeyValuePair<string, string> kvp = _noaa_urls[comboWebImage_noaa.SelectedIndex];
            txtWebImage_url.Text = kvp.Value;

            comboWebImage_noaa.SelectedIndex = 0;
        }

        private void txtMeterItemRotatorSTOPcommand_TextChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkWebImage_bypass_cache_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void radMultiMeter_vfo_display_both_CheckedChanged(object sender, EventArgs e)
        {
            if(!radMultiMeter_vfo_display_both.Checked) return;
            updateMeterType();
        }

        private void radMultiMeter_vfo_display_vfoa_CheckedChanged(object sender, EventArgs e)
        {
            if (!radMultiMeter_vfo_display_vfoa.Checked) return;
            updateMeterType();
        }

        private void radMultiMeter_vfo_display_vfob_CheckedChanged(object sender, EventArgs e)
        {
            if (!radMultiMeter_vfo_display_vfob.Checked) return;
            updateMeterType();
        }

        private void chkMultiMeter_auto_container_height_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            clsContainerComboboxItem cci = (clsContainerComboboxItem)comboContainerSelect.SelectedItem;
            if (cci != null)
            {
                MeterManager.AutoContainerHeight(cci.ID, chkMultiMeter_auto_container_height.Checked);
            }
        }

        private void nudBandButtons_columns_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudBandButtons_border_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudBandButtons_margin_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudBandButtons_radius_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudBandButtons_height_ratio_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkBandButtons_use_indicator_CheckedChanged(object sender, EventArgs e)
        {
            updateButtonIndicatorControls();
            updateMeterType();
        }

        private void nudBandButtons_indicator_border_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }
        private void updateButtonIndicatorControls()
        {
            if (initializing) return;
            bool enable = chkBandButtons_use_indicator.Checked;
            lblBandButtons_indicator_border.Enabled = enable;
            nudBandButtons_indicator_border.Enabled = enable;
            lblBandButtons_indicator_style.Enabled = enable;
            nudBandButtons_indicator_style.Enabled = enable;
        }
        private void clrbtnBandButtons_indicator_on_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }
        private void clrbtnBandButtons_indicator_off_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnBandButtons_border_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnBandButtons_fill_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnBandButtons_hover_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkBandButtons_band_inactive_use_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkBandButtons_fade_rx_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkBandButtons_fade_tx_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }
        private Font _bandButtons_font = null;
        private void btnBandButtons_font_Click(object sender, EventArgs e)
        {
            using (FontDialog fontDialog = new FontDialog())
            {
                fontDialog.Font = _bandButtons_font;
                if (fontDialog.ShowDialog() == DialogResult.OK)
                {
                    if (!isFontTrueType(fontDialog.Font)) return;
                    _bandButtons_font = fontDialog.Font;
                    updateMeterType();
                }
            }
        }

        private void nudBandButtons_indicator_style_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudMeterItemRotatorBeamWidth_alpha_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkLegacyItems_band_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            LegacyItemController.HideBands = chkLegacyItems_band.Checked;
        }

        private void chkLegacyItems_mode_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            LegacyItemController.HideModes = chkLegacyItems_mode.Checked;
        }

        private void chkLegacyItems_filter_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            LegacyItemController.HideFilters = chkLegacyItems_filter.Checked;
        }

        private void chkLegacyItems_expand_spectral_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            LegacyItemController.ExpandSpectrumToRight = chkLegacyItems_expand_spectral.Checked;
        }

        private void nudButtonBox_font_scale_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudButtonBox_font_x_shift_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudButtonBox_font_y_shift_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void notifyAntennaState()
        {
            for(int b = (int)Band.B160M; b <= (int)Band.B6M; b++)
            {
                // rx
                RadioButtonTS[] rx_buttons = _AlexRxAntButtons[b];

                // tx
                RadioButtonTS[] tx_buttons = _AlexTxAntButtons[b];

                // check
                CheckBoxTS[] chk_buttons = _AlexRxOnlyAntCheckBoxes[b];
            }
        }

        private void clrbtnLedIndicator_PanelBackgroundTX_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMeterItemIndicator_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMeterItemSubIndicator_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkButtonBox_antenna_rx1_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkButtonBox_antenna_rx2_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkButtonBox_antenna_rx3_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkButtonBox_antenna_tx1_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkButtonBox_antenna_tx2_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkButtonBox_antenna_tx3_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkButtonBox_antenna_byp_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkButtonBox_antenna_ext1_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkButtonBox_antenna_xvtr_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkButtonBox_antenna_rxtxant_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }
        private int getTotalColumnsNeededForAntennaButtons()
        {
            int enable_count = 0;
            if (chkButtonBox_antenna_rx1.Checked) enable_count++;
            if (chkButtonBox_antenna_rx2.Checked) enable_count++;
            if (chkButtonBox_antenna_rx3.Checked) enable_count++;
            if (chkButtonBox_antenna_tx1.Checked) enable_count++;
            if (chkButtonBox_antenna_tx2.Checked) enable_count++;
            if (chkButtonBox_antenna_tx3.Checked) enable_count++;
            if (chkButtonBox_antenna_byp.Checked) enable_count++;
            if (chkButtonBox_antenna_ext1.Checked) enable_count++;
            if (chkButtonBox_antenna_xvtr.Checked) enable_count++;
            if (chkButtonBox_antenna_rxtxant.Checked) enable_count++;

            return enable_count;
        }

        private void chkMultiMeter_vfo_show_bandtext_CheckedChanged(object sender, EventArgs e)
        {
            updateVfoShowBandtextColour();
            updateMeterType();
        }

        private void clrbtnMultiMeter_vfo_show_bandtext_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void updateVfoShowBandtextColour()
        {
            clrbtnMultiMeter_vfo_show_bandtext.Enabled = chkMultiMeter_vfo_show_bandtext.Checked;
        }

        private void chkLegacyItems_vfoa_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            LegacyItemController.HideVFOA = chkLegacyItems_vfoa.Checked;
        }

        private void chkLegacyItems_vfob_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            LegacyItemController.HideVFOB = chkLegacyItems_vfob.Checked;
        }

        private void chkLegacyItems_expand_spectral_top_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            LegacyItemController.ExpandSpectrumToTop = chkLegacyItems_expand_spectral_top.Checked;
        }

        private void chkLegacyItems_vfosync_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            LegacyItemController.HideVFOSync = chkLegacyItems_vfosync.Checked;
        }

        private void clrbtnMMVfoDisplayFrequency_small_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void btnVFOCopyColourFromMainNumbers_Click(object sender, EventArgs e)
        {
            clrbtnMMVfoDisplayFrequency_small.Color = clrbtnMMVfoDisplayFrequency.Color;
        }

        private void nudHistory_vertical_ratio_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnHistory_background_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkHistory_fade_rx_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkHistory_fade_tx_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudHistory_update_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudHistory_keep_for_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void comboHistory_reading_0_SelectedIndexChanged(object sender, EventArgs e)
        {
            clsComboHistoryItem chi = comboHistory_reading_0.SelectedItem as clsComboHistoryItem;
            if (chi == null) return;

            updateMeterType();
        }
        private class clsComboHistoryItem
        {
            private string _reading_name;
            private Reading _reading;
            public clsComboHistoryItem(Reading r)
            {
                _reading = r;
                _reading_name = MeterManager.ReadingName(r);
            }
            public Reading Reading
            {
                get { return _reading; }
            }
            public string ReadingName
            {
                get { return _reading_name; }
            }
            public override string ToString()
            {
                return _reading_name;
            }
        }
        private void initComboHistoryReadings0()
        {
            List<clsComboHistoryItem> items = new List<clsComboHistoryItem>();
            comboHistory_reading_0.Items.Clear();
            comboHistory_reading_1.Items.Clear();
            for (int i = (int)Reading.SIGNAL_STRENGTH; i <= (int)Reading.SWR; i++)
            {
                if (i == 22 || i == 23) continue; // skip these as not used

                Reading r = (Reading)i;
                clsComboHistoryItem chi = new clsComboHistoryItem(r);
                items.Add(chi);
            }

            items = items.OrderBy(item => item.ReadingName).ToList();

            foreach (clsComboHistoryItem chi in items)
            {
                int index = comboHistory_reading_0.Items.Add(chi);
                index = comboHistory_reading_1.Items.Add(chi);
            }
        }

        private void nudHistory_axis0_min_ValueChanged(object sender, EventArgs e)
        {
            if (nudHistory_axis0_min.Value > nudHistory_axis0_max.Value) nudHistory_axis0_max.Value = nudHistory_axis0_min.Value;
            updateMeterType();
        }

        private void nudHistory_axis0_max_ValueChanged(object sender, EventArgs e)
        {
            if (nudHistory_axis0_max.Value < nudHistory_axis0_min.Value) nudHistory_axis0_min.Value = nudHistory_axis0_max.Value;
            updateMeterType();
        }

        private void chkHistory_auto_0_scale_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void comboHistory_reading_1_SelectedIndexChanged(object sender, EventArgs e)
        {
            clsComboHistoryItem chi = comboHistory_reading_1.SelectedItem as clsComboHistoryItem;
            if (chi == null) return;

            updateMeterType();
        }

        private void chkHistory_auto_1_scale_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void nudHistory_axis1_min_ValueChanged(object sender, EventArgs e)
        {
            if (nudHistory_axis1_min.Value > nudHistory_axis1_max.Value) nudHistory_axis1_max.Value = nudHistory_axis1_min.Value;
            updateMeterType();
        }

        private void nudHistory_axis1_max_ValueChanged(object sender, EventArgs e)
        {
            if (nudHistory_axis1_max.Value < nudHistory_axis1_min.Value) nudHistory_axis1_min.Value = nudHistory_axis1_max.Value;
            updateMeterType();
        }

        private void udDSPNR2trainT2_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            WDSP.SetRXAEMNRtrainT2(WDSP.id(0, 0), (double)udDSPNR2trainT2.Value);
            WDSP.SetRXAEMNRtrainT2(WDSP.id(0, 1), (double)udDSPNR2trainT2.Value);
        }

        private void udDSPNR2trainT2RX2_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            WDSP.SetRXAEMNRtrainT2(WDSP.id(2, 0), (double)udDSPNR2trainT2RX2.Value);
            WDSP.SetRXAEMNRtrainT2(WDSP.id(2, 1), (double)udDSPNR2trainT2RX2.Value);
        }

        private void chkHistory_1_show_axis_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void btnHistory_copy_minmax_from_0_Click(object sender, EventArgs e)
        {
            nudHistory_axis1_min.Value = nudHistory_axis0_min.Value;
            nudHistory_axis1_max.Value = nudHistory_axis0_max.Value;
        }

        private void btnMMIO_variable_history_Click(object sender, EventArgs e)
        {
            mmioSetupVariable(0);
        }

        private void btnMMIO_variable_2_history_Click(object sender, EventArgs e)
        {
            mmioSetupVariable(1);
        }

        private void clrbtnMultiMeter_vfo_lock_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnMultiMeter_vfo_sync_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void ucTunestepOptionsGrid_buttons_checkbox_changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnHistory_colour_0_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnHistory_colour_1_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnHistory_lines_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnHistory_time_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void btnGetMonitorHz_Click(object sender, EventArgs e)
        {
            if (console == null) return;
            udDisplayFPS.Value = (decimal)Display.GetCurrentMonitorRefreshRate(console);
        }

        private void chkLockContainer_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            clsContainerComboboxItem cci = (clsContainerComboboxItem)comboContainerSelect.SelectedItem;
            if (cci != null)
            {
                MeterManager.LockContainer(cci.ID, chkLockContainer.Checked);
                btnContainerDelete.Enabled = !chkLockContainer.Checked;
                btnAddMeterItem.Enabled = !chkLockContainer.Checked;
                btnRemoveMeterItem.Enabled = !chkLockContainer.Checked;
                btnMeterUp.Enabled = !chkLockContainer.Checked;
                btnMeterDown.Enabled = !chkLockContainer.Checked;
            }
        }
        public void SetupCMAsio(bool pa_issue, bool cmasio_config_flag)
        {
            // for these callsigns always show cmasio tab
            List<string> callsign_ignore = new List<string>() { "mw0lge", "m0lge", "oe3ide", "w2pa" };

            bool ignore = false;
            foreach (string call in callsign_ignore)
            {
                string tmp;
                tmp = txtGenCustomTitle == null || txtGenCustomTitle.Text == null ? "" : txtGenCustomTitle.Text;
                ignore |= tmp.Contains(call, StringComparison.OrdinalIgnoreCase);

                tmp = txtOwnCallsign == null || txtOwnCallsign.Text == null ? "" : txtOwnCallsign.Text;
                ignore |= tmp.Contains(call, StringComparison.OrdinalIgnoreCase);
            }

            if (pa_issue || (!cmasio_config_flag && !ignore))
            {
                tcAudio.TabPages.Remove(tpCMAsio);
                return;
            }

            comboASIODevicesAvailable.Items.Clear();

            txtCurrentAsioDevice.Text = CMASIOConfig.GetASIOdrivername();
            nudAsioBlockNum.Value = (decimal)CMASIOConfig.GetASIOblocknum();
            chkAsioLockMode.Checked = CMASIOConfig.GetASIOlockmode();

            //the ASIO driver in use wont be in the list, lets add it
            if (!string.IsNullOrEmpty(txtCurrentAsioDevice.Text)) 
                comboASIODevicesAvailable.Items.Add(txtCurrentAsioDevice.Text);

            comboASIODevicesAvailable.Items.AddRange(CMASIOConfig.GetASIODevices().ToArray());

            if (comboASIODevicesAvailable.Items.Count == 0)
            {
                comboASIODevicesAvailable.Items.Add("None Available");
            }

            setCMasioControls(!string.IsNullOrEmpty(txtCurrentAsioDevice.Text));
        }

        private void btnCMASIOActive_Click(object sender, EventArgs e)
        {
            if (comboASIODevicesAvailable.SelectedItem == null) return;
            string selected = comboASIODevicesAvailable.SelectedItem.ToString();
            if (selected == "None Available") return;
            if (string.IsNullOrEmpty(selected)) return;

            CMASIOConfig.SetASIOdrivername(selected);
            setCMasioControls(true);
            updateCMAsioInfo();
        }

        private void btnCMASIODisable_Click(object sender, EventArgs e)
        {
            CMASIOConfig.SetASIOdrivername("");
            updateCMAsioInfo();
        }
        private void setCMasioControls(bool enabled)
        {
            nudAsioBlockNum.Enabled = enabled;
            chkAsioLockMode.Enabled = enabled;
            nudAsioBlockNum.Enabled = enabled;
            btnCMAsioDefaultBlockNum.Enabled = enabled;
        }
        private void nudAsioBlockNum_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            CMASIOConfig.SetASIOblocknum((int)nudAsioBlockNum.Value, chkAsioLockMode.Checked);
            updateCMAsioInfo();
        }

        private void comboASIODevicesAvailable_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
        }

        private void chkAsioLockMode_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            CMASIOConfig.SetASIOblocknum((int)nudAsioBlockNum.Value, chkAsioLockMode.Checked);
            updateCMAsioInfo();
        }

        private void btnCMAsioDefaultBlockNum_Click(object sender, EventArgs e)
        {
            nudAsioBlockNum.Value = 5;
        }
        private void updateCMAsioInfo()
        {
            lblCMAsioInfo.Text = "Settings updated. Restart to take effect.";
            lblCMAsioInfo.Visible = true;
        }
        private void tmrLedValid_Tick(object sender, EventArgs e)
        {
            if (!txtLedIndicator_condition.Visible) tmrLedValid.Enabled = false;
            updateLedValidControls();
        }

        private void chkLed_notx_true_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void chkLed_notx_false_CheckedChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }
        private void nudLedIndicator_UpdateInterval_ValueChanged(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void tcCAT_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            if (tcCAT.SelectedTab == tpMultiMetersIO)
                updateVariableList();
        }

        private void chkAutoATTTXPsOff_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.AutoAttTXWhenNotInPS = chkAutoATTTXPsOff.Checked;
            chkUndoAutoATTTx.Enabled = chkAutoATTTXPsOff.Checked;
        }

        private void chkUndoAutoATTTx_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.UndoAutoATttTX = chkUndoAutoATTTx.Checked;
        }

        private void chkAutoATTRx1_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            setupAttRXControls(1);
            console.AutoAttRX1 = chkAutoATTRx1.Checked;
            chkAutoAttUndoRX1_CheckedChanged(this, EventArgs.Empty);
        }
        private void setupAttRXControls(int rx)
        {
            bool enabled;
            if(rx==1)
                enabled = chkAutoATTRx1.Checked && chkAutoATTRx1.Enabled; // enabled used for radios that dont have rx1
            else
                enabled = chkAutoATTRx2.Checked && chkAutoATTRx2.Enabled; // enabled used for radios that dont have rx2

            if (rx == 1)
            {
                chkAutoAttUndoRX1.Enabled = enabled;
                nudAutoAttHoldRX1.Enabled = enabled;
                lblAutoAttHoldRX1.Enabled = enabled;
            }
            else
            {
                chkAutoAttUndoRX2.Enabled = enabled;
                nudAutoAttHoldRX2.Enabled = enabled;
                lblAutoAttHoldRX2.Enabled = enabled;
            }
        }

        private void chkAutoAttUndoRX1_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.AutoAttUndoRX1 = chkAutoAttUndoRX1.Checked;
            nudAutoAttHoldRX1_ValueChanged(this, EventArgs.Empty);
        }

        private void nudAutoAttHoldRX1_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.AutoAttUndoDelayRX1 = (int)nudAutoAttHoldRX1.Value;
        }

        private void chkAutoATTRx2_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            setupAttRXControls(2);
            console.AutoAttRX2 = chkAutoATTRx2.Checked;
            chkAutoAttUndoRX2_CheckedChanged(this, EventArgs.Empty);
        }

        private void chkAutoAttUndoRX2_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.AutoAttUndoRX2 = chkAutoAttUndoRX2.Checked;
            nudAutoAttHoldRX2_ValueChanged(this, EventArgs.Empty);
        }

        private void nudAutoAttHoldRX2_ValueChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            console.AutoAttUndoDelayRX2 = (int)nudAutoAttHoldRX2.Value;
        }

        private void lnkDiscordJoin_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            lnkDiscordJoin.LinkVisited = true;
            Common.OpenUri("https://discord.gg/6fHCRKnDc9");
        }

        private void chkDiscordEnabled_CheckedChanged(object sender, EventArgs e)
        {
            if (initializing) return;

            txtDiscordCallsign_TextChanged(this, EventArgs.Empty);
            if (ThetisBotDiscord.IsValidCallsign(txtDiscordCallsign.Text))
            {
                chkDiscordEnabled.Enabled = true;
                ThetisBotDiscord.SetEnabled(chkDiscordEnabled.Checked);
            }
            else
            {
                chkDiscordEnabled.Checked = false;
                chkDiscordEnabled.Enabled = false;
            }

            updateDiscordState();
        }

        private void txtDiscordCallsign_TextChanged(object sender, EventArgs e)
        {
            if (initializing) return;
            ThetisBotDiscord.SetCallsign(txtDiscordCallsign.Text);
            if (!ThetisBotDiscord.IsValidCallsign(txtDiscordCallsign.Text))
            {
                chkDiscordEnabled.Checked = false;
                chkDiscordEnabled.Enabled = false;
            }
            else
                chkDiscordEnabled.Enabled = true;

            updateDiscordState();
        }
        private void updateDiscordState()
        {
            if (ThetisBotDiscord.IsConnected)
            {
                if (ThetisBotDiscord.IsReady)
                {
                    lblDiscordState.Text = "Connected + Ready";
                }
                else
                {
                    lblDiscordState.Text = "Connected + Waiting for ready...";
                }
            }
            else
            {
                if (chkDiscordEnabled.Checked)
                {
                    lblDiscordState.Text = "Tyring to connect...";
                }
                else
                {
                    lblDiscordState.Text = "Disconnected";
                }
            }
        }
        private void OnDiscordConnect()
        {
            updateDiscordState();
        }
        private void OnDiscordDisconnect()
        {
            updateDiscordState();
        }
        private void OnDiscordReady()
        {
            updateDiscordState();
        }

        private void txtDiscordUniqueIDs_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '[' || e.KeyChar == ']' || e.KeyChar == '"' ||
                e.KeyChar == '\'' || e.KeyChar == '\\' || e.KeyChar == '/' || e.KeyChar == '%')
            {
                e.Handled = true;
            }
        }

        private void txtDiscordFilter_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '[' || e.KeyChar == ']' || e.KeyChar == '"' ||
                e.KeyChar == '\'' || e.KeyChar == '\\' || e.KeyChar == '/' || e.KeyChar == '%')
            {
                e.Handled = true;
            }
        }

        private void txtDiscordUniqueIDs_TextChanged(object sender, EventArgs e)
        {
            ThetisBotDiscord.UniqueIDs = txtDiscordUniqueIDs.Text;
        }

        private void txtDiscordFilter_TextChanged(object sender, EventArgs e)
        {
            ThetisBotDiscord.Filter = txtDiscordFilter.Text;
        }

        private void clrbtnButonBox_click_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void clrbtnButonBox_fontcolour_Changed(object sender, EventArgs e)
        {
            updateMeterType();
        }

        private void txtDiscordIgnore_TextChanged(object sender, EventArgs e)
        {
            ThetisBotDiscord.Ignore = txtDiscordIgnore.Text;
        }

        private void pbDiscordInfo_tag_Click(object sender, EventArgs e)
        {
            toolTip1.Show(toolTip1.GetToolTip(txtDiscordUniqueIDs), txtDiscordUniqueIDs, 10 * 1000);
        }

        private void pbDiscordInfo_ignore_Click(object sender, EventArgs e)
        {
            toolTip1.Show(toolTip1.GetToolTip(txtDiscordIgnore), txtDiscordIgnore, 10 * 1000);
        }

        private void pbDiscordInfo_filter_Click(object sender, EventArgs e)
        {
            toolTip1.Show(toolTip1.GetToolTip(txtDiscordFilter), txtDiscordFilter, 10 * 1000);
        }

        private void txtDiscordIgnore_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '[' || e.KeyChar == ']' || e.KeyChar == '"' ||
                e.KeyChar == '\'' || e.KeyChar == '\\' || e.KeyChar == '/' || e.KeyChar == '%')
            {
                e.Handled = true;
            }
        }
        //wd5y
        private void chkAmpDRVLim_CheckedChanged(object sender, EventArgs e)
        {
            if (chkAmpDRVLim.Checked == true & console.chkExternalPA.Checked == true)
            {
                int drvlimpwr = (int)(console.ptbPWR.Value / (float)(console.ptbPWR.Maximum - console.ptbPWR.Minimum) * GetPABandMaxPower(console.TXBand));
                int tunlimpwr = (int)(console.ptbTune.Value / (float)(console.ptbTune.Maximum - console.ptbTune.Minimum) * GetPABandMaxPower(console.TXBand));

                if (numUpDnDRVLim.Value < drvlimpwr & numUpDnTUNLim.Value < tunlimpwr)
                {
                    console.RXOnly = true;
                    console.chkExternalPA.Checked = false;
                    console.ptbPWR.Value = 0;
                    console.lblPWR.Text = "Drive: " + 0 + "w";
                    console.lblPWR2.Text = "Drive:" + 0 + "w";
                    console.ptbTune.Value = 0;
                    console.lblTune.Text = "Tune: " + 0 + "w";
                    console.lblTune2.Text = "Tune:" + 0 + "w";

                    MessageBox.Show("The Drive And/Or Tune Power Is Above The Maximum Limit.", "Release PTT And Reset Power.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    console.RXOnly = false;
                    console.chkExternalPA.Checked = true;
                    return;
                }
            }

            if (chkAmpDRVLim.Checked == true & console.chkExternalPA.Checked == true)
            {
                int drvlimpwr = (int)(console.ptbPWR.Value / (float)(console.ptbPWR.Maximum - console.ptbPWR.Minimum) * GetPABandMaxPower(console.TXBand));

                if (numUpDnDRVLim.Value < drvlimpwr)
                {
                    console.RXOnly = true;
                    console.chkExternalPA.Checked = false;
                    console.ptbPWR.Value = 0;
                    console.lblPWR.Text = "Drive: " + 0 + "w";
                    console.lblPWR2.Text = "Drive:" + 0 + "w";

                    MessageBox.Show("The Drive And/Or Tune Power Is Above The Maximum Limit.", "Release PTT And Reset Power.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    console.RXOnly = false;
                    console.chkExternalPA.Checked = true;
                    return;
                }
            }
            if (chkAmpDRVLim.Checked == true & console.chkExternalPA.Checked == true)
            {
                int tunlimpwr = (int)(console.ptbTune.Value / (float)(console.ptbTune.Maximum - console.ptbTune.Minimum) * GetPABandMaxPower(console.TXBand));

                if (numUpDnTUNLim.Value < tunlimpwr)
                {
                    console.RXOnly = true;
                    console.chkExternalPA.Checked = false;
                    console.ptbTune.Value = 0;
                    console.lblTune.Text = "Tune: " + 0 + "w";
                    console.lblTune2.Text = "Tune:" + 0 + "w";

                    MessageBox.Show("The Drive And/Or Tune Power Is Above The Maximum Limit.", "Release PTT And Reset Power.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    console.RXOnly = false;
                    console.chkExternalPA.Checked = true;
                    return;
                }
            }
        }
        //wd5y
    }

    #region PADeviceInfo Helper Class

    public class PADeviceInfo
    {
        private string _Name;
        private int _Index;

        public string Name
        {
            get { return _Name; }
        }

        public int Index
        {
            get { return _Index; }
        }

        public PADeviceInfo(String argName, int argIndex)
        {
            _Name = argName;
            _Index = argIndex;
        }

        public override string ToString()
        {
            //ToString is used by the combo box to show the text
            //[2.10.3.6]MW0LGE fixes #414, note might have issues when first running up, but should be ok after a profile save
            byte[] bytes = Encoding.Default.GetBytes(_Name);
            return Encoding.UTF8.GetString(bytes);
        }       
    }

    #endregion

    #region 60m Channels Class

    public class Channel60m
    {
        private double freq;
        public Channel60m(double f)
            : base()
        {
            freq = f;
        }

        public double Freq
        {
            get
            {
                return freq;
            }
            set
            {
                freq = value;
            }
        }
    }
    #endregion
}