From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dangerous Pi <dangerous-pi@users.noreply.github.com>
Date: Tue, 11 Feb 2026 00:00:00 +0000
Subject: [PATCH] client: detect booster board / LC tank loading during hw tune

When a booster board or other LC tank circuit is installed on a PM3
Easy (non-RDV4), the HF antenna voltage during `hw tune` drops into
the 2550-2750 mV range. Previously this was reported as "unusable"
with no Q-factor calculation. This change detects the loaded state
and warns the user about the likely cause.

The detection only fires on non-RDV4 devices since the voltage range
is calibrated for the PM3 Easy voltage divider (11:1, vdd_other=5400).
On RDV4 (42.67:1 divider), the same mV reading has different meaning.
---
 client/src/cmdhw.c | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/client/src/cmdhw.c b/client/src/cmdhw.c
--- a/client/src/cmdhw.c
+++ b/client/src/cmdhw.c
@@ -909,6 +909,8 @@
 #define LF_MARGINAL_V   10000
 #define HF_UNUSABLE_V   3000
 #define HF_MARGINAL_V   5000
+#define HF_BOOSTER_LOW  2550    // lower bound of HF booster/LC tank loading range (mV)
+#define HF_BOOSTER_HIGH 2750    // upper bound of HF booster/LC tank loading range (mV)
 #define ANTENNA_ERROR   1.00 // current algo has 3% error margin.

     PrintAndLogEx(NORMAL, "");
@@ -1055,6 +1057,10 @@

     memset(judgement, 0, sizeof(judgement));

+    bool hf_booster_detected = (package->v_hf >= HF_BOOSTER_LOW
+                                && package->v_hf <= HF_BOOSTER_HIGH
+                                && !IfPm3Rdv4Fw());
+
     PrintAndLogEx(SUCCESS, "");
     PrintAndLogEx(SUCCESS, "Approx. Q factor measurement");

@@ -1062,16 +1068,24 @@
         // Q measure with Vlr=Q*(2*Vdd/pi)
         double hfq = (double)package->v_hf * 3.14 / 2 / vdd;
         PrintAndLogEx(SUCCESS, "Peak voltage.......... " _YELLOW_("%.1lf"), hfq);
-    }
-
-    if (package->v_hf < HF_UNUSABLE_V)
+    } else if (hf_booster_detected) {
+        PrintAndLogEx(SUCCESS, "Your HF antenna measurement shows");
+        PrintAndLogEx(SUCCESS, "low voltage that is consistent");
+        PrintAndLogEx(SUCCESS, "with the installation of a booster");
+        PrintAndLogEx(SUCCESS, "board. If you do not have a");
+        PrintAndLogEx(SUCCESS, "booster board installed, either");
+        PrintAndLogEx(SUCCESS, "your antenna is malfunctioning or");
+        PrintAndLogEx(SUCCESS, "you have a tag on the HF antenna.");
+    }
+
+    if (hf_booster_detected)
+        snprintf(judgement, sizeof(judgement), _YELLOW_("loaded"));
+    else if (package->v_hf < HF_UNUSABLE_V)
         snprintf(judgement, sizeof(judgement), _RED_("unusable"));
     else if (package->v_hf < HF_MARGINAL_V)
         snprintf(judgement, sizeof(judgement), _YELLOW_("marginal"));
     else
         snprintf(judgement, sizeof(judgement), _GREEN_("ok"));

-    PrintAndLogEx((package->v_hf < HF_UNUSABLE_V) ? WARNING : SUCCESS, "HF antenna ( %s )", judgement);
+    PrintAndLogEx((package->v_hf < HF_UNUSABLE_V && !hf_booster_detected) ? WARNING : SUCCESS, "HF antenna ( %s )", judgement);
+
+    if (hf_booster_detected) {
+        PrintAndLogEx(NORMAL, "");
+    }

     // graph LF measurements
     // even here, these values has 3% error.
@@ -1103,6 +1117,9 @@

     PrintAndLogEx(NORMAL, "");
     PrintAndLogEx(INFO, "Q factor must be measured without tag on the antenna");
+    if (hf_booster_detected) {
+        PrintAndLogEx(INFO, "Booster board detection range: %.2f - %.2f V", HF_BOOSTER_LOW / 1000.0, HF_BOOSTER_HIGH / 1000.0);
+    }
     PrintAndLogEx(NORMAL, "");
     return PM3_SUCCESS;
 }
