1 #include <QtCore/QFile>
2 #include <QtGui/QPainter>
6 #include "ameterwidget.h"
8 #define SET_IM_STATUS 1
10 AMeterWidget::AMeterWidget(QWidget *parent)
13 // Reciprocal of gravity
15 // timer = new QTimer(this);
16 connect(timer, SIGNAL(timeout()), this, SLOT(tick()));
29 telepathist = new Telepathist(this);
32 m_sensor = new QAccelerometer(this);
33 m_sensor->addFilter(this);
37 AMeterWidget::~AMeterWidget()
42 void AMeterWidget::paintEvent(QPaintEvent *e)
48 a = sqrt(ax * ax + ay * ay + az * az);
52 paint.drawImage(QPoint(0, 0), *image);
55 paint.setRenderHints(QPainter::Antialiasing);
65 paint.setPen(QPen(QBrush(QColor(255, 255, 255, 255)), 1));
66 paint.setBrush(QBrush(QColor(255, 255, 255, 255)));
67 paint.drawEllipse(QPointF(x1, y1), 3, 3);
68 paint.drawLine(QPointF(cx, cy), QPointF(x1, y1));
71 void AMeterWidget::resizeEvent(QResizeEvent *e)
82 image = new QImage(size(), QImage::Format_ARGB32);
83 paint = new QPainter(image);
84 paint->setRenderHints(QPainter::Antialiasing);
91 paint->setPen(QPen(QBrush(QColor(64, 64, 64, 255)), 3));
93 paint->drawLine(QPointF(cx, 0), QPointF(cx, cy + cy));
94 paint->drawLine(QPointF(0, cy), QPointF(cx + cx, cy));
96 paint->drawEllipse(QPointF(cx, cy), rx, ry);
97 paint->drawEllipse(QPointF(cx, cy), 2 * rx, 2 * ry);
98 paint->drawEllipse(QPointF(cx, cy), 3 * rx, 3 * ry);
99 paint->drawEllipse(QPointF(cx, cy), 4 * rx, 4 * ry);
101 paint->setPen(QPen(QBrush(QColor(64, 64, 64, 255)), 1));
103 paint->drawLine(QPointF(cx - cx, cy + cx), QPointF(cx + cx, cy - cx));
104 paint->drawLine(QPointF(cx - cx, cy - cx), QPointF(cx + cx, cy + cx));
106 paint->drawEllipse(QPointF(cx, cy), 0.25 * rx, 0.25 * ry);
107 paint->drawEllipse(QPointF(cx, cy), 0.50 * rx, 0.50 * ry);
108 paint->drawEllipse(QPointF(cx, cy), 0.75 * rx, 0.75 * ry);
110 paint->drawEllipse(QPointF(cx, cy), 1.25 * rx, 1.25 * ry);
111 paint->drawEllipse(QPointF(cx, cy), 1.50 * rx, 1.50 * ry);
112 paint->drawEllipse(QPointF(cx, cy), 1.75 * rx, 1.75 * ry);
114 paint->drawEllipse(QPointF(cx, cy), 2.25 * rx, 2.25 * ry);
115 paint->drawEllipse(QPointF(cx, cy), 2.50 * rx, 2.50 * ry);
116 paint->drawEllipse(QPointF(cx, cy), 2.75 * rx, 2.75 * ry);
119 paint->drawEllipse(QPointF(cx, cy), 3.25 * rx, 3.25 * ry);
120 paint->drawEllipse(QPointF(cx, cy), 3.50 * rx, 3.50 * ry);
121 paint->drawEllipse(QPointF(cx, cy), 3.75 * rx, 3.75 * ry);
126 bool AMeterWidget::filter(QAccelerometerReading *reading)
128 ax = reading->x() * rg;
129 ay = reading->y() * rg;
130 az = reading->z() * rg;
137 void AMeterWidget::tick()
147 f = new QFile("/sys/class/i2c-adapter/i2c-3/3-001d/coord");
148 if (f->open(QFile::ReadOnly))
150 f->read(strbuf, 127);
151 if (sscanf(strbuf, "%d %d %d", &x, &y, &z) == 3)
162 if (fabs(ax - bx) > 0.125 || fabs(ay - by) > 0.125 || fabs(az - bz) > 0.125)
167 telepathist->setStatus(2, "available", "In the pocket");
176 telepathist->setStatus(3, "away", "Fishing");