/** write byte to SMB380 EEPROM
   \param addr address to write to (image addresses are automatically extended to EEPROM space)
   \param data byte content to write 
   \return result of bus communication function
*/
int smb380_write_ee(unsigned char addr, unsigned char data) 
{	
	int comres;
	if (p_smb380==0) 			/* check pointers */
		return E_SMB_NULL_PTR;
    if (p_smb380->delay_msec == 0)
	    return E_SMB_NULL_PTR;
    comres = smb380_set_ee_w( SMB380_EE_W_ON );
	addr|=0x20;   /* add eeprom address offset to image address if not applied */
	comres += smb380_write_reg(addr, &data, 1 );
	p_smb380->delay_msec( SMB380_EE_W_DELAY );
	comres += smb380_set_ee_w( SMB380_EE_W_OFF);
	return comres;
}
Beispiel #2
0
int smb380_write_ee(unsigned char addr, unsigned char data) 
{	
	int comres;
	if (p_smb380==0) 			
		return E_SMB_NULL_PTR;
    if (p_smb380->delay_msec == 0)
	    return E_SMB_NULL_PTR;
    comres = smb380_set_ee_w( SMB380_EE_W_ON );
	addr|=0x20;   
	comres += smb380_write_reg(addr, &data, 1 );
	p_smb380->delay_msec( SMB380_EE_W_DELAY );
	comres += smb380_set_ee_w( SMB380_EE_W_OFF);
	return comres;
}
Beispiel #3
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;
}