-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdetector.h
executable file
·69 lines (59 loc) · 2.4 KB
/
detector.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef DETECTOR_H
#define DETECTOR_H
#include <QAccelerometer>
#include <QTimer>
#include <QThread>
QTM_USE_NAMESPACE
/// Step Detector.
class Detector: public QObject {
Q_OBJECT
Q_ENUMS(Activity)
Q_PROPERTY(bool running READ running WRITE setRunning NOTIFY runningChanged)
Q_PROPERTY(int activity READ activity NOTIFY activityChanged)
Q_PROPERTY(int runningStepTimeDiff READ runningStepTimeDiff WRITE setRunningStepTimeDiff NOTIFY runningStepTimeDiffChanged)
Q_PROPERTY(int minReadingDiff READ minReadingDiff WRITE setMinReadingDiff NOTIFY minReadingDiffChanged)
public:
enum Activity {
Idle,
Unknown,
Walking,
Running
};
explicit Detector(QObject *parent = 0);
void init(); ///< Initialize the accelerometer.
bool running() {return running_;}
int activity() {return (int)activity_;}
int runningStepTimeDiff() {return runningStepTimeDiff_;}
int minReadingDiff() {return minReadingDiff_;}
signals:
void step(int value);
void runningChanged(bool value);
void activityChanged(int value);
void runningStepTimeDiffChanged(int value);
void minReadingDiffChanged(int value);
public slots:
void setRunning(bool value);
void setActivity(Activity value);
void setRunningStepTimeDiff(int value);
void setMinReadingDiff(int value);
void detect(); ///< Detect step.
void reset(); ///< Reset all parameters to default.
void report(); ///< Report step count.
/// Guess current activity (running or walking) and adapt parameters to it.
void adapt(qreal reading, qint64 timeStamp);
public:
QAccelerometer *accelerometer_;
bool increasing_; ///< True if accelerometer readings are increasing.
qreal lastReading_; ///< Last accelerometer reading.
qint64 lastStepTime_; ///< Time of the last step (ms since Epoch).
qint64 minStepTimeDiff_; ///< Minimum time between steps (ms).
unsigned readingCount_; ///< Reading count.
qreal totalReading_; ///< Sum of the last N accelerometer readings.
Activity activity_; ///< Current activity.
bool running_; ///< True if the DetectorWorker is running.
int runningStepTimeDiff_; ///< Minimum time difference between steps, while running (ms).
int minReadingDiff_; ///< Minimum reading delta to consider a step.
int stepCount_; ///< Total unreported step count.
QTimer *reporter_; ///< Step reporter timer.
};
#endif // DETECTOR_H