#include "mainwindow.h"
#include <QtGui/QApplication>
#include <stdio.h>
#define ACCELEROMETER_FILE_N900 "/sys/class/i2c-adapter/i2c-3/3-001d/coord"
class Accelerometer {
int x;
int y;
int z;
public:
Accelerometer() : x(0), y(0), z(0)
{
update();
}
bool update()
{
int tmp[3] = {0, 0, 0};
FILE *fd;
if (!(fd = fopen(ACCELEROMETER_FILE_N900, "r"))) {
return false;
}
if (fscanf(fd, "%i %i %i", tmp, tmp+1, tmp+2) != 3) {
return false;
}
if (fclose(fd) == EOF) {
return false;
}
x = tmp[0];
y = tmp[1];
z = tmp[2];
//How to change this?
writeln('x=%i',x);
return true;
}
int getX() { return x; }
int getY() { return y; }
int getZ() { return z; }
};
int main(int argc, char *argv[])
{
MainWindow mainWindow;
mainWindow.setOrientation(MainWindow::ScreenOrientationAuto);
mainWindow.showExpanded();
return app.exec();
}
#include "mainwindow.h"
#include <QtGui/QApplication>
#include <stdio.h>
#define ACCELEROMETER_FILE_N900 "/sys/class/i2c-adapter/i2c-3/3-001d/coord"
class Accelerometer {
int x;
int y;
int z;
public:
Accelerometer() : x(0), y(0), z(0)
{
update();
}
bool update()
{
int tmp[3] = {0, 0, 0};
FILE *fd;
if (!(fd = fopen(ACCELEROMETER_FILE_N900, "r"))) {
return false;
}
if (fscanf(fd, "%i %i %i", tmp, tmp+1, tmp+2) != 3) {
return false;
}
if (fclose(fd) == EOF) {
return false;
}
x = tmp[0];
y = tmp[1];
z = tmp[2];
//How to change this?
writeln('x=%i',x);
return true;
}
int getX() { return x; }
int getY() { return y; }
int getZ() { return z; }
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow mainWindow;
mainWindow.setOrientation(MainWindow::ScreenOrientationAuto);
mainWindow.showExpanded();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
The object name of label is label_2. Which code do I have to write to change Label2 text to accelerometer X value? Or what else do I have to write? Or do you have any examples of codes which show on smartphone view acceleration values with only one *.cpp file without any addidtional *.h files?
Bookmarks