]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
Fixed typro saving PTT GPIO settings.
authorJohn Melton G0ORX <john.d.melton@googlemail.com>
Tue, 17 Mar 2020 08:53:48 +0000 (08:53 +0000)
committerJohn Melton G0ORX <john.d.melton@googlemail.com>
Tue, 17 Mar 2020 08:53:48 +0000 (08:53 +0000)
Added ANF and SNB enable/disable to midi.
Added preliminary code to better support PlutoSDR.
Fixed zoom/pan dialogs when zoom pan sliders not being displayed.
Fixed SoapySDR Hardware AGC checkbox position on Radio menu.
Added separate mutex for receiver display.

15 files changed:
ext.c
ext.h
gpio.c
gpio.h
midi.h
midi2.c
midi3.c
radio_menu.c
receiver.c
receiver.h
rx_panadapter.c
sliders.c
soapy_discovery.c
soapy_protocol.c
zoompan.c

diff --git a/ext.c b/ext.c
index 619271c1974a609d2fa2d7187beccd58b145af39..d4f677cb86e1644d5082ba9e083d97e6953e8185 100644 (file)
--- a/ext.c
+++ b/ext.c
@@ -140,7 +140,6 @@ int ext_noise_update(void *data) {
 }
 
 int ext_mox_update(void *data) {
-g_print("ext_mox_update: %d\n",GPOINTER_TO_INT(data));
   mox_update(GPOINTER_TO_INT(data));
   return 0;
 }
@@ -627,10 +626,10 @@ int ext_set_rf_gain(void *data) {
   int pos=GPOINTER_TO_INT(data);
   double value;
   value=(double)pos;
-  if(value<0.0) {
-    value=0.0;
-  } else if(value>100.0) {
-    value=100.0;
+  if(value<-12.0) {
+    value=-12.0;
+  } else if(value>48.0) {
+    value=48.0;
   }
   set_rf_gain(active_receiver->id,value);
   return 0;
@@ -692,6 +691,19 @@ int ext_remote_command(void *data) {
   return 0;
 }
 
+int ext_anf_update(void *data) {
+  if(active_receiver->anf==0) {
+    active_receiver->anf=1;
+    mode_settings[vfo[active_receiver->id].mode].anf=1;
+  } else {
+    active_receiver->snb=0;
+    mode_settings[vfo[active_receiver->id].mode].anf=0;
+  }
+  SetRXAANFRun(active_receiver->id, active_receiver->anf);
+  g_idle_add(ext_vfo_update, NULL);
+  return 0;
+}
+
 int ext_mute_update(void *data) {
   active_receiver->mute_radio=!active_receiver->mute_radio;
   return 0;
diff --git a/ext.h b/ext.h
index 906a09931af8319de8517c6fbe124aceb70d149d..5af161784b62bb4a27ca582a01de142962a1d693 100644 (file)
--- a/ext.h
+++ b/ext.h
@@ -77,6 +77,7 @@ extern int ext_two_tone(void *data);
 extern int ext_nr_update(void *data);
 extern int ext_nb_update(void *data);
 extern int ext_snb_update(void *data);
+extern int ext_anf_update(void *data);
 extern int ext_band_plus(void *data);
 extern int ext_band_minus(void *data);
 extern int ext_bandstack_plus(void *data);
diff --git a/gpio.c b/gpio.c
index efd9e6442aefe1cd0b8565763b5afb69aafe610c..653a78f0728280c8692f4b48a999eb97d9cfc34a 100644 (file)
--- a/gpio.c
+++ b/gpio.c
@@ -245,6 +245,7 @@ char *sw_string[SWITCH_ACTIONS] = {
   "A TO B",
   "A SWAP B",
   "AGC",
+  "ANF",
   "B TO A",
   "BAND -",
   "BAND +",
@@ -1489,11 +1490,11 @@ void gpio_save_state() {
 
 #ifdef PTT
   sprintf(value,"%d",ENABLE_PTT_GPIO);         
-  setProperty("ENABLE_PPT_GPIO",value);                
+  setProperty("ENABLE_PTT_GPIO",value);                
   sprintf(value,"%d",PTT_GPIO);                
-  setProperty("PPT_GPIO",value);               
+  setProperty("PTT_GPIO",value);               
   sprintf(value,"%d",PTT_ACTIVE_LOW);          
-  setProperty("PPT_ACTIVE_LOW",value);         
+  setProperty("PTT_ACTIVE_LOW",value);         
 #endif
   saveProperties("gpio.props");
 
diff --git a/gpio.h b/gpio.h
index ad204b8883e7f0572b26ecfe4b0dc262949778b7..b15d8a0e15ad46ef0753de4b4f63c76665d9253e 100644 (file)
--- a/gpio.h
+++ b/gpio.h
@@ -83,6 +83,7 @@ enum {
   A_TO_B,
   A_SWAP_B,
   AGC,
+  ANF,
   B_TO_A,
   BAND_MINUS,
   BAND_PLUS,
diff --git a/midi.h b/midi.h
index fbfa310f53a2953cf38b0649b6144eb33fc8b498..55ed5335aec5ab31cd70c62698806c7f91373929 100644 (file)
--- a/midi.h
+++ b/midi.h
@@ -52,6 +52,7 @@ enum MIDIaction {
   MIDI_AF_GAIN,                // AFGAIN:              AF gain
   AGCATTACK,           // AGCATTACK:           AGC ATTACK (cycle fast/med/slow etc.)
   MIDI_AGC,            // AGCVAL:              AGC level
+  ANF,                 // ANF:                 toggel ANF on/off
   ATT,                 // ATT:                 Step attenuator or Programmable attenuator
   VFO_B2A,             // B2A:                 VFO B -> A
   BAND_DOWN,           // BANDDOWN:            cycle through bands downwards
@@ -92,6 +93,7 @@ enum MIDIaction {
   RIT_TOGGLE,                  // RITTOGGLE:           toggle RIT on/off
   RIT_VAL,             // RITVAL:              change RIT value
   MIDI_SAT,            // SAT:                 cycle through SAT modes off/SAT/RSAT
+  SNB,                 // SNB:                 toggle SNB on/off
   MIDI_SPLIT,          // SPLIT:               Split on/off
   SWAP_RX,             // SWAPRX:              swap active receiver (if there are two receivers)
   SWAP_VFO,            // SWAPVFO:             swap VFO A/B frequency
diff --git a/midi2.c b/midi2.c
index 94b23e9a5ef478984221e9cd4960b72a74655da0..78cfaff985c8407e17566c0f82ee86659c0e111a 100644 (file)
--- a/midi2.c
+++ b/midi2.c
@@ -105,6 +105,7 @@ static struct {
         { MIDI_AF_GAIN,        "AFGAIN"},
        { AGCATTACK,            "AGCATTACK"},
         { MIDI_AGC,            "AGCVAL"},
+        { ANF,                 "ANF"},
         { ATT,                 "ATT"},
        { VFO_B2A,              "B2A"},
         { BAND_DOWN,           "BANDDOWN"},
@@ -145,6 +146,7 @@ static struct {
         { RIT_TOGGLE,          "RITTOGGLE"},
         { RIT_VAL,             "RITVAL"},
         { MIDI_SAT,            "SAT"},
+        { SNB,                         "SNB"},
        { MIDI_SPLIT,           "SPLIT"},
        { SWAP_RX,              "SWAPRX"},
        { SWAP_VFO,             "SWAPVFO"},
diff --git a/midi3.c b/midi3.c
index 6f3415d079640899c74203f965df49530e63718e..d4f1aa94e7d661217a54f8487203fec34db50d05 100644 (file)
--- a/midi3.c
+++ b/midi3.c
@@ -91,6 +91,12 @@ void DoTheMidi(enum MIDIaction action, enum MIDItype type, int val) {
            *dp=dnew;
            g_idle_add(ext_set_agc_gain, (gpointer) dp);
            break;
+       /////////////////////////////////////////////////////////// "ANF"
+       case ANF:       // only key supported
+           if (type == MIDI_KEY) {
+             g_idle_add(ext_anf_update, NULL);
+           }
+           break;
        /////////////////////////////////////////////////////////// "ATT"
        case ATT:       // Key for ALEX attenuator, wheel or knob for slider
            switch(type) {
@@ -590,7 +596,7 @@ void DoTheMidi(enum MIDIaction action, enum MIDItype type, int val) {
             } else  if (type == MIDI_WHEEL) {
                 new=(int)active_receiver->rf_gain+val;
             }
-            g_idle_add(ext_set_rf_gain, GINT_TO_POINTER((int)val));
+            g_idle_add(ext_set_rf_gain, GINT_TO_POINTER((int)new));
            break;
        /////////////////////////////////////////////////////////// "RFPOWER"
        case TX_DRIVE: // knob or wheel supported
@@ -693,6 +699,12 @@ void DoTheMidi(enum MIDIaction action, enum MIDItype type, int val) {
            }
            g_idle_add(ext_vfo_update, NULL);
             break;
+       /////////////////////////////////////////////////////////// "SNB"
+       case SNB:       // only key supported
+           if (type == MIDI_KEY) {
+             g_idle_add(ext_snb_update, NULL);
+           }
+           break;
        /////////////////////////////////////////////////////////// "SPLIT"
        case MIDI_SPLIT: // only key supported
            // toggle split mode
index daab5d41af5aa44b4fb75edfbfe8d35212ff58db..3b20c2a24bd728653ceb6a47300eb7ef5bbcc1fb 100644 (file)
@@ -785,6 +785,7 @@ void radio_menu(GtkWidget *parent) {
     row++;
     temp_row=row;
 
+    col=0;
     if(radio->info.soapy.rx_has_automatic_gain) {
       GtkWidget *agc=gtk_check_button_new_with_label("Hardware AGC: ");
       gtk_grid_attach(GTK_GRID(grid),agc,col,row,1,1);
index 88ee5b1f70a5b217c3eb82cb825904c03cb6d6c7..583cc325dcc05c307edef9d32fbe0e5e55834229 100644 (file)
@@ -565,6 +565,7 @@ static gint update_display(gpointer data) {
 
   if(rx->displaying) {
     if(rx->pixels>0) {
+      g_mutex_lock(&rx->display_mutex);
       GetPixels(rx->id,0,rx->pixel_samples,&rc);
       if(rc) {
         if(rx->display_panadapter) {
@@ -573,8 +574,8 @@ static gint update_display(gpointer data) {
         if(rx->display_waterfall) {
           waterfall_update(rx);
         }
-    }
-  
+      }
+      g_mutex_unlock(&rx->display_mutex);
       if(active_receiver==rx) {
         double m=GetRXAMeter(rx->id,smeter)+meter_calibration;
         meter_update(rx,SMETER,m,0.0,0.0,0.0);
@@ -787,6 +788,10 @@ fprintf(stderr,"create_pure_signal_receiver: id=%d buffer_size=%d\n",id,buffer_s
       rx->pixels = 8*width;
     }
   }
+
+  // need mutex for zoom/pan
+  g_mutex_init(&rx->display_mutex);
+
   // allocate buffers
   rx->iq_input_buffer=g_new(double,2*rx->buffer_size);
   //rx->audio_buffer=NULL;
@@ -872,6 +877,8 @@ fprintf(stderr,"create_receiver: id=%d buffer_size=%d fft_size=%d pixels=%d fps=
   RECEIVER *rx=malloc(sizeof(RECEIVER));
   rx->id=id;
   g_mutex_init(&rx->mutex);
+  g_mutex_init(&rx->display_mutex);
+fprintf(stderr,"create_receiver: g_mutex_init: %p\n",&rx->mutex);
   switch(id) {
     case 0:
       rx->adc=0;
@@ -1109,6 +1116,7 @@ void receiver_change_sample_rate(RECEIVER *rx,int sample_rate) {
 //
 
   g_mutex_lock(&rx->mutex);
+fprintf(stderr,"receiver_change_sample_rate: g_mutex_lock: %p\n",&rx->mutex);
 
   rx->sample_rate=sample_rate;
   int scale=rx->sample_rate/48000;
@@ -1130,6 +1138,7 @@ g_print("receiver_change_sample_rate: id=%d rate=%d scale=%d buffer_size=%d outp
     init_analyzer(rx);
     fprintf(stderr,"PS FEEDBACK change sample rate:id=%d rate=%d buffer_size=%d output_samples=%d\n",
                    rx->id, rx->sample_rate, rx->buffer_size, rx->output_samples);
+fprintf(stderr,"receiver_change_sample_rate: g_mutex_unlock: %p\n",&rx->mutex);
     g_mutex_unlock(&rx->mutex);
     return;
   }
@@ -1153,6 +1162,7 @@ g_print("receiver_change_sample_rate: id=%d rate=%d scale=%d buffer_size=%d outp
 
   SetChannelState(rx->id,1,0);
 
+fprintf(stderr,"receiver_change_sample_rate: g_mutex_unlock: %p\n",&rx->mutex);
   g_mutex_unlock(&rx->mutex);
 
 fprintf(stderr,"receiver_change_sample_rate: id=%d rate=%d buffer_size=%d output_samples=%d\n",rx->id, rx->sample_rate, rx->buffer_size, rx->output_samples);
@@ -1326,8 +1336,6 @@ static void process_rx_buffer(RECEIVER *rx) {
 void full_rx_buffer(RECEIVER *rx) {
   int error;
 
-  g_mutex_lock(&rx->mutex);
-
   // noise blanker works on original IQ samples
   if(rx->nb) {
      xanbEXT (rx->id, rx->iq_input_buffer, rx->iq_input_buffer);
@@ -1348,7 +1356,6 @@ void full_rx_buffer(RECEIVER *rx) {
 
 //g_print("full_rx_buffer: rx=%d buffer_size=%d samples=%d\n",rx->id,rx->buffer_size,rx->samples);
   process_rx_buffer(rx);
-  g_mutex_unlock(&rx->mutex);
 }
 
 static int rx_buffer_seen=0;
@@ -1378,7 +1385,7 @@ void add_div_iq_samples(RECEIVER *rx, double i0, double q0, double i1, double q1
 }
 
 void receiver_change_zoom(RECEIVER *rx,double zoom) {
-  g_mutex_lock(&rx->mutex);
+  g_mutex_lock(&rx->display_mutex);
   if(rx->pixel_samples!=NULL) {
     g_free(rx->pixel_samples);
   }
@@ -1399,12 +1406,12 @@ void receiver_change_zoom(RECEIVER *rx,double zoom) {
   }
   rx->zoom=(int)zoom;
   init_analyzer(rx);
-  g_mutex_unlock(&rx->mutex);
+  g_mutex_unlock(&rx->display_mutex);
 }
 
 void receiver_change_pan(RECEIVER *rx,double pan) {
-  g_mutex_lock(&rx->mutex);
+  g_mutex_lock(&rx->display_mutex);
   rx->pan=(int)pan;
-  g_mutex_unlock(&rx->mutex);
+  g_mutex_unlock(&rx->display_mutex);
 }
 
index a0b5be9937e46d0907441c866f19e812fafade6c..2913815883cf0ed7c06d7070e2d3de50aebadcb5 100644 (file)
@@ -37,6 +37,7 @@ typedef enum _audio_t audio_t;
 typedef struct _receiver {
   gint id;
   GMutex mutex;
+  GMutex display_mutex;
 
   gint ddc;
   gint adc;
index 0b18a05999cfc0a0e0c91b36bbc114be4621487f..682ac7789c36a8fb10e1557e1c00a879a45b7264 100644 (file)
@@ -334,7 +334,7 @@ void rx_panadapter_update(RECEIVER *rx) {
           break;
       }
       break;
-    case 1048576:
+    case 1024000:
     case 1536000:
     case 2097152:
       divisor=200000L;
index a8308b2333a6dd647190ea7ef6cf7d1165fa2fa4..19bd28e8fd3ce760ab5dab12d1dddd740ba15a2a 100644 (file)
--- a/sliders.c
+++ b/sliders.c
@@ -386,7 +386,7 @@ void set_rf_gain(int rx,double value) {
   }
 #endif
   if(display_sliders) {
-    gtk_range_set_value (GTK_RANGE(rf_gain_scale),receiver[rx]->rf_gain);
+    gtk_range_set_value (GTK_RANGE(attenuation_scale),receiver[rx]->rf_gain);
   } else {
     if(scale_status!=RF_GAIN || scale_rx!=rx) {
       if(scale_status!=NO_FUNCTION) {
index 630d34d9887284c14e04979e6ea4ccd5d9a8c21d..a9cfcf1a20de4217696e6b5b4929ee303e9d2038 100644 (file)
@@ -120,10 +120,10 @@ static void get_info(char *driver) {
 
   if(strcmp(driver,"lime")==0) {
     sample_rate=768000;
+  } else if(strcmp(driver,"plutosdr")==0) {
+    sample_rate=768000;
   } else if(strcmp(driver,"rtlsdr")==0) {
     sample_rate=1024000;
-  } else if(strcmp(driver,"plutosdr")==0) {
-    sample_rate=2048000;
   } else {
     sample_rate=1024000;
   }
index 95fca283f3288f508734b044171b81351b8bf19e..f266132a21d9c60950f24c89faa4be01cb917977 100644 (file)
@@ -89,6 +89,7 @@ g_print("soapy_protocol_set_mic_sample_rate: rate=%d mic_sample_divisor=%d\n",ra
 }
 
 void soapy_protocol_change_sample_rate(RECEIVER *rx) {
+// rx->mutex already locked
 g_print("soapy_protocol_change_sample_rate: %d\n",rx->sample_rate);
   if(rx->sample_rate==radio_sample_rate) {
     if(rx->resample_buffer!=NULL) {
@@ -311,7 +312,8 @@ fprintf(stderr,"soapy_protocol: receive_thread\n");
   while(running) {
     elements=SoapySDRDevice_readStream(soapy_device,rx_stream,buffs,max_samples,&flags,&timeNs,timeoutUs);
     if(elements<0) {
-      fprintf(stderr,"soapy_protocol_receive_thread: SoapySDRDevice_readStream failed: %s max_samples=%d\n",SoapySDR_errToStr(elements),max_samples);
+      fprintf(stderr,"soapy_protocol_receive_thread: SoapySDRDevice_readStream failed: %s max_samples=%d read=%d\n",SoapySDR_errToStr(elements),max_samples,elements);
+      continue;
     }
     for(i=0;i<elements;i++) {
       rx->buffer[i*2]=(double)buffer[i*2];
@@ -446,7 +448,7 @@ void soapy_protocol_set_tx_frequency(TRANSMITTER *tx) {
 void soapy_protocol_set_rx_antenna(RECEIVER *rx,int ant) {
   int rc;
   if(soapy_device!=NULL) {
-//    fprintf(stderr,"soapy_protocol: set_rx_antenna: %s\n",radio->info.soapy.rx_antenna[ant]);
+    g_print("soapy_protocol: set_rx_antenna: %s\n",radio->info.soapy.rx_antenna[ant]);
     rc=SoapySDRDevice_setAntenna(soapy_device,SOAPY_SDR_RX,rx->adc,radio->info.soapy.rx_antenna[ant]);
     if(rc!=0) {
       fprintf(stderr,"soapy_protocol: SoapySDRDevice_setAntenna RX failed: %s\n",SoapySDR_errToStr(rc));
@@ -457,7 +459,7 @@ void soapy_protocol_set_rx_antenna(RECEIVER *rx,int ant) {
 void soapy_protocol_set_tx_antenna(TRANSMITTER *tx,int ant) {
   int rc;
   if(soapy_device!=NULL) {
-//    fprintf(stderr,"soapy_protocol: set_tx_antenna: %s\n",radio->info.soapy.tx_antenna[ant]);
+    g_print("soapy_protocol: set_tx_antenna: %s\n",radio->info.soapy.tx_antenna[ant]);
     rc=SoapySDRDevice_setAntenna(soapy_device,SOAPY_SDR_TX,tx->dac,radio->info.soapy.tx_antenna[ant]);
     if(rc!=0) {
       fprintf(stderr,"soapy_protocol: SoapySDRDevice_setAntenna TX failed: %s\n",SoapySDR_errToStr(rc));
index 2aee381eb240ca27ec73d064609234a2869974c3..13173bf47c5acbb636325cc464805f0739f65015 100644 (file)
--- a/zoompan.c
+++ b/zoompan.c
@@ -57,7 +57,7 @@ static GdkRGBA gray;
 int zoompan_active_receiver_changed(void *data) {
   if(display_zoompan) {
     gtk_range_set_value(GTK_RANGE(zoom_scale),active_receiver->zoom);
-    gtk_range_set_range(GTK_RANGE(pan_scale),0.0,(double)(active_receiver->pixels-active_receiver->width));
+    gtk_range_set_range(GTK_RANGE(pan_scale),0.0,(double)(active_receiver->zoom==1?active_receiver->pixels:active_receiver->pixels-active_receiver->width));
     gtk_range_set_value (GTK_RANGE(pan_scale),active_receiver->pan);
     if(active_receiver->zoom == 1) {
       gtk_widget_set_sensitive(pan_scale, FALSE);
@@ -68,7 +68,7 @@ int zoompan_active_receiver_changed(void *data) {
 
 static void zoom_value_changed_cb(GtkWidget *widget, gpointer data) {
   receiver_change_zoom(active_receiver,gtk_range_get_value(GTK_RANGE(zoom_scale)));
-  gtk_range_set_range(GTK_RANGE(pan_scale),0.0,(double)(active_receiver->pixels-active_receiver->width));
+  gtk_range_set_range(GTK_RANGE(pan_scale),0.0,(double)(active_receiver->zoom==1?active_receiver->pixels:active_receiver->pixels-active_receiver->width));
   gtk_range_set_value (GTK_RANGE(pan_scale),active_receiver->pan);
   if(active_receiver->zoom == 1) {
     gtk_widget_set_sensitive(pan_scale, FALSE);
@@ -125,6 +125,7 @@ static void pan_value_changed_cb(GtkWidget *widget, gpointer data) {
 }
 
 void set_pan(int rx,double value) {
+g_print("set_pan: %f\n",value);
   receiver[rx]->pan=(int)value;
   if(display_zoompan) {
     gtk_range_set_value (GTK_RANGE(pan_scale),receiver[rx]->pan);
@@ -143,7 +144,7 @@ void set_pan(int rx,double value) {
       sprintf(title,"Pan RX %d",rx);
       scale_dialog=gtk_dialog_new_with_buttons(title,GTK_WINDOW(top_window),GTK_DIALOG_DESTROY_WITH_PARENT,NULL,NULL);
       GtkWidget *content=gtk_dialog_get_content_area(GTK_DIALOG(scale_dialog));
-      pan_scale=gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL,0.0, active_receiver->zoom==1?active_receiver->pixels:active_receiver->pixels-active_receiver->width, 1.00);
+      pan_scale=gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL,0.0, receiver[rx]->zoom==1?receiver[rx]->pixels:receiver[rx]->pixels-receiver[rx]->width, 1.00);
       gtk_widget_set_size_request (pan_scale, 400, 30);
       gtk_range_set_value (GTK_RANGE(pan_scale),receiver[rx]->pan);
       gtk_widget_show(pan_scale);
@@ -159,10 +160,12 @@ void set_pan(int rx,double value) {
 }
 
 void update_pan(double pan) {
-  int p=active_receiver->pan+(int)pan;
-  if(p<0) p=0;
-  if(p>(active_receiver->pixels-active_receiver->width)) p=active_receiver->pixels-active_receiver->width;
-  set_pan(active_receiver->id,p);
+  if(active_receiver->zoom>1) {
+    int p=active_receiver->pan+(int)pan;
+    if(p<0) p=0;
+    if(p>(active_receiver->pixels-active_receiver->width)) p=active_receiver->pixels-active_receiver->width;
+    set_pan(active_receiver->id,(double)p);
+  }
 }
 
 GtkWidget *zoompan_init(int my_width, int my_height) {