Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@
# something like "source /path/to/gnuradio/setup_env.sh"

CC?=gcc
CFLAGS?=-O2 `pkg-config --cflags librtlsdr` -g
LDFLAGS?=-lglut -lGL -lrtlsdr -lfftw3 -lm `pkg-config --libs librtlsdr`
CFLAGS?=-O2 -g
LDFLAGS?=-lglut -lGL -lfftw3 -lm
RTLFLAGS=`pkg-config --cflags --libs librtlsdr`
PREFIX?=/usr/local
PROGRAM=rtl_waterfall

all:
$(CC) $(CFLAGS) -o rtl_waterfall rtl_waterfall.c $(LDFLAGS)
$(CC) $(CFLAGS) -o $(PROGRAM) $(PROGRAM).c $(LDFLAGS) $(RTLFLAGS)

install:
mkdir -p $(PREFIX)/bin
cp $(PROGRAM) $(PREFIX)/bin

clean:
rm -f rtl_waterfall
rm -f $(PROGRAM) *.o
26 changes: 19 additions & 7 deletions rtl_waterfall.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ int gain_manual_increase() {
for (int i = 0; i < gainsteps; i++)
if (gains[i] > g) {
rtlsdr_set_tuner_gain(dev, gains[i]);
printf("set gain to %.1f\n", gains[i]/10.0);
return 0;
}
return -1;
Expand All @@ -393,6 +394,7 @@ int gain_manual_decrease() {
gain_manual_enable();
for (int i = gainsteps-1; i ; i--)
if (gains[i] < g) {
printf("set gain to %.1f\n", gains[i]/10.0);
rtlsdr_set_tuner_gain(dev, gains[i]);
return 0;
}
Expand All @@ -402,15 +404,15 @@ int gain_manual_decrease() {

int main(int argc, char **argv)
{
int c;
int c, listgain = 0;
uint32_t dev_index = 0;
int gain = 0, ppm = 0;
frequency = 100e6; /* global */

// setup window
glut_init(&argc, argv);

while ((c = getopt(argc, argv, "d:f:g:p:r:")) != -1) {
while ((c = getopt(argc, argv, "d:f:g:lp:r:")) != -1) {
switch (c) {
case 'd':
dev_index = atoi(optarg);
Expand All @@ -421,6 +423,9 @@ int main(int argc, char **argv)
case 'g':
gain = (int) (atof(optarg) * 10); // nice clean fractional decibels
break;
case 'l':
listgain = 1;
break;
case 'p':
ppm = (int) lround(atof(optarg)); // accept fractional ppm correction
break;
Expand Down Expand Up @@ -457,6 +462,18 @@ int main(int argc, char **argv)
exit(1);
}

/* Set the gain */
gain_manual_enable(); // set manual mode first so gain levels can be queried
gain_get_levels();
gain_auto_enable(); // switch back to auto gain mode
if (listgain) {
printf("Supported gain levels: ");
for (int i = 0; i < gainsteps; i++)
printf("%.1f ", gains[i]/10.0);
printf("\n");
return 0;
}

/* Set the sample rate */
if (rtlsdr_set_sample_rate(dev, samp_rate) < 0)
fprintf(stderr, "WARNING: Failed to set sample rate.\n");
Expand All @@ -478,11 +495,6 @@ int main(int argc, char **argv)
if (rtlsdr_set_freq_correction(dev, ppm) < 0)
fprintf(stderr, "WARNING: Failed to set frequency correction\n");

/* Set the gain */
gain_manual_enable(); // set manual mode first so gain levels can be queried
gain_get_levels();
gain_auto_enable(); // switch back to auto gain mode

if (gain) {
if (gain_is_valid(gain)) {
if (rtlsdr_set_tuner_gain(dev, gain) < 0)
Expand Down