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 ** |
51 |
51 |
52 if (!m_initDone) { |
52 if (!m_initDone) { |
53 initSensor<CompassSensorChannelInterface>("compasssensor"); |
53 initSensor<CompassSensorChannelInterface>("compasssensor"); |
54 |
54 |
55 if (m_sensorInterface) { |
55 if (m_sensorInterface) { |
56 QObject::connect(static_cast<CompassSensorChannelInterface*>(m_sensorInterface), SIGNAL(levelChanged(const int&)), this, SLOT(slotLevelChanged(const int&))); |
56 QObject::connect(static_cast<CompassSensorChannelInterface*>(m_sensorInterface), SIGNAL(dataAvailable(const Compass&)), this, SLOT(dataAvailable(const Compass&))); |
57 QObject::connect(static_cast<CompassSensorChannelInterface*>(m_sensorInterface), SIGNAL(degreesChanged(const int&)), this, SLOT(slotDegreesChanged(const int&))); |
|
58 } else { |
57 } else { |
59 qWarning() << "Unable to initialize compass sensor."; |
58 qWarning() << "Unable to initialize compass sensor."; |
60 } |
59 } |
61 |
60 |
62 // metadata TODO accuracy |
61 // metadata TODO accuracy |
67 |
66 |
68 m_initDone = true; |
67 m_initDone = true; |
69 } |
68 } |
70 } |
69 } |
71 |
70 |
72 void maemo6compass::slotLevelChanged(const int& level) |
71 void maemo6compass::dataAvailable(const Compass& data) |
73 { |
72 { |
74 // The scale for level is [0,3], where 3 is the best |
73 // The scale for level is [0,3], where 3 is the best |
75 // Qt: Measured as a value from 0 to 1 with higher values being better. |
74 // Qt: Measured as a value from 0 to 1 with higher values being better. |
76 float l = ((float) level) / 3.0; |
75 m_reading.setCalibrationLevel(((float) data.level()) / 3.0); |
77 |
76 |
78 qreal calibrationLevel = l; |
77 // The scale for degrees from sensord is [0,359] |
79 m_reading.setCalibrationLevel(calibrationLevel); |
78 // Value can be directly used as azimuth |
80 //m_reading.setTimestamp(level.timestamp()); |
79 m_reading.setAzimuth(data.degrees()); |
81 m_reading.setTimestamp(createTimestamp()); //TODO: use correct timestamp |
80 |
|
81 m_reading.setTimestamp(data.data().timestamp_); |
82 newReadingAvailable(); |
82 newReadingAvailable(); |
83 } |
83 } |
84 |
|
85 void maemo6compass::slotDegreesChanged(const int& degrees) |
|
86 { |
|
87 // The scale for degrees from sensord is [0,359] |
|
88 // Value can be directly used as azimuth |
|
89 qreal azimuth = degrees; |
|
90 m_reading.setAzimuth(azimuth); |
|
91 //m_reading.setTimestamp(degrees.timestamp()); |
|
92 m_reading.setTimestamp(createTimestamp()); //TODO: use correct timestamp |
|
93 newReadingAvailable(); |
|
94 } |
|