2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "../TypesInternal.h"
19 #include "../TimeUtil.h"
20 #include "SleepMonitor.h"
22 #define IDX_SLEEP_STATE 0
23 #define IDX_REMAINING 6
27 SleepMonitor::SleepMonitor(SleepLogger *logger) :
31 setSensor(HUMAN_SLEEP_MONITOR_SENSOR);
35 SleepMonitor::~SleepMonitor()
39 bool SleepMonitor::start()
46 void SleepMonitor::stop()
52 void SleepMonitor::lazyStop()
60 void SleepMonitor::onEvent(sensor_data_t *eventData)
62 _D("%d at %llu", (int)eventData->values[IDX_SLEEP_STATE], eventData->timestamp);
64 uint64_t timestamp = TimeUtil::getTime(eventData->timestamp);
65 __logger->record(timestamp - SEC_TO_MS(SECONDS_PER_MINUTE), timestamp,
66 static_cast<int>(eventData->values[IDX_SLEEP_STATE]));
68 if (static_cast<int>(eventData->values[IDX_REMAINING]) > 0)
71 __logger->flushCache();