Commit f1f9969a27032bc0ff45439b459716fa646acbe0

Add a cmdline option to change axis: gsensor_axis=x,y,z where x, y, z are number in {-3,-2,-1,1,2,3}:
1,2,3 stands for reported x,y,z axis, and -1,-2,-3 for the opposite of this axis.
Default option is 1,-2,3 for diam/raph and -1,-2,3 for blac
  
4949//#define DEBUG
5050
5151char phys[20];
52 int open_input()
53{
52char axis_order[3];
53
54void parse_axis_order() {
55 int fd=open("/proc/cmdline", O_RDONLY);
56 char buf[1024];
57 char *ptr,*ptr2;
58 int i;
59 buf[1023]=0;
60 if(fd<0)
61 return;
62 if(read(fd, buf, 1023)<0) {
63 close(fd);
64 return;
65 }
66 ptr=strstr(buf, "gsensor_axis=");
67 if(!ptr)
68 return;
69 if(ptr!=buf)
70 if(ptr[-1]!=' ')
71 return;
72 ptr+=strlen("gesnsor_axis=");
73
74 for(i=0;i<3;++i) {
75 ptr2=index(ptr, ',');
76 if(!ptr2)
77 ptr2=index(ptr, ' ');
78 if(ptr2)
79 *ptr2=0;
80 axis_order[i]=atoi(ptr);
81 ptr=ptr2+1;
82 }
83}
84
85int open_input() {
5486 /* scan all input drivers and look for "kionix-ksd9" */
5587 int fd = -1;
5688 const char *dirname = "/dev/input";
111111 if (!strcmp(name, "kionix-kxsd9")) {
112112 bzero(phys, 20);
113113 ioctl(fd, EVIOCGPHYS(sizeof(phys)-1), &phys);
114 if(strcmp(phys, "i2c/0-0019")==0) {
115 axis_order[0]=-1;
116 axis_order[1]=-2;
117 axis_order[2]=3;
118 } else {
119 axis_order[0]=1;
120 axis_order[1]=-2;
121 axis_order[2]=3;
122 }
123 parse_axis_order();
114124
125
115126 LOGD("using %s (name=%s,phys=%s)", devname, name, phys);
116127 break;
117128 }
287287 break;
288288 };
289289 }
290 double dat[3];
291 dat[0]=oldx/MS2;
292 dat[1]=oldy/MS2;
293 dat[2]=oldz/MS2;
294
295 data->acceleration.x=(axis_order[0]>0) ? dat[axis_order[0]] : -dat[-axis_order[0]];
296 data->acceleration.y=(axis_order[1]>0) ? dat[axis_order[1]] : -dat[-axis_order[1]];
297 data->acceleration.z=(axis_order[2]>0) ? dat[axis_order[2]] : -dat[-axis_order[2]];
298
290299 //It seems blackstone's accelerometer is upside down.
291300 if(strcmp(phys, "i2c/0-0019")==0) {
292301 data->acceleration.x=-oldx/MS2;