29 int lis3dh_limitangle(
int angle) {
31 if (angle < -90) {
return -90; }
32 if (angle > 90) {
return 90; }
39 int lis3dh_scaleresult(
int value) {
44 r = value - (i * 100);
46 return (r > 49) ? ++i : i;
55 int avg_factor = device->tiltavg_factor;
62 if ((avg_factor > 0) && (avg_factor < 100)) {
64 x = lis3dh_scaleresult((
x * avg_factor) + (device->tiltavgX * (100 - avg_factor )));
65 y = lis3dh_scaleresult((y * avg_factor) + (device->tiltavgY * (100 - avg_factor )));
66 z = lis3dh_scaleresult((z * avg_factor) + (device->tiltavgZ * (100 - avg_factor )));
81 float y_radians = atan(((
float)y/(sqrt(
x*
x + z*z))));
82 float x_radians = atan(((
float)
x/(sqrt(y*y + z*z))));
83 float z_radians = atan((sqrt(
x*
x + y*y) / z));
88 *ay = lis3dh_limitangle( (
int) (y_radians * 57.3) );
89 *ax = lis3dh_limitangle( (
int) (x_radians * 57.3) );
90 *az = lis3dh_limitangle( (
int) (z_radians * 57.3) );
93 *motion = (int) (sqrt(
x*
x + y*y + z*z)) - 1000;
108 if ((avg_factor < 0) || (avg_factor > 100))
114 device->tiltavg_factor = avg_factor;