# HG changeset patch
# User Richard Birch <n7uoa.birch@gmail.com>
# Date 1528776273 21600
#      Mon Jun 11 22:04:33 2018 -0600
# Node ID a4c1ce4e14c0d74aa96c87b114736fceb90d2fcd
# Parent  907a29c461756340424bde01760cfc2065f9f91c
[vx5] Added support for virtual jumpers. Fixed #5383

diff -r 907a29c46175 -r a4c1ce4e14c0 chirp/drivers/vx5.py
--- a/chirp/drivers/vx5.py	Sun Jun 10 19:14:03 2018 -0400
+++ b/chirp/drivers/vx5.py	Mon Jun 11 22:04:33 2018 -0600
@@ -14,10 +14,17 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+import logging
+
 from chirp.drivers import yaesu_clone
 from chirp import chirp_common, directory, errors, bitwise
+from chirp.settings import RadioSetting, RadioSettingGroup, \
+    RadioSettingValueBoolean, RadioSettingValueInteger, \
+    RadioSettingValueList, RadioSettings
 from textwrap import dedent
 
+LOG = logging.getLogger(__name__)
+
 MEM_FORMAT = """
 struct mem_struct {
   u8 unknown1:2,
@@ -76,6 +83,20 @@
 
 #seekto 0x1D03;
 u8 current_bank;
+
+#seekto 0x000A;
+struct {
+  struct {
+    u8 flag_1:1,
+       flag_2:1,
+       full_rx:1,
+       mars_cap:1,
+       full_tx:1,
+       country:3;
+  } jumper;
+  #seekto 0x000A;
+  u8 full_jumper;
+} settings;
 """
 
 TMODES = ["", "Tone", "TSQL", "DTCS"]
@@ -106,8 +127,8 @@
         _bank_used = self._radio._memobj.bank_used[bank.index]
         for i in range(0, len(_members)):
             if _members[i].status == 0xFF:
-                # LOG.debug("empty found, inserting %d at %d" %
-                #           (memory.number, i))
+                LOG.debug("empty found, inserting %d at %d" %
+                          (memory.number, i))
                 if self._radio._memobj.current_bank == 0xFF:
                     self._radio._memobj.current_bank = bank.index
                 _members[i].status = 0x00
@@ -179,6 +200,7 @@
     def get_features(self):
         rf = chirp_common.RadioFeatures()
         rf.can_odd_split = True
+        rf.has_settings = True
         rf.has_bank = True
         rf.has_ctone = False
         rf.has_dtcs_polarity = False
@@ -311,6 +333,80 @@
         _flg.skip = mem.skip == "S"
         _flg.pskip = mem.skip == "P"
 
+    def get_settings(self):
+        _settings = self._memobj.settings
+        _jumper = _settings.jumper
+        jumper = RadioSettingGroup("jumper", "Jumper")
+        top = RadioSettings(jumper)
+
+        options = ["Japan", "U.S.A.", "Asia", "Europe",
+                   "Country 5", "Germany", "Country 7", "Country 8"]
+        rs = RadioSetting(
+            "settings.jumper.country", "Country",
+            RadioSettingValueList(options, options[_jumper.country]))
+        jumper.append(rs)
+
+        rs = RadioSetting(
+            "settings.jumper.flag_1", "Jumper 1",
+            RadioSettingValueBoolean(_jumper.flag_1))
+        jumper.append(rs)
+
+        rs = RadioSetting(
+            "settings.jumper.flag_2", "Jumper 2",
+            RadioSettingValueBoolean(_jumper.flag_2))
+        jumper.append(rs)
+
+        rs = RadioSetting(
+            "settings.jumper.full_rx", "Full RX",
+            RadioSettingValueBoolean(_jumper.full_rx))
+        jumper.append(rs)
+
+        rs = RadioSetting(
+            "settings.jumper.mars_cap", "MARS/CAP",
+            RadioSettingValueBoolean(_jumper.mars_cap))
+        jumper.append(rs)
+
+        rs = RadioSetting(
+            "settings.jumper.full_tx", "Full TX",
+            RadioSettingValueBoolean(_jumper.full_tx))
+        jumper.append(rs)
+
+        return top
+
+    def set_settings(self, settings):
+        _settings = self._memobj.settings
+        for element in settings:
+            if not isinstance(element, RadioSetting):
+                self.set_settings(element)
+                continue
+            else:
+                try:
+                    name = element.get_name()
+                    if "." in name:
+                        bits = name.split(".")
+                        obj = self._memobj
+                        for bit in bits[:-1]:
+                            if "/" in bit:
+                                bit, index = bit.split("/", 1)
+                                index = int(index)
+                                obj = getattr(obj, bit)[index]
+                            else:
+                                obj = getattr(obj, bit)
+                        setting = bits[-1]
+                    else:
+                        obj = _settings
+                        setting = element.get_name()
+
+                    if element.has_apply_callback():
+                        LOG.debug("Using apply callback")
+                        element.run_apply_callback()
+                    elif element.value.get_mutable():
+                        LOG.debug("Setting %s = %s" % (setting, element.value))
+                        setattr(obj, setting, element.value)
+                except Exception, e:
+                    LOG.debug(element.get_name())
+                    raise
+
     @classmethod
     def get_prompts(cls):
         rp = chirp_common.RadioPrompts()
