# HG changeset patch
# User Jim Unroe <rock.unroe@gmail.com>
# Date 1639878119 18000
#      Sat Dec 18 20:41:59 2021 -0500
# Node ID 46668279f5d67a87249641dbbad647e1c06f5120
# Parent  25ebadb2b69bcb75273e84d5c1289331bcef78a4
[UV-5X3] Fix for Unable to See Settings on BTECH UV-5X3

The BTECH UV-5X3 as shipped from the factory does not always have all 6 of the
sub-VFOs populated with frequencies. This was generating and error conditions
that was preventing the Settings tabs from being displayed.

This patch detects an unpopulated sub-VFO setting and populates the setting
with the appropriate low band limit frequency.

fixes #9617

diff -r 25ebadb2b69b -r 46668279f5d6 chirp/drivers/uv5x3.py
--- a/chirp/drivers/uv5x3.py	Wed Dec 15 08:34:34 2021 -0800
+++ b/chirp/drivers/uv5x3.py	Sat Dec 18 20:41:59 2021 -0500
@@ -790,6 +790,9 @@
         def convert_bytes_to_freq(bytes):
             real_freq = 0
             for byte in bytes:
+                if byte > 9:
+                    real_freq = 0
+                    continue
                 real_freq = (real_freq * 10) + byte
             return chirp_common.format_freq(real_freq * 10)
 
@@ -866,43 +869,55 @@
         rs.set_apply_callback(apply_freq, _mem.vfo.b)
         work.append(rs)
 
-        val1a = RadioSettingValueString(0, 10, convert_bytes_to_freq(
-                                            _mem.subvfoa.vhf.freq))
+        val = convert_bytes_to_freq(_mem.subvfoa.vhf.freq)
+        if int(float(val)) == 0:
+            val = str(int(_mem.limits.vhf.lower)) + ".000000"
+        val1a = RadioSettingValueString(0, 10, val)
         val1a.set_validate_callback(my_vhf_validate)
         rs = RadioSetting("subvfoa.vhf.freq", "VFO A VHF (Saved)", val1a)
         rs.set_apply_callback(apply_freq, _mem.subvfoa.vhf)
         work.append(rs)
 
-        val1b = RadioSettingValueString(0, 10, convert_bytes_to_freq(
-                                            _mem.subvfob.vhf.freq))
+        val = convert_bytes_to_freq(_mem.subvfob.vhf.freq)
+        if int(float(val)) == 0:
+            val = str(int(_mem.limits.vhf.lower)) + ".000000"
+        val1b = RadioSettingValueString(0, 10, val)
         val1b.set_validate_callback(my_vhf_validate)
         rs = RadioSetting("subvfob.vhf.freq", "VFO B VHF (Saved)", val1b)
         rs.set_apply_callback(apply_freq, _mem.subvfob.vhf)
         work.append(rs)
 
-        val1a = RadioSettingValueString(0, 10, convert_bytes_to_freq(
-                                            _mem.subvfoa.vhf2.freq))
+        val = convert_bytes_to_freq(_mem.subvfoa.vhf2.freq)
+        if int(float(val)) == 0:
+            val = str(int(_mem.limits.vhf2.lower)) + ".000000"
+        val1a = RadioSettingValueString(0, 10, val)
         val1a.set_validate_callback(my_vhf2_validate)
         rs = RadioSetting("subvfoa.vhf2.freq", "VFO A VHF2 (Saved)", val1a)
         rs.set_apply_callback(apply_freq, _mem.subvfoa.vhf2)
         work.append(rs)
 
-        val1b = RadioSettingValueString(0, 10, convert_bytes_to_freq(
-                                            _mem.subvfob.vhf2.freq))
+        val = convert_bytes_to_freq(_mem.subvfob.vhf2.freq)
+        if int(float(val)) == 0:
+            val = str(int(_mem.limits.vhf2.lower)) + ".000000"
+        val1b = RadioSettingValueString(0, 10, val)
         val1b.set_validate_callback(my_vhf2_validate)
         rs = RadioSetting("subvfob.vhf2.freq", "VFO B VHF2 (Saved)", val1b)
         rs.set_apply_callback(apply_freq, _mem.subvfob.vhf2)
         work.append(rs)
 
-        val1a = RadioSettingValueString(0, 10, convert_bytes_to_freq(
-                                            _mem.subvfoa.uhf.freq))
+        val = convert_bytes_to_freq(_mem.subvfoa.uhf.freq)
+        if int(float(val)) == 0:
+            val = str(int(_mem.limits.uhf.lower)) + ".000000"
+        val1a = RadioSettingValueString(0, 10, val)
         val1a.set_validate_callback(my_uhf_validate)
         rs = RadioSetting("subvfoa.uhf.freq", "VFO A UHF (Saved)", val1a)
         rs.set_apply_callback(apply_freq, _mem.subvfoa.uhf)
         work.append(rs)
 
-        val1b = RadioSettingValueString(0, 10, convert_bytes_to_freq(
-                                            _mem.subvfob.uhf.freq))
+        val = convert_bytes_to_freq(_mem.subvfob.uhf.freq)
+        if int(float(val)) == 0:
+            val = str(int(_mem.limits.uhf.lower)) + ".000000"
+        val1b = RadioSettingValueString(0, 10, val)
         val1b.set_validate_callback(my_uhf_validate)
         rs = RadioSetting("subvfob.uhf.freq", "VFO B UHF (Saved)", val1b)
         rs.set_apply_callback(apply_freq, _mem.subvfob.uhf)
