23 #define READ_SIZE sizeof(gsensor_accel_t)
24 #define DEV_PATH "/dev/gsensor"
26 int getXYZ(gsensor_accel_t
*bufData
)
30 memset(bufData
, 0, READ_SIZE
);
31 fd
= open(DEV_PATH
, O_RDONLY
);
34 printf("open ##DEV_PATH failed!\n");
37 i
= read(fd
, bufData
, READ_SIZE
);
40 i
= READ_SIZE
; /*See the programmer's manual*/
41 printf("Read %d bytes from DEV_PATH, Intended size is %d\n", i
, READ_SIZE
);
42 printf("x = %d\n" , bufData
->x
);
43 printf("y = %d\n" , bufData
->y
);
44 printf("z = %d\n" , bufData
->z
);
45 printf("g = %d\n" , bufData
->x
*bufData
->x
+ bufData
->y
*bufData
->y
+ bufData
->z
*bufData
->z
);
53 enum DIRECTION
isDirection(int x
, int y
, int z
)
55 if((x
*x
+ y
*y
< 32) && z
*z
> 225)
63 if((x
*x
+ z
*z
< 32) && y
*y
> 225)
71 if((y
*y
+ z
*z
< 32) && x
*x
> 225)
82 int waitDirection(enum DIRECTION tempDir
, int max_Time
)
84 gsensor_accel_t tempData
;
86 for(i
= 0; i
< max_Time
; i
++)
89 if(isDirection(tempData
.x
, tempData
.y
, tempData
.z
) == tempDir
)
100 printf("*******************************************\n");
101 printf("** gsensor DIRECTION **\n");
102 printf("** DIRECTION: up down **\n");
103 printf("** left right **\n");
104 printf("** front back **\n");
105 printf("*******************************************\n");
108 int main(int argc
, char *argv
[]){
110 unsigned int foundDir
;
111 unsigned char *dirChar
[DIRECTION_MAX
]={
126 for(i
= 0; i
< DIRECTION_MAX
; i
++)
128 if(!strcmp(dirChar
[i
], argv
[1]))
131 foundDir
= waitDirection((enum DIRECTION
)i
, 200);
133 printf("Direction Detected!\n");
135 printf("Time out occured! please check!\n");