Wojciech Rynczuk / Mbed 2 deprecated vcdMaker_Demo_DISCO_L476

Dependencies:   BSP_DISCO_L476VG COMPASS_DISCO_L476VG mbed vcdLogger vcdSignal

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers accelerometer.cpp Source File

accelerometer.cpp

Go to the documentation of this file.
00001 /*!
00002   @file accelerometer.cpp
00003 
00004   The implementation of the accelerometer signal class.
00005 
00006   @par Full Description
00007   The implementation of the accelerometer signal class.
00008 
00009   @if REVISION_HISTORY_INCLUDED
00010   @par Edit History
00011   @li [0]    wojciech.rynczuk@wp.pl    04-MAR-2016    Initial file revision.
00012   @endif
00013 
00014   @ingroup Signal
00015 
00016   The MIT License (MIT)
00017   Copyright (c) 2016 Wojciech Rynczuk
00018 
00019 */
00020 
00021 #include "accelerometer.hpp "
00022 
00023 Accelerometer::Accelerometer(const string& name, COMPASS_DISCO_L476VG& compass, Logger& logger) : Signal(name, 32, logger), m_pCompass(&compass)
00024 {
00025     m_AccXYZ[0] = 0;
00026     m_AccXYZ[1] = 0;
00027     m_AccXYZ[2] = 0;
00028     m_PrevAccXYZ[0] = 0;
00029     m_PrevAccXYZ[1] = 0;
00030     m_PrevAccXYZ[2] = 0;
00031 }
00032 
00033 Accelerometer::~Accelerometer()
00034 {
00035 }
00036   
00037 void Accelerometer::PrintState()
00038 {
00039     string  suffix("AccX");
00040     string  msg("");
00041     int32_t time_ref = 0;
00042     
00043     m_pCompass->AccGetXYZ(m_AccXYZ);
00044     if ( (CheckFilter()) || \
00045          (fabs((float)(m_AccXYZ[0] - m_PrevAccXYZ[0])) > 200) || \
00046          (fabs((float)(m_AccXYZ[1] - m_PrevAccXYZ[1])) > 200) || \
00047          (fabs((float)(m_AccXYZ[2] - m_PrevAccXYZ[2])) > 200))
00048     {
00049         PrintReal(m_AccXYZ[0], suffix, msg, time_ref);
00050         suffix = "AccY";
00051         time_ref = 0;
00052         PrintReal(m_AccXYZ[1], suffix, msg, time_ref);
00053         suffix = "AccZ";
00054         time_ref = 0;
00055         PrintReal(m_AccXYZ[2], suffix, msg, time_ref);
00056         m_PrevAccXYZ[0] = m_AccXYZ[0];
00057         m_PrevAccXYZ[1] = m_AccXYZ[1];
00058         m_PrevAccXYZ[2] = m_AccXYZ[2];
00059     }
00060 }