forked from DFRobot/DFRobot_OzoneSensor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DFRobot_OzoneSensor.h
79 lines (73 loc) · 2.95 KB
/
DFRobot_OzoneSensor.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
/*!
* @file DFRobot_OzoneSensor.h
* @brief Define the basic structure of the DFRobot_OzoneSensor class, the implementation of the basic methods
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @license The MIT License (MIT)
* @author [ZhixinLiu]([email protected])
* @version V1.0
* @date 2019-10-10
* @url https://github.com/DFRobot/DFRobot_OzoneSensor
*/
#ifndef __DFRobot_OzoneSensor_H__
#define __DFRobot_OzoneSensor_H__
#include <Arduino.h>
#include <Wire.h>
#define OZONE_ADDRESS_0 0x70
#define OZONE_ADDRESS_1 0x71
#define OZONE_ADDRESS_2 0x72
#define OZONE_ADDRESS_3 0x73
#define MEASURE_MODE_AUTOMATIC 0x00 ///< active mode
#define MEASURE_MODE_PASSIVE 0x01 ///< passive mode
#define AUTO_READ_DATA 0x00 ///< auto read ozone data
#define PASSIVE_READ_DATA 0x01 ///< passive read ozone data
#define MODE_REGISTER 0x03 ///< mode register
#define SET_PASSIVE_REGISTER 0x04 ///< read ozone data register
#define AUTO_DATA_HIGE_REGISTER 0x09 ///< AUTO data high eight bits
#define AUTO_DATA_LOW_REGISTER 0x0A ///< AUTO data Low eight bits
#define PASS_DATA_HIGE_REGISTER 0x07 ///< AUTO data high eight bits
#define PASS_DATA_LOW_REGISTER 0x08 ///< AUTO data Low eight bits
#define OCOUNT 100 ///< Ozone Count Value
class DFRobot_OzoneSensor{
public:
DFRobot_OzoneSensor(TwoWire & wire = Wire);
~DFRobot_OzoneSensor();
/**
* @fn begin
* @brief initialization function
* @param i2c address
* @n OZONE_ADDRESS_0 0x70
* @n OZONE_ADDRESS_1 0x71
* @n OZONE_ADDRESS_2 0x72
* @n OZONE_ADDRESS_3 0x73
* @return bool type
* @retval true initialization success
* @retval false initialization failed
*/
bool begin(uint8_t addr = OZONE_ADDRESS_0);
/**
* @fn setModes
* @brief Set mode Active or passive measurement.
* @param mode mode is Active or passive.
* @n MEASURE_MODE_AUTOMATIC active mode
* @n MEASURE_MODE_PASSIVE passive mode
* @return None
*/
void setModes(uint8_t mode);
/**
* @fn readOzoneData
* @brief read ozone data.
* @param collectNum is the number of data collected,(The default value is 20)
* @n COLLECT_NUMBER The collection range is 1-100
* @return ozone concentration: one part per billion (PPB).
*/
int16_t readOzoneData(uint8_t collectNum = 20);
private:
void i2cWrite(uint8_t reg , uint8_t pData);
int16_t i2cReadOzoneData(uint8_t reg);
int ozoneData[OCOUNT] = {0x00};
int getAverageNum(int bArray[], int iFilterLen);
TwoWire & _wire;
uint8_t _addr; ///< IIC Slave number
uint8_t _M_Flag = 0; ///< mode flag
};
#endif