From f01ea221d6af37df986bb7b7ef3bb24ac38a7e16 Mon Sep 17 00:00:00 2001
From: c vw <dl1ycf@darc.de>
Date: Sat, 9 Jun 2018 17:49:48 +0200
Subject: [PATCH] Fixes for STEMlab/HAMlab, plus removal of tons of debug
 output from rigctl.

---
 meter.c   | 10 ++++++++++
 rigctl.c  |  4 ++--
 rx_menu.c |  8 +++++---
 sliders.c |  4 ++++
 4 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/meter.c b/meter.c
index 358c851..4f90e91 100644
--- a/meter.c
+++ b/meter.c
@@ -232,6 +232,11 @@ if(analog_meter) {
     case SMETER:
       {
       double level=value+(double)adc_attenuation[rx->adc];
+      if (filter_board == CHARLY25) {
+	// preamp/dither encodes the preamp level
+        if (rx->preamp) level -= 18.0;
+        if (rx->dither) level -= 18.0;
+      }
       offset=210.0;
 
       int i;
@@ -529,6 +534,11 @@ if(analog_meter) {
       text_location=10;
       offset=5.0;
       double level=value+(double)adc_attenuation[rx->adc];
+      if (filter_board == CHARLY25) {
+	// preamp/dither encodes the preamp level
+        if (rx->preamp) level -= 18.0;
+        if (rx->dither) level -= 18.0;
+      }
       if(meter_width>=114) {
         //int db=meter_width/114; // S9+60 (9*6)+60
         //if(db>2) db=2;
diff --git a/rigctl.c b/rigctl.c
index c121392..06a841b 100644
--- a/rigctl.c
+++ b/rigctl.c
@@ -58,8 +58,8 @@
 #include <sys/socket.h>
 #include <arpa/inet.h> //inet_addr
 
-//#undef RIGCTL_DEBUG
-#define RIGCTL_DEBUG
+#undef RIGCTL_DEBUG
+//#define RIGCTL_DEBUG
 
 int rigctl_port_base=19090;
 int rigctl_enable=0;
diff --git a/rx_menu.c b/rx_menu.c
index 3e83bb1..70f0565 100644
--- a/rx_menu.c
+++ b/rx_menu.c
@@ -119,9 +119,8 @@ static void mute_radio_cb(GtkWidget *widget, gpointer data) {
 // call audo_close_output with old device, audio_open_output with new one
 //
 static void local_output_changed_cb(GtkWidget *widget, gpointer data) {
-//active_receiver->audio_device=(int)(long)data;
   int newdev = (int)(long)data;
-fprintf(stderr,"local_output_changed rx=%d from %d to %d\n",active_receiver->id,active_receiver->audio_device,newdev);
+  fprintf(stderr,"local_output_changed rx=%d from %d to %d\n",active_receiver->id,active_receiver->audio_device,newdev);
   if(active_receiver->local_audio) {
     audio_close_output(active_receiver);                     // audio_close with OLD device
     active_receiver->audio_device=newdev;                    // update rx to NEW device
@@ -130,7 +129,10 @@ fprintf(stderr,"local_output_changed rx=%d from %d to %d\n",active_receiver->id,
     } else {
       active_receiver->local_audio=0;
     }
-fprintf(stderr,"local_output_changed rx=%d local_audio=%d\n",active_receiver->id,active_receiver->local_audio);
+    fprintf(stderr,"local_output_changed rx=%d local_audio=%d\n",active_receiver->id,active_receiver->local_audio);
+  } else {
+    // If not (currently) using local audio, just change dev num
+    active_receiver->audio_device=newdev;
   }
 }
 
diff --git a/sliders.c b/sliders.c
index acf78d7..1f127db 100644
--- a/sliders.c
+++ b/sliders.c
@@ -217,11 +217,15 @@ static gboolean load_att_type_cb(gpointer data) {
 
 static void c25_att_combobox_changed(GtkWidget *widget, gpointer data) {
   int id = atoi(gtk_combo_box_get_active_id(GTK_COMBO_BOX(widget)));
+  //DL1YCF: store attenuation, such that in meter.c the correct level is displayed
+  adc_attenuation[active_receiver->adc] = 12.0*id;
   set_alex_attenuation(id);
 }
 
 static void c25_preamp_combobox_changed(GtkWidget *widget, gpointer data) {
   int id = atoi(gtk_combo_box_get_active_id(GTK_COMBO_BOX(widget)));
+  //DL1YCF comment: dither and preamp are "misused" to store the PreAmp value.
+  //                this has to be exploited in meter.c
   active_receiver->dither = id >= 2;
   active_receiver->preamp = id >= 1;
 }
-- 
2.45.2