ESP32-PaxCounter/src/cyclic.cpp

140 lines
4.2 KiB
C++
Raw Normal View History

2018-07-22 20:27:58 +02:00
/* This routine is called by interrupt in regular intervals */
/* Interval can be set in paxcounter.conf (HOMECYCLE) */
// Basic config
2018-10-03 23:07:22 +02:00
#include "cyclic.h"
2018-07-22 20:27:58 +02:00
Ticker cyclicTimer;
2021-03-03 16:20:21 +01:00
void setCyclicIRQ() { xTaskNotify(irqHandlerTask, CYCLIC_IRQ, eSetBits); }
2018-07-22 20:27:58 +02:00
// do all housekeeping
2018-09-21 18:23:34 +02:00
void doHousekeeping() {
2021-03-03 16:20:21 +01:00
// check if update or maintenance mode trigger switch was set by rcommand
if ((RTC_runmode == RUNMODE_UPDATE) || (RTC_runmode == RUNMODE_MAINTENANCE))
2021-03-04 21:22:49 +01:00
do_reset(true); // warmstart
2022-02-06 20:23:08 +01:00
// print heap and task storage information
ESP_LOGD(TAG, "Heap: Free:%d, Min:%d, Size:%d, Alloc:%d, StackHWM:%d",
ESP.getFreeHeap(), ESP.getMinFreeHeap(), ESP.getHeapSize(),
ESP.getMaxAllocHeap(), uxTaskGetStackHighWaterMark(NULL));
2022-02-06 20:23:08 +01:00
if (irqHandlerTask != NULL)
ESP_LOGD(TAG, "IRQhandler %d bytes left | Taskstate = %d",
uxTaskGetStackHighWaterMark(irqHandlerTask),
eTaskGetState(irqHandlerTask));
if (rcmdTask != NULL)
ESP_LOGD(TAG, "Rcommand interpreter %d bytes left | Taskstate = %d",
uxTaskGetStackHighWaterMark(rcmdTask), eTaskGetState(rcmdTask));
#if (HAS_LORA)
2022-02-06 20:23:08 +01:00
if (lmicTask != NULL)
ESP_LOGD(TAG, "LMiCtask %d bytes left | Taskstate = %d",
uxTaskGetStackHighWaterMark(lmicTask), eTaskGetState(lmicTask));
if (lorasendTask != NULL)
ESP_LOGD(TAG, "Lorasendtask %d bytes left | Taskstate = %d",
uxTaskGetStackHighWaterMark(lorasendTask),
eTaskGetState(lorasendTask));
#endif
2019-04-13 18:44:25 +02:00
#if (HAS_GPS)
2022-02-06 20:23:08 +01:00
if (GpsTask != NULL)
ESP_LOGD(TAG, "Gpsloop %d bytes left | Taskstate = %d",
uxTaskGetStackHighWaterMark(GpsTask), eTaskGetState(GpsTask));
#endif
#ifdef HAS_SPI
2022-02-06 20:23:08 +01:00
if (spiTask != NULL)
ESP_LOGD(TAG, "spiloop %d bytes left | Taskstate = %d",
uxTaskGetStackHighWaterMark(spiTask), eTaskGetState(spiTask));
#endif
2022-02-06 20:23:08 +01:00
2020-05-21 19:42:42 +02:00
#ifdef HAS_MQTT
2022-02-06 20:23:08 +01:00
if (mqttTask != NULL)
ESP_LOGD(TAG, "MQTTloop %d bytes left | Taskstate = %d",
uxTaskGetStackHighWaterMark(mqttTask), eTaskGetState(mqttTask));
2020-05-21 19:42:42 +02:00
#endif
2019-04-08 22:51:12 +02:00
#if (defined HAS_DCF77 || defined HAS_IF482)
2022-02-06 20:23:08 +01:00
if (ClockTask != NULL)
ESP_LOGD(TAG, "Clockloop %d bytes left | Taskstate = %d",
uxTaskGetStackHighWaterMark(ClockTask), eTaskGetState(ClockTask));
#endif
#if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED)
2022-02-06 20:23:08 +01:00
if (ledLoopTask != NULL)
ESP_LOGD(TAG, "LEDloop %d bytes left | Taskstate = %d",
uxTaskGetStackHighWaterMark(ledLoopTask),
eTaskGetState(ledLoopTask));
#endif
2022-11-06 15:00:54 +01:00
#ifdef HAS_BUTTON
if (buttonLoopTask != NULL)
ESP_LOGD(TAG, "Buttonloop %d bytes left | Taskstate = %d",
uxTaskGetStackHighWaterMark(buttonLoopTask),
eTaskGetState(buttonLoopTask));
#endif
2018-07-22 20:27:58 +02:00
// read battery voltage into global variable
#if (defined BAT_MEASURE_ADC || defined HAS_PMU || defined HAS_IP5306)
2020-04-11 21:30:09 +02:00
batt_level = read_battlevel();
#ifdef HAS_PMU
AXP192_showstatus();
#endif
#ifdef HAS_IP5306
printIP5306Stats();
#endif
#endif
// display BME680/280 sensor data
#if (HAS_BME)
2019-03-08 18:13:51 +01:00
#ifdef HAS_BME680
2019-01-06 19:41:42 +01:00
ESP_LOGI(TAG, "BME680 Temp: %.2f°C | IAQ: %.2f | IAQacc: %d",
bme_status.temperature, bme_status.iaq, bme_status.iaq_accuracy);
#elif defined HAS_BME280
2019-03-16 09:08:25 +01:00
ESP_LOGI(TAG, "BME280 Temp: %.2f°C | Humidity: %.2f | Pressure: %.0f",
2019-03-08 18:13:51 +01:00
bme_status.temperature, bme_status.humidity, bme_status.pressure);
2019-12-08 12:58:12 +01:00
#elif defined HAS_BMP180
2019-12-25 23:22:11 +01:00
ESP_LOGI(TAG, "BMP180 Temp: %.2f°C | Pressure: %.0f", bme_status.temperature,
bme_status.pressure);
#endif
2019-03-08 18:13:51 +01:00
#endif
2018-12-22 14:37:47 +01:00
// check free heap memory
if (ESP.getMinFreeHeap() <= MEM_LOW) {
ESP_LOGW(TAG,
2018-07-22 20:27:58 +02:00
"Memory full, counter cleared (heap low water mark = %d Bytes / "
"free heap = %d bytes)",
2019-01-06 19:41:42 +01:00
ESP.getMinFreeHeap(), ESP.getFreeHeap());
do_reset(true); // memory leak, reset device
2018-07-22 20:27:58 +02:00
}
2018-12-22 14:37:47 +01:00
// check free PSRAM memory
#ifdef BOARD_HAS_PSRAM
if (ESP.getMinFreePsram() <= MEM_LOW) {
ESP_LOGW(TAG, "PSRAM full, counter cleared");
do_reset(true); // memory leak, reset device
2018-12-22 14:37:47 +01:00
}
#endif
2020-02-03 15:29:32 +01:00
#if (HAS_SDS011)
2020-04-11 23:36:17 +02:00
if (isSDS011Active) {
sds011_loop();
} else {
sds011_wakeup();
}
2020-02-03 15:29:32 +01:00
#endif
2022-02-26 17:30:23 +01:00
#if (HAS_SDCARD)
sdcard_flush();
#endif
2020-02-03 15:29:32 +01:00
} // doHousekeeping()
uint32_t getFreeRAM() {
#ifndef BOARD_HAS_PSRAM
return ESP.getFreeHeap();
#else
return ESP.getFreePsram();
#endif
}