Hi,
If I use the enclosed python code to test g-sensor on gta02 (read
/dev/input/event3) while holding the neo vertically, normally the
result looks like this:
x = -72, y = -990, t = 1.976891 pi
x = -72, y = -990, t = 1.976891 pi
x = -54, y = -990, t = 1.982655 pi
x = -72, y = -990, t = 1.976891 pi
x = -72, y = -990, t = 1.976891 pi
It's quite reasonable. However,
* sometimes after booting
* always after resume (apm -s)
the result will look like this:
x = 1620, y = -36, t = 0.492928 pi
x = 1620, y = -18, t = 0.496463 pi
x = 1620, y = -36, t = 0.492928 pi
x = 1620, y = -36, t = 0.492928 pi
x = 1620, y = -36, t = 0.492928 pi
I wonder what's the cause? Any more information I could provide?
Regards,
John
from struct import unpack_from
import time
import math
# shamelessly stole from olv
"get the angle related to (0, -1). return 0 < theta < 2pi"
def get_xy_theta(u):
uu = u[0] * u[0] + u[1] * u[1]
theta = math.acos(-u[1] / math.sqrt(uu))
if (u[0] < 0):
theta = 2 * math.pi - theta
return theta
# Read the accelerometer and unpack values
def get_xy():
x, y = 0, 0
while x == 0 or y == 0:
block = f.read(16)
if block[8] == "\x02":
if block[10] == "\x00":
x = unpack_from( "@l", block[12:] )[0]
if block[10] == "\x01":
y = unpack_from( "@l", block[12:] )[0]
# shamelessly stole from olv
#fx = (x - y) / 1.1415926
#fy = (x + y) / 1.1415926
fx = x
fy = y
return (fx, fy)
try:
f = open("/dev/input/event3", "rb", 0)
except IOError:
# give a fake one
get_xy = lambda: (0, -980)
if __name__ == "__main__":
while True:
p = get_xy()
t = get_xy_theta(p)
print "x = %d, y = %d, t = %f pi" % (p[0], p[1], t/math.pi)
time.sleep(0.1)