diff options
author | Leon Lindenfelser <llindenfelser@multitech.com> | 2015-12-10 16:28:45 -0600 |
---|---|---|
committer | Leon Lindenfelser <llindenfelser@multitech.com> | 2015-12-10 16:28:45 -0600 |
commit | 8f3d5d0a8e9539ebcc203f5dd7c3661cad101a35 (patch) | |
tree | bb04e45e7d6c97098048bc64358b513e69644dce /SensorHandler | |
parent | 0ae5b17f7977f197e59110d5cf6450d49ae0ba24 (diff) | |
download | mtdot-box-evb-factory-firmware-8f3d5d0a8e9539ebcc203f5dd7c3661cad101a35.tar.gz mtdot-box-evb-factory-firmware-8f3d5d0a8e9539ebcc203f5dd7c3661cad101a35.tar.bz2 mtdot-box-evb-factory-firmware-8f3d5d0a8e9539ebcc203f5dd7c3661cad101a35.zip |
Fixed acceleration values... use int16_t not uint16_t.
Added a timer to sensor read loops so they can't get stuck in eternal loops.
Changed light sensor data rate from 1.56 to 6.25.
Diffstat (limited to 'SensorHandler')
-rw-r--r-- | SensorHandler/SensorHandler.cpp | 56 |
1 files changed, 34 insertions, 22 deletions
diff --git a/SensorHandler/SensorHandler.cpp b/SensorHandler/SensorHandler.cpp index 1b471b3..18f9ddc 100644 --- a/SensorHandler/SensorHandler.cpp +++ b/SensorHandler/SensorHandler.cpp @@ -29,7 +29,7 @@ void SensorHandler::initSensors(){ // Setup the Accelerometer for 8g range, 14 bit resolution, Noise reduction off, sample rate 1.56 Hz // normal oversample mode, High pass filter off _accelerometer.setCommonParameters(MMA845x::RANGE_8g,MMA845x::RES_MAX,MMA845x::LN_OFF, - MMA845x::DR_1_56,MMA845x::OS_NORMAL,MMA845x::HPF_OFF ); + MMA845x::DR_6_25,MMA845x::OS_NORMAL,MMA845x::HPF_OFF ); // Setup the Barometric sensor for post processed Ambient pressure, 4 samples per data acquisition. //and a sample taken every second when in active mode @@ -57,18 +57,24 @@ void SensorHandler::startSensorThread(void const *p) void SensorHandler::readSensors() { uint8_t result; + Timer timer; + timer.start(); + _getSensorThread.signal_wait(START_THREAD); while(1){ // Test Accelerometer XYZ data ready bit to see if acquisition complete + timer.reset(); do { - osDelay(100); // allows other threads to process + osDelay(20); // allows other threads to process result = _accelerometer.getStatus(); - } while ((result & MMA845x::XYZDR) == 0 ); - - // Retrieve accelerometer data - _mutex.lock(); - _accelerometerData = _accelerometer.getXYZ(); - _mutex.unlock(); + if((result & MMA845x::XYZDR) != 0 ){ + // Retrieve accelerometer data + _mutex.lock(); + _accelerometerData = _accelerometer.getXYZ(); + _mutex.unlock(); + } + } while (((result & MMA845x::XYZDR) == 0 ) && (timer.read_ms() < 1000)); + // Trigger a Pressure reading _barometricSensor.setParameters(MPL3115A2::DATA_NORMAL, MPL3115A2::DM_BAROMETER, MPL3115A2::OR_16, @@ -76,15 +82,18 @@ void SensorHandler::readSensors() _barometricSensor.triggerOneShot(); // Test barometer device status to see if acquisition is complete + timer.reset(); do { - osDelay(100); // allows other threads to process + osDelay(20); // allows other threads to process result = _barometricSensor.getStatus(); - } while ((result & MPL3115A2::PTDR) == 0 ); - - // Retrieve barometric pressure - _mutex.lock(); - _pressure = _barometricSensor.getBaroData() >> 12; // convert 32 bit signed to 20 bit unsigned value - _mutex.unlock(); + if((result & MPL3115A2::PTDR) != 0){ + // Retrieve barometric pressure + _mutex.lock(); + _pressure = _barometricSensor.getBaroData() >> 12; // convert 32 bit signed to 20 bit unsigned value + _mutex.unlock(); + } + } while (((result & MPL3115A2::PTDR) == 0) && (timer.read_ms() < 100)); + // Trigger an Altitude reading _barometricSensor.setParameters(MPL3115A2::DATA_NORMAL, MPL3115A2::DM_ALTIMETER, MPL3115A2::OR_16, @@ -92,20 +101,23 @@ void SensorHandler::readSensors() _barometricSensor.triggerOneShot(); // Test barometer device status to see if acquisition is complete + timer.reset(); do { - osDelay(100); // allows other threads to process + osDelay(20); // allows other threads to process result = _barometricSensor.getStatus(); - } while ((result & MPL3115A2::PTDR) == 0 ); - - // Retrieve temperature and altitude. - _mutex.lock(); - _barometerData = _barometricSensor.getAllData(false); - _mutex.unlock(); + if((result & MPL3115A2::PTDR) != 0 ){ + // Retrieve temperature and altitude. + _mutex.lock(); + _barometerData = _barometricSensor.getAllData(false); + _mutex.unlock(); + } + } while (((result & MPL3115A2::PTDR) == 0 ) && (timer.read_ms() < 100)); // Retrieve light level _mutex.lock(); _light = _lightSensor.getData(); _mutex.unlock(); + osDelay(100); // allows other threads to process } } |