SET(ACCEL "ON")
SET(PROXIMITY "ON")
+SET(SENSORHUB "ON")
# Common Options
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O2 -omit-frame-pointer -std=gnu++0x")
#ADD_DEFINITIONS(-Wall -g -D_DEBUG)
INCLUDE(FindPkgConfig)
-PKG_CHECK_MODULES(hal_pkgs REQUIRED dlog)
+PKG_CHECK_MODULES(hal_pkgs REQUIRED dlog glib-2.0 gio-2.0 gobject-2.0 vconf)
FOREACH(flag ${hal_pkgs_LDFLAGS})
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
ADD_DEFINITIONS(-DENABLE_PROXIMITY)
ENDIF()
+IF("${SENSORHUB}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/sensorhub/*.cpp)
+ADD_DEFINITIONS(-DENABLE_SENSORHUB)
+ENDIF()
+
MESSAGE("Sources: ${SRCS}")
ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${hal_pkgs_LDFLAGS})
#include "accel/accel.h"
#include "proxi/proxi.h"
+#include "sensorhub/sensorhub.h"
static std::vector<sensor_device_t> devs;
create_sensor<proxi_device>("Proximity");
#endif
+#ifdef ENABLE_SENSORHUB
+ create_sensor<sensorhub_device>("Sensorhub");
+#endif
+
*devices = &devs[0];
return devs.size();
float values[SENSOR_DATA_VALUE_SIZE];
} sensor_data_t;
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
+#define SENSORHUB_DATA_VALUE_SIZE 4096
+
+/* sensorhub_data_t */
+typedef struct sensorhub_data_t {
+ int accuracy;
+ unsigned long long timestamp;
+ int value_count;
+ char values[SENSORHUB_DATA_VALUE_SIZE];
+} sensorhub_data_t;
-#ifdef __cplusplus
/*
* Create devices
*/
typedef void *sensor_device_t;
typedef int (*create_t)(sensor_device_t **devices);
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#ifdef __cplusplus
/*
* Sensor device interface
* 1 device must be abstracted from 1 device event node
--- /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 <gio/gio.h>
+#include <sensor_logs.h>
+#include "dbus_util.h"
+
+void init_dbus(void)
+{
+}
+
+void fini_dbus(void)
+{
+}
--- /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 _DBUS_UTIL_H_
+#define _DBUS_UTIL_H_
+
+void init_dbus(void);
+void fini_dbus(void);
+
+#endif /* _DBUS_UTIL_H_ */
--- /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 <algorithm>
+#include <sensor_logs.h>
+
+#include "sensorhub.h"
+#include "sensorhub_controller.h"
+#include "sensorhub_manager.h"
+#include "system_state.h"
+
+sensorhub_device::sensorhub_device()
+{
+ controller = new(std::nothrow) sensorhub_controller();
+ if (!controller) {
+ ERR("Failed to allocated memory");
+ throw;
+ }
+
+ manager = new(std::nothrow) sensorhub_manager();
+ if (!manager) {
+ ERR("Failed to allocated memory");
+ throw;
+ }
+ manager->set_controller(controller);
+ system_state_handler::get_instance().set_controller(controller);
+
+ INFO("sensorhub_device is created!");
+}
+
+sensorhub_device::~sensorhub_device()
+{
+ delete controller;
+ delete manager;
+
+ INFO("sensorhub_device is destroyed!");
+}
+
+int sensorhub_device::get_poll_fd(void)
+{
+ return controller->get_poll_fd();
+}
+
+int sensorhub_device::get_sensors(const sensor_handle_t **sensors)
+{
+ int size;
+ size = manager->get_sensors(sensors);
+
+ return size;
+}
+
+bool sensorhub_device::enable(uint16_t id)
+{
+ system_state_handler::get_instance().initialize();
+
+ controller->enable();
+ sensorhub_sensor *sensor = manager->get_sensor(id);
+
+ if (!sensor) {
+ ERR("Failed to enable sensor(0x%x)", id);
+ return false;
+ }
+
+ return sensor->enable();
+}
+
+bool sensorhub_device::disable(uint16_t id)
+{
+ system_state_handler::get_instance().finalize();
+
+ controller->disable();
+ sensorhub_sensor *sensor = manager->get_sensor(id);
+
+ if (!sensor) {
+ ERR("Failed to disable sensor(0x%x)", id);
+ return false;
+ }
+
+ return sensor->disable();
+}
+
+bool sensorhub_device::set_interval(uint16_t id, unsigned long val)
+{
+ sensorhub_sensor *sensor = manager->get_sensor(id);
+
+ if (!sensor) {
+ ERR("Failed to set interval to sensor(0x%x)", id);
+ return false;
+ }
+
+ return sensor->set_interval(val);
+}
+
+bool sensorhub_device::set_batch_latency(uint16_t id, unsigned long val)
+{
+ sensorhub_sensor *sensor = manager->get_sensor(id);
+
+ if (!sensor) {
+ ERR("Failed to set batch latency to sensor(0x%x)", id);
+ return false;
+ }
+
+ return sensor->set_batch_latency(val);
+}
+
+bool sensorhub_device::set_attribute(uint16_t id, int32_t attribute, int32_t value)
+{
+ int ret;
+
+ sensorhub_sensor *sensor = manager->get_sensor(id);
+
+ if (!sensor) {
+ ERR("Failed to set attribute to sensor(0x%x)", id);
+ return false;
+ }
+
+ ret = sensor->set_attribute(attribute, value);
+
+ if ((ret < 0) && (ret != -EBUSY)) {
+ ERR("Failed to send sensorhub data");
+ return false;
+ }
+
+ if (ret == -EBUSY) {
+ WARN("Command is sent during sensorhub firmware update");
+ return false;
+ }
+
+ return true;
+}
+
+bool sensorhub_device::set_attribute_str(uint16_t id, char *attribute, char *value, int value_len)
+{
+ int ret;
+
+ sensorhub_sensor *sensor = manager->get_sensor(id);
+
+ if (!sensor) {
+ ERR("Failed to set attribute to sensor(0x%x)", id);
+ return false;
+ }
+
+ ret = sensor->set_attribute_str(attribute, value, value_len);
+
+ if ((ret < 0) && (ret != -EBUSY)) {
+ ERR("Failed to send sensorhub data");
+ return false;
+ }
+
+ if (ret == -EBUSY) {
+ WARN("Command is sent during sensorhub firmware update");
+ return false;
+ }
+
+ return true;
+}
+
+int sensorhub_device::read_fd(uint16_t **ids)
+{
+ sensorhub_data_t data;
+
+ // step 1
+ if (!controller->read_fd(data))
+ return 0;
+
+ // step 2
+ const char *hub_data = data.values;
+ int data_len = data.value_count;
+
+ // step 3
+ event_ids.clear();
+
+ while (data_len > 0) {
+ DBG("Remaining data length: %d", data_len);
+ int parsed = parse(hub_data, data_len);
+ if (parsed < 0) {
+ ERR("Parsing failed");
+ break;
+ }
+
+ data_len -= parsed;
+ hub_data += parsed;
+ }
+
+ // step 4
+ int size = event_ids.size();
+
+ if (event_ids.empty())
+ return 0;
+
+ *ids = &event_ids[0];
+
+ return size;
+}
+
+int sensorhub_device::get_data(uint16_t id, sensor_data_t **data, int *length)
+{
+ int remains = 1;
+
+ sensorhub_sensor *sensor = manager->get_sensor(id);
+ if (!sensor) {
+ ERR("Failed to get data from sensor(0x%x)", id);
+ return -1;
+ }
+
+ remains = sensor->get_data(data, length);
+
+ return remains;
+}
+
+bool sensorhub_device::flush(uint16_t id)
+{
+ return false;
+}
+
+int sensorhub_device::parse(const char *hub_data, int data_len)
+{
+ return parse_data(hub_data, data_len);
+}
+
+int sensorhub_device::parse_data(const char *hub_data, int data_len)
+{
+ const char *cursor = hub_data;
+ char libtype = 0;
+
+ sensorhub_sensor *sensor = manager->get_sensor(libtype);
+ if (!sensor) {
+ ERR("Unknown Sensorhub lib type: %d", libtype);
+ return -1;
+ }
+
+ event_ids.push_back(sensor->get_id());
+
+ return sensor->parse(cursor, data_len);
+}
+
+int sensorhub_device::parse_debug(const char *hub_data, int data_len)
+{
+ return 0;
+}
+
--- /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 _SENSORHUB_DEVICE_H_
+#define _SENSORHUB_DEVICE_H_
+
+#include <vector>
+#include <sensor_hal.h>
+
+#include "sensorhub_controller.h"
+#include "sensorhub_manager.h"
+
+class sensorhub_device : public sensor_device {
+public:
+ sensorhub_device();
+ virtual ~sensorhub_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 *key, 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:
+ sensorhub_manager *manager;
+ sensorhub_controller *controller;
+ std::vector<uint16_t> event_ids;
+
+ int parse(const char *hub_data, int data_len);
+ int parse_data(const char *hub_data, int data_len);
+ int parse_debug(const char *hub_data, int data_len);
+};
+
+#endif /* _SENSORHUB_DEVICE_H_ */
--- /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 <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <linux/input.h>
+#include <sys/ioctl.h>
+#include <fstream>
+
+#include <sensor_logs.h>
+#include <util.h>
+#include "sensorhub_controller.h"
+
+sensorhub_controller::sensorhub_controller()
+: m_enabled(false)
+, m_poll_node(-1)
+, m_data_node(-1)
+{
+}
+
+sensorhub_controller::~sensorhub_controller()
+{
+}
+
+int sensorhub_controller::get_poll_fd(void)
+{
+ return -1;
+}
+
+bool sensorhub_controller::enable(void)
+{
+ m_enabled = true;
+ INFO("Enable Sensorhub");
+ return true;
+}
+
+bool sensorhub_controller::disable(void)
+{
+ m_enabled = false;
+ INFO("Disable Sensorhub");
+ return true;
+}
+
+int sensorhub_controller::open_input_node(const char* input_node)
+{
+ return -1;
+}
+
+bool sensorhub_controller::read_fd(sensorhub_data_t &data)
+{
+ return false;
+}
+
+int sensorhub_controller::read_sensorhub_data(void)
+{
+ return -1;
+}
+
+int sensorhub_controller::read_large_sensorhub_data(void)
+{
+ return -1;
+}
+
+int sensorhub_controller::send_sensorhub_data(const char *data, int data_len)
+{
+ return -1;
+}
+
+int sensorhub_controller::print_sensorhub_data(const char* name, const char *data, int length)
+{
+ return 0;
+}
+
--- /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 _SENSORHUB_CONTROLLER_H_
+#define _SENSORHUB_CONTROLLER_H_
+
+#include <sensor_hal.h>
+
+class sensorhub_controller {
+public:
+ sensorhub_controller();
+ virtual ~sensorhub_controller();
+
+ int open_input_node(const char* input_node);
+ int get_poll_fd(void);
+
+ bool enable(void);
+ bool disable(void);
+
+ bool read_fd(sensorhub_data_t &data);
+
+ int read_sensorhub_data(void);
+ int read_large_sensorhub_data(void);
+ int send_sensorhub_data(const char *data, int data_len);
+
+private:
+ bool m_enabled;
+ int m_poll_node;
+ int m_data_node;
+
+ int print_sensorhub_data(const char* name, const char *data, int length);
+};
+
+#endif /* _SENSORHUB_CONTROLLER_H_ */
--- /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 "sensorhub_controller.h"
+#include "sensorhub_manager.h"
+#include "sensorhub_sensor.h"
+
+std::map<uint16_t, sensorhub_sensor *> sensorhub_manager::m_id_sensor;
+std::map<char, sensorhub_sensor *> sensorhub_manager::m_key_sensor;
+std::vector<sensor_handle_t> sensorhub_manager::m_handles;
+
+sensorhub_manager::sensorhub_manager()
+{
+}
+
+sensorhub_manager::~sensorhub_manager()
+{
+ for (auto &it : m_id_sensor)
+ delete it.second;
+
+ m_id_sensor.clear();
+ m_key_sensor.clear();
+ m_handles.clear();
+}
+
+bool sensorhub_manager::add_sensor(sensor_handle_t handle, char key, sensorhub_sensor *sensor)
+{
+ m_handles.push_back(handle);
+ m_id_sensor[handle.id] = sensor;
+ m_key_sensor[key] = sensor;
+
+ return true;
+}
+
+void sensorhub_manager::set_controller(sensorhub_controller *controller)
+{
+ for (auto const &it : m_id_sensor) {
+ sensorhub_sensor *sensor = it.second;
+ sensor->set_controller(controller);
+ }
+}
+
+sensorhub_sensor *sensorhub_manager::get_sensor(uint16_t id)
+{
+ return m_id_sensor[id];
+}
+
+sensorhub_sensor *sensorhub_manager::get_sensor(char key)
+{
+ return m_key_sensor[key];
+}
+
+int sensorhub_manager::get_sensors(const sensor_handle_t **sensors)
+{
+ int size;
+
+ if (m_handles.empty()) {
+ *sensors = 0;
+ return 0;
+ }
+
+ size = m_handles.size();
+ *sensors = &m_handles[0];
+
+ return 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.
+ *
+ */
+
+#ifndef _SENSORHUB_MANAGER_H_
+#define _SENSORHUB_MANAGER_H_
+
+#include <map>
+#include <vector>
+
+#include "sensorhub_controller.h"
+#include "sensorhub_sensor.h"
+
+#define REGISTER_SENSOR(handle, key, sensor_class) \
+static void __attribute__((constructor)) add_sensorhub_sensor(void) \
+{ \
+ sensorhub_sensor *sensor = new(std::nothrow) (sensor_class)(); \
+ if (!sensor) { \
+ _E("ERROR: Failed to allocate memory(%s)", #sensor_class); \
+ return; \
+ } \
+ sensorhub_manager::add_sensor((handle), (key), (sensor)); \
+}
+
+class sensorhub_manager {
+public:
+ sensorhub_manager();
+ virtual ~sensorhub_manager();
+
+ sensorhub_sensor *get_sensor(uint16_t id);
+ sensorhub_sensor *get_sensor(char key);
+ int get_sensors(const sensor_handle_t **sensors);
+
+ void set_controller(sensorhub_controller *controller);
+
+ static bool add_sensor(sensor_handle_t handle, char key, sensorhub_sensor *sensor);
+private:
+ static std::map<uint16_t, sensorhub_sensor *> m_id_sensor;
+ static std::map<char, sensorhub_sensor *> m_key_sensor;
+ static std::vector<sensor_handle_t> m_handles;
+};
+#endif /* _SENSORHUB_MANAGER_H_ */
--- /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 <sensor_logs.h>
+#include <time.h>
+#include "sensorhub_controller.h"
+#include "sensorhub_sensor.h"
+
+void sensorhub_sensor::set_controller(sensorhub_controller *controller)
+{
+ m_controller = controller;
+}
+
+bool sensorhub_sensor::set_interval(unsigned long val)
+{
+ return false;
+}
+
+bool sensorhub_sensor::set_batch_latency(unsigned long val)
+{
+ return false;
+}
+
+bool sensorhub_sensor::set_attribute(int32_t attribute, int32_t value)
+{
+ return false;
+}
+
+bool sensorhub_sensor::set_attribute_str(char *attribute, char *value, int value_len)
+{
+ return false;
+}
+
+bool sensorhub_sensor::flush(void)
+{
+ return false;
+}
+
+unsigned long long sensorhub_sensor::get_timestamp(void)
+{
+ struct timespec t;
+ clock_gettime(CLOCK_REALTIME, &t);
+ return ((unsigned long long)(t.tv_sec)*1000000000LL + t.tv_nsec) / 1000;
+}
+
--- /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 _SENSORHUB_SENSOR_H_
+#define _SENSORHUB_SENSOR_H_
+
+class sensorhub_sensor {
+public:
+ sensorhub_sensor() {}
+ virtual ~sensorhub_sensor() {}
+
+ virtual int16_t get_id(void) = 0;
+
+ virtual bool enable(void) = 0;
+ virtual bool disable(void) = 0;
+ virtual int parse(const char *hub_data, int data_len) = 0;
+ virtual int get_data(sensor_data_t **data, int *length) = 0;
+
+ void set_controller(sensorhub_controller *controller);
+
+ virtual bool set_interval(unsigned long val);
+ virtual bool set_batch_latency(unsigned long val);
+ virtual bool set_attribute(int32_t attribute, int32_t value);
+ virtual bool set_attribute_str(char *key, char *value, int value_len);
+
+ virtual bool flush(void);
+protected:
+ sensorhub_controller *m_controller;
+
+ unsigned long long get_timestamp(void);
+};
+
+#endif /* _SENSORHUB_SENSOR_H_ */
--- /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 <sensor_logs.h>
+#include "dbus_util.h"
+#include "system_state.h"
+
+#define CPU_BOOST_DURATION 400
+#define WAKEUP_LCD_CUSTOM_PARAM 7000
+
+system_state_handler::system_state_handler()
+{
+}
+
+system_state_handler::~system_state_handler()
+{
+ INFO("system_state_handler is destroyed!\n");
+}
+
+system_state_handler& system_state_handler::get_instance()
+{
+ static system_state_handler instance;
+ return instance;
+}
+
+void system_state_handler::set_controller(sensorhub_controller *controller)
+{
+ m_controller = controller;
+}
+
+bool system_state_handler::initialize()
+{
+ return true;
+}
+
+void system_state_handler::finalize(void)
+{
+}
+
+void system_state_handler::set_poweroff_state(void)
+{
+}
+
+void system_state_handler::display_signal_handler(GDBusConnection *conn,
+ const gchar *name, const gchar *path, const gchar *interface,
+ const gchar *sig, GVariant *param, gpointer user_data)
+{
+}
+
+bool system_state_handler::start_listen_display_state()
+{
+ return true;
+}
+
+void system_state_handler::stop_listen_display_state()
+{
+
+}
+
+void system_state_handler::poweroff_signal_handler(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface,
+ const gchar *sig, GVariant *param, gpointer user_data)
+{
+}
+
+bool system_state_handler::start_listen_poweroff_state(void)
+{
+ return true;
+}
+
+void system_state_handler::stop_listen_poweroff_state(void)
+{
+}
+
+void system_state_handler::charger_state_cb(keynode_t *node, void *user_data)
+{
+}
+
+bool system_state_handler::is_display_on(void)
+{
+ return true;
+}
+
+bool system_state_handler::inform_display_state(bool display_on)
+{
+ return inform_display_state();
+}
+
+bool system_state_handler::inform_display_state()
+{
+ return true;
+}
+
+bool system_state_handler::is_charger_connected(void)
+{
+ return false;
+}
+
+bool system_state_handler::is_powering_off()
+{
+ return false;
+}
+
+bool system_state_handler::inform_charger_state()
+{
+ return true;
+}
+
+bool system_state_handler::inform_ssp_sleep(void)
+{
+ return true;
+}
+
+bool system_state_handler::inform_ssp_wakeup(void)
+{
+ return true;
+}
+
+bool system_state_handler::inform_current_time(void)
+{
+ return true;
+}
+
+void system_state_handler::request_display_lock(int msec)
+{
+ return;
+}
+
+void system_state_handler::request_display_wakeup()
+{
+ return;
+}
--- /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 _SYSTEM_STATE_HANDLER_H_
+#define _SYSTEM_STATE_HANDLER_H_
+
+#include <glib.h>
+#include <vconf.h>
+#include <gio/gio.h>
+
+#include "sensorhub_controller.h"
+
+class system_state_handler {
+private:
+ system_state_handler();
+ ~system_state_handler();
+
+ void set_poweroff_state(void);
+
+ bool start_listen_display_state(void);
+ bool start_listen_poweroff_state(void);
+ void stop_listen_display_state(void);
+ void stop_listen_poweroff_state(void);
+
+ bool inform_display_state(bool display_on);
+ bool inform_display_state(void);
+ bool inform_ssp_sleep(void);
+ bool inform_ssp_wakeup(void);
+
+ static void display_signal_handler(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface,
+ const gchar *sig, GVariant *param, gpointer user_data);
+
+ static void poweroff_signal_handler(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface,
+ const gchar *sig, GVariant *param, gpointer user_data);
+
+ static void display_state_cb(keynode_t *node, void *user_data);
+ static void charger_state_cb(keynode_t *node, void *user_data);
+ static void sleep_state_cb(keynode_t *node, void *user_data);
+
+ sensorhub_controller *m_controller;
+
+public:
+ void set_controller(sensorhub_controller *controller);
+ bool initialize(void);
+ void finalize(void);
+
+ bool is_display_on(void);
+ bool is_charger_connected(void);
+ bool is_powering_off(void);
+
+ bool inform_charger_state(void);
+ bool inform_current_time(void);
+ void request_display_lock(int msec);
+ void request_display_wakeup(void);
+
+ static system_state_handler& get_instance(void);
+};
+
+#endif
--- /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 <algorithm>
+#include <sensor_hal.h>
+#include <sensor_logs.h>
+
+#include "sensorhub_manager.h"
+#include "system_state.h"
+#include "wristup.h"
+
+#define SENSOR_NAME "WRIST_UP_SENSOR"
+#define SHUB_LIB_WRIST_UP 0
+#define WRIST_UP_PACKET_SIZE 1
+
+static const sensor_handle_t handle = {
+ id: 0x1,
+ name: SENSOR_NAME,
+ type: SENSOR_DEVICE_GESTURE_WRIST_UP,
+ event_type: (SENSOR_DEVICE_GESTURE_WRIST_UP << 16) | 0x0001,
+ model_name: "Wristup",
+ vendor: "Samsung Electronics",
+ min_range: 0,
+ max_range: 1,
+ resolution: 1,
+ min_interval: 0,
+ max_batch_count: 0,
+ wakeup_supported: true
+};
+
+wristup_sensor::wristup_sensor()
+{
+}
+
+wristup_sensor::~wristup_sensor()
+{
+ INFO("wristup_sensor is destroyed!");
+}
+
+int16_t wristup_sensor::get_id(void)
+{
+ return handle.id;
+}
+
+bool wristup_sensor::enable(void)
+{
+ return false;
+}
+
+bool wristup_sensor::disable(void)
+{
+ return false;
+}
+
+int wristup_sensor::parse(const char *data, int data_len)
+{
+ return WRIST_UP_PACKET_SIZE;
+}
+
+int wristup_sensor::get_data(sensor_data_t **data, int *length)
+{
+ return -1;
+}
+
+bool wristup_sensor::set_attribute(int32_t attribute, int32_t value)
+{
+ return false;
+}
+
+bool wristup_sensor::set_attribute_str(char *key, char *value, int value_len)
+{
+ return false;
+}
+
+REGISTER_SENSOR(handle, (char)SHUB_LIB_WRIST_UP, wristup_sensor)
--- /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 _WRISTUP_SENSOR_H_
+#define _WRISTUP_SENSOR_H_
+
+#include "sensorhub_sensor.h"
+
+class wristup_sensor : public sensorhub_sensor {
+public:
+ wristup_sensor();
+ virtual ~wristup_sensor();
+
+ int16_t get_id(void);
+
+ bool enable(void);
+ bool disable(void);
+
+ int parse(const char *data, int data_len);
+ int get_data(sensor_data_t **data, int *length);
+
+ bool set_attribute(int32_t attribute, int32_t value);
+ bool set_attribute_str(char *attribute, char *value, int value_len);
+
+private:
+ sensorhub_data_t m_data;
+};
+
+#endif /* _WRISTUP_SENSOR_H_ */