SmartOS/Drivers/SHT30.h

59 lines
1.4 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef _SHT30_H_
#define _SHT30_H_
#include "Device\Power.h"
class OutputPort;
class I2C;
// 光强传感器
class SHT30 : public Power
{
public:
I2C* IIC; // I2C通信口
byte Address; // 设备地址
byte Mode; // 模式。0=CLKSTRETCH/1=POLLING/2=Periodic
byte Freq; // 频率多少秒测量一次。05/1/2/4/1005表示0.5s
byte Repeat; // 重复性。0=高/1=中/2=低,多次测量相差不多,说明重复性高
OutputPort* Pwr; // 电源
bool Opened;
SHT30();
virtual ~SHT30();
bool Open();
uint ReadSerialNumber();
ushort ReadStatus();
bool Read(ushort& temp, ushort& humi);
// 电源等级变更(如进入低功耗模式)时调用
virtual void ChangePower(int level);
private:
bool Write(ushort cmd);
ushort Read2(ushort cmd);
// 同时读取温湿度并校验Crc
uint Read4(ushort cmd);
bool CheckStatus();
void SetMode();
ushort GetMode() const;
};
/*
开发历史
2015-10-03
SHT30三种采集数据方式
1Stretch阻塞模式发送命令后采集需要长时间等待SCL拉高才能发送读取头然后读取数据
2Polling非阻塞模式发送命令后采集需要反复多次启动并发送读取头得到ACK以后才能读取数据
3内部定期采集模式启动时发送Periodic命令读取时发送FetchData命令后直接读取数据
感谢kazuyuki@407605899
*/
#endif