[chirp_devel] [PATCH] [uv-b5] Update Broadcast FM Radio Presets for Baofeng UV-B5/B6

Jim Unroe
Sat Sep 28 18:51:08 PDT 2013


# HG changeset patch
# User Jim Unroe <rock.unroe at gmail.com>
# Date 1380419318 14400
# Node ID 2601dd65c83a1556d0b57dc59107cd37f79d84a4
# Parent  ac65038940f227d46ba28186627b42108dae6447
[uv-b5] Update Broadcast FM Radio Presets for Baofeng UV-B5/B6
revised FM Presets to be similar to the wouxun.py driver FM Presets
related to #995

diff -r ac65038940f2 -r 2601dd65c83a chirp/uvb5.py
--- a/chirp/uvb5.py	Thu Sep 26 11:39:51 2013 +0200
+++ b/chirp/uvb5.py	Sat Sep 28 21:48:38 2013 -0400
@@ -17,7 +17,8 @@
 from chirp import chirp_common, directory, bitwise, memmap, errors, util
 from chirp.settings import RadioSetting, RadioSettingGroup, \
                 RadioSettingValueBoolean, RadioSettingValueList, \
-                RadioSettingValueInteger, RadioSettingValueString
+                RadioSettingValueInteger, RadioSettingValueString, \
+                RadioSettingValueFloat
 
 mem_format = """
 struct memory {
@@ -49,9 +50,7 @@
 struct memory vfo2;
 
 #seekto 0x09D0;
-struct {
-  u16 freq;
-} broadcastfm[16];
+u16 fm_presets[16];
 
 #seekto 0x0A30;
 struct {
@@ -590,28 +589,20 @@
         rs.set_apply_callback(apply_limit, self._memobj.limits)
         basic.append(rs)
 
-        bcastfm = RadioSettingGroup("bcastfm", "FM Radio Presets")
-        group.append(bcastfm)
-
-        def convert_bytes_to_freq(bytes):
-            real_freq = int(bytes) + 650
-            if real_freq > 1080:
-                real_freq = 0
-            return chirp_common.format_freq(real_freq * 100000)
-
-        def apply_freq(setting, obj):
-            value = chirp_common.parse_freq(str(setting.value)) / 100000
-            if value < 650 or value > 1080:
-                value = 65535 + 650
-            obj.freq = value - 650
+        fm_preset = RadioSettingGroup("fm_preset", "FM Radio Presets")
+        group.append(fm_preset)
 
         for i in range(0, 16):
-            _freq = RadioSettingValueString(0, 10,
-               convert_bytes_to_freq(self._memobj.broadcastfm[i].freq))
-            rs = RadioSetting("broadcastfm/%i.freq" % i,
-                              "Channel %i (65.0-108.0)" % (i + 1), _freq)
-            rs.set_apply_callback(apply_freq, self._memobj.broadcastfm[i])
-            bcastfm.append(rs)
+            if self._memobj.fm_presets[i] != 0xFFFF:
+                used = True
+                preset = self._memobj.fm_presets[i]/10.0+65
+            else:
+                used = False
+                preset = 65
+            rs = RadioSetting("fm_presets_%1i" % i, "FM Preset %i" % (i+1),
+                          RadioSettingValueBoolean(used),
+                          RadioSettingValueFloat(65, 108, preset, 0.1, 1))
+            fm_preset.append(rs)
 
         testmode = RadioSettingGroup("testmode", "Test Mode Settings")
         group.append(testmode)
@@ -658,31 +649,51 @@
         _settings = self._memobj.settings
         for element in settings:
             if not isinstance(element, RadioSetting):
-                self.set_settings(element)
-                continue
+                if element.get_name() == "fm_preset" :
+                    self._set_fm_preset(element)
+                else:
+                    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():
+                        print "Using apply callback"
+                        element.run_apply_callback()
+                    else:
+                        print "Setting %s = %s" % (setting, element.value)
+                        setattr(obj, setting, element.value)
+                except Exception, e:
+                    print element.get_name()
+                    raise
+
+    def _set_fm_preset(self, settings):
+        for element in settings:
             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]
+                index = (int(element.get_name().split("_")[-1]))
+                val = element.value
+                if val[0].get_value():
+                    value = int(val[1].get_value()*10-650)
                 else:
-                    obj = _settings
-                    setting = element.get_name()
-
-                if element.has_apply_callback():
-                    print "Using apply callback"
-                    element.run_apply_callback()
-                else:
-                    print "Setting %s = %s" % (setting, element.value)
-                    setattr(obj, setting, element.value)
+                    value = 0xffff
+                print "Setting fm_presets[%1i] = %s" % (index, value)
+                setting = self._memobj.fm_presets
+                setting[index] = value
             except Exception, e:
                 print element.get_name()
                 raise



More information about the chirp_devel mailing list