qtmobility/plugins/sensors/maemo6/maemo6als.cpp
changeset 11 06b8e2af4411
parent 8 71781823f776
child 14 6fbed849b4f4
equal deleted inserted replaced
8:71781823f776 11:06b8e2af4411
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the Qt Mobility Components.
     7 ** This file is part of the Qt Mobility Components.
     8 **
     8 **
    50     setReading<QAmbientLightReading>(&m_reading);
    50     setReading<QAmbientLightReading>(&m_reading);
    51     if (!m_initDone) {
    51     if (!m_initDone) {
    52         initSensor<ALSSensorChannelInterface>("alssensor");
    52         initSensor<ALSSensorChannelInterface>("alssensor");
    53 
    53 
    54         if (m_sensorInterface)
    54         if (m_sensorInterface)
    55             QObject::connect(static_cast<const ALSSensorChannelInterface*>(m_sensorInterface), SIGNAL(ALSChanged(const int&)), this, SLOT(slotDataAvailable(const int&)));
    55             QObject::connect(static_cast<const ALSSensorChannelInterface*>(m_sensorInterface), SIGNAL(ALSChanged(const Unsigned&)), this, SLOT(slotDataAvailable(const Unsigned&)));
    56         else
    56         else
    57             qWarning() << "Unable to initialize ambient light sensor.";
    57             qWarning() << "Unable to initialize ambient light sensor.";
    58 
    58 
    59         // metadata
    59         // metadata
    60         addDataRate(1, 1); // 1Hz
    60         addDataRate(1, 1); // 1Hz
    61         sensor->setDataRate(1);
    61         sensor->setDataRate(1);
    62         addOutputRange(0, 5, 1);
    62         addOutputRange(0, 5, 1);
    63         setDescription(QLatin1String("Ambient light intensity given as 5 pre-defined levels"));
    63         setDescription(QLatin1String("Measures ambient light intensity given as 5 pre-defined levels"));
    64 
    64 
    65         m_initDone = true;
    65         m_initDone = true;
    66     }
    66     }
    67 }
    67 }
    68 
    68 
    69 void maemo6als::slotDataAvailable(const int& data)
    69 void maemo6als::slotDataAvailable(const Unsigned& data)
    70 {
    70 {
    71     // Convert from integer to fixed levels
    71     // Convert from integer to fixed levels
    72     // TODO: verify levels
    72     // TODO: verify levels
    73     QAmbientLightReading::LightLevel level;
    73     QAmbientLightReading::LightLevel level;
    74     if (data < 0) {
    74     int x = data.x();
       
    75     if (x < 0) {
    75         level = QAmbientLightReading::Undefined;
    76         level = QAmbientLightReading::Undefined;
    76     } else if (data < 10) {
    77     } else if (x < 10) {
    77         level = QAmbientLightReading::Dark;
    78         level = QAmbientLightReading::Dark;
    78     } else if (data < 50) {
    79     } else if (x < 50) {
    79         level = QAmbientLightReading::Twilight;
    80         level = QAmbientLightReading::Twilight;
    80     } else if (data < 100) {
    81     } else if (x < 100) {
    81         level = QAmbientLightReading::Light;
    82         level = QAmbientLightReading::Light;
    82     } else if (data < 150) {
    83     } else if (x < 150) {
    83         level = QAmbientLightReading::Bright;
    84         level = QAmbientLightReading::Bright;
    84     } else {
    85     } else {
    85         level = QAmbientLightReading::Sunny;
    86         level = QAmbientLightReading::Sunny;
    86     }
    87     }
    87 
       
    88     if (level != m_reading.lightLevel()) {
    88     if (level != m_reading.lightLevel()) {
    89         m_reading.setLightLevel(level);
    89         m_reading.setLightLevel(level);
    90         //m_reading.setTimestamp(data.timestamp());
    90         m_reading.setTimestamp(data.UnsignedData().timestamp_);
    91         m_reading.setTimestamp(createTimestamp()); //TODO: use correct timestamp
       
    92         newReadingAvailable();
    91         newReadingAvailable();
    93     }
    92     }
    94 }
    93 }