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@1:446154224f92, 2016-02-20 (annotated)
- Committer:
- ketjow
- Date:
- Sat Feb 20 20:48:44 2016 +0000
- Revision:
- 1:446154224f92
- Parent:
- 0:9a59cffaafad
- Child:
- 2:a13cde5c679c
vcdMaker Demo release 1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ketjow | 1:446154224f92 | 1 | /*! |
ketjow | 1:446154224f92 | 2 | @file accelerometer.cpp |
ketjow | 1:446154224f92 | 3 | |
ketjow | 1:446154224f92 | 4 | The implementation of the accelerometer signal class. |
ketjow | 1:446154224f92 | 5 | |
ketjow | 1:446154224f92 | 6 | @par Full Description |
ketjow | 1:446154224f92 | 7 | The implementation of the accelerometer signal class. |
ketjow | 1:446154224f92 | 8 | |
ketjow | 1:446154224f92 | 9 | @if REVISION_HISTORY_INCLUDED |
ketjow | 1:446154224f92 | 10 | @par Edit History |
ketjow | 1:446154224f92 | 11 | @li [0] wojciech.rynczuk@wp.pl 20-JAN-2015 Initial file revision. |
ketjow | 1:446154224f92 | 12 | @endif |
ketjow | 1:446154224f92 | 13 | |
ketjow | 1:446154224f92 | 14 | @ingroup Signal |
ketjow | 1:446154224f92 | 15 | |
ketjow | 1:446154224f92 | 16 | @par Copyright (c) MMXV Wojciech Rynczuk |
ketjow | 1:446154224f92 | 17 | |
ketjow | 1:446154224f92 | 18 | Distributed under MIT License |
ketjow | 1:446154224f92 | 19 | |
ketjow | 1:446154224f92 | 20 | */ |
ketjow | 1:446154224f92 | 21 | |
ketjow | 0:9a59cffaafad | 22 | #include "accelerometer.hpp" |
ketjow | 0:9a59cffaafad | 23 | |
ketjow | 0:9a59cffaafad | 24 | #define MMA8451_I2C_ADDRESS (0x1d<<1) |
ketjow | 0:9a59cffaafad | 25 | |
ketjow | 0:9a59cffaafad | 26 | Accelerometer::Accelerometer(const string& name, Logger& logger) : Signal(name, 32, logger) |
ketjow | 0:9a59cffaafad | 27 | { |
ketjow | 0:9a59cffaafad | 28 | m_Accelerometer = new MMA8451Q(PTE25, PTE24, MMA8451_I2C_ADDRESS); |
ketjow | 0:9a59cffaafad | 29 | m_Filter = 1; |
ketjow | 0:9a59cffaafad | 30 | m_AccXPrev = 0; |
ketjow | 0:9a59cffaafad | 31 | m_AccYPrev = 0; |
ketjow | 0:9a59cffaafad | 32 | m_AccZPrev = 0; |
ketjow | 0:9a59cffaafad | 33 | m_AccXCurr = 0; |
ketjow | 0:9a59cffaafad | 34 | m_AccYCurr = 0; |
ketjow | 0:9a59cffaafad | 35 | m_AccZCurr = 0; |
ketjow | 0:9a59cffaafad | 36 | } |
ketjow | 0:9a59cffaafad | 37 | |
ketjow | 0:9a59cffaafad | 38 | Accelerometer::~Accelerometer() |
ketjow | 0:9a59cffaafad | 39 | { |
ketjow | 0:9a59cffaafad | 40 | delete m_Accelerometer; |
ketjow | 0:9a59cffaafad | 41 | } |
ketjow | 0:9a59cffaafad | 42 | |
ketjow | 0:9a59cffaafad | 43 | void Accelerometer::PrintState() |
ketjow | 0:9a59cffaafad | 44 | { |
ketjow | 0:9a59cffaafad | 45 | string suffix("AccX"); |
ketjow | 0:9a59cffaafad | 46 | string msg("f"); |
ketjow | 0:9a59cffaafad | 47 | int32_t time_ref = 0; |
ketjow | 0:9a59cffaafad | 48 | |
ketjow | 0:9a59cffaafad | 49 | m_AccXCurr = m_Accelerometer->getAccX(); |
ketjow | 0:9a59cffaafad | 50 | m_AccYCurr = m_Accelerometer->getAccY(); |
ketjow | 0:9a59cffaafad | 51 | m_AccZCurr = m_Accelerometer->getAccZ(); |
ketjow | 0:9a59cffaafad | 52 | if ( (CheckFilter()) || \ |
ketjow | 0:9a59cffaafad | 53 | (fabs(m_AccXCurr - m_AccXPrev) > 0.1) || \ |
ketjow | 0:9a59cffaafad | 54 | (fabs(m_AccYCurr - m_AccYPrev) > 0.1) || \ |
ketjow | 0:9a59cffaafad | 55 | (fabs(m_AccZCurr - m_AccZPrev) > 0.1)) |
ketjow | 0:9a59cffaafad | 56 | { |
ketjow | 0:9a59cffaafad | 57 | PrintReal(m_AccXCurr, suffix, msg, time_ref); |
ketjow | 0:9a59cffaafad | 58 | suffix = "AccY"; |
ketjow | 0:9a59cffaafad | 59 | PrintReal(m_AccYCurr, suffix, msg, time_ref); |
ketjow | 0:9a59cffaafad | 60 | suffix = "AccZ"; |
ketjow | 0:9a59cffaafad | 61 | PrintReal(m_AccZCurr, suffix, msg, time_ref); |
ketjow | 0:9a59cffaafad | 62 | m_AccXPrev = m_AccXCurr; |
ketjow | 0:9a59cffaafad | 63 | m_AccYPrev = m_AccYCurr; |
ketjow | 0:9a59cffaafad | 64 | m_AccZPrev = m_AccZCurr; |
ketjow | 0:9a59cffaafad | 65 | } |
ketjow | 0:9a59cffaafad | 66 | } |