mirror of
https://github.com/lumapu/ahoy.git
synced 2025-06-15 00:51:38 +02:00
added CmtRadio to app
This commit is contained in:
parent
6cbd256c1f
commit
5525d25e4b
3 changed files with 37 additions and 8 deletions
28
src/app.cpp
28
src/app.cpp
|
@ -40,6 +40,12 @@ void app::setup() {
|
|||
mNrfRadio.setup(mConfig->nrf.amplifierPower, mConfig->nrf.pinIrq, mConfig->nrf.pinCe, mConfig->nrf.pinCs);
|
||||
mNrfRadio.enableDebug();
|
||||
}
|
||||
#if defined(ESP32)
|
||||
if(mConfig->cmt.enabled) {
|
||||
mCmtRadio.setup();
|
||||
mCmtRadio.enableDebug();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(AP_ONLY)
|
||||
mInnerLoopCb = std::bind(&app::loopStandard, this);
|
||||
|
@ -67,7 +73,7 @@ void app::setup() {
|
|||
DBGPRINTLN(String(ESP.getHeapFragmentation()));
|
||||
DBGPRINTLN(String(ESP.getMaxFreeBlockSize()));*/
|
||||
|
||||
if(!mNrfRadio.isChipConnected())
|
||||
if(!mNrfRadio.isChipConnected() && mConfig->nrf.enabled)
|
||||
DPRINTLN(DBG_WARN, F("WARNING! your NRF24 module can't be reached, check the wiring"));
|
||||
|
||||
// when WiFi is in client mode, then enable mqtt broker
|
||||
|
@ -137,6 +143,22 @@ void app::loopStandard(void) {
|
|||
mPayload.process(true);
|
||||
mMiPayload.process(true);
|
||||
}
|
||||
#if defined(ESP32)
|
||||
if (mCmtRadio.loop()) {
|
||||
while (!mCmtRadio.mBufCtrl.empty()) {
|
||||
hmsPacket_t *p = &mCmtRadio.mBufCtrl.front();
|
||||
if (mConfig->serial.debug) {
|
||||
DPRINT(DBG_INFO, F("RX "));
|
||||
DBGPRINT(String(p->data[0]));
|
||||
DBGPRINT(F("RSSI "));
|
||||
DBGPRINT(String(p->rssi));
|
||||
DBGPRINT(F("dBm | "));
|
||||
ah::dumpBuf(&p->data[1], p->data[0]);
|
||||
}
|
||||
mCmtRadio.mBufCtrl.pop();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
mPayload.loop();
|
||||
mMiPayload.loop();
|
||||
|
||||
|
@ -158,6 +180,10 @@ void app::onWifi(bool gotIp) {
|
|||
if (gotIp) {
|
||||
mInnerLoopCb = std::bind(&app::loopStandard, this);
|
||||
every(std::bind(&app::tickSend, this), mConfig->nrf.sendInterval, "tSend");
|
||||
#if defined(ESP32)
|
||||
if(mConfig->cmt.enabled)
|
||||
everySec(std::bind(&CmtRadioType::tickSecond, mCmtRadio), "tsCmt");
|
||||
#endif
|
||||
mMqttReconnect = true;
|
||||
mSunrise = 0; // needs to be set to 0, to reinstall sunrise and ivComm tickers!
|
||||
once(std::bind(&app::tickNtpUpdate, this), 2, "ntp2");
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#define ASIN(x) (degrees(asin(x)))
|
||||
#define ACOS(x) (degrees(acos(x)))
|
||||
|
||||
typedef CmtRadio<esp32_3wSpi<>> CmtRadioType;
|
||||
typedef HmSystem<MAX_NUM_INVERTERS> HmSystemType;
|
||||
typedef HmPayload<HmSystemType, HmRadio<>> PayloadType;
|
||||
typedef MiPayload<HmSystemType, HmRadio<>> MiPayloadType;
|
||||
|
@ -67,7 +68,7 @@ class app : public IApp, public ah::Scheduler {
|
|||
}
|
||||
|
||||
void handleHmsIntr(void) {
|
||||
//mSys.Radio.handleHmsIntr();
|
||||
mCmtRadio.handleIntr();
|
||||
}
|
||||
|
||||
uint32_t getUptime() {
|
||||
|
@ -213,6 +214,7 @@ class app : public IApp, public ah::Scheduler {
|
|||
|
||||
HmSystemType mSys;
|
||||
HmRadio<> mNrfRadio;
|
||||
CmtRadioType mCmtRadio;
|
||||
|
||||
private:
|
||||
typedef std::function<void()> innerLoopCb;
|
||||
|
|
|
@ -20,18 +20,18 @@ typedef struct {
|
|||
#define U32_B0(val) ((uint8_t)((val ) & 0xff))
|
||||
|
||||
template<class SPI, uint32_t DTU_SN = 0x87654321>
|
||||
class HmsRadio {
|
||||
class CmtRadio {
|
||||
typedef SPI SpiType;
|
||||
typedef Cmt2300a<SpiType> CmtType;
|
||||
public:
|
||||
HmsRadio() {
|
||||
CmtRadio() {
|
||||
mDtuSn = DTU_SN;
|
||||
}
|
||||
|
||||
void setup(bool genDtuSn = true) {
|
||||
if(genDtuSn)
|
||||
generateDtuSn();
|
||||
if(!mCmt.resetCMT())
|
||||
if(!mCmt.reset())
|
||||
DPRINTLN(DBG_WARN, F("Initializing CMT2300A failed!"));
|
||||
else
|
||||
mCmt.goRx();
|
||||
|
@ -43,13 +43,14 @@ class HmsRadio {
|
|||
mIrqRcvd = false;
|
||||
}
|
||||
|
||||
void loop() {
|
||||
bool loop() {
|
||||
mCmt.loop();
|
||||
if(!mIrqRcvd)
|
||||
return;
|
||||
return false;
|
||||
mIrqRcvd = false;
|
||||
getRx();
|
||||
mCmt.goRx();
|
||||
return true;
|
||||
}
|
||||
|
||||
void tickSecond() {
|
||||
|
@ -57,7 +58,7 @@ class HmsRadio {
|
|||
prepareSwitchChannelCmd(mIvIdChannelSet);
|
||||
}
|
||||
|
||||
void handeIntr(void) {
|
||||
void handleIntr(void) {
|
||||
mIrqRcvd = true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue