Open eringerli opened 2 years ago
these functions should take a value and return a value, or take in a pointer to 3 floats and do the conversion?
I thought, as these two methods are protected
, they can access the data directly. As virtual
methods can't be inlined, I took the most efficient way by doing the conversion in place, without using 6 (+6 in the most used way of accessing/converting temp&acc&gyro) references in code that gets called potentionally thousands of times a second.
I can do it, if you really want to, but I hope I wouldn't have to.
so duplicated code (the whole _read() method) can be removed.
Don't the other derived classes still need _read()
from the LSM6DS
base class?
The only class which reimpmement it is LSM6DSO32, because it has extended ranges. As the conversion is done in two virtual
methods (first commit), I reimplemented the one which is actually different anew. _read()
is exactly the same for all the chips in this lib, this could even be made non-virtual
.
Oh, sry, was reading the code diff wrong. The _read
was removed from the derived class Adafruit_LSM6DSO32
. Not the base class.
OK, this looks like some nice code clean up.
Did you test these changes?
TBH, I don't own an LSM6DSO32. But after I worked on PR #34, the dedup was obvious.
@caternuson It is almost three weeks later. Are there any changes I have to implement?
Sorry. Wanted to find a time to test this on hardware. Went ahead and set something up for testing.
Looks like something isn't quite correct somewhere.
Running the adafruit_lsm6dso32_test.ino example on an Itsy M4 (PID 3800) with a LSM6DSO32 breakout (PID 4692) with current library produces expected output (accelo held flat on table):
With PR code, readings are off:
Looks like maybe a factor of 2 somewhere?
I have found the error: getAccelRange()
and setAccelRange()
are not used in _read()
in this branch. I suggest testing PR #34, there the ranges should be correct. I can close this and add the description to #34 if you like.
@eringerli can you amend this PR so it is complete and working? alternatively, can reduce this PR - each PR should be independant so it can be tested/reverted as needed.
added methods for converting the raw values to the ones in SI units
This change moves the code for the conversion of raw values to their own virtual methods. This enables the next commit:
LSM6DSO32: removed a lot of duplicated code
With dedicated converter methods, the LSM6DSO32 can do its conversion for the bigger ranges there, so duplicated code (the whole
_read()
method) can be removed. Also,getAccelRange()
andsetAccelRange()
are exactly the same as in the base class, the difference is only theenum
type. Replaced these methods with a call to the base class with the casted range.