From 7a5dc5ad58d98852afe158be8427244191b61fcb Mon Sep 17 00:00:00 2001 From: denny Date: Sun, 20 Mar 2016 06:27:53 -0400 Subject: [PATCH] wip: #34 Updates the HackRF tuner editor and a few other tuner config/editor items --- .../TunerConfigurationFactory.java | 4 +- .../tuner/hackrf/HackRFInformationPanel.java | 104 --- .../hackrf/HackRFTunerConfigurationPanel.java | 557 -------------- .../tuner/hackrf/HackRFTunerEditor.java | 464 ++++++++++++ .../tuner/hackrf/HackRFTunerEditorPanel.java | 123 ---- src/source/tuner/rtl/RTL2832InfoPanel.java | 76 -- src/source/tuner/rtl/RTL2832TunerType.java | 28 - .../rtl/e4k/E4KTunerConfigurationPanel.java | 687 ----------------- src/source/tuner/rtl/e4k/E4KTunerEditor.java | 9 +- .../R820TTunerConfigurationEditorOld.java | 695 ------------------ .../tuner/rtl/r820t/R820TTunerEditor.java | 13 +- 11 files changed, 478 insertions(+), 2282 deletions(-) delete mode 100644 src/source/tuner/hackrf/HackRFInformationPanel.java delete mode 100644 src/source/tuner/hackrf/HackRFTunerConfigurationPanel.java create mode 100644 src/source/tuner/hackrf/HackRFTunerEditor.java delete mode 100644 src/source/tuner/hackrf/HackRFTunerEditorPanel.java delete mode 100644 src/source/tuner/rtl/RTL2832InfoPanel.java delete mode 100644 src/source/tuner/rtl/RTL2832TunerType.java delete mode 100644 src/source/tuner/rtl/e4k/E4KTunerConfigurationPanel.java delete mode 100644 src/source/tuner/rtl/r820t/R820TTunerConfigurationEditorOld.java diff --git a/src/source/tuner/configuration/TunerConfigurationFactory.java b/src/source/tuner/configuration/TunerConfigurationFactory.java index 7684f820..1851bec7 100644 --- a/src/source/tuner/configuration/TunerConfigurationFactory.java +++ b/src/source/tuner/configuration/TunerConfigurationFactory.java @@ -9,7 +9,9 @@ import source.tuner.airspy.AirspyTunerConfiguration; import source.tuner.airspy.AirspyTunerEditor; import source.tuner.fcd.proV1.FCD1TunerConfiguration; import source.tuner.fcd.proplusV2.FCD2TunerConfiguration; +import source.tuner.hackrf.HackRFTuner; import source.tuner.hackrf.HackRFTunerConfiguration; +import source.tuner.hackrf.HackRFTunerEditor; import source.tuner.rtl.RTL2832Tuner; import source.tuner.rtl.e4k.E4KTunerConfiguration; import source.tuner.rtl.e4k.E4KTunerEditor; @@ -62,7 +64,7 @@ public class TunerConfigurationFactory case FUNCUBE_DONGLE_PRO_PLUS: return new EmptyEditor( "a tuner" ); case HACKRF: - return new EmptyEditor( "a tuner" ); + return new HackRFTunerEditor( model, (HackRFTuner)tuner ); case RAFAELMICRO_R820T: return new R820TTunerEditor( model, (RTL2832Tuner)tuner ); case UNKNOWN: diff --git a/src/source/tuner/hackrf/HackRFInformationPanel.java b/src/source/tuner/hackrf/HackRFInformationPanel.java deleted file mode 100644 index f3825577..00000000 --- a/src/source/tuner/hackrf/HackRFInformationPanel.java +++ /dev/null @@ -1,104 +0,0 @@ -package source.tuner.hackrf; - -/******************************************************************************* - * SDR Trunk - * Copyright (C) 2014 Dennis Sheirer - * - * 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 3 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, see - ******************************************************************************/ - -import javax.swing.JLabel; -import javax.swing.JPanel; - -import net.miginfocom.swing.MigLayout; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import source.tuner.hackrf.HackRFTunerController.Serial; - -public class HackRFInformationPanel extends JPanel -{ - private static final long serialVersionUID = 1L; - - private final static Logger mLog = - LoggerFactory.getLogger( HackRFInformationPanel.class ); - - private HackRFTunerController mController; - - /** - * Displays HackRF firmware, serial number and part identifier - */ - public HackRFInformationPanel( HackRFTunerController controller ) - { - mController = controller; - - initGUI(); - } - - private void initGUI() - { - setLayout( new MigLayout( "fill,wrap 2", - "[right,grow][grow]", - "[][][][grow]" ) ); - - Serial serial = null; - - try - { - serial = mController.getSerial(); - } - catch( Exception e ) - { - mLog.error( "couldn't read HackRF serial number", e ); - } - - if( serial != null ) - { - add( new JLabel( "Serial:" ) ); - add( new JLabel( serial.getSerialNumber() ) ); - add( new JLabel( "Part:" ) ); - add( new JLabel( serial.getPartID() ) ); - } - else - { - add( new JLabel( "Serial:" ) ); - add( new JLabel( "Unknown" ) ); - add( new JLabel( "Part:" ) ); - add( new JLabel( "Unknown" ) ); - } - - String firmware = null; - - try - { - firmware = mController.getFirmwareVersion(); - } - catch( Exception e ) - { - mLog.error( "couldn't read HackRF firmware version", e ); - } - - add( new JLabel( "Firmware:" ) ); - - if( firmware != null ) - { - add( new JLabel( firmware ) ); - } - else - { - add( new JLabel( "Unknown" ) ); - } - } -} diff --git a/src/source/tuner/hackrf/HackRFTunerConfigurationPanel.java b/src/source/tuner/hackrf/HackRFTunerConfigurationPanel.java deleted file mode 100644 index 92ff881b..00000000 --- a/src/source/tuner/hackrf/HackRFTunerConfigurationPanel.java +++ /dev/null @@ -1,557 +0,0 @@ -/******************************************************************************* - * SDR Trunk - * Copyright (C) 2014 Dennis Sheirer - * - * 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 3 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, see - ******************************************************************************/ -package source.tuner.hackrf; - -import java.awt.EventQueue; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.text.DecimalFormat; - -import javax.swing.BorderFactory; -import javax.swing.ComboBoxModel; -import javax.swing.DefaultComboBoxModel; -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JSpinner; -import javax.swing.JTextField; -import javax.swing.JToggleButton; -import javax.swing.SpinnerModel; -import javax.swing.SpinnerNumberModel; -import javax.swing.SwingConstants; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import javax.usb.UsbException; - -import net.miginfocom.swing.MigLayout; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import settings.SettingsManager; -import source.SourceException; -import source.tuner.hackrf.HackRFTunerController.HackRFLNAGain; -import source.tuner.hackrf.HackRFTunerController.HackRFSampleRate; -import source.tuner.hackrf.HackRFTunerController.HackRFVGAGain; - -public class HackRFTunerConfigurationPanel extends JPanel -{ - private final static Logger mLog = - LoggerFactory.getLogger( HackRFTunerConfigurationPanel.class ); - - private static final long serialVersionUID = 1L; - - private SettingsManager mSettingsManager; - private HackRFTunerController mController; - private HackRFTunerConfiguration mSelectedConfig; - - private JButton mNewConfiguration; - private JButton mDeleteConfiguration; - private JComboBox mComboConfigurations; - - private JTextField mName; - - private JSpinner mFrequencyCorrection; - private JToggleButton mAmplifier; - private JComboBox mComboLNAGain; - private JComboBox mComboVGAGain; - - private JComboBox mComboSampleRate; - - public HackRFTunerConfigurationPanel( SettingsManager settingsManager, - HackRFTunerController controller ) - { - mSettingsManager = settingsManager; - mController = controller; - - init(); - } - - /** - * Initializes the gui components - */ - private void init() - { - setLayout( new MigLayout( "fill,wrap 2", "[grow,right][grow]", "[][][][][][][grow]" ) ); - - /** - * Tuner configuration selector - */ - mComboConfigurations = new JComboBox(); - - mComboConfigurations.setModel( getModel() ); - - /* Determine which tuner configuration should be selected/displayed */ -// TunerConfigurationAssignment savedConfig = null; - String serial = null; - - try - { - serial = mController.getSerial().getSerialNumber(); - } - catch ( UsbException e2 ) - { - mLog.error( "couldn't read hackrf serial number", e2 ); - } - -// if( serial != null ) -// { -// savedConfig = mSettingsManager.getSelectedTunerConfiguration( -// TunerType.HACKRF, serial ); -// } -// -// if( savedConfig != null ) -// { -// mSelectedConfig = getNamedConfiguration( -// savedConfig.getTunerConfigurationName() ); -// } - - /* If we couldn't determine the saved/selected config, use the first one */ - if( mSelectedConfig == null ) - { - mSelectedConfig = mComboConfigurations.getItemAt( 0 ); - - //Store this config as the default for this tuner at this address - -// if( serial != null ) -// { -// mSettingsManager -// .setSelectedTunerConfiguration( TunerType.HACKRF, -// serial, mSelectedConfig ); -// } - } - - mComboConfigurations.setSelectedItem( mSelectedConfig ); - - mComboConfigurations.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent e ) - { - HackRFTunerConfiguration selected = - (HackRFTunerConfiguration)mComboConfigurations - .getItemAt( mComboConfigurations.getSelectedIndex() ); - - if( selected != null ) - { - update( selected ); - } - } - }); - - add( new JLabel( "Config:" ) ); - add( mComboConfigurations, "growx,push" ); - - - /** - * Tuner Configuration Name - */ - mName = new JTextField(); - mName.setText( mSelectedConfig.getName() ); - - mName.addFocusListener( new FocusListener() - { - @Override - public void focusLost( FocusEvent e ) - { - mSelectedConfig.setName( mName.getText() ); - save(); - } - @Override - public void focusGained( FocusEvent e ) {} - } ); - - add( new JLabel( "Name:" ) ); - add( mName, "growx,push" ); - - /** - * Frequency Correction - */ - SpinnerModel model = - new SpinnerNumberModel( 0.0, //initial value - -1000.0, //min - 1000.0, //max - 0.1 ); //step - - mFrequencyCorrection = new JSpinner( model ); - - JSpinner.NumberEditor editor = - (JSpinner.NumberEditor)mFrequencyCorrection.getEditor(); - - DecimalFormat format = editor.getFormat(); - format.setMinimumFractionDigits( 1 ); - editor.getTextField().setHorizontalAlignment( SwingConstants.CENTER ); - - mFrequencyCorrection.setValue( mSelectedConfig.getFrequencyCorrection() ); - - mFrequencyCorrection.addChangeListener( new ChangeListener() - { - @Override - public void stateChanged( ChangeEvent e ) - { - final double value = ((SpinnerNumberModel)mFrequencyCorrection - .getModel()).getNumber().doubleValue(); - - EventQueue.invokeLater( new Runnable() - { - @Override - public void run() - { - try - { - mController.setFrequencyCorrection( value ); - mSelectedConfig.setFrequencyCorrection( value ); - save(); - } - catch ( SourceException e1 ) - { - JOptionPane.showMessageDialog( - HackRFTunerConfigurationPanel.this, - "HackRF Tuner Controller - couldn't apply " - + "frequency correction value: " + value + - e1.getLocalizedMessage() ); - - mLog.error( "HackRF Tuner Controller - couldn't apply " - + "frequency correction value: " + value, e1 ); - } - } - } ); - } - } ); - - add( new JLabel( "Correction PPM:" ) ); - add( mFrequencyCorrection, "growx,push" ); - - /** - * Sample Rate - */ - mComboSampleRate = new JComboBox<>( HackRFSampleRate.values() ); - mComboSampleRate.setSelectedItem( mSelectedConfig.getSampleRate() ); - mComboSampleRate.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent e ) - { - HackRFSampleRate sampleRate = - (HackRFSampleRate)mComboSampleRate.getSelectedItem(); - try - { - - mController.setSampleRate( sampleRate ); - - mSelectedConfig.setSampleRate( sampleRate ); - save(); - } - catch ( UsbException e2 ) - { - JOptionPane.showMessageDialog( - HackRFTunerConfigurationPanel.this, - "HackRF Tuner Controller - couldn't apply the sample " - + "rate setting [" + sampleRate.getLabel() + "] " + - e2.getLocalizedMessage() ); - - mLog.error( "HackRF Tuner Controller - couldn't apply sample " - + "rate setting [" + sampleRate.getLabel() + "]", e ); - } - } - } ); - add( new JLabel( "Sample Rate:" ) ); - add( mComboSampleRate, "growx,push" ); - - /** - * Gain Controls - */ - JPanel gainPanel = new JPanel(); - gainPanel.setLayout( new MigLayout( "", - "[][right][grow,fill][right][grow,fill]", "[grow,fill]" ) ); - gainPanel.setBorder( BorderFactory.createTitledBorder( "Gain" ) ); - - /* Amplifier */ - mAmplifier = new JToggleButton( "Amp" ); - mAmplifier.setSelected( mSelectedConfig.getAmplifierEnabled() ); - mAmplifier.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent arg0 ) - { - try - { - mController.setAmplifierEnabled( mAmplifier.isSelected() ); - mSelectedConfig.setAmplifierEnabled( mAmplifier.isSelected() ); - save(); - } - catch ( UsbException e ) - { - mLog.error( "couldn't enable/disable amplifier", e ); - mAmplifier.setEnabled( !mAmplifier.isSelected() ); - - JOptionPane.showMessageDialog( - HackRFTunerConfigurationPanel.this, - "Couldn't change amplifier setting", - "Error changing amplifier setting", - JOptionPane.ERROR_MESSAGE ); - } - } - } ); - gainPanel.add( mAmplifier ); - - /* LNA Gain Control */ - mComboLNAGain = new JComboBox( HackRFLNAGain.values() ); - mComboLNAGain.setSelectedItem( mSelectedConfig.getLNAGain() ); - mComboLNAGain.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent arg0 ) - { - try - { - HackRFLNAGain lnaGain = - (HackRFLNAGain)mComboLNAGain.getSelectedItem(); - - if ( lnaGain == null ) - { - lnaGain = HackRFLNAGain.GAIN_0; - } - - if( mComboLNAGain.isEnabled() ) - { - mController.setLNAGain( lnaGain ); - } - - mSelectedConfig.setLNAGain( lnaGain ); - - save(); - } - catch ( UsbException e ) - { - JOptionPane.showMessageDialog( - HackRFTunerConfigurationPanel.this, - "HackRF Tuner Controller - couldn't apply the LNA " - + "gain setting - " + e.getLocalizedMessage() ); - - mLog.error( "HackRF Tuner Controller - couldn't apply LNA " - + "gain setting - ", e ); - } - } - } ); - mComboLNAGain.setToolTipText( "LNA Gain. Adjust to set " - + "the IF gain" ); - gainPanel.add( new JLabel( "LNA" ) ); - gainPanel.add( mComboLNAGain ); - - /* VGA Gain Control */ - mComboVGAGain = new JComboBox( HackRFVGAGain.values() ); - mComboVGAGain.setSelectedItem( mSelectedConfig.getVGAGain() ); - mComboVGAGain.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent arg0 ) - { - try - { - HackRFVGAGain vgaGain = (HackRFVGAGain)mComboVGAGain.getSelectedItem(); - - if( vgaGain == null ) - { - vgaGain = HackRFVGAGain.GAIN_4; - } - - if( mComboVGAGain.isEnabled() ) - { - mController.setVGAGain( vgaGain ); - } - - mSelectedConfig.setVGAGain( vgaGain ); - save(); - } - catch ( UsbException e ) - { - JOptionPane.showMessageDialog( - HackRFTunerConfigurationPanel.this, - "HackRF Tuner Controller - couldn't apply the VGA " - + "gain setting - " + e.getLocalizedMessage() ); - - mLog.error( "HackRF Tuner Controller - couldn't apply VGA " - + "gain setting", e ); - } - } - } ); - mComboVGAGain.setToolTipText( "VGA Gain. Adjust to set the " - + "baseband gain" ); - gainPanel.add( new JLabel( "VGA" ) ); - gainPanel.add( mComboVGAGain, "wrap" ); - - add( gainPanel, "span,growx" ); - - /** - * Create a new configuration - */ - mNewConfiguration = new JButton( "New" ); - - mNewConfiguration.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent e ) - { -// TunerConfiguration config = -// mSettingsManager -// .addNewTunerConfiguration( -// TunerType.HACKRF, -// "New Configuration" ); - - mComboConfigurations.setModel( getModel() ); - -// mComboConfigurations.setSelectedItem( config ); - - repaint(); - } - } ); - - add( mNewConfiguration, "growx,push" ); - - /** - * Delete the currently selected configuration - */ - mDeleteConfiguration = new JButton( "Delete" ); - - mDeleteConfiguration.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent e ) - { - HackRFTunerConfiguration selected = - (HackRFTunerConfiguration)mComboConfigurations - .getItemAt( mComboConfigurations.getSelectedIndex() ); - - if( selected != null ) - { - int n = JOptionPane.showConfirmDialog( - HackRFTunerConfigurationPanel.this, - "Are you sure you want to delete '" - + selected.getName() + "'?", - "Are you sure?", - JOptionPane.YES_NO_OPTION ); - - if( n == JOptionPane.YES_OPTION ) - { -// mSettingsManager -// .deleteTunerConfiguration( selected ); - - mComboConfigurations.setModel( getModel() ); - - mComboConfigurations.setSelectedIndex( 0 ); - - repaint(); - } - } - } - } ); - - add( mDeleteConfiguration, "growx,push,wrap" ); - } - - /** - * Updates gui controls with the values from the tuner configuration - * @param config - tuner configuration - */ - private void update( HackRFTunerConfiguration config ) - { - mSelectedConfig = config; - - try - { - mController.apply( config ); - - mName.setText( config.getName() ); - mFrequencyCorrection.setValue( config.getFrequencyCorrection() ); - - mComboLNAGain.setSelectedItem( mSelectedConfig.getLNAGain() ); - mComboVGAGain.setSelectedItem( mSelectedConfig.getVGAGain() ); - - mComboSampleRate.setSelectedItem( mSelectedConfig.getSampleRate() ); - -// mSettingsManager.setSelectedTunerConfiguration( -// TunerType.HACKRF, mController.getSerial().getSerialNumber(), config ); - } - catch ( SourceException e1 ) - { - JOptionPane.showMessageDialog( - HackRFTunerConfigurationPanel.this, - "HackRF Tuner Controller - couldn't " - + "apply the tuner configuration settings - " + - e1.getLocalizedMessage() ); - - mLog.error( "HackRF Tuner Controller - couldn't apply " - + "config [" + config.getName() + "]", e1 ); - } - } - - /** - * Constructs a combo box model for the tuner configuration combo component - * by assembling a list of the tuner configurations appropriate for this - * specific tuner - */ - private ComboBoxModel getModel() - { -// ArrayList configs = -// mSettingsManager -// .getTunerConfigurations( TunerType.HACKRF ); - - DefaultComboBoxModel model = - new DefaultComboBoxModel(); - -// for( TunerConfiguration config: configs ) -// { -// model.addElement( (HackRFTunerConfiguration)config ); -// } - - return model; - } - - /** - * Retrieves a specific (named) tuner configuration - */ - private HackRFTunerConfiguration getNamedConfiguration( String name ) - { -// ArrayList configs = -// mSettingsManager -// .getTunerConfigurations( TunerType.HACKRF ); - -// for( TunerConfiguration config: configs ) -// { -// if( config.getName().contentEquals( name ) ) -// { -// return (HackRFTunerConfiguration)config; -// } -// } - - return null; - } - - /** - * Saves current tuner configuration settings - */ - private void save() - { -// mSettingsManager.save(); - } -} diff --git a/src/source/tuner/hackrf/HackRFTunerEditor.java b/src/source/tuner/hackrf/HackRFTunerEditor.java new file mode 100644 index 00000000..81542ef5 --- /dev/null +++ b/src/source/tuner/hackrf/HackRFTunerEditor.java @@ -0,0 +1,464 @@ +/******************************************************************************* + * SDR Trunk + * Copyright (C) 2014-2016 Dennis Sheirer + * + * 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 3 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, see + ******************************************************************************/ +package source.tuner.hackrf; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.text.DecimalFormat; + +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JSeparator; +import javax.swing.JSpinner; +import javax.swing.JTextField; +import javax.swing.JToggleButton; +import javax.swing.SpinnerModel; +import javax.swing.SpinnerNumberModel; +import javax.swing.SwingConstants; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.usb.UsbException; + +import net.miginfocom.swing.MigLayout; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import source.SourceException; +import source.tuner.configuration.TunerConfiguration; +import source.tuner.configuration.TunerConfigurationEditor; +import source.tuner.configuration.TunerConfigurationEvent; +import source.tuner.configuration.TunerConfigurationEvent.Event; +import source.tuner.configuration.TunerConfigurationModel; +import source.tuner.hackrf.HackRFTunerController.BoardID; +import source.tuner.hackrf.HackRFTunerController.HackRFLNAGain; +import source.tuner.hackrf.HackRFTunerController.HackRFSampleRate; +import source.tuner.hackrf.HackRFTunerController.HackRFVGAGain; +import source.tuner.hackrf.HackRFTunerController.Serial; + +public class HackRFTunerEditor extends TunerConfigurationEditor +{ + private static final long serialVersionUID = 1L; + + private final static Logger mLog = LoggerFactory.getLogger( HackRFTunerEditor.class ); + + private JTextField mConfigurationName; + private JButton mTunerInfo; + private JComboBox mComboSampleRate; + private JSpinner mFrequencyCorrection; + private JToggleButton mAmplifier; + private JComboBox mComboLNAGain; + private JComboBox mComboVGAGain; + private boolean mLoading; + + private HackRFTunerController mController; + + public HackRFTunerEditor( TunerConfigurationModel tunerConfigurationModel, HackRFTuner tuner ) + { + super( tunerConfigurationModel ); + + mController = tuner.getController(); + + init(); + } + + private HackRFTunerConfiguration getConfiguration() + { + if( hasItem() ) + { + return (HackRFTunerConfiguration)getItem(); + } + + return null; + } + + private void init() + { + setLayout( new MigLayout( "fill,wrap 4", "[right][grow,fill][right][grow,fill]", + "[][][][][][][grow]" ) ); + + add( new JLabel( "HackRF Tuner Configuration" ), "span,align center" ); + + mConfigurationName = new JTextField(); + mConfigurationName.setEnabled( false ); + mConfigurationName.addFocusListener( new FocusListener() + { + @Override + public void focusLost( FocusEvent e ) + { + save(); + } + @Override + public void focusGained( FocusEvent e ) {} + } ); + + add( new JLabel( "Name:" ) ); + add( mConfigurationName, "span 2" ); + + mTunerInfo = new JButton( "Tuner Info" ); + mTunerInfo.setEnabled( false ); + mTunerInfo.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + JOptionPane.showMessageDialog( HackRFTunerEditor.this, getTunerInfo(), + "Tuner Info", JOptionPane.INFORMATION_MESSAGE ); + } + } ); + add( mTunerInfo ); + + mComboSampleRate = new JComboBox<>( HackRFSampleRate.values() ); + mComboSampleRate.setEnabled( false ); + mComboSampleRate.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + HackRFSampleRate sampleRate = + (HackRFSampleRate)mComboSampleRate.getSelectedItem(); + try + { + + mController.setSampleRate( sampleRate ); + save(); + } + catch ( UsbException e2 ) + { + JOptionPane.showMessageDialog( HackRFTunerEditor.this, "HackRF Tuner Controller" + + " - couldn't apply the sample rate setting [" + sampleRate.getLabel() + + "] " + e2.getLocalizedMessage() ); + + mLog.error( "HackRF Tuner Controller - couldn't apply sample rate setting [" + + sampleRate.getLabel() + "]", e ); + } + } + } ); + add( new JLabel( "Sample Rate:" ) ); + add( mComboSampleRate ); + + SpinnerModel model = new SpinnerNumberModel( 0.0, //initial value + -1000.0, //min + 1000.0, //max + 0.1 ); //step + + mFrequencyCorrection = new JSpinner( model ); + mFrequencyCorrection.setEnabled( false ); + JSpinner.NumberEditor editor = (JSpinner.NumberEditor)mFrequencyCorrection.getEditor(); + + DecimalFormat format = editor.getFormat(); + format.setMinimumFractionDigits( 1 ); + editor.getTextField().setHorizontalAlignment( SwingConstants.CENTER ); + + mFrequencyCorrection.addChangeListener( new ChangeListener() + { + @Override + public void stateChanged( ChangeEvent e ) + { + final double value = ((SpinnerNumberModel)mFrequencyCorrection + .getModel()).getNumber().doubleValue(); + + try + { + mController.setFrequencyCorrection( value ); + save(); + } + catch ( SourceException e1 ) + { + JOptionPane.showMessageDialog( HackRFTunerEditor.this, "HackRF Tuner Controller" + + " - couldn't apply frequency correction value: " + value + + e1.getLocalizedMessage() ); + + mLog.error( "HackRF Tuner Controller - couldn't apply frequency correction " + + "value: " + value, e1 ); + } + } + } ); + + add( new JLabel( "PPM:" ) ); + add( mFrequencyCorrection ); + + add( new JSeparator( JSeparator.HORIZONTAL ), "span,grow" ); + add( new JLabel( "Gain" ) ); + add( new JLabel( "" ), "span 2" ); //filler + + mAmplifier = new JToggleButton( "Amplifier" ); + mAmplifier.setEnabled( false ); + mAmplifier.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent arg0 ) + { + try + { + mController.setAmplifierEnabled( mAmplifier.isSelected() ); + save(); + } + catch ( UsbException e ) + { + mLog.error( "couldn't enable/disable amplifier", e ); + + JOptionPane.showMessageDialog( HackRFTunerEditor.this, "Couldn't change amplifier setting", + "Error changing amplifier setting", JOptionPane.ERROR_MESSAGE ); + } + } + } ); + add( mAmplifier ); + + mComboLNAGain = new JComboBox( HackRFLNAGain.values() ); + mComboLNAGain.setEnabled( false ); + mComboLNAGain.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent arg0 ) + { + try + { + HackRFLNAGain lnaGain = (HackRFLNAGain)mComboLNAGain.getSelectedItem(); + + if ( lnaGain == null ) + { + lnaGain = HackRFLNAGain.GAIN_0; + } + + mController.setLNAGain( lnaGain ); + save(); + } + catch ( UsbException e ) + { + JOptionPane.showMessageDialog( HackRFTunerEditor.this, "HackRF Tuner Controller" + + " - couldn't apply the LNA gain setting - " + e.getLocalizedMessage() ); + + mLog.error( "HackRF Tuner Controller - couldn't apply LNA gain setting - ", e ); + } + } + } ); + mComboLNAGain.setToolTipText( "LNA Gain. Adjust to set the IF gain" ); + add( new JLabel( "LNA:" ) ); + add( mComboLNAGain ); + + mComboVGAGain = new JComboBox( HackRFVGAGain.values() ); + mComboVGAGain.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent arg0 ) + { + try + { + HackRFVGAGain vgaGain = (HackRFVGAGain)mComboVGAGain.getSelectedItem(); + + if( vgaGain == null ) + { + vgaGain = HackRFVGAGain.GAIN_4; + } + + mController.setVGAGain( vgaGain ); + save(); + } + catch ( UsbException e ) + { + JOptionPane.showMessageDialog( HackRFTunerEditor.this, "HackRF Tuner Controller" + + " - couldn't apply the VGA gain setting - " + e.getLocalizedMessage() ); + + mLog.error( "HackRF Tuner Controller - couldn't apply VGA gain setting", e ); + } + } + } ); + mComboVGAGain.setToolTipText( "VGA Gain. Adjust to set the baseband gain" ); + add( new JLabel( "VGA:" ) ); + add( mComboVGAGain ); + } + + /** + * Sets each of the tuner configuration controls to the enabled argument state + */ + private void setControlsEnabled( boolean enabled ) + { + if( mConfigurationName.isEnabled() != enabled ) + { + mConfigurationName.setEnabled( enabled ); + } + + if( mTunerInfo.isEnabled() != enabled ) + { + mTunerInfo.setEnabled( enabled ); + } + + if( mFrequencyCorrection.isEnabled() != enabled ) + { + mFrequencyCorrection.setEnabled( enabled ); + } + + if( mComboSampleRate.isEnabled() != enabled ) + { + mComboSampleRate.setEnabled( enabled ); + } + + if( mAmplifier.isEnabled() != enabled ) + { + mAmplifier.setEnabled( enabled ); + } + + if( mComboLNAGain.isEnabled() != enabled ) + { + mComboLNAGain.setEnabled( enabled ); + } + + if( mComboVGAGain.isEnabled() != enabled ) + { + mComboVGAGain.setEnabled( enabled ); + } + } + + private String getTunerInfo() + { + BoardID board = BoardID.INVALID; + + try + { + board = mController.getBoardID(); + } + catch ( UsbException e ) + { + mLog.error( "couldn't read HackRF board identifier", e ); + } + + StringBuilder sb = new StringBuilder(); + + sb.append( "

HackRF Tuner

" ); + + sb.append( "Board: " ); + sb.append( board.getLabel() ); + sb.append( "
" ); + + Serial serial = null; + + try + { + serial = mController.getSerial(); + } + catch( Exception e ) + { + mLog.error( "couldn't read HackRF serial number", e ); + } + + if( serial != null ) + { + sb.append( "Serial: " ); + sb.append( serial.getSerialNumber() ); + sb.append( "
" ); + + sb.append( "Part: " ); + sb.append( serial.getPartID() ); + sb.append( "
" ); + } + else + { + sb.append( "Serial: Unknown
" ); + sb.append( "Part: Unknown
" ); + } + + String firmware = null; + + try + { + firmware = mController.getFirmwareVersion(); + } + catch( Exception e ) + { + mLog.error( "couldn't read HackRF firmware version", e ); + } + + if( firmware != null ) + { + sb.append( "Firmware: " ); + sb.append( firmware ); + sb.append( "
" ); + } + else + { + sb.append( "Firmware: Unknown
" ); + } + + return sb.toString(); + } + + @Override + public void setItem( TunerConfiguration tunerConfiguration ) + { + super.setItem( tunerConfiguration ); + + if( hasItem() ) + { + HackRFTunerConfiguration config = getConfiguration(); + + //Toggle loading so that we don't fire a change event and schedule a settings file save + mLoading = true; + + if( tunerConfiguration.isAssigned() ) + { + setControlsEnabled( true ); + + mConfigurationName.setText( config.getName() ); + mComboSampleRate.setSelectedItem( config.getSampleRate() ); + mFrequencyCorrection.setValue( config.getFrequencyCorrection() ); + mAmplifier.setSelected( config.getAmplifierEnabled() ); + mComboLNAGain.setSelectedItem( config.getLNAGain() ); + mComboVGAGain.setSelectedItem( config.getVGAGain() ); + } + else + { + setControlsEnabled( false ); + mConfigurationName.setText( config.getName() ); + } + + mLoading = false; + } + else + { + setControlsEnabled( false ); + mConfigurationName.setText( "" ); + } + } + + @Override + public void save() + { + if( hasItem() && !mLoading ) + { + HackRFTunerConfiguration config = getConfiguration(); + + config.setName( mConfigurationName.getText() ); + + double value = ((SpinnerNumberModel)mFrequencyCorrection + .getModel()).getNumber().doubleValue(); + config.setFrequencyCorrection( value ); + config.setSampleRate( (HackRFSampleRate)mComboSampleRate.getSelectedItem() ); + config.setAmplifierEnabled( mAmplifier.isSelected() ); + config.setLNAGain( (HackRFLNAGain)mComboLNAGain.getSelectedItem() ); + config.setVGAGain( (HackRFVGAGain)mComboVGAGain.getSelectedItem() ); + + getTunerConfigurationModel().broadcast( + new TunerConfigurationEvent( getConfiguration(), Event.CHANGE ) ); + } + } +} diff --git a/src/source/tuner/hackrf/HackRFTunerEditorPanel.java b/src/source/tuner/hackrf/HackRFTunerEditorPanel.java deleted file mode 100644 index c0666bb0..00000000 --- a/src/source/tuner/hackrf/HackRFTunerEditorPanel.java +++ /dev/null @@ -1,123 +0,0 @@ -/******************************************************************************* - * SDR Trunk - * Copyright (C) 2014 Dennis Sheirer - * - * 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 3 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, see - ******************************************************************************/ -package source.tuner.hackrf; - -import gui.control.JFrequencyControl; - -import java.awt.Color; - -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.usb.UsbException; - -import net.miginfocom.swing.MigLayout; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import settings.SettingsManager; -import source.SourceException; -import source.tuner.frequency.FrequencyChangeEvent; -import source.tuner.frequency.FrequencyChangeEvent.Event; -import source.tuner.frequency.IFrequencyChangeProcessor; -import source.tuner.hackrf.HackRFTunerController.BoardID; - -import com.jidesoft.swing.JideTabbedPane; - -public class HackRFTunerEditorPanel extends JPanel implements IFrequencyChangeProcessor -{ - private static final long serialVersionUID = 1L; - - private final static Logger mLog = - LoggerFactory.getLogger( HackRFTunerEditorPanel.class ); - - private JFrequencyControl mFrequencyControl; - - private HackRFTuner mTuner; - private HackRFTunerController mController; - private SettingsManager mSettingsManager; - - public HackRFTunerEditorPanel( HackRFTuner tuner, - SettingsManager resourceManager ) - { - mTuner = tuner; - mController = mTuner.getController(); - mSettingsManager = resourceManager; - - initGUI(); - } - - private void initGUI() - { - setLayout( new MigLayout( "fill,wrap 2", - "[right,grow][grow]", - "[][][][][][grow]" ) ); - - BoardID board = BoardID.INVALID; - - try - { - board = mTuner.getController().getBoardID(); - } - catch ( UsbException e ) - { - mLog.error( "couldn't read HackRF board identifier", e ); - } - - add( new JLabel( board.getLabel() ), "span,align center" ); - - mFrequencyControl = new JFrequencyControl(); - - mFrequencyControl.addListener( this ); - - /* Add frequency control as frequency change listener. This creates a - * feedback loop, so the control does not rebroadcast the event */ - mTuner.getController().addListener( mFrequencyControl ); - - mFrequencyControl.setFrequency( mController.getFrequency(), false ); - - add( mFrequencyControl, "span,align center" ); - - JideTabbedPane tabs = new JideTabbedPane(); - tabs.setFont( this.getFont() ); - tabs.setForeground( Color.BLACK ); - - add( tabs, "span,grow,push" ); - - tabs.add( "Config", new HackRFTunerConfigurationPanel( - mSettingsManager, mTuner.getController() ) ); - - tabs.add( "Info", new HackRFInformationPanel( mTuner.getController() ) ); - } - - @Override - public void frequencyChanged( FrequencyChangeEvent event ) - { - if( event.getEvent() == Event.NOTIFICATION_FREQUENCY_CHANGE ) - { - try - { - mController.setFrequency( event.getValue().longValue() ); - } - catch ( SourceException e ) - { - mLog.error( "error setting frequency [" + event.getValue().longValue() + "]", e ); - } - } - } -} diff --git a/src/source/tuner/rtl/RTL2832InfoPanel.java b/src/source/tuner/rtl/RTL2832InfoPanel.java deleted file mode 100644 index f65bfbc9..00000000 --- a/src/source/tuner/rtl/RTL2832InfoPanel.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * SDR Trunk - * Copyright (C) 2014 Dennis Sheirer - * - * 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 3 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, see - ******************************************************************************/ -package source.tuner.rtl; - -import javax.swing.JLabel; -import javax.swing.JPanel; - -import net.miginfocom.swing.MigLayout; -import source.tuner.rtl.RTL2832TunerController.Descriptor; - -public class RTL2832InfoPanel extends JPanel -{ - RTL2832TunerController mController; - - public RTL2832InfoPanel( RTL2832TunerController controller ) - { - mController = controller; - - init(); - } - - public void dispose() - { - mController = null; - } - - private void init() - { - setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][][][][][][][grow]" ) ); - - Descriptor descriptor = mController.getDescriptor(); - - add( new JLabel( "RTL-2832 EEPROM Descriptor" ), "span,align center" ); - - if( descriptor == null ) - { - add( new JLabel( "No descriptor" ), "wrap" ) ; - } - else - { - add( new JLabel( "USB ID:" ) ) ; - add( new JLabel( descriptor.getVendorID() + ":" + - descriptor.getProductID() ), "wrap" ) ; - - add( new JLabel( "Vendor:" ) ) ; - add( new JLabel( descriptor.getVendorLabel() ), "wrap" ) ; - - add( new JLabel( "Product:" ) ) ; - add( new JLabel( descriptor.getProductLabel() ), "wrap" ) ; - - add( new JLabel( "Serial:" ) ) ; - add( new JLabel( descriptor.getSerial() ), "wrap" ) ; - - add( new JLabel( "IR Enabled:" ) ) ; - add( new JLabel( ( descriptor.irEnabled() ? "Yes" : "No" ) ), "wrap" ) ; - - add( new JLabel( "Remote Wake:" ) ) ; - add( new JLabel( ( descriptor.remoteWakeupEnabled() ? "Yes" : "No" ) ), "wrap" ) ; - } - } -} diff --git a/src/source/tuner/rtl/RTL2832TunerType.java b/src/source/tuner/rtl/RTL2832TunerType.java deleted file mode 100644 index 72233f32..00000000 --- a/src/source/tuner/rtl/RTL2832TunerType.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * SDR Trunk - * Copyright (C) 2014 Dennis Sheirer - * - * 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 3 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, see - ******************************************************************************/ -package source.tuner.rtl; - -public enum RTL2832TunerType -{ - E4000, - FC0012, - FC0013, - R820T, - R828D, - UNKNOWN; -} diff --git a/src/source/tuner/rtl/e4k/E4KTunerConfigurationPanel.java b/src/source/tuner/rtl/e4k/E4KTunerConfigurationPanel.java deleted file mode 100644 index 3ec3e0db..00000000 --- a/src/source/tuner/rtl/e4k/E4KTunerConfigurationPanel.java +++ /dev/null @@ -1,687 +0,0 @@ -/******************************************************************************* - * SDR Trunk - * Copyright (C) 2014 Dennis Sheirer - * - * 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 3 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, see - ******************************************************************************/ -package source.tuner.rtl.e4k; - -import java.awt.EventQueue; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.text.DecimalFormat; - -import javax.swing.BorderFactory; -import javax.swing.ComboBoxModel; -import javax.swing.DefaultComboBoxModel; -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JSpinner; -import javax.swing.JTextField; -import javax.swing.SpinnerModel; -import javax.swing.SpinnerNumberModel; -import javax.swing.SwingConstants; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import javax.usb.UsbException; - -import net.miginfocom.swing.MigLayout; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.usb4java.LibUsbException; - -import settings.SettingsManager; -import source.SourceException; -import source.tuner.rtl.RTL2832TunerController.SampleRate; -import source.tuner.rtl.e4k.E4KTunerController.E4KEnhanceGain; -import source.tuner.rtl.e4k.E4KTunerController.E4KGain; -import source.tuner.rtl.e4k.E4KTunerController.E4KLNAGain; -import source.tuner.rtl.e4k.E4KTunerController.E4KMixerGain; - -public class E4KTunerConfigurationPanel extends JPanel -{ - private static final long serialVersionUID = 1L; - private final static Logger mLog = - LoggerFactory.getLogger( E4KTunerConfigurationPanel.class ); - - private SettingsManager mSettingsManager; - private E4KTunerController mController; - private E4KTunerConfiguration mSelectedConfig; - - private JButton mNewConfiguration; - private JButton mDeleteConfiguration; - private JComboBox mComboConfigurations; - - private JTextField mName; - - private JSpinner mFrequencyCorrection; - private JSpinner mSampleRateCorrection; - private JComboBox mComboMasterGain; - private JComboBox mComboMixerGain; - private JComboBox mComboLNAGain; - private JComboBox mComboEnhanceGain; - - private JComboBox mComboSampleRate; - - public E4KTunerConfigurationPanel( SettingsManager settingsManager, - E4KTunerController controller ) - { - mSettingsManager = settingsManager; - mController = controller; - - init(); - } - - /** - * Initializes the gui components - */ - private void init() - { - setLayout( new MigLayout( "fill,wrap 2", "[grow,right][grow]", "[][][][][][][grow]" ) ); - - /** - * Tuner configuration selector - */ - mComboConfigurations = new JComboBox(); - - mComboConfigurations.setModel( getModel() ); - - /* Determine which tuner configuration should be selected/displayed */ -// TunerConfigurationAssignment savedConfig = mSettingsManager -// .getSelectedTunerConfiguration( -// TunerType.ELONICS_E4000, mController.getUniqueID() ); -// -// if( savedConfig != null ) -// { -// mSelectedConfig = getNamedConfiguration( -// savedConfig.getTunerConfigurationName() ); -// } - - /* If we couldn't determine the saved/selected config, use the first one */ - if( mSelectedConfig == null ) - { - mSelectedConfig = mComboConfigurations.getItemAt( 0 ); - - //Store this config as the default for this tuner at this address -// mSettingsManager -// .setSelectedTunerConfiguration( -// TunerType.ELONICS_E4000, -// mController.getUniqueID(), mSelectedConfig ); - } - - mComboConfigurations.setSelectedItem( mSelectedConfig ); - - mComboConfigurations.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent e ) - { - E4KTunerConfiguration selected = - (E4KTunerConfiguration)mComboConfigurations - .getItemAt( mComboConfigurations.getSelectedIndex() ); - - if( selected != null ) - { - update( selected ); - } - } - }); - - add( new JLabel( "Config:" ) ); - add( mComboConfigurations, "growx,push" ); - - /** - * Tuner Configuration Name - */ - add( new JLabel( "Name:" ) ); - mName = new JTextField(); - mName.setText( mSelectedConfig.getName() ); - - mName.addFocusListener( new FocusListener() - { - @Override - public void focusLost( FocusEvent e ) - { - /* Update the config name */ - mSelectedConfig.setName( mName.getText() ); - - /* Reset this named config as the assigned config for this - * tuner */ -// mSettingsManager -// .setSelectedTunerConfiguration( -// TunerType.ELONICS_E4000, -// mController.getUniqueID(), mSelectedConfig ); - - save(); - } - @Override - public void focusGained( FocusEvent e ) {} - } ); - - add( mName, "growx,push" ); - - /** - * Frequency Correction - */ - SpinnerModel model = - new SpinnerNumberModel( 0.0, //initial value - -1000.0, //min - 1000.0, //max - 0.1 ); //step - - mFrequencyCorrection = new JSpinner( model ); - - JSpinner.NumberEditor editor = - (JSpinner.NumberEditor)mFrequencyCorrection.getEditor(); - - DecimalFormat format = editor.getFormat(); - format.setMinimumFractionDigits( 1 ); - editor.getTextField().setHorizontalAlignment( SwingConstants.CENTER ); - - mFrequencyCorrection.setValue( mSelectedConfig.getFrequencyCorrection() ); - - mFrequencyCorrection.addChangeListener( new ChangeListener() - { - @Override - public void stateChanged( ChangeEvent e ) - { - final double value = ((SpinnerNumberModel)mFrequencyCorrection - .getModel()).getNumber().doubleValue(); - - EventQueue.invokeLater( new Runnable() - { - @Override - public void run() - { - try - { - mController.setFrequencyCorrection( value ); - mSelectedConfig.setFrequencyCorrection( value ); - save(); - } - catch ( SourceException e1 ) - { - JOptionPane.showMessageDialog( - E4KTunerConfigurationPanel.this, - "E4K Tuner Controller - couldn't apply " - + "frequency correction value: " + value + - e1.getLocalizedMessage() ); - - mLog.error( "E4K Tuner Controller - couldn't apply " - + "frequency correction value: " + value, e1 ); - } - } - } ); - } - } ); - - add( new JLabel( "Correction PPM:" ) ); - add( mFrequencyCorrection, "growx,push" ); - - /** - * Sample Rate - */ - mComboSampleRate = new JComboBox<>( SampleRate.values() ); - mComboSampleRate.setSelectedItem( mSelectedConfig.getSampleRate() ); - mComboSampleRate.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent e ) - { - SampleRate sampleRate = - (SampleRate)mComboSampleRate.getSelectedItem(); - try - { - - mController.setSampleRate( sampleRate ); - - mSelectedConfig.setSampleRate( sampleRate ); - save(); - } - catch ( SourceException | LibUsbException eSampleRate ) - { - JOptionPane.showMessageDialog( - E4KTunerConfigurationPanel.this, - "E4K Tuner Controller - couldn't apply the sample " - + "rate setting [" + sampleRate.getLabel() + "] " + - eSampleRate.getLocalizedMessage() ); - - mLog.error( "E4K Tuner Controller - couldn't apply sample " - + "rate setting [" + sampleRate.getLabel() + "]", - eSampleRate ); - } - } - } ); - add( new JLabel( "Sample Rate:" ) ); - add( mComboSampleRate, "growx,push" ); - -// /** -// * Sample Rate Correction -// */ -// SpinnerModel sampleRateCorrectionModel = -// new SpinnerNumberModel( 0, //initial value -// -32768, //min -// 32767, //max -// 1 ); //step -// -// mSampleRateCorrection = new JSpinner( sampleRateCorrectionModel ); -// -// JSpinner.NumberEditor sampleRateCorrectionEditor = -// (JSpinner.NumberEditor)mSampleRateCorrection.getEditor(); -// -// DecimalFormat sampleRateCorrectionFormat = -// sampleRateCorrectionEditor.getFormat(); -// -// sampleRateCorrectionFormat.setMinimumFractionDigits( 0 ); -// -// sampleRateCorrectionEditor.getTextField() -// .setHorizontalAlignment( SwingConstants.CENTER ); -// -// mSampleRateCorrection.addChangeListener( new ChangeListener() -// { -// @Override -// public void stateChanged( ChangeEvent e ) -// { -// final int value = ((SpinnerNumberModel)mSampleRateCorrection -// .getModel()).getNumber().intValue(); -// -// EventQueue.invokeLater( new Runnable() -// { -// @Override -// public void run() -// { -// try -// { -// mController.setSampleRateFrequencyCorrection( value ); -// } -// catch ( SourceException | UsbException e1 ) -// { -// JOptionPane.showMessageDialog( -// E4KTunerConfigurationPanel.this, -// "E4K Tuner Controller - couldn't apply " -// + "sample rate correction value: " + value + -// e1.getLocalizedMessage() ); -// -// Log.error( "E4K Tuner Controller - couldn't apply " -// + "sample rate correction value: " + value + -// e1.getLocalizedMessage() ); -// } -// } -// } ); -// } -// } ); -// -// add( mSampleRateCorrection ); -// add( new JLabel( "Sample Rate Correction (ppm)" ), "wrap" ); - - /** - * Gain Controls - */ - JPanel gainPanel = new JPanel(); - gainPanel.setLayout( new MigLayout( "fill", "[right][left][right][left]", "" ) ); - gainPanel.setBorder( BorderFactory.createTitledBorder( "Gain" ) ); - - /* Master Gain Control */ - mComboMasterGain = new JComboBox( E4KGain.values() ); - mComboMasterGain.setSelectedItem( mSelectedConfig.getMasterGain() ); - - mComboMasterGain.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent arg0 ) - { - try - { - E4KGain gain = (E4KGain)mComboMasterGain.getSelectedItem(); - - mController.setGain( (E4KGain)mComboMasterGain.getSelectedItem(), true ); - - if( gain == E4KGain.MANUAL ) - { - mComboMixerGain.setSelectedItem( - mController.getMixerGain( true ) ); - mComboMixerGain.setEnabled( true ); - - mComboLNAGain.setSelectedItem( - mController.getLNAGain( true ) ); - mComboLNAGain.setEnabled( true ); - - mComboEnhanceGain.setEnabled( true ); - mComboEnhanceGain.setSelectedItem( - mController.getEnhanceGain( true ) ); - } - else - { - mComboMixerGain.setEnabled( false ); - mComboMixerGain.setSelectedItem( gain.getMixerGain() ); - - mComboLNAGain.setEnabled( false ); - mComboLNAGain.setSelectedItem( gain.getLNAGain() ); - - mComboEnhanceGain.setEnabled( false ); - mComboEnhanceGain.setSelectedItem( gain.getEnhanceGain() ); - } - - mSelectedConfig.setMasterGain( gain ); - save(); - } - catch ( UsbException e ) - { - JOptionPane.showMessageDialog( - E4KTunerConfigurationPanel.this, - "E4K Tuner Controller - couldn't apply the gain " - + "setting - " + e.getLocalizedMessage() ); - - mLog.error( "E4K Tuner Controller - couldn't apply " - + "gain setting", e ); - } - } - } ); - mComboMasterGain.setToolTipText( "Select AUTOMATIC for auto " - + "gain, MANUAL to enable
independent control of " - + "Mixer, LNA and Enhance gain
" - + "settings, or one of the individual gain settings for
" - + "semi-manual gain control" ); - gainPanel.add( new JLabel( "Master" ) ); - gainPanel.add( mComboMasterGain ); - - /* Mixer Gain Control */ - mComboMixerGain = new JComboBox( E4KMixerGain.values() ); - mComboMixerGain.setSelectedItem( mSelectedConfig.getMixerGain() ); - mComboMixerGain.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent arg0 ) - { - EventQueue.invokeLater( new Runnable() - { - @Override - public void run() - { - try - { - E4KMixerGain mixerGain = - (E4KMixerGain)mComboMixerGain.getSelectedItem(); - - if( mComboMixerGain.isEnabled() ) - { - mController.setMixerGain( mixerGain, true ); - } - - mSelectedConfig.setMixerGain( mixerGain ); - save(); - } - catch ( UsbException e ) - { - JOptionPane.showMessageDialog( - E4KTunerConfigurationPanel.this, - "E4K Tuner Controller - couldn't apply the mixer " - + "gain setting - " + e.getLocalizedMessage() ); - - mLog.error( "E4K Tuner Controller - couldn't apply mixer " - + "gain setting", e ); - } - } - } ); - } - } ); - mComboMixerGain.setToolTipText( "Mixer Gain. Set master gain " - + "to MASTER to enable adjustment" ); - mComboMixerGain.setEnabled( false ); - gainPanel.add( new JLabel( "Mixer" ) ); - gainPanel.add( mComboMixerGain, "wrap" ); - - /* LNA Gain Control */ - mComboLNAGain = new JComboBox( E4KLNAGain.values() ); - mComboLNAGain.setSelectedItem( mSelectedConfig.getLNAGain() ); - mComboLNAGain.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent arg0 ) - { - try - { - E4KLNAGain lnaGain = (E4KLNAGain)mComboLNAGain.getSelectedItem(); - - if( mComboLNAGain.isEnabled() ) - { - mController.setLNAGain( lnaGain, true ); - } - - mSelectedConfig.setLNAGain( lnaGain ); - save(); - } - catch ( UsbException e ) - { - JOptionPane.showMessageDialog( - E4KTunerConfigurationPanel.this, - "E4K Tuner Controller - couldn't apply the LNA " - + "gain setting - " + e.getLocalizedMessage() ); - - mLog.error( "E4K Tuner Controller - couldn't apply LNA " - + "gain setting - ", e ); - } - } - } ); - mComboLNAGain.setToolTipText( "LNA Gain. Set master gain " - + "to MANUAL to enable adjustment" ); - mComboLNAGain.setEnabled( false ); - gainPanel.add( new JLabel( "LNA" ) ); - gainPanel.add( mComboLNAGain ); - - /* Enhance Gain Control */ - mComboEnhanceGain = new JComboBox( E4KEnhanceGain.values() ); - mComboEnhanceGain.setSelectedItem( mSelectedConfig.getEnhanceGain() ); - mComboEnhanceGain.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent arg0 ) - { - try - { - E4KEnhanceGain enhanceGain = - (E4KEnhanceGain)mComboEnhanceGain.getSelectedItem(); - - if( mComboEnhanceGain.isEnabled() ) - { - mController.setEnhanceGain( enhanceGain, true ); - } - - mSelectedConfig.setEnhanceGain( enhanceGain ); - save(); - } - catch ( UsbException e ) - { - JOptionPane.showMessageDialog( - E4KTunerConfigurationPanel.this, - "E4K Tuner Controller - couldn't apply the enhance " - + "gain setting - " + e.getLocalizedMessage() ); - - mLog.error( "E4K Tuner Controller - couldn't apply enhance " - + "gain setting", e ); - } - } - } ); - mComboEnhanceGain.setToolTipText( "Enhance Gain. Set master gain " - + "to MANUAL to enable adjustment" ); - mComboEnhanceGain.setEnabled( false ); - gainPanel.add( new JLabel( "Enhance" ) ); - gainPanel.add( mComboEnhanceGain, "wrap" ); - - add( gainPanel, "span,grow,push" ); - - /** - * Create a new configuration - */ - mNewConfiguration = new JButton( "New" ); - - mNewConfiguration.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent e ) - { -// TunerConfiguration config = -// mSettingsManager -// .addNewTunerConfiguration( -// TunerType.ELONICS_E4000, -// "New Configuration" ); - - mComboConfigurations.setModel( getModel() ); - -// mComboConfigurations.setSelectedItem( config ); - - repaint(); - } - } ); - - add( mNewConfiguration, "growx,push" ); - - /** - * Delete the currently selected configuration - */ - mDeleteConfiguration = new JButton( "Delete" ); - - mDeleteConfiguration.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent e ) - { - E4KTunerConfiguration selected = - (E4KTunerConfiguration)mComboConfigurations - .getItemAt( mComboConfigurations.getSelectedIndex() ); - - if( selected != null ) - { - int n = JOptionPane.showConfirmDialog( - E4KTunerConfigurationPanel.this, - "Are you sure you want to delete '" - + selected.getName() + "'?", - "Are you sure?", - JOptionPane.YES_NO_OPTION ); - - if( n == JOptionPane.YES_OPTION ) - { -// mSettingsManager -// .deleteTunerConfiguration( selected ); - - mComboConfigurations.setModel( getModel() ); - - mComboConfigurations.setSelectedIndex( 0 ); - - repaint(); - } - } - } - } ); - - add( mDeleteConfiguration, "growx,push,wrap" ); - } - - /** - * Updates gui controls with the values from the tuner configuration - * @param config - tuner configuration - */ - private void update( E4KTunerConfiguration config ) - { - mSelectedConfig = config; - - try - { - mController.apply( config ); - - mName.setText( config.getName() ); - mFrequencyCorrection.setValue( config.getFrequencyCorrection() ); - - mComboMixerGain.setSelectedItem( mSelectedConfig.getMixerGain() ); - mComboLNAGain.setSelectedItem( mSelectedConfig.getLNAGain() ); - mComboEnhanceGain.setSelectedItem( mSelectedConfig.getEnhanceGain() ); - - /* Apply master gain last so that the Mixer, LNA, and Enhance gain - * settings are updated with the master setting where necessary */ - mComboMasterGain.setSelectedItem( mSelectedConfig.getMasterGain() ); - - mComboSampleRate.setSelectedItem( mSelectedConfig.getSampleRate() ); - -// mSettingsManager.setSelectedTunerConfiguration( -// TunerType.ELONICS_E4000, mController.getUniqueID(), config ); - } - catch ( SourceException e1 ) - { - JOptionPane.showMessageDialog( - E4KTunerConfigurationPanel.this, - "E4K Tuner Controller - couldn't " - + "apply the tuner configuration settings - " + - e1.getLocalizedMessage() ); - - mLog.error( "E4K Tuner Controller - couldn't apply " - + "config [" + config.getName() + "]", e1 ); - } - } - - /** - * Constructs a combo box model for the tuner configuration combo component - * by assembling a list of the tuner configurations appropriate for this - * specific tuner - */ - private ComboBoxModel getModel() - { -// ArrayList configs = -// mSettingsManager -// .getTunerConfigurations( TunerType.ELONICS_E4000 ); - - DefaultComboBoxModel model = - new DefaultComboBoxModel(); - -// for( TunerConfiguration config: configs ) -// { -// model.addElement( (E4KTunerConfiguration)config ); -// } - - return model; - } - - /** - * Retrieves a specific (named) tuner configuration - */ - private E4KTunerConfiguration getNamedConfiguration( String name ) - { -// ArrayList configs = -// mSettingsManager -// .getTunerConfigurations( TunerType.ELONICS_E4000 ); -// -// for( TunerConfiguration config: configs ) -// { -// if( config.getName().contentEquals( name ) ) -// { -// return (E4KTunerConfiguration)config; -// } -// } - - return null; - } - - /** - * Saves current tuner configuration settings - */ - private void save() - { -// mSettingsManager.save(); - } -} diff --git a/src/source/tuner/rtl/e4k/E4KTunerEditor.java b/src/source/tuner/rtl/e4k/E4KTunerEditor.java index 67cfb310..1ea51265 100644 --- a/src/source/tuner/rtl/e4k/E4KTunerEditor.java +++ b/src/source/tuner/rtl/e4k/E4KTunerEditor.java @@ -27,6 +27,7 @@ import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JOptionPane; +import javax.swing.JSeparator; import javax.swing.JSpinner; import javax.swing.JTextField; import javax.swing.SpinnerModel; @@ -131,6 +132,7 @@ public class E4KTunerEditor extends TunerConfigurationEditor add( mTunerInfo ); mComboSampleRate = new JComboBox<>( SampleRate.values() ); + mComboSampleRate.setEnabled( false ); mComboSampleRate.addActionListener( new ActionListener() { @Override @@ -199,6 +201,9 @@ public class E4KTunerEditor extends TunerConfigurationEditor add( new JLabel( "PPM:" ) ); add( mFrequencyCorrection ); + add( new JSeparator( JSeparator.HORIZONTAL ), "span,grow" ); + add( new JLabel( "Gain" ), "wrap" ); + mComboMasterGain = new JComboBox( E4KGain.values() ); mComboMasterGain.setEnabled( false ); mComboMasterGain.addActionListener( new ActionListener() @@ -252,7 +257,7 @@ public class E4KTunerEditor extends TunerConfigurationEditor + "Mixer, LNA and Enhance gain
" + "settings, or one of the individual gain settings for
" + "semi-manual gain control" ); - add( new JLabel( "Master" ) ); + add( new JLabel( "Master:" ) ); add( mComboMasterGain ); mComboMixerGain = new JComboBox( E4KMixerGain.values() ); @@ -279,7 +284,7 @@ public class E4KTunerEditor extends TunerConfigurationEditor mComboMixerGain.setToolTipText( "Mixer Gain. Set master gain " + "to MASTER to enable adjustment" ); mComboMixerGain.setEnabled( false ); - add( new JLabel( "Mixer" ) ); + add( new JLabel( "Mixer:" ) ); add( mComboMixerGain ); mComboLNAGain = new JComboBox( E4KLNAGain.values() ); diff --git a/src/source/tuner/rtl/r820t/R820TTunerConfigurationEditorOld.java b/src/source/tuner/rtl/r820t/R820TTunerConfigurationEditorOld.java deleted file mode 100644 index 841a8e49..00000000 --- a/src/source/tuner/rtl/r820t/R820TTunerConfigurationEditorOld.java +++ /dev/null @@ -1,695 +0,0 @@ -/******************************************************************************* - * SDR Trunk - * Copyright (C) 2014 Dennis Sheirer - * - * 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 3 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, see - ******************************************************************************/ -package source.tuner.rtl.r820t; - -import java.awt.EventQueue; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.text.DecimalFormat; - -import javax.swing.BorderFactory; -import javax.swing.ComboBoxModel; -import javax.swing.DefaultComboBoxModel; -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JSpinner; -import javax.swing.JTextField; -import javax.swing.SpinnerModel; -import javax.swing.SpinnerNumberModel; -import javax.swing.SwingConstants; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import javax.usb.UsbException; - -import net.miginfocom.swing.MigLayout; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.usb4java.LibUsbException; - -import settings.SettingsManager; -import source.SourceException; -import source.tuner.rtl.RTL2832TunerController.SampleRate; -import source.tuner.rtl.r820t.R820TTunerController.R820TGain; -import source.tuner.rtl.r820t.R820TTunerController.R820TLNAGain; -import source.tuner.rtl.r820t.R820TTunerController.R820TMixerGain; -import source.tuner.rtl.r820t.R820TTunerController.R820TVGAGain; - -public class R820TTunerConfigurationEditorOld extends JPanel -{ - private static final long serialVersionUID = 1L; - - private final static Logger mLog = - LoggerFactory.getLogger( R820TTunerConfigurationEditorOld.class ); - - private static final R820TGain DEFAULT_GAIN = R820TGain.GAIN_279; - - private SettingsManager mSettingsManager; - private R820TTunerController mController; - private R820TTunerConfiguration mSelectedConfig; - - private JButton mNewConfiguration; - private JButton mDeleteConfiguration; - private JComboBox mComboConfigurations; - - private JTextField mName; - - private JSpinner mFrequencyCorrection; - private JSpinner mSampleRateCorrection; - private JComboBox mComboMasterGain; - private JComboBox mComboMixerGain; - private JComboBox mComboLNAGain; - private JComboBox mComboVGAGain; - - private JComboBox mComboSampleRate; - - public R820TTunerConfigurationEditorOld( SettingsManager settingsManager, - R820TTunerController controller ) - { - mSettingsManager = settingsManager; - mController = controller; - - init(); - } - - /** - * Initializes the gui components - */ - private void init() - { - setLayout( new MigLayout( "fill,wrap 2", "[grow,right][grow]", "[][][][][][][grow]" ) ); - - /** - * Tuner configuration selector - */ - mComboConfigurations = new JComboBox(); - - mComboConfigurations.setModel( getModel() ); - - /* Determine which tuner configuration should be selected/displayed */ -// TunerConfigurationAssignment savedConfig = mSettingsManager -// .getSelectedTunerConfiguration( -// TunerType.RAFAELMICRO_R820T, mController.getUniqueID() ); -// -// if( savedConfig != null ) -// { -// mSelectedConfig = getNamedConfiguration( -// savedConfig.getTunerConfigurationName() ); -// } - - /* If we couldn't determine the saved/selected config, use the first one */ -// if( mSelectedConfig == null ) -// { -// mSelectedConfig = mComboConfigurations.getItemAt( 0 ); -// -// //Store this config as the default for this tuner at this address -// mSettingsManager -// .setSelectedTunerConfiguration( -// TunerType.RAFAELMICRO_R820T, -// mController.getUniqueID(), mSelectedConfig ); -// } - - mComboConfigurations.setSelectedItem( mSelectedConfig ); - - mComboConfigurations.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent e ) - { - R820TTunerConfiguration selected = - (R820TTunerConfiguration)mComboConfigurations - .getItemAt( mComboConfigurations.getSelectedIndex() ); - - if( selected != null ) - { - update( selected ); - } - } - }); - - add( new JLabel( "Config:" ) ); - add( mComboConfigurations, "growx,push" ); - - - /** - * Tuner Configuration Name - */ - mName = new JTextField(); - mName.setText( mSelectedConfig.getName() ); - - mName.addFocusListener( new FocusListener() - { - @Override - public void focusLost( FocusEvent e ) - { - mSelectedConfig.setName( mName.getText() ); - save(); - } - @Override - public void focusGained( FocusEvent e ) {} - } ); - - add( new JLabel( "Name:" ) ); - add( mName, "growx,push" ); - - /** - * Frequency Correction - */ - SpinnerModel model = - new SpinnerNumberModel( 0.0, //initial value - -1000.0, //min - 1000.0, //max - 0.1 ); //step - - mFrequencyCorrection = new JSpinner( model ); - - JSpinner.NumberEditor editor = - (JSpinner.NumberEditor)mFrequencyCorrection.getEditor(); - - DecimalFormat format = editor.getFormat(); - format.setMinimumFractionDigits( 1 ); - editor.getTextField().setHorizontalAlignment( SwingConstants.CENTER ); - - mFrequencyCorrection.setValue( mSelectedConfig.getFrequencyCorrection() ); - - mFrequencyCorrection.addChangeListener( new ChangeListener() - { - @Override - public void stateChanged( ChangeEvent e ) - { - final double value = ((SpinnerNumberModel)mFrequencyCorrection - .getModel()).getNumber().doubleValue(); - - EventQueue.invokeLater( new Runnable() - { - @Override - public void run() - { - try - { - mController.setFrequencyCorrection( value ); - mSelectedConfig.setFrequencyCorrection( value ); - save(); - } - catch ( SourceException e1 ) - { - JOptionPane.showMessageDialog( - R820TTunerConfigurationEditorOld.this, - "R820T Tuner Controller - couldn't apply " - + "frequency correction value: " + value + - e1.getLocalizedMessage() ); - - mLog.error( "R820T Tuner Controller - couldn't apply " - + "frequency correction value: " + value, e1 ); - } - } - } ); - } - } ); - - add( new JLabel( "Correction PPM:" ) ); - add( mFrequencyCorrection, "growx,push" ); - - /** - * Sample Rate - */ - mComboSampleRate = new JComboBox<>( SampleRate.values() ); - mComboSampleRate.setSelectedItem( mSelectedConfig.getSampleRate() ); - mComboSampleRate.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent e ) - { - SampleRate sampleRate = - (SampleRate)mComboSampleRate.getSelectedItem(); - try - { - - mController.setSampleRate( sampleRate ); - - mSelectedConfig.setSampleRate( sampleRate ); - save(); - } - catch ( SourceException | LibUsbException eSampleRate ) - { - JOptionPane.showMessageDialog( - R820TTunerConfigurationEditorOld.this, - "R820T Tuner Controller - couldn't apply the sample " - + "rate setting [" + sampleRate.getLabel() + "] " + - eSampleRate.getLocalizedMessage() ); - - mLog.error( "R820T Tuner Controller - couldn't apply sample " - + "rate setting [" + sampleRate.getLabel() + "]", - eSampleRate ); - } - } - } ); - add( new JLabel( "Sample Rate:" ) ); - add( mComboSampleRate, "growx,push" ); - -// /** -// * Sample Rate Correction -// */ -// SpinnerModel sampleRateCorrectionModel = -// new SpinnerNumberModel( 0, //initial value -// -32768, //min -// 32767, //max -// 1 ); //step -// -// mSampleRateCorrection = new JSpinner( sampleRateCorrectionModel ); -// -// JSpinner.NumberEditor sampleRateCorrectionEditor = -// (JSpinner.NumberEditor)mSampleRateCorrection.getEditor(); -// -// DecimalFormat sampleRateCorrectionFormat = -// sampleRateCorrectionEditor.getFormat(); -// -// sampleRateCorrectionFormat.setMinimumFractionDigits( 0 ); -// -// sampleRateCorrectionEditor.getTextField() -// .setHorizontalAlignment( SwingConstants.CENTER ); -// -// mSampleRateCorrection.addChangeListener( new ChangeListener() -// { -// @Override -// public void stateChanged( ChangeEvent e ) -// { -// final int value = ((SpinnerNumberModel)mSampleRateCorrection -// .getModel()).getNumber().intValue(); -// -// EventQueue.invokeLater( new Runnable() -// { -// @Override -// public void run() -// { -// try -// { -// mController.setSampleRateFrequencyCorrection( value ); -// } -// catch ( SourceException | LibUsbException e1 ) -// { -// JOptionPane.showMessageDialog( -// R820TTunerConfigurationPanel.this, -// "E4K Tuner Controller - couldn't apply " -// + "sample rate correction value: " + value + -// e1.getLocalizedMessage() ); -// -// mLog.error( "E4K Tuner Controller - couldn't apply " -// + "sample rate correction value: " + value + -// e1.getLocalizedMessage() ); -// } -// } -// } ); -// } -// } ); -// -// add( mSampleRateCorrection ); -// add( new JLabel( "Sample Rate Correction (ppm)" ), "grow,push" ); - - /** - * Gain Controls - */ - JPanel gainPanel = new JPanel(); - gainPanel.setLayout( new MigLayout( "", "[grow,fill]", "[grow,fill]" ) ); - gainPanel.setBorder( BorderFactory.createTitledBorder( "Gain" ) ); - - /* Master Gain Control */ - mComboMasterGain = new JComboBox( R820TGain.values() ); - mComboMasterGain.setSelectedItem( mSelectedConfig.getMasterGain() ); - - mComboMasterGain.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent arg0 ) - { - try - { - R820TGain gain = (R820TGain)mComboMasterGain.getSelectedItem(); - - mController.setGain( (R820TGain)mComboMasterGain.getSelectedItem(), true ); - - if( gain == R820TGain.MANUAL ) - { - mComboMixerGain.setSelectedItem( gain.getMixerGain() ); - mComboMixerGain.setEnabled( true ); - - mComboLNAGain.setSelectedItem( gain.getLNAGain() ); - mComboLNAGain.setEnabled( true ); - - mComboVGAGain.setSelectedItem( gain.getVGAGain() ); - mComboVGAGain.setEnabled( true ); - } - else - { - mComboMixerGain.setEnabled( false ); - mComboMixerGain.setSelectedItem( gain.getMixerGain() ); - - mComboLNAGain.setEnabled( false ); - mComboLNAGain.setSelectedItem( gain.getLNAGain() ); - - mComboVGAGain.setEnabled( false ); - mComboVGAGain.setSelectedItem( gain.getVGAGain() ); - } - - mSelectedConfig.setMasterGain( gain ); - save(); - } - catch ( UsbException e ) - { - JOptionPane.showMessageDialog( - R820TTunerConfigurationEditorOld.this, - "R820T Tuner Controller - couldn't apply the gain " - + "setting - " + e.getLocalizedMessage() ); - - mLog.error( "R820T Tuner Controller - couldn't apply " - + "gain setting - ", e ); - } - } - } ); - mComboMasterGain.setToolTipText( "Select AUTOMATIC for auto " - + "gain, MANUAL to enable
independent control of " - + "Mixer, LNA and Enhance gain
" - + "settings, or one of the individual gain settings for
" - + "semi-manual gain control" ); - gainPanel.add( new JLabel( "Master" ) ); - gainPanel.add( mComboMasterGain ); - - /* Mixer Gain Control */ - mComboMixerGain = new JComboBox( R820TMixerGain.values() ); - mComboMixerGain.setSelectedItem( mSelectedConfig.getMixerGain() ); - mComboMixerGain.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent arg0 ) - { - EventQueue.invokeLater( new Runnable() - { - @Override - public void run() - { - try - { - R820TMixerGain mixerGain = - (R820TMixerGain)mComboMixerGain.getSelectedItem(); - - if( mixerGain == null ) - { - mixerGain = DEFAULT_GAIN.getMixerGain(); - } - - if( mComboMixerGain.isEnabled() ) - { - mController.setMixerGain( mixerGain, true ); - } - - mSelectedConfig.setMixerGain( mixerGain ); - save(); - } - catch ( UsbException e ) - { - JOptionPane.showMessageDialog( - R820TTunerConfigurationEditorOld.this, - "R820T Tuner Controller - couldn't apply the mixer " - + "gain setting - " + e.getLocalizedMessage() ); - - mLog.error( "R820T Tuner Controller - couldn't apply mixer " - + "gain setting - ", e ); - } - } - } ); - } - } ); - mComboMixerGain.setToolTipText( "Mixer Gain. Set master gain " - + "to MASTER to enable adjustment" ); - mComboMixerGain.setEnabled( false ); - gainPanel.add( new JLabel( "Mixer" ) ); - gainPanel.add( mComboMixerGain, "wrap" ); - - /* LNA Gain Control */ - mComboLNAGain = new JComboBox( R820TLNAGain.values() ); - mComboLNAGain.setSelectedItem( mSelectedConfig.getLNAGain() ); - mComboLNAGain.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent arg0 ) - { - try - { - R820TLNAGain lnaGain = - (R820TLNAGain)mComboLNAGain.getSelectedItem(); - - if ( lnaGain == null ) - { - lnaGain = DEFAULT_GAIN.getLNAGain(); - } - - if( mComboLNAGain.isEnabled() ) - { - mController.setLNAGain( lnaGain, true ); - } - - mSelectedConfig.setLNAGain( lnaGain ); - save(); - } - catch ( UsbException e ) - { - JOptionPane.showMessageDialog( - R820TTunerConfigurationEditorOld.this, - "R820T Tuner Controller - couldn't apply the LNA " - + "gain setting - " + e.getLocalizedMessage() ); - - mLog.error( "R820T Tuner Controller - couldn't apply LNA " - + "gain setting - ", e ); - } - } - } ); - mComboLNAGain.setToolTipText( "LNA Gain. Set master gain " - + "to MANUAL to enable adjustment" ); - mComboLNAGain.setEnabled( false ); - gainPanel.add( new JLabel( "LNA" ) ); - gainPanel.add( mComboLNAGain ); - - /* VGA Gain Control */ - mComboVGAGain = new JComboBox( R820TVGAGain.values() ); - mComboVGAGain.setSelectedItem( mSelectedConfig.getVGAGain() ); - mComboVGAGain.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent arg0 ) - { - try - { - R820TVGAGain vgaGain = - (R820TVGAGain)mComboVGAGain.getSelectedItem(); - - if( vgaGain == null ) - { - vgaGain = DEFAULT_GAIN.getVGAGain(); - } - - if( mComboVGAGain.isEnabled() ) - { - mController.setVGAGain( vgaGain, true ); - } - - mSelectedConfig.setVGAGain( vgaGain ); - save(); - } - catch ( UsbException e ) - { - JOptionPane.showMessageDialog( - R820TTunerConfigurationEditorOld.this, - "R820T Tuner Controller - couldn't apply the VGA " - + "gain setting - " + e.getLocalizedMessage() ); - - mLog.error( "R820T Tuner Controller - couldn't apply VGA " - + "gain setting", e ); - } - } - } ); - mComboVGAGain.setToolTipText( "VGA Gain. Set master gain " - + "to MANUAL to enable adjustment" ); - mComboVGAGain.setEnabled( false ); - gainPanel.add( new JLabel( "VGA" ) ); - gainPanel.add( mComboVGAGain, "wrap" ); - - add( gainPanel, "span" ); - - /** - * Create a new configuration - */ - mNewConfiguration = new JButton( "New" ); - - mNewConfiguration.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent e ) - { -// TunerConfiguration config = -// mSettingsManager -// .addNewTunerConfiguration( -// TunerType.RAFAELMICRO_R820T, -// "New Configuration" ); -// -// mComboConfigurations.setModel( getModel() ); -// -// mComboConfigurations.setSelectedItem( config ); -// -// repaint(); - } - } ); - - add( mNewConfiguration, "growx,push" ); - - /** - * Delete the currently selected configuration - */ - mDeleteConfiguration = new JButton( "Delete" ); - - mDeleteConfiguration.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent e ) - { - R820TTunerConfiguration selected = - (R820TTunerConfiguration)mComboConfigurations - .getItemAt( mComboConfigurations.getSelectedIndex() ); - - if( selected != null ) - { - int n = JOptionPane.showConfirmDialog( - R820TTunerConfigurationEditorOld.this, - "Are you sure you want to delete '" - + selected.getName() + "'?", - "Are you sure?", - JOptionPane.YES_NO_OPTION ); - - if( n == JOptionPane.YES_OPTION ) - { -// mSettingsManager -// .deleteTunerConfiguration( selected ); - - mComboConfigurations.setModel( getModel() ); - - mComboConfigurations.setSelectedIndex( 0 ); - - repaint(); - } - } - } - } ); - - add( mDeleteConfiguration, "growx,push,wrap" ); - } - - /** - * Updates gui controls with the values from the tuner configuration - * @param config - tuner configuration - */ - private void update( R820TTunerConfiguration config ) - { - mSelectedConfig = config; - - try - { - mController.apply( config ); - - mName.setText( config.getName() ); - mFrequencyCorrection.setValue( config.getFrequencyCorrection() ); - - mComboMixerGain.setSelectedItem( mSelectedConfig.getMixerGain() ); - mComboLNAGain.setSelectedItem( mSelectedConfig.getLNAGain() ); - mComboVGAGain.setSelectedItem( mSelectedConfig.getVGAGain() ); - - /* Apply master gain last so that the Mixer, LNA, and VGA gain - * settings are updated with the master setting where necessary */ - mComboMasterGain.setSelectedItem( mSelectedConfig.getMasterGain() ); - - mComboSampleRate.setSelectedItem( mSelectedConfig.getSampleRate() ); - -// mSettingsManager.setSelectedTunerConfiguration( -// TunerType.RAFAELMICRO_R820T, mController.getUniqueID(), config ); - } - catch ( SourceException e1 ) - { - JOptionPane.showMessageDialog( - R820TTunerConfigurationEditorOld.this, - "R820T Tuner Controller - couldn't " - + "apply the tuner configuration settings - " + - e1.getLocalizedMessage() ); - - mLog.error( "R820T Tuner Controller - couldn't apply " - + "config [" + config.getName() + "]", e1 ); - } - } - - /** - * Constructs a combo box model for the tuner configuration combo component - * by assembling a list of the tuner configurations appropriate for this - * specific tuner - */ - private ComboBoxModel getModel() - { -// ArrayList configs = -// mSettingsManager -// .getTunerConfigurations( TunerType.RAFAELMICRO_R820T ); - - DefaultComboBoxModel model = - new DefaultComboBoxModel(); - -// for( TunerConfiguration config: configs ) -// { -// model.addElement( (R820TTunerConfiguration)config ); -// } - - return model; - } - - /** - * Retrieves a specific (named) tuner configuration - */ - private R820TTunerConfiguration getNamedConfiguration( String name ) - { -// ArrayList configs = -// mSettingsManager -// .getTunerConfigurations( TunerType.RAFAELMICRO_R820T ); -// -// for( TunerConfiguration config: configs ) -// { -// if( config.getName().contentEquals( name ) ) -// { -// return (R820TTunerConfiguration)config; -// } -// } - - return null; - } - - /** - * Saves current tuner configuration settings - */ - private void save() - { -// mSettingsManager.save(); - } -} diff --git a/src/source/tuner/rtl/r820t/R820TTunerEditor.java b/src/source/tuner/rtl/r820t/R820TTunerEditor.java index 6fddb93e..7c325eb0 100644 --- a/src/source/tuner/rtl/r820t/R820TTunerEditor.java +++ b/src/source/tuner/rtl/r820t/R820TTunerEditor.java @@ -59,8 +59,7 @@ import source.tuner.rtl.r820t.R820TTunerController.R820TVGAGain; public class R820TTunerEditor extends TunerConfigurationEditor { - private final static Logger mLog = - LoggerFactory.getLogger( R820TTunerEditor.class ); + private final static Logger mLog = LoggerFactory.getLogger( R820TTunerEditor.class ); private static final long serialVersionUID = 1L; private static final R820TGain DEFAULT_GAIN = R820TGain.GAIN_279; @@ -69,16 +68,15 @@ public class R820TTunerEditor extends TunerConfigurationEditor private JTextField mConfigurationName; private JButton mTunerInfo; + private JComboBox mComboSampleRate; private JSpinner mFrequencyCorrection; private JComboBox mComboMasterGain; private JComboBox mComboMixerGain; private JComboBox mComboLNAGain; private JComboBox mComboVGAGain; - private JComboBox mComboSampleRate; private boolean mLoading; - public R820TTunerEditor( TunerConfigurationModel tunerConfigurationModel, - RTL2832Tuner tuner ) + public R820TTunerEditor( TunerConfigurationModel tunerConfigurationModel, RTL2832Tuner tuner ) { super( tunerConfigurationModel ); mController = (R820TTunerController)tuner.getController(); @@ -103,9 +101,6 @@ public class R820TTunerEditor extends TunerConfigurationEditor add( new JLabel( "R820T Tuner Configuration" ), "span,align center" ); - /** - * Tuner Configuration Name - */ mConfigurationName = new JTextField(); mConfigurationName.setEnabled( false ); mConfigurationName.addFocusListener( new FocusListener() @@ -215,7 +210,7 @@ public class R820TTunerEditor extends TunerConfigurationEditor /** * Gain Controls */ - add( new JLabel( "Gain" ), "span,align left" ); + add( new JLabel( "Gain" ), "warp" ); /* Master Gain Control */ mComboMasterGain = new JComboBox( R820TGain.values() );