]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
rewrite get_nr(), slightly better now but NR handling needs refactoring vfo-changes
authorRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Tue, 28 Nov 2023 02:31:33 +0000 (08:01 +0530)
committerRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Tue, 28 Nov 2023 02:31:33 +0000 (08:01 +0530)
vfo.c

diff --git a/vfo.c b/vfo.c
index 3236ca98cb46ae1183ec215c1946f3393f8c4f78..16258faf5aa595e2e8e310fecba0e545555556ba 100644 (file)
--- 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;