Got an iPhone or iPad? We have a brand new Pastebin App for both devices, and it's totally free! Click here to download the new Pastebin App for iOS.
Guest

Untitled

By: a guest on Jan 28th, 2010  |  syntax: None  |  size: 5.78 KB  |  hits: 30  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. --- /home/markus/linux-on-qualcomm-s-msm-android-hardware/sensors/sensors.c     2010-01-21 20:17:05.000000000 +0100
  2. +++ sensors.c   2010-01-28 22:39:21.000000000 +0100
  3.  -16,7 +16,7 @@
  4.  /*
  5.   * Heavily modified by HUSSON Pierre-Hugues <phhusson@free.fr> for raphael/diamond/blac/topaz
  6.   */
  7. -
  8.  -141,14 +144,27 @@
  9.                         fd = -1;
  10.                 }
  11.         }
  12. +       closedir(dir);
  13.         if(fd==-1) {
  14. +                       LOGD("bma_open: bma150 open:");
  15.                 int status;
  16. -               char buf[5];
  17. +               char buf[5] = {0x14,0,0,0,0};
  18. +               int retries=10;
  19. +
  20.                 fd=open("/dev/bma150", O_RDONLY);
  21. -               if(fd==-1)
  22. +               if (fd < 0) {
  23. +                       LOGD("bma_open: bma150 open FAILED");
  24.                         return fd;
  25. -               buf[0]=0x14;
  26. +               }
  27.                 bma150=1;
  28. +
  29. +               status = ioctl(fd, BMA_IOCTL_INIT, buf);
  30. +               status = ioctl(fd, BMA_IOCTL_READ, buf);
  31. +               if (status < 0) {
  32. +                       LOGD("bma_open: failed to read bwidth range: %d", status);
  33. +                       return status;
  34. +               }
  35. +
  36.                 // 2G = -2G .. 2G
  37.                 // 4G = -4G .. 4G
  38.                 // 8G = -8G .. 8G
  39.  -156,18 +172,20 @@
  40.                 buf[1] = (buf[1] & 0xe7) | (BMA_RANGE_2G << 3);
  41.                 status = ioctl(fd, BMA_IOCTL_WRITE, buf);
  42.                 if (status < 0) {
  43. -                       LOGE("bma_open: failed to write bwidth range: %d", status);
  44. +                       LOGD("bma_open: failed to write bwidth range: %d", status);
  45.                         return status;
  46.                 }
  47. +               LOGD("_bma_open success, fd = %d", fd);
  48. +*/
  49. +               LOGD("bma_open: bma150 open SUCCESSFULL");
  50.         }
  51. -       closedir(dir);
  52.         return fd;
  53.  }
  54.  
  55.  int sFD=-1;
  56.  int evdev_close(struct hw_device_t *dev) {
  57.  #ifdef DEBUG
  58. -       LOGE("called evdev_close");
  59. +       LOGD("called evdev_close");
  60.  #endif
  61.         close(sFD);
  62.         sFD=-1;
  63.  -175,10 +193,11 @@
  64.  }
  65.  
  66.  native_handle_t *open_data_source(struct sensors_control_device_t *dev) {
  67. +                       LOGD("bma_open: open_data_source:");
  68.         native_handle_t *hdl=native_handle_create(1,0);
  69. -       hdl->data[0]=sFD;
  70. +       //hdl->data[0]=sFD;
  71.  #ifdef DEBUG
  72. -       LOGE("called open_data_source");
  73. +       LOGD("called open_data_source");
  74.  #endif
  75.         return hdl;
  76.  }
  77.  -196,12 +216,15 @@
  78.         enabled=!!( ( activated&(1<<SENSOR_TYPE_ACCELEROMETER)) |
  79.                         (activated&(1<<SENSOR_TYPE_ORIENTATION)));
  80.         if(bma150) {
  81. -               char buf[8];
  82. +               char buf[8] = {0, 0, 0, 0, 0, 0, 0, 0};;
  83.                 int status;
  84.                 int mode;
  85.                 int retries=20;
  86. -               if (enabled)
  87. +              
  88. +               if (enabled) {
  89.                         mode = BMA_MODE_NORMAL;
  90. +                       LOGD("bma_open: enabled");
  91. +               }
  92.                 else
  93.                         mode = BMA_MODE_SLEEP;
  94.                 buf[0] = mode;
  95.  
  96.  -315,18 +343,19 @@
  97.  double oldx=0,oldy=0,oldz=0,rawx=0,rawy=0,rawz=0;
  98.  int state=0;
  99.  int data_poll(struct sensors_data_device_t *dev, sensors_data_t* data) {
  100. +                       LOGD("bma_open: data_poll ");
  101.         struct input_event event;
  102.         int ret;
  103.         double value;
  104.         double dat[3];
  105.  #ifdef DEBUG
  106. -       LOGE("called data poll");
  107. +       LOGD("called data poll");
  108.  #endif
  109.         data->time=time(NULL)*1000*1000*1000;
  110.  
  111.         if(state==1) {
  112.  #ifdef DEBUG
  113. -               LOGE("Got accel data, send orientation");
  114. +               LOGD("Got accel data, send orientation");
  115.  #endif
  116.                 state=2;
  117.                 data->sensor=SENSOR_TYPE_ORIENTATION;
  118.  -342,17 +371,17 @@
  119.                 data->orientation.pitch=-data->orientation.pitch;
  120.                 data->orientation.roll=asin(oldx/value)*180.0/3.14159;
  121.  #ifdef DEBUG
  122. -               LOGE("Returing orientation %f,%f,%f\n", data->acceleration.x, data->acceleration.y, data->acceleration.z);
  123. +               LOGD("Returing orientation %f,%f,%f\n", data->acceleration.x, data->acceleration.y, data->acceleration.z);
  124.  #endif
  125.                 return SENSOR_TYPE_ORIENTATION;
  126.         } else if(state==2) {
  127.  #ifdef DEBUG
  128. -               LOGE("Sent orientation, send light");
  129. +               LOGD("Sent orientation, send light");
  130.  #endif
  131.                 state=3;
  132.                 value=read_light();
  133.                 if(value<0) {
  134. -                       LOGE("Or not...");
  135. +                       LOGD("Or not...");
  136.                         return data_poll(dev, data);
  137.                 }
  138.                 data->sensor=SENSOR_TYPE_LIGHT;
  139.  -360,12 +389,12 @@
  140.                 return SENSOR_TYPE_LIGHT;
  141.         } else if(state==3) {
  142.  #ifdef DEBUG
  143. -               LOGE("Sent light, send proximity");
  144. +               LOGD("Sent light, send proximity");
  145.  #endif
  146.                 state=0;
  147.                 value=read_prox();
  148.                 if(value<0) {
  149. -                       LOGE("Or not...");
  150. +                       LOGD("Or not...");
  151.                         return data_poll(dev, data);
  152.                 }
  153.                 data->sensor=SENSOR_TYPE_PROXIMITY;
  154.  -387,9 +416,21 @@
  155.                         status = ioctl(sFD, BMA_IOCTL_READ_ACCELERATION, accel);
  156.                 } while( status < 0 && retries-- > 0 );
  157.  
  158. +               if (status < 0) {
  159. +                       LOGD("Error polling for data after %d retries: %d, fd=%d", retries, status, sFD);
  160. +               PR_LN();
  161. +                       return -1;
  162. +               } else {
  163. +                       LOGD("bma_open: BUFFER: %d:%d:%d", accel[0], accel[1], accel[2]);
  164. +               }
  165. +
  166. +
  167.                 dat[0]=accel[0]*gFactor;
  168.                 dat[1]=accel[1]*gFactor;
  169.                 dat[2]=accel[2]*gFactor;
  170. +#ifdef DEBUG
  171. +               LOGD("Got raw data: %f %f %f", dat[0], dat[1], dat[2]);
  172. +#endif
  173.  
  174.         } else {
  175.                 int got=0;
  176.  -427,26 +468,30 @@
  177.                 dat[1]=rawy/MS2;
  178.                 dat[2]=rawz/MS2;
  179.         }
  180. +       LOGD("Axis Order  %d,%d,%d\n", axis_order[0], axis_order[1], axis_order[2]);
  181.  
  182.         oldx=(axis_order[0]>0) ? dat[axis_order[0]-1] : -dat[-axis_order[0]-1];
  183.         oldy=(axis_order[1]>0) ? dat[axis_order[1]-1] : -dat[-axis_order[1]-1];
  184.         oldz=(axis_order[2]>0) ? dat[axis_order[2]-1] : -dat[-axis_order[2]-1];
  185. -       data->acceleration.x=oldx;
  186. -       data->acceleration.y=oldy;
  187. -       data->acceleration.z=oldz;
  188. +//     data->acceleration.x=oldx;
  189. +//     data->acceleration.y=oldy;
  190. +//     data->acceleration.z=oldz;
  191. +       data->acceleration.x=dat[0];
  192. +       data->acceleration.y=dat[1];
  193. +       data->acceleration.z=dat[2];
  194.  #ifdef DEBUG
  195. -       LOGE("Returing %f,%f,%f\n", data->acceleration.x, data->acceleration.y, data->acceleration.z);
  196. +       LOGD("Returing %f,%f,%f\n", data->acceleration.x, data->acceleration.y, data->acceleration.z);
  197.  #endif
  198.         return SENSOR_TYPE_ACCELEROMETER;
  199.  }
  200.  
  201.  int evdev_open(const struct hw_module_t* module, const char* id, struct hw_device_t** device) {
  202.  #ifdef DEBUG
  203. -       LOGE("evdev_open");
  204. +       LOGD("evdev_open");
  205.  #endif
  206.         if(strcmp(id, SENSORS_HARDWARE_CONTROL)==0) {
  207.  #ifdef DEBUG
  208. -               LOGE("evdev_open hw ctl");
  209. +               LOGD("evdev_open hw ctl");
  210.  #endif
  211.                 struct sensors_control_device_t *dev;
  212.                 *device=malloc(sizeof(struct sensors_control_device_t));