From 8f7da1e5997cf6a1b13adf8daa4091606acd0ad4 Mon Sep 17 00:00:00 2001
From: Ramakrishnan Muthukrishnan <ram@rkrishnan.org>
Date: Wed, 12 Jan 2022 11:14:10 +0530
Subject: [PATCH] rigctl: implement zzmg correctly

---
 rigctl.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/rigctl.c b/rigctl.c
index 100c98f..fc5c66b 100644
--- a/rigctl.c
+++ b/rigctl.c
@@ -1817,14 +1817,17 @@ gboolean parse_extended_cmd(char *command, CLIENT *client) {
       }
       break;
     case 'G': // ZZMG
-      // set/read mic gain
-      if (command[4] == ';') {
-        sprintf(reply, "ZZMG%03d;", (int)mic_gain);
-        send_resp(client->fd, reply);
-      } else if (command[7] == ';') {
-        mic_gain = (double)atoi(&command[4]);
-      }
-      break;
+        // set/read mic gain
+        if (command[4] == ';') {
+            sprintf(reply, "ZZMG%03d;", (int)(((mic_gain + 12.0) / 72.0) * 100.0));
+            send_resp(client->fd, reply);
+        } else if (command[7] == ';') {
+            command[7] = '\0';
+            double gain = (double)atoi(&command[4]);
+            gain = ((gain / 100.0) * 72.0) - 12.0;
+            set_mic_gain(gain);
+        }
+        break;
     case 'L': // ZZML
       // read DSP modes and indexes
       if (command[4] == ';') {
-- 
2.45.2