Skip to content

Commit

Permalink
0.7.51
Browse files Browse the repository at this point in the history
* fix CMT configureable pins #1150
* fix default CMT pins for opendtufusion
* beautified `system`
* changed main loops, fix resets #1125, #1135
  • Loading branch information
lumapu committed Sep 15, 2023
1 parent b06f8e9 commit 9521cf7
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 84 deletions.
6 changes: 6 additions & 0 deletions src/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Development Changes

## 0.7.51 - 2023-09-16
* fix CMT configureable pins #1150
* fix default CMT pins for opendtufusion
* beautified `system`
* changed main loops, fix resets #1125, #1135

## 0.7.50 - 2023-09-12
* moved MqTT info to `system`
* added CMT info for ESP32 devices
Expand Down
73 changes: 19 additions & 54 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@


//-----------------------------------------------------------------------------
app::app()
: ah::Scheduler {},
mInnerLoopCb {nullptr} {
}
app::app() : ah::Scheduler {} {}


//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -55,14 +52,6 @@ void app::setup() {
DSERIAL.flush();
#endif // ETHERNET

#if !defined(ETHERNET)
#if defined(AP_ONLY)
mInnerLoopCb = std::bind(&app::loopStandard, this);
#else
mInnerLoopCb = std::bind(&app::loopWifi, this);
#endif
#endif /* !defined(ETHERNET) */

#if !defined(ETHERNET)
mWifi.setup(mConfig, &mTimestamp, std::bind(&app::onNetwork, this, std::placeholders::_1));
#if !defined(AP_ONLY)
Expand Down Expand Up @@ -128,14 +117,6 @@ void app::setup() {

//-----------------------------------------------------------------------------
void app::loop(void) {
if (mInnerLoopCb)
mInnerLoopCb();
#if !defined(ETHERNET)
#endif
}

//-----------------------------------------------------------------------------
void app::loopStandard(void) {
ah::Scheduler::loop();

if (mNrfRadio.loop() && mConfig->nrf.enabled) {
Expand Down Expand Up @@ -198,47 +179,29 @@ void app::loopStandard(void) {
mHmsPayload.loop();
#endif

if (mMqttEnabled)
if (mMqttEnabled && mNetworkConnected)
mMqtt.loop();
}

#if !defined(ETHERNET)
//-----------------------------------------------------------------------------
void app::loopWifi(void) {
ah::Scheduler::loop();
yield();
}
#endif /* !defined(ETHERNET) */

//-----------------------------------------------------------------------------
void app::onNetwork(bool gotIp) {
DPRINTLN(DBG_DEBUG, F("onNetwork"));
ah::Scheduler::resetTicker();
regularTickers(); // reinstall regular tickers
if (gotIp) {
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");
#if !defined(ETHERNET)
if (WIFI_AP == WiFi.getMode()) {
mMqttEnabled = false;
}
everySec(std::bind(&ahoywifi::tickWifiLoop, &mWifi), "wifiL");
#endif /* !defined(ETHERNET) */
mInnerLoopCb = [this]() { this->loopStandard(); };
} else {
#if defined(ETHERNET)
mInnerLoopCb = nullptr;
#else /* defined(ETHERNET) */
mInnerLoopCb = [this]() { this->loopWifi(); };
everySec(std::bind(&ahoywifi::tickWifiLoop, &mWifi), "wifiL");
#endif /* defined(ETHERNET) */
mNetworkConnected = gotIp;
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");
tickNtpUpdate();
#if !defined(ETHERNET)
if (WIFI_AP == WiFi.getMode()) {
mMqttEnabled = false;
}
everySec(std::bind(&ahoywifi::tickWifiLoop, &mWifi), "wifiL");
#endif /* !defined(ETHERNET) */
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -560,6 +523,8 @@ void app::resetSystem(void) {
mSavePending = false;
mSaveReboot = false;

mNetworkConnected = false;

memset(&mStat, 0, sizeof(statistics_t));
}

Expand Down
9 changes: 2 additions & 7 deletions src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ class app : public IApp, public ah::Scheduler {
void setup(void);
void loop(void);
void loopStandard(void);
#if !defined(ETHERNET)
void loopWifi(void);
#endif /* !defined(ETHERNET) */
void onNetwork(bool gotIp);
void regularTickers(void);

Expand Down Expand Up @@ -272,8 +269,6 @@ class app : public IApp, public ah::Scheduler {
#define CHECK_AVAIL true
#define SKIP_YIELD_DAY true

typedef std::function<void()> innerLoopCb;

void resetSystem(void);
void zeroIvValues(bool checkAvail = false, bool skipYieldDay = true);

Expand Down Expand Up @@ -325,8 +320,6 @@ class app : public IApp, public ah::Scheduler {
void tickZeroValues(void);
void tickMidnight(void);

innerLoopCb mInnerLoopCb;

HmSystemType mSys;
HmRadio<> mNrfRadio;

Expand Down Expand Up @@ -360,6 +353,8 @@ class app : public IApp, public ah::Scheduler {
uint8_t mSendLastIvId;
bool mSendFirst;

bool mNetworkConnected;

statistics_t mStat;

// mqtt
Expand Down
2 changes: 1 addition & 1 deletion src/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//-------------------------------------
#define VERSION_MAJOR 0
#define VERSION_MINOR 7
#define VERSION_PATCH 50
#define VERSION_PATCH 51

//-------------------------------------
typedef struct {
Expand Down
4 changes: 3 additions & 1 deletion src/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,12 @@ build_flags = ${env.build_flags}
-DDEF_CMT_CSB=4
-DDEF_CMT_FCSB=21
-DDEF_CMT_IRQ=8
-DDEF_CMT_SDIO=5
-DDEF_CMT_SCLK=6
-DDEF_LED0=18
-DDEF_LED1=17
-DLED_ACTIVE_HIGH
-DARDUINO_USB_MODE=1
;-DARDUINO_USB_CDC_ON_BOOT=1
-DARDUINO_USB_CDC_ON_BOOT=1
monitor_filters =
esp32_exception_decoder, colorize
6 changes: 3 additions & 3 deletions src/web/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ <h3>Support this project:</h3>
}
}

function parseIv(obj) {
function parseIv(obj, ts) {
var p = div(["none"]);
for(var i of obj) {
var icon = iconSuccess;
Expand All @@ -125,7 +125,7 @@ <h3>Support this project:</h3>
icon = iconWarn;
cl = "icon-warn";
avail = "disabled";
} else if(false == i["is_avail"]) {
} else if((false == i["is_avail"]) || (0 == ts)) {
icon = iconInfo;
cl = "icon-info";
avail = "not yet available";
Expand Down Expand Up @@ -192,7 +192,7 @@ <h3>Support this project:</h3>
parseNav(obj["generic"]);
parseGeneric(obj["generic"]);
parseSys(obj);
parseIv(obj["inverter"]);
parseIv(obj["inverter"], obj.ts_now);
parseWarn(obj["warnings"]);
if(exeOnce) {
window.setInterval("tick()", 1000);
Expand Down
2 changes: 1 addition & 1 deletion src/web/html/setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@
ml("div", {class: "row mb-3"}, [
ml("div", {class: "col-12 col-sm-3 my-2"}, p[0].toUpperCase()),
ml("div", {class: "col-12 col-sm-9"},
sel(p[1], ("ESP32-S3" == system["chip_model"]) ? esp32s3pins : esp32pins, obj[p[0]])
sel(p[1], (("ESP32-S3" == system["chip_model"]) ? esp32s3pins : esp32pins), obj[p[0]])
)
])
);
Expand Down
26 changes: 10 additions & 16 deletions src/web/html/system.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,24 @@
parseRssi(obj);
}

function genTabRow(key, value) {
var r = div(["row", "p-1"]);
r.appendChild(div(["col"], key));
r.appendChild(div(["col"], value));
return r;
}

function parseSysInfo(obj) {
const data = ["sdk", "cpu_freq", "chip_revision",
"chip_model", "chip_cores", "esp_type", "mac", "wifi_rssi", "ts_uptime",
"flash_size", "sketch_used", "heap_total", "heap_free", "heap_frag",
"max_free_blk", "version", "core_version", "reboot_reason"];

var main = document.getElementById("info");
var h = div(["head", "p-2"]);
var r = div(["row"]);
r.appendChild(div(["col", "a-c"], "System Information"));
h.appendChild(r);
main.appendChild(h);

lines = [];
for (const [key, value] of Object.entries(obj)) {
if(!data.includes(key) || (typeof value == 'undefined')) continue;
main.appendChild(genTabRow(key, value));
lines.push(tr(key.replace('_', ' '), value));
}

document.getElementById("info").append(
headline("System Information"),
ml("table", {class: "table"},
ml("tbody", {}, lines)
)
);
}

function badge(success, text, second="error") {
Expand All @@ -58,7 +52,7 @@
if(typeof val2 == "number")
val2 = String(val2);
return ml("tr", {}, [
ml("th", {}, val1),
ml("th", {style: "width: 50%"}, val1),
ml("td", {}, val2)
]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/web/web.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ class Web {

// pinout
uint8_t pin;
for (uint8_t i = 0; i < 12; i++) {
for (uint8_t i = 0; i < 14; i++) {
pin = request->arg(String(pinArgNames[i])).toInt();
switch(i) {
case 0: mConfig->nrf.pinCs = ((pin != 0xff) ? pin : DEF_NRF_CS_PIN); break;
Expand Down

0 comments on commit 9521cf7

Please sign in to comment.