This is the vcdMaker demo project. See http://vcdmaker.org for details. vcdMaker is supposed to help engineers to debug their applications and systems. It transforms text log files into the VCD format which can be easily displayed as a waveform.

Dependencies:   mbed vcdLogger vcdSignal

Signals/accelerometer.cpp

Committer:
ketjow
Date:
2016-02-12
Revision:
0:9a59cffaafad
Child:
1:446154224f92

File content as of revision 0:9a59cffaafad:

#include "accelerometer.hpp"

#define MMA8451_I2C_ADDRESS (0x1d<<1)

Accelerometer::Accelerometer(const string& name, Logger& logger) : Signal(name, 32, logger)
{
    m_Accelerometer = new MMA8451Q(PTE25, PTE24, MMA8451_I2C_ADDRESS);
    m_Filter = 1;
    m_AccXPrev = 0;
    m_AccYPrev = 0;
    m_AccZPrev = 0;
    m_AccXCurr = 0;
    m_AccYCurr = 0;
    m_AccZCurr = 0;
}

Accelerometer::~Accelerometer()
{
    delete m_Accelerometer;
}
  
void Accelerometer::PrintState()
{
    string  suffix("AccX");
    string  msg("f");
    int32_t time_ref = 0;
    
    m_AccXCurr = m_Accelerometer->getAccX();
    m_AccYCurr = m_Accelerometer->getAccY();
    m_AccZCurr = m_Accelerometer->getAccZ();
    if ( (CheckFilter()) || \
         (fabs(m_AccXCurr - m_AccXPrev) > 0.1) || \
         (fabs(m_AccYCurr - m_AccYPrev) > 0.1) || \
         (fabs(m_AccZCurr - m_AccZPrev) > 0.1))
    {
        PrintReal(m_AccXCurr, suffix, msg, time_ref);
        suffix = "AccY";
        PrintReal(m_AccYCurr, suffix, msg, time_ref);
        suffix = "AccZ";
        PrintReal(m_AccZCurr, suffix, msg, time_ref);
        m_AccXPrev = m_AccXCurr;
        m_AccYPrev = m_AccYCurr;
        m_AccZPrev = m_AccZCurr;
    }
}