1/* 2 * Copyright (C) 2015 Intel Corporation 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17#include <cutils/log.h> 18#include "GroveLight.hpp" 19#include "SensorsHAL.hpp" 20 21struct sensor_t GroveLight::sensorDescription = { 22 .name = "Grove Light Sensor", 23 .vendor = "Senba Optical & Electronic", 24 .version = 1, 25 .handle = -1, 26 .type = SENSOR_TYPE_LIGHT, 27 .maxRange = 60.0f, 28 .resolution = 1.0f, 29 .power = 0.001f, 30 .minDelay = 10, 31 .fifoReservedEventCount = 0, 32 .fifoMaxEventCount = 0, 33 .stringType = SENSOR_STRING_TYPE_LIGHT, 34 .requiredPermission = "", 35 .maxDelay = 1000, 36 .flags = SENSOR_FLAG_ON_CHANGE_MODE, 37 .reserved = {}, 38}; 39 40Sensor * GroveLight::createSensor(int pollFd) { 41 return new GroveLight(pollFd, 0); 42} 43 44void GroveLight::initModule() { 45 SensorContext::addSensorModule(&sensorDescription, createSensor); 46} 47 48GroveLight::GroveLight(int pollFd, int pin) : upm::GroveLight(pin), pollFd(pollFd) { 49 handle = sensorDescription.handle; 50 type = SENSOR_TYPE_LIGHT; 51} 52 53GroveLight::~GroveLight() {} 54 55int GroveLight::pollEvents(sensors_event_t* data, int count) { 56 data->light = value(); 57 return 1; 58} 59 60int GroveLight::activate(int handle, int enabled) { 61 /* start or stop the acquisition thread */ 62 return activateAcquisitionThread(pollFd, handle, enabled); 63} 64