Debug component: add free PSRAM sensor (#5334)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
kahrendt 2023-09-04 22:02:59 -04:00 committed by GitHub
parent d382ca2401
commit 562f7c8718
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 78 additions and 9 deletions

View file

@ -145,6 +145,10 @@ void DebugComponent::dump_config() {
features += "BT,"; features += "BT,";
info.features &= ~CHIP_FEATURE_BT; info.features &= ~CHIP_FEATURE_BT;
} }
if (info.features & CHIP_FEATURE_EMB_PSRAM) {
features += "EMB_PSRAM,";
info.features &= ~CHIP_FEATURE_EMB_PSRAM;
}
if (info.features) if (info.features)
features += "Other:" + format_hex(info.features); features += "Other:" + format_hex(info.features);
ESP_LOGD(TAG, "Chip: Model=%s, Features=%s Cores=%u, Revision=%u", model, features.c_str(), info.cores, ESP_LOGD(TAG, "Chip: Model=%s, Features=%s Cores=%u, Revision=%u", model, features.c_str(), info.cores,
@ -423,6 +427,12 @@ void DebugComponent::update() {
this->loop_time_sensor_->publish_state(this->max_loop_time_); this->loop_time_sensor_->publish_state(this->max_loop_time_);
this->max_loop_time_ = 0; this->max_loop_time_ = 0;
} }
#ifdef USE_ESP32
if (this->psram_sensor_ != nullptr) {
this->psram_sensor_->publish_state(heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
}
#endif // USE_ESP32
#endif // USE_SENSOR #endif // USE_SENSOR
} }

View file

@ -33,6 +33,9 @@ class DebugComponent : public PollingComponent {
void set_fragmentation_sensor(sensor::Sensor *fragmentation_sensor) { fragmentation_sensor_ = fragmentation_sensor; } void set_fragmentation_sensor(sensor::Sensor *fragmentation_sensor) { fragmentation_sensor_ = fragmentation_sensor; }
#endif #endif
void set_loop_time_sensor(sensor::Sensor *loop_time_sensor) { loop_time_sensor_ = loop_time_sensor; } void set_loop_time_sensor(sensor::Sensor *loop_time_sensor) { loop_time_sensor_ = loop_time_sensor; }
#ifdef USE_ESP32
void set_psram_sensor(sensor::Sensor *psram_sensor) { this->psram_sensor_ = psram_sensor; }
#endif // USE_ESP32
#endif // USE_SENSOR #endif // USE_SENSOR
protected: protected:
uint32_t free_heap_{}; uint32_t free_heap_{};
@ -47,6 +50,9 @@ class DebugComponent : public PollingComponent {
sensor::Sensor *fragmentation_sensor_{nullptr}; sensor::Sensor *fragmentation_sensor_{nullptr};
#endif #endif
sensor::Sensor *loop_time_sensor_{nullptr}; sensor::Sensor *loop_time_sensor_{nullptr};
#ifdef USE_ESP32
sensor::Sensor *psram_sensor_{nullptr};
#endif // USE_ESP32
#endif // USE_SENSOR #endif // USE_SENSOR
#ifdef USE_TEXT_SENSOR #ifdef USE_TEXT_SENSOR

View file

@ -17,6 +17,8 @@ from . import CONF_DEBUG_ID, DebugComponent
DEPENDENCIES = ["debug"] DEPENDENCIES = ["debug"]
CONF_PSRAM = "psram"
CONFIG_SCHEMA = { CONFIG_SCHEMA = {
cv.GenerateID(CONF_DEBUG_ID): cv.use_id(DebugComponent), cv.GenerateID(CONF_DEBUG_ID): cv.use_id(DebugComponent),
cv.Optional(CONF_FREE): sensor.sensor_schema( cv.Optional(CONF_FREE): sensor.sensor_schema(
@ -47,24 +49,38 @@ CONFIG_SCHEMA = {
accuracy_decimals=0, accuracy_decimals=0,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
cv.Optional(CONF_PSRAM): cv.All(
cv.only_on_esp32,
cv.requires_component("psram"),
sensor.sensor_schema(
unit_of_measurement=UNIT_BYTES,
icon=ICON_COUNTER,
accuracy_decimals=0,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
),
} }
async def to_code(config): async def to_code(config):
debug_component = await cg.get_variable(config[CONF_DEBUG_ID]) debug_component = await cg.get_variable(config[CONF_DEBUG_ID])
if CONF_FREE in config: if free_conf := config.get(CONF_FREE):
sens = await sensor.new_sensor(config[CONF_FREE]) sens = await sensor.new_sensor(free_conf)
cg.add(debug_component.set_free_sensor(sens)) cg.add(debug_component.set_free_sensor(sens))
if CONF_BLOCK in config: if block_conf := config.get(CONF_BLOCK):
sens = await sensor.new_sensor(config[CONF_BLOCK]) sens = await sensor.new_sensor(block_conf)
cg.add(debug_component.set_block_sensor(sens)) cg.add(debug_component.set_block_sensor(sens))
if CONF_FRAGMENTATION in config: if fragmentation_conf := config.get(CONF_FRAGMENTATION):
sens = await sensor.new_sensor(config[CONF_FRAGMENTATION]) sens = await sensor.new_sensor(fragmentation_conf)
cg.add(debug_component.set_fragmentation_sensor(sens)) cg.add(debug_component.set_fragmentation_sensor(sens))
if CONF_LOOP_TIME in config: if loop_time_conf := config.get(CONF_LOOP_TIME):
sens = await sensor.new_sensor(config[CONF_LOOP_TIME]) sens = await sensor.new_sensor(loop_time_conf)
cg.add(debug_component.set_loop_time_sensor(sens)) cg.add(debug_component.set_loop_time_sensor(sens))
if psram_conf := config.get(CONF_PSRAM):
sens = await sensor.new_sensor(psram_conf)
cg.add(debug_component.set_psram_sensor(sens))

View file

@ -1448,6 +1448,15 @@ sensor:
pressure: pressure:
name: "BMP581 Pressure" name: "BMP581 Pressure"
oversampling: 128x oversampling: 128x
- platform: debug
free:
name: "Heap Free"
block:
name: "Heap Max Block"
loop_time:
name: "Loop Time"
psram:
name: "PSRAM Free"
esp32_touch: esp32_touch:
setup_mode: false setup_mode: false
@ -3448,7 +3457,6 @@ number:
still_threshold: still_threshold:
name: g8 still threshold name: g8 still threshold
select: select:
- platform: template - platform: template
id: test_select id: test_select

View file

@ -28,6 +28,10 @@ ota:
logger: logger:
debug:
psram:
uart: uart:
- id: uart_1 - id: uart_1
tx_pin: 1 tx_pin: 1
@ -525,6 +529,16 @@ sensor:
time: time:
name: System Time name: System Time
- platform: debug
free:
name: "Heap Free"
block:
name: "Heap Max Block"
loop_time:
name: "Loop Time"
psram:
name: "PSRAM Free"
- platform: vbus - platform: vbus
model: custom model: custom
command: 0x100 command: 0x100

View file

@ -14,6 +14,10 @@ esphome:
logger: logger:
debug:
psram:
light: light:
- platform: neopixelbus - platform: neopixelbus
type: GRB type: GRB
@ -50,3 +54,14 @@ binary_sensor:
- platform: tt21100 - platform: tt21100
name: Home Button name: Home Button
index: 1 index: 1
sensor:
- platform: debug
free:
name: "Heap Free"
block:
name: "Max Block Free"
loop_time:
name: "Loop Time"
psram:
name: "PSRAM Free"