代码整理,减少头文件引用
This commit is contained in:
parent
15d31acf61
commit
acf1971e1d
|
@ -1,6 +1,8 @@
|
|||
#include "ByteArray.h"
|
||||
#include "BH1750.h"
|
||||
|
||||
#include "I2C.h"
|
||||
|
||||
#define CMD_PWN_OFF 0x00
|
||||
#define CMD_PWN_ON 0x01
|
||||
#define CMD_RESET 0x07
|
||||
|
@ -17,7 +19,7 @@
|
|||
BH1750::BH1750()
|
||||
{
|
||||
IIC = nullptr;
|
||||
|
||||
|
||||
// 7位地址,到了I2C那里,需要左移1位
|
||||
Address = 0x5C;
|
||||
//Address = 0x23;
|
||||
|
@ -26,7 +28,7 @@ BH1750::BH1750()
|
|||
BH1750::~BH1750()
|
||||
{
|
||||
delete IIC;
|
||||
IIC = nullptr;
|
||||
IIC = nullptr;
|
||||
}
|
||||
|
||||
void BH1750::Init()
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
#ifndef _BH1750_H_
|
||||
#define _BH1750_H_
|
||||
|
||||
#include "I2C.h"
|
||||
#include "Power.h"
|
||||
#include "Device\Power.h"
|
||||
|
||||
class I2C;
|
||||
|
||||
// 光强传感器
|
||||
class BH1750 : public Power
|
||||
{
|
||||
public:
|
||||
I2C* IIC; // I2C通信口
|
||||
byte Address; // 设备地址
|
||||
I2C* IIC; // I2C通信口
|
||||
byte Address; // 设备地址
|
||||
|
||||
BH1750();
|
||||
virtual ~BH1750();
|
||||
|
|
|
@ -1,31 +1,42 @@
|
|||
#include "JTW8953.h"
|
||||
#include "Sys.h"
|
||||
#include "JTW8953.h"
|
||||
|
||||
#define ADDRESS_W 0xa6 //从机的地址和写入标志
|
||||
#define ADDRESS_R 0xa7 //从机的地址和读取标志
|
||||
#include "I2C.h"
|
||||
|
||||
#define ADDRESS_W 0xa6 // 从机的地址和写入标志
|
||||
#define ADDRESS_R 0xa7 // 从机的地址和读取标志
|
||||
|
||||
#define ADDRESS_C 0xB1 // MCU配置起始地址
|
||||
#define ADDRESS_T 0xC0 // 触摸键起始地址, 共有9个触摸键地址范围0xc0~0xD0
|
||||
|
||||
JTW8953::JTW8953()
|
||||
{
|
||||
IIC = nullptr;
|
||||
IIC = nullptr;
|
||||
Port = nullptr;
|
||||
// 7位地址
|
||||
Address = 0xa7;
|
||||
Address = 0x53;
|
||||
}
|
||||
|
||||
JTW8953::~JTW8953()
|
||||
{
|
||||
delete IIC;
|
||||
IIC = nullptr;
|
||||
IIC = nullptr;
|
||||
|
||||
delete Port;
|
||||
Port = nullptr;
|
||||
}
|
||||
|
||||
void JTW8953::Init()
|
||||
{
|
||||
debug_printf("\r\nJTW8953::Init Address=0x%02X \r\n", Address);
|
||||
|
||||
IIC->Address = Address;
|
||||
IIC->Address = Address << 1;
|
||||
}
|
||||
|
||||
void JTW8953::SetSlide(bool slide)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool JTW8953::SetConfig(const Buffer& bs) const
|
||||
{
|
||||
|
@ -88,10 +99,12 @@ bool JTW8953::Read(uint addr, Buffer& bs) const
|
|||
|
||||
void JTW8953::JTW8953Test()
|
||||
{
|
||||
auto iic = SoftI2C();
|
||||
SoftI2C iic;
|
||||
iic.SetPin(PB15, PA12);
|
||||
|
||||
auto jtw = JTW8953();
|
||||
InputPort port(PD13);
|
||||
|
||||
JTW8953 jtw;
|
||||
jtw.IIC = &iic;
|
||||
|
||||
// 读取数据缓存
|
||||
|
|
|
@ -1,20 +1,22 @@
|
|||
#ifndef _JTW8953_H_
|
||||
#define _JTW8953_H_
|
||||
|
||||
#include "I2C.h"
|
||||
#include "..\Storage\Storage.h"
|
||||
class I2C;
|
||||
class InputPort;
|
||||
|
||||
// EEPROM
|
||||
class JTW8953 : public CharStorage
|
||||
// 滑条按键触摸芯片
|
||||
class JTW8953
|
||||
{
|
||||
public:
|
||||
|
||||
JTW8953();
|
||||
virtual ~JTW8953();
|
||||
I2C* IIC; // I2C通信口
|
||||
InputPort* Port; // 中断引脚
|
||||
byte Address; // 设备地址
|
||||
|
||||
I2C* IIC; // I2C通信口
|
||||
JTW8953();
|
||||
~JTW8953();
|
||||
|
||||
void Init();
|
||||
void SetSlide(bool slide);
|
||||
// 写入键位数据
|
||||
bool WriteKey(ushort index, byte data);
|
||||
|
||||
|
@ -22,14 +24,13 @@ public:
|
|||
// 设置配置
|
||||
bool SetConfig(const Buffer& bs) const;
|
||||
|
||||
virtual bool Write(uint addr, const Buffer& bs) const;
|
||||
bool Write(uint addr, const Buffer& bs) const;
|
||||
|
||||
virtual bool Read(uint addr, Buffer& bs) const;
|
||||
bool Read(uint addr, Buffer& bs) const;
|
||||
|
||||
static void JTW8953Test();
|
||||
|
||||
private:
|
||||
byte Address; // 设备地址
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "SHT30.h"
|
||||
|
||||
#include "I2C.h"
|
||||
|
||||
#define LITTLE_ENDIAN
|
||||
|
||||
//-- Enumerations -------------------------------------------------------------
|
||||
|
@ -104,6 +106,8 @@ SHT30::SHT30()
|
|||
Address = 0x44; // ADDR=VSS
|
||||
//Address = 0x45; // ADDR=VDD
|
||||
|
||||
Pwr = nullptr;
|
||||
|
||||
Mode = 2;
|
||||
Freq = 5;
|
||||
Repeat = 2;
|
||||
|
@ -111,7 +115,7 @@ SHT30::SHT30()
|
|||
|
||||
SHT30::~SHT30()
|
||||
{
|
||||
Pwr = false;
|
||||
if(Pwr) *Pwr = false;
|
||||
|
||||
delete IIC;
|
||||
IIC = nullptr;
|
||||
|
@ -133,7 +137,7 @@ void SHT30::Init()
|
|||
debug_printf(" 内部定期采集 每秒%d次", Freq);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
debug_printf(" 重复性 ");
|
||||
switch (Repeat)
|
||||
{
|
||||
|
@ -154,7 +158,7 @@ void SHT30::Init()
|
|||
IIC->Address = Address << 1;
|
||||
IIC->Retry = 2;
|
||||
|
||||
Pwr = true;
|
||||
if(Pwr) *Pwr = true;
|
||||
|
||||
bool rs = CheckStatus();
|
||||
|
||||
|
@ -302,7 +306,7 @@ void SHT30::SetMode()
|
|||
// 软重启
|
||||
if(!rs) rs = Write(CMD_SOFT_RESET);
|
||||
// 硬重启
|
||||
if(!rs) Pwr.Down(100);
|
||||
if(!rs && Pwr) Pwr->Down(100);
|
||||
}
|
||||
|
||||
ushort SHT30::GetMode() const
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
#ifndef _SHT30_H_
|
||||
#define _SHT30_H_
|
||||
|
||||
#include "I2C.h"
|
||||
#include "Power.h"
|
||||
#include "Device\Power.h"
|
||||
|
||||
class OutputPort;
|
||||
class I2C;
|
||||
|
||||
// 光强传感器
|
||||
class SHT30 : public Power
|
||||
|
@ -14,7 +16,7 @@ public:
|
|||
byte Freq; // 频率,多少秒测量一次。05/1/2/4/10,05表示0.5s
|
||||
byte Repeat; // 重复性。0=高/1=中/2=低,多次测量相差不多,说明重复性高
|
||||
|
||||
OutputPort Pwr; // 电源
|
||||
OutputPort* Pwr; // 电源
|
||||
|
||||
SHT30();
|
||||
virtual ~SHT30();
|
||||
|
|
Loading…
Reference in New Issue