summaryrefslogtreecommitdiffstats
path: root/examples/sensors/grue/plugin
diff options
context:
space:
mode:
authorWolfgang Beck <wolfgang.beck@nokia.com>2011-12-15 14:11:46 +1000
committerQt by Nokia <qt-info@nokia.com>2011-12-20 04:38:54 +0100
commit52a414bd2291dbf9b99606019ab50a914280ecb0 (patch)
treee9c25309ea7aa6c121b688459ab491436406e9e8 /examples/sensors/grue/plugin
parent72a3d3b60b20abbc7e6af2ec1e33275bfa7841b1 (diff)
Grue example doesn't work in simulator
Change-Id: I486e24befd3f31345ec7f8dffd9a183f9f2ec4cb Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Lincoln Ramsay <lincoln.ramsay@nokia.com>
Diffstat (limited to 'examples/sensors/grue/plugin')
-rw-r--r--examples/sensors/grue/plugin/gruesensorimpl.cpp17
-rw-r--r--examples/sensors/grue/plugin/gruesensorimpl.h1
2 files changed, 12 insertions, 6 deletions
diff --git a/examples/sensors/grue/plugin/gruesensorimpl.cpp b/examples/sensors/grue/plugin/gruesensorimpl.cpp
index d06ab8ee..7ea4aa00 100644
--- a/examples/sensors/grue/plugin/gruesensorimpl.cpp
+++ b/examples/sensors/grue/plugin/gruesensorimpl.cpp
@@ -46,6 +46,7 @@ char const * const gruesensorimpl::id("grue.gruesensor");
gruesensorimpl::gruesensorimpl(QSensor *sensor)
: QSensorBackend(sensor)
+ , lightLevel(QAmbientLightReading::Undefined)
{
// We need a light sensor
lightSensor = new QAmbientLightSensor(this);
@@ -95,13 +96,18 @@ void gruesensorimpl::stop()
void gruesensorimpl::lightChanged()
{
- qreal chance = 0.0;
+ if (lightLevel == lightSensor->reading()->lightLevel())
+ return;
+
+ lightLevel = lightSensor->reading()->lightLevel();
+
+ int chance = 0;
darkTimer->stop();
switch (lightSensor->reading()->lightLevel()) {
case QAmbientLightReading::Dark:
// It is dark. You are likely to be eaten by a grue.
- chance = 0.1;
+ chance = 10;
darkTimer->start();
break;
default:
@@ -112,7 +118,6 @@ void gruesensorimpl::lightChanged()
if (chance != m_reading.chanceOfBeingEaten() || m_reading.timestamp() == 0) {
m_reading.setTimestamp(timer.elapsed());
m_reading.setChanceOfBeingEaten(chance);
-
newReadingAvailable();
}
}
@@ -120,16 +125,16 @@ void gruesensorimpl::lightChanged()
void gruesensorimpl::increaseChance()
{
// The longer you stay in the dark, the higher your chance of being eaten
- qreal chance = m_reading.chanceOfBeingEaten() + 0.1;
+ int chance = m_reading.chanceOfBeingEaten() + 10;
m_reading.setTimestamp(timer.elapsed());
m_reading.setChanceOfBeingEaten(chance);
newReadingAvailable();
- // No point in using the timer anymore if we've hit 1... you can't get more
+ // No point in using the timer anymore if we've hit 100... you can't get more
// likely to be eaten than 100%
- if (chance >= 1.0)
+ if (chance >= 100)
darkTimer->stop();
}
diff --git a/examples/sensors/grue/plugin/gruesensorimpl.h b/examples/sensors/grue/plugin/gruesensorimpl.h
index fa4938e7..55d567be 100644
--- a/examples/sensors/grue/plugin/gruesensorimpl.h
+++ b/examples/sensors/grue/plugin/gruesensorimpl.h
@@ -70,6 +70,7 @@ private:
QAmbientLightSensor *lightSensor;
QTimer *darkTimer;
QTime timer;
+ QAmbientLightReading::LightLevel lightLevel;
};
#endif