39 ** |
39 ** |
40 ****************************************************************************/ |
40 ****************************************************************************/ |
41 |
41 |
42 #include "maemo6proximitysensor.h" |
42 #include "maemo6proximitysensor.h" |
43 |
43 |
44 const char *maemo6proximitysensor::id("maemo6.proximity"); |
44 char const * const maemo6proximitysensor::id("maemo6.proximity"); |
45 bool maemo6proximitysensor::m_initDone = false; |
45 bool maemo6proximitysensor::m_initDone = false; |
46 |
46 |
47 maemo6proximitysensor::maemo6proximitysensor(QSensor *sensor) |
47 maemo6proximitysensor::maemo6proximitysensor(QSensor *sensor) |
48 : maemo6sensorbase(sensor) |
48 : maemo6sensorbase(sensor) |
49 { |
49 { |
|
50 const QString sensorName = "proximitysensor"; |
|
51 initSensor<ProximitySensorChannelInterface>(sensorName, m_initDone); |
|
52 |
|
53 if (m_sensorInterface){ |
|
54 if (!(QObject::connect(m_sensorInterface, SIGNAL(dataAvailable(const Unsigned&)), |
|
55 this, SLOT(slotDataAvailable(const Unsigned&))))) |
|
56 qWarning() << "Unable to connect "<< sensorName; |
|
57 } |
|
58 else |
|
59 qWarning() << "Unable to initialize "<<sensorName; |
50 setReading<QProximityReading>(&m_reading); |
60 setReading<QProximityReading>(&m_reading); |
51 |
61 // metadata |
52 if (!m_initDone) { |
62 addDataRate(2, 2); // 2 Hz |
53 initSensor<ProximitySensorChannelInterface>("proximitysensor"); |
63 addOutputRange(0, 1, 1); // close definition in meters - may be used as metadata even the sensor gives true/false values |
54 |
64 setDescription(QLatin1String("Measures if a living object is in proximity or not")); |
55 if (m_sensorInterface) |
|
56 QObject::connect(static_cast<ProximitySensorChannelInterface*>(m_sensorInterface), SIGNAL(dataAvailable(const Unsigned&)), this, SLOT(slotDataAvailable(const Unsigned&))); |
|
57 else |
|
58 qWarning() << "Unable to initialize proximity sensor."; |
|
59 |
|
60 // metadata |
|
61 addDataRate(2, 2); // 2Hz |
|
62 sensor->setDataRate(2); |
|
63 addOutputRange(0, 1, 1); // close definition in meters - may be used as metadata even the sensor gives true/false values |
|
64 setDescription(QLatin1String("Measures if a living object is in proximity or not")); |
|
65 |
|
66 m_initDone = true; |
|
67 } |
|
68 } |
65 } |
69 |
66 |
70 void maemo6proximitysensor::slotDataAvailable(const Unsigned& data) |
67 void maemo6proximitysensor::slotDataAvailable(const Unsigned& data) |
71 { |
68 { |
72 bool close; |
69 m_reading.setClose(data.x()? true: false); |
73 if (data.x()) |
|
74 close = true; |
|
75 else |
|
76 close = false; |
|
77 m_reading.setClose(close); |
|
78 m_reading.setTimestamp(data.UnsignedData().timestamp_); |
70 m_reading.setTimestamp(data.UnsignedData().timestamp_); |
79 newReadingAvailable(); |
71 newReadingAvailable(); |
80 } |
72 } |