From 467a8540b1dbf59231038235f351601a3b2bd509 Mon Sep 17 00:00:00 2001 From: Adriana Reus Date: Fri, 7 Nov 2014 14:30:05 +0200 Subject: [PATCH] Change enable_count with flag Tracked-On: https://jira01.devtools.intel.com/browse/GMINL-3725 Change-Id: I50eae55b9128ce4e3c647dbed633fea933b522dd Signed-off-by: Adriana Reus --- common.h | 2 +- control.c | 37 +++++++++++++++++-------------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/common.h b/common.h index 1de6af2..b59cbd3 100644 --- a/common.h +++ b/common.h @@ -137,7 +137,7 @@ struct sensor_info_t float sampling_rate; /* requested events / second */ int dev_num; /* Associated iio dev num, ex: 3 for /dev/iio:device3 */ - int enable_count; + int enabled; int catalog_index;/* Associated entry within the sensor_catalog array */ int type; /* Sensor type, such as SENSOR_TYPE_GYROSCOPE */ diff --git a/control.c b/control.c index a12735c..839fdf0 100644 --- a/control.c +++ b/control.c @@ -258,11 +258,11 @@ int adjust_counters (int s, int enabled) ALOGI("Enabling sensor %d (iio device %d: %s)\n", s, dev_num, sensor_info[s].friendly_name); - sensor_info[s].enable_count++; - - if (sensor_info[s].enable_count > 1) + if (sensor_info[s].enabled) return 0; /* The sensor was, and remains, in use */ + sensor_info[s].enabled = 1; + switch (sensor_info[s].type) { case SENSOR_TYPE_MAGNETIC_FIELD: compass_read_data(&sensor_info[s]); @@ -274,16 +274,13 @@ int adjust_counters (int s, int enabled) break; } } else { - if (sensor_info[s].enable_count == 0) - return -1; /* Spurious disable call */ + if (sensor_info[s].enabled == 0) + return 0; /* Spurious disable call */ ALOGI("Disabling sensor %d (iio device %d: %s)\n", s, dev_num, sensor_info[s].friendly_name); - sensor_info[s].enable_count--; - - if (sensor_info[s].enable_count > 0) - return 0; /* The sensor was, and remains, in use */ + sensor_info[s].enabled = 0; /* Sensor disabled, lower report available flag */ sensor_info[s].report_pending = 0; @@ -299,7 +296,7 @@ int adjust_counters (int s, int enabled) /* If uncalibrated type and pair is already active don't adjust counters */ if (sensor_info[s].type == SENSOR_TYPE_GYROSCOPE_UNCALIBRATED && - sensor_info[sensor_info[s].pair_idx].enable_count != 0) + sensor_info[sensor_info[s].pair_idx].enabled != 0) return 0; /* We changed the state of a sensor - adjust per iio device counters */ @@ -547,7 +544,7 @@ int sensor_activate(int s, int enabled) * Reactivate gyro uncalibrated - Uncalibrated has handler */ if (sensor_info[s].type == SENSOR_TYPE_GYROSCOPE && - sensor_info[s].pair_idx && sensor_info[sensor_info[s].pair_idx].enable_count != 0) { + sensor_info[s].pair_idx && sensor_info[sensor_info[s].pair_idx].enabled != 0) { sensor_activate(sensor_info[s].pair_idx, 0); ret = sensor_activate(s, enabled); @@ -711,7 +708,7 @@ static void enable_motion_trigger (int dev_num) for (s=0; s new_sampling_rate) new_sampling_rate= sensor_info[n].sampling_rate; @@ -1307,7 +1304,7 @@ int sensor_flush (int s) { /* If one shot or not enabled return -EINVAL */ if (sensor_desc[s].flags & SENSOR_FLAG_ONE_SHOT_MODE || - sensor_info[s].enable_count == 0) + sensor_info[s].enabled == 0) return -EINVAL; sensor_info[s].meta_data_pending++; -- 2.11.0