summaryrefslogtreecommitdiff
path: root/SensorHandler
diff options
context:
space:
mode:
authorLeon Lindenfelser <llindenfelser@multitech.com>2015-12-08 16:17:13 -0600
committerLeon Lindenfelser <llindenfelser@multitech.com>2015-12-08 16:17:13 -0600
commitcbcf16a4dafeb8c1e2120c3cc08e2c2ef72e164f (patch)
tree2d505e2f3088f568de394498507870e5340e6f34 /SensorHandler
parent9a9407a11dad3013a99cefbbc00ecf1db561eb3f (diff)
downloadmtdot-box-evb-factory-firmware-cbcf16a4dafeb8c1e2120c3cc08e2c2ef72e164f.tar.gz
mtdot-box-evb-factory-firmware-cbcf16a4dafeb8c1e2120c3cc08e2c2ef72e164f.tar.bz2
mtdot-box-evb-factory-firmware-cbcf16a4dafeb8c1e2120c3cc08e2c2ef72e164f.zip
Added more getters to the sensor handler.
Added test code in main to print out data from getters.
Diffstat (limited to 'SensorHandler')
-rw-r--r--SensorHandler/SensorHandler.cpp59
-rw-r--r--SensorHandler/SensorHandler.h12
2 files changed, 63 insertions, 8 deletions
diff --git a/SensorHandler/SensorHandler.cpp b/SensorHandler/SensorHandler.cpp
index 33515f7..89f7d2d 100644
--- a/SensorHandler/SensorHandler.cpp
+++ b/SensorHandler/SensorHandler.cpp
@@ -86,7 +86,7 @@ void SensorHandler::readSensors()
_pressure = _barometricSensor.getBaroData() >> 12; // convert 32 bit signed to 20 bit unsigned value
_mutex.unlock();
- // Trigger a Altitude reading
+ // Trigger an Altitude reading
_barometricSensor.setParameters(MPL3115A2::DATA_NORMAL, MPL3115A2::DM_ALTIMETER, MPL3115A2::OR_16,
MPL3115A2::AT_1);
_barometricSensor.triggerOneShot();
@@ -97,7 +97,7 @@ void SensorHandler::readSensors()
result = _barometricSensor.getStatus();
} while ((result & MPL3115A2::PTDR) == 0 );
- // Retrieve temperature
+ // Retrieve temperature and altitude.
_mutex.lock();
_barometerData = _barometricSensor.getAllData(false);
_mutex.unlock();
@@ -117,7 +117,19 @@ MMA845x_DATA SensorHandler::getAcceleration(){
return data;
}
-uint16_t SensorHandler::getLight(){
+float SensorHandler::getLight(){
+ float light;
+ uint16_t whole;
+ _mutex.lock();
+ whole = _light;
+ _mutex.unlock();
+ light = whole * 24 % 100;
+ light /= 100;
+ light = light + (whole * 24 / 100); // 16000 lux full scale .24 lux per bit
+ return light;
+}
+
+uint16_t SensorHandler::getLightRaw(){
uint16_t light;
_mutex.lock();
light = _light;
@@ -125,7 +137,18 @@ uint16_t SensorHandler::getLight(){
return light;
}
-uint32_t SensorHandler::getPressure(){
+float SensorHandler::getPressure(){
+ float pressure;
+ uint32_t whole;
+ _mutex.lock();
+ whole = _pressure;
+ _mutex.unlock();
+ pressure = (whole & 3) * .25;
+ pressure = pressure + (whole >> 2);
+ return pressure;
+}
+
+uint32_t SensorHandler::getPressureRaw(){
uint32_t pressure;
_mutex.lock();
pressure = _pressure;
@@ -133,6 +156,34 @@ uint32_t SensorHandler::getPressure(){
return pressure;
}
+float SensorHandler::getTemp(Scale scale){
+ float temperature;
+ uint16_t whole;
+ _mutex.lock();
+ whole = _barometerData._temp;
+ _mutex.unlock();
+ temperature = whole & 0x0f;
+ temperature *= .0625;
+ temperature += (whole >> 4);
+ if(scale == FAHRENHEIT){
+ temperature = temperature * 1.8 + 32;
+ }
+ return temperature;
+}
+
+float SensorHandler::getAltitude(){
+ float altitude;
+ uint32_t whole;
+ _mutex.lock();
+ whole = _barometerData._baro;
+ _mutex.unlock();
+ whole /= 4096;
+ altitude = (whole & 0x0f) * .0625;
+ whole /= 16;
+ altitude += whole;
+ return altitude;
+}
+
MPL3115A2_DATA SensorHandler::getBarometer(){
MPL3115A2_DATA data;
_mutex.lock();
diff --git a/SensorHandler/SensorHandler.h b/SensorHandler/SensorHandler.h
index f3ad83d..01ccf77 100644
--- a/SensorHandler/SensorHandler.h
+++ b/SensorHandler/SensorHandler.h
@@ -22,14 +22,18 @@
class SensorHandler
{
public:
+ enum Scale{CELSIUS, FAHRENHEIT};
SensorHandler(void);
~SensorHandler(void);
MMA845x_DATA getAcceleration(void);
- uint16_t getLight(void);
- uint32_t getPressure(void);
+ float getLight(void);
+ uint16_t getLightRaw(void);
+ float getPressure(void);
+ uint32_t getPressureRaw(void);
+ float getTemp(Scale);
+ float getAltitude(void);
MPL3115A2_DATA getBarometer(void);
-
-
+
private:
Thread _getSensorThread;
static void startSensorThread (void const *p);