qtmobility/examples/sensors/metadata/main.cpp
changeset 11 06b8e2af4411
equal deleted inserted replaced
8:71781823f776 11:06b8e2af4411
       
     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:BSD$
       
    10 ** You may use this file under the terms of the BSD license as follows:
       
    11 **
       
    12 ** "Redistribution and use in source and binary forms, with or without
       
    13 ** modification, are permitted provided that the following conditions are
       
    14 ** met:
       
    15 **   * Redistributions of source code must retain the above copyright
       
    16 **     notice, this list of conditions and the following disclaimer.
       
    17 **   * Redistributions in binary form must reproduce the above copyright
       
    18 **     notice, this list of conditions and the following disclaimer in
       
    19 **     the documentation and/or other materials provided with the
       
    20 **     distribution.
       
    21 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
       
    22 **     the names of its contributors may be used to endorse or promote
       
    23 **     products derived from this software without specific prior written
       
    24 **     permission.
       
    25 **
       
    26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
       
    27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
       
    28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
       
    29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
       
    30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
       
    31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
       
    32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
       
    33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
       
    34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
       
    37 ** $QT_END_LICENSE$
       
    38 **
       
    39 ****************************************************************************/
       
    40 
       
    41 #include <QtCore>
       
    42 #include <qaccelerometer.h>
       
    43 #include <qambientlightsensor.h>
       
    44 #include <qcompass.h>
       
    45 #include <qmagnetometer.h>
       
    46 #include <qorientationsensor.h>
       
    47 #include <qproximitysensor.h>
       
    48 #include <qrotationsensor.h>
       
    49 #include <qtapsensor.h>
       
    50 
       
    51 QTM_USE_NAMESPACE
       
    52 
       
    53 bool checkSensor( QSensor *sensor )
       
    54 {
       
    55     QTextStream out(stdout);
       
    56     bool conclusion = true;
       
    57     out << endl << "--- Metadata ---" << endl;
       
    58 
       
    59     // Get readings from functions
       
    60 
       
    61     // void     addFilter ( QSensorFilter * filter )
       
    62     qrangelist sen_datarates = sensor->availableDataRates();
       
    63     // bool     connectToBackend ()
       
    64     int sen_datarate = sensor->dataRate();
       
    65     QString sen_desc = sensor->description();
       
    66     int sen_error = sensor->error();
       
    67     QByteArray sen_ident = sensor->identifier();
       
    68     bool sen_active = sensor->isActive();
       
    69     bool sen_busy = sensor->isBusy();
       
    70     bool sen_isConn = sensor->isConnectedToBackend();
       
    71     int sen_outRange = sensor->outputRange();
       
    72     qoutputrangelist sen_outRList = sensor->outputRanges();
       
    73     QSensorReading *sen_reading = sensor->reading();
       
    74     // void 	removeFilter ( QSensorFilter * filter )
       
    75     // void 	setDataRate ( int rate )
       
    76     // void 	setIdentifier ( const QByteArray & identifier )
       
    77     // void 	setOutputRange ( int index )
       
    78     QByteArray sen_type = sensor->type();
       
    79 
       
    80     // Print findings
       
    81 
       
    82     out << "Identifier: " << sen_ident
       
    83         << " Type: " << sen_type << endl;
       
    84     out << "Description: " << sen_desc << endl;
       
    85     out << "Active: " << sen_active
       
    86         << " Busy: " << sen_busy
       
    87         << " Connected: " << sen_isConn
       
    88         << " Last error: " << sen_error << endl;
       
    89 
       
    90     out << "Using datarate: " << sen_datarate
       
    91         << " Out of:";
       
    92     for( int i = 0; i < sen_datarates.size(); ++i )
       
    93     {
       
    94         out << " [" << sen_datarates[i].first << "," << sen_datarates[i].second << "]";
       
    95     }
       
    96     out << endl;
       
    97 
       
    98     out << "Using output range: " << sen_outRange
       
    99         << " Out of (min,max,accuracy):";
       
   100     for( int i = 0; i < sen_outRList.size(); ++i )
       
   101     {
       
   102         out << " (" << sen_outRList[i].minimum << "," << sen_outRList[i].maximum << "," << sen_outRList[i].accuracy << ")";
       
   103     }
       
   104     out << endl;
       
   105 
       
   106     //out << sen_reading << endl; //QSensorReading *
       
   107 
       
   108     return conclusion;
       
   109 }
       
   110 
       
   111 int main( int argc, char **argv )
       
   112 {
       
   113     QCoreApplication app(argc, argv);
       
   114     QTextStream out(stdout);
       
   115     bool result = true;
       
   116 
       
   117     QSensor *sensors[8];
       
   118     sensors[0] = new QAccelerometer;
       
   119     sensors[1] = new QAmbientLightSensor;
       
   120     sensors[2] = new QCompass;
       
   121     sensors[3] = new QMagnetometer;
       
   122     sensors[4] = new QOrientationSensor;
       
   123     sensors[5] = new QProximitySensor;
       
   124     sensors[6] = new QRotationSensor;
       
   125     sensors[7] = new QTapSensor;
       
   126 
       
   127     for( int i = 0; i < 8; ++i )
       
   128     {
       
   129         if( ! sensors[i] )
       
   130         {
       
   131             out << "sensor number " << i << " unavailable" << endl;
       
   132             continue;
       
   133         }
       
   134         if( ! sensors[i]->connectToBackend() )
       
   135         {
       
   136             out << "connectToBackend failed" << endl;
       
   137             result = false;
       
   138         } else {
       
   139             if( ! checkSensor( sensors[i] ) )
       
   140                 result = false;
       
   141         }
       
   142     }
       
   143 
       
   144     return result;
       
   145 }