diff options
author | Avichal <avichal.a@samsung.com> | 2019-04-29 17:03:00 +0530 |
---|---|---|
committer | Avichal <avichal.a@samsung.com> | 2019-04-29 17:04:21 +0530 |
commit | 3224cae2e278f483fb32080a3d6b6e31c8f7cd46 (patch) | |
tree | 77add00245d1b6c8537c7855cb4be29c6cef62ca | |
parent | e8afd826619329657b057b7f175c09634e2f7e7b (diff) | |
download | sensor-hal-tw2-accepted/tizen_unified.tar.gz sensor-hal-tw2-accepted/tizen_unified.tar.bz2 sensor-hal-tw2-accepted/tizen_unified.zip |
Update sensor HAL for TW3 and TW2tizen_6.0.m2_releasetizen_5.5.m2_releasesubmit/tizen_6.0_hotfix/20201103.114801submit/tizen_6.0_hotfix/20201102.192501submit/tizen_6.0/20201029.205101submit/tizen_5.5_wearable_hotfix/20201026.184301submit/tizen_5.5_mobile_hotfix/20201026.185101submit/tizen_5.5/20191031.000010submit/tizen/20190429.122510accepted/tizen/unified/20190429.224433accepted/tizen/6.0/unified/hotfix/20201103.052413accepted/tizen/6.0/unified/20201030.124009accepted/tizen/5.5/unified/wearable/hotfix/20201027.123523accepted/tizen/5.5/unified/mobile/hotfix/20201027.082300accepted/tizen/5.5/unified/20191031.004208tizen_6.0_hotfixtizen_6.0tizen_5.5_wearable_hotfixtizen_5.5_tvtizen_5.5_mobile_hotfixtizen_5.5tizenaccepted/tizen_unifiedaccepted/tizen_6.0_unified_hotfixaccepted/tizen_6.0_unifiedaccepted/tizen_5.5_unified_wearable_hotfixaccepted/tizen_5.5_unified_mobile_hotfixaccepted/tizen_5.5_unified
- Using 64bit Timestamp
- Remove uneccessary log
Merged from kibak patch
Change-Id: I250d598d6cd8e3832ff0942cdb0c89b0b95c17e2
Signed-off-by: Avichal <avichal.a@samsung.com>
-rwxr-xr-x | src/gyro/gyro_device.cpp | 2 | ||||
-rwxr-xr-x | src/hrm/hrm_device.cpp | 22 | ||||
-rwxr-xr-x | src/hrm_raw/hrm_raw_device.cpp | 28 | ||||
-rwxr-xr-x | src/light/light_device.cpp | 1 | ||||
-rw-r--r-- | src/macro.h | 4 | ||||
-rwxr-xr-x | src/pressure/pressure_device.cpp | 56 | ||||
-rw-r--r-- | src/pressure/pressure_device.h | 5 |
7 files changed, 97 insertions, 21 deletions
diff --git a/src/gyro/gyro_device.cpp b/src/gyro/gyro_device.cpp index d82b141..2e3155a 100755 --- a/src/gyro/gyro_device.cpp +++ b/src/gyro/gyro_device.cpp @@ -176,7 +176,6 @@ bool gyro_device::update_value_input_event(void) x = y = z = false; struct input_event gyro_input; - _D("gyro event detection"); while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) { int len = read(m_node_handle, &gyro_input, sizeof(gyro_input)); @@ -216,7 +215,6 @@ bool gyro_device::update_value_input_event(void) default: _E("gyro_input event[type = %d, code = %d] is unknown.", gyro_input.type, gyro_input.code); return false; - break; } } else if (gyro_input.type == EV_SYN) { syn = true; diff --git a/src/hrm/hrm_device.cpp b/src/hrm/hrm_device.cpp index c96615a..961f249 100755 --- a/src/hrm/hrm_device.cpp +++ b/src/hrm/hrm_device.cpp @@ -183,7 +183,6 @@ bool hrm_device::update_value_input_event(void) bool syn = false; struct input_event hrm_input; - _D("hrm event detection"); while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) { int len = read(m_node_handle, &hrm_input, sizeof(hrm_input)); @@ -205,20 +204,35 @@ bool hrm_device::update_value_input_event(void) case REL_Z: hrm_raw[2] = (int)hrm_input.value - 1; break; + case REL_Z + 1: + fired_time |= SHORT_TO_UINT64(hrm_input.value, 48); + break; + case REL_Z + 2: + fired_time |= SHORT_TO_UINT64(hrm_input.value, 32); + break; + case REL_Z + 3: + fired_time |= SHORT_TO_UINT64(hrm_input.value, 16); + break; + case REL_Z + 4: + fired_time |= SHORT_TO_UINT64(hrm_input.value, 0); + break; default: _E("hrm_input event[type = %d, code = %d] is unknown.", hrm_input.type, hrm_input.code); return false; - break; } } else if (hrm_input.type == EV_SYN) { syn = true; - fired_time = util::get_timestamp(&hrm_input.time); } else { _E("hrm_input event[type = %d, code = %d] is unknown.", hrm_input.type, hrm_input.code); return false; } } + if (syn == false) { + _E("EV_SYN didn't come until %d inputs had come", read_input_cnt); + return false; + } + if (hrm_raw[0] * RAW_DATA_UNIT > HR_MAX) { _E("Drop abnormal HR: %d", hrm_raw[0]); return false; @@ -228,7 +242,7 @@ bool hrm_device::update_value_input_event(void) m_peek_to_peek = hrm_raw[1]; m_snr = ((float)hrm_raw[2] / SNR_SIG_FIGS); m_spo2 = 0; - m_fired_time = fired_time; + m_fired_time = fired_time / 1000; /* ns to us */ return true; } diff --git a/src/hrm_raw/hrm_raw_device.cpp b/src/hrm_raw/hrm_raw_device.cpp index a0a00d4..5fedc22 100755 --- a/src/hrm_raw/hrm_raw_device.cpp +++ b/src/hrm_raw/hrm_raw_device.cpp @@ -223,6 +223,7 @@ bool hrm_raw_device::update_value_input_event(void) bool syn = false; int read_input_cnt = 0; int index = 0; + unsigned long long fired_time = 0; struct input_event hrm_raw_input; while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) { @@ -235,7 +236,22 @@ bool hrm_raw_device::update_value_input_event(void) ++read_input_cnt; if (hrm_raw_input.type == EV_REL) { - index = hrm_raw_input.code - REL_X; + switch (hrm_raw_input.code) { + case REL_MISC + 1: + fired_time |= SHORT_TO_UINT64(hrm_raw_input.value, 48); + break; + case REL_MISC + 2: + fired_time |= SHORT_TO_UINT64(hrm_raw_input.value, 32); + break; + case REL_MISC + 3: + fired_time |= SHORT_TO_UINT64(hrm_raw_input.value, 16); + break; + case REL_MISC + 4: + fired_time |= SHORT_TO_UINT64(hrm_raw_input.value, 0); + break; + default: + index = hrm_raw_input.code - REL_X; + } /* Check an avaiable value REL_X(0x00) ~ REL_MISC(0x09) */ if (index >= INPUT_VALUE_COUNT) { @@ -243,13 +259,8 @@ bool hrm_raw_device::update_value_input_event(void) return false; } m_data.values[index] = (unsigned int)hrm_raw_input.value - INPUT_EVENT_BIAS; - _I("SRINIEVENT: EV_REL input had come, val:%d, index[%d]", hrm_raw_input.value, index); } else if (hrm_raw_input.type == EV_SYN) { syn = true; - m_data.timestamp = util::get_timestamp(&hrm_raw_input.time); - m_data.value_count = INPUT_VALUE_COUNT; - - _I("SRINIEVENT: EV_SYN input had come, val:%d, index[%d]", hrm_raw_input.value, index); } else { _E("hrm_raw_input event[type = %d, code = %d] is unknown.", hrm_raw_input.type, hrm_raw_input.code); return false; @@ -260,6 +271,10 @@ bool hrm_raw_device::update_value_input_event(void) _E("EV_SYN didn't come until %d inputs had come", read_input_cnt); return false; } + + m_data.timestamp = fired_time / 1000; /* ns to us */ + m_data.value_count = INPUT_VALUE_COUNT; + return true; } @@ -305,7 +320,6 @@ int hrm_raw_device::get_data(uint32_t id, sensor_data_t **data, int *length) sensor_data->value_count = m_data.value_count; memcpy(sensor_data->values, m_data.values, m_data.value_count * sizeof(m_data.values[0])); } - _I("SRINIHAL: Sensor Data:%.2f, id: %d", sensor_data->values[0], id); *data = sensor_data; *length = sizeof(sensor_data_t); diff --git a/src/light/light_device.cpp b/src/light/light_device.cpp index d40e8e6..dd834bd 100755 --- a/src/light/light_device.cpp +++ b/src/light/light_device.cpp @@ -165,7 +165,6 @@ bool light_device::update_value_lux(void) { int lux = -1; struct input_event light_event; - _D("Light event detection"); int len = read(m_node_handle, &light_event, sizeof(light_event)); if (len == -1) { diff --git a/src/macro.h b/src/macro.h index c2c1557..2383254 100644 --- a/src/macro.h +++ b/src/macro.h @@ -18,8 +18,10 @@ #ifndef __MACRO_H__ #define __MACRO_H__ -#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#define likely(x) __builtin_expect(!!(x), 1) +#define unlikely(x) __builtin_expect(!!(x), 0) +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) #define MIN(x, y) ((x) < (y) ? (x) : (y)) #endif /* __MACRO_H__ */ diff --git a/src/pressure/pressure_device.cpp b/src/pressure/pressure_device.cpp index 757ea9f..ec4b340 100755 --- a/src/pressure/pressure_device.cpp +++ b/src/pressure/pressure_device.cpp @@ -21,14 +21,20 @@ #include <fcntl.h> #include <unistd.h> #include <linux/input.h> +#include <math.h> #include "util.h" +#include "macro.h" #include "sensor_common.h" #include "sensor_log.h" #define SEA_LEVEL_RESOLUTION 0.01 #define SEA_LEVEL_PRESSURE 101325.0 #define SEA_LEVEL_EPSILON 0.00001 +#define DEFAULT_LPF_FACTOR 0.9 +#define ONE_FLOOR_PRESSURE 0.375 /* A floor is 3m. (1hPa = 8m) */ +#define SEC_TO_MS 1000 +#define POLL_1HZ_MS 1000 #define MODEL_NAME "LPS25H" #define VENDOR "ST Microelectronics" @@ -41,6 +47,8 @@ #define TEMPERATURE_OFFSET 42.5 #define MAX_BATCH_COUNT 0 +#define PRESSURE_I2C_READ_FAIL 0 + #define SENSOR_NAME "SENSOR_PRESSURE" #define SENSOR_TYPE_PRESSURE "PRESSURE" @@ -67,8 +75,11 @@ static sensor_info_t sensor_info = { pressure_device::pressure_device() : m_node_handle(-1) , m_pressure(0) +, m_pressure_raw(0) , m_temperature(0) , m_sea_level_pressure(SEA_LEVEL_PRESSURE) +, m_prev_pressure(0) +, m_factor(0) , m_polling_interval(1000) , m_fired_time(0) , m_sensorhub_controlled(false) @@ -151,6 +162,14 @@ bool pressure_device::disable(uint32_t id) return true; } +void pressure_device::update_filter_factor(void) +{ + if (m_polling_interval <= POLL_1HZ_MS) + m_factor = DEFAULT_LPF_FACTOR; + else + m_factor = DEFAULT_LPF_FACTOR / (m_polling_interval / SEC_TO_MS); +} + bool pressure_device::set_interval(uint32_t id, unsigned long val) { unsigned long long polling_interval_ns; @@ -165,6 +184,8 @@ bool pressure_device::set_interval(uint32_t id, unsigned long val) _I("Interval is changed from %lu ms to %lu ms", m_polling_interval, val); m_polling_interval = val; + + update_filter_factor(); return true; } @@ -180,7 +201,6 @@ bool pressure_device::update_value_input_event(void) bool syn = false; struct input_event pressure_event; - _D("pressure event detection"); while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) { int len = read(m_node_handle, &pressure_event, sizeof(pressure_event)); @@ -219,11 +239,10 @@ bool pressure_device::update_value_input_event(void) break; default: _E("pressure_event event[type = %d, code = %d] is unknown.", pressure_event.type, pressure_event.code); - break; + return false; } } else if (pressure_event.type == EV_SYN) { syn = true; - fired_time = util::get_timestamp(&pressure_event.time); } else { _E("pressure_event event[type = %d, code = %d] is unknown.", pressure_event.type, pressure_event.code); return false; @@ -236,13 +255,13 @@ bool pressure_device::update_value_input_event(void) } if (pressure) - m_pressure = pressure_raw[0]; + m_pressure_raw = m_pressure = pressure_raw[0]; if (sea_level) m_sea_level_pressure = pressure_raw[1]; if (temperature) m_temperature = pressure_raw[2]; - m_fired_time = fired_time; + m_fired_time = fired_time / 1000; /* ns to us */ _D("m_pressure = %d, sea_level = %f, temperature = %d, time = %lluus", m_pressure, m_sea_level_pressure, m_temperature, m_fired_time); @@ -282,6 +301,7 @@ int pressure_device::get_data(uint32_t id, sensor_data_t **data, int *length) sensor_data->values[0] = m_pressure; sensor_data->values[1] = (float)m_sea_level_pressure; sensor_data->values[2] = m_temperature; + sensor_data->values[3] = m_pressure_raw; raw_to_base(sensor_data); @@ -291,9 +311,33 @@ int pressure_device::get_data(uint32_t id, sensor_data_t **data, int *length) return 0; } +float pressure_device::pressure_filter(float pressure) +{ + /* + * 1. LPF is applied when a changed pressure value is less than ONE_FLOOR_PRESSURE. + * It tends to be more precise in dynamic changing scenario. + * 2. When I2C read fail error is occurred, sensorhub reports pressure value as ZERO. + * This value MUST be shown only in *#0*# > sensor > barometer, not the other applications. + */ + + float diff; + + /* Filter out ZERO pressure value */ + if (unlikely(pressure == PRESSURE_I2C_READ_FAIL)) + return m_prev_pressure; + + diff = fabsf(m_prev_pressure - pressure); + if (diff < ONE_FLOOR_PRESSURE) + pressure = (m_factor * m_prev_pressure) + ((1 - m_factor) * pressure); + + m_prev_pressure = pressure; + return pressure; +} + void pressure_device::raw_to_base(sensor_data_t *data) { - data->values[0] = data->values[0] * RAW_DATA_UNIT; + data->values[3] = data->values[3] * RAW_DATA_UNIT; + data->values[0] = pressure_filter(data->values[3]); m_sea_level_pressure = data->values[1] * SEA_LEVEL_RESOLUTION; data->values[1] = pressure_to_altitude(data->values[0]); data->values[2] = data->values[2] * TEMPERATURE_RESOLUTION + TEMPERATURE_OFFSET; diff --git a/src/pressure/pressure_device.h b/src/pressure/pressure_device.h index 4a014df..114523d 100644 --- a/src/pressure/pressure_device.h +++ b/src/pressure/pressure_device.h @@ -41,8 +41,11 @@ public: private: int m_node_handle; int m_pressure; + int m_pressure_raw; int m_temperature; float m_sea_level_pressure; + float m_prev_pressure; + float m_factor; unsigned long m_polling_interval; unsigned long long m_fired_time; @@ -54,6 +57,8 @@ private: std::vector<uint32_t> event_ids; bool update_value_input_event(void); + void update_filter_factor(void); + float pressure_filter(float pressure); void raw_to_base(sensor_data_t *data); float pressure_to_altitude(float pressure); }; |