From: c vw <dl1ycf@darc.de>
Date: Thu, 27 Feb 2020 17:20:48 +0000 (+0100)
Subject: HL2 and MIDI correction
X-Git-Url: https://git.rkrishnan.org/pf/frontends/%22..//%22file:/%22?a=commitdiff_plain;h=f07396bb656227fd4ceb9e50ee570c560893fe68;p=pihpsdr.git

HL2 and MIDI correction
---

diff --git a/hpsdrsim.c b/hpsdrsim.c
index f61a886..2f588d6 100644
--- a/hpsdrsim.c
+++ b/hpsdrsim.c
@@ -1059,7 +1059,7 @@ void process_ep2(uint8_t *frame)
 	     // to an RX gain of -12 to +48 dB. However, we set here that
              // a value of +16 (that is, 28 on the 0-60 scale) corresponds to
              // "zero attenuation"
-	     chk_data(40 -(frame[4] & 0x3F) , rx_att[0], "RX1 HL ATT/GAIN");
+	     chk_data(37 -(frame[4] & 0x3F) , rx_att[0], "RX1 HL ATT/GAIN");
            } else {
              chk_data((frame[4] & 0x1F) >> 0, rx_att[0], "RX1 ATT");
              chk_data((frame[4] & 0x20) >> 5, rx1_attE, "RX1 ATT enable");
diff --git a/meter.c b/meter.c
index c08f973..f77b9f5 100644
--- a/meter.c
+++ b/meter.c
@@ -200,7 +200,7 @@ if(analog_meter) {
     case SMETER:
       {
       if(have_rx_gain) {
-        level=value+40.0-(adc_attenuation[rx->adc]+12.0);
+        level=value+rx_gain_calibration-adc_attenuation[rx->adc];
       } else {
         level=value+(double)adc_attenuation[rx->adc];
       }
@@ -570,7 +570,7 @@ if(analog_meter) {
       text_location=10;
       offset=5.0;
       if(have_rx_gain) {
-        level=value+40.0-(adc_attenuation[rx->adc]+12.0);
+        level=value+rx_gain_calibration-adc_attenuation[rx->adc];
       } else {
         level=value+(double)adc_attenuation[rx->adc];
       }
diff --git a/midi3.c b/midi3.c
index d35b7c9..6c6a08d 100644
--- a/midi3.c
+++ b/midi3.c
@@ -103,17 +103,31 @@ void DoTheMidi(enum MIDIaction action, enum MIDItype type, int val) {
 		}
 		break;
 	      case MIDI_WHEEL:
-		  new=adc_attenuation[active_receiver->adc] + val;
-		  if (new > 31) new=31;
-		  if (new < 0 ) new=0;
-		  dp=malloc(sizeof(double));
-		  *dp=new;
-		  g_idle_add(ext_set_attenuation_value,(gpointer) dp);
-		  break;
+		new=adc_attenuation[active_receiver->adc] + val;
+		dp=malloc(sizeof(double));
+		*dp=(double) new;
+                if(have_rx_gain) {
+                  if(*dp<-12.0) {
+                    *dp=-12.0;
+                  } else if(*dp>48.0) {
+                    *dp=48.0;
+                  }
+                } else {
+                  if(*dp<0.0) {
+                    *dp=0.0;
+                  } else if (*dp>31.0) {
+                    *dp=31.0;
+                  }
+                }
+		g_idle_add(ext_set_attenuation_value,(gpointer) dp);
+		break;
 	      case MIDI_KNOB:
-		new=(31*val)/100;
 		dp=malloc(sizeof(double));
-		*dp=new;
+                if (have_rx_gain) {
+		  *dp=-12.0 + 0.6*(double) val;
+                } else {
+                  *dp = 0.31 * (double) val;
+                }
 		g_idle_add(ext_set_attenuation_value,(gpointer) dp);
 		break;
 	      default:
diff --git a/rx_panadapter.c b/rx_panadapter.c
index ae696f1..37e47a8 100644
--- a/rx_panadapter.c
+++ b/rx_panadapter.c
@@ -385,7 +385,7 @@ void rx_panadapter_update(RECEIVER *rx) {
   samples[0]=-200.0;
   samples[display_width-1]=-200.0;
   if(have_rx_gain) {
-    s1=(double)samples[0]+40.0-(adc_attenuation[rx->adc]+12.0);
+    s1=(double)samples[0]+rx_gain_calibration-adc_attenuation[rx->adc];
   } else {
     s1=(double)samples[0]+(double)adc_attenuation[rx->adc];
   }
@@ -406,7 +406,7 @@ void rx_panadapter_update(RECEIVER *rx) {
   cairo_move_to(cr, 0.0, s1);
   for(i=1;i<display_width;i++) {
     if(have_rx_gain) {
-      s2=(double)samples[i]+40.0-(adc_attenuation[rx->adc]+12.0);
+      s2=(double)samples[i]+rx_gain_calibration-adc_attenuation[rx->adc];
     } else {
       s2=(double)samples[i]+(double)adc_attenuation[rx->adc];
     }