-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sensor.hpp
69 lines (56 loc) · 1.88 KB
/
Sensor.hpp
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
#pragma once
#include "pico/stdlib.h"
#include "hardware/pio.h"
class Sensor {
//--------------------------------------------------
// Constants
//--------------------------------------------------
public:
static const uint16_t DEFAULT_FREQ_DIVIDER = 1;
static const uint8_t PIN_UNUSED = UINT8_MAX;
private:
static const uint32_t BUFFER = 5000;
//--------------------------------------------------
// Variables
//--------------------------------------------------
private:
const PIO sens_pio = pio0;
const uint8_t pin = PIN_UNUSED;
const uint8_t sideset_pin = PIN_UNUSED;
const uint16_t freq_divider = DEFAULT_FREQ_DIVIDER;
//--------------------------------------------------
uint sens_sm = 0;
static uint sens_offset;
uint32_t last_on = 0;
bool initialised = false;
//--------------------------------------------------
// Statics
//--------------------------------------------------
public:
static Sensor* pio_sensors[NUM_PIOS][NUM_PIO_STATE_MACHINES];
static uint8_t pio_claimed_sms[NUM_PIOS];
static void pio0_interrupt_callback();
static void pio1_interrupt_callback();
//--------------------------------------------------
// Constructors/Destructor
//--------------------------------------------------
public:
Sensor() {}
Sensor(PIO pio, uint8_t pin, uint8_t sideset_pin,
uint16_t freq_divider = DEFAULT_FREQ_DIVIDER);
~Sensor();
//--------------------------------------------------
// Methods
//--------------------------------------------------
public:
bool init();
void start();
uint32_t last_on_time() { return last_on; }
uint32_t get_received(uint32_t& bufferCount);
static uint32_t millis();
private:
void check_for_transition();
volatile uint32_t receivedBuffer[BUFFER];
volatile uint32_t readIndex = 0;
volatile uint32_t writeIndex = 0;
};