From d3e8816bb4bfbdc526a774257dbfa3189ba312c0 Mon Sep 17 00:00:00 2001 From: denny Date: Sun, 20 Mar 2016 05:30:16 -0400 Subject: [PATCH] wip: #34 Adds the E4000 tuner editor and updates a few other tuner editor pieces. --- .../tuner/airspy/AirspyTunerEditor.java | 7 +- .../TunerConfigurationFactory.java | 19 +- .../TunerConfigurationModel.java | 2 - .../tuner/rtl/e4k/E4KTunerConfiguration.java | 12 +- .../tuner/rtl/e4k/E4KTunerController.java | 16 +- src/source/tuner/rtl/e4k/E4KTunerEditor.java | 494 ++++++++++++++++++ .../tuner/rtl/e4k/E4KTunerEditorPanel.java | 122 ----- .../tuner/rtl/r820t/R820TTunerEditor.java | 236 +++++---- 8 files changed, 635 insertions(+), 273 deletions(-) create mode 100644 src/source/tuner/rtl/e4k/E4KTunerEditor.java delete mode 100644 src/source/tuner/rtl/e4k/E4KTunerEditorPanel.java diff --git a/src/source/tuner/airspy/AirspyTunerEditor.java b/src/source/tuner/airspy/AirspyTunerEditor.java index 36066eaa..ee034ca3 100644 --- a/src/source/tuner/airspy/AirspyTunerEditor.java +++ b/src/source/tuner/airspy/AirspyTunerEditor.java @@ -52,7 +52,9 @@ import source.tuner.airspy.AirspyTunerController.Gain; import source.tuner.airspy.AirspyTunerController.GainMode; import source.tuner.configuration.TunerConfiguration; import source.tuner.configuration.TunerConfigurationEditor; +import source.tuner.configuration.TunerConfigurationEvent; import source.tuner.configuration.TunerConfigurationModel; +import source.tuner.configuration.TunerConfigurationEvent.Event; public class AirspyTunerEditor extends TunerConfigurationEditor { @@ -113,8 +115,6 @@ public class AirspyTunerEditor extends TunerConfigurationEditor add( new JLabel( "Airspy Tuner Configuration" ), "span,align center" ); -// tabs.add( "Info", new AirspyInformationPanel( mController ) ); - mConfigurationName = new JTextField(); mConfigurationName.setEnabled( false ); mConfigurationName.addFocusListener( new FocusListener() @@ -569,6 +569,9 @@ public class AirspyTunerEditor extends TunerConfigurationEditor config.setLNAGain( mLNAGain.getValue() ); config.setMixerAGC( mMixerAGC.isSelected() ); config.setLNAAGC( mLNAAGC.isSelected() ); + + getTunerConfigurationModel().broadcast( + new TunerConfigurationEvent( getConfiguration(), Event.CHANGE ) ); } } diff --git a/src/source/tuner/configuration/TunerConfigurationFactory.java b/src/source/tuner/configuration/TunerConfigurationFactory.java index a8db8333..7684f820 100644 --- a/src/source/tuner/configuration/TunerConfigurationFactory.java +++ b/src/source/tuner/configuration/TunerConfigurationFactory.java @@ -12,11 +12,15 @@ import source.tuner.fcd.proplusV2.FCD2TunerConfiguration; import source.tuner.hackrf.HackRFTunerConfiguration; import source.tuner.rtl.RTL2832Tuner; import source.tuner.rtl.e4k.E4KTunerConfiguration; +import source.tuner.rtl.e4k.E4KTunerEditor; import source.tuner.rtl.r820t.R820TTunerConfiguration; import source.tuner.rtl.r820t.R820TTunerEditor; public class TunerConfigurationFactory { + /** + * Creates a tuner configuration for the specified tuner type, unique ID and name + */ public static TunerConfiguration getTunerConfiguration( TunerType type, String uniqueID, String name ) { @@ -41,6 +45,9 @@ public class TunerConfigurationFactory } } + /** + * Creates a tuner editor gui for the specified tuner + */ public static Editor getEditor( Tuner tuner, TunerConfigurationModel model ) { @@ -49,20 +56,18 @@ public class TunerConfigurationFactory case AIRSPY_R820T: return new AirspyTunerEditor( model, (AirspyTuner)tuner ); case ELONICS_E4000: - break; + return new E4KTunerEditor( model, (RTL2832Tuner)tuner ); case FUNCUBE_DONGLE_PRO: - break; + return new EmptyEditor( "a tuner" ); case FUNCUBE_DONGLE_PRO_PLUS: - break; + return new EmptyEditor( "a tuner" ); case HACKRF: - break; + return new EmptyEditor( "a tuner" ); case RAFAELMICRO_R820T: return new R820TTunerEditor( model, (RTL2832Tuner)tuner ); case UNKNOWN: default: - break; + throw new IllegalArgumentException( "Unrecognized Tuner: " + tuner.getName() ); } - - return new EmptyEditor( "a tuner" ); } } diff --git a/src/source/tuner/configuration/TunerConfigurationModel.java b/src/source/tuner/configuration/TunerConfigurationModel.java index 44f4008f..daa37793 100644 --- a/src/source/tuner/configuration/TunerConfigurationModel.java +++ b/src/source/tuner/configuration/TunerConfigurationModel.java @@ -153,7 +153,6 @@ public class TunerConfigurationModel extends AbstractTableModel { if( config.isAssigned() ) { - mLog.debug( "Unassigning: " + config.getName() ); config.setAssigned( false ); int index = mTunerConfigurations.indexOf( config ); @@ -162,7 +161,6 @@ public class TunerConfigurationModel extends AbstractTableModel } } - mLog.debug( "Assigning: " + configToAssign.getName() ); configToAssign.setAssigned( true ); int index = mTunerConfigurations.indexOf( configToAssign ); fireTableCellUpdated( index, ASSIGNED ); diff --git a/src/source/tuner/rtl/e4k/E4KTunerConfiguration.java b/src/source/tuner/rtl/e4k/E4KTunerConfiguration.java index 072d2fa6..3d4c9eff 100644 --- a/src/source/tuner/rtl/e4k/E4KTunerConfiguration.java +++ b/src/source/tuner/rtl/e4k/E4KTunerConfiguration.java @@ -29,12 +29,12 @@ import source.tuner.rtl.e4k.E4KTunerController.E4KMixerGain; public class E4KTunerConfiguration extends TunerConfiguration { - private E4KGain mMasterGain = E4KGain.AUTOMATIC; - private E4KMixerGain mMixerGain = E4KMixerGain.AUTOMATIC; - private E4KLNAGain mLNAGain = E4KLNAGain.AUTOMATIC; - private E4KEnhanceGain mEnhanceGain = E4KEnhanceGain.AUTOMATIC; - private double mFrequencyCorrection = 8.9d; - private SampleRate mSampleRate = SampleRate.RATE_1_920MHZ; + private E4KGain mMasterGain = E4KGain.MANUAL; + private E4KMixerGain mMixerGain = E4KMixerGain.GAIN_4; + private E4KLNAGain mLNAGain = E4KLNAGain.GAIN_PLUS_200; + private E4KEnhanceGain mEnhanceGain = E4KEnhanceGain.GAIN_3; + private double mFrequencyCorrection = 0.0d; + private SampleRate mSampleRate = SampleRate.RATE_2_400MHZ; /** * Default constructor for JAXB diff --git a/src/source/tuner/rtl/e4k/E4KTunerController.java b/src/source/tuner/rtl/e4k/E4KTunerController.java index 6f4df48c..a5f92bda 100644 --- a/src/source/tuner/rtl/e4k/E4KTunerController.java +++ b/src/source/tuner/rtl/e4k/E4KTunerController.java @@ -19,7 +19,6 @@ package source.tuner.rtl.e4k; import java.util.Arrays; -import javax.swing.JPanel; import javax.usb.UsbException; import org.slf4j.Logger; @@ -30,7 +29,6 @@ import org.usb4java.DeviceHandle; import org.usb4java.LibUsb; import org.usb4java.LibUsbException; -import settings.SettingsManager; import source.SourceException; import source.tuner.TunerType; import source.tuner.configuration.TunerConfiguration; @@ -110,8 +108,6 @@ public class E4KTunerController extends RTL2832TunerController public static final byte CHFCALIB_CMD = (byte)0x01; - private E4KTunerEditorPanel mEditor; - public E4KTunerController( Device device, DeviceDescriptor deviceDescriptor, ThreadPoolManager threadPoolManager ) @@ -252,16 +248,6 @@ public class E4KTunerController extends RTL2832TunerController } } - public JPanel getEditor( SettingsManager settingsManager ) - { - if( mEditor == null ) - { - mEditor = new E4KTunerEditorPanel( this, settingsManager ); - } - - return mEditor; - } - /** * Sets the IF filters (mixer, channel and RC) to the correct filter setting * for the selected bandwidth/sample rate @@ -1070,7 +1056,7 @@ public class E4KTunerController extends RTL2832TunerController (byte)( ( temp & ~mask ) | ( value & mask ) ), controlI2CRepeater ); - int temp2 = readE4KRegister( register, controlI2CRepeater ); + readE4KRegister( register, controlI2CRepeater ); } } diff --git a/src/source/tuner/rtl/e4k/E4KTunerEditor.java b/src/source/tuner/rtl/e4k/E4KTunerEditor.java new file mode 100644 index 00000000..67cfb310 --- /dev/null +++ b/src/source/tuner/rtl/e4k/E4KTunerEditor.java @@ -0,0 +1,494 @@ +/******************************************************************************* + * 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.rtl.e4k; + +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.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 source.SourceException; +import source.tuner.configuration.TunerConfiguration; +import source.tuner.configuration.TunerConfigurationEditor; +import source.tuner.configuration.TunerConfigurationEvent; +import source.tuner.configuration.TunerConfigurationModel; +import source.tuner.rtl.RTL2832Tuner; +import source.tuner.rtl.RTL2832TunerController.Descriptor; +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 E4KTunerEditor extends TunerConfigurationEditor +{ + private final static Logger mLog = LoggerFactory.getLogger( E4KTunerEditor.class ); + + private static final long serialVersionUID = 1L; + + private JTextField mConfigurationName; + private JButton mTunerInfo; + private JComboBox mComboSampleRate; + private JSpinner mFrequencyCorrection; + private JComboBox mComboMasterGain; + private JComboBox mComboMixerGain; + private JComboBox mComboLNAGain; + private JComboBox mComboEnhanceGain; + + private E4KTunerController mController; + private boolean mLoading; + + public E4KTunerEditor( TunerConfigurationModel tunerConfigurationModel, RTL2832Tuner tuner ) + { + super( tunerConfigurationModel ); + mController = (E4KTunerController)tuner.getController(); + + init(); + } + + private E4KTunerConfiguration getConfiguration() + { + if( hasItem() ) + { + return (E4KTunerConfiguration)getItem(); + } + + return null; + } + + private void init() + { + setLayout( new MigLayout( "fill,wrap 4", "[right][grow,fill][right][grow,fill]", + "[][][][][][][][grow]" ) ); + + add( new JLabel( "E4000 Tuner Configuration" ), "span,align center" ); + + /** + * Tuner Configuration Name + */ + add( new JLabel( "Name:" ) ); + mConfigurationName = new JTextField(); + mConfigurationName.setEnabled( false ); + mConfigurationName.addFocusListener( new FocusListener() + { + @Override + public void focusLost( FocusEvent e ) + { + save(); + } + @Override + public void focusGained( FocusEvent e ) {} + } ); + + add( mConfigurationName, "span 2" ); + + mTunerInfo = new JButton( "Tuner Info" ); + mTunerInfo.setEnabled( false ); + mTunerInfo.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + JOptionPane.showMessageDialog( E4KTunerEditor.this, getTunerInfo(), + "Tuner Info", JOptionPane.INFORMATION_MESSAGE ); + } + } ); + add( mTunerInfo ); + + mComboSampleRate = new JComboBox<>( SampleRate.values() ); + mComboSampleRate.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + SampleRate sampleRate = (SampleRate)mComboSampleRate.getSelectedItem(); + + try + { + mController.setSampleRate( sampleRate ); + save(); + } + catch ( SourceException | LibUsbException eSampleRate ) + { + JOptionPane.showMessageDialog( E4KTunerEditor.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 ); + + 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( E4KTunerEditor.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( "PPM:" ) ); + add( mFrequencyCorrection ); + + mComboMasterGain = new JComboBox( E4KGain.values() ); + mComboMasterGain.setEnabled( false ); + 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.setSelectedItem( mController.getEnhanceGain( true ) ); + mComboEnhanceGain.setEnabled( true ); + } + else + { + mComboMixerGain.setEnabled( false ); + mComboMixerGain.setSelectedItem( gain.getMixerGain() ); + + mComboLNAGain.setEnabled( false ); + mComboLNAGain.setSelectedItem( gain.getLNAGain() ); + + mComboEnhanceGain.setEnabled( false ); + mComboEnhanceGain.setSelectedItem( gain.getEnhanceGain() ); + } + + save(); + } + catch ( UsbException e ) + { + JOptionPane.showMessageDialog( E4KTunerEditor.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" ); + add( new JLabel( "Master" ) ); + add( mComboMasterGain ); + + mComboMixerGain = new JComboBox( E4KMixerGain.values() ); + mComboMixerGain.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent arg0 ) + { + try + { + E4KMixerGain mixerGain = (E4KMixerGain)mComboMixerGain.getSelectedItem(); + mController.setMixerGain( mixerGain, true ); + save(); + } + catch ( UsbException e ) + { + JOptionPane.showMessageDialog( E4KTunerEditor.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 ); + add( new JLabel( "Mixer" ) ); + add( mComboMixerGain ); + + mComboLNAGain = new JComboBox( E4KLNAGain.values() ); + mComboLNAGain.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent arg0 ) + { + try + { + E4KLNAGain lnaGain = (E4KLNAGain)mComboLNAGain.getSelectedItem(); + mController.setLNAGain( lnaGain, true ); + save(); + } + catch ( UsbException e ) + { + JOptionPane.showMessageDialog( E4KTunerEditor.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 ); + add( new JLabel( "LNA:" ) ); + add( mComboLNAGain ); + + mComboEnhanceGain = new JComboBox( E4KEnhanceGain.values() ); + mComboEnhanceGain.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent arg0 ) + { + try + { + E4KEnhanceGain enhance = (E4KEnhanceGain)mComboEnhanceGain.getSelectedItem(); + mController.setEnhanceGain( enhance, true ); + save(); + } + catch ( UsbException e ) + { + JOptionPane.showMessageDialog( E4KTunerEditor.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 ); + add( new JLabel( "Enhance:" ) ); + add( mComboEnhanceGain ); + } + + /** + * 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( mComboMasterGain.isEnabled() != enabled ) + { + mComboMasterGain.setEnabled( enabled ); + } + + if( mComboMixerGain.isEnabled() != enabled ) + { + mComboMixerGain.setEnabled( enabled ); + } + + if( mComboLNAGain.isEnabled() != enabled ) + { + mComboLNAGain.setEnabled( enabled ); + } + + if( mComboEnhanceGain.isEnabled() != enabled ) + { + mComboEnhanceGain.setEnabled( enabled ); + } + } + + private String getTunerInfo() + { + StringBuilder sb = new StringBuilder(); + + Descriptor descriptor = mController.getDescriptor(); + + sb.append( "

RTL-2832 with E4000 Tuner

" ); + + if( descriptor == null ) + { + sb.append( "No EEPROM Descriptor Available" ); + } + else + { + sb.append( "USB ID: " ); + sb.append( descriptor.getVendorID() ); + sb.append( ":" ); + sb.append( descriptor.getProductID() ); + sb.append( "
" ); + + sb.append( "Vendor: " ); + sb.append( descriptor.getVendorLabel() ); + sb.append( "
" ); + + sb.append( "Product: " ); + sb.append( descriptor.getProductLabel() ); + sb.append( "
" ); + + sb.append( "Serial: " ); + sb.append( descriptor.getSerial() ); + sb.append( "
" ); + + sb.append( "IR Enabled: " ); + sb.append( descriptor.irEnabled() ); + sb.append( "
" ); + + sb.append( "Remote Wake: " ); + sb.append( descriptor.remoteWakeupEnabled() ); + sb.append( "
" ); + } + + return sb.toString(); + } + + @Override + public void save() + { + if( hasItem() && !mLoading ) + { + E4KTunerConfiguration config = getConfiguration(); + + config.setName( mConfigurationName.getText() ); + + config.setSampleRate( (SampleRate)mComboSampleRate.getSelectedItem() ); + + double value = ((SpinnerNumberModel)mFrequencyCorrection + .getModel()).getNumber().doubleValue(); + config.setFrequencyCorrection( value ); + + config.setMasterGain( (E4KGain)mComboMasterGain.getSelectedItem() ); + config.setMixerGain( (E4KMixerGain)mComboMixerGain.getSelectedItem() ); + config.setLNAGain( (E4KLNAGain)mComboLNAGain.getSelectedItem() ); + config.setEnhanceGain( (E4KEnhanceGain)mComboEnhanceGain.getSelectedItem() ); + + getTunerConfigurationModel().broadcast( new TunerConfigurationEvent( + getConfiguration(), TunerConfigurationEvent.Event.CHANGE ) ); + } + + } + + @Override + public void setItem( TunerConfiguration tunerConfiguration ) + { + super.setItem( tunerConfiguration ); + + if( hasItem() ) + { + E4KTunerConfiguration 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() ); + mFrequencyCorrection.setValue( config.getFrequencyCorrection() ); + mComboSampleRate.setSelectedItem( config.getSampleRate() ); + mComboMasterGain.setSelectedItem( config.getMasterGain() ); + mComboMixerGain.setSelectedItem( config.getMixerGain() ); + mComboLNAGain.setSelectedItem( config.getLNAGain() ); + mComboEnhanceGain.setSelectedItem( config.getEnhanceGain() ); + } + else + { + setControlsEnabled( false ); + mConfigurationName.setText( config.getName() ); + } + + mLoading = false; + } + else + { + setControlsEnabled( false ); + mConfigurationName.setText( "" ); + } + } +} diff --git a/src/source/tuner/rtl/e4k/E4KTunerEditorPanel.java b/src/source/tuner/rtl/e4k/E4KTunerEditorPanel.java deleted file mode 100644 index fe797d55..00000000 --- a/src/source/tuner/rtl/e4k/E4KTunerEditorPanel.java +++ /dev/null @@ -1,122 +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 gui.control.JFrequencyControl; - -import java.awt.Color; -import java.awt.EventQueue; - -import javax.swing.JLabel; -import javax.swing.JPanel; - -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.rtl.RTL2832InfoPanel; - -import com.jidesoft.swing.JideTabbedPane; - -public class E4KTunerEditorPanel extends JPanel implements IFrequencyChangeProcessor -{ - private final static Logger mLog = - LoggerFactory.getLogger( E4KTunerEditorPanel.class ); - - private static final long serialVersionUID = 1L; - - private E4KTunerController mController; - private SettingsManager mSettingsManager; - - private JFrequencyControl mFrequencyControl; - - public E4KTunerEditorPanel( E4KTunerController controller, - SettingsManager settingsManager ) - { - mController = controller; - mSettingsManager = settingsManager; - - initGUI(); - } - - private void initGUI() - { - setLayout( new MigLayout( "fill,wrap 2", "[right][grow]", "[][][grow]" ) ); - - add( new JLabel( "RTL2832 with E4000 Tuner" ), "span 2, align center, wrap" ); - - mFrequencyControl = new JFrequencyControl(); - - mFrequencyControl.addListener( this ); - - /* Add frequency control as listener on the controller, to maintain - * sync with the tuned frequency value */ - mController.addListener( mFrequencyControl ); - - mFrequencyControl.setFrequency( mController.getFrequency(), false ); - - add( mFrequencyControl, "span 2, align center, wrap" ); - - JideTabbedPane tabs = new JideTabbedPane(); - tabs.setFont( this.getFont() ); - tabs.setForeground( Color.BLACK ); - - tabs.addTab( "Configuration", - new E4KTunerConfigurationPanel( mSettingsManager, mController ) ); - - tabs.addTab( "Info", new RTL2832InfoPanel( mController ) ); - - add( tabs, "grow,push,span" ); - } - - /** - * Frequency change listener for the frequency control gui component to - * apply end-user requested frequency changes against the tuner - */ - @Override - public void frequencyChanged( FrequencyChangeEvent event ) - { - if( event.getEvent() == Event.NOTIFICATION_FREQUENCY_CHANGE ) - { - final long frequency = event.getValue().longValue(); - - EventQueue.invokeLater( new Runnable() - { - @Override - public void run() - { - try - { - mController.setFrequency( frequency ); - } - catch ( SourceException e ) - { - mLog.error( "E4KTunerController - error setting frequency [" + - frequency + "]", e ); - } - } - } ); - } - } -} diff --git a/src/source/tuner/rtl/r820t/R820TTunerEditor.java b/src/source/tuner/rtl/r820t/R820TTunerEditor.java index 2a2e68d8..6fddb93e 100644 --- a/src/source/tuner/rtl/r820t/R820TTunerEditor.java +++ b/src/source/tuner/rtl/r820t/R820TTunerEditor.java @@ -44,8 +44,6 @@ import org.slf4j.LoggerFactory; import org.usb4java.LibUsbException; import source.SourceException; -import source.tuner.airspy.AirspyDeviceInformation; -import source.tuner.airspy.AirspyTunerEditor; import source.tuner.configuration.TunerConfiguration; import source.tuner.configuration.TunerConfigurationEditor; import source.tuner.configuration.TunerConfigurationEvent; @@ -87,121 +85,6 @@ public class R820TTunerEditor extends TunerConfigurationEditor init(); } - - @Override - public void save() - { - if( hasItem() && !mLoading ) - { - R820TTunerConfiguration config = getConfiguration(); - - config.setName( mConfigurationName.getText() ); - - double value = ((SpinnerNumberModel)mFrequencyCorrection - .getModel()).getNumber().doubleValue(); - config.setFrequencyCorrection( value ); - - config.setSampleRate( (SampleRate)mComboSampleRate.getSelectedItem() ); - - R820TGain gain = (R820TGain)mComboMasterGain.getSelectedItem(); - config.setMasterGain( gain ); - - R820TMixerGain mixerGain = (R820TMixerGain)mComboMixerGain.getSelectedItem(); - config.setMixerGain( mixerGain ); - - R820TLNAGain lnaGain = (R820TLNAGain)mComboLNAGain.getSelectedItem(); - config.setLNAGain( lnaGain ); - - R820TVGAGain vgaGain = (R820TVGAGain)mComboVGAGain.getSelectedItem(); - config.setVGAGain( vgaGain ); - - getTunerConfigurationModel().broadcast( - new TunerConfigurationEvent( getConfiguration(), Event.CHANGE ) ); - } - } - - @Override - public void setItem( TunerConfiguration item ) - { - super.setItem( item ); - - if( hasItem() ) - { - R820TTunerConfiguration config = getConfiguration(); - - //Toggle loading so that we don't fire a change event and schedule a settings file save - mLoading = true; - - if( item.isAssigned() ) - { - setControlsEnabled( true ); - mConfigurationName.setText( config.getName() ); - mFrequencyCorrection.setValue( config.getFrequencyCorrection() ); - mComboSampleRate.setSelectedItem( config.getSampleRate() ); - mComboMasterGain.setSelectedItem( config.getMasterGain() ); - mComboMixerGain.setSelectedItem( config.getMixerGain() ); - mComboLNAGain.setSelectedItem( config.getLNAGain() ); - mComboVGAGain.setSelectedItem( config.getVGAGain() ); - } - else - { - setControlsEnabled( false ); - mConfigurationName.setText( config.getName() ); - } - - mLoading = false; - } - else - { - setControlsEnabled( false ); - mConfigurationName.setText( "" ); - } - } - /** - * 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( mComboMasterGain.isEnabled() != enabled ) - { - mComboMasterGain.setEnabled( enabled ); - } - - if( mComboMixerGain.isEnabled() != enabled ) - { - mComboMixerGain.setEnabled( enabled ); - } - - if( mComboLNAGain.isEnabled() != enabled ) - { - mComboLNAGain.setEnabled( enabled ); - } - - if( mComboVGAGain.isEnabled() != enabled ) - { - mComboVGAGain.setEnabled( enabled ); - } - } private R820TTunerConfiguration getConfiguration() { @@ -252,7 +135,6 @@ public class R820TTunerEditor extends TunerConfigurationEditor } ); add( mTunerInfo ); - mComboSampleRate = new JComboBox<>( SampleRate.values() ); mComboSampleRate.setEnabled( false ); mComboSampleRate.addActionListener( new ActionListener() @@ -333,7 +215,7 @@ public class R820TTunerEditor extends TunerConfigurationEditor /** * Gain Controls */ - add( new JLabel( "Gain" ), "span" ); + add( new JLabel( "Gain" ), "span,align left" ); /* Master Gain Control */ mComboMasterGain = new JComboBox( R820TGain.values() ); @@ -520,6 +402,52 @@ public class R820TTunerEditor extends TunerConfigurationEditor 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( mComboMasterGain.isEnabled() != enabled ) + { + mComboMasterGain.setEnabled( enabled ); + } + + if( mComboMixerGain.isEnabled() != enabled ) + { + mComboMixerGain.setEnabled( enabled ); + } + + if( mComboLNAGain.isEnabled() != enabled ) + { + mComboLNAGain.setEnabled( enabled ); + } + + if( mComboVGAGain.isEnabled() != enabled ) + { + mComboVGAGain.setEnabled( enabled ); + } + } + private String getTunerInfo() { StringBuilder sb = new StringBuilder(); @@ -563,4 +491,74 @@ public class R820TTunerEditor extends TunerConfigurationEditor return sb.toString(); } + + @Override + public void save() + { + if( hasItem() && !mLoading ) + { + R820TTunerConfiguration config = getConfiguration(); + + config.setName( mConfigurationName.getText() ); + + double value = ((SpinnerNumberModel)mFrequencyCorrection + .getModel()).getNumber().doubleValue(); + config.setFrequencyCorrection( value ); + + config.setSampleRate( (SampleRate)mComboSampleRate.getSelectedItem() ); + + R820TGain gain = (R820TGain)mComboMasterGain.getSelectedItem(); + config.setMasterGain( gain ); + + R820TMixerGain mixerGain = (R820TMixerGain)mComboMixerGain.getSelectedItem(); + config.setMixerGain( mixerGain ); + + R820TLNAGain lnaGain = (R820TLNAGain)mComboLNAGain.getSelectedItem(); + config.setLNAGain( lnaGain ); + + R820TVGAGain vgaGain = (R820TVGAGain)mComboVGAGain.getSelectedItem(); + config.setVGAGain( vgaGain ); + + getTunerConfigurationModel().broadcast( + new TunerConfigurationEvent( getConfiguration(), Event.CHANGE ) ); + } + } + + @Override + public void setItem( TunerConfiguration tunerConfiguration ) + { + super.setItem( tunerConfiguration ); + + if( hasItem() ) + { + R820TTunerConfiguration 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() ); + mFrequencyCorrection.setValue( config.getFrequencyCorrection() ); + mComboSampleRate.setSelectedItem( config.getSampleRate() ); + mComboMasterGain.setSelectedItem( config.getMasterGain() ); + mComboMixerGain.setSelectedItem( config.getMixerGain() ); + mComboLNAGain.setSelectedItem( config.getLNAGain() ); + mComboVGAGain.setSelectedItem( config.getVGAGain() ); + } + else + { + setControlsEnabled( false ); + mConfigurationName.setText( config.getName() ); + } + + mLoading = false; + } + else + { + setControlsEnabled( false ); + mConfigurationName.setText( "" ); + } + } }