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
magnetometer.cpp
00001 /*! 00002 @file magnetometer.cpp 00003 00004 The implementation of the magnetometer signal class. 00005 00006 @par Full Description 00007 The implementation of the magnetometer 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 @endif 00013 00014 @ingroup Signal 00015 00016 The MIT License (MIT) 00017 Copyright (c) 2016 Wojciech Rynczuk 00018 00019 */ 00020 00021 #include "magnetometer.hpp " 00022 00023 Magnetometer::Magnetometer(const string& name, Logger& logger) : Signal(name, 32, logger) 00024 { 00025 m_Magnetometer = new MAG3110(PTE25, PTE24); 00026 m_MagXPrev = 0; 00027 m_MagYPrev = 0; 00028 m_MagZPrev = 0; 00029 m_MagXCurr = 0;; 00030 m_MagYCurr = 0; 00031 m_MagZCurr = 0; 00032 } 00033 00034 Magnetometer::~Magnetometer() 00035 { 00036 delete m_Magnetometer; 00037 } 00038 00039 void Magnetometer::PrintState() 00040 { 00041 string suffix("MagX"); 00042 string msg(""); 00043 int32_t time_ref = 0; 00044 00045 m_MagXCurr = m_Magnetometer->readVal(MAG_OUT_X_MSB); 00046 m_MagYCurr = m_Magnetometer->readVal(MAG_OUT_Y_MSB); 00047 m_MagZCurr = m_Magnetometer->readVal(MAG_OUT_Z_MSB); 00048 if ( (CheckFilter()) || \ 00049 (fabs((float)(m_MagXCurr - m_MagXPrev)) > 50) || \ 00050 (fabs((float)(m_MagYCurr - m_MagYPrev)) > 50) || \ 00051 (fabs((float)(m_MagZCurr - m_MagZPrev)) > 50)) 00052 { 00053 PrintVector(m_MagXCurr, suffix, msg, time_ref); 00054 suffix = "MagY"; 00055 time_ref = 0; 00056 PrintVector(m_MagYCurr, suffix, msg, time_ref); 00057 suffix = "MagZ"; 00058 time_ref = 0; 00059 PrintVector(m_MagZCurr, suffix, msg, time_ref); 00060 m_MagXPrev = m_MagXCurr; 00061 m_MagYPrev = m_MagYCurr; 00062 m_MagZPrev = m_MagZCurr; 00063 } 00064 }
Generated on Tue Jul 12 2022 21:39:12 by
1.7.2