From 7c07e792cc2cdcf42a11f048d07d4c446d15abac Mon Sep 17 00:00:00 2001
From: c vw <dl1ycf@darc.de>
Date: Thu, 27 Feb 2020 17:46:26 +0100
Subject: [PATCH] - corrected TX panadapter frequency markers and band edges -
 corrected analog RF output watt meter - OC menu TX labels corrected - put all
 ALC stuff in one column in the meter menu - corrected HERMESlite rxgain
 setting in P1

---
 hpsdrsim.c      | 15 ++++-----------
 meter.c         |  2 +-
 meter_menu.c    |  1 +
 oc_menu.c       |  3 ++-
 old_protocol.c  |  8 +++-----
 tx_panadapter.c |  4 ++--
 6 files changed, 13 insertions(+), 20 deletions(-)

diff --git a/hpsdrsim.c b/hpsdrsim.c
index c8dc5d1..f61a886 100644
--- a/hpsdrsim.c
+++ b/hpsdrsim.c
@@ -1056,17 +1056,10 @@ void process_ep2(uint8_t *frame)
 	     // Some firmware/emulators use bit6 to indicate a 6-bit format
 	     // for a combined attenuator/preamplifier with the AD9866 chip.
 	     // The value is between 0 and 60 and formally correspondes to
-	     // to an RX gain of -12 to +48 dB. However the front-end hardware
-	     // determines which is the correct "zero level", that is, the gain
-	     // which corresponds to full-amplitude IQ samples for a 0 dBm input.
-	     // Experimentally, we set this "zero level" to +13 dB that (that is,
-	     // a RxGain value of 25). So the "attenuation" is (25 -G) where G
-	     // is the RXgain value.
-	     // NOTE: according to the AD9866 data sheet, this "calibration value"
-	     //       should be 22 instead of 25, while a value of 31 is used
-	     //       by the HermesLite firmware  when bit6 is not set.
-	     //
-	     chk_data(25 -(frame[4] & 0x3F) , rx_att[0], "RX1 HL ATT/GAIN");
+	     // 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");
            } 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 01f365d..c08f973 100644
--- a/meter.c
+++ b/meter.c
@@ -439,7 +439,7 @@ if(analog_meter) {
       max_count++;
 
       //angle=(max_level/2.0)+offset;
-      angle=(max_level*10.0*interval)+offset;
+      angle=(max_level*10.0/(double)interval)+offset;
       radians=angle*M_PI/180.0;
       cairo_arc(cr, cx, cy, radius+8, radians, radians);
       cairo_line_to(cr, cx, cy);
diff --git a/meter_menu.c b/meter_menu.c
index bb98f69..393c7c6 100644
--- a/meter_menu.c
+++ b/meter_menu.c
@@ -139,6 +139,7 @@ void meter_menu (GtkWidget *parent) {
   row++;
   col=0;
 
+  col++;
   GtkWidget *alc_gain=gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(alc_peak),"ALC Gain");
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (alc_gain), alc==TXA_ALC_GAIN);
   gtk_widget_show(alc_gain);
diff --git a/oc_menu.c b/oc_menu.c
index 6ae650d..2d2a2dd 100644
--- a/oc_menu.c
+++ b/oc_menu.c
@@ -172,7 +172,8 @@ void oc_menu(GtkWidget *parent) {
     //gtk_widget_override_font(oc_rx_title, pango_font_description_from_string("Arial 18"));
     gtk_widget_show(oc_rx_title);
     gtk_grid_attach(GTK_GRID(grid),oc_rx_title,i,2,1,1);
-    GtkWidget *oc_tx_title=gtk_label_new(oc_id);
+    GtkWidget *oc_tx_title=gtk_label_new(NULL);
+    gtk_label_set_markup(GTK_LABEL(oc_tx_title), oc_id);
     //gtk_widget_override_font(oc_tx_title, pango_font_description_from_string("Arial 18"));
     gtk_widget_show(oc_tx_title);
     gtk_grid_attach(GTK_GRID(grid),oc_tx_title,i+7,2,1,1);
diff --git a/old_protocol.c b/old_protocol.c
index 1ed2aae..44e1680 100644
--- a/old_protocol.c
+++ b/old_protocol.c
@@ -1395,12 +1395,10 @@ if(last_power!=power) {
         if (have_rx_gain) {
 	  //
 	  // HERMESlite has a RXgain value in the range 0-60 that
-	  // is stored in gx_gain_slider. The firmware uses bit 6
-	  // of C4 to determine this case. However RadioBerry seems
-	  // to behave differently and stores bit5 of the gain in the
-	  // dither bit (see above) and a 5-bit attenuation value here.
+	  // is stored in rx_gain_slider. The firmware uses bit 6
+	  // of C4 to determine this case.
 	  //
-          int rxgain = - adc_attenuation[active_receiver->adc]+12; // -12..48 to 0..60
+          int rxgain = adc_attenuation[active_receiver->adc]+12; // -12..48 to 0..60
           if (rxgain <  0) rxgain=0;
           if (rxgain > 60) rxgain=60;
 	  // encode all 6 bits of RXgain in ATT value and set bit6
diff --git a/tx_panadapter.c b/tx_panadapter.c
index 403deea..fe2fa9f 100644
--- a/tx_panadapter.c
+++ b/tx_panadapter.c
@@ -241,7 +241,7 @@ void tx_panadapter_update(TRANSMITTER *tx) {
   }
 
   // plot frequency markers
-  long long half=6000LL; //(long long)(tx->output_rate/2);
+  long long half= duplex ? 3000LL : 12000LL; //(long long)(tx->output_rate/2);
   long long frequency;
   if(vfo[txvfo].ctun) {
     frequency=vfo[txvfo].ctun_frequency;
@@ -262,7 +262,7 @@ void tx_panadapter_update(TRANSMITTER *tx) {
 #ifdef TX_FREQ_MARKERS
   cairo_text_extents_t extents;
   long long f;
-  long long divisor=50000;
+  long long divisor=2000;
   for(i=0;i<display_width;i++) {
     f = frequency - half + (long) (hz_per_pixel * i);
     if (f > 0) {
-- 
2.45.2