1 /* Medfield sensor plugins
2 * Copyright (C) 2013 Intel Corporation
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; version 2.1.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301USA
18 #include "lightprocessor.h"
25 const char *LIGHT_INDEX_KEY = DEFAULT_SENSOR_KEY_PREFIX"40001";
27 LightProcessor::LightProcessor()
32 mSupportedEvents.push_back(LIGHT_EVENT_CHANGE_LEVEL);
33 mSupportedEvents.push_back(LIGHT_EVENT_LEVEL_DATA_REPORT_ON_TIME);
34 mSupportedEvents.push_back(LIGHT_EVENT_LUX_DATA_REPORT_ON_TIME);
37 bool LightProcessor::fill_values(unsigned int type, int &count,
38 data_unit_idx_t &unit, data_accuracy &accuracy)
45 case LIGHT_LUX_DATA_SET:
47 mValues[0] = mLuxValue;
48 accuracy = ACCURACY_GOOD;
51 case LIGHT_BASE_DATA_SET:
54 accuracy = ACCURACY_NORMAL;
55 unit = IDX_UNIT_LEVEL_1_TO_10;
64 int LightProcessor::get_property(unsigned int property_level,
65 base_property_struct &result)
67 strcpy(result.sensor_name,"ltr502");
68 strcpy(result.sensor_vendor,"Lite-On");
70 if (property_level == LIGHT_BASE_DATA_SET) {
71 result.sensor_unit_idx = IDX_UNIT_LEVEL_1_TO_10;
72 result.sensor_min_range = 1;
73 result.sensor_max_range = 10;
74 result.sensor_resolution = 0.0002;
75 } else if (property_level == LIGHT_LUX_DATA_SET) {
76 result.sensor_unit_idx = IDX_UNIT_LUX;
77 result.sensor_min_range = 0;
78 result.sensor_max_range = 10000;
79 result.sensor_resolution = 1;
87 bool LightProcessor::enable()
91 mFd = open("/dev/ltr502als_lsensor", O_RDONLY);
99 DbgPrint("Opening sensor file failed");
104 bool LightProcessor::disable()
114 static int luxToIndex(int luminance)
116 static const int luxValues[10] = {
117 10, 50, 100, 150, 250,
118 300, 400, 1000, 2000, 3000
121 for (unsigned int i = 0; i < sizeof(luxValues)/sizeof(int); i++) {
122 if (luxValues[i] >= luminance)
129 void* LightProcessor::started()
134 pollInfo.events = POLLIN;
135 poll(&pollInfo,1,2000);
137 if (pollInfo.revents & POLLIN) {
138 DbgPrint("HAVE POLLIN");
140 int readCount = read(mFd,&value,sizeof(int));
141 if (readCount != sizeof(int)) {
142 return (void *) cworker::STARTED;
145 int oldIndex = mIndex;
146 int currentIndex = luxToIndex(value);
150 mIndex = currentIndex;
151 mValueMutex.unlock();
153 if (currentIndex != oldIndex) {
154 vconf_set_int(LIGHT_INDEX_KEY, currentIndex);
155 DbgPrint("Notifying change old %d new %d", oldIndex, currentIndex);
158 DbgPrint("Readed value %d",value);
161 return (void *) cworker::STARTED;