[chirp_devel] def convert_freq_to_bytes(real_freq):
IZ3GME Marco
Fri Jan 25 03:48:21 PST 2013
If you want the parameter to be different than the default you simply
have to specify it (eg. add precision=5 at object creation)
For vfob try this
val1b = RadioSettingValueFloat(136, 512,
convert_bytes_to_freq(self._memobj.vfob.freq), precision=5)
73 de IZ3GME Marco
On 25/01/2013 12:28, Jim Unroe wrote:
>
>
> On Fri, Jan 25, 2013 at 4:13 AM, IZ3GME Marco <iz3gme.marco at gmail.com
> <mailto:iz3gme.marco at gmail.com>> wrote:
>
> It's a rounding problem due to the internal representation of float.
>
> I tried the following version of convert_freq_to_bytes which seems to
> works but may be Dan or some other python expert have a better solution.
>
> def convert_freq_to_bytes(freq):
> bytes = [ 0 for x in range(0,8) ] # init list with 8
> times 0
> real_freq = "%3.5f" % freq # now is a string
> real_freq = int(real_freq[0:3]+ real_freq[4:])
> # and now an int
> 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
>
> 73 de IZ3GME Marco
>
> I still get 146.63999 out for 146.64000 in.
>
> In settings.py, I had changed 'precision=4' to 'precision=5'
>
> class RadioSettingValueFloat(RadioSettingValue):
> """A floating-point setting"""
> def __init__(self, minval, maxval, current, resolution=0.001,
> precision=4):
>
> The reason I did this was to get 5 places past the decimal. Maybe that
> was the wrong way to accomplish that. Anyway, I changed back to
> 'precision=4' and now the result is 146.6400, which is better than
> 146.63999, but still not exactly what I am looking for.
>
> Thanks again. You help and guidance is greatly appreciated.
> Jim KC9HI
>
>
>
>
> _______________________________________________
> chirp_devel mailing list
> chirp_devel at intrepid.danplanet.com
> http://intrepid.danplanet.com/mailman/listinfo/chirp_devel
> Developer docs: http://chirp.danplanet.com/projects/chirp/wiki/Developers
>
More information about the chirp_devel
mailing list