# HG changeset patch
# User K. Arvanitis <kosta@alumni.uvic.ca>
# Date 1422243928 28800
#      Sun Jan 25 19:45:28 2015 -0800
# Node ID 1e842859ec126d1e7bb336d13ee9c3d68ff1d3b0
# Parent  b25606106a9c0cd78f3cc5f602475da64cde081d
[FT-60] Memory Bank Link Scan
Added settings support for memory bank link scan.
Extended bitwise int data element to support xor operator.
Note: The mbs settings are stored in the 16 bits located at
memory location 0x09E in the high order bits.
Note: A bank can be linked even if it contains no memories.
In this case the radio ignores it during the mbl scan.
Bug #675
Bug #1945
diff -r b25606106a9c -r 1e842859ec12 chirp/bitwise.py
--- a/chirp/bitwise.py Wed Jan 21 23:30:19 2015 -0800
+++ b/chirp/bitwise.py Sun Jan 25 19:45:28 2015 -0800
@@ -304,6 +304,9 @@
     def __or__(self, val):
         return self.get_value() | val
 
+    def __xor__(self, val):
+        return self.get_value() ^ val
+
     def __and__(self, val):
         return self.get_value() & val
 
@@ -325,6 +328,9 @@
     def __ror__(self, val):
         return val | self.get_value()
 
+    def __rxor__(self, val):
+        return val ^ self.get_value()
+
     def __rmod__(self, val):
         return val % self.get_value()
 
@@ -362,6 +368,10 @@
         self.set_value(self.get_value() | val)
         return self
 
+    def __ixor__(self, val):
+        self.set_value(self.get_value() ^ val)
+        return self
+
     def __index__(self):
         return abs(self)
 
diff -r b25606106a9c -r 1e842859ec12 chirp/ft60.py
--- a/chirp/ft60.py Wed Jan 21 23:30:19 2015 -0800
+++ b/chirp/ft60.py Sun Jan 25 19:45:28 2015 -0800
@@ -274,10 +274,6 @@
             bank = chirp_common.Bank(self, "%i" % (i + 1), "Bank %i" % (i + 1))
             bank.index = i
             banks.append(bank)
-
-            #mbs = (self._radio._memobj.mbs >> i) & 1
-            #print "Bank %i: mbs: %i " % (i, mbs)
-
         return banks
 
     def add_memory_to_mapping(self, memory, bank):
@@ -402,9 +398,10 @@
         eai = RadioSettingGroup("eai", "EAI/EPCS Settings")
         switch = RadioSettingGroup("switch", "Switch/Knob Settings")
         misc = RadioSettingGroup("misc", "Miscellaneous Settings")
+        mbls = RadioSettingGroup("banks", "Memory Bank Link Scan")
 
         setmode = RadioSettingGroup("top", "Set Mode",
-                    repeater, ctcss, arts, scan, power, wires, eai, switch, misc)
+                    repeater, ctcss, arts, scan, power, wires, eai, switch, misc, mbls)
 
         # APO
         opts = [ "OFF" ] + [ "%0.1f" % (x * 0.5) for x in range(1, 24+1) ]
@@ -585,6 +582,20 @@
         scan.append( RadioSetting("wx_alt", "Weather Alert Scan",
             RadioSettingValueList(opts, opts[_settings.wx_alt])))
 
+        # MBS
+        for i in range(0, 10):
+            opts = [ "OFF" ] + [ "ON" ]
+            mbs = (self._memobj.mbs >> i) & 1
+            rs = RadioSetting("mbs%i" % i, "Bank %s Scan" % (i + 1),
+                RadioSettingValueList(opts, opts[mbs]))
+            def apply_mbs(s, index):
+                if int(s.value):
+                    self._memobj.mbs |= (1 << index)
+                else:
+                    self._memobj.mbs &= ~(1 << index);
+            rs.set_apply_callback(apply_mbs, i);
+            mbls.append(rs)
+
         return setmode
 
     def set_settings(self, uisettings):
@@ -599,16 +610,16 @@
             try:
                 name = element.get_name()
                 value = element.value
-                obj = getattr(_settings, name)
 
                 if element.has_apply_callback():
                     print "Using apply callback"
                     element.run_apply_callback()
                 else:
+                    obj = getattr(_settings, name)
                     setattr(_settings, name, value)
 
                 if os.getenv("CHIRP_DEBUG"):
-                    print "Setting %s: %s <= %s" % (name, obj, element.value)
+                    print "Setting %s: %s" % (name, value)
             except Exception, e:
                 print element.get_name()
                 raise