static long gsensor_dev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
	int temp;
	int ret[2];
	
	switch(cmd)
	{
	case GSENSOR_IOCTL_G_X:
		if(is_data_ready() == 0)
		{
			//printk("gsensor not ready!\n");
			return -EAGAIN;
		}
		temp = mxc6225XU_read(CMD_RD_X);
		//temp = 1;
		if(copy_to_user((void __user *)arg,&temp,sizeof(int)))
			return -EFAULT;
		break;

	case GSENSOR_IOCTL_G_Y:
		if(is_data_ready() == 0)
		{
			//printk("gsensor not ready!\n");
			return -EAGAIN;
		}
		temp = mxc6225XU_read(CMD_RD_Y);  
		//temp = 2;
		if(copy_to_user((void __user *)arg,&temp,sizeof(int)))
			return -EFAULT;
		break;

	//huanggq
	case GSENSOR_IOCTL_G_STATE:
		if(is_data_ready() == 0)
		{
			//printk("gsensor not ready!\n");
			return -EAGAIN;
		}
		
		ret[0] = (state_val & 0x60)>>5;	// shake
		if( (state_val & 0x10) != 0 )
			ret[1] = state_val & 0x03;	// orientation
		else
		  ret[1] = 0;

		//ret[0] = 5;
		//ret[1] = 3;
		if( copy_to_user((void __user *)arg, ret, sizeof(int)*2) )
			return -EFAULT;
		break;


	default:
		return -EINVAL;	
	}
	return 0;
}
示例#2
0
static int read(const struct motion_sensor_t *s, vector_3_t v)
{
	uint8_t raw[6];
	uint8_t xyz_reg;
	int ret, range, i, tmp = 0;
	struct l3gd20_data *data = s->drv_data;

	ret = is_data_ready(s, &tmp);
	if (ret != EC_SUCCESS)
		return ret;

	/*
	 * If sensor data is not ready, return the previous read data.
	 * Note: return success so that motion senor task can read again
	 * to get the latest updated sensor data quickly.
	 */
	if (!tmp) {
		if (v != s->raw_xyz)
			memcpy(v, s->raw_xyz, sizeof(s->raw_xyz));
		return EC_SUCCESS;
	}

	xyz_reg = get_xyz_reg(s->type);

	/* Read 6 bytes starting at xyz_reg */
	i2c_lock(s->port, 1);
	ret = i2c_xfer(s->port, s->addr,
			&xyz_reg, 1, raw, 6, I2C_XFER_SINGLE);
	i2c_lock(s->port, 0);

	if (ret != EC_SUCCESS) {
		CPRINTF("[%T %s type:0x%X RD XYZ Error]",
			s->name, s->type);
		return ret;
	}

	for (i = X; i <= Z; i++)
		v[i] = ((int16_t)((raw[i * 2 + 1] << 8) | raw[i * 2]));

	if (s->rot_standard_ref)
		rotate(v, *s->rot_standard_ref, v);

	/* apply offset in the device coordinates */
	range = get_range(s);
	for (i = X; i <= Z; i++)
		v[i] += (data->offset[i] << 5) / range;

	return EC_SUCCESS;
}