bewest / decoding-carelink

python serial driver for mm comlink2 protocol
http://bewest.github.io/decoding-carelink
Other
71 stars 52 forks source link

Floating point accuracy fix in set_temp_basal #198

Open cjo20 opened 8 years ago

cjo20 commented 8 years ago

Basal rates weren't being set correctly in the pump (e.g. 0.6u/hr was being set as 0.575u/hr)

if rate = 0.6:

>>> int(0.6/0.025)
23
>>> 0.6/0.025
23.999999999999996

If the user is trying to set a basal rate that the pump can support, this should always result in better behaviour than the current code. oref0 dev should only try to set supported rates.

If users try to set basal rates not supported by the pump, it could end up setting a rate up to 0.0125u/hr more than they requested.

scottleibrand commented 8 years ago

Can you PR this against the openaps/decocare repo as well? Not sure which branch, but that same file is at https://github.com/openaps/decocare/blob/master/decocare/commands.py#L296 in master.

cjo20 commented 8 years ago

Done here: https://github.com/openaps/decocare/pull/2

scottleibrand commented 8 years ago

Merged openaps/decocare#2 and tested. Confirmed it allows setting a 0.6U/hr temp, whereas without this fix it ended up at 0.575U/hr. 👍 for merge

scottleibrand commented 8 years ago

Per https://github.com/openaps/decocare/pull/1 it looks like this branch is no longer used by openaps, so it's up to @bewest whether he wants to try to keep it in sync with openaps/decocare or not.