sensor-hal: refactoring sensor HAL interface 55/58755/1
authorMu-Woong Lee <muwoong.lee@samsung.com>
Wed, 3 Feb 2016 07:48:58 +0000 (16:48 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Wed, 3 Feb 2016 07:48:58 +0000 (16:48 +0900)
* remove useless functions and consolidate functions to 1 function
* hal-id: int32_t -> int16_t
* common structures are defined in sensor_hal.h

Change-Id: Ie1d8f32a15ebf3a851e43b07972200647ce74dfa
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
src/accel/accel.cpp
src/accel/accel.h
src/create.cpp
src/sensor_common.h [deleted file]
src/sensor_hal.h

index 55e6302..c35fee0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * accel_sensor_device
+ * accel_device
  *
  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
  *
@@ -21,7 +21,6 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <linux/input.h>
-#include <sys/poll.h>
 #include <util.h>
 #include <macro.h>
 #include <sensor_logs.h>
 #define RESOLUTION 16
 #define RAW_DATA_UNIT 0.122
 #define MIN_INTERVAL 1
-#define FIFO_COUNT 0
 #define MAX_BATCH_COUNT 0
 
-static const sensor_properties_s accel_properties = {
-       name : MODEL_NAME,
+#define SENSORHUB_ACCELEROMETER_ENABLE_BIT 0
+
+static const sensor_info_t accel_info = {
+       model_name : MODEL_NAME,
        vendor : VENDOR,
        min_range : MIN_RANGE(RESOLUTION) * RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(RAW_DATA_UNIT),
        max_range : MAX_RANGE(RESOLUTION) * RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(RAW_DATA_UNIT),
        resolution : RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(RAW_DATA_UNIT),
        min_interval : MIN_INTERVAL,
-       fifo_count : FIFO_COUNT,
        max_batch_count : MAX_BATCH_COUNT,
 };
 
@@ -60,18 +59,18 @@ static const sensor_handle_t handles[] = {
                name: "Accelerometer",
                type: SENSOR_DEVICE_ACCELEROMETER,
                event_type: (SENSOR_DEVICE_ACCELEROMETER << 16) | 0x0001,
-               properties : accel_properties
+               info : accel_info
        },
        {
                id: 0x2,
                name: "Accelerometer RAW",
                type: SENSOR_DEVICE_ACCELEROMETER,
                event_type: (SENSOR_DEVICE_ACCELEROMETER << 16) | 0x0002,
-               properties : accel_properties
+               info : accel_info
        }
 };
 
-accel_sensor_device::accel_sensor_device()
+accel_device::accel_device()
 : m_node_handle(-1)
 , m_x(-1)
 , m_y(-1)
@@ -107,18 +106,23 @@ accel_sensor_device::accel_sensor_device()
                throw ENXIO;
        }
 
-       INFO("accel_sensor_device is created!\n");
+       INFO("accel_device is created!\n");
 }
 
-accel_sensor_device::~accel_sensor_device()
+accel_device::~accel_device()
 {
        close(m_node_handle);
        m_node_handle = -1;
 
-       INFO("accel_sensor_device is destroyed!\n");
+       INFO("accel_device is destroyed!\n");
+}
+
+int accel_device::get_poll_fd()
+{
+       return m_node_handle;
 }
 
-bool accel_sensor_device::get_sensors(std::vector<sensor_handle_t> &sensors)
+bool accel_device::get_sensors(std::vector<sensor_handle_t> &sensors)
 {
        int size = ARRAY_SIZE(handles);
 
@@ -128,7 +132,7 @@ bool accel_sensor_device::get_sensors(std::vector<sensor_handle_t> &sensors)
        return true;
 }
 
-bool accel_sensor_device::enable(uint32_t id)
+bool accel_device::enable(uint16_t id)
 {
        util::set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_ACCELEROMETER_ENABLE_BIT);
        set_interval(id, m_polling_interval);
@@ -138,7 +142,7 @@ bool accel_sensor_device::enable(uint32_t id)
        return true;
 }
 
-bool accel_sensor_device::disable(uint32_t id)
+bool accel_device::disable(uint16_t id)
 {
        util::set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_ACCELEROMETER_ENABLE_BIT);
 
@@ -146,12 +150,7 @@ bool accel_sensor_device::disable(uint32_t id)
        return true;
 }
 
-int accel_sensor_device::get_poll_fd()
-{
-       return m_node_handle;
-}
-
-bool accel_sensor_device::set_interval(uint32_t id, unsigned long val)
+bool accel_device::set_interval(uint16_t id, unsigned long val)
 {
        unsigned long long polling_interval_ns;
 
@@ -167,24 +166,17 @@ bool accel_sensor_device::set_interval(uint32_t id, unsigned long val)
        return true;
 }
 
-bool accel_sensor_device::set_batch_latency(uint32_t id, unsigned long val)
+bool accel_device::set_batch_latency(uint16_t id, unsigned long val)
 {
        return false;
 }
 
-bool accel_sensor_device::set_command(uint32_t id, std::string command, std::string value)
+bool accel_device::set_attribute(uint16_t id, int32_t attribute, int32_t value)
 {
        return false;
 }
 
-bool accel_sensor_device::is_data_ready(void)
-{
-       bool ret;
-       ret = update_value_input_event();
-       return ret;
-}
-
-bool accel_sensor_device::update_value_input_event(void)
+bool accel_device::update_value_input_event(void)
 {
        int accel_raw[3] = {0,};
        bool x,y,z;
@@ -254,56 +246,47 @@ bool accel_sensor_device::update_value_input_event(void)
        return true;
 }
 
-bool accel_sensor_device::get_sensor_data(uint32_t id, sensor_data_t &data)
+bool accel_device::read_fd(std::vector<uint16_t> &ids)
 {
-       data.accuracy = SENSOR_ACCURACY_GOOD;
-       data.timestamp = m_fired_time;
-       data.value_count = 3;
-       data.values[0] = m_x;
-       data.values[1] = m_y;
-       data.values[2] = m_z;
+       if (!update_value_input_event()) {
+               DBG("Failed to update value");
+               return false;
+       }
 
-       raw_to_base(data);
+       ids.push_back(handles[0].id);
+       ids.push_back(handles[1].id);
 
        return true;
 }
 
-int accel_sensor_device::get_sensor_event(uint32_t id, sensor_event_t **event)
+int accel_device::get_data(uint16_t id, sensor_data_t **data)
 {
-       sensor_event_t *sensor_event;
-       sensor_event = (sensor_event_t *)malloc(sizeof(sensor_event_t));
+       sensor_data_t *sensor_data;
+       sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
 
-       sensor_event->data.accuracy = SENSOR_ACCURACY_GOOD;
-       sensor_event->data.timestamp = m_fired_time;
-       sensor_event->data.value_count = 3;
-       sensor_event->data.values[0] = m_x;
-       sensor_event->data.values[1] = m_y;
-       sensor_event->data.values[2] = m_z;
+       sensor_data->accuracy = SENSOR_ACCURACY_GOOD;
+       sensor_data->timestamp = m_fired_time;
+       sensor_data->value_count = 3;
+       sensor_data->values[0] = m_x;
+       sensor_data->values[1] = m_y;
+       sensor_data->values[2] = m_z;
 
-       raw_to_base(sensor_event->data);
+       raw_to_base(sensor_data);
 
-       *event = sensor_event;
+       *data = sensor_data;
 
-       return sizeof(sensor_event_t);
+       return sizeof(sensor_data_t);
 }
 
-void accel_sensor_device::raw_to_base(sensor_data_t &data)
+bool accel_device::flush(uint16_t id)
 {
-       data.value_count = 3;
-       data.values[0] = RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(data.values[0] * RAW_DATA_UNIT);
-       data.values[1] = RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(data.values[1] * RAW_DATA_UNIT);
-       data.values[2] = RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(data.values[2] * RAW_DATA_UNIT);
+       return false;
 }
 
-bool accel_sensor_device::get_properties(uint32_t id, sensor_properties_s &properties)
+void accel_device::raw_to_base(sensor_data_t *data)
 {
-       properties.name = MODEL_NAME;
-       properties.vendor = VENDOR;
-       properties.min_range = accel_properties.min_range;
-       properties.max_range = accel_properties.max_range;
-       properties.min_interval = accel_properties.min_interval;
-       properties.resolution = accel_properties.resolution;
-       properties.fifo_count = accel_properties.fifo_count;
-       properties.max_batch_count = accel_properties.max_batch_count;
-       return true;
+       data->value_count = 3;
+       data->values[0] = RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(data->values[0] * RAW_DATA_UNIT);
+       data->values[1] = RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(data->values[1] * RAW_DATA_UNIT);
+       data->values[2] = RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(data->values[2] * RAW_DATA_UNIT);
 }
index 533264c..cf13520 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * accel_sensor_device
+ * accel_device
  *
  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
  *
  *
  */
 
-#ifndef _ACCEL_SENSOR_DEVICE_H_
-#define _ACCEL_SENSOR_DEVICE_H_
+#ifndef _ACCEL_DEVICE_H_
+#define _ACCEL_DEVICE_H_
 
+#include <vector>
 #include <sensor_hal.h>
 
-class accel_sensor_device : public sensor_device
+class accel_device : public sensor_device
 {
 public:
-       accel_sensor_device();
-       virtual ~accel_sensor_device();
+       accel_device();
+       virtual ~accel_device();
 
        int get_poll_fd(void);
        bool get_sensors(std::vector<sensor_handle_t> &sensors);
-       bool enable(uint32_t id);
-       bool disable(uint32_t id);
-       bool set_interval(uint32_t id, unsigned long val);
-       bool set_batch_latency(uint32_t id, unsigned long val);
-       bool set_command(uint32_t id, std::string command, std::string value);
-       bool is_data_ready(void);
-       bool get_sensor_data(uint32_t id, sensor_data_t &data);
-       int get_sensor_event(uint32_t id, sensor_event_t **event);
-       bool get_properties(uint32_t id, sensor_properties_s &properties);
+
+       bool enable(uint16_t id);
+       bool disable(uint16_t id);
+
+       bool set_interval(uint16_t id, unsigned long val);
+       bool set_batch_latency(uint16_t id, unsigned long val);
+       bool set_attribute(uint16_t id, int32_t attribute, int32_t value);
+
+       bool read_fd(std::vector<uint16_t> &ids);
+       int get_data(uint16_t id, sensor_data_t **data);
+       bool flush(uint16_t id);
 
 private:
        int m_node_handle;
@@ -54,6 +57,6 @@ private:
        std::string m_interval_node;
 
        bool update_value_input_event(void);
-       void raw_to_base(sensor_data_t &data);
+       void raw_to_base(sensor_data_t *data);
 };
-#endif /*_ACCEL_SENSOR_DEVICE_CLASS_H_*/
+#endif /*_ACCEL_DEVICE_H_*/
index a442333..281a886 100644 (file)
@@ -60,7 +60,7 @@ extern "C" sensor_devices* create(void)
        retvm_if(!devices, NULL, "Failed to allocate memory");
 
 #ifdef ENABLE_ACCEL
-       create_sensor<accel_sensor_device>("Accel");
+       create_sensor<accel_device>("Accel");
 #endif
 
 #ifdef ENABLE_GYRO
diff --git a/src/sensor_common.h b/src/sensor_common.h
deleted file mode 100644 (file)
index 5b58340..0000000
+++ /dev/null
@@ -1,413 +0,0 @@
-/*
- * libsensord-share
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __SENSOR_COMMON_H__
-#define __SENSOR_COMMON_H__
-
-#include <unistd.h>
-#include <sensor_logs.h>
-#include <string>
-#include <vector>
-
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-
-#ifndef DEPRECATED
-#define DEPRECATED __attribute__((deprecated))
-#endif
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-/**
- * @defgroup SENSOR_FRAMEWORK SensorFW
- * To support the unified API for the various sensors
- */
-
-/**
- * @defgroup SENSOR_FRAMEWORK_COMMON Sensor Framework Common API
- * @ingroup SENSOR_FRAMEWORK
- *
- * These APIs are used to control the sensors.
- * @{
- */
-
-typedef enum {
-       ALL_SENSOR = -1,
-       UNKNOWN_SENSOR = 0,
-       ACCELEROMETER_SENSOR,
-       GEOMAGNETIC_SENSOR,
-       LIGHT_SENSOR,
-       PROXIMITY_SENSOR,
-       THERMOMETER_SENSOR,
-       GYROSCOPE_SENSOR,
-       PRESSURE_SENSOR,
-       MOTION_SENSOR,
-       FUSION_SENSOR,
-       PEDOMETER_SENSOR,
-       CONTEXT_SENSOR,
-       FLAT_SENSOR,
-       BIO_SENSOR,
-       BIO_HRM_SENSOR,
-       AUTO_ROTATION_SENSOR,
-       GRAVITY_SENSOR,
-       LINEAR_ACCEL_SENSOR,
-       ROTATION_VECTOR_SENSOR,
-       GEOMAGNETIC_RV_SENSOR,
-       GAMING_RV_SENSOR,
-       ORIENTATION_SENSOR,
-       TILT_SENSOR,
-       PIR_SENSOR,
-       PIR_LONG_SENSOR,
-       TEMPERATURE_SENSOR,
-       HUMIDITY_SENSOR,
-       ULTRAVIOLET_SENSOR,
-       DUST_SENSOR,
-       BIO_LED_GREEN_SENSOR,
-       BIO_LED_IR_SENSOR,
-       BIO_LED_RED_SENSOR,
-       RV_RAW_SENSOR,
-       UNCAL_GYROSCOPE_SENSOR,
-       UNCAL_GEOMAGNETIC_SENSOR
-} sensor_type_t;
-
-typedef unsigned int sensor_id_t;
-
-typedef void *sensor_t;
-
-typedef enum {
-       SENSOR_PRIVILEGE_PUBLIC,
-       SENSOR_PRIVILEGE_INTERNAL,
-} sensor_privilege_t;
-
-#define SENSOR_DATA_VALUE_SIZE 16
-
-/*
- *     When modifying it, check copy_sensor_data()
- */
-typedef struct sensor_data_t {
-/*
- *     Use "accuracy" instead of "data_accuracy"
- *     which is going to be removed soon
- */
-       union {
-               int accuracy;
-               int data_accuracy; //deprecated
-       };
-
-       union {
-               unsigned long long timestamp;
-               unsigned long long time_stamp; //deprecated
-       };
-
-/*
- *     Use "value_count" instead of "values_num"
- *     which is going to be removed soon
- */
-       union {
-               int value_count;
-               int values_num; //deprecated
-       };
-
-       float values[SENSOR_DATA_VALUE_SIZE];
-
-/*
- *     If extra_data_size > 0,
- *     then use extra_data.
- */
-       int extra_data_size;
-       void *extra_data;
-} sensor_data_t;
-
-#define SENSOR_HUB_DATA_SIZE   4096
-
-typedef struct sensorhub_data_t {
-    int version;
-    int sensorhub;
-    int type;
-    int hub_data_size;
-    unsigned long long timestamp;
-    char hub_data[SENSOR_HUB_DATA_SIZE];
-    float data[16];
-} sensorhub_data_t;
-
-enum sensor_accuracy_t {
-       SENSOR_ACCURACY_UNDEFINED = -1,
-       SENSOR_ACCURACY_BAD = 0,
-       SENSOR_ACCURACY_NORMAL =1,
-       SENSOR_ACCURACY_GOOD = 2,
-       SENSOR_ACCURACY_VERYGOOD = 3
-};
-
-/*
- *     To prevent naming confliction as using same enums as sensor CAPI use
- */
-#ifndef __SENSOR_H__
-enum sensor_option_t {
-       SENSOR_OPTION_DEFAULT = 0,
-       SENSOR_OPTION_ON_IN_SCREEN_OFF = 1,
-       SENSOR_OPTION_ON_IN_POWERSAVE_MODE = 2,
-       SENSOR_OPTION_ALWAYS_ON = SENSOR_OPTION_ON_IN_SCREEN_OFF | SENSOR_OPTION_ON_IN_POWERSAVE_MODE,
-       SENSOR_OPTION_END
-};
-
-typedef enum sensor_option_t sensor_option_e;
-#endif
-
-/*
- *     To prevent naming confliction as using same enums as sensor CAPI use
- */
-#ifndef __SENSOR_H__
-enum sensor_wakeup_t {
-       SENSOR_WAKEUP_UNKNOWN = -1,
-       SENSOR_WAKEUP_OFF = 0,
-       SENSOR_WAKEUP_ON = 1,
-};
-
-typedef enum sensor_wakeup_t sensor_wakeup_e;
-#endif
-
-enum sensor_interval_t {
-       SENSOR_INTERVAL_FASTEST = 0,
-       SENSOR_INTERVAL_NORMAL = 200,
-};
-
-typedef enum {
-       CONDITION_NO_OP,
-       CONDITION_EQUAL,
-       CONDITION_GREAT_THAN,
-       CONDITION_LESS_THAN,
-} condition_op_t;
-
-#define COMMAND_CHANNEL_PATH                   "/tmp/sensord_command_socket"
-#define EVENT_CHANNEL_PATH                             "/tmp/sensord_event_socket"
-
-#define MAX_HANDLE                     256
-#define MAX_HANDLE_REACHED     -2
-
-#define CLIENT_ID_INVALID   -1
-
-#define SENSOR_TYPE_MASK  0xFFFF
-
-enum packet_type_t {
-       CMD_NONE = 0,
-       CMD_GET_ID,
-       CMD_GET_SENSOR_LIST,
-       CMD_HELLO,
-       CMD_BYEBYE,
-       CMD_DONE,
-       CMD_START,
-       CMD_STOP,
-       CMD_REG,
-       CMD_UNREG,
-       CMD_SET_OPTION,
-       CMD_SET_WAKEUP,
-       CMD_SET_BATCH,
-       CMD_UNSET_BATCH,
-       CMD_SET_COMMAND,
-       CMD_GET_DATA,
-       CMD_SEND_SENSORHUB_DATA,
-       CMD_CNT,
-};
-
-enum sensor_state_t {
-       SENSOR_STATE_UNKNOWN = -1,
-       SENSOR_STATE_STOPPED = 0,
-       SENSOR_STATE_STARTED = 1,
-       SENSOR_STATE_PAUSED = 2
-};
-
-enum poll_interval_t {
-       POLL_100HZ_MS   = 10,
-       POLL_50HZ_MS    = 20,
-       POLL_25HZ_MS    = 40,
-       POLL_20HZ_MS    = 50,
-       POLL_10HZ_MS    = 100,
-       POLL_5HZ_MS             = 200,
-       POLL_1HZ_MS             = 1000,
-       POLL_MAX_HZ_MS  = POLL_1HZ_MS,
-};
-
-typedef struct {
-       char name[NAME_MAX];
-} cmd_get_id_t;
-
-typedef struct {
-} cmd_get_sensor_list_t;
-
-typedef struct {
-       int client_id;
-       int sensor;
-} cmd_hello_t;
-
-typedef struct {
-} cmd_byebye_t;
-
-
-typedef struct {
-       unsigned int type;
-} cmd_get_data_t;
-
-typedef struct {
-       long value;
-} cmd_done_t;
-
-
-typedef struct {
-       int client_id;
-} cmd_get_id_done_t;
-
-typedef struct {
-       int sensor_cnt;
-       char data[0];
-} cmd_get_sensor_list_done_t;
-
-typedef struct {
-       int state;
-       sensor_data_t base_data;
-} cmd_get_data_done_t;
-
-typedef struct {
-} cmd_start_t;
-
-typedef struct {
-} cmd_stop_t;
-
-typedef struct {
-       unsigned int event_type;
-} cmd_reg_t;
-
-typedef struct {
-       unsigned int event_type;
-} cmd_unreg_t;
-
-typedef struct {
-       unsigned int interval;
-       unsigned int latency;
-} cmd_set_batch_t;
-
-typedef struct {
-} cmd_unset_batch_t;
-
-typedef struct {
-       int option;
-} cmd_set_option_t;
-
-typedef struct {
-       int wakeup;
-} cmd_set_wakeup_t;
-
-typedef struct  {
-       unsigned int cmd;
-       long value;
-} cmd_set_command_t;
-
-typedef struct  {
-       int data_len;
-       char data[0];
-} cmd_send_sensorhub_data_t;
-
-#define EVENT_CHANNEL_MAGIC 0xCAFECAFE
-
-typedef struct {
-       unsigned int magic;
-       int client_id;
-} event_channel_ready_t;
-
-typedef struct {
-       std::string name;
-       std::string vendor;
-       float min_range;
-       float max_range;
-       float resolution;
-       int min_interval;
-       int fifo_count;
-       int max_batch_count;
-       bool wakeup_supported;
-} sensor_properties_s;
-
-/*
- * When modifying it, check copy_sensor*_data()
- */
-typedef struct sensor_event_t {
-       unsigned int event_type;
-       sensor_id_t sensor_id;
-       sensor_data_t data;
-} sensor_event_t;
-
-typedef struct sensorhub_event_t {
-       unsigned int event_type;
-       sensor_id_t sensor_id;
-       sensorhub_data_t data;
-} sensorhub_event_t;
-
-typedef struct {
-       std::vector<void*> devices;
-} sensor_devices;
-
-typedef sensor_devices* (*create_t)(void);
-
-typedef void *(*cmd_func_t)(void *data, void *cb_data);
-
-typedef std::vector<unsigned int> event_type_vector;
-
-enum sensorhub_enable_bit {
-       SENSORHUB_ACCELEROMETER_ENABLE_BIT = 0,
-       SENSORHUB_GYROSCOPE_ENABLE_BIT,
-       SENSORHUB_GEOMAGNETIC_UNCALIB_ENABLE_BIT,
-       SENSORHUB_GEOMAGNETIC_RAW_ENABLE_BIT,
-       SENSORHUB_GEOMAGNETIC_ENABLE_BIT,
-       SENSORHUB_PRESSURE_ENABLE_BIT,
-       SENSORHUB_GESTURE_ENABLE_BIT,
-       SENSORHUB_PROXIMITY_ENABLE_BIT,
-       SENSORHUB_TEMPERATURE_HUMIDITY_ENABLE_BIT,
-       SENSORHUB_LIGHT_ENABLE_BIT,
-       SENSORHUB_PROXIMITY_RAW_ENABLE_BIT,
-       SENSORHUB_ORIENTATION_ENABLE_BIT,
-       SENSORHUB_STEP_DETECTOR_ENABLE_BIT = 12,
-       SENSORHUB_SIG_MOTION_ENABLE_BIT,
-       SENSORHUB_GYRO_UNCALIB_ENABLE_BIT,
-       SENSORHUB_GAME_ROTATION_VECTOR_ENABLE_BIT = 15,
-       SENSORHUB_ROTATION_VECTOR_ENABLE_BIT,
-       SENSORHUB_STEP_COUNTER_ENABLE_BIT,
-       SENSORHUB_BIO_HRM_RAW_ENABLE_BIT,
-       SENSORHUB_BIO_HRM_RAW_FAC_ENABLE_BIT,
-       SENSORHUB_BIO_HRM_LIB_ENABLE_BIT,
-       SENSORHUB_TILT_MOTION,
-       SENSORHUB_UV_SENSOR,
-       SENSORHUB_PIR_ENABLE_BIT,
-       SENSORHUB_ENABLE_BIT_MAX,
-};
-
-enum sensor_permission_t {
-       SENSOR_PERMISSION_NONE  = 0,
-       SENSOR_PERMISSION_STANDARD = (1 << 0),
-       SENSOR_PERMISSION_BIO   =  (1 << 1),
-};
-
-#define BIO_SENSOR_PRIVELEGE_NAME "sensord::bio"
-#define BIO_SENSOR_ACCESS_RIGHT "rw"
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-//! End of a file
index 3dee6a0..46fd840 100644 (file)
 #define _SENSOR_HAL_H_
 
 #include <stdint.h>
+
+#ifdef __cplusplus
 #include <string>
 #include <vector>
-#include <sensor_common.h>
+#endif /* __cplusplus */
 
 #define SENSOR_HAL_VERSION(maj,min) \
                        ((((maj) & 0xffff) << 24) | ((min) & 0xffff))
 
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
 /*
  * Sensor Types
  * These types are used to controll the sensors
@@ -97,21 +104,61 @@ typedef enum {
        SENSOR_DEVICE_ROTATION_VECTOR_RAW,
 } sensor_device_type;
 
+typedef struct sensor_info_t {
+       const char *model_name;
+       const char *vendor;
+       float min_range;
+       float max_range;
+       float resolution;
+       int min_interval;
+       int max_batch_count;
+       bool wakeup_supported;
+} sensor_info_t;
+
 /*
  * A platform sensor handler is generated based on this handle
  * ID can be assigned from HAL developer. so it has to be unique in HAL.
  */
 typedef struct sensor_handle_t {
-       uint32_t id;
-       std::string name;
+       uint16_t id;
+       const char *name;
        sensor_device_type type;
        unsigned int event_type; // for Internal API
-       sensor_properties_s properties;
+       sensor_info_t info;
 } sensor_handle_t;
 
+enum sensor_accuracy_t {
+       SENSOR_ACCURACY_UNDEFINED = -1,
+       SENSOR_ACCURACY_BAD = 0,
+       SENSOR_ACCURACY_NORMAL =1,
+       SENSOR_ACCURACY_GOOD = 2,
+       SENSOR_ACCURACY_VERYGOOD = 3
+};
+
+#define SENSOR_DATA_VALUE_SIZE 16
+
+/* sensor_data_t */
+typedef struct sensor_data_t {
+       int accuracy;
+       unsigned long long timestamp;
+       int value_count;
+       float values[SENSOR_DATA_VALUE_SIZE];
+} sensor_data_t;
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#ifdef __cplusplus
+typedef struct {
+       std::vector<void*> devices;
+} sensor_devices;
+
+typedef sensor_devices* (*create_t)(void);
+
 /*
  * Sensor device interface
- * 1 HAL must be abstracted from 1 device event node
+ * 1 device must be abstracted from 1 device event node
  */
 class sensor_device
 {
@@ -126,23 +173,18 @@ public:
        virtual int get_poll_fd(void) = 0;
        virtual bool get_sensors(std::vector<sensor_handle_t> &sensors) = 0;
 
-       /* enable/disable sensor device */
-       virtual bool enable(uint32_t id) = 0;
-       virtual bool disable(uint32_t id) = 0;
-
-       /* set_command or set_option? */
-       virtual bool set_command(uint32_t id, std::string command, std::string value) = 0;
+       virtual bool enable(uint16_t id) = 0;
+       virtual bool disable(uint16_t id) = 0;
 
-       /* the belows can be merged to one */
-       virtual bool set_interval(uint32_t id, unsigned long val) = 0;
-       virtual bool set_batch_latency(uint32_t id, unsigned long val) = 0;
+       virtual bool set_interval(uint16_t id, unsigned long val) = 0;
+       virtual bool set_batch_latency(uint16_t id, unsigned long val) = 0;
+       virtual bool set_attribute(uint16_t id, int32_t attribute, int32_t value) = 0;
 
-       /* sensor fw read the data when is_data_ready() is true */
-       virtual bool is_data_ready() = 0;
-       virtual bool get_sensor_data(uint32_t id, sensor_data_t &data) = 0;
-       virtual int get_sensor_event(uint32_t id, sensor_event_t **event) = 0;
+       virtual bool read_fd(std::vector<uint16_t> &ids) = 0;
+       virtual int get_data(uint16_t id, sensor_data_t **data) = 0;
 
-       /* TODO: use get_sensors() instead of get_properties() */
-       virtual bool get_properties(uint32_t id, sensor_properties_s &properties) = 0;
+       virtual bool flush(uint16_t id) = 0;
 };
+#endif /* __cplusplus */
+
 #endif /* _SENSOR_HAL_H_ */