2 * Copyright (C) 2003 Robert Kooima
4 * NEVERBALL is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
15 #define _ISOC99_SOURCE
19 #define M_PI 3.14159265358979323846
20 #define ACCEL_FILENAME "/sys/class/i2c-adapter/i2c-3/3-001d/coord"
22 static struct _accel {
40 static int has_read = 0;
42 fd = fopen(ACCEL_FILENAME, "r");
45 i = fscanf(fd, "%i %i %i", &ax, &ay, &az);
50 /* Combine with previous reading */
53 accel.x = ax * 0.2f + accel.x * 0.8f;
54 accel.y = ay * 0.2f + accel.y * 0.8f;
55 accel.z = az * 0.2f + accel.z * 0.8f;
65 return i == 3 ? 1 : 0;
68 int tilt_get_button(int *b, int *s)
73 float tilt_get_x(void)
75 return atan2f(accel.y, -accel.z) * 180.0f / M_PI;
78 float tilt_get_z(void)
80 return atan2f(-accel.x, -accel.z) * 180.0f / M_PI;