From dd9d3a38613f4708a14d74547ce635773cae14a8 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 5 Feb 2016 21:35:52 +0900 Subject: [PATCH] sensor-hal-tm1: modify Sensor HAL interface + clean up boilerplate Change-Id: I1c79151d4ee26d39ac6ea31ab8c37e506f250bd6 Signed-off-by: kibak.yoon --- src/accel/accel.cpp | 70 +++++++++++++++++++++-------------------------------- src/accel/accel.h | 8 +++--- src/macro.h | 4 +-- src/sensor_hal.h | 25 ++++++++----------- src/sensor_logs.h | 4 +-- src/util.cpp | 5 +--- src/util.h | 4 +-- 7 files changed, 47 insertions(+), 73 deletions(-) diff --git a/src/accel/accel.cpp b/src/accel/accel.cpp index 98a9850..5029828 100644 --- a/src/accel/accel.cpp +++ b/src/accel/accel.cpp @@ -1,7 +1,5 @@ /* - * accel_device - * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. @@ -16,14 +14,15 @@ * limitations under the License. * */ + #include #include #include #include #include #include -#include #include + #include "accel.h" #define GRAVITY 9.80665 @@ -43,38 +42,22 @@ #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, - max_batch_count : MAX_BATCH_COUNT, - wakeup_supported : false, -}; - -static const sensor_handle_t handles[] = { - { - id: 0x1, - name: "Accelerometer", - type: SENSOR_DEVICE_ACCELEROMETER, - event_type: (SENSOR_DEVICE_ACCELEROMETER << 16) | 0x0001, - info : accel_info - }, - { - id: 0x2, - name: "Accelerometer RAW", - type: SENSOR_DEVICE_ACCELEROMETER, - event_type: (SENSOR_DEVICE_ACCELEROMETER << 16) | 0x0002, - info : accel_info - } +static const sensor_handle_t handle = { + id: 0x1, + name: "Accelerometer", + type: SENSOR_DEVICE_ACCELEROMETER, + event_type: (SENSOR_DEVICE_ACCELEROMETER << 16) | 0x0001, + 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, + max_batch_count: MAX_BATCH_COUNT, + wakeup_supported: false }; -static uint16_t event_ids[] = { - 0x1, - 0x2, -}; +std::vector accel_device::event_ids; accel_device::accel_device() : m_node_handle(-1) @@ -130,10 +113,9 @@ int accel_device::get_poll_fd() int accel_device::get_sensors(const sensor_handle_t **sensors) { - int size = ARRAY_SIZE(handles); - *sensors = handles; + *sensors = &handle; - return size; + return 1; } bool accel_device::enable(uint16_t id) @@ -180,6 +162,11 @@ bool accel_device::set_attribute(uint16_t id, int32_t attribute, int32_t value) return false; } +bool accel_device::set_attribute_str(uint16_t id, char *attribute, char *value, int value_len) +{ + return false; +} + bool accel_device::update_value_input_event(void) { int accel_raw[3] = {0,}; @@ -252,18 +239,17 @@ bool accel_device::update_value_input_event(void) int accel_device::read_fd(uint16_t **ids) { - int size; - if (!update_value_input_event()) { DBG("Failed to update value"); return false; } - size = ARRAY_SIZE(event_ids); + event_ids.clear(); + event_ids.push_back(handle.id); - *ids = event_ids; + *ids = &event_ids[0]; - return size; + return event_ids.size(); } int accel_device::get_data(uint16_t id, sensor_data_t **data, int *length) diff --git a/src/accel/accel.h b/src/accel/accel.h index 0abc345..2135684 100644 --- a/src/accel/accel.h +++ b/src/accel/accel.h @@ -1,7 +1,5 @@ /* - * accel_device - * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. @@ -22,6 +20,7 @@ #include #include +#include class accel_device : public sensor_device { public: @@ -37,6 +36,7 @@ public: 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 set_attribute_str(uint16_t id, char *attribute, char *value, int value_len); int read_fd(uint16_t **ids); int get_data(uint16_t id, sensor_data_t **data, int *length); @@ -56,6 +56,8 @@ private: std::string m_enable_node; std::string m_interval_node; + static std::vector event_ids; + bool update_value_input_event(void); void raw_to_base(sensor_data_t *data); }; diff --git a/src/macro.h b/src/macro.h index 5e2ca3e..64446af 100644 --- a/src/macro.h +++ b/src/macro.h @@ -1,7 +1,5 @@ /* - * libsensord-share - * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. diff --git a/src/sensor_hal.h b/src/sensor_hal.h index 8b51bad..5530c7c 100644 --- a/src/sensor_hal.h +++ b/src/sensor_hal.h @@ -1,7 +1,5 @@ /* - * libsensord-share - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. @@ -100,17 +98,6 @@ 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. @@ -120,7 +107,14 @@ typedef struct sensor_handle_t { const char *name; sensor_device_type type; unsigned int event_type; // for Internal API - sensor_info_t info; + 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_handle_t; enum sensor_accuracy_t { @@ -174,6 +168,7 @@ public: 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; + virtual bool set_attribute_str(uint16_t id, char *attribute, char *value, int value_len) = 0; virtual int read_fd(uint16_t **ids) = 0; virtual int get_data(uint16_t id, sensor_data_t **data, int *length) = 0; diff --git a/src/sensor_logs.h b/src/sensor_logs.h index 9682c42..3385aad 100644 --- a/src/sensor_logs.h +++ b/src/sensor_logs.h @@ -1,7 +1,5 @@ /* - * libsensord-share - * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. diff --git a/src/util.cpp b/src/util.cpp index a8d9d11..9c0dbd3 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,7 +1,5 @@ /* - * libsensord-share - * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. @@ -308,4 +306,3 @@ bool util::set_node_value(const string &node_path, unsigned long long value) return true; } - diff --git a/src/util.h b/src/util.h index 81488e0..70c600a 100644 --- a/src/util.h +++ b/src/util.h @@ -1,7 +1,5 @@ /* - * libsensord-share - * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. -- 2.7.4