Initial code check in continued

This commit is contained in:
dennis.sheirer
2014-04-26 19:48:24 +00:00
parent 960a6f9952
commit 3dfedcf8d1
474 changed files with 76613 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
/*******************************************************************************
* 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 <http://www.gnu.org/licenses/>
******************************************************************************/
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" ) ;
}
}
}

View File

@@ -0,0 +1,59 @@
/*******************************************************************************
* 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 <http://www.gnu.org/licenses/>
******************************************************************************/
package source.tuner.rtl;
import source.Source.SampleType;
import source.mixer.SampleAdapter;
public class RTL2832SampleAdapter extends SampleAdapter
{
private final static float[] mLOOKUP_VALUES;
/**
* Creates a static lookup table that converts the 8-bit valued range
* from 0 - 255 into scaled float values of -128 to 0 to 127
*/
static
{
mLOOKUP_VALUES = new float[ 256 ];
float scale = (float)( 1.0f / 127.0f );
for( int x = 0; x < 256; x++ )
{
mLOOKUP_VALUES[ x ] = (float)( x - 128 ) * scale;
}
mLOOKUP_VALUES[ 128 ] = 0.0000001f;
}
@Override
public Float[] convert( byte[] samples )
{
Float[] convertedSamples = new Float[ samples.length ];
int pointer = 0;
for( byte sample: samples )
{
/* Convert byte value into float from the lookup table */
convertedSamples[ pointer++ ] = mLOOKUP_VALUES[ ( sample & 0xFF ) ];
}
return convertedSamples;
}
}

View File

@@ -0,0 +1,168 @@
/*******************************************************************************
* 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 <http://www.gnu.org/licenses/>
******************************************************************************/
package source.tuner.rtl;
import java.util.concurrent.RejectedExecutionException;
import javax.swing.JPanel;
import javax.usb.UsbException;
import log.Log;
import sample.Listener;
import source.SourceException;
import source.tuner.FrequencyChangeListener;
import source.tuner.Tuner;
import source.tuner.TunerChannel;
import source.tuner.TunerChannelSource;
import source.tuner.TunerClass;
import source.tuner.TunerConfiguration;
import source.tuner.TunerType;
import source.tuner.rtl.RTL2832TunerController.SampleRate;
import controller.ResourceManager;
import controller.ThreadPoolManager;
public class RTL2832Tuner extends Tuner
{
private TunerClass mTunerClass;
protected RTL2832TunerController mController;
public RTL2832Tuner( TunerClass tunerClass,
RTL2832TunerController controller )
throws SourceException
{
super( tunerClass.getVendorDeviceLabel() + "/" +
controller.getTunerType().getLabel() + " #" +
controller.getUniqueID() );
mTunerClass = tunerClass;
mController = controller;
mController.addListener( (FrequencyChangeListener)this );
}
public RTL2832TunerController getController()
{
return mController;
}
@Override
public String getUniqueID()
{
return mController.getUniqueID();
}
@Override
public TunerClass getTunerClass()
{
return mTunerClass;
}
@Override
public TunerType getTunerType()
{
return mController.getTunerType();
}
@Override
public JPanel getEditor( ResourceManager resourceManager )
{
return mController.getEditor( resourceManager );
}
@Override
public void apply( TunerConfiguration config ) throws SourceException
{
mController.apply( config );
}
@Override
public int getSampleRate()
{
try
{
return mController.getCurrentSampleRate();
}
catch( SourceException e )
{
Log.error( "RTL2832 Tuner - couldn't get sample rate - " +
e.getLocalizedMessage() );
}
return 0;
}
public void setSampleRate( SampleRate sampleRate ) throws SourceException
{
try
{
mController.setSampleRate( sampleRate );
}
catch( UsbException e )
{
throw new SourceException( "RTL2832 Tuner - error setting "
+ "sample rate", e );
}
}
@Override
public int getFrequency() throws SourceException
{
return mController.getFrequency();
}
public void setFrequency( int frequency ) throws SourceException
{
mController.setFrequency( frequency );
}
@Override
public TunerChannelSource getChannel( ThreadPoolManager threadPoolManager,
TunerChannel channel )
throws RejectedExecutionException,
SourceException
{
return mController.getChannel( threadPoolManager, this, channel );
}
/**
* Releases the tuned channel so that the tuner controller can tune to
* other frequencies as needed.
*/
@Override
public void releaseChannel( TunerChannelSource source )
{
/* Unregister for receiving samples */
removeListener( (Listener<Float[]>)source );
/* Tell the controller to release the channel and cleanup */
if( source != null )
{
mController.releaseChannel( source );
}
}
@Override
public void addListener( Listener<Float[]> listener )
{
mController.addListener( listener );
}
@Override
public void removeListener( Listener<Float[]> listener )
{
mController.removeListener( listener );
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,28 @@
/*******************************************************************************
* 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 <http://www.gnu.org/licenses/>
******************************************************************************/
package source.tuner.rtl;
public enum RTL2832TunerType
{
E4000,
FC0012,
FC0013,
R820T,
R828D,
UNKNOWN;
}

View File

@@ -0,0 +1,124 @@
/*******************************************************************************
* 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 <http://www.gnu.org/licenses/>
******************************************************************************/
package source.tuner.rtl.e4k;
import javax.xml.bind.annotation.XmlAttribute;
import source.tuner.TunerConfiguration;
import source.tuner.TunerType;
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 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_200MHZ;
/**
* Default constructor for JAXB
*/
public E4KTunerConfiguration()
{
this( "Default" );
}
public E4KTunerConfiguration( String name )
{
super( name );
}
@Override
public TunerType getTunerType()
{
return TunerType.ELONICS_E4000;
}
@XmlAttribute( name="master_gain" )
public E4KGain getMasterGain()
{
return mMasterGain;
}
public void setMasterGain( E4KGain gain )
{
mMasterGain = gain;
}
@XmlAttribute( name="mixer_gain" )
public E4KMixerGain getMixerGain()
{
return mMixerGain;
}
public void setMixerGain( E4KMixerGain mixerGain )
{
mMixerGain = mixerGain;
}
@XmlAttribute( name="lna_gain" )
public E4KLNAGain getLNAGain()
{
return mLNAGain;
}
public void setLNAGain( E4KLNAGain lnaGain )
{
mLNAGain = lnaGain;
}
@XmlAttribute( name="enhance_gain" )
public E4KEnhanceGain getEnhanceGain()
{
return mEnhanceGain;
}
public void setEnhanceGain( E4KEnhanceGain enhanceGain )
{
mEnhanceGain = enhanceGain;
}
@XmlAttribute( name="frequency_correction" )
public double getFrequencyCorrection()
{
return mFrequencyCorrection;
}
public void setFrequencyCorrection( double value )
{
mFrequencyCorrection = value;
}
@XmlAttribute( name="sample_rate" )
public SampleRate getSampleRate()
{
return mSampleRate;
}
public void setSampleRate( SampleRate sampleRate )
{
mSampleRate = sampleRate;
}
}

View File

@@ -0,0 +1,688 @@
/*******************************************************************************
* 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 <http://www.gnu.org/licenses/>
******************************************************************************/
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 java.util.ArrayList;
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 com.jidesoft.swing.JideTabbedPane;
import log.Log;
import net.miginfocom.swing.MigLayout;
import source.SourceException;
import source.tuner.TunerConfiguration;
import source.tuner.TunerConfigurationAssignment;
import source.tuner.TunerType;
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;
import controller.ResourceManager;
public class E4KTunerConfigurationPanel extends JPanel
{
private static final long serialVersionUID = 1L;
private ResourceManager mResourceManager;
private E4KTunerController mController;
private E4KTunerConfiguration mSelectedConfig;
private JButton mNewConfiguration;
private JButton mDeleteConfiguration;
private JComboBox<E4KTunerConfiguration> mComboConfigurations;
private JTextField mName;
private JSpinner mFrequencyCorrection;
private JSpinner mSampleRateCorrection;
private JComboBox<E4KGain> mComboMasterGain;
private JComboBox<E4KMixerGain> mComboMixerGain;
private JComboBox<E4KLNAGain> mComboLNAGain;
private JComboBox<E4KEnhanceGain> mComboEnhanceGain;
private JComboBox<SampleRate> mComboSampleRate;
public E4KTunerConfigurationPanel( ResourceManager resourceManager,
E4KTunerController controller )
{
mResourceManager = resourceManager;
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<E4KTunerConfiguration>();
mComboConfigurations.setModel( getModel() );
/* Determine which tuner configuration should be selected/displayed */
TunerConfigurationAssignment savedConfig = mResourceManager
.getSettingsManager().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
mResourceManager.getSettingsManager()
.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 */
mResourceManager.getSettingsManager()
.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() );
Log.error( "E4K Tuner Controller - couldn't apply "
+ "frequency correction value: " + value +
e1.getLocalizedMessage() );
}
}
} );
}
} );
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 | UsbException eSampleRate )
{
JOptionPane.showMessageDialog(
E4KTunerConfigurationPanel.this,
"E4K Tuner Controller - couldn't apply the sample "
+ "rate setting [" + sampleRate.getLabel() + "] " +
eSampleRate.getLocalizedMessage() );
Log.error( "E4K Tuner Controller - couldn't apply sample "
+ "rate setting [" + sampleRate.getLabel() + "] " +
eSampleRate.getLocalizedMessage() );
}
}
} );
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>( 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() );
Log.error( "E4K Tuner Controller - couldn't apply "
+ "gain setting - " + e.getLocalizedMessage() );
}
}
} );
mComboMasterGain.setToolTipText( "<html>Select <b>AUTOMATIC</b> for auto "
+ "gain, <b>MANUAL</b> to enable<br> independent control of "
+ "<i>Mixer</i>, <i>LNA</i> and <i>Enhance</i> gain<br>"
+ "settings, or one of the individual gain settings for<br>"
+ "semi-manual gain control</html>" );
gainPanel.add( new JLabel( "Master" ) );
gainPanel.add( mComboMasterGain );
/* Mixer Gain Control */
mComboMixerGain = new JComboBox<E4KMixerGain>( 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() );
Log.error( "E4K Tuner Controller - couldn't apply mixer "
+ "gain setting - " + e.getLocalizedMessage() );
}
}
} );
}
} );
mComboMixerGain.setToolTipText( "<html>Mixer Gain. Set master gain "
+ "to <b>MASTER</b> to enable adjustment</html>" );
mComboMixerGain.setEnabled( false );
gainPanel.add( new JLabel( "Mixer" ) );
gainPanel.add( mComboMixerGain, "wrap" );
/* LNA Gain Control */
mComboLNAGain = new JComboBox<E4KLNAGain>( 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() );
Log.error( "E4K Tuner Controller - couldn't apply LNA "
+ "gain setting - " + e.getLocalizedMessage() );
}
}
} );
mComboLNAGain.setToolTipText( "<html>LNA Gain. Set master gain "
+ "to <b>MANUAL</b> to enable adjustment</html>" );
mComboLNAGain.setEnabled( false );
gainPanel.add( new JLabel( "LNA" ) );
gainPanel.add( mComboLNAGain );
/* Enhance Gain Control */
mComboEnhanceGain = new JComboBox<E4KEnhanceGain>( 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() );
Log.error( "E4K Tuner Controller - couldn't apply enhance "
+ "gain setting - " + e.getLocalizedMessage() );
}
}
} );
mComboEnhanceGain.setToolTipText( "<html>Enhance Gain. Set master gain "
+ "to <b>MANUAL</b> to enable adjustment</html>" );
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 =
mResourceManager.getSettingsManager()
.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 )
{
mResourceManager.getSettingsManager()
.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() );
mResourceManager.getSettingsManager().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() );
Log.error( "E4K Tuner Controller - couldn't apply "
+ "config [" + config.getName() + "] - " +
e1.getLocalizedMessage() );
}
}
/**
* 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<E4KTunerConfiguration> getModel()
{
ArrayList<TunerConfiguration> configs =
mResourceManager.getSettingsManager()
.getTunerConfigurations( TunerType.ELONICS_E4000 );
DefaultComboBoxModel<E4KTunerConfiguration> model =
new DefaultComboBoxModel<E4KTunerConfiguration>();
for( TunerConfiguration config: configs )
{
model.addElement( (E4KTunerConfiguration)config );
}
return model;
}
/**
* Retrieves a specific (named) tuner configuration
*/
private E4KTunerConfiguration getNamedConfiguration( String name )
{
ArrayList<TunerConfiguration> configs =
mResourceManager.getSettingsManager()
.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()
{
mResourceManager.getSettingsManager().save();
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,111 @@
/*******************************************************************************
* 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 <http://www.gnu.org/licenses/>
******************************************************************************/
package source.tuner.rtl.e4k;
import gui.control.JFrequencyControl;
import java.awt.Color;
import java.awt.EventQueue;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import com.jidesoft.swing.JideTabbedPane;
import log.Log;
import net.miginfocom.swing.MigLayout;
import source.SourceComponentEditor;
import source.SourceException;
import source.tuner.FrequencyChangeListener;
import source.tuner.rtl.RTL2832InfoPanel;
import controller.ResourceManager;
public class E4KTunerEditorPanel extends JPanel implements FrequencyChangeListener
{
private static final long serialVersionUID = 1L;
private E4KTunerController mController;
private ResourceManager mResourceManager;
private JFrequencyControl mFrequencyControl;
public E4KTunerEditorPanel( E4KTunerController controller,
ResourceManager resourceManager )
{
mController = controller;
mResourceManager = resourceManager;
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( mResourceManager, 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( final int frequency, int bandwidth )
{
EventQueue.invokeLater( new Runnable()
{
@Override
public void run()
{
try
{
mController.setFrequency( frequency );
}
catch ( SourceException e )
{
Log.error( "E4KTunerController - error setting frequency [" +
frequency + "] - " + e.getLocalizedMessage() );
}
}
} );
}
}

View File

@@ -0,0 +1,123 @@
/*******************************************************************************
* 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 <http://www.gnu.org/licenses/>
******************************************************************************/
package source.tuner.rtl.r820t;
import javax.xml.bind.annotation.XmlAttribute;
import source.tuner.TunerConfiguration;
import source.tuner.TunerType;
import source.tuner.rtl.RTL2832TunerController.SampleRate;
import source.tuner.rtl.r820t.R820TTunerController.R820TEnhanceGain;
import source.tuner.rtl.r820t.R820TTunerController.R820TGain;
import source.tuner.rtl.r820t.R820TTunerController.R820TLNAGain;
import source.tuner.rtl.r820t.R820TTunerController.R820TMixerGain;
public class R820TTunerConfiguration extends TunerConfiguration
{
private R820TGain mMasterGain = R820TGain.AUTOMATIC;
private R820TMixerGain mMixerGain = R820TMixerGain.AUTOMATIC;
private R820TLNAGain mLNAGain = R820TLNAGain.AUTOMATIC;
private R820TEnhanceGain mEnhanceGain = R820TEnhanceGain.AUTOMATIC;
private double mFrequencyCorrection = -12.0d;
private SampleRate mSampleRate = SampleRate.RATE_1_200MHZ;
/**
* Default constructor for JAXB
*/
public R820TTunerConfiguration()
{
this( "Default" );
}
public R820TTunerConfiguration( String name )
{
super( name );
}
@Override
public TunerType getTunerType()
{
return TunerType.ELONICS_E4000;
}
@XmlAttribute( name = "master_gain" )
public R820TGain getMasterGain()
{
return mMasterGain;
}
public void setMasterGain( R820TGain gain )
{
mMasterGain = gain;
}
@XmlAttribute( name = "mixer_gain" )
public R820TMixerGain getMixerGain()
{
return mMixerGain;
}
public void setMixerGain( R820TMixerGain mixerGain )
{
mMixerGain = mixerGain;
}
@XmlAttribute( name = "lna_gain" )
public R820TLNAGain getLNAGain()
{
return mLNAGain;
}
public void setLNAGain( R820TLNAGain lnaGain )
{
mLNAGain = lnaGain;
}
@XmlAttribute( name = "enhance_gain" )
public R820TEnhanceGain getEnhanceGain()
{
return mEnhanceGain;
}
public void setEnhanceGain( R820TEnhanceGain enhanceGain )
{
mEnhanceGain = enhanceGain;
}
@XmlAttribute( name = "frequency_correction" )
public double getFrequencyCorrection()
{
return mFrequencyCorrection;
}
public void setFrequencyCorrection( double value )
{
mFrequencyCorrection = value;
}
@XmlAttribute( name = "sample_rate" )
public SampleRate getSampleRate()
{
return mSampleRate;
}
public void setSampleRate( SampleRate sampleRate )
{
mSampleRate = sampleRate;
}
}

View File

@@ -0,0 +1,619 @@
/*******************************************************************************
* 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 <http://www.gnu.org/licenses/>
******************************************************************************/
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 java.util.ArrayList;
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 log.Log;
import net.miginfocom.swing.MigLayout;
import source.SourceException;
import source.tuner.TunerConfiguration;
import source.tuner.TunerConfigurationAssignment;
import source.tuner.TunerType;
import source.tuner.rtl.RTL2832TunerController.SampleRate;
import source.tuner.rtl.r820t.R820TTunerController.R820TEnhanceGain;
import source.tuner.rtl.r820t.R820TTunerController.R820TGain;
import source.tuner.rtl.r820t.R820TTunerController.R820TLNAGain;
import source.tuner.rtl.r820t.R820TTunerController.R820TMixerGain;
import controller.ResourceManager;
public class R820TTunerConfigurationPanel extends JPanel
{
private static final long serialVersionUID = 1L;
private ResourceManager mResourceManager;
private R820TTunerController mController;
private R820TTunerConfiguration mSelectedConfig;
private JButton mNewConfiguration;
private JButton mDeleteConfiguration;
private JComboBox<R820TTunerConfiguration> mComboConfigurations;
private JTextField mName;
private JSpinner mFrequencyCorrection;
private JComboBox<R820TGain> mComboMasterGain;
private JComboBox<R820TMixerGain> mComboMixerGain;
private JComboBox<R820TLNAGain> mComboLNAGain;
private JComboBox<R820TEnhanceGain> mComboEnhanceGain;
private JComboBox<SampleRate> mComboSampleRate;
public R820TTunerConfigurationPanel( ResourceManager resourceManager,
R820TTunerController controller )
{
mResourceManager = resourceManager;
mController = controller;
init();
}
/**
* Initializes the gui components
*/
private void init()
{
setLayout( new MigLayout( "", "[grow,fill]", "[grow,fill]" ) );
setBorder( BorderFactory.createTitledBorder( "Tuner Configuration" ) );
/**
* Tuner configuration selector
*/
mComboConfigurations = new JComboBox<R820TTunerConfiguration>();
mComboConfigurations.setModel( getModel() );
/* Determine which tuner configuration should be selected/displayed */
TunerConfigurationAssignment savedConfig = mResourceManager
.getSettingsManager().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
mResourceManager.getSettingsManager()
.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( mComboConfigurations, "span 2,wrap" );
/**
* 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( mName );
add( new JLabel( "Name" ), "wrap" );
/**
* 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(
R820TTunerConfigurationPanel.this,
"E4K Tuner Controller - couldn't apply "
+ "frequency correction value: " + value +
e1.getLocalizedMessage() );
Log.error( "E4K Tuner Controller - couldn't apply "
+ "frequency correction value: " + value +
e1.getLocalizedMessage() );
}
}
} );
}
} );
add( mFrequencyCorrection );
add( new JLabel( "Frequency Correction (ppm)" ), "wrap" );
/**
* 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 | UsbException eSampleRate )
{
JOptionPane.showMessageDialog(
R820TTunerConfigurationPanel.this,
"E4K Tuner Controller - couldn't apply the sample "
+ "rate setting [" + sampleRate.getLabel() + "] " +
eSampleRate.getLocalizedMessage() );
Log.error( "E4K Tuner Controller - couldn't apply sample "
+ "rate setting [" + sampleRate.getLabel() + "] " +
eSampleRate.getLocalizedMessage() );
}
}
} );
add( mComboSampleRate );
add( new JLabel( "Sample Rate" ), "wrap" );
/**
* 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>( 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(
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(
R820TTunerConfigurationPanel.this,
"E4K Tuner Controller - couldn't apply the gain "
+ "setting - " + e.getLocalizedMessage() );
Log.error( "E4K Tuner Controller - couldn't apply "
+ "gain setting - " + e.getLocalizedMessage() );
}
}
} );
mComboMasterGain.setToolTipText( "<html>Select <b>AUTOMATIC</b> for auto "
+ "gain, <b>MANUAL</b> to enable<br> independent control of "
+ "<i>Mixer</i>, <i>LNA</i> and <i>Enhance</i> gain<br>"
+ "settings, or one of the individual gain settings for<br>"
+ "semi-manual gain control</html>" );
gainPanel.add( mComboMasterGain );
gainPanel.add( new JLabel( "Master" ), "wrap" );
/* Mixer Gain Control */
mComboMixerGain = new JComboBox<R820TMixerGain>( 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( mComboMixerGain.isEnabled() )
{
mController.setMixerGain( mixerGain, true );
}
mSelectedConfig.setMixerGain( mixerGain );
save();
}
catch ( UsbException e )
{
JOptionPane.showMessageDialog(
R820TTunerConfigurationPanel.this,
"E4K Tuner Controller - couldn't apply the mixer "
+ "gain setting - " + e.getLocalizedMessage() );
Log.error( "E4K Tuner Controller - couldn't apply mixer "
+ "gain setting - " + e.getLocalizedMessage() );
}
}
} );
}
} );
mComboMixerGain.setToolTipText( "<html>Mixer Gain. Set master gain "
+ "to <b>MASTER</b> to enable adjustment</html>" );
mComboMixerGain.setEnabled( false );
gainPanel.add( mComboMixerGain );
gainPanel.add( new JLabel( "Mixer" ), "wrap" );
/* LNA Gain Control */
mComboLNAGain = new JComboBox<R820TLNAGain>( R820TLNAGain.values() );
mComboLNAGain.setSelectedItem( mSelectedConfig.getLNAGain() );
mComboLNAGain.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent arg0 )
{
try
{
R820TLNAGain lnaGain = (R820TLNAGain)mComboLNAGain.getSelectedItem();
if( mComboLNAGain.isEnabled() )
{
mController.setLNAGain( lnaGain, true );
}
mSelectedConfig.setLNAGain( lnaGain );
save();
}
catch ( UsbException e )
{
JOptionPane.showMessageDialog(
R820TTunerConfigurationPanel.this,
"E4K Tuner Controller - couldn't apply the LNA "
+ "gain setting - " + e.getLocalizedMessage() );
Log.error( "E4K Tuner Controller - couldn't apply LNA "
+ "gain setting - " + e.getLocalizedMessage() );
}
}
} );
mComboLNAGain.setToolTipText( "<html>LNA Gain. Set master gain "
+ "to <b>MANUAL</b> to enable adjustment</html>" );
mComboLNAGain.setEnabled( false );
gainPanel.add( mComboLNAGain );
gainPanel.add( new JLabel( "LNA" ), "wrap" );
/* Enhance Gain Control */
mComboEnhanceGain = new JComboBox<R820TEnhanceGain>( R820TEnhanceGain.values() );
mComboEnhanceGain.setSelectedItem( mSelectedConfig.getEnhanceGain() );
mComboEnhanceGain.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent arg0 )
{
try
{
R820TEnhanceGain enhanceGain =
(R820TEnhanceGain)mComboEnhanceGain.getSelectedItem();
if( mComboEnhanceGain.isEnabled() )
{
mController.setEnhanceGain( enhanceGain, true );
}
mSelectedConfig.setEnhanceGain( enhanceGain );
save();
}
catch ( UsbException e )
{
JOptionPane.showMessageDialog(
R820TTunerConfigurationPanel.this,
"E4K Tuner Controller - couldn't apply the enhance "
+ "gain setting - " + e.getLocalizedMessage() );
Log.error( "E4K Tuner Controller - couldn't apply enhance "
+ "gain setting - " + e.getLocalizedMessage() );
}
}
} );
mComboEnhanceGain.setToolTipText( "<html>Enhance Gain. Set master gain "
+ "to <b>MANUAL</b> to enable adjustment</html>" );
mComboEnhanceGain.setEnabled( false );
gainPanel.add( mComboEnhanceGain );
gainPanel.add( new JLabel( "Enhance" ), "wrap" );
add( gainPanel, "span" );
/**
* Create a new configuration
*/
mNewConfiguration = new JButton( "New" );
mNewConfiguration.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
TunerConfiguration config =
mResourceManager.getSettingsManager()
.addNewTunerConfiguration(
TunerType.ELONICS_E4000,
"New Configuration" );
mComboConfigurations.setModel( getModel() );
mComboConfigurations.setSelectedItem( config );
repaint();
}
} );
add( mNewConfiguration );
/**
* 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(
R820TTunerConfigurationPanel.this,
"Are you sure you want to delete '"
+ selected.getName() + "'?",
"Are you sure?",
JOptionPane.YES_NO_OPTION );
if( n == JOptionPane.YES_OPTION )
{
mResourceManager.getSettingsManager()
.deleteTunerConfiguration( selected );
mComboConfigurations.setModel( getModel() );
mComboConfigurations.setSelectedIndex( 0 );
repaint();
}
}
}
} );
add( mDeleteConfiguration, "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() );
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() );
mResourceManager.getSettingsManager().setSelectedTunerConfiguration(
TunerType.ELONICS_E4000, mController.getUniqueID(), config );
}
catch ( SourceException e1 )
{
JOptionPane.showMessageDialog(
R820TTunerConfigurationPanel.this,
"E4K Tuner Controller - couldn't "
+ "apply the tuner configuration settings - " +
e1.getLocalizedMessage() );
Log.error( "E4K Tuner Controller - couldn't apply "
+ "config [" + config.getName() + "] - " +
e1.getLocalizedMessage() );
}
}
/**
* 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<R820TTunerConfiguration> getModel()
{
ArrayList<TunerConfiguration> configs =
mResourceManager.getSettingsManager()
.getTunerConfigurations( TunerType.RAFAELMICRO_R820T );
DefaultComboBoxModel<R820TTunerConfiguration> model =
new DefaultComboBoxModel<R820TTunerConfiguration>();
for( TunerConfiguration config: configs )
{
model.addElement( (R820TTunerConfiguration)config );
}
return model;
}
/**
* Retrieves a specific (named) tuner configuration
*/
private R820TTunerConfiguration getNamedConfiguration( String name )
{
ArrayList<TunerConfiguration> configs =
mResourceManager.getSettingsManager()
.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()
{
mResourceManager.getSettingsManager().save();
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,93 @@
/*******************************************************************************
* 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 <http://www.gnu.org/licenses/>
******************************************************************************/
package source.tuner.rtl.r820t;
import gui.control.JFrequencyControl;
import java.awt.EventQueue;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import log.Log;
import net.miginfocom.swing.MigLayout;
import source.SourceException;
import source.tuner.FrequencyChangeListener;
import controller.ResourceManager;
public class R820TTunerEditorPanel extends JPanel implements FrequencyChangeListener
{
private static final long serialVersionUID = 1L;
private R820TTunerController mController;
private ResourceManager mResourceManager;
private JFrequencyControl mFrequencyControl;
public R820TTunerEditorPanel( R820TTunerController controller,
ResourceManager resourceManager )
{
mController = controller;
mResourceManager = resourceManager;
initGUI();
}
private void initGUI()
{
setLayout( new MigLayout( "", "[grow,fill]", "[grow,fill]" ) );
setBorder( BorderFactory.createTitledBorder( "Rafael Micro R820T Tuner" ) );
mFrequencyControl = new JFrequencyControl();
mFrequencyControl.addListener( this );
mFrequencyControl.setFrequency( mController.getFrequency(), false );
add( mFrequencyControl, "wrap" );
add( new R820TTunerConfigurationPanel( mResourceManager, mController ),
"wrap" );
}
/**
* Frequency change listener for the frequency control gui component to
* apply end-user requested frequency changes against the tuner
*/
@Override
public void frequencyChanged( final int frequency, int bandwidth )
{
EventQueue.invokeLater( new Runnable()
{
@Override
public void run()
{
try
{
mController.setFrequency( frequency );
}
catch ( SourceException e )
{
Log.error( "E4KTunerController - error setting frequency [" +
frequency + "] - " + e.getLocalizedMessage() );
}
}
} );
}
}