示例#1
0
static int gyro_enable_data(int enable)
{
    struct gyro_context *cxt = NULL;
    //int err =0;
    cxt = gyro_context_obj;
    if(NULL  == cxt->gyro_ctl.open_report_data)
    {
      GYRO_ERR("no gyro control path\n");
      return -1;
    }

    if(1 == enable)
    {
       GYRO_LOG("gyro enable data\n");
       cxt->is_active_data =true;
       cxt->is_first_data_after_enable = true;
       cxt->gyro_ctl.open_report_data(1);
       gyro_real_enable(enable);
       if(false == cxt->is_polling_run && cxt->is_batch_enable == false)
       {
          if(false == cxt->gyro_ctl.is_report_input_direct)
          {
              mod_timer(&cxt->timer, jiffies + atomic_read(&cxt->delay)/(1000/HZ));
              cxt->is_polling_run = true;
          }
       }
    }
    if(0 == enable)
    {
       GYRO_LOG("gyro disable \n");

       cxt->is_active_data =false;
       cxt->gyro_ctl.open_report_data(0);
       if(true == cxt->is_polling_run)
       {
          if(false == cxt->gyro_ctl.is_report_input_direct)
          {
              cxt->is_polling_run = false;
              smp_mb();
              del_timer_sync(&cxt->timer);
              smp_mb();
              cancel_work_sync(&cxt->report);
            cxt->drv_data.gyro_data.values[0] = GYRO_INVALID_VALUE;
               cxt->drv_data.gyro_data.values[1] = GYRO_INVALID_VALUE;
               cxt->drv_data.gyro_data.values[2] = GYRO_INVALID_VALUE;
          }
       }
       gyro_real_enable(enable);
    }
    return 0;
}
int gyro_enable_nodata(int enable)
{
	struct gyro_context *cxt = NULL;

	cxt = gyro_context_obj;
	if (NULL  == cxt->gyro_ctl.enable_nodata) {
		GYRO_ERR("gyro_enable_nodata:gyro ctl path is NULL\n");
		return -1;
	}

	if (1 == enable)
		cxt->is_active_nodata = true;

	if (0 == enable)
		cxt->is_active_nodata = false;

	gyro_real_enable(enable);
	return 0;
}