accel: Fix accelerometer unit confusion
The original orientation code was based upon code that expected 1G to roughly correspond to a reading of 256, to work-around the fact that the input layer could not pass fractional values easily. So the orientation_calc() code expected that too. But IIO readings after scaling are properly in m/s², and our readings are integers. We'll pass the scaling around to be applied at the last minute, when doing calculations. Closes: #100
This commit is contained in:
@@ -56,12 +56,23 @@ string_to_orientation (const char *orientation)
|
||||
#define THRESHOLD_LANDSCAPE 35
|
||||
#define THRESHOLD_PORTRAIT 35
|
||||
|
||||
/* First apply scale to get m/s², then
|
||||
* convert to 1G ~= 256 as the code expects */
|
||||
#define SCALE(a) ((int) ((gdouble) a * scale * 256.0 / 9.81))
|
||||
|
||||
OrientationUp
|
||||
orientation_calc (OrientationUp prev,
|
||||
int x, int y, int z)
|
||||
int in_x, int in_y, int in_z,
|
||||
gdouble scale)
|
||||
{
|
||||
int rotation;
|
||||
OrientationUp ret = prev;
|
||||
int x, y, z;
|
||||
|
||||
/* this code expects 1G ~= 256 */
|
||||
x = SCALE(in_x);
|
||||
y = SCALE(in_y);
|
||||
z = SCALE(in_z);
|
||||
|
||||
/* Portrait check */
|
||||
rotation = round(atan((double) x / sqrt(y * y + z * z)) * RADIANS_TO_DEGREES);
|
||||
|
Reference in New Issue
Block a user