From: Ramakrishnan Muthukrishnan <ram@rkrishnan.org>
Date: Tue, 28 Nov 2023 02:31:33 +0000 (+0530)
Subject: rewrite get_nr(), slightly better now but NR handling needs refactoring
X-Git-Url: https://git.rkrishnan.org/pf/components/nxhtml.html?a=commitdiff_plain;h=refs%2Fheads%2Fvfo-changes;p=pihpsdr.git

rewrite get_nr(), slightly better now but NR handling needs refactoring
---

diff --git a/vfo.c b/vfo.c
index 3236ca9..16258fa 100644
--- a/vfo.c
+++ b/vfo.c
@@ -1018,24 +1018,22 @@ void draw_item(cairo_t *cr, size_t item, uint status) {
 // I am not proud of this code
 int get_nr(RECEIVER *rx)
 {
-    if (rx->nr == 0 && rx->nr2 == 0 && rx->nr3 == 0 && rx->nr4 == 0) {
-	return 0;
-    }
+    int nr_bitmap = rx->nr | (rx->nr2 << 1) | (rx->nr3 << 2) | (rx->nr4 << 3);
 
-    if (rx->nr == 1 && rx->nr2 == 0 && rx->nr3 == 0 && rx->nr4 == 0) {
+    switch (nr_bitmap) {
+    case 0:
+	return 0;
+    case 1:
 	return 1;
-    }
-
-    if (rx->nr == 0 && rx->nr2 == 1 && rx->nr3 == 0 && rx->nr4 == 0) {
+    case 2:
 	return 2;
-    }
-
-    if (rx->nr == 0 && rx->nr2 == 0 && rx->nr3 == 1 && rx->nr4 == 0) {
+    case 4:
 	return 3;
-    }
-
-    if (rx->nr == 0 && rx->nr2 == 0 && rx->nr3 == 0 && rx->nr4 == 1) {
+    case 8:
 	return 4;
+    default:
+	g_print("NR: unknown NR value");
+	return -1;
     }
 
     return -1;