mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-27 05:06:44 +00:00
Add memory functions to device class
This commit is contained in:
parent
a7e6def457
commit
09c9e7f066
@ -7,6 +7,7 @@
|
|||||||
* INCLUDES
|
* INCLUDES
|
||||||
*********************/
|
*********************/
|
||||||
#include "../../src/hal/hasp_hal.h" // for halGpioName()
|
#include "../../src/hal/hasp_hal.h" // for halGpioName()
|
||||||
|
#include "../../src/dev/device.h"
|
||||||
#include "tft_espi_drv.h"
|
#include "tft_espi_drv.h"
|
||||||
#include "ArduinoLog.h"
|
#include "ArduinoLog.h"
|
||||||
#include "hasp_macro.h"
|
#include "hasp_macro.h"
|
||||||
@ -165,7 +166,7 @@ static void tftShowConfig(TFT_eSPI & tft)
|
|||||||
#else
|
#else
|
||||||
LOG_VERBOSE(TAG_TFT, F("Processor : STM%x"), tftSetup.esp);
|
LOG_VERBOSE(TAG_TFT, F("Processor : STM%x"), tftSetup.esp);
|
||||||
#endif
|
#endif
|
||||||
LOG_VERBOSE(TAG_TFT, F("CPU freq. : %i MHz"), halGetCpuFreqMHz());
|
LOG_VERBOSE(TAG_TFT, F("CPU freq. : %i MHz"), haspDevice.get_cpu_frequency());
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
LOG_VERBOSE(TAG_TFT, F("Voltage : %2.2f V"), ESP.getVcc() / 918.0); // 918 empirically determined
|
LOG_VERBOSE(TAG_TFT, F("Voltage : %2.2f V"), ESP.getVcc() / 918.0); // 918 empirically determined
|
||||||
|
@ -39,19 +39,27 @@ class BaseDevice {
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
virtual size_t get_free_max_block()
|
||||||
|
{}
|
||||||
|
virtual size_t get_free_heap()
|
||||||
|
{}
|
||||||
|
virtual uint8_t get_heap_fragmentation()
|
||||||
|
{}
|
||||||
|
virtual uint16_t get_cpu_frequency()
|
||||||
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dev
|
} // namespace dev
|
||||||
|
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
#warning Building for ESP32 Devices
|
#warning Building for ESP32 Devices
|
||||||
#include "dev/esp32/esp32.h"
|
#include "esp32/esp32.h"
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
#warning Building for ESP8266 Devices
|
#warning Building for ESP8266 Devices
|
||||||
#include "dev/esp8266/esp8266.h"
|
#include "esp8266/esp8266.h"
|
||||||
#elif defined(STM32F4)
|
#elif defined(STM32F4)
|
||||||
#warning Building for STM32F4xx Devices
|
#warning Building for STM32F4xx Devices
|
||||||
#include "dev/stm32f4.h"
|
#include "stm32f4/stm32f4.h"
|
||||||
#else
|
#else
|
||||||
#warning Building for Generic Devices
|
#warning Building for Generic Devices
|
||||||
using dev::BaseDevice;
|
using dev::BaseDevice;
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
#include <Esp.h>
|
#include <Esp.h>
|
||||||
#include "esp_system.h"
|
#include "esp_system.h"
|
||||||
|
|
||||||
#include "dev/device.h"
|
#include "../device.h"
|
||||||
#include "dev/esp32/esp32.h"
|
#include "esp32.h"
|
||||||
|
|
||||||
#include "driver/adc.h"
|
#include "driver/adc.h"
|
||||||
#include "esp_adc_cal.h"
|
#include "esp_adc_cal.h"
|
||||||
@ -69,6 +69,31 @@ void Esp32Device::update_backlight()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t Esp32Device::get_free_max_block()
|
||||||
|
{
|
||||||
|
return ESP.getMaxAllocHeap();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Esp32Device::get_free_heap()
|
||||||
|
{
|
||||||
|
return ESP.getFreeHeap();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t Esp32Device::get_heap_fragmentation()
|
||||||
|
{
|
||||||
|
uint32_t free = ESP.getFreeHeap();
|
||||||
|
if(free) {
|
||||||
|
return (int8_t)(100.00f - (float)ESP.getMaxAllocHeap() * 100.00f / (float)free);
|
||||||
|
} else {
|
||||||
|
return 100; // no free memory
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t Esp32Device::get_cpu_frequency()
|
||||||
|
{
|
||||||
|
return ESP.getCpuFreqMHz();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace dev
|
} // namespace dev
|
||||||
|
|
||||||
#if defined(LANBONL8)
|
#if defined(LANBONL8)
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#ifndef HASP_DEVICE_ESP32_H
|
#ifndef HASP_DEVICE_ESP32_H
|
||||||
#define HASP_DEVICE_ESP32_H
|
#define HASP_DEVICE_ESP32_H
|
||||||
|
|
||||||
#include "dev/device.h"
|
#include "../device.h"
|
||||||
|
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
|
|
||||||
@ -25,6 +25,14 @@ class Esp32Device : public BaseDevice {
|
|||||||
|
|
||||||
bool get_backlight_power() override;
|
bool get_backlight_power() override;
|
||||||
|
|
||||||
|
size_t get_free_max_block() override;
|
||||||
|
|
||||||
|
size_t get_free_heap() override;
|
||||||
|
|
||||||
|
uint8_t get_heap_fragmentation() override;
|
||||||
|
|
||||||
|
uint16_t get_cpu_frequency() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t backlight_pin;
|
uint8_t backlight_pin;
|
||||||
uint8_t backlight_level;
|
uint8_t backlight_level;
|
||||||
@ -39,10 +47,10 @@ using dev::Esp32Device;
|
|||||||
|
|
||||||
#if defined(LANBONL8)
|
#if defined(LANBONL8)
|
||||||
#warning Building for Lanbon L8
|
#warning Building for Lanbon L8
|
||||||
#include "dev/esp32/lanbonl8.h"
|
#include "lanbonl8.h"
|
||||||
#elif defined(M5STACK)
|
#elif defined(M5STACK)
|
||||||
#warning Building for M5Stack core2
|
#warning Building for M5Stack core2
|
||||||
#include "dev/esp32/m5stackcore2.h"
|
#include "m5stackcore2.h"
|
||||||
#else
|
#else
|
||||||
extern dev::Esp32Device haspDevice;
|
extern dev::Esp32Device haspDevice;
|
||||||
#endif
|
#endif
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#ifndef HASP_DEVICE_LANBONL8_H
|
#ifndef HASP_DEVICE_LANBONL8_H
|
||||||
#define HASP_DEVICE_LANBONL8_H
|
#define HASP_DEVICE_LANBONL8_H
|
||||||
|
|
||||||
#include "dev/esp32/esp32.h"
|
#include "esp32.h"
|
||||||
|
|
||||||
#if defined(LANBONL8)
|
#if defined(LANBONL8)
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#if defined(M5STACK)
|
#if defined(M5STACK)
|
||||||
|
|
||||||
#include "dev/esp32/esp32.h"
|
#include "esp32.h"
|
||||||
|
|
||||||
namespace dev {
|
namespace dev {
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include <Esp.h>
|
#include <Esp.h>
|
||||||
|
|
||||||
#include "dev/esp8266/esp8266.h"
|
#include "esp8266.h"
|
||||||
|
|
||||||
#include "hasp_conf.h"
|
#include "hasp_conf.h"
|
||||||
#include "hasp_debug.h"
|
#include "hasp_debug.h"
|
||||||
@ -59,6 +59,26 @@ void Esp8266Device::update_backlight()
|
|||||||
analogWrite(backlight_pin, backlight_power ? map(backlight_level, 0, 100, 0, 1023) : 0);
|
analogWrite(backlight_pin, backlight_power ? map(backlight_level, 0, 100, 0, 1023) : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t Esp8266Device::get_free_max_block()
|
||||||
|
{
|
||||||
|
return ESP.getMaxFreeBlockSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Esp8266Device::get_free_heap(void)
|
||||||
|
{
|
||||||
|
return ESP.getFreeHeap();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t Esp8266Device::get_heap_fragmentation()
|
||||||
|
{
|
||||||
|
return ESP.getHeapFragmentation();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t Esp8266Device::get_cpu_frequency()
|
||||||
|
{
|
||||||
|
return ESP.getCpuFreqMHz();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace dev
|
} // namespace dev
|
||||||
|
|
||||||
dev::Esp8266Device haspDevice;
|
dev::Esp8266Device haspDevice;
|
||||||
|
@ -26,6 +26,14 @@ class Esp8266Device : public BaseDevice {
|
|||||||
|
|
||||||
bool get_backlight_power() override;
|
bool get_backlight_power() override;
|
||||||
|
|
||||||
|
size_t get_free_max_block() override;
|
||||||
|
|
||||||
|
size_t get_free_heap() override;
|
||||||
|
|
||||||
|
uint8_t get_heap_fragmentation() override;
|
||||||
|
|
||||||
|
uint16_t get_cpu_frequency() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t backlight_pin;
|
uint8_t backlight_pin;
|
||||||
uint8_t backlight_level;
|
uint8_t backlight_level;
|
||||||
|
@ -6,15 +6,15 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
void halRestartMcu(void);
|
// void halRestartMcu(void);
|
||||||
uint8_t halGetHeapFragmentation(void);
|
|
||||||
String halGetResetInfo(void);
|
String halGetResetInfo(void);
|
||||||
size_t halGetMaxFreeBlock(void);
|
// uint8_t halGetHeapFragmentation(void);
|
||||||
size_t halGetFreeHeap(void);
|
// size_t halGetMaxFreeBlock(void);
|
||||||
|
// size_t halGetFreeHeap(void);
|
||||||
String halGetCoreVersion(void);
|
String halGetCoreVersion(void);
|
||||||
String halGetChipModel();
|
String halGetChipModel();
|
||||||
String halGetMacAddress(int start, const char * seperator);
|
String halGetMacAddress(int start, const char * seperator);
|
||||||
uint16_t halGetCpuFreqMHz(void);
|
// uint16_t halGetCpuFreqMHz(void);
|
||||||
String halDisplayDriverName(void);
|
String halDisplayDriverName(void);
|
||||||
String halGpioName(uint8_t gpio);
|
String halGpioName(uint8_t gpio);
|
||||||
|
|
||||||
|
@ -875,7 +875,8 @@ void dispatch_reboot(bool saveConfig)
|
|||||||
Serial.flush();
|
Serial.flush();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
halRestartMcu();
|
// halRestartMcu();
|
||||||
|
haspDevice.reboot();
|
||||||
}
|
}
|
||||||
|
|
||||||
void dispatch_current_state()
|
void dispatch_current_state()
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "hasp_conf.h"
|
#include "hasp_conf.h"
|
||||||
|
#include "dev/device.h"
|
||||||
|
|
||||||
#include "hal/hasp_hal.h"
|
#include "hal/hasp_hal.h"
|
||||||
#include "hasp_debug.h"
|
#include "hasp_debug.h"
|
||||||
@ -369,9 +370,9 @@ static void debugPrintTimestamp(int level, Print * _logOutput)
|
|||||||
|
|
||||||
static void debugPrintHaspMemory(int level, Print * _logOutput)
|
static void debugPrintHaspMemory(int level, Print * _logOutput)
|
||||||
{
|
{
|
||||||
size_t maxfree = halGetMaxFreeBlock();
|
size_t maxfree = haspDevice.get_free_max_block();
|
||||||
uint32_t totalfree = halGetFreeHeap();
|
size_t totalfree = haspDevice.get_free_heap();
|
||||||
uint8_t frag = halGetHeapFragmentation();
|
uint8_t frag = haspDevice.get_heap_fragmentation();
|
||||||
|
|
||||||
/* Print HASP Memory Info */
|
/* Print HASP Memory Info */
|
||||||
if(debugAnsiCodes) {
|
if(debugAnsiCodes) {
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "hasp_conf.h"
|
#include "hasp_conf.h"
|
||||||
|
#include "dev/device.h"
|
||||||
|
|
||||||
#include "hasp_gui.h"
|
#include "hasp_gui.h"
|
||||||
#include "hal/hasp_hal.h"
|
#include "hal/hasp_hal.h"
|
||||||
@ -118,7 +119,6 @@ extern char mqttNodeName[16];
|
|||||||
char mqttNodeName[3] = "na";
|
char mqttNodeName[3] = "na";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
String getOption(int value, String label, bool selected)
|
String getOption(int value, String label, bool selected)
|
||||||
{
|
{
|
||||||
@ -527,10 +527,10 @@ void webHandleInfo()
|
|||||||
httpMessage += F("s");
|
httpMessage += F("s");
|
||||||
|
|
||||||
httpMessage += F("<br/><b>Free Memory: </b>");
|
httpMessage += F("<br/><b>Free Memory: </b>");
|
||||||
Utilities::format_bytes(halGetFreeHeap(), size_buf, sizeof(size_buf));
|
Utilities::format_bytes(haspDevice.get_free_heap(), size_buf, sizeof(size_buf));
|
||||||
httpMessage += size_buf;
|
httpMessage += size_buf;
|
||||||
httpMessage += F("<br/><b>Memory Fragmentation: </b>");
|
httpMessage += F("<br/><b>Memory Fragmentation: </b>");
|
||||||
httpMessage += String(halGetHeapFragmentation());
|
httpMessage += String(haspDevice.get_heap_fragmentation());
|
||||||
|
|
||||||
#if ARDUINO_ARCH_ESP32
|
#if ARDUINO_ARCH_ESP32
|
||||||
if(psramFound()) {
|
if(psramFound()) {
|
||||||
@ -648,7 +648,7 @@ void webHandleInfo()
|
|||||||
httpMessage += F("</p/><p><b>MCU Model: </b>");
|
httpMessage += F("</p/><p><b>MCU Model: </b>");
|
||||||
httpMessage += halGetChipModel();
|
httpMessage += halGetChipModel();
|
||||||
httpMessage += F("<br/><b>CPU Frequency: </b>");
|
httpMessage += F("<br/><b>CPU Frequency: </b>");
|
||||||
httpMessage += String(halGetCpuFreqMHz());
|
httpMessage += String(haspDevice.get_cpu_frequency());
|
||||||
httpMessage += F("MHz");
|
httpMessage += F("MHz");
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
|
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
|
||||||
@ -670,7 +670,7 @@ void webHandleInfo()
|
|||||||
// httpMessage += String(ESP.getSdkVersion());
|
// httpMessage += String(ESP.getSdkVersion());
|
||||||
//#else
|
//#else
|
||||||
httpMessage += F("<br/><b>Core version: </b>");
|
httpMessage += F("<br/><b>Core version: </b>");
|
||||||
httpMessage += String(halGetCoreVersion());
|
httpMessage += halGetCoreVersion();
|
||||||
//#endif
|
//#endif
|
||||||
httpMessage += F("<br/><b>Last Reset: </b>");
|
httpMessage += F("<br/><b>Last Reset: </b>");
|
||||||
httpMessage += halGetResetInfo();
|
httpMessage += halGetResetInfo();
|
||||||
@ -1129,7 +1129,8 @@ void webHandleMqttConfig()
|
|||||||
F("'><p><button type='submit' name='save' value='mqtt'>" D_HTTP_SAVE_SETTINGS "</button></form></p>");
|
F("'><p><button type='submit' name='save' value='mqtt'>" D_HTTP_SAVE_SETTINGS "</button></form></p>");
|
||||||
|
|
||||||
add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F(""));
|
add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F(""));
|
||||||
// httpMessage += PSTR("<p><form method='get' action='/config'><button type='submit'>↩ " D_HTTP_CONFIGURATION
|
// httpMessage += PSTR("<p><form method='get' action='/config'><button type='submit'>↩ "
|
||||||
|
// D_HTTP_CONFIGURATION
|
||||||
// "</button></form></p>");
|
// "</button></form></p>");
|
||||||
|
|
||||||
webSendPage(httpGetNodename(), httpMessage.length(), false);
|
webSendPage(httpGetNodename(), httpMessage.length(), false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user