equal
deleted
inserted
replaced
46 |
46 |
47 gruesensorimpl::gruesensorimpl(QSensor *sensor) |
47 gruesensorimpl::gruesensorimpl(QSensor *sensor) |
48 : QSensorBackend(sensor) |
48 : QSensorBackend(sensor) |
49 { |
49 { |
50 lightSensor = new QAmbientLightSensor(this); |
50 lightSensor = new QAmbientLightSensor(this); |
51 lightSensor->setUpdatePolicy(QSensor::OccasionalUpdates); |
|
52 lightSensor->addFilter(this); |
51 lightSensor->addFilter(this); |
|
52 lightSensor->connectToBackend(); |
53 |
53 |
54 setSupportedUpdatePolicies(QSensor::OnChangeUpdates | QSensor::OccasionalUpdates); |
|
55 setReading<GrueSensorReading>(&m_reading); |
54 setReading<GrueSensorReading>(&m_reading); |
|
55 setDataRates(lightSensor); |
|
56 addOutputRange(0, 1, 0.1); |
|
57 setDescription(QLatin1String("Grue Sensor")); |
56 } |
58 } |
57 |
59 |
58 void gruesensorimpl::start() |
60 void gruesensorimpl::start() |
59 { |
61 { |
|
62 lightSensor->setDataRate(sensor()->dataRate()); |
60 lightSensor->start(); |
63 lightSensor->start(); |
61 } |
64 } |
62 |
65 |
63 void gruesensorimpl::stop() |
66 void gruesensorimpl::stop() |
64 { |
67 { |
65 lightSensor->stop(); |
68 lightSensor->stop(); |
66 } |
|
67 |
|
68 void gruesensorimpl::poll() |
|
69 { |
|
70 lightSensor->poll(); |
|
71 } |
69 } |
72 |
70 |
73 bool gruesensorimpl::filter(QAmbientLightReading *reading) |
71 bool gruesensorimpl::filter(QAmbientLightReading *reading) |
74 { |
72 { |
75 qreal chance; |
73 qreal chance; |
87 default: |
85 default: |
88 chance = 0.0; |
86 chance = 0.0; |
89 break; |
87 break; |
90 } |
88 } |
91 |
89 |
92 if (QSensorBackend::m_sensor->updatePolicy() == QSensor::OccasionalUpdates || |
90 if (chance != m_reading.chanceOfBeingEaten()) { |
93 chance != m_reading.chanceOfBeingEaten()) { |
|
94 m_reading.setTimestamp(reading->timestamp()); |
91 m_reading.setTimestamp(reading->timestamp()); |
95 m_reading.setChanceOfBeingEaten(chance); |
92 m_reading.setChanceOfBeingEaten(chance); |
96 |
93 |
97 newReadingAvailable(); |
94 newReadingAvailable(); |
98 } |
95 } |