int geomagnetic_api_read(int *xyz, int *raw, int *xy1y2, int *accuracy) { struct geomagnetic_data *data = i2c_get_clientdata(this_client); struct yas_mag_data magdata; int i; geomagnetic_work(&magdata); if (xyz != NULL) { for (i = 0; i < 3; i++) { xyz[i] = magdata.xyz.v[i]; } } if (raw != NULL) { for (i = 0; i < 3; i++) { raw[i] = magdata.raw.v[i]; } } if (xy1y2 != NULL) { for (i = 0; i < 3; i++) { xy1y2[i] = magdata.xy1y2.v[i]; } } if (accuracy != NULL) { *accuracy = atomic_read(&data->last_status); } return 0; }
int geomagnetic_api_read(int *xyz, int *raw, int *xy1y2, int *accuracy) { struct geomagnetic_data *data = i2c_get_clientdata(this_client); struct yas_mag_data magdata; int i; int zero_acc = 0; //printk("[%s] %d \n",__func__, __LINE__); geomagnetic_work(&magdata); if (xyz != NULL) { for (i = 0; i < 3; i++) { xyz[i] = magdata.xyz.v[i]; } } if (raw != NULL) { for (i = 0; i < 3; i++) { raw[i] = magdata.raw.v[i]; } } if (xy1y2 != NULL) { for (i = 0; i < 3; i++) { xy1y2[i] = magdata.xy1y2.v[i]; } } #if 0 if (accuracy != NULL) { *accuracy = atomic_read(&data->last_status); } #else if (accuracy != NULL) { for (i = 0; i < 3; i++) { if((magdata.xy1y2.v[i]==0)||(magdata.xy1y2.v[i]==4095)) { *accuracy=0; zero_acc = 1; } } if(!zero_acc) *accuracy = 3; } //printk("[%s] accuracy = %d \n",__func__, *accuracy); #endif return 0; }
static void geomagnetic_input_work_func(struct work_struct *work) { struct geomagnetic_data *data = container_of((struct delayed_work *)work, struct geomagnetic_data, work); uint32_t time_delay_ms; struct yas_mag_data magdata; time_delay_ms = geomagnetic_work(&magdata); if (time_delay_ms > 0) { schedule_delayed_work(&data->work, msecs_to_jiffies(time_delay_ms) + 1); } else { schedule_delayed_work(&data->work, 0); } }