Example #1
0
static int bma150_accl_set_mode(void)
{
	int ret = 0;
	struct drv_data *dd;
	dd = i2c_get_clientdata(bma150_accl_client);

	switch (dd->bma150_accl_mode) {
	case SENSOR_DELAY_FASTEST:
		/* BMA150 mode set to FASTEST (max sensitivity) */
	case SENSOR_DELAY_GAME:
		/* BMA150 mode set to GAME */
		ret = smb380_set_any_motion_count(1);
		if (ret < 0)
			return ret;
		ret = smb380_set_bandwidth(5);
		if (ret < 0)
			return ret;
		break;

	case SENSOR_DELAY_NORMAL:
		/* BMA150 mode set to NORMAL */
	case SENSOR_DELAY_UI:
		/* BMA150 mode set to UI */
	default:
		ret = smb380_set_any_motion_count(2);
		if (ret < 0)
			return ret;
		ret = smb380_set_bandwidth(3);
		if (ret < 0)
			return ret;
		break;
	}

	return 0;
}
Example #2
0
int smb380_calibrate(smb380acc_t orientation, int *tries)
{

	unsigned short offset_x, offset_y, offset_z;
	unsigned short old_offset_x, old_offset_y, old_offset_z;
	int need_calibration=0, min_max_ok=0;	
	int ltries;

	smb380acc_t min,max,avg;

	smb380_set_range(SMB380_RANGE_2G);
	smb380_set_bandwidth(SMB380_BW_25HZ);

	smb380_set_ee_w(1);  
	
	smb380_get_offset(0, &offset_x);
	smb380_get_offset(1, &offset_y);
	smb380_get_offset(2, &offset_z);

	old_offset_x = offset_x;
	old_offset_y = offset_y;
	old_offset_z = offset_z;
	ltries = *tries;

	do {

		smb380_read_accel_avg(10, &min, &max, &avg);  /* read acceleration data min, max, avg */

		min_max_ok = smb380_verify_min_max(min, max, avg);

		/* check if calibration is needed */
		if (min_max_ok)
			need_calibration = smb380_calc_new_offset(orientation, avg, &offset_x, &offset_y, &offset_z);		
		  
		if (*tries==0) /*number of maximum tries reached? */
			break;

		if (need_calibration) {   
			/* when needed calibration is updated in image */
			(*tries)--;
			smb380_set_offset(0, offset_x); 
   		 	smb380_set_offset(1, offset_y);
 	  	 	smb380_set_offset(2, offset_z);
			smb380_pause(20);
   		}
    } while (need_calibration || !min_max_ok);

	        		
    if (*tries>0 && *tries < ltries) {

		if (old_offset_x!= offset_x) 
			smb380_set_offset_eeprom(0, offset_x);

		if (old_offset_y!= offset_y) 
	   		smb380_set_offset_eeprom(1,offset_y);

		if (old_offset_z!= offset_z) 
	   		smb380_set_offset_eeprom(2, offset_z);
	}	
		
	smb380_set_ee_w(0);	    
    smb380_pause(20);
	*tries = ltries - *tries;

	return !need_calibration;
}