mirror of
https://github.com/esphome/esphome.git
synced 2026-05-24 01:37:15 +08:00
[debug] Add iram sensor for ESP32
This commit is contained in:
@@ -45,6 +45,7 @@ class DebugComponent : public PollingComponent {
|
||||
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; }
|
||||
void set_iram_sensor(sensor::Sensor *iram_sensor) { this->iram_sensor_ = iram_sensor; }
|
||||
#endif // USE_ESP32
|
||||
void set_cpu_frequency_sensor(sensor::Sensor *cpu_frequency_sensor) {
|
||||
this->cpu_frequency_sensor_ = cpu_frequency_sensor;
|
||||
@@ -71,6 +72,7 @@ class DebugComponent : public PollingComponent {
|
||||
sensor::Sensor *loop_time_sensor_{nullptr};
|
||||
#ifdef USE_ESP32
|
||||
sensor::Sensor *psram_sensor_{nullptr};
|
||||
sensor::Sensor *iram_sensor_{nullptr};
|
||||
#endif // USE_ESP32
|
||||
sensor::Sensor *cpu_frequency_sensor_{nullptr};
|
||||
#endif // USE_SENSOR
|
||||
|
||||
@@ -301,6 +301,9 @@ void DebugComponent::update_platform_() {
|
||||
if (this->psram_sensor_ != nullptr) {
|
||||
this->psram_sensor_->publish_state(heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
|
||||
}
|
||||
if (this->iram_sensor_ != nullptr) {
|
||||
this->iram_sensor_->publish_state(heap_caps_get_free_size(MALLOC_CAP_IRAM_8BIT));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ DEPENDENCIES = ["debug"]
|
||||
|
||||
CONF_MIN_FREE = "min_free"
|
||||
CONF_PSRAM = "psram"
|
||||
CONF_IRAM = "iram"
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
cv.GenerateID(CONF_DEBUG_ID): cv.use_id(DebugComponent),
|
||||
@@ -98,6 +99,16 @@ CONFIG_SCHEMA = {
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
),
|
||||
cv.Optional(CONF_IRAM): cv.All(
|
||||
cv.only_on_esp32,
|
||||
sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_BYTES,
|
||||
icon=ICON_COUNTER,
|
||||
accuracy_decimals=0,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
),
|
||||
cv.Optional(CONF_CPU_FREQUENCY): cv.All(
|
||||
sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_HERTZ,
|
||||
@@ -138,6 +149,10 @@ async def to_code(config):
|
||||
sens = await sensor.new_sensor(psram_conf)
|
||||
cg.add(debug_component.set_psram_sensor(sens))
|
||||
|
||||
if iram_conf := config.get(CONF_IRAM):
|
||||
sens = await sensor.new_sensor(iram_conf)
|
||||
cg.add(debug_component.set_iram_sensor(sens))
|
||||
|
||||
if cpu_freq_conf := config.get(CONF_CPU_FREQUENCY):
|
||||
sens = await sensor.new_sensor(cpu_freq_conf)
|
||||
cg.add(debug_component.set_cpu_frequency_sensor(sens))
|
||||
|
||||
@@ -9,3 +9,5 @@ sensor:
|
||||
name: "Heap Fragmentation"
|
||||
min_free:
|
||||
name: "Heap Min Free"
|
||||
iram:
|
||||
name: "Free IRAM"
|
||||
|
||||
@@ -13,5 +13,7 @@ sensor:
|
||||
name: "Heap Fragmentation"
|
||||
min_free:
|
||||
name: "Heap Min Free"
|
||||
iram:
|
||||
name: "Free IRAM"
|
||||
|
||||
psram:
|
||||
|
||||
@@ -6,3 +6,5 @@ sensor:
|
||||
name: "Heap Fragmentation"
|
||||
min_free:
|
||||
name: "Heap Min Free"
|
||||
iram:
|
||||
name: "Free IRAM"
|
||||
|
||||
Reference in New Issue
Block a user