Repository navigation
Expand file tree
/
Copy pathsensing.hh
More file actions
75 lines (55 loc) · 1.74 KB
/
Copy pathsensing.hh
File metadata and controls
75 lines (55 loc) · 1.74 KB
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
70
71
72
73
74
75
// water.hh
#ifndef SENSING_H
#define SENSING_H
#include <array>
#include <ctime>
#include <queue>
#include <deque>
#include "DRV8833.hh"
#define POSITIONS 130
template <typename T, int MaxLen, typename Container=std::deque<T>>
class FixedQueue : public std::queue<T, Container> {
public:
void push(const T& value) {
if (this->size() == MaxLen) {
this->c.pop_front();
}
std::queue<T, Container>::push(value);
}
};
typedef struct result {
std::time_t time;
std::array<uint16_t, POSITIONS> vis_results;
std::array<uint16_t, POSITIONS> nir_results;
} result_t;
class Sensing {
public:
// Singleton functions
// Get Sensing instance
static Sensing& instance();
// Disallow copying
Sensing& operator = (const Sensing&) = delete;
Sensing(const Sensing&) = delete;
// Disallow moving
Sensing& operator = (Sensing&&) = delete;
Sensing(Sensing&&) = delete;
// Class functions
// Performs ADC conversion and pushes a result_t onto the FixedQueue results
void getResult(DRV8833& motor);
inline float resultRawToFloat(uint16_t raw_result);
// Set lamp on or off
void lampSet(bool on);
// Toggle lamp
void lampToggle(void);
result_t queuePeek(void);
private:
// Singleton variables
Sensing();
~Sensing();
// Class variables
const uint16_t ONE_VOLT = static_cast<uint16_t>(static_cast<float>(UINT16_MAX) / static_cast<float>(3.3));
unsigned int lampGpio;
bool lampOn;
FixedQueue<result_t, 4> results;
};
#endif // SENSING_H