[chirp_devel] [PATCH 3 of 3] [tg_uv2p] (revised) Dont set a priority channel if empty or Broadcast-FM. Fixes fifth issue in #9939

Ran Katz
Sun Aug 14 04:49:36 PDT 2022


# HG changeset patch
# User Ran Katz <rankatz at gmail.com>
# Date 1660477131 -10800
#      Sun Aug 14 14:38:51 2022 +0300
# Node ID 542344db60eb230eedc8962dc49175daa0ee3a53
# Parent  3eb8629bf6d76415605f6dc9004226c42d1bf55f
[tg_uv2p] (revised) Dont set a priority channel if empty or Broadcast-FM. Fixes fifth issue in #9939
Per Dan's suggestion changed implementation to a validation function and an exception to notify user of wrong input

diff --git a/chirp/drivers/tg_uv2p.py b/chirp/drivers/tg_uv2p.py
--- a/chirp/drivers/tg_uv2p.py
+++ b/chirp/drivers/tg_uv2p.py
@@ -508,10 +508,16 @@
         mem_vals.insert(0, 0xFF)
         user_options.insert(0, "Not Set")
         options_map = zip(user_options, mem_vals)
-
-        rs = RadioSetting("priority_channel", "Priority Channel",
-                          RadioSettingValueMap(options_map,
-                                               _settings.priority_channel))
+        if _settings.priority_channel >= 200:
+            _priority_ch = 0xFF
+        else:
+            _priority_ch = _settings.priority_channel
+        rs = RadioSetting(
+            "priority_channel",
+            "Priority Channel \n"
+            "Note: Unused channels,\nor channels "
+            "in the\nbroadcast FM band,\nwill not be set",
+            RadioSettingValueMap(options_map, _priority_ch))
         cfg_grp.append(rs)
 
         # Step
@@ -679,6 +685,17 @@
 
         return group
 
+    def _validate_priority_ch(self, ch_num):
+        if ch_num == 0xFF:
+            return True
+        _mem, _bf, _nam = self._get_memobjs(ch_num)
+        if (_mem.freq.get_raw()[0] == "\xFF") or (_bf.band == "\x0F"):
+            return False
+        elif _bf.band == 0x00:
+            return False
+        else:
+            return True
+
     def set_settings(self, settings):
         for element in settings:
             if not isinstance(element, RadioSetting):
@@ -733,6 +750,18 @@
                                     "when keypad is locked")
                         LOG.debug("Setting %s = %s" % (setting, element.value))
                         setattr(obj, setting, element.value)
+                    elif setting == "priority_channel":
+                        _check = self._validate_priority_ch(int(element.value))
+                        if _check:
+                            LOG.debug("Setting %s = %s" % (setting,
+                                                           element.value))
+                            setattr(obj, setting, element.value)
+                        else:
+                            raise errors.InvalidValueError(
+                                "Please select a valid priority channel:\n"
+                                "A used memory channel which is not "
+                                "in the Broadcast FM band (88-108MHz),\n"
+                                "Or select 'Not Used'")
                     elif element.value.get_mutable():
                         LOG.debug("Setting %s = %s" % (setting, element.value))
                         setattr(obj, setting, element.value)




More information about the chirp_devel mailing list