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
#ifndef GRF500_H
#define GRF500_H
 
#include <Wire.h>
#include <Arduino.h>
 
#define SDA_PIN (16)  /**< I2C data line pin */
#define SCL_PIN (17)  /**< I2C clock line pin */
 
#define RANGEFINDER_GRF500_MAX_DISTANCE (50000)
 
/**
 * @brief The GRF500 class handles interaction with the GRF500 altimeter sensor.
 *
 * Provides initialization of I2C, register-mode activation and
 * periodic distance measurement in a FreeRTOS task.
 */
class GRF500
{
public:
    /**
     * @brief Construct a new GRF500 instance
     * @param addr I2C address (default 0x66)
     */
    explicit GRF500(uint8_t addr = 0x66);
    ~GRF500() = default;
 
    /**
     * @brief FreeRTOS task entry point (static)
     * @param pvParameters Pointer to TaskCreator instance
     */
    static void Task(void *pvParameters);
 
    /**
     * @brief Initialize device: start I2C, scan and enable register-mode
     * @return true on success, false otherwise
     */
    bool begin();
 
    /**
     * @brief Read and log measurements when available
     */
    void update();
 
    /**
     * @brief Last measured distance (meters)
     */
    static double distance;
 
private:
    static uint8_t address;          /**< I2C address stored globally */
    bool registerModeActivated{false};
    uint32_t lastReadMs{0};          /**< Timestamp of last read */
 
    bool scan(uint8_t addr);
    void enableRegisterMode();
    bool checkRegisterMode();
    void readDistance();
    void readMeasurements();
};
 
#endif // GRF500_H