# HG changeset patch
# User Marco Filippi <iz3gme.marco@gmail.com>
# Date 1358873067 -3600
# Node ID b6d885a5b0d312a0187d1c77bde2cea00741481a
# Parent  92c41d462373df9094be5afddd19c7b9543d23df
Cleanup and debug Jim code

diff --git a/chirp/uv5r.py b/chirp/uv5r.py
--- a/chirp/uv5r.py
+++ b/chirp/uv5r.py
@@ -944,56 +944,12 @@
                                                     STEP_LIST[self._memobj.vfob.step]))
             workmode.append(rs)
 
-        # here is my practice code
-        _vfoa = self._memobj.vfoa.freq
-        rs = RadioSetting("vfoa.freq", "VFO A Frequency",
-                          RadioSettingValueInteger(0, 9, _vfoa[0]),
-                          RadioSettingValueInteger(0, 9, _vfoa[1]),
-                          RadioSettingValueInteger(0, 9, _vfoa[2]),
-                          RadioSettingValueInteger(0, 9, _vfoa[3]),
-                          RadioSettingValueInteger(0, 9, _vfoa[4]),
-                          RadioSettingValueInteger(0, 9, _vfoa[5]),
-                          RadioSettingValueInteger(0, 9, _vfoa[6]),
-                          RadioSettingValueInteger(0, 9, _vfoa[7]))
-        workmode.append(rs)
-
-        def my_validate(value):
-            if value < 400 and value > 174:
-                raise InvalidValueError("Can't be between 174-400")
-            return value
-
-        real_freq = 0
-        for byte in self._memobj.vfoa.freq:
-            real_freq = (real_freq * 10) + byte
-        real_freq /= 100000
-        val1a = RadioSettingValueFloat(136, 512, real_freq)
-        val1a.set_callback(my_validate)
-        rs = RadioSetting("footest", "VFO A Frequency", val1a)
-        workmode.append(rs)
-
-        real_freq = 0
-        for byte in self._memobj.vfob.freq:
-            real_freq = (real_freq * 10) + byte
-        real_freq /= 100000
-        val1b = RadioSettingValueFloat(136, 512, real_freq)
-        val1b.set_callback(my_validate)
-        rs = RadioSetting("vfob.freq", "VFO B Frequency", val1b)
-        workmode.append(rs)
-
         def convert_bytes_to_freq(bytes):
            real_freq = 0
            for byte in bytes:
                real_freq = (real_freq * 10) + byte
            return real_freq / 100000.0
 
-        def convert_freq_to_bytes(real_freq):
-            bytes = [ 0 for x in range(0,8) ]   # init list with 8 times 0
-            real_freq = int(freq * 100000)      # it has to be integer
-            for i in range(7, -1, -1):          # go from 7 to 0
-                bytes[i] = real_freq%10         # extract last digit
-                real_freq /= 10                 # throw away last digit
-            return bytes
-
         def my_validate(value):
             if value < 400 and value > 174:
                 raise InvalidValueError("Can't be between 174-400")
@@ -1011,18 +967,6 @@
         rs = RadioSetting("vfob.freq", "VFO B Frequency", val1b)
         workmode.append(rs)
 
-        test = RadioSettingGroup("test", "test")
-        group.append(test)
-        def my_validate(value):
-            if value < 300 and value > 200:
-                raise InvalidValueError("Can't be between 200-300")
-            return value
-
-        val = RadioSettingValueFloat(136, 450, 146.52)
-        val.set_callback(my_validate)
-        rs = RadioSetting("footest", "Foo Test", val)
-        test.append(rs)
-
         return group
 
     def get_settings(self):
@@ -1034,38 +978,39 @@
             traceback.print_exc()
             return None
 
-    def convert_freq_to_bytes(real_freq):
-        bytes = [ 0 for x in range(0,8) ]   # init list with 8 times 0
-        real_freq = int(freq * 100000)      # it has to be integer
-        for i in range(7, -1, -1):          # go from 7 to 0
-            bytes[i] = real_freq%10         # extract last digit
-            real_freq /= 10                 # throw away last digit
-        return bytes
-
     def set_settings(self, settings):
+        def convert_freq_to_bytes(freq):
+            bytes = [ 0 for x in range(0,8) ]   # init list with 8 times 0
+            real_freq = int(freq * 100000)      # it has to be integer
+            for i in range(7, -1, -1):          # go from 7 to 0
+                bytes[i] = real_freq%10         # extract last digit
+                real_freq /= 10                 # throw away last digit
+            return bytes
+            
         _settings = self._memobj.settings[0]
         for element in settings:
             if not isinstance(element, RadioSetting):
                 self.set_settings(element)
                 continue
             elif element.get_name() == "vfoa.freq":
-                convert_freq_to_bytes(self._memobj.vfoa.freq, element.value)
+                self._memobj.vfoa.freq = convert_freq_to_bytes(element.value.get_value())
             elif element.get_name() == "vfob.freq":
-                convert_freq_to_bytes(self._memobj.vfob.freq, element.value)
-            try:
-                if "." in element.get_name():
-                    bits = element.get_name().split(".")
-                    obj = self._memobj
-                    for bit in bits[:-1]:
-                        obj = getattr(obj, bit)
-                    setting = bits[-1]
-                else:
-                    obj = _settings
-                    setting = element.get_name()
-                print "Setting %s = %s" % (setting, element.value)
-                if setting == "footest":
-                    return # This is a fake setting!
-                setattr(obj, setting, element.value)
-            except Exception, e:
-                print element.get_name()
-                raise
+                self._memobj.vfob.freq = convert_freq_to_bytes(element.value.get_value())
+            else:
+                try:
+                    if "." in element.get_name():
+                        bits = element.get_name().split(".")
+                        obj = self._memobj
+                        for bit in bits[:-1]:
+                            obj = getattr(obj, bit)
+                        setting = bits[-1]
+                    else:
+                        obj = _settings
+                        setting = element.get_name()
+                    print "Setting %s = %s" % (setting, element.value)
+                    if setting == "footest":
+                        return # This is a fake setting!
+                    setattr(obj, setting, element.value)
+                except Exception, e:
+                    print element.get_name()
+                    raise
