#include <common.h>
#include <sf_common.h>
+
#include <proxi_sensor.h>
#include <sensor_plugin_loader.h>
+
#define SENSOR_NAME "PROXI_SENSOR"
proxi_sensor::proxi_sensor()
proxi_sensor::~proxi_sensor()
{
- INFO("proxi_sensor is destroyed!");
+ INFO("proxi_sensor is destroyed!\n");
}
bool proxi_sensor::init()
return false;
}
- INFO("%s is created!", sensor_base::get_name());
+ INFO("%s is created!\n", sensor_base::get_name());
return true;
}
bool proxi_sensor::working(void *inst)
{
- proxi_sensor *sensor = (proxi_sensor *)inst;
+ proxi_sensor *sensor = (proxi_sensor*)inst;
return sensor->process_event();
}
AUTOLOCK(m_client_info_mutex);
AUTOLOCK(m_mutex);
+ event.sensor_id = get_id();
if (get_client_cnt(PROXIMITY_EVENT_DISTANCE_DATA_REPORT_ON_TIME)) {
event.event_type = PROXIMITY_EVENT_DISTANCE_DATA_REPORT_ON_TIME;
raw_to_base(event.data);
bool proxi_sensor::on_start(void)
{
- AUTOLOCK(m_mutex);
-
if (!m_sensor_hal->enable()) {
- ERR("m_sensor_hal start fail");
+ ERR("m_sensor_hal start fail\n");
return false;
}
bool proxi_sensor::on_stop(void)
{
- AUTOLOCK(m_mutex);
-
if (!m_sensor_hal->disable()) {
- ERR("m_sensor_hal stop fail");
+ ERR("m_sensor_hal stop fail\n");
return false;
}
return stop_poll();
}
-bool proxi_sensor::get_properties(const unsigned int type, sensor_properties_t &properties)
+bool proxi_sensor::get_properties(sensor_properties_t &properties)
{
- return m_sensor_hal->get_properties(properties);
+ m_sensor_hal->get_properties(properties);
+
+ properties.min_range = properties.min_range * 5;
+ properties.max_range = properties.max_range * 5;
+
+ return true;
}
-int proxi_sensor::get_sensor_data(const unsigned int type, sensor_data_t &data)
+int proxi_sensor::get_sensor_data(unsigned int type, sensor_data_t &data)
{
int state;
state = m_sensor_hal->get_sensor_data(data);
if (state < 0) {
- ERR("m_sensor_hal get struct_data fail");
+ ERR("m_sensor_hal get struct_data fail\n");
return -1;
}
void proxi_sensor::raw_to_state(sensor_data_t &data)
{
- data.values_num = 1;
+ data.value_count = 1;
}
extern "C" void *create(void)
try {
inst = new proxi_sensor();
} catch (int err) {
- ERR("Failed to create proxi_sensor class, errno : %d, errstr : %s", err, strerror(err));
+ ERR("proxi_sensor class create fail , errno : %d , errstr : %s\n", err, strerror(err));
return NULL;
}
- return (void *)inst;
+ return (void*)inst;
}
extern "C" void destroy(void *inst)
{
- delete (proxi_sensor *)inst;
+ delete (proxi_sensor*)inst;
}
/*
- * sensord
+ * proxi_sensor_hal
*
* Copyright (c) 2014 Samsung Electronics Co., Ltd.
*
* limitations under the License.
*
*/
-
-#include <fstream>
#include <fcntl.h>
#include <sys/stat.h>
-#include <sys/ioctl.h>
#include <dirent.h>
+
#include <linux/input.h>
#include <cconfig.h>
+
#include <proxi_sensor_hal.h>
+#include <sys/ioctl.h>
+#include <fstream>
+#include <cconfig.h>
#include <iio_common.h>
-using std::ifstream;
-using config::CConfig;
+#define NO_FLAG 0
+#define PROXIMITY_TYPE 8
-#define INITIAL_VALUE -1
-#define INITIAL_TIME 0
+#define EVENT_DIR "events/"
+#define EVENT_EN_NODE "in_proximity_thresh_either_en"
#define SENSOR_TYPE_PROXI "PROXI"
-#define ELEMENT_NAME "NAME"
+#define ELEMENT_NAME "NAME"
#define ELEMENT_VENDOR "VENDOR"
-#define ATTR_VALUE "value"
+#define ATTR_VALUE "value"
-#define INPUT_NAME "proximity_sensor"
+#define PROXI_CODE 0x0019
-#define NO_FLAG 0
-#define ENABLE_VAL true
-#define DISABLE_VAL false
+using std::ifstream;
+using config::CConfig;
proxi_sensor_hal::proxi_sensor_hal()
: m_state(PROXIMITY_STATE_FAR)
-, m_node_handle(INITIAL_VALUE)
-, m_fired_time(INITIAL_TIME)
-, m_sensorhub_supported(false)
+, m_fired_time(0)
+, m_node_handle(-1)
{
- int fd, ret;
+ const string sensorhub_interval_node_name = "prox_poll_delay";
+ CConfig &config = CConfig::get_instance();
- if (!check_hw_node())
- {
- ERR("check_hw_node() fail");
+ node_path_info_query query;
+ node_path_info info;
+ int input_method = IIO_METHOD;
+
+ if (!get_model_properties(SENSOR_TYPE_PROXI, m_model_id, input_method)) {
+ ERR("Failed to find model_properties");
throw ENXIO;
+
}
- CConfig &config = CConfig::get_instance();
+ query.input_method = input_method;
+ query.sensorhub_controlled = m_sensorhub_controlled = false;
+ query.sensor_type = SENSOR_TYPE_PROXI;
+ query.input_event_key = "proximity_sensor";
+ query.iio_enable_node_name = "proximity_enable";
+ query.sensorhub_interval_node_name = sensorhub_interval_node_name;
- if (!config.get(SENSOR_TYPE_PROXI, m_model_id, ELEMENT_VENDOR, m_vendor))
- {
- ERR("[VENDOR] is empty");
+ if (!get_node_path_info(query, info)) {
+ ERR("Failed to get node info");
+ throw ENXIO;
+ }
+
+ m_data_node = info.data_node_path;
+ m_enable_node = info.base_dir + string(EVENT_DIR) + string(EVENT_EN_NODE);
+
+ INFO("data node: %s",m_data_node.c_str());
+ INFO("enable node: %s",m_enable_node.c_str());
+
+ if (!config.get(SENSOR_TYPE_PROXI, m_model_id, ELEMENT_VENDOR, m_vendor)) {
+ ERR("[VENDOR] is empty\n");
throw ENXIO;
}
INFO("m_vendor = %s", m_vendor.c_str());
- if (!config.get(SENSOR_TYPE_PROXI, m_model_id, ELEMENT_NAME, m_chip_name))
- {
- ERR("[NAME] is empty");
+ if (!config.get(SENSOR_TYPE_PROXI, m_model_id, ELEMENT_NAME, m_chip_name)) {
+ ERR("[NAME] is empty\n");
throw ENXIO;
}
- INFO("m_chip_name = %s", m_chip_name.c_str());
+ INFO("m_chip_name = %s\n",m_chip_name.c_str());
- fd = open(m_event_resource.c_str(), NO_FLAG);
- if (fd == -1)
- {
+ int fd, ret;
+ fd = open(m_data_node.c_str(), NO_FLAG);
+ if (fd == -1) {
ERR("Could not open event resource");
throw ENXIO;
}
- ret = ioctl(fd, IOCTL_IIO_EVENT_FD, &m_event_fd);
+ ret = ioctl(fd, IOCTL_IIO_EVENT_FD, &m_node_handle);
close(fd);
- if ((ret == -1) || (m_event_fd == -1))
- {
+ if ((ret == -1) || (m_node_handle == -1)) {
ERR("Failed to retrieve event fd");
throw ENXIO;
}
- INFO("proxi_sensor_hal is created!");
+ INFO("Proxi_sensor_hal is created!\n");
+
}
proxi_sensor_hal::~proxi_sensor_hal()
{
- close(m_event_fd);
- INFO("proxi_sensor_hal is destroyed!");
+ close(m_node_handle);
+ m_node_handle = -1;
+
+ INFO("Proxi_sensor_hal is destroyed!\n");
}
string proxi_sensor_hal::get_model_id(void)
bool proxi_sensor_hal::enable_resource(bool enable)
{
- update_sysfs_num(m_enable_resource.c_str(), enable);
+ update_sysfs_num(m_enable_node.c_str(), enable);
return true;
}
{
AUTOLOCK(m_mutex);
- enable_resource(ENABLE_VAL);
+ enable_resource(true);
m_fired_time = 0;
- INFO("Proximity sensor real starting");
+ INFO("Proxi sensor real starting");
return true;
}
{
AUTOLOCK(m_mutex);
- enable_resource(DISABLE_VAL);
+ enable_resource(true);
- INFO("Proximity sensor real stopping");
+ INFO("Proxi sensor real stopping");
return true;
}
FD_ZERO(&readfds);
FD_ZERO(&exceptfds);
- FD_SET(m_event_fd, &readfds);
- FD_SET(m_event_fd, &exceptfds);
+ FD_SET(m_node_handle, &readfds);
+ FD_SET(m_node_handle, &exceptfds);
int ret;
- ret = select(m_event_fd + 1, &readfds, NULL, &exceptfds, NULL);
+ ret = select(m_node_handle + 1, &readfds, NULL, &exceptfds, NULL);
- if (ret == -1)
- {
- ERR("select error:%s m_event_fd:d", strerror(errno), m_event_fd);
+ if (ret == -1) {
+ ERR("select error:%s m_node_handle:%d", strerror(errno), m_node_handle);
return false;
}
- else if (!ret)
- {
+ else if (!ret) {
DBG("select timeout");
return false;
}
- if (FD_ISSET(m_event_fd, &exceptfds))
- {
+ if (FD_ISSET(m_node_handle, &exceptfds)) {
ERR("select exception occurred!");
return false;
}
- if (FD_ISSET(m_event_fd, &readfds))
- {
+ if (FD_ISSET(m_node_handle, &readfds)) {
INFO("proximity event detection!");
- int len = read(m_event_fd, &proxi_event, sizeof(proxi_event));
+ int len = read(m_node_handle, &proxi_event, sizeof(proxi_event));
- if (len == -1)
- {
- DBG("Error in read(m_event_fd):%s.", strerror(errno));
+ if (len == -1) {
+ DBG("Error in read(m_node_handle):%s.", strerror(errno));
return false;
}
ull_bytes_t ev_data;
ev_data.num = proxi_event.event_id;
- if (ev_data.bytes[CH_TYPE] == PROXIMITY_TYPE)
- {
+ if (ev_data.bytes[CH_TYPE] == PROXIMITY_TYPE) {
AUTOLOCK(m_value_mutex);
int temp;
temp = GET_DIR_VAL(ev_data.bytes[DIRECTION]);
- if (temp == PROXIMITY_NODE_STATE_FAR)
- {
+ if (temp == PROXIMITY_NODE_STATE_FAR) {
INFO("PROXIMITY_STATE_FAR state occurred");
m_state = PROXIMITY_STATE_FAR;
}
- else if (temp == PROXIMITY_NODE_STATE_NEAR)
- {
+ else if (temp == PROXIMITY_NODE_STATE_NEAR) {
INFO("PROXIMITY_STATE_NEAR state occurred");
m_state = PROXIMITY_STATE_NEAR;
}
- else
- {
+ else {
ERR("PROXIMITY_STATE Unknown: %d", proxi_event.event_id);
return false;
}
}
m_fired_time = proxi_event.timestamp;
}
- else
- {
+ else {
ERR("No proximity event data available to read");
return false;
}
-
return true;
}
int proxi_sensor_hal::get_sensor_data(sensor_data_t &data)
{
AUTOLOCK(m_value_mutex);
- data.data_accuracy = SENSOR_ACCURACY_UNDEFINED;
- data.data_unit_idx = SENSOR_UNIT_STATE_ON_OFF;
+ data.accuracy = SENSOR_ACCURACY_UNDEFINED;
data.timestamp = m_fired_time;
- data.values_num = 1;
- data.values[0] = (float)(m_state);
+ data.value_count = 1;
+ data.values[0] = m_state;
+
return 0;
}
bool proxi_sensor_hal::get_properties(sensor_properties_t &properties)
{
- properties.sensor_unit_idx = SENSOR_UNIT_STATE_ON_OFF;
- properties.sensor_min_range = 0;
- properties.sensor_max_range = 1;
- snprintf(properties.sensor_name, sizeof(properties.sensor_name), "%s", m_chip_name.c_str());
- snprintf(properties.sensor_vendor, sizeof(properties.sensor_vendor), "%s", m_vendor.c_str());
- properties.sensor_resolution = 1;
+ properties.name = m_chip_name;
+ properties.vendor = m_vendor;
+ properties.min_range = 0;
+ properties.max_range = 1;
+ properties.min_interval = 1;
+ properties.resolution = 1;
+ properties.fifo_count = 0;
+ properties.max_batch_count = 0;
return true;
}
-bool proxi_sensor_hal::is_sensorhub_supported(void)
-{
- return false;
-}
-
-bool proxi_sensor_hal::check_hw_node(void)
-{
- string name_node;
- string hw_name;
- string file_name;
- DIR *main_dir = NULL;
- struct dirent *dir_entry = NULL;
- bool find_node = false;
-
- INFO("======================start check_hw_node=============================");
-
- m_sensorhub_supported = is_sensorhub_supported();
- main_dir = opendir(IIO_DIR);
-
- if (!main_dir)
- {
- ERR("Could not open IIO directory\n");
- return false;
- }
-
- while (!find_node)
- {
- dir_entry = readdir(main_dir);
- if(dir_entry == NULL)
- break;
-
- if ((strncasecmp(dir_entry->d_name , ".", 1 ) != 0) && (strncasecmp(dir_entry->d_name , "..", 2 ) != 0) && (dir_entry->d_ino != 0))
- {
- file_name = string(IIO_DIR) + string(dir_entry->d_name) + string(NAME_NODE);
-
- ifstream infile(file_name.c_str());
-
- if (!infile)
- continue;
-
- infile >> hw_name;
-
- if (strncmp(dir_entry->d_name, IIO_DEV_BASE_NAME, IIO_DEV_STR_LEN) == 0)
- {
- if (CConfig::get_instance().is_supported(SENSOR_TYPE_PROXI, hw_name) == true)
- {
- m_name = m_model_id = hw_name;
- m_proxi_dir = string(dir_entry->d_name);
- m_enable_resource = string(IIO_DIR) + m_proxi_dir + string(EVENT_DIR) + string(EVENT_EN_NODE);
- m_event_resource = string(DEV_DIR) + m_proxi_dir;
-
- INFO("m_enable_resource = %s", m_enable_resource.c_str());
- INFO("m_model_id = %s", m_model_id.c_str());
- INFO("m_proxi_dir = %s", m_proxi_dir.c_str());
- INFO("m_event_resource = %s", m_event_resource.c_str());
-
- find_node = true;
- break;
- }
- }
- }
- }
-
- closedir(main_dir);
- return find_node;
-}
-
extern "C" void *create(void)
{
proxi_sensor_hal *inst;
- try
- {
+ try {
inst = new proxi_sensor_hal();
- }
- catch (int err)
- {
- ERR("Failed to create proxi_sensor_hal class, errno : %d, errstr : %s", err, strerror(err));
+ } catch (int err) {
+ ERR("proxi_sensor class create fail , errno : %d , errstr : %s\n", err, strerror(err));
return NULL;
}
- return (void *)inst;
+ return (void*)inst;
}
extern "C" void destroy(void *inst)
{
- delete (proxi_sensor_hal *)inst;
+ delete (proxi_sensor_hal*)inst;
}