- --- /home/markus/linux-on-qualcomm-s-msm-android-hardware/sensors/sensors.c 2010-01-21 20:17:05.000000000 +0100
- +++ sensors.c 2010-01-28 22:39:21.000000000 +0100
- -16,7 +16,7 @@
- /*
- * Heavily modified by HUSSON Pierre-Hugues <phhusson@free.fr> for raphael/diamond/blac/topaz
- */
- -
- -141,14 +144,27 @@
- fd = -1;
- }
- }
- + closedir(dir);
- if(fd==-1) {
- + LOGD("bma_open: bma150 open:");
- int status;
- - char buf[5];
- + char buf[5] = {0x14,0,0,0,0};
- + int retries=10;
- +
- fd=open("/dev/bma150", O_RDONLY);
- - if(fd==-1)
- + if (fd < 0) {
- + LOGD("bma_open: bma150 open FAILED");
- return fd;
- - buf[0]=0x14;
- + }
- bma150=1;
- +
- + status = ioctl(fd, BMA_IOCTL_INIT, buf);
- + status = ioctl(fd, BMA_IOCTL_READ, buf);
- + if (status < 0) {
- + LOGD("bma_open: failed to read bwidth range: %d", status);
- + return status;
- + }
- +
- // 2G = -2G .. 2G
- // 4G = -4G .. 4G
- // 8G = -8G .. 8G
- -156,18 +172,20 @@
- buf[1] = (buf[1] & 0xe7) | (BMA_RANGE_2G << 3);
- status = ioctl(fd, BMA_IOCTL_WRITE, buf);
- if (status < 0) {
- - LOGE("bma_open: failed to write bwidth range: %d", status);
- + LOGD("bma_open: failed to write bwidth range: %d", status);
- return status;
- }
- + LOGD("_bma_open success, fd = %d", fd);
- +*/
- + LOGD("bma_open: bma150 open SUCCESSFULL");
- }
- - closedir(dir);
- return fd;
- }
- int sFD=-1;
- int evdev_close(struct hw_device_t *dev) {
- #ifdef DEBUG
- - LOGE("called evdev_close");
- + LOGD("called evdev_close");
- #endif
- close(sFD);
- sFD=-1;
- -175,10 +193,11 @@
- }
- native_handle_t *open_data_source(struct sensors_control_device_t *dev) {
- + LOGD("bma_open: open_data_source:");
- native_handle_t *hdl=native_handle_create(1,0);
- - hdl->data[0]=sFD;
- + //hdl->data[0]=sFD;
- #ifdef DEBUG
- - LOGE("called open_data_source");
- + LOGD("called open_data_source");
- #endif
- return hdl;
- }
- -196,12 +216,15 @@
- enabled=!!( ( activated&(1<<SENSOR_TYPE_ACCELEROMETER)) |
- (activated&(1<<SENSOR_TYPE_ORIENTATION)));
- if(bma150) {
- - char buf[8];
- + char buf[8] = {0, 0, 0, 0, 0, 0, 0, 0};;
- int status;
- int mode;
- int retries=20;
- - if (enabled)
- +
- + if (enabled) {
- mode = BMA_MODE_NORMAL;
- + LOGD("bma_open: enabled");
- + }
- else
- mode = BMA_MODE_SLEEP;
- buf[0] = mode;
- -315,18 +343,19 @@
- double oldx=0,oldy=0,oldz=0,rawx=0,rawy=0,rawz=0;
- int state=0;
- int data_poll(struct sensors_data_device_t *dev, sensors_data_t* data) {
- + LOGD("bma_open: data_poll ");
- struct input_event event;
- int ret;
- double value;
- double dat[3];
- #ifdef DEBUG
- - LOGE("called data poll");
- + LOGD("called data poll");
- #endif
- data->time=time(NULL)*1000*1000*1000;
- if(state==1) {
- #ifdef DEBUG
- - LOGE("Got accel data, send orientation");
- + LOGD("Got accel data, send orientation");
- #endif
- state=2;
- data->sensor=SENSOR_TYPE_ORIENTATION;
- -342,17 +371,17 @@
- data->orientation.pitch=-data->orientation.pitch;
- data->orientation.roll=asin(oldx/value)*180.0/3.14159;
- #ifdef DEBUG
- - LOGE("Returing orientation %f,%f,%f\n", data->acceleration.x, data->acceleration.y, data->acceleration.z);
- + LOGD("Returing orientation %f,%f,%f\n", data->acceleration.x, data->acceleration.y, data->acceleration.z);
- #endif
- return SENSOR_TYPE_ORIENTATION;
- } else if(state==2) {
- #ifdef DEBUG
- - LOGE("Sent orientation, send light");
- + LOGD("Sent orientation, send light");
- #endif
- state=3;
- value=read_light();
- if(value<0) {
- - LOGE("Or not...");
- + LOGD("Or not...");
- return data_poll(dev, data);
- }
- data->sensor=SENSOR_TYPE_LIGHT;
- -360,12 +389,12 @@
- return SENSOR_TYPE_LIGHT;
- } else if(state==3) {
- #ifdef DEBUG
- - LOGE("Sent light, send proximity");
- + LOGD("Sent light, send proximity");
- #endif
- state=0;
- value=read_prox();
- if(value<0) {
- - LOGE("Or not...");
- + LOGD("Or not...");
- return data_poll(dev, data);
- }
- data->sensor=SENSOR_TYPE_PROXIMITY;
- -387,9 +416,21 @@
- status = ioctl(sFD, BMA_IOCTL_READ_ACCELERATION, accel);
- } while( status < 0 && retries-- > 0 );
- + if (status < 0) {
- + LOGD("Error polling for data after %d retries: %d, fd=%d", retries, status, sFD);
- + PR_LN();
- + return -1;
- + } else {
- + LOGD("bma_open: BUFFER: %d:%d:%d", accel[0], accel[1], accel[2]);
- + }
- +
- +
- dat[0]=accel[0]*gFactor;
- dat[1]=accel[1]*gFactor;
- dat[2]=accel[2]*gFactor;
- +#ifdef DEBUG
- + LOGD("Got raw data: %f %f %f", dat[0], dat[1], dat[2]);
- +#endif
- } else {
- int got=0;
- -427,26 +468,30 @@
- dat[1]=rawy/MS2;
- dat[2]=rawz/MS2;
- }
- + LOGD("Axis Order %d,%d,%d\n", axis_order[0], axis_order[1], axis_order[2]);
- oldx=(axis_order[0]>0) ? dat[axis_order[0]-1] : -dat[-axis_order[0]-1];
- oldy=(axis_order[1]>0) ? dat[axis_order[1]-1] : -dat[-axis_order[1]-1];
- oldz=(axis_order[2]>0) ? dat[axis_order[2]-1] : -dat[-axis_order[2]-1];
- - data->acceleration.x=oldx;
- - data->acceleration.y=oldy;
- - data->acceleration.z=oldz;
- +// data->acceleration.x=oldx;
- +// data->acceleration.y=oldy;
- +// data->acceleration.z=oldz;
- + data->acceleration.x=dat[0];
- + data->acceleration.y=dat[1];
- + data->acceleration.z=dat[2];
- #ifdef DEBUG
- - LOGE("Returing %f,%f,%f\n", data->acceleration.x, data->acceleration.y, data->acceleration.z);
- + LOGD("Returing %f,%f,%f\n", data->acceleration.x, data->acceleration.y, data->acceleration.z);
- #endif
- return SENSOR_TYPE_ACCELEROMETER;
- }
- int evdev_open(const struct hw_module_t* module, const char* id, struct hw_device_t** device) {
- #ifdef DEBUG
- - LOGE("evdev_open");
- + LOGD("evdev_open");
- #endif
- if(strcmp(id, SENSORS_HARDWARE_CONTROL)==0) {
- #ifdef DEBUG
- - LOGE("evdev_open hw ctl");
- + LOGD("evdev_open hw ctl");
- #endif
- struct sensors_control_device_t *dev;
- *device=malloc(sizeof(struct sensors_control_device_t));