tarask
6 days ago 532005c6573d95199ce0ffbc33df4c7a0a4c3ef9
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
#ifndef NRA15_H
#define NRA15_H
 
#include <Arduino.h>
 
// Pin number for UART
#define NRA15_RX_PIN 16  // ESP32 RX <- NRA15 TX (yellow)
#define NRA15_TX_PIN 17  // ESP32 TX -> NRA15 RX (white)
 
// Max distance for NRA-15 in cm
#define RANGEFINDER_NRA15_MAX_DISTANCE 10000  // 100m = 10000cm
 
// Uncomment to use HardwareSerial instead of SoftwareSerial
// #define NRA15_USE_HARDWARE_SERIAL
 
#ifndef NRA15_USE_HARDWARE_SERIAL
    #include <SoftwareSerial.h>
#endif
 
/**
 * @brief The NRA15 class represents an NRA-15 radar device.
 * 
 * This class provides methods to communicate with NRA-15 radar
 * and send data via MAVLink protocol.
 */
class NRA15 {
public:
    /**
     * @brief Default constructor
     */
    NRA15() {}
    
    /**
     * @brief Destructor
     */
    ~NRA15();
    
    /**
     * @brief Task function for handling NRA-15 data reception.
     * 
     * @param pvParameters Pointer to task parameters (TaskCreator)
     */
    static void NRA15RxTask(void *pvParameters);
    
    /**
     * @brief Variable to store the distance measured (in meters)
     */
    static double distance;
 
private:
    /**
     * @brief Universal pointer to Serial (works for both Hardware and Software)
     */
    static Stream *serial;
    
#ifndef NRA15_USE_HARDWARE_SERIAL
    /**
     * @brief Pointer to SoftwareSerial object (only when using SoftwareSerial)
     */
    static SoftwareSerial *softSerial;
#endif
};
 
#endif // NRA15_H