Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed vcdLogger vcdSignal
accelerometer.cpp
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 20-JAN-2015 Initial file revision. 00012 @li [1] wojciech.rynczuk@wp.pl 04-MAR-2016 Fixed real printing. 00013 @endif 00014 00015 @ingroup Signal 00016 00017 The MIT License (MIT) 00018 Copyright (c) 2016 Wojciech Rynczuk 00019 00020 */ 00021 00022 #include "accelerometer.hpp " 00023 00024 #define MMA8451_I2C_ADDRESS (0x1d<<1) 00025 00026 Accelerometer::Accelerometer(const string& name, Logger& logger) : Signal(name, 32, logger) 00027 { 00028 m_Accelerometer = new MMA8451Q(PTE25, PTE24, MMA8451_I2C_ADDRESS); 00029 m_Filter = 1; 00030 m_AccXPrev = 0; 00031 m_AccYPrev = 0; 00032 m_AccZPrev = 0; 00033 m_AccXCurr = 0; 00034 m_AccYCurr = 0; 00035 m_AccZCurr = 0; 00036 } 00037 00038 Accelerometer::~Accelerometer() 00039 { 00040 delete m_Accelerometer; 00041 } 00042 00043 void Accelerometer::PrintState() 00044 { 00045 string suffix("AccX"); 00046 string msg(""); 00047 int32_t time_ref = 0; 00048 00049 m_AccXCurr = m_Accelerometer->getAccX(); 00050 m_AccYCurr = m_Accelerometer->getAccY(); 00051 m_AccZCurr = m_Accelerometer->getAccZ(); 00052 if ( (CheckFilter()) || \ 00053 (fabs(m_AccXCurr - m_AccXPrev) > 0.1) || \ 00054 (fabs(m_AccYCurr - m_AccYPrev) > 0.1) || \ 00055 (fabs(m_AccZCurr - m_AccZPrev) > 0.1)) 00056 { 00057 PrintReal(m_AccXCurr, suffix, msg, time_ref); 00058 suffix = "AccY"; 00059 PrintReal(m_AccYCurr, suffix, msg, time_ref); 00060 suffix = "AccZ"; 00061 PrintReal(m_AccZCurr, suffix, msg, time_ref); 00062 m_AccXPrev = m_AccXCurr; 00063 m_AccYPrev = m_AccYCurr; 00064 m_AccZPrev = m_AccZCurr; 00065 } 00066 }
Generated on Tue Jul 12 2022 21:39:12 by
1.7.2