4 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include <sensor_log.h>
22 #include <face_down_alg_impl.h>
24 #define GRAVITY 9.80665
25 #define TWENTY_DEGREES 0.349066
26 #define ONE_SIXTY_DEGREES 2.79253
27 #define WINDOW_SIZE (2000*1000)
29 face_down_alg_impl::face_down_alg_impl()
32 m_last_event_time = 0;
33 m_latest_down_time = 0;
36 face_down_alg_impl::~face_down_alg_impl()
40 void face_down_alg_impl::push_event(const sensor_event_t & event)
42 //_I("face_down_alg: %llu acc[2]: %f",event.data->timestamp,event.data->values[2]);
43 m_current_time = event.data->timestamp;
46 if (event.data->values[2] < (GRAVITY * cos(ONE_SIXTY_DEGREES)))
47 m_latest_down_time = event.data->timestamp;
49 if (event.data->values[2] > (GRAVITY * cos(TWENTY_DEGREES)))
50 m_oldest_up_time.push(event.data->timestamp);
53 void face_down_alg_impl::remove_old_up_time(void)
55 while (m_oldest_up_time.size() > 0 && (m_current_time - m_oldest_up_time.front() > WINDOW_SIZE))
56 m_oldest_up_time.pop();
59 bool face_down_alg_impl::get_face_down(void)
61 unsigned long long down = is_facing_down();
62 unsigned long long up = was_facing_up();
63 //_I("face_down_alg: down: %llu, up: %llu", down, up);
68 if (m_current_time - m_last_event_time < WINDOW_SIZE)
71 m_last_event_time = m_current_time;
75 unsigned long long face_down_alg_impl::is_facing_down(void)
77 if (m_current_time - m_latest_down_time < WINDOW_SIZE)
78 return m_latest_down_time;
82 unsigned long long face_down_alg_impl::was_facing_up(void)
85 if (m_oldest_up_time.size() == 0)
87 return m_oldest_up_time.front();