编译通过,是否支持电源管理,由各个设备负责
This commit is contained in:
parent
6bdc22cb90
commit
ae229272df
|
@ -266,7 +266,7 @@ void NRF24L01::Init(Spi* spi, Pin ce, Pin irq, Pin power)
|
||||||
|
|
||||||
// 初始化前必须先关闭电源。因为系统可能是重启,而模块并没有重启,还保留着上一次的参数
|
// 初始化前必须先关闭电源。因为系统可能是重启,而模块并没有重启,还保留着上一次的参数
|
||||||
//!!! 重大突破!当前版本程序,烧写后无法触发IRQ中断,但是重新上电以后可以中断,而Reset也不能触发。并且发现,只要模块带电,寄存器参数不会改变。
|
//!!! 重大突破!当前版本程序,烧写后无法触发IRQ中断,但是重新上电以后可以中断,而Reset也不能触发。并且发现,只要模块带电,寄存器参数不会改变。
|
||||||
SetPower(false);*/
|
SetPowerMode(false);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
NRF24L01::~NRF24L01()
|
NRF24L01::~NRF24L01()
|
||||||
|
@ -279,7 +279,7 @@ NRF24L01::~NRF24L01()
|
||||||
Register(NULL);
|
Register(NULL);
|
||||||
|
|
||||||
// 关闭电源
|
// 关闭电源
|
||||||
SetPower(false);
|
SetPowerMode(false);
|
||||||
|
|
||||||
delete _spi;
|
delete _spi;
|
||||||
_spi = NULL;
|
_spi = NULL;
|
||||||
|
@ -439,7 +439,7 @@ bool NRF24L01::Config()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//ShowStatus();
|
//ShowStatus();
|
||||||
SetPower(false);
|
SetPowerMode(false);
|
||||||
_CE = false;
|
_CE = false;
|
||||||
|
|
||||||
SetAddress(true);
|
SetAddress(true);
|
||||||
|
@ -497,7 +497,7 @@ bool NRF24L01::Config()
|
||||||
// 清除中断标志
|
// 清除中断标志
|
||||||
ClearStatus(true, true);
|
ClearStatus(true, true);
|
||||||
|
|
||||||
if(!SetPower(true)) return false;
|
if(!SetPowerMode(true)) return false;
|
||||||
|
|
||||||
_CE = true;
|
_CE = true;
|
||||||
|
|
||||||
|
@ -558,7 +558,7 @@ bool NRF24L01::GetPower()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取/设置当前电源状态
|
// 获取/设置当前电源状态
|
||||||
bool NRF24L01::SetPower(bool on)
|
bool NRF24L01::SetPowerMode(bool on)
|
||||||
{
|
{
|
||||||
byte mode = ReadReg(CONFIG);
|
byte mode = ReadReg(CONFIG);
|
||||||
RF_CONFIG config;
|
RF_CONFIG config;
|
||||||
|
@ -566,7 +566,7 @@ bool NRF24L01::SetPower(bool on)
|
||||||
|
|
||||||
if(!(on ^ config.PWR_UP)) return true;
|
if(!(on ^ config.PWR_UP)) return true;
|
||||||
|
|
||||||
debug_printf("NRF24L01::SetPower %s电源\r\n", on ? "打开" : "关闭");
|
debug_printf("NRF24L01::SetPowerMode %s电源\r\n", on ? "打开" : "关闭");
|
||||||
|
|
||||||
config.PWR_UP = on ? 1 : 0;
|
config.PWR_UP = on ? 1 : 0;
|
||||||
|
|
||||||
|
@ -584,7 +584,7 @@ bool NRF24L01::SetPower(bool on)
|
||||||
config.Init(ReadReg(CONFIG));
|
config.Init(ReadReg(CONFIG));
|
||||||
if(!config.PWR_UP)
|
if(!config.PWR_UP)
|
||||||
{
|
{
|
||||||
debug_printf("NRF24L01::SetPower 无法打开电源!\r\n");
|
debug_printf("NRF24L01::SetPowerMode 无法打开电源!\r\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -592,6 +592,20 @@ bool NRF24L01::SetPower(bool on)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NRF24L01::ChangePower(int level)
|
||||||
|
{
|
||||||
|
if(level == 1)
|
||||||
|
{
|
||||||
|
// 芯片内部关闭电源
|
||||||
|
SetPowerMode(false);
|
||||||
|
}
|
||||||
|
else if(level > 1)
|
||||||
|
{
|
||||||
|
// 整个模块断电
|
||||||
|
Power = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 获取当前模式是否接收模式
|
// 获取当前模式是否接收模式
|
||||||
bool NRF24L01::GetMode()
|
bool NRF24L01::GetMode()
|
||||||
{
|
{
|
||||||
|
@ -812,7 +826,7 @@ void NRF24L01::OnClose()
|
||||||
{
|
{
|
||||||
if(_tidRecv) Sys.SetTask(_tidRecv, false);
|
if(_tidRecv) Sys.SetTask(_tidRecv, false);
|
||||||
|
|
||||||
SetPower(false);
|
SetPowerMode(false);
|
||||||
|
|
||||||
_spi->Close();
|
_spi->Close();
|
||||||
_CE.Close();
|
_CE.Close();
|
||||||
|
|
|
@ -74,8 +74,6 @@ void ShunCom::ChangePower(int level)
|
||||||
Power = false;
|
Power = false;
|
||||||
Sleep = false;
|
Sleep = false;
|
||||||
Config = false;
|
Config = false;
|
||||||
|
|
||||||
PackPort::ChangePower(level);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShunCom::OnWrite(const ByteArray& bs)
|
bool ShunCom::OnWrite(const ByteArray& bs)
|
||||||
|
|
|
@ -3,12 +3,13 @@
|
||||||
|
|
||||||
#include "Sys.h"
|
#include "Sys.h"
|
||||||
#include "Port.h"
|
#include "Port.h"
|
||||||
|
#include "Power.h"
|
||||||
#include "Net\ITransport.h"
|
#include "Net\ITransport.h"
|
||||||
#include "Message\DataStore.h"
|
#include "Message\DataStore.h"
|
||||||
|
|
||||||
// 上海顺舟Zigbee协议
|
// 上海顺舟Zigbee协议
|
||||||
// 主站发送所有从站收到,从站发送只有主站收到
|
// 主站发送所有从站收到,从站发送只有主站收到
|
||||||
class ShunCom : public PackPort
|
class ShunCom : public PackPort, public Power
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -6,10 +6,11 @@
|
||||||
#include "Net\ITransport.h"
|
#include "Net\ITransport.h"
|
||||||
#include "Timer.h"
|
#include "Timer.h"
|
||||||
#include "Thread.h"
|
#include "Thread.h"
|
||||||
|
#include "Power.h"
|
||||||
#include "Message\DataStore.h"
|
#include "Message\DataStore.h"
|
||||||
|
|
||||||
// NRF24L01类
|
// NRF24L01类
|
||||||
class NRF24L01 : public ITransport
|
class NRF24L01 : public ITransport, public Power
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
byte WriteBuf(byte reg, const byte *pBuf, byte bytes);
|
byte WriteBuf(byte reg, const byte *pBuf, byte bytes);
|
||||||
|
@ -58,7 +59,7 @@ public:
|
||||||
bool Check();
|
bool Check();
|
||||||
bool Config(); // 完成基础参数设定,默认初始化为发送模式
|
bool Config(); // 完成基础参数设定,默认初始化为发送模式
|
||||||
bool GetPower(); // 获取当前电源状态
|
bool GetPower(); // 获取当前电源状态
|
||||||
bool SetPower(bool on); // 设置当前电源状态。返回是否成功
|
bool SetPowerMode(bool on); // 设置当前电源状态。返回是否成功
|
||||||
bool GetMode(); // 获取当前模式是否接收模式
|
bool GetMode(); // 获取当前模式是否接收模式
|
||||||
bool SetMode(bool isReceive); // 切换收发模式,不包含参数设定
|
bool SetMode(bool isReceive); // 切换收发模式,不包含参数设定
|
||||||
void SetAddress(bool full); // 设置地址。参数指定是否设置0通道地址以外的完整地址
|
void SetAddress(bool full); // 设置地址。参数指定是否设置0通道地址以外的完整地址
|
||||||
|
@ -66,6 +67,9 @@ public:
|
||||||
void ClearFIFO(bool rx);
|
void ClearFIFO(bool rx);
|
||||||
void ClearStatus(bool tx, bool rx);
|
void ClearStatus(bool tx, bool rx);
|
||||||
|
|
||||||
|
// 电源等级变更(如进入低功耗模式)时调用
|
||||||
|
virtual void ChangePower(int level);
|
||||||
|
|
||||||
IDataPort* Led; // 数据灯
|
IDataPort* Led; // 数据灯
|
||||||
|
|
||||||
byte Status;
|
byte Status;
|
||||||
|
|
|
@ -35,13 +35,6 @@ bool ITransport::Open()
|
||||||
Opened = OnOpen();
|
Opened = OnOpen();
|
||||||
Opening = false;
|
Opening = false;
|
||||||
|
|
||||||
/*// 设置电源管理
|
|
||||||
if(Opened)
|
|
||||||
{
|
|
||||||
Power* pwr = dynamic_cast<Power*>(this);
|
|
||||||
if(pwr) pwr->SetPower();
|
|
||||||
}*/
|
|
||||||
|
|
||||||
return Opened;
|
return Opened;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,9 +129,3 @@ uint PackPort::OnPortReceive(ITransport* sender, ByteArray& bs, void* param, voi
|
||||||
PackPort* pp = dynamic_cast<PackPort*>((PackPort*)param);
|
PackPort* pp = dynamic_cast<PackPort*>((PackPort*)param);
|
||||||
return pp->OnReceive(bs, param2);
|
return pp->OnReceive(bs, param2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PackPort::ChangePower(int level)
|
|
||||||
{
|
|
||||||
Power* pwr = dynamic_cast<Power*>(Port);
|
|
||||||
if(pwr) pwr->ChangePower(level);
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#define __ITransport_H__
|
#define __ITransport_H__
|
||||||
|
|
||||||
#include "Sys.h"
|
#include "Sys.h"
|
||||||
#include "Power.h"
|
|
||||||
|
|
||||||
class ITransport;
|
class ITransport;
|
||||||
|
|
||||||
|
@ -74,9 +73,6 @@ public:
|
||||||
|
|
||||||
virtual void Set(ITransport* port);
|
virtual void Set(ITransport* port);
|
||||||
|
|
||||||
// 电源等级变更(如进入低功耗模式)时调用
|
|
||||||
virtual void ChangePower(int level);
|
|
||||||
|
|
||||||
virtual string ToString() { return "PackPort"; }
|
virtual string ToString() { return "PackPort"; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#define SERIAL_BAUDRATE 1024000
|
#define SERIAL_BAUDRATE 1024000
|
||||||
|
|
||||||
// 串口类
|
// 串口类
|
||||||
class SerialPort : public ITransport
|
class SerialPort : public ITransport, public Power
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
byte _index;
|
byte _index;
|
||||||
|
|
|
@ -85,7 +85,9 @@ ITransport* CreateShunCom(COM_Def index, int baudRate, Pin rst, Pin power, Pin s
|
||||||
|
|
||||||
zb->Sleep.Init(slp, true);
|
zb->Sleep.Init(slp, true);
|
||||||
zb->Config.Init(cfg, true);
|
zb->Config.Init(cfg, true);
|
||||||
zb->Init(&sp, rst);
|
zb->Init(sp, rst);
|
||||||
|
|
||||||
|
sp->SetPower();
|
||||||
zb->SetPower();
|
zb->SetPower();
|
||||||
|
|
||||||
/*zb.Register(OnZig, &zb);
|
/*zb.Register(OnZig, &zb);
|
||||||
|
|
Loading…
Reference in New Issue