-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDFRobot_FS3000.h
92 lines (76 loc) · 2.2 KB
/
DFRobot_FS3000.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* @file DFRobot_FS3000.h
* @brief This is the constructor for the air velocity module driver library.
* @copyright Copyright (c) 2024 DFRobot Co.Ltd (http://www.dfrobot.com)
* @license The MIT License (MIT)
* @author [TangJie](jie.tang@dfrobot.com)
* @version V1.0
* @date 2024-12-02
* @url https://github.com/DFRobot/DFRobot_FS3000
*/
#ifndef _DFROBOT_FS3000_
#define _DFROBOT_FS3000_
#include "Arduino.h"
#include "Wire.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#define AIRFLOW_RANGE_7_MPS 0x09
#define AIRFLOW_RANGE_15_MPS 0x0D
//#define ENABLE_DBG ///< Enable this macro to view the detailed execution process of the program.
#ifdef ENABLE_DBG
#define DBG(...) {Serial.print("[");Serial.print(__FUNCTION__); Serial.print("(): "); Serial.print(__LINE__); Serial.print(" ] "); Serial.println(__VA_ARGS__);}
#else
#define DBG(...)
#endif
class DFRobot_FS3000
{
public:
/**
* @fn DFRobot_FS3000
* @brief Constructor for the FS3000 sensor.
* @param pWire I2C bus object.
* @return NULL
*/
DFRobot_FS3000(TwoWire *pWire=&Wire);
/**
* @fn ~DFRobot_FS3000
* @brief Destructor for the FS3000 sensor.
*/
~DFRobot_FS3000(void){
_pWire->end();
};
/**
* @fn setRange
* @brief Set the airflow detection range.
* @param range AIRFLOW_RANGE_7_MPS: FS3000_1005, AIRFLOW_RANGE_15MPS: FS3000_1015
* @return 1: Setting successful, 0: Setting failed.
*/
uint8_t setRange(uint8_t range);
/**
* @fn readRaw
* @brief Get the raw data from the sensor.
* @return Raw data from the FS3000 register.
*/
uint16_t readRaw(void);
/**
* @fn readMeterPerSec
* @brief Get the airflow velocity in meters per second (m/s).
* @return Airflow velocity data.
*/
float readMeterPerSec(void);
/**
* @fn readMilePerHour
* @brief Get the airflow velocity in miles per hour (mph).
* @return Airflow velocity data.
*/
float readMilePerHour(void);
private:
TwoWire *_pWire;
uint8_t readData(void* buf, uint8_t len);
bool checkSum(void* buf);
float _mpsDataPoint[13];
int _rawDataPoint[13];
uint8_t _addr = 0x28;
};
#endif