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,";
info.features &= ~CHIP_FEATURE_BT;
}
if (info.features & CHIP_FEATURE_EMB_PSRAM) {
features += "EMB_PSRAM,";
info.features &= ~CHIP_FEATURE_EMB_PSRAM;
}
if (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,
@ -423,6 +427,12 @@ void DebugComponent::update() {
this->loop_time_sensor_->publish_state(this->max_loop_time_);
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
}

View File

@ -33,6 +33,9 @@ class DebugComponent : public PollingComponent {
void set_fragmentation_sensor(sensor::Sensor *fragmentation_sensor) { fragmentation_sensor_ = fragmentation_sensor; }
#endif
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
protected:
uint32_t free_heap_{};
@ -47,6 +50,9 @@ class DebugComponent : public PollingComponent {
sensor::Sensor *fragmentation_sensor_{nullptr};
#endif
sensor::Sensor *loop_time_sensor_{nullptr};
#ifdef USE_ESP32
sensor::Sensor *psram_sensor_{nullptr};
#endif // USE_ESP32
#endif // USE_SENSOR
#ifdef USE_TEXT_SENSOR

View File

@ -17,6 +17,8 @@ from . import CONF_DEBUG_ID, DebugComponent
DEPENDENCIES = ["debug"]
CONF_PSRAM = "psram"
CONFIG_SCHEMA = {
cv.GenerateID(CONF_DEBUG_ID): cv.use_id(DebugComponent),
cv.Optional(CONF_FREE): sensor.sensor_schema(
@ -47,24 +49,38 @@ CONFIG_SCHEMA = {
accuracy_decimals=0,
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):
debug_component = await cg.get_variable(config[CONF_DEBUG_ID])
if CONF_FREE in config:
sens = await sensor.new_sensor(config[CONF_FREE])
if free_conf := config.get(CONF_FREE):
sens = await sensor.new_sensor(free_conf)
cg.add(debug_component.set_free_sensor(sens))
if CONF_BLOCK in config:
sens = await sensor.new_sensor(config[CONF_BLOCK])
if block_conf := config.get(CONF_BLOCK):
sens = await sensor.new_sensor(block_conf)
cg.add(debug_component.set_block_sensor(sens))
if CONF_FRAGMENTATION in config:
sens = await sensor.new_sensor(config[CONF_FRAGMENTATION])
if fragmentation_conf := config.get(CONF_FRAGMENTATION):
sens = await sensor.new_sensor(fragmentation_conf)
cg.add(debug_component.set_fragmentation_sensor(sens))
if CONF_LOOP_TIME in config:
sens = await sensor.new_sensor(config[CONF_LOOP_TIME])
if loop_time_conf := config.get(CONF_LOOP_TIME):
sens = await sensor.new_sensor(loop_time_conf)
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:
name: "BMP581 Pressure"
oversampling: 128x
- platform: debug
free:
name: "Heap Free"
block:
name: "Heap Max Block"
loop_time:
name: "Loop Time"
psram:
name: "PSRAM Free"
esp32_touch:
setup_mode: false
@ -3448,7 +3457,6 @@ number:
still_threshold:
name: g8 still threshold
select:
- platform: template
id: test_select

View File

@ -28,6 +28,10 @@ ota:
logger:
debug:
psram:
uart:
- id: uart_1
tx_pin: 1
@ -525,6 +529,16 @@ sensor:
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
model: custom
command: 0x100

View File

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