From a744ba21362a0549c56e8efbc7e6c0a5624b7be9 Mon Sep 17 00:00:00 2001
From: Ramakrishnan Muthukrishnan <ram@rkrishnan.org>
Date: Fri, 14 Jan 2022 16:27:19 +0530
Subject: [PATCH] store and use the original real attenuation value before
 truncation

---
 rigctl.c  | 4 ++--
 sliders.c | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/rigctl.c b/rigctl.c
index 67e7cf2..6ab71dc 100644
--- a/rigctl.c
+++ b/rigctl.c
@@ -3463,7 +3463,7 @@ int parse_cmd(void *data) {
       if (command[2] == ';') {
         double att = 0.0;
         if (have_rx_gain) {
-          att = adc[active_receiver->adc].attenuation + 12.0;
+          att = adc[active_receiver->adc].attenuation_orig + 12.0;
           printf("after stage 1: %f\n", att);
           att = round(att * (99.0 / 60.0));
           printf("after stage 2: %f\n", att);
@@ -3480,7 +3480,7 @@ int parse_cmd(void *data) {
           printf("setting attn level [0..99]: %d\n", attI);
 
           if (have_rx_gain) {
-              att = round(((attI * 60.0) / 99.0) - 12.0);
+              att = ((attI * 60.0) / 99.0) - 12.0;
           } else {
               att = (attI * 31.0) / 99.0;
           }
diff --git a/sliders.c b/sliders.c
index 61569ad..f5d63ce 100644
--- a/sliders.c
+++ b/sliders.c
@@ -154,7 +154,8 @@ static void attenuation_value_changed_cb(GtkWidget *widget, gpointer data) {
 void set_attenuation_value(double value) {
   g_print("%s\n",__FUNCTION__);
   printf("last attn value: %d, setting it to: %f\n", adc[active_receiver->adc].attenuation, value);
-  adc[active_receiver->adc].attenuation=(int)value;
+  adc[active_receiver->adc].attenuation_orig = value;
+  adc[active_receiver->adc].attenuation = (int)value;
   set_attenuation(adc[active_receiver->adc].attenuation);
   if(display_sliders) {
     if (have_rx_gain) {
-- 
2.45.2