sensor lib

Dependents:   gather_sensor_data

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BH1750Sensor.cpp Source File

BH1750Sensor.cpp

00001 #include "BH1750Sensor.h"
00002 
00003 BH1750Sensor::BH1750Sensor(PinName scaPin, PinName sclPin): BH1750_sensor(scaPin, sclPin) {
00004     reading_type = BH1750_ALL;
00005     BH1750_sensor.init();
00006 }
00007 
00008         
00009 sensorStatus BH1750Sensor::readSensor(string &sensor_reading) {
00010 
00011     //add start to reading
00012     sensor_reading = "{";
00013     
00014     //Read Visible Light Intensity
00015     if ((reading_type & BH1750_VL) == BH1750_VL) {
00016         float vl = BH1750_sensor.readIntensity();
00017         //check required here
00018 
00019         char reading_type_string[10];
00020         sprintf(reading_type_string, "%05X", BH1750_VL);        
00021         char vl_string[10];
00022         sprintf(vl_string, "%2.2f", vl);        
00023         sensor_reading = sensor_reading + reading_type_string + ":" + vl_string;
00024     }
00025     
00026     //add end to reading
00027     sensor_reading = sensor_reading + "}";
00028     
00029     return SENSOR_SUCCESS;
00030 }
00031 
00032     
00033 sensorStatus BH1750Sensor::setReadingType(sensorReadingType sensor_reading_types) {
00034     if ((sensor_reading_types > BH1750_FIRST) && (sensor_reading_types <= BH1750_ALL)) {
00035         reading_type = sensor_reading_types;
00036         return SENSOR_SUCCESS;
00037     } else {
00038         return SENSOR_PARAM_OUT_RANGE;
00039     }
00040 }  
00041     
00042 sensorReadingType BH1750Sensor::getReadingType() {
00043     return reading_type;
00044 }
00045