# HG changeset patch # User Dan Smith dsmith@danplanet.com # Date 1361832532 28800 # Node ID 8f7e6e07076f39efb3ecf87717fd50935b0b58c8 # Parent 680852fc3ef56aa6c3edeab17ea87924b241028a [uv5r][RFC] Dynamically honor band limits
Since we let the user set them arbitrarily, it seems weird to honor a second set of invisible limits. We have to be careful to support looking up these limits in the absence of an actual image, but we can substitute the original ones there.
diff -r 680852fc3ef5 -r 8f7e6e07076f chirp/uv5r.py --- a/chirp/uv5r.py Sun Feb 24 22:04:01 2013 -0800 +++ b/chirp/uv5r.py Mon Feb 25 14:48:52 2013 -0800 @@ -22,6 +22,7 @@ RadioSettingValueInteger, RadioSettingValueList, \ RadioSettingValueBoolean, RadioSettingValueString, \ InvalidValueError +from chirp.chirp_common import to_MHz
MEM_FORMAT = """ #seekto 0x0008; @@ -474,7 +475,15 @@ rf.valid_power_levels = UV5R_POWER_LEVELS rf.valid_duplexes = ["", "-", "+", "split", "off"] rf.valid_modes = ["FM", "NFM"] - rf.valid_bands = [(136000000, 174000000), (400000000, 520000000)] + if self._mmap is not None: + limits = self._get_limits() + rf.valid_bands = [ + (to_MHz(limits[0]), to_MHz(limits[1])), + (to_MHz(limits[2]), to_MHz(limits[3])), + ] + else: + rf.valid_bands = [(136000000, 174000000), (400000000, 520000000)] + rf.memory_bounds = (0, 127) return rf
@@ -711,6 +720,17 @@ return int(version_tag[idx:idx+3]) raise Exception("Unrecognized firmware version string")
+ def _get_limitobj(self): + if self._is_orig(): + return getattr(self._memobj, 'limits_old') + else: + return getattr(self._memobj, 'limits_new') + + def _get_limits(self): + limit = self._get_limitobj() + return (int(limit.vhf.lower), int(limit.vhf.upper), + int(limit.uhf.lower), int(limit.uhf.upper)) + def _get_settings(self): _settings = self._memobj.settings[0] basic = RadioSettingGroup("basic", "Basic Settings") @@ -871,37 +891,33 @@ PONMSG_LIST[_settings.ponmsg])) other.append(rs)
+ # FIXME: argh, fix this later (bitwise .name) if self._is_orig(): - limit = "limits_old" + limitname = "limits_old" else: - limit = "limits_new" - - vhf_limit = getattr(self._memobj, limit).vhf - rs = RadioSetting("%s.vhf.lower" % limit, "VHF Lower Limit (MHz)", - RadioSettingValueInteger(1, 1000, - vhf_limit.lower)) + limitname = "limits_new" + limit = self._get_limitobj() + vhf_lo, vhf_hi, uhf_lo, uhf_hi = self._get_limits() + rs = RadioSetting("%s.vhf.lower" % limitname, "VHF Lower Limit (MHz)", + RadioSettingValueInteger(1, 1000, vhf_lo)) other.append(rs)
- rs = RadioSetting("%s.vhf.upper" % limit, "VHF Upper Limit (MHz)", - RadioSettingValueInteger(1, 1000, - vhf_limit.upper)) + rs = RadioSetting("%s.vhf.upper" % limitname, "VHF Upper Limit (MHz)", + RadioSettingValueInteger(1, 1000, vhf_hi)) other.append(rs)
- rs = RadioSetting("%s.vhf.enable" % limit, "VHF TX Enabled", - RadioSettingValueBoolean(vhf_limit.enable)) + rs = RadioSetting("%s.vhf.enable" % limitname, "VHF TX Enabled", + RadioSettingValueBoolean(limit.vhf.enable)) other.append(rs)
- uhf_limit = getattr(self._memobj, limit).uhf - rs = RadioSetting("%s.uhf.lower" % limit, "UHF Lower Limit (MHz)", - RadioSettingValueInteger(1, 1000, - uhf_limit.lower)) + rs = RadioSetting("%s.uhf.lower" % limitname, "UHF Lower Limit (MHz)", + RadioSettingValueInteger(1, 1000, uhf_lo)) other.append(rs) - rs = RadioSetting("%s.uhf.upper" % limit, "UHF Upper Limit (MHz)", - RadioSettingValueInteger(1, 1000, - uhf_limit.upper)) + rs = RadioSetting("%s.uhf.upper" % limitname, "UHF Upper Limit (MHz)", + RadioSettingValueInteger(1, 1000, uhf_hi)) other.append(rs) - rs = RadioSetting("%s.uhf.enable" % limit, "UHF TX Enabled", - RadioSettingValueBoolean(uhf_limit.enable)) + rs = RadioSetting("%s.uhf.enable" % limitname, "UHF TX Enabled", + RadioSettingValueBoolean(limit.uhf.enable)) other.append(rs)
workmode = RadioSettingGroup("workmode", "Work Mode Settings")