summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeon Lindenfelser <llindenfelser@multitech.com>2015-12-10 16:28:45 -0600
committerLeon Lindenfelser <llindenfelser@multitech.com>2015-12-10 16:28:45 -0600
commit8f3d5d0a8e9539ebcc203f5dd7c3661cad101a35 (patch)
treebb04e45e7d6c97098048bc64358b513e69644dce
parent0ae5b17f7977f197e59110d5cf6450d49ae0ba24 (diff)
downloadmtdot-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.
-rw-r--r--Layout/LayoutDemoSampling.cpp41
-rw-r--r--Layout/LayoutDemoSampling.h6
-rw-r--r--SensorHandler/SensorHandler.cpp56
3 files changed, 61 insertions, 42 deletions
diff --git a/Layout/LayoutDemoSampling.cpp b/Layout/LayoutDemoSampling.cpp
index 52c1493..aea80ac 100644
--- a/Layout/LayoutDemoSampling.cpp
+++ b/Layout/LayoutDemoSampling.cpp
@@ -80,51 +80,58 @@ void LayoutDemoSampling::updateInterval(uint32_t seconds) {
writeField(_fInfo, buf, size, true);
}
-void LayoutDemoSampling::updateAccelerationX(uint16_t x) {
+void LayoutDemoSampling::updateAccelerationX(int16_t x) {
char buf[16];
+ size_t size;
memset(buf, ' ', sizeof(buf));
- snprintf(buf, sizeof(buf), "%d", x);
- writeField(_fAccx, buf, true);
+ size = snprintf(buf, sizeof(buf), "%d", x);
+ writeField(_fAccx, buf, size, true);
}
-void LayoutDemoSampling::updateAccelerationY(uint16_t y) {
+void LayoutDemoSampling::updateAccelerationY(int16_t y) {
char buf[16];
+ size_t size;
memset(buf, ' ', sizeof(buf));
- snprintf(buf, sizeof(buf), "%d", y);
- writeField(_fAccy, buf, true);
+ size = snprintf(buf, sizeof(buf), "%d", y);
+ writeField(_fAccy, buf, size, true);
}
-void LayoutDemoSampling::updateAccelerationZ(uint16_t z) {
+void LayoutDemoSampling::updateAccelerationZ(int16_t z) {
char buf[16];
+ size_t size;
memset(buf, ' ', sizeof(buf));
- snprintf(buf, sizeof(buf), "%d", z);
- writeField(_fAccz, buf, true);
+ size = snprintf(buf, sizeof(buf), "%d", z);
+ writeField(_fAccz, buf, size, true);
}
void LayoutDemoSampling::updatePressure(float pressure) {
char buf[16];
+ size_t size;
memset(buf, ' ', sizeof(buf));
- snprintf(buf, sizeof(buf), "%3.2f KPa", pressure/1000);
- writeField(_fPres, buf, true);
+ size = snprintf(buf, sizeof(buf), "%3.2f KPa", pressure/1000);
+ writeField(_fPres, buf, size, true);
}
void LayoutDemoSampling::updateAltitude(float altitude) {
char buf[16];
+ size_t size;
memset(buf, ' ', sizeof(buf));
- snprintf(buf, sizeof(buf), "%5.2f m", altitude);
- writeField(_fAlt, buf, true);
+ size = snprintf(buf, sizeof(buf), "%5.2f m", altitude);
+ writeField(_fAlt, buf, size, true);
}
void LayoutDemoSampling::updateTemperature(float temperature) {
char buf[16];
+ size_t size;
memset(buf, ' ', sizeof(buf));
- snprintf(buf, sizeof(buf), "%3.2f C", temperature);
- writeField(_fTemp, buf, true);
+ size = snprintf(buf, sizeof(buf), "%3.2f C", temperature);
+ writeField(_fTemp, buf, size, true);
}
void LayoutDemoSampling::updateLight(float light) {
char buf[16];
+ size_t size;
memset(buf, ' ', sizeof(buf));
- snprintf(buf, sizeof(buf), "%4.2f lux", light);
- writeField(_fLight, buf, true);
+ size = snprintf(buf, sizeof(buf), "%4.2f lux", light);
+ writeField(_fLight, buf, size, true);
}
diff --git a/Layout/LayoutDemoSampling.h b/Layout/LayoutDemoSampling.h
index f3faceb..a590966 100644
--- a/Layout/LayoutDemoSampling.h
+++ b/Layout/LayoutDemoSampling.h
@@ -15,9 +15,9 @@ class LayoutDemoSampling : public Layout {
void updateSw2(std::string sw2);
void updateCountdown(uint32_t seconds);
void updateInterval(uint32_t seconds);
- void updateAccelerationX(uint16_t x);
- void updateAccelerationY(uint16_t y);
- void updateAccelerationZ(uint16_t z);
+ void updateAccelerationX(int16_t x);
+ void updateAccelerationY(int16_t y);
+ void updateAccelerationZ(int16_t z);
void updatePressure(float pressure);
void updateAltitude(float altitude);
void updateTemperature(float temperature);
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
}
}