[chirp_devel] VFO Frequency Presets
Dan and the group, Here are two patch files that I have created in an attempt to create a menu setting to allow the CHIRP user to preset the VFO frequency of a UV-5R.
I am close but can't quite get to the point where it work. Dan has provided some extra features in CHIRP to work with this (test1.patch). My code is in test2.patch.
I'm trying to take a value from the radio that is in the form 0x01, 0x04, 0x06, 0x05, 0x02, 0x00, 0x,00, 0x00 for 146.52000, taking that and converting it into a floating point decimal to display to the user for editing, and then convert it back for the radio.
Thanks in advance for your advice, Jim KC9HI
real_freq = 0
for byte in self._memobj.vfoa.freq:
real_freq = (real_freq * 10) + byte
real_freq /= 100000
I think if you change this to the following it will do what you want:
real_freq /= 1000.0
You need at least one side to be a float to get a float in return. Then I think that this will work:
val1a = RadioSettingValueFloat(136, 512, real_freq)
val1a.set_callback(my_validate)
rs = RadioSetting("footest", "VFO A Frequency", val1a)
workmode.append(rs)
Since you have to do this twice, I'd like you to make it a helper function, like this:
def convert_bytes_to_freq(bytes): real_freq = 0 for byte in self._memobj.vfob.freq: real_freq = (real_freq * 10) + byte return real_freq / 1000.0
Then you can do this:
val1b = RadioSettingValueFloat(136, 512, convert_bytes_to_freq(self._memobj.vfoa.freq))
On the set side, you'll need to do the opposite of the above, potentially with a special-case for those two values (I forget how that code is organized). I imagine getting the "get" side working first is your priority, so we can work on that after you're happy with this.
Since you have to do this twice, I'd like you to make it a helper function, like this:
def convert_bytes_to_freq(bytes): real_freq = 0 for byte in self._memobj.vfob.freq: real_freq = (real_freq * 10) + byte return real_freq / 1000.0
I think I have it working for the 'get' side. I have a problem with the 'helper function' code. As it is written above, it is specific to 'vfob' (self._memobj.vfob.freq). Is there a simple way to make it for this one block of code work for both VFOs? Also, where is the best place to put this 'helper function'? I currently have it just above my code for the menu selection.
Jim
On 20/01/2013 01:32, Jim Unroe wrote:
Since you have to do this twice, I'd like you to make it a helper function, like this: def convert_bytes_to_freq(bytes): real_freq = 0 for byte in self._memobj.vfob.freq: real_freq = (real_freq * 10) + byte return real_freq / 1000.0
I think I have it working for the 'get' side. I have a problem with the 'helper function' code. As it is written above, it is specific to 'vfob' (self._memobj.vfob.freq). Is there a simple way to make it for this one block of code work for both VFOs? Also, where is the best place to put this 'helper function'? I currently have it just above my code for the menu selection.
Jim
It's a typo for sure :) here's the function Dan had in mind ;)
def convert_bytes_to_freq(bytes): real_freq = 0 for byte in bytes: real_freq = (real_freq * 10) + byte return real_freq / 1000.0
I think "just above the code that needs it" is a good place for it.
73 de IZ3GME Marco
It's a typo for sure :) here's the function Dan had in mind ;)
def convert_bytes_to_freq(bytes): real_freq = 0 for byte in bytes: real_freq = (real_freq * 10) + byte return real_freq / 1000.0
I think "just above the code that needs it" is a good place for it.
Thanks Marco. I should have figured that out on my own.
The driver is now reading and displaying the values from a saved image and the UV-5R. Now I just need some guidance on how to go the other way.
Thanks so much to you and Dan for all your help. Jim
It's a typo for sure :) here's the function Dan had in mind ;)
Oops, yeah, that's what I meant, thanks Marco :)
The driver is now reading and displaying the values from a saved image and the UV-5R.
Nice!
Now I just need some guidance on how to go the other way.
So, set_settings() attempts to be automatic about how it applies the settings, using the setting name to find the structure. Since you've got a special case here, I think it's okay to call it out specifically. In the big for loop, there's an if..else that handles the case where settings are nested in structs, so it looks for a "." in the name. I'd just add an "elif" in there for yours. Something like:
elif element.get_name() == "vfoa.freq": convert_freq_to_bytes(self._memobj.vfoa.freq, element.value)
with convert_freq_to_bytes() being a helper function with something like the example code I gave you in it for going the other direction. It should take two arguments for the "real_freq" and "bytes". Take a stab at writing it and let me know if you need a little more detail.
Thanks a lot for doing this Jim! How many things remain after this before CHIRP is as functional as the OEM software? Seems like you're going to run out of things to add pretty soon now! :)
Now I just need some guidance on how to go the other way.
So, set_settings() attempts to be automatic about how it applies the settings, using the setting name to find the structure. Since you've got a special case here, I think it's okay to call it out specifically. In the big for loop, there's an if..else that handles the case where
Jim, take a look to the update 817 source: I do exactly this in set_settings for a couple of settings.
73 de IZ3GME Marco
Thanks Dan and Marco. I take a look and see what I and come up with later today. Jim
On Sun, Jan 20, 2013 at 12:46 PM, Marco IZ3GME iz3gme.marco@gmail.comwrote:
Now I just need some guidance on how to go the other way.
So, set_settings() attempts to be automatic about how it applies the settings, using the setting name to find the structure. Since you've got a special case here, I think it's okay to call it out specifically. In the big for loop, there's an if..else that handles the case where
Jim, take a look to the update 817 source: I do exactly this in set_settings for a couple of settings.
73 de IZ3GME Marco _______________________________________________ chirp_devel mailing list chirp_devel@intrepid.danplanet.com http://intrepid.danplanet.com/mailman/listinfo/chirp_devel Developer docs: http://chirp.danplanet.com/projects/chirp/wiki/Developers
participants (3)
-
Dan Smith
-
Jim Unroe
-
Marco IZ3GME