src/sensors/qmagnetometer.cpp
changeset 0 876b1a06bc25
equal deleted inserted replaced
-1:000000000000 0:876b1a06bc25
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include "qmagnetometer.h"
       
    43 #include "qmagnetometer_p.h"
       
    44 
       
    45 QTM_BEGIN_NAMESPACE
       
    46 
       
    47 IMPLEMENT_READING(QMagnetometerReading)
       
    48 
       
    49 /*!
       
    50     \class QMagnetometerReading
       
    51     \ingroup sensors_reading
       
    52 
       
    53     \brief The QMagnetometerReading class represents one reading from the
       
    54            magnetometer.
       
    55 
       
    56     \section2 QMagnetometerReading Units
       
    57     The magnetometer returns magnetic flux density values along 3 axes.
       
    58     The scale of the values is teslas. The axes are arranged as follows.
       
    59 
       
    60     \image sensors-coordinates2.jpg
       
    61 
       
    62     The magnetometer can report on either raw magnetic flux values or geomagnetic flux values.
       
    63     By default it returns raw magnetic flux values. The QMagnetometer::returnGeoValues property
       
    64     must be set to return geomagnetic flux values.
       
    65 
       
    66     The primary difference between raw and geomagnetic values is that extra processing
       
    67     is done to eliminate local magnetic interference from the geomagnetic values so they
       
    68     represent only the effect of the Earth's magnetic field. This process is not perfect
       
    69     and the accuracy of each reading may change.
       
    70 
       
    71     The image below shows the difference between geomagnetic (on the left) and raw (on the right)
       
    72     readings for a phone that is being subjected to magnetic interference.
       
    73 
       
    74     \image sensors-geo-vs-raw-magnetism.jpg
       
    75 
       
    76     The accuracy of each reading is measured as a number from 0 to 1.
       
    77     A value of 1 is the highest level that the device can support and 0 is
       
    78     the worst.
       
    79 */
       
    80 
       
    81 /*!
       
    82     \property QMagnetometerReading::x
       
    83     \brief the raw magnetic flux density on the X axis.
       
    84 
       
    85     Measured as telsas.
       
    86     \sa {QMagnetometerReading Units}
       
    87 */
       
    88 
       
    89 qreal QMagnetometerReading::x() const
       
    90 {
       
    91     return d->x;
       
    92 }
       
    93 
       
    94 /*!
       
    95     Sets the raw magnetic flux density on the X axis to \a x.
       
    96 */
       
    97 void QMagnetometerReading::setX(qreal x)
       
    98 {
       
    99     d->x = x;
       
   100 }
       
   101 
       
   102 /*!
       
   103     \property QMagnetometerReading::y
       
   104     \brief the raw magnetic flux density on the Y axis.
       
   105 
       
   106     Measured as telsas.
       
   107     \sa {QMagnetometerReading Units}
       
   108 */
       
   109 
       
   110 qreal QMagnetometerReading::y() const
       
   111 {
       
   112     return d->y;
       
   113 }
       
   114 
       
   115 /*!
       
   116     Sets the raw magnetic flux density on the Y axis to \a y.
       
   117 */
       
   118 void QMagnetometerReading::setY(qreal y)
       
   119 {
       
   120     d->y = y;
       
   121 }
       
   122 
       
   123 /*!
       
   124     \property QMagnetometerReading::z
       
   125     \brief the raw magnetic flux density on the Z axis.
       
   126 
       
   127     Measured as telsas.
       
   128     \sa {QMagnetometerReading Units}
       
   129 */
       
   130 
       
   131 qreal QMagnetometerReading::z() const
       
   132 {
       
   133     return d->z;
       
   134 }
       
   135 
       
   136 /*!
       
   137     Sets the raw magnetic flux density on the Z axis to \a z.
       
   138 */
       
   139 void QMagnetometerReading::setZ(qreal z)
       
   140 {
       
   141     d->z = z;
       
   142 }
       
   143 
       
   144 /*!
       
   145     \property QMagnetometerReading::calibrationLevel
       
   146     \brief the accuracy of the reading.
       
   147 
       
   148     Measured as a value from 0 to 1 with higher values being better.
       
   149 
       
   150     Note that this only changes when measuring geomagnetic flux density.
       
   151     Raw magnetic flux readings will always have a value of 1.
       
   152     \sa {QMagnetometerReading Units}
       
   153 */
       
   154 
       
   155 qreal QMagnetometerReading::calibrationLevel() const
       
   156 {
       
   157     return d->calibrationLevel;
       
   158 }
       
   159 
       
   160 /*!
       
   161     Sets the accuracy of the reading to \a calibrationLevel.
       
   162 */
       
   163 void QMagnetometerReading::setCalibrationLevel(qreal calibrationLevel)
       
   164 {
       
   165     d->calibrationLevel = calibrationLevel;
       
   166 }
       
   167 
       
   168 // =====================================================================
       
   169 
       
   170 /*!
       
   171     \class QMagnetometerFilter
       
   172     \ingroup sensors_filter
       
   173 
       
   174     \brief The QMagnetometerFilter class is a convenience wrapper around QSensorFilter.
       
   175 
       
   176     The only difference is that the filter() method features a pointer to QMagnetometerReading
       
   177     instead of QSensorReading.
       
   178 */
       
   179 
       
   180 /*!
       
   181     \fn QMagnetometerFilter::filter(QMagnetometerReading *reading)
       
   182 
       
   183     Called when \a reading changes. Returns false to prevent the reading from propagating.
       
   184 
       
   185     \sa QSensorFilter::filter()
       
   186 */
       
   187 
       
   188 char const * const QMagnetometer::type("QMagnetometer");
       
   189 
       
   190 /*!
       
   191     \class QMagnetometer
       
   192     \ingroup sensors_type
       
   193 
       
   194     \brief The QMagnetometer class is a convenience wrapper around QSensor.
       
   195 
       
   196     The only behavioural difference is that this class sets the type properly.
       
   197 
       
   198     This class also features a reading() function that returns a QMagnetometerReading instead of a QSensorReading.
       
   199 
       
   200     For details about how the sensor works, see \l QMagnetometerReading.
       
   201 
       
   202     \sa QMagnetometerReading
       
   203 */
       
   204 
       
   205 /*!
       
   206     \fn QMagnetometer::QMagnetometer(QObject *parent)
       
   207 
       
   208     Construct the sensor as a child of \a parent.
       
   209 */
       
   210 
       
   211 /*!
       
   212     \fn QMagnetometer::~QMagnetometer()
       
   213 
       
   214     Destroy the sensor. Stops the sensor if it has not already been stopped.
       
   215 */
       
   216 
       
   217 /*!
       
   218     \fn QMagnetometer::reading() const
       
   219 
       
   220     Returns the reading class for this sensor.
       
   221 
       
   222     \sa QSensor::reading()
       
   223 */
       
   224 
       
   225 /*!
       
   226     \property QMagnetometer::returnGeoValues
       
   227     \brief a value indicating if geomagnetic values should be returned.
       
   228 
       
   229     Set to true to return geomagnetic flux density.
       
   230     Set to false (the default) to return raw magnetic flux density.
       
   231 
       
   232     Note that you must access this property via QObject::property() and QObject::setProperty().
       
   233     The property must be set before calling start().
       
   234 */
       
   235 
       
   236 #include "moc_qmagnetometer.cpp"
       
   237 QTM_END_NAMESPACE
       
   238