projects
/
speedfreak
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
67d43ca
)
Fixed a bug in calibrate function
author
Rikhard Kuutti
<rikhard.kuutti@fudeco.com>
Fri, 5 Mar 2010 09:10:52 +0000
(11:10 +0200)
committer
Rikhard Kuutti
<rikhard.kuutti@fudeco.com>
Fri, 5 Mar 2010 09:10:52 +0000
(11:10 +0200)
Client/accelerometer.cpp
patch
|
blob
|
history
diff --git
a/Client/accelerometer.cpp
b/Client/accelerometer.cpp
index
04a05ce
..
b2fa1d5
100644
(file)
--- a/
Client/accelerometer.cpp
+++ b/
Client/accelerometer.cpp
@@
-97,15
+97,21
@@
void Accelerometer::initValues()
*/
void Accelerometer::calibrate(void)
{
*/
void Accelerometer::calibrate(void)
{
- QFile file(kFileName);
- if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) return;
-
unsigned int iteration = 0;
unsigned int iteration = 0;
- QByteArray line;
- QRegExp rx("([0-9-]+) ([0-9-]+) ([0-9-]+)");
-
do {
do {
+ // Opening the file must be done inside the loop
+ // or else the values obtained from file.readLine();
+ // will be empty for all but the first iteration
+ QFile file(kFileName);
+ if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
+ {
+ return;
+ }
+
+ QByteArray line;
+ QRegExp rx("([0-9-]+) ([0-9-]+) ([0-9-]+)");
+
// Read data, parse with regular expressions and process it
line = file.readLine();
rx.indexIn(line);
// Read data, parse with regular expressions and process it
line = file.readLine();
rx.indexIn(line);
@@
-114,18
+120,18
@@
void Accelerometer::calibrate(void)
int sampleY = rx.cap(2).toInt();
int sampleZ = rx.cap(3).toInt();
int sampleY = rx.cap(2).toInt();
int sampleZ = rx.cap(3).toInt();
- calibrationX += sampleX; // Accumulate Samples
- calibrationY += sampleY; // for all axes.
- calibrationZ += sampleZ;
+ calibrationX = calibrationX + sampleX; // Accumulate Samples
+ calibrationY = calibrationY + sampleY; // for all axes.
+ calibrationZ = calibrationZ + sampleZ;
iteration++;
iteration++;
- } while(iteration!=1024); // 1024 times
- calibrationX = calibrationX>>10; // division by 1024
+ file.close();
+ } while(iteration != 1024); // 1024 times
+
+ calibrationX = calibrationX>>10; // division by 1024
calibrationY = calibrationY>>10;
calibrationZ = calibrationZ>>10;
calibrationY = calibrationY>>10;
calibrationZ = calibrationZ>>10;
-
- file.close();
}
/**
}
/**