Active Topics

 


Reply
Thread Tools
shep's Avatar
Posts: 85 | Thanked: 65 times | Joined on Jan 2010 @ Ireland
#1
Hi All,

I'm trying to parse the accelerometer data using QT.

My code looks like this:
Code:
void MainWindow::update_accel()
{

    // read the file /sys/class/i2c-adapter/i2c-3/3-001d/coord

    QFile file("/sys/class/i2c-adapter/i2c-3/3-001d/coord");
    if (!file.open (QIODevice::ReadOnly))
    {
        return;
    }
    else
    {
        QTextStream stream ( &file );
        QString line;
        while( !stream.atEnd() )
        {
            line = stream.readLine();

            ui->label->setText(line);
        }
    }
}
The app just hangs when I call this function and I can't figure out why. I have tried on Windows to use another filename and it works fine...but the app hangs on the N900.

Any clues?

Thanks!

Shep
__________________
- Hey! I also do other stuff Touchscreen apps for Windows and Android
- Currently developing a Diet Assistant/Weight Tracker for the N900
 
Posts: 63 | Thanked: 52 times | Joined on Jan 2006 @ Brisbane, Australia
#2
http://doc.trolltech.com/4.6/qfile.html

On Unix, there are some special system files (e.g. in /proc) for which size() will always return 0, yet you may still be able to read more data from such a file; the data is generated in direct response to you calling read(). In this case, however, you cannot use atEnd() to determine if there is more data to read (since atEnd() will return true for a file that claims to have size 0). Instead, you should either call readAll(), or call read() or readLine() repeatedly until no more data can be read.
__________________
Programmer, connectivity, sensors, Jolla/llornkcor technologies
 

The Following 2 Users Say Thank You to lpotter For This Useful Post:
Posts: 13 | Thanked: 18 times | Joined on Jun 2009 @ India
#3
Try following code, it works for me.

static const QString PROC_ENTRY = "/sys/class/i2c-adapter/i2c-3/3-001d/coord";


QFile f(PROC_ENTRY);
if (!f.exists() or !f.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << "could not read motion data";
}
else {
QByteArray line = f.readLine();
QRegExp rx("([0-9-]+) ([0-9-]+) ([0-9-]+)");

rx.indexIn(line);
qreal x = rx.cap(1).toInt();
qreal y = rx.cap(2).toInt();
qreal z = rx.cap(3).toInt();

mCurrentPos.setX(x);
mCurrentPos.setY(y);

f.close();
}
 

The Following 7 Users Say Thank You to kunal_the_one For This Useful Post:
shep's Avatar
Posts: 85 | Thanked: 65 times | Joined on Jan 2010 @ Ireland
#4
Originally Posted by kunal_the_one View Post
Try following code, it works for me.
That works great! Thanks a million.

One more question...using a sample rate of 30 times per second I see some "jitter" on all 3-axes ... +/-18?

Is that right? Caused by gravity? Unusual solar flare activity?

Shep
__________________
- Hey! I also do other stuff Touchscreen apps for Windows and Android
- Currently developing a Diet Assistant/Weight Tracker for the N900
 
Posts: 60 | Thanked: 33 times | Joined on Apr 2010
#5
 

The Following 2 Users Say Thank You to raedbenz For This Useful Post:
shep's Avatar
Posts: 85 | Thanked: 65 times | Joined on Jan 2010 @ Ireland
#6
Great article, thanks!
__________________
- Hey! I also do other stuff Touchscreen apps for Windows and Android
- Currently developing a Diet Assistant/Weight Tracker for the N900
 
Reply


 
Forum Jump


All times are GMT. The time now is 16:12.