summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuHyun Kim <jh8212.kim@samsung.com>2012-02-18 17:25:16 +0900
committerJuHyun Kim <jh8212.kim@samsung.com>2012-02-18 17:25:16 +0900
commitaf4822f55a6e6e809e001bf25de9baf53a9149b0 (patch)
treed721a22e087f59913af02e16b42fa3f795e17bb3
parentd439bbb82c222a3577dc14249650f19cb064739b (diff)
downloadlibslp-sensor-af4822f55a6e6e809e001bf25de9baf53a9149b0.tar.gz
libslp-sensor-af4822f55a6e6e809e001bf25de9baf53a9149b0.tar.bz2
libslp-sensor-af4822f55a6e6e809e001bf25de9baf53a9149b0.zip
update libslp-sensor
-rwxr-xr-xinclude/SLP_SensorFW_PG.h25
-rwxr-xr-xinclude/sensor.h31
-rwxr-xr-xinclude/sensor_accel.h9
-rwxr-xr-xinclude/sensor_geomag.h5
-rwxr-xr-xinclude/sensor_gyro.h6
-rwxr-xr-xinclude/sensor_light.h5
-rwxr-xr-xinclude/sensor_motion.h5
-rwxr-xr-xinclude/sensor_proxi.h6
-rwxr-xr-xsrc/client.cpp464
9 files changed, 338 insertions, 218 deletions
diff --git a/include/SLP_SensorFW_PG.h b/include/SLP_SensorFW_PG.h
index 91a4671..b799459 100755
--- a/include/SLP_SensorFW_PG.h
+++ b/include/SLP_SensorFW_PG.h
@@ -261,13 +261,6 @@ Once the application is connected to a sensor, data processing can be done using
<h2 class="pg">Processing data without connecting to a sensor</h2>
-<b>API : sf_read_raw_data</b><br>
-<b>Parameter In</b>: sensor_type_t sensor_type<br>
-<b>Parameter Out</b>: float values[] , size_t *values_size<br>
-<b>Parameter Return</b>: int <br>
-<b>Functionality</b>: This API gets raw data from a sensor without connecting to the sensor-server. This doesn't need a connection handle. The type of sensor is supplied and return data is stored in the output parameter values [].<br>
-
-
<b>API : sf_check_rotation</b><br>
<b>Parameter Out</b>: unsigned long *state<br>
@@ -361,18 +354,6 @@ int main()
sensor_data->time_stamp);
- //Get the Raw Data(Bypass server)
- ret_val = sf_read_raw_data(sensor_type,(float *)raw_data, &size);
- if(ret_val != 0)
- {
- printf("\n Sensor Error : sensor_get_data FAILED with code %d",ret_val);
- return -1;
- }
-
- printf("\n Seneor test : My raw data is x= %f y= %f and z= %f \n",
- raw_data[0], raw_data[1], raw_data[2]);
-
-
//Get the rotation/orientation
ret_val = sf_check_rotation(&rotaion_state);
@@ -610,12 +591,6 @@ int main(int argc, char *argv[])
<td>unsigned long *curr_state</td>
<td>This API gets the current rotation value such as ROTATION_LANDSCAPE_LEFT , ROTATION_PORTRAIT_TOP etc</td>
</tr>
- <tr>
- <td>11</td>
- <td>sf_read_raw_data</td>
- <td>sensor_type_t sensor_type , float values[] , size_t *values_size</td>
- <td>This API reads raw data without connecting the process with the sensor</td>
- </tr>
</table>
diff --git a/include/sensor.h b/include/sensor.h
index cb20ece..2770464 100755
--- a/include/sensor.h
+++ b/include/sensor.h
@@ -79,6 +79,9 @@ typedef enum {
#include <sensor_motion.h>
#include <sensor_gyro.h>
+#define MAX_KEY_LEN 30
+#define MAX_VALUE_SIZE 12
+
typedef enum {
CONDITION_NO_OP,
CONDITION_EQUAL,
@@ -126,7 +129,7 @@ typedef struct {
int data_unit_idx;
unsigned long long time_stamp;
int values_num;
- float values[12];
+ float values[MAX_VALUE_SIZE];
} sensor_data_t;
typedef struct {
@@ -140,8 +143,17 @@ typedef struct {
float sensor_min_range;
float sensor_max_range;
float sensor_resolution;
+ char sensor_name[MAX_KEY_LEN];
+ char sensor_vendor[MAX_KEY_LEN];
} sensor_properties_t;
+typedef struct {
+ int sensor_unit_idx;
+ float sensor_min_range;
+ float sensor_max_range;
+ float sensor_resolution;
+} sensor_data_properties_t;
+
/**
* @fn int sf_is_sensor_event_available ( sensor_type_t desired_sensor_type , unsigned int desired_event_type )
@@ -152,6 +164,14 @@ typedef struct {
*/
int sf_is_sensor_event_available ( sensor_type_t desired_sensor_type , unsigned int desired_event_type );
+/**
+ * @fn int sf_get_data_properties(unsigned data_id, sensor_dada_properties_t *return_data_properties)
+ * @brief This API loads the properties of data ID like unit of sensor data, max/min range of sensor data etc to the output parameter sensor_data_properties.
+ * @param[in] data_id your desired data ID
+ * @param[out] return_data_properties property information of your desired data ID
+ * @return if it succeed, it return zero value , otherwise negative value return
+ */
+int sf_get_data_properties(unsigned int data_id, sensor_data_properties_t *return_data_properties);
/**
* @fn int sf_get_properties(sensor_type_t sensor_type, sensor_properties_t *return_properties)
@@ -164,6 +184,15 @@ int sf_get_properties(sensor_type_t sensor_type, sensor_properties_t *return_pro
/**
+ * @fn int sf_set_property(sensor_type_t sensor_type, unsigned int property_id, long value)
+ * @brief This API set the property of sensor type like calibration, enable wakeup event, etc
+ * @param[in] sensor_type your desired sensor type, property_id your desired property ID, value for property input
+ * @return if it succeed, it return zero value , otherwise negative value return
+ */
+int sf_set_property(sensor_type_t sensor_type, unsigned int property_id, long value);
+
+
+/**
* @fn int sf_connect(sensor_type_t sensor_type)
* @brief This API connects a sensor type to respective sensor. The application calls with the type of the sensor (ex. ACCELEROMETER_SENSOR) and on basis of that server takes decision of which plug-in to be connected. Once sensor connected application can proceed for data processing. This API returns a positive handle which should be used by application to communicate on sensor type.
* @param[in] sensor_type your desired sensor type
diff --git a/include/sensor_accel.h b/include/sensor_accel.h
index 04e695f..31bd28b 100755
--- a/include/sensor_accel.h
+++ b/include/sensor_accel.h
@@ -77,6 +77,15 @@ enum accelerometer_rotate_state {
ROTATION_EVENT_270 = 4, /*CCW base*/
};
+enum accelerometer_property_id {
+ ACCELEROMETER_PROPERTY_UNKNOWN = 0,
+ ACCELEROMETER_PROPERTY_SET_CALIBRATION,
+ ACCELEROMETER_PROPERTY_CHECK_CALIBRATION_STATUS,
+ ACCELEROMETER_PROPERTY_SET_WAKEUP,
+ ACCELEROMETER_PROPERTY_CHECK_WAKEUP_STATUS,
+};
+
+
struct rotation_event {
enum accelerometer_rotate_state rotation;
diff --git a/include/sensor_geomag.h b/include/sensor_geomag.h
index 42589f6..b96e026 100755
--- a/include/sensor_geomag.h
+++ b/include/sensor_geomag.h
@@ -63,6 +63,11 @@ enum geomag_evet_type {
GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME = (GEOMAGNETIC_SENSOR<<16) |0x0004,
};
+enum geomag_property_id {
+ GEOMAGNETIC_PROPERTY_UNKNOWN = 0,
+ GEOMAGNETIC_PROPERTY_SET_ACCEL_CALIBRATION,
+ GEOMAGNETIC_PROPERTY_CHECK_ACCEL_CALIBRATION,
+};
/**
diff --git a/include/sensor_gyro.h b/include/sensor_gyro.h
index 90a3d66..bd2574b 100755
--- a/include/sensor_gyro.h
+++ b/include/sensor_gyro.h
@@ -59,6 +59,12 @@ enum gyro_evet_type {
GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME = (GYROSCOPE_SENSOR<<16) |0x0001,
};
+enum gyro_property_id {
+ GYROSCOPE_PROPERTY_UNKNOWN = 0,
+ GYROSCOPE_PROPERTY_SET_CALIBRATION,
+ GYROSCOPE_PROPERTY_CHECK_CALIBRATION,
+};
+
/**
* @}
diff --git a/include/sensor_light.h b/include/sensor_light.h
index 7ec3c59..c4af180 100755
--- a/include/sensor_light.h
+++ b/include/sensor_light.h
@@ -51,14 +51,19 @@ extern "C"
enum light_data_id {
LIGHT_BASE_DATA_SET = (LIGHT_SENSOR<<16) | 0x0001,
+ LIGHT_LUX_DATA_SET = (LIGHT_SENSOR<<16) | 0x0002,
};
enum light_evet_type {
LIGHT_EVENT_CHANGE_LEVEL = (LIGHT_SENSOR<<16) |0x0001,
LIGHT_EVENT_LEVEL_DATA_REPORT_ON_TIME = (LIGHT_SENSOR<<16) |0x0002,
+ LIGHT_EVENT_LUX_DATA_REPORT_ON_TIME = (LIGHT_SENSOR<<16) |0x0004,
};
+enum light_property_id {
+ LIGHT_PROPERTY_UNKNOWN = 0,
+};
/**
* @}
diff --git a/include/sensor_motion.h b/include/sensor_motion.h
index 7edb61b..ec095aa 100755
--- a/include/sensor_motion.h
+++ b/include/sensor_motion.h
@@ -74,6 +74,11 @@ enum motion_top_to_bottom_event {
MOTION_ENGIEN_TOP_TO_BOTTOM_DETECTION,
};
+enum motion_property_id {
+ MOTION_PROPERTY_UNKNOWN = 0,
+ MOTION_PROPERTY_CHECK_ACCEL_SENSOR,
+ MOTION_PROPERTY_CHECK_GYRO_SENSOR,
+};
/**
* @}
diff --git a/include/sensor_proxi.h b/include/sensor_proxi.h
index 73f2455..fafc0fd 100755
--- a/include/sensor_proxi.h
+++ b/include/sensor_proxi.h
@@ -49,11 +49,13 @@ extern "C"
enum proxi_data_id {
PROXIMITY_BASE_DATA_SET = (PROXIMITY_SENSOR<<16) | 0x0001,
+ PROXIMITY_DISTANCE_DATA_SET = (PROXIMITY_SENSOR<<16) | 0x0002,
};
enum proxi_evet_type {
PROXIMITY_EVENT_CHANGE_STATE = (PROXIMITY_SENSOR<<16) |0x0001,
PROXIMITY_EVENT_STATE_REPORT_ON_TIME = (PROXIMITY_SENSOR<<16) |0x0002,
+ PROXIMITY_EVENT_DISTANCE_DATA_REPORT_ON_TIME = (PROXIMITY_SENSOR<<16) |0x0004,
};
enum proxi_change_state {
@@ -61,6 +63,10 @@ enum proxi_change_state {
PROXIMITY_STATE_NEAR = 1,
};
+enum proxi_property_id {
+ PROXIMITY_PROPERTY_UNKNOWN = 0,
+};
+
/**
* @}
*/
diff --git a/src/client.cpp b/src/client.cpp
index faf4d67..fb1d825 100755
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -88,6 +88,10 @@ extern int errno;
#define ROTATION_THD 45
#define RADIAN_VALUE (57.2957)
+#define XY_POSITIVE_THD 2.0
+#define XY_NEGATIVE_THD -2.0
+
+#define ON_TIME_REQUEST_COUNTER 1
@@ -247,81 +251,95 @@ inline static void cb_release_handle(int i)
g_cb_table[i].source = NULL;
g_cb_table[i].gsource_interval = 0;
g_cb_table[i].gID = 0;
-
+
_lock.unlock();
}
-static void sensor_changed_cb (keynode_t *node, void *data)
+
+static void sensor_changed_cb(keynode_t *node, void *data)
{
- int *cb_handle = (int*)(data);
+ unsigned int event_type = (unsigned int)(data);
+ int i = 0;
int val;
sensor_event_data_t cb_data;
sensor_panning_data_t panning_data;
- if (g_cb_table[*cb_handle].sensor_callback_func_t) {
+ if(!node)
+ {
+ ERR("Node is NULL");
+ return;
+ }
- if ( vconf_keynode_get_type(node) != VCONF_TYPE_INT ) {
- ERR("Err invaild key_type , incomming key_type : %d , key_name : %s , key_value : %d",
- vconf_keynode_get_type(node), vconf_keynode_get_name(node),vconf_keynode_get_int(node));
- return;
- }
-
- val = vconf_keynode_get_int(node);
+ if (vconf_keynode_get_type(node) != VCONF_TYPE_INT ) {
+ ERR("Err invaild key_type , incomming key_type : %d , key_name : %s , key_value : %d", vconf_keynode_get_type(node), vconf_keynode_get_name(node),vconf_keynode_get_int(node));
+ return;
+ }
- if(g_cb_table[*cb_handle].cb_event_type == MOTION_ENGINE_EVENT_PANNING)
+ val = vconf_keynode_get_int(node);
+
+ for( i = 0 ; i < MAX_CB_BIND_SLOT ; i++)
+ {
+ if(g_cb_table[i].cb_event_type == event_type)
{
- if(val != 0)
+ if (g_cb_table[i].sensor_callback_func_t)
{
- panning_data.x = (short)(val >> 16);
- panning_data.y = (short)(val & 0x0000FFFF);
- cb_data.event_data_size = sizeof(sensor_panning_data_t);
- cb_data.event_data = (void *)&panning_data;
- g_cb_table[*cb_handle].sensor_callback_func_t(g_cb_table[*cb_handle].cb_event_type, &cb_data , g_cb_table[*cb_handle].client_data);
+ if(g_cb_table[i].cb_event_type == MOTION_ENGINE_EVENT_PANNING)
+ {
+ if(val != 0)
+ {
+ panning_data.x = (short)(val >> 16);
+ panning_data.y = (short)(val & 0x0000FFFF);
+ cb_data.event_data_size = sizeof(sensor_panning_data_t);
+ cb_data.event_data = (void *)&panning_data;
+ g_cb_table[i].sensor_callback_func_t(g_cb_table[i].cb_event_type, &cb_data, g_cb_table[i].client_data);
+ }
+ } else {
+ if ( val<0 )
+ {
+ ERR("vconf_keynode_get_int fail for key : %s , handle_num : %d , get_value : %d\n", g_cb_table[i].call_back_key,i , val);
+ return ;
+ }
+
+ switch (g_cb_table[i].cb_event_type) {
+ case ACCELEROMETER_EVENT_ROTATION_CHECK :
+ /* fall through */
+ case ACCELEROMETER_EVENT_SET_HORIZON :
+ /* fall through */
+ case ACCELEROMETER_EVENT_SET_WAKEUP :
+ /* fall through */
+ case GEOMAGNETIC_EVENT_CALIBRATION_NEEDED :
+ /* fall through */
+ case LIGHT_EVENT_CHANGE_LEVEL :
+ /* fall through */
+ case PROXIMITY_EVENT_CHANGE_STATE:
+ /* fall through */
+ case MOTION_ENGINE_EVENT_SNAP:
+ /* fall through */
+ case MOTION_ENGINE_EVENT_SHAKE:
+ /* fall through */
+ case MOTION_ENGINE_EVENT_DOUBLETAP:
+ /* fall through */
+ case MOTION_ENGINE_EVENT_TOP_TO_BOTTOM:
+ /* fall through */
+ cb_data.event_data_size = sizeof(val);
+ cb_data.event_data = (void *)&val;
+ break;
+ default :
+ ERR("Undefined cb_event_type");
+ return ;
+ break;
+ }
+ g_cb_table[i].sensor_callback_func_t(g_cb_table[i].cb_event_type , &cb_data , g_cb_table[i].client_data);
+ }
}
- }
- else if ( val<0 ) {
- ERR("vconf_keynode_get_int fail for key : %s , handle_num : %d , get_value : %d\n", g_cb_table[*cb_handle].call_back_key,*cb_handle , val);
- } else {
- switch (g_cb_table[*cb_handle].cb_event_type) {
- case ACCELEROMETER_EVENT_ROTATION_CHECK :
- /* fall through */
- case ACCELEROMETER_EVENT_SET_HORIZON :
- /* fall through */
- case ACCELEROMETER_EVENT_SET_WAKEUP :
- /* fall through */
- case GEOMAGNETIC_EVENT_CALIBRATION_NEEDED :
- /* fall through */
- case LIGHT_EVENT_CHANGE_LEVEL :
- /* fall through */
- case PROXIMITY_EVENT_CHANGE_STATE:
- /* fall through */
- case MOTION_ENGINE_EVENT_SNAP:
- /* fall through */
- case MOTION_ENGINE_EVENT_SHAKE:
- /* fall through */
- case MOTION_ENGINE_EVENT_DOUBLETAP:
- /* fall through */
- case MOTION_ENGINE_EVENT_TOP_TO_BOTTOM:
- /* fall through */
- cb_data.event_data_size = sizeof(val);
- cb_data.event_data = (void *)&val ;
- break;
- default :
- ERR("Undefined cb_event_type");
- return ;
- break;
+ else {
+ ERR("Empty Callback func in event : %d\n", event_type);
}
-
-
- g_cb_table[*cb_handle].sensor_callback_func_t(g_cb_table[*cb_handle].cb_event_type , &cb_data , g_cb_table[*cb_handle].client_data);
- }
-
- } else {
- ERR("Empty Callback func in cb_handle : %d\n", *cb_handle);
+ }
}
-
}
+
static gboolean sensor_timeout_handler(gpointer data)
{
int *cb_handle = (int*)(data);
@@ -372,7 +390,7 @@ static gboolean sensor_timeout_handler(gpointer data)
}
///////////////////////////////////for internal ///////////////////////////////////
-static int server_get_properties(int handle , sensor_properties_t *return_properties )
+static int server_get_properties(int handle , unsigned int data_id, void *property_data)
{
cpacket packet(sizeof(cmd_return_property_t) + sizeof(base_property_struct)+ 4);
cmd_get_property_t *cmd_payload;
@@ -394,7 +412,11 @@ static int server_get_properties(int handle , sensor_properties_t *return_proper
packet.set_cmd(CMD_GET_PROPERTY);
packet.set_payload_size(sizeof(cmd_get_property_t));
- cmd_payload->get_level = ((unsigned int)g_bind_table[handle].sensor_type<<16) | 0x0001;
+ if(data_id)
+ cmd_payload->get_level = data_id;
+ else
+ cmd_payload->get_level = ((unsigned int)g_bind_table[handle].sensor_type<<16) | 0x0001;
+
INFO("Send CMD_GET_PROPERTY command\n");
@@ -431,10 +453,28 @@ static int server_get_properties(int handle , sensor_properties_t *return_proper
base_property_struct *base_return_property;
base_return_property = (base_property_struct *)return_payload->property_struct;
- return_properties->sensor_unit_idx = base_return_property->sensor_unit_idx ;
- return_properties->sensor_min_range= base_return_property->sensor_min_range;
- return_properties->sensor_max_range= base_return_property->sensor_max_range;
- return_properties->sensor_resolution = base_return_property->sensor_resolution;
+ if(data_id)
+ {
+ sensor_data_properties_t *return_properties;
+ return_properties = (sensor_data_properties_t *)property_data;
+ return_properties->sensor_unit_idx = base_return_property->sensor_unit_idx ;
+ return_properties->sensor_min_range= base_return_property->sensor_min_range;
+ return_properties->sensor_max_range= base_return_property->sensor_max_range;
+ return_properties->sensor_resolution = base_return_property->sensor_resolution;
+ }
+ else
+ {
+ sensor_properties_t *return_properties;
+ return_properties = (sensor_properties_t *)property_data;
+ return_properties->sensor_unit_idx = base_return_property->sensor_unit_idx ;
+ return_properties->sensor_min_range= base_return_property->sensor_min_range;
+ return_properties->sensor_max_range= base_return_property->sensor_max_range;
+ return_properties->sensor_resolution = base_return_property->sensor_resolution;
+ memset(return_properties->sensor_name, '\0', sizeof(return_properties->sensor_name));
+ memset(return_properties->sensor_vendor, '\0', sizeof(return_properties->sensor_vendor));
+ strncpy(return_properties->sensor_name, base_return_property->sensor_name, strlen(base_return_property->sensor_name));
+ strncpy(return_properties->sensor_vendor, base_return_property->sensor_vendor, strlen(base_return_property->sensor_vendor));
+ }
}
} else {
ERR("unexpected server cmd\n");
@@ -447,6 +487,73 @@ static int server_get_properties(int handle , sensor_properties_t *return_proper
}
+static int server_set_property(int handle , unsigned int property_id, long value )
+{
+ cpacket packet(sizeof(cmd_set_value_t) + 4);
+ cmd_set_value_t *cmd_payload;
+ INFO("server_set_property called with handle : %d \n", handle);
+ if (handle < 0) {
+ ERR("Invalid handle\n");
+ errno = EINVAL;
+ return -1;
+ }
+
+ cmd_payload = (cmd_set_value_t*)packet.data();
+ if (!cmd_payload) {
+ ERR("cannot find memory for send packet.data");
+ errno = ENOMEM;
+ return -2;
+ }
+
+ packet.set_version(PROTOCOL_VERSION);
+ packet.set_cmd(CMD_SET_VALUE);
+ packet.set_payload_size(sizeof(cmd_set_value_t));
+
+ cmd_payload->sensor_type = g_bind_table[handle].sensor_type;
+ cmd_payload->property = property_id;
+ cmd_payload->value = value;
+
+
+ INFO("Send CMD_SET_VALUE command\n");
+ if (g_bind_table[handle].ipc && g_bind_table[handle].ipc->send(packet.packet(), packet.size()) == false) {
+ ERR("Faield to send a packet\n");
+ release_handle(handle);
+ errno = ECOMM;
+ return -2;
+ }
+
+ if (g_bind_table[handle].ipc && g_bind_table[handle].ipc->recv(packet.packet(), packet.header_size()) == false) {
+ ERR("Faield to receive a packet\n");
+ release_handle(handle);
+ errno = ECOMM;
+ return -2;
+ }
+
+ if (packet.payload_size()) {
+ if (g_bind_table[handle].ipc && g_bind_table[handle].ipc->recv((char*)packet.packet() + packet.header_size(), packet.payload_size()) == false) {
+ ERR("Faield to receive a packet\n");
+ release_handle(handle);
+ errno = ECOMM;
+ return -2;
+ }
+
+ if (packet.cmd() == CMD_DONE) {
+ cmd_done_t *payload;
+ payload = (cmd_done_t*)packet.data();
+ if (payload->value == -1) {
+ ERR("cannot support input property\n");
+ errno = ENODEV;
+ return -1;
+ }
+ } else {
+ ERR("unexpected server cmd\n");
+ errno = ECOMM;
+ return -2;
+ }
+ }
+
+ return 0;
+}
///////////////////////////////////for external ///////////////////////////////////
@@ -522,6 +629,28 @@ EXTAPI int sf_is_sensor_event_available ( sensor_type_t desired_sensor_type , un
return 0;
}
+EXTAPI int sf_get_data_properties(unsigned int data_id, sensor_data_properties_t *return_data_properties)
+{
+ int handle;
+ int state = -1;
+
+ retvm_if( (!return_data_properties ) , -1 , "Invalid return properties pointer : %p", return_data_properties);
+
+
+ handle = sf_connect((sensor_type_t)(data_id >> 16));
+ if ( handle < 0 ) {
+ ERR("Sensor connet fail !! for : %x \n", (data_id >> 16));
+ return -1;
+ } else {
+ state = server_get_properties( handle , data_id, return_data_properties );
+ if ( state < 0 ) {
+ ERR("server_get_properties fail , state : %d \n",state);
+ }
+ sf_disconnect(handle);
+ }
+
+ return state;
+}
EXTAPI int sf_get_properties(sensor_type_t sensor_type, sensor_properties_t *return_properties)
{
@@ -535,7 +664,7 @@ EXTAPI int sf_get_properties(sensor_type_t sensor_type, sensor_properties_t *ret
ERR("Sensor connet fail !! for : %x \n", sensor_type);
return -1;
} else {
- state = server_get_properties( handle , return_properties );
+ state = server_get_properties( handle , 0, return_properties );
if ( state < 0 ) {
ERR("server_get_properties fail , state : %d \n",state);
}
@@ -545,6 +674,28 @@ EXTAPI int sf_get_properties(sensor_type_t sensor_type, sensor_properties_t *ret
return state;
}
+
+EXTAPI int sf_set_property(sensor_type_t sensor_type, unsigned int property_id, long value)
+{
+ int handle;
+ int state = -1;
+
+ handle = sf_connect(sensor_type);
+ if ( handle < 0 ) {
+ ERR("Sensor connet fail !! for : %x \n", sensor_type);
+ return -1;
+ } else {
+ state = server_set_property( handle , property_id, value );
+ if ( state < 0 ) {
+ ERR("server_set_property fail , state : %d \n",state);
+ }
+ sf_disconnect(handle);
+ }
+
+ return state;
+}
+
+
EXTAPI int sf_connect(sensor_type_t sensor_type)
{
register int i, j;
@@ -574,55 +725,31 @@ EXTAPI int sf_connect(sensor_type_t sensor_type)
case ACCELEROMETER_SENSOR :
sf_channel_name = (char *)ACCEL_SENSOR_BASE_CHANNEL_NAME;
g_bind_table[i].cb_event_max_num = 6;
-
- for(j = 0 ; j < g_bind_table[i].cb_event_max_num ; j++)
- g_bind_table[i].cb_slot_num[j] = -1;
-
break;
case GEOMAGNETIC_SENSOR :
sf_channel_name = (char *)GEOMAG_SENSOR_BASE_CHANNEL_NAME;
g_bind_table[i].cb_event_max_num = 3;
-
- for(j = 0 ; j < g_bind_table[i].cb_event_max_num ; j++)
- g_bind_table[i].cb_slot_num[j] = -1;
-
break;
case LIGHT_SENSOR:
sf_channel_name = (char *)LIGHT_SENSOR_BASE_CHANNEL_NAME;
- g_bind_table[i].cb_event_max_num = 2;
-
- for(j = 0 ; j < g_bind_table[i].cb_event_max_num ; j++)
- g_bind_table[i].cb_slot_num[j] = -1;
-
+ g_bind_table[i].cb_event_max_num = 3;
break;
case PROXIMITY_SENSOR:
sf_channel_name = (char *)PROXI_SENSOR_BASE_CHANNEL_NAME;
- g_bind_table[i].cb_event_max_num = 2;
-
- for(j = 0 ; j < g_bind_table[i].cb_event_max_num ; j++)
- g_bind_table[i].cb_slot_num[j] = -1;
-
+ g_bind_table[i].cb_event_max_num = 3;
break;
case MOTION_SENSOR:
sf_channel_name = (char *)MOTION_ENGINE_BASE_CHANNEL_NAME;
g_bind_table[i].cb_event_max_num = 7;
-
- for(j = 0 ; j < g_bind_table[i].cb_event_max_num ; j++)
- g_bind_table[i].cb_slot_num[j] = -1;
-
break;
case GYROSCOPE_SENSOR:
sf_channel_name = (char *)GYRO_SENSOR_BASE_CHANNEL_NAME;
g_bind_table[i].cb_event_max_num = 1;
-
- for(j = 0 ; j < g_bind_table[i].cb_event_max_num ; j++)
- g_bind_table[i].cb_slot_num[j] = -1;
-
break;
case THERMOMETER_SENSOR:
@@ -640,6 +767,9 @@ EXTAPI int sf_connect(sensor_type_t sensor_type)
g_bind_table[i].my_handle = i;
g_bind_table[i].sensor_state = SENSOR_STATE_STOPPED;
+ for(j = 0 ; j < g_bind_table[i].cb_event_max_num ; j++)
+ g_bind_table[i].cb_slot_num[j] = -1;
+
try {
g_bind_table[i].ipc = new csock( (char *)STR_SF_CLIENT_IPC_SOCKET, csock::SOCK_TCP|csock::SOCK_IPC|csock::SOCK_WORKER, 0, 0);
} catch (...) {
@@ -987,86 +1117,27 @@ EXTAPI int sf_register_event(int handle , unsigned int event_type , event_condi
switch (event_type ) {
case ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME:
- /* fall through */
+ /* fall through */
case GEOMAGNETIC_EVENT_ATTITUDE_DATA_REPORT_ON_TIME:
- /* fall through */
+ /* fall through */
case PROXIMITY_EVENT_STATE_REPORT_ON_TIME:
/* fall through */
case GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME:
- collect_data_flag = 1;
- g_cb_table[i].request_count = 1; //support only 1
- g_cb_table[i].request_data_id = (event_type & (0xFFFF<<16)) |0x0001;
- if (!event_condition) {
- g_cb_table[i].gsource_interval = BASE_GATHERING_INTERVAL;
- } else {
- if ( (event_condition->cond_op == CONDITION_EQUAL) && (event_condition->cond_value1 > 0 ) ) {
- g_cb_table[i].gsource_interval = (guint)event_condition->cond_value1;
- } else {
- ERR("Invaild input_condition interval , input_interval : %f\n", event_condition->cond_value1);
- cb_release_handle(i);
- errno = EINVAL;
- return -1;
- }
- }
-
- break;
-
+ /* fall through */
case LIGHT_EVENT_LEVEL_DATA_REPORT_ON_TIME:
collect_data_flag = 1;
- g_cb_table[i].request_count = 1; //support only 1
- g_cb_table[i].request_data_id = LIGHT_BASE_DATA_SET;
- if (!event_condition) {
- g_cb_table[i].gsource_interval = (BASE_GATHERING_INTERVAL*5);
- } else {
- if ( (event_condition->cond_op == CONDITION_EQUAL) && (event_condition->cond_value1 > 0 ) ) {
- g_cb_table[i].gsource_interval = (guint)event_condition->cond_value1;
- } else {
- ERR("Invaild input_condition interval , input_interval : %f\n", event_condition->cond_value1);
- cb_release_handle(i);
- errno = EINVAL;
- return -1;
- }
- }
+ g_cb_table[i].request_data_id = (event_type & (0xFFFF<<16)) |0x0001;
break;
-
+ case LIGHT_EVENT_LUX_DATA_REPORT_ON_TIME:
+ /* fall through */
case GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME:
- collect_data_flag = 1;
- g_cb_table[i].request_count = 1; //support only 1
- g_cb_table[i].request_data_id = GEOMAGNETIC_RAW_DATA_SET;
- if (!event_condition) {
- g_cb_table[i].gsource_interval = (BASE_GATHERING_INTERVAL);
- } else {
- if ( (event_condition->cond_op == CONDITION_EQUAL) && (event_condition->cond_value1 > 0 ) ) {
- g_cb_table[i].gsource_interval = (guint)event_condition->cond_value1;
- } else {
- ERR("Invaild input_condition interval , input_interval : %f\n", event_condition->cond_value1);
- cb_release_handle(i);
- errno = EINVAL;
- return -1;
- }
- }
- break;
-
+ /* fall through */
case ACCELEROMETER_EVENT_ORIENTATION_DATA_REPORT_ON_TIME:
+ /* fall through */
+ case PROXIMITY_EVENT_DISTANCE_DATA_REPORT_ON_TIME:
collect_data_flag = 1;
- g_cb_table[i].request_count = 1; //support only 1
- g_cb_table[i].request_data_id = ACCELEROMETER_ORIENTATION_DATA_SET;
- if (!event_condition) {
- g_cb_table[i].gsource_interval = BASE_GATHERING_INTERVAL;
- } else {
- if ( (event_condition->cond_op == CONDITION_EQUAL) && (event_condition->cond_value1 > 0 ) ) {
- g_cb_table[i].gsource_interval = (guint)event_condition->cond_value1;
- } else {
- ERR("Invaild input_condition interval , input_interval : %f\n", event_condition->cond_value1);
- cb_release_handle(i);
- errno = EINVAL;
- return -1;
- }
- }
-
+ g_cb_table[i].request_data_id = (event_type & (0xFFFF<<16)) |0x0002;
break;
-
-
}
INFO("key : %s(p:%p), cb_handle value : %d\n", g_cb_table[i].call_back_key ,g_cb_table[i].call_back_key, i );
@@ -1074,7 +1145,7 @@ EXTAPI int sf_register_event(int handle , unsigned int event_type , event_condi
if ( collect_data_flag ) {
sensor_data_t *collected_data_set;
- collected_data_set = new sensor_data_t [g_cb_table[i].request_count];
+ collected_data_set = new sensor_data_t [ON_TIME_REQUEST_COUNTER];
if ( !collected_data_set ) {
ERR("memory allocation fail for gathering datas\n");
cb_release_handle(i);
@@ -1083,6 +1154,20 @@ EXTAPI int sf_register_event(int handle , unsigned int event_type , event_condi
}
g_cb_table[i].collected_data = (void *)collected_data_set;
g_cb_table[i].current_collected_idx = 0;
+
+ if (!event_condition) {
+ g_cb_table[i].gsource_interval = BASE_GATHERING_INTERVAL;
+ } else {
+ if ( (event_condition->cond_op == CONDITION_EQUAL) && (event_condition->cond_value1 > 0 ) ) {
+ g_cb_table[i].gsource_interval = (guint)event_condition->cond_value1;
+ } else {
+ ERR("Invaild input_condition interval , input_interval : %f\n", event_condition->cond_value1);
+ cb_release_handle(i);
+ errno = EINVAL;
+ return -1;
+ }
+ }
+
if ( g_cb_table[i].gsource_interval != 0 ) {
g_cb_table[i].source = g_timeout_source_new(g_cb_table[i].gsource_interval);
@@ -1100,16 +1185,12 @@ EXTAPI int sf_register_event(int handle , unsigned int event_type , event_condi
g_cb_table[i].request_data_id = 0;
g_cb_table[i].collected_data = NULL;
- if (vconf_notify_key_changed( g_cb_table[i].call_back_key,
- sensor_changed_cb, (void *)&g_cb_table[i].my_cb_handle) < 0 ) {
- ERR("vconf_add_changed_cb fail, for key : %s , my_cb_handle value : %d\n", g_cb_table[i].call_back_key, g_cb_table[i].my_cb_handle);
- cb_release_handle(i);
- errno = ENODEV;
- return -2;
- }
-
+ if (vconf_notify_key_changed( g_cb_table[i].call_back_key,sensor_changed_cb,(void*)(g_cb_table[i].cb_event_type)) < 0 ) {
+ DBG("vconf_add_changed_cb is already registered for key : %s , my_cb_handle value : %d\n", g_cb_table[i].call_back_key, g_cb_table[i].my_cb_handle);
+ } else {
+ DBG("vconf_add_chaged_cb success for key : %s , my_cb_handle value : %d\n", g_cb_table[i].call_back_key, g_cb_table[i].my_cb_handle);
+ }
}
-
g_bind_table[handle].cb_slot_num[avail_cb_slot_idx] = i;
return 0;
@@ -1174,6 +1255,10 @@ EXTAPI int sf_unregister_event(int handle, unsigned int event_type)
case LIGHT_EVENT_LEVEL_DATA_REPORT_ON_TIME:
/* fall through */
case GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME:
+ /* fall through */
+ case LIGHT_EVENT_LUX_DATA_REPORT_ON_TIME:
+ /* fall through */
+ case PROXIMITY_EVENT_DISTANCE_DATA_REPORT_ON_TIME:
collect_data_flag = 1;
break;
}
@@ -1223,8 +1308,6 @@ EXTAPI int sf_unregister_event(int handle, unsigned int event_type)
g_bind_table[handle].cb_slot_num[i] = -1;
return state;
-
-
}
@@ -1325,8 +1408,8 @@ EXTAPI int sf_check_rotation( unsigned long *curr_state)
int state = -1;
double raw_z;
- double atan_value, norm_z;
- int acc_theta , acc_pitch;
+ double atan_value = 0, norm_z = 0;
+ int acc_theta = 0 , acc_pitch = 0;
int handle = 0;
int lcd_type = 0;
@@ -1376,22 +1459,23 @@ EXTAPI int sf_check_rotation( unsigned long *curr_state)
if(vconf_get_int(LCD_TYPE_KEY, &lcd_type) != 0)
lcd_type = 0;
- atan_value = atan2(base_data_values->values[1],base_data_values->values[0]);
-
- acc_theta = (int)(atan_value * (RADIAN_VALUE) + 270)%360;
-
- raw_z = (double)(base_data_values->values[2]/(0.004 * 9.81));
+ if((base_data_values->values[0] > XY_POSITIVE_THD || base_data_values->values[0] < XY_NEGATIVE_THD) || (base_data_values->values[1] > XY_POSITIVE_THD || base_data_values->values[1] < XY_NEGATIVE_THD))
+ {
+ atan_value = atan2(base_data_values->values[1],base_data_values->values[0]);
+ acc_theta = ((int)(atan_value * (RADIAN_VALUE) + 270.0))%360;
+ raw_z = (double)(base_data_values->values[2]) / 9.8;
- if ( raw_z > 250 ) {
- norm_z = 1.0;
- }
- else if ( raw_z < -250 ) {
- norm_z = -1.0;
- }
- else {
- norm_z = ((double)raw_z)/250;
+ if ( raw_z > 1.0 ) {
+ norm_z = 1.0;
+ }
+ else if ( raw_z < -1.0 ) {
+ norm_z = -1.0;
+ }
+ else {
+ norm_z = raw_z;
+ }
+ acc_pitch = (int)( acos(norm_z) *(RADIAN_VALUE));
}
- acc_pitch = (int)( acos(norm_z) *(RADIAN_VALUE));
INFO( "cal value [acc_theta] : %d , [acc_pitch] : %d\n",acc_theta ,acc_pitch);
@@ -1429,8 +1513,4 @@ EXTAPI int sf_check_rotation( unsigned long *curr_state)
}
-EXTAPI int sf_read_raw_data(sensor_type_t sensor_type , float values[] , size_t *values_size)
-{
- return -1;
-}
//! End of a file