From 52a36123cef41eee8031e3ff7b98729b373fe5b7 Mon Sep 17 00:00:00 2001
From: c vw <dl1ycf@darc.de>
Date: Wed, 22 Jul 2020 10:07:35 +0200
Subject: [PATCH] Improvements for PURESIGNAL on HERMESLITE2.

---
 old_protocol.c | 11 +++++++++--
 transmitter.c  | 21 ++++++++++++---------
 2 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/old_protocol.c b/old_protocol.c
index 14dabfc..94f9436 100644
--- a/old_protocol.c
+++ b/old_protocol.c
@@ -1463,7 +1463,12 @@ static int last_power=0;
           if (rxgain > 60) rxgain=60;
 	  // encode all 6 bits of RXgain in ATT value and set bit6
           if (isTransmitting()) {
-	    output_buffer[C4] = 0x40 | (31 - (transmitter->attenuation & 0x1F));
+	    //
+	    // Set the preamp to (19-TXatt) dB (+19 ... –12 dB)
+	    // temporary change: use +31 ... 0 dB to allow PURESIGNAL on
+            // a barefoot HL2 with "cross talk" feedback from the TRX relay
+            //
+	    output_buffer[C4] = 0x40 | (43 - (transmitter->attenuation & 0x1F));
           } else { 
 	    output_buffer[C4] = 0x40 | (rxgain & 0x3F);
           }
@@ -1520,7 +1525,9 @@ static int last_power=0;
 	    }
 	}
         output_buffer[C3]=0x00;
-        output_buffer[C3]|=transmitter->attenuation;			// Step attenuator of first ADC, value used when TXing
+ 	// this is a no-op on the HermesLite2 which needs b7 set to make this effective
+	// no need to bother here since we do this manually (see above)
+        output_buffer[C3]|=transmitter->attenuation & 0x1F;  // Step attenuator of first ADC, value used when TXing
         output_buffer[C4]=0x00;
         break;
       case 7:
diff --git a/transmitter.c b/transmitter.c
index 25abad7..20936d9 100644
--- a/transmitter.c
+++ b/transmitter.c
@@ -427,6 +427,7 @@ static gboolean update_display(gpointer data) {
       int start = (full-width) /2;      // Copy from start ... (end-1) 
       float *tfp=tx->pixel_samples;
       float *rfp=rx_feedback->pixel_samples+start;
+      float offset;
       int i;
       //
       // The TX panadapter shows a RELATIVE signal strength. A CW or single-tone signal at
@@ -436,23 +437,25 @@ static gboolean update_display(gpointer data) {
       // on the attenuation effective in the feedback path.
       // We try to normalize the feeback signal such that is looks like a "normal" TX
       // panadapter if the feedback is optimal for PURESIGNAL (that is, if the attenuation
-      // is optimal). The correction depends on the protocol (different peak levels in the TX
-      // feedback channel, old=0.407, new=0.2899, difference is 3 dB).
+      // is optimal). The correction (offset) depends on the protocol (different peak levels in the TX
+      // feedback channel.
       switch (protocol) {
         case ORIGINAL_PROTOCOL:
-          for (i=0; i<width; i++) {
-            *tfp++ =*rfp++ + 12.0;
-          }
+	  // TX dac feedback peak = 0.406, on HermesLite2 0.230
+          offset = (device == DEVICE_HERMES_LITE2) ? 17.0 : 12.0;
           break;
         case NEW_PROTOCOL:
-          for (i=0; i<width; i++) {
-            *tfp++ =*rfp++ + 15.0;
-          }
+          // TX dac feedback peak = 0.2899
+	  offset = 15.0;
           break;
         default:
-          memcpy(tfp, rfp, width*sizeof(float));
+          // we probably never come here
+          offset = 0.0;
           break;
       }
+      for (i=0; i<width; i++) {
+        *tfp++ =*rfp++ + offset;
+      }
       g_mutex_unlock(&rx_feedback->mutex);
     } else {
 #endif
-- 
2.45.2