-
Notifications
You must be signed in to change notification settings - Fork 0
/
Speedometer.h
62 lines (52 loc) · 1.73 KB
/
Speedometer.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
#ifndef _SPEEDOMETER__H_
#define _SPEEDOMETER__H_
#include <StateMachine.h>
#include "Sensor.h"
#include "RangeWindow.h"
#define TRACE 0
class Speedometer : public StateMachine {
public:
// Define model scales, such as 160 for US N scale of 1:160
enum E_Scale {
eUK = 148, eJP = 150, eUS = 160
};
private:
// Separation of sensors (mm)
const int m_spacing;
// Time of most recent first-detect (msec)
uint32_t m_sense_when;
// Measured speed (scale mi/hr or km/hr)
double m_speed;
// Model scale (1:148, 1:150, or 1:160)
E_Scale m_scale;
// (Pointer to) Window of range
RangeWindow<uint8_t>* m_window;
// Metric (km/hr) or imperial (mi/hr)
bool m_metric;
// State of finite state machine
enum E_State {
eClear, // waiting for sense on sensor A or B
eSenseA, // sensed on A, waiting for B
eSenseB, // sensed on B, waiting for A
eUpdated, // speed measured, waiting for display to update
eActive, // waiting for both sensors to clear
eClearing // waiting for timeout after sensors clear
} m_state;
bool m_detA; // sensor A detected
bool m_detB; // sensor B detected
bool m_triggered; // sensor emitters triggered
bool m_updated; // speed measure updated
public:
Speedometer(E_Scale s = eJP);
virtual bool update();
int begin();
void setScale(E_Scale s);
void setMetric(bool m);
void setWindow(RangeWindow<uint8_t>* win);
bool inWindow(const uint8_t range) const;
bool within(const uint8_t range) const;
double calcScaleSpeed(const uint32_t dt_msec) const;
bool isUpdated();
double getSpeed();
};
#endif