mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-24 14:26:11 +02:00
added ePaper (for ESP32 only!), thx @dAjaY85 #735
improved `/live` margins #732 renamed `var` to `VAr` #732
This commit is contained in:
parent
501daf04bc
commit
6dbb88e27e
19 changed files with 2685 additions and 3009 deletions
38
src/app.cpp
38
src/app.cpp
|
@ -4,14 +4,13 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "app.h"
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#include "utils/sun.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
app::app() : ah::Scheduler() {}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::setup() {
|
||||
Serial.begin(115200);
|
||||
|
@ -33,16 +32,16 @@ void app::setup() {
|
|||
mSys.enableDebug();
|
||||
mSys.setup(mConfig->nrf.amplifierPower, mConfig->nrf.pinIrq, mConfig->nrf.pinCe, mConfig->nrf.pinCs);
|
||||
|
||||
#if defined(AP_ONLY)
|
||||
#if defined(AP_ONLY)
|
||||
mInnerLoopCb = std::bind(&app::loopStandard, this);
|
||||
#else
|
||||
#else
|
||||
mInnerLoopCb = std::bind(&app::loopWifi, this);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
mWifi.setup(mConfig, &mTimestamp, std::bind(&app::onWifi, this, std::placeholders::_1));
|
||||
#if !defined(AP_ONLY)
|
||||
#if !defined(AP_ONLY)
|
||||
everySec(std::bind(&ahoywifi::tickWifiLoop, &mWifi), "wifiL");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
mSys.addInverters(&mConfig->inst);
|
||||
|
||||
|
@ -61,15 +60,15 @@ void app::setup() {
|
|||
if (!mSys.Radio.isChipConnected())
|
||||
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
|
||||
#if !defined(AP_ONLY)
|
||||
// when WiFi is in client mode, then enable mqtt broker
|
||||
#if !defined(AP_ONLY)
|
||||
mMqttEnabled = (mConfig->mqtt.broker[0] > 0);
|
||||
if (mMqttEnabled) {
|
||||
mMqtt.setup(&mConfig->mqtt, mConfig->sys.deviceName, mVersion, &mSys, &mTimestamp);
|
||||
mMqtt.setSubscriptionCb(std::bind(&app::mqttSubRxCb, this, std::placeholders::_1));
|
||||
mPayload.addAlarmListener(std::bind(&PubMqttType::alarmEventListener, &mMqtt, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
setupLed();
|
||||
|
||||
mWeb.setup(this, &mSys, mConfig);
|
||||
|
@ -85,6 +84,7 @@ void app::setup() {
|
|||
|
||||
regularTickers();
|
||||
|
||||
|
||||
// DBGPRINTLN("--- end setup");
|
||||
// DBGPRINTLN(String(ESP.getFreeHeap()));
|
||||
// DBGPRINTLN(String(ESP.getHeapFragmentation()));
|
||||
|
@ -214,15 +214,15 @@ void app::tickNtpUpdate(void) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::tickCalcSunrise(void) {
|
||||
if (mSunrise == 0) // on boot/reboot calc sun values for current time
|
||||
if (mSunrise == 0) // on boot/reboot calc sun values for current time
|
||||
ah::calculateSunriseSunset(mTimestamp, mCalculatedTimezoneOffset, mConfig->sun.lat, mConfig->sun.lon, &mSunrise, &mSunset);
|
||||
|
||||
if (mTimestamp > (mSunset + mConfig->sun.offsetSec)) // current time is past communication stop, calc sun values for next day
|
||||
if (mTimestamp > (mSunset + mConfig->sun.offsetSec)) // current time is past communication stop, calc sun values for next day
|
||||
ah::calculateSunriseSunset(mTimestamp + 86400, mCalculatedTimezoneOffset, mConfig->sun.lat, mConfig->sun.lon, &mSunrise, &mSunset);
|
||||
|
||||
tickIVCommunication();
|
||||
|
||||
uint32_t nxtTrig = mSunset + mConfig->sun.offsetSec + 60; // set next trigger to communication stop, +60 for safety that it is certain past communication stop
|
||||
uint32_t nxtTrig = mSunset + mConfig->sun.offsetSec + 60; // set next trigger to communication stop, +60 for safety that it is certain past communication stop
|
||||
onceAt(std::bind(&app::tickCalcSunrise, this), nxtTrig, "Sunri");
|
||||
if (mMqttEnabled)
|
||||
tickSun();
|
||||
|
@ -230,15 +230,15 @@ void app::tickCalcSunrise(void) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::tickIVCommunication(void) {
|
||||
mIVCommunicationOn = !mConfig->sun.disNightCom; // if sun.disNightCom is false, communication is always on
|
||||
if (!mIVCommunicationOn) { // inverter communication only during the day
|
||||
mIVCommunicationOn = !mConfig->sun.disNightCom; // if sun.disNightCom is false, communication is always on
|
||||
if (!mIVCommunicationOn) { // inverter communication only during the day
|
||||
uint32_t nxtTrig;
|
||||
if (mTimestamp < (mSunrise - mConfig->sun.offsetSec)) { // current time is before communication start, set next trigger to communication start
|
||||
if (mTimestamp < (mSunrise - mConfig->sun.offsetSec)) { // current time is before communication start, set next trigger to communication start
|
||||
nxtTrig = mSunrise - mConfig->sun.offsetSec;
|
||||
} else {
|
||||
if (mTimestamp >= (mSunset + mConfig->sun.offsetSec)) { // current time is past communication stop, nothing to do. Next update will be done at midnight by tickCalcSunrise
|
||||
if (mTimestamp >= (mSunset + mConfig->sun.offsetSec)) { // current time is past communication stop, nothing to do. Next update will be done at midnight by tickCalcSunrise
|
||||
nxtTrig = 0;
|
||||
} else { // current time lies within communication start/stop time, set next trigger to communication stop
|
||||
} else { // current time lies within communication start/stop time, set next trigger to communication stop
|
||||
mIVCommunicationOn = true;
|
||||
nxtTrig = mSunset + mConfig->sun.offsetSec;
|
||||
}
|
||||
|
@ -367,7 +367,7 @@ void app::resetSystem(void) {
|
|||
mSendFirst = true;
|
||||
|
||||
mSunrise = 0;
|
||||
mSunset = 0;
|
||||
mSunset = 0;
|
||||
|
||||
mMqttEnabled = false;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue