Hey everyone!
I'm quite new to Rust, so be kind if my question sounds a bit weird! So, currently i am building a weather station with an Raspberry Pi.
To do temp and RH measurements i use the AM2302 Sensor. I have written a small driver in Rust for this Sensor, but i'm not quite satisfied.
During the measurements i collect the response values from the Sensor and push those into a vector. The resulting Slice may be look like that:
['0','0','0','1','1','0', .... ] and so on.
Then i do the conversion like this:
let rh_high = isize::from_str_radix(&bin[RH_HIGH], 2).unwrap();
let rh_low = isize::from_str_radix(&bin[RH_LOW], 2).unwrap();
let t_high = isize::from_str_radix(&bin[T_HIGH], 2).unwrap();
// and so on...
So, the bits are stored as chars, then i convert the String into isize and so on. Okay, it works, the values are correct. But it seems a little bit weird - is there any "better" method, to convert a Vector of Bits into a floating point number?
The Sensor works like that: '1' Values are held about 70usec, '0' are held about 30usec , so you have to wait for every information and store it - currently they get pushed into a vec. May be we can optimize this, also?
Thanks in advance!