Closed paweljasinski closed 6 years ago
How about new set of specialized read functions.
read_float
- returns mV float and raw, in case of int build - error
read_raw
- returns only raw
read_int
- returns sign (-1,0,1), mV, uV and raw - this would be to mimic the existing one,
but read_int
could return just int32_t uV and raw
Not sure what's the best solution, but I would avoid specialized read functions to keep the API lean. Maybe something like
read()
returns V, V_dec, raw and sign
nil
on float and (-1,1) on intThe application can then adapt according to the value of sign:
if sign then
-- int build
print(string.format("%s%d.%03d", sign > 0 and "+" or "-", V, V_dec))
else
-- float build
-- just use V as it is
end
Guess we have the same issue with the ds18b20 module - missing sign between 0⁰C and -1⁰C?
I have some of ds18b20 around. I can test it as well. If ds is also affected, should I create separate issue for ds, or can I piggybag here?
should I create separate issue for ds, or can I piggybag here?
I'd vote for a separate issue.
Expected behavior
This is the case for integer build only Positive and negative values derived from volt and volt_dec in the range -1mV .. +1mV should be different for different polarization.
Actual behavior
As the voltage raises above the -1mV, the volt is 0 and volt_dec is positive.
raising about -1 mV
volt volt_dec dac -1 93 65466 -1 46 65469 0 984 65473 0 937 65476 0 875 65480
crossing zero
volt volt_dec dac 0 31 65534 0 15 65535 0 0 0 0 15 1 0 31 2
Workaround
Look at the dac value and correct the sign. or Do yourself the dac conversion. or Use floating build
Test code
NodeMCU version
dev branch, bee404c35890bbbcb4dd158991adb25621337a50
Hardware
wemos D1 with ads1015 (max gain, differential between in0 and in1, address pin grounded, 3.3V power).