SET(ACCEL "ON")
-SET(PROXIMITY "OFF")
+SET(PROXIMITY "ON")
# Common Options
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O2 -omit-frame-pointer -std=gnu++0x")
ENDIF()
IF("${PROXIMITY}" STREQUAL "ON")
-FILE(GLOB_RECURSE SRCS ${SRCS} src/proximity/*.cpp)
+FILE(GLOB_RECURSE SRCS ${SRCS} src/proxi/*.cpp)
ADD_DEFINITIONS(-DENABLE_PROXIMITY)
ENDIF()
/*
- * sensor-plugins-tm1
- *
* Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
#include <sensor_logs.h>
#include <vector>
-#ifdef ENABLE_ACCEL
#include "accel/accel.h"
-#endif
-#ifdef ENABLE_PROXIMITY
-#include "proximity/proxi.h"
-#endif
+#include "proxi/proxi.h"
static std::vector<sensor_device_t> devs;
extern "C" int create(sensor_device_t **devices)
{
- int size;
- sensor_device_t *_devices;
-
#ifdef ENABLE_ACCEL
create_sensor<accel_device>("Accel");
#endif
#ifdef ENABLE_PROXIMITY
- create_sensor<proxi_sensor_device>("Proximity");
+ create_sensor<proxi_device>("Proximity");
#endif
- size = devs.size();
- _devices = (sensor_device_t *)malloc(size * sizeof(sensor_device_t));
- retvm_if(!_devices, 0, "Failed to allocate memory");
-
- for (int i = 0; i < size; ++i)
- _devices[i] = devs[i];
-
- *devices = _devices;
+ *devices = &devs[0];
- return size;
+ return devs.size();
}
--- /dev/null
+/*
+ * 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.
+ * 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.
+ *
+ */
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <linux/input.h>
+#include <util.h>
+#include <sensor_logs.h>
+
+#include "proxi.h"
+
+#define MODEL_NAME "IMS1911"
+#define VENDOR "ITM"
+#define MIN_RANGE 0
+#define MAX_RANGE 5
+#define RESOLUTION 1
+#define MIN_INTERVAL 1
+#define MAX_BATCH_COUNT 0
+
+#define SENSORHUB_PROXIMITY_ENABLE_BIT 7
+
+static const sensor_handle_t handle = {
+ id: 0x1,
+ name: "Proximity Sensor",
+ type: SENSOR_DEVICE_PROXIMITY,
+ event_type: (SENSOR_DEVICE_PROXIMITY << 16) | 0x0001,
+ model_name: MODEL_NAME,
+ vendor: VENDOR,
+ min_range: MIN_RANGE,
+ max_range: MAX_RANGE,
+ resolution: RESOLUTION,
+ min_interval: MIN_INTERVAL,
+ max_batch_count: MAX_BATCH_COUNT,
+ wakeup_supported: false
+};
+
+std::vector<uint16_t> proxi_device::event_ids;
+
+proxi_device::proxi_device()
+: m_node_handle(-1)
+, m_state(-1)
+, m_fired_time(0)
+, m_sensorhub_controlled(false)
+{
+ const std::string sensorhub_interval_node_name = "prox_poll_delay";
+
+ node_info_query query;
+ node_info info;
+
+ query.sensorhub_controlled = m_sensorhub_controlled = util::is_sensorhub_controlled(sensorhub_interval_node_name);
+ query.sensor_type = "PROXI";
+ query.key = "proximity_sensor";
+ query.iio_enable_node_name = "proximity_enable";
+ query.sensorhub_interval_node_name = sensorhub_interval_node_name;
+
+ if (!util::get_node_info(query, info)) {
+ ERR("Failed to get node info");
+ throw ENXIO;
+ }
+
+ util::show_node_info(info);
+
+ m_data_node = info.data_node_path;
+ m_enable_node = info.enable_node_path;
+
+ if ((m_node_handle = open(m_data_node.c_str(), O_RDWR)) < 0) {
+ ERR("accel handle open fail for accel processor, error:%s", strerror(errno));
+ throw ENXIO;
+ }
+
+ INFO("proxi_device is created!");
+}
+
+proxi_device::~proxi_device()
+{
+ close(m_node_handle);
+ m_node_handle = -1;
+
+ INFO("proxi_device is destroyed!");
+}
+
+int proxi_device::get_poll_fd()
+{
+ return m_node_handle;
+}
+
+int proxi_device::get_sensors(const sensor_handle_t **sensors)
+{
+ *sensors = &handle;
+
+ return 1;
+}
+
+bool proxi_device::enable(uint16_t id)
+{
+ util::set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_PROXIMITY_ENABLE_BIT);
+
+ m_fired_time = 0;
+ INFO("Enable proximity sensor");
+ return true;
+}
+
+bool proxi_device::disable(uint16_t id)
+{
+ util::set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_PROXIMITY_ENABLE_BIT);
+
+ INFO("Disable proximity sensor");
+ return true;
+}
+
+bool proxi_device::set_interval(uint16_t id, unsigned long interval_ms)
+{
+ return true;
+}
+
+bool proxi_device::set_batch_latency(uint16_t id, unsigned long val)
+{
+ return false;
+}
+
+bool proxi_device::set_attribute(uint16_t id, int32_t attribute, int32_t value)
+{
+ return false;
+}
+
+bool proxi_device::set_attribute_str(uint16_t id, char *attribute, char *value, int value_len)
+{
+ return false;
+}
+
+bool proxi_device::update_value_input_event(void)
+{
+ struct input_event proxi_event;
+ DBG("proxi event detection!");
+
+ int len = read(m_node_handle, &proxi_event, sizeof(proxi_event));
+
+ if (len == -1) {
+ DBG("read(m_node_handle) is error:%s", strerror(errno));
+ return false;
+ }
+
+ if ((proxi_event.type == EV_ABS) && (proxi_event.code == ABS_DISTANCE)) {
+ m_state = proxi_event.value;
+ m_fired_time = util::get_timestamp(&proxi_event.time);
+
+ DBG("m_state = %d, time = %lluus", m_state, m_fired_time);
+
+ return true;
+ }
+
+ return false;
+}
+
+int proxi_device::read_fd(uint16_t **ids)
+{
+ if (!update_value_input_event()) {
+ DBG("Failed to update value");
+ return false;
+ }
+
+ event_ids.clear();
+ event_ids.push_back(handle.id);
+
+ *ids = &event_ids[0];
+
+ return event_ids.size();
+}
+
+int proxi_device::get_data(uint16_t id, sensor_data_t **data, int *length)
+{
+ int remains = 1;
+ sensor_data_t *sensor_data;
+ sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
+
+ sensor_data->accuracy = SENSOR_ACCURACY_GOOD;
+ sensor_data->timestamp = m_fired_time;
+ sensor_data->value_count = 1;
+ sensor_data->values[0] = m_state;
+
+ *data = sensor_data;
+ *length = sizeof(sensor_data_t);
+
+ return --remains;
+}
+
+bool proxi_device::flush(uint16_t id)
+{
+ return false;
+}
--- /dev/null
+/*
+ * 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.
+ * 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 _PROXI_DEVICE_H_
+#define _PROXI_DEVICE_H_
+
+#include <sensor_hal.h>
+#include <string>
+#include <vector>
+
+class proxi_device : public sensor_device
+{
+public:
+ proxi_device();
+ virtual ~proxi_device();
+
+ int get_poll_fd(void);
+ int get_sensors(const sensor_handle_t **sensors);
+
+ 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 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);
+
+ bool flush(uint16_t id);
+
+private:
+ int m_node_handle;
+ unsigned int m_state;
+ unsigned long long m_fired_time;
+ bool m_sensorhub_controlled;
+
+ std::string m_data_node;
+ std::string m_enable_node;
+
+ static std::vector<uint16_t> event_ids;
+
+ bool update_value_input_event(void);
+};
+#endif /*_PROXI_DEVICE_H_*/
+++ /dev/null
-/*
- * proxi_sensor_device
- *
- * 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.
- *
- */
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <dirent.h>
-#include <linux/input.h>
-#include <util.h>
-#include "proxi.h"
-
-#define MODEL_NAME "K2HH"
-#define VENDOR "ST Microelectronics"
-#define MIN_RANGE 0
-#define MAX_RANGE 5
-#define RESOLUTION 1
-#define MIN_INTERVAL 1
-#define FIFO_COUNT 0
-#define MAX_BATCH_COUNT 0
-
-static const sensor_properties_s proxi_properties = {
- name : MODEL_NAME,
- vendor : VENDOR,
- min_range : MIN_RANGE,
- max_range : MAX_RANGE,
- resolution : RESOLUTION,
- min_interval : MIN_INTERVAL,
- fifo_count : FIFO_COUNT,
- max_batch_count : MAX_BATCH_COUNT,
-};
-
-static const sensor_handle_t handles[] = {
- {
- id: 0x1,
- name: "Proximity Sensor",
- type: SENSOR_DEVICE_PROXIMITY,
- event_type: (SENSOR_DEVICE_PROXIMITY << 16) | 0x0001,
- properties : proxi_properties
- }
-};
-
-proxi_sensor_device::proxi_sensor_device()
-: m_node_handle(-1)
-, m_state(-1)
-, m_fired_time(0)
-, m_sensorhub_controlled(false)
-{
- const std::string sensorhub_interval_node_name = "prox_poll_delay";
-
- node_info_query query;
- node_info info;
-
- query.sensorhub_controlled = m_sensorhub_controlled = util::is_sensorhub_controlled(sensorhub_interval_node_name);
- query.sensor_type = "PROXI";
- query.key = "proximity_sensor";
- query.iio_enable_node_name = "proximity_enable";
- query.sensorhub_interval_node_name = sensorhub_interval_node_name;
-
- if (!util::get_node_info(query, info)) {
- ERR("Failed to get node info");
- throw ENXIO;
- }
-
- util::show_node_info(info);
-
- m_data_node = info.data_node_path;
- m_enable_node = info.enable_node_path;
-
- if ((m_node_handle = open(m_data_node.c_str(), O_RDWR)) < 0) {
- ERR("accel handle open fail for accel processor, error:%s\n", strerror(errno));
- throw ENXIO;
- }
-
- INFO("Proxi_sensor_device is created!\n");
-}
-
-proxi_sensor_device::~proxi_sensor_device()
-{
- close(m_node_handle);
- m_node_handle = -1;
-
- INFO("Proxi_sensor_device is destroyed!\n");
-}
-
-bool proxi_sensor_device::get_sensors(std::vector<sensor_handle_t> &sensors)
-{
- int size = ARRAY_SIZE(handles);
-
- for (int i = 0; i < size; ++i)
- sensors.push_back(handles[i]);
-
- return true;
-}
-
-bool proxi_sensor_device::enable(uint32_t id)
-{
- util::set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_PROXIMITY_ENABLE_BIT);
-
- m_fired_time = 0;
- INFO("Enable proximity sensor");
- return true;
-}
-
-bool proxi_sensor_device::disable(uint32_t id)
-{
- util::set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_PROXIMITY_ENABLE_BIT);
-
- INFO("Disable proximity sensor");
- return true;
-}
-
-int proxi_sensor_device::get_poll_fd()
-{
- return m_node_handle;
-}
-
-bool proxi_sensor_device::set_interval(uint32_t id, unsigned long interval_ms)
-{
- return true;
-}
-
-bool proxi_sensor_device::set_batch_latency(uint32_t id, unsigned long val)
-{
- return false;
-}
-
-bool proxi_sensor_device::set_command(uint32_t id, std::string command, std::string value)
-{
- return false;
-}
-
-bool proxi_sensor_device::is_data_ready(void)
-{
- bool ret;
- ret = update_value();
- return ret;
-}
-
-bool proxi_sensor_device::update_value(void)
-{
- struct input_event proxi_event;
- DBG("proxi event detection!");
-
- int len = read(m_node_handle, &proxi_event, sizeof(proxi_event));
-
- if (len == -1) {
- DBG("read(m_node_handle) is error:%s.\n", strerror(errno));
- return false;
- }
-
- if ((proxi_event.type == EV_ABS) && (proxi_event.code == ABS_DISTANCE)) {
- m_state = proxi_event.value;
- m_fired_time = util::get_timestamp(&proxi_event.time);
-
- DBG("m_state = %d, time = %lluus", m_state, m_fired_time);
-
- return true;
- }
-
- return false;
-}
-
-bool proxi_sensor_device::get_sensor_data(uint32_t id, sensor_data_t &data)
-{
- data.accuracy = SENSOR_ACCURACY_UNDEFINED;
- data.timestamp = m_fired_time;
- data.value_count = 1;
- data.values[0] = m_state;
-
- return true;
-}
-
-int proxi_sensor_device::get_sensor_event(uint32_t id, sensor_event_t **event)
-{
- sensor_event_t *sensor_event;
- sensor_event = (sensor_event_t *)malloc(sizeof(sensor_event_t));
-
- sensor_event->data.accuracy = SENSOR_ACCURACY_GOOD;
- sensor_event->data.timestamp = m_fired_time;
- sensor_event->data.value_count = 1;
- sensor_event->data.values[0] = m_state;
-
- *event = sensor_event;
-
- return sizeof(sensor_event_t);
-}
-
-bool proxi_sensor_device::get_properties(uint32_t id, sensor_properties_s &properties)
-{
- properties.name = MODEL_NAME;
- properties.vendor = VENDOR;
- properties.min_range = proxi_properties.min_range;
- properties.max_range = proxi_properties.max_range;
- properties.min_interval = proxi_properties.min_interval;
- properties.resolution = proxi_properties.resolution;
- properties.fifo_count = proxi_properties.fifo_count;
- properties.max_batch_count = proxi_properties.max_batch_count;
- return true;
-}
+++ /dev/null
-/*
- * proxi_sensor_device
- *
- * 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 _PROXI_SENSOR_DEVICE_H_
-#define _PROXI_SENSOR_DEVICE_H_
-
-#include <sensor_hal.h>
-
-class proxi_sensor_device : public sensor_device
-{
-public:
- proxi_sensor_device();
- virtual ~proxi_sensor_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 ms_interval);
- 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);
-
-private:
- int m_node_handle;
- unsigned int m_state;
- unsigned long long m_fired_time;
- bool m_sensorhub_controlled;
-
- std::string m_data_node;
- std::string m_enable_node;
-
- bool update_value(void);
-};
-#endif /*_PROXI_SENSOR_DEVICE_H_*/