Files
audio2midi/src/esp_info.cpp
Jose 6d55c2315a Changes committed:
new file:   .gitignore
	modified:   README.md
	new file:   data/www/dashboard.html
	new file:   data/www/index.html
	new file:   data/www/wifi.html
	new file:   include/README
	new file:   lib/README
	new file:   notes.ods
	new file:   platformio.ini
	new file:   src/NoteMappings copy.h
	new file:   src/NoteMappings.h
	new file:   src/audio_input.cpp
	new file:   src/audio_input.h
	new file:   src/ble.cpp
	new file:   src/ble.h
	new file:   src/config.h
	new file:   src/esp_info.cpp
	new file:   src/esp_info.h
	new file:   src/fft_processing.cpp
	new file:   src/fft_processing.h
	new file:   src/led_control.cpp
	new file:   src/led_control.h
	new file:   src/main.cpp
	new file:   src/midi.cpp
	new file:   src/midi.h
	new file:   src/web_server.cpp
	new file:   src/web_server.h
	new file:   test/README
2025-04-12 21:23:24 +02:00

155 lines
6.0 KiB
C++

// esp_info.cpp
#include <Arduino.h>
#include "esp_info.h"
#include "driver/temp_sensor.h"
static bool temp_sensor_initialized = false;
float readInternalTemperature() {
esp_err_t err;
float temp = 0;
if (!temp_sensor_initialized) {
Serial.println("Initializing temperature sensor...");
// Manual default configuration for ESP32-S3
temp_sensor_config_t temp_config = {
.dac_offset = TSENS_DAC_L2, // Default offset
.clk_div = 6, // Default clock divider
};
err = temp_sensor_set_config(temp_config);
if (err != ESP_OK) {
Serial.printf("Failed to set temp sensor config: %d\n", err);
return NAN;
}
err = temp_sensor_start();
if (err != ESP_OK) {
Serial.printf("Failed to start temp sensor: %d\n", err);
return NAN;
}
temp_sensor_initialized = true;
delay(100); // Allow sensor to stabilize
Serial.println("Temperature sensor initialized");
}
err = temp_sensor_read_celsius(&temp);
if (err != ESP_OK) {
Serial.printf("Failed to read temperature: %d\n", err);
return NAN;
}
return temp;
}
void prettyPrintBytes(size_t bytes) {
if (bytes < 1024) {
Serial.printf("%d b\n", bytes);
} else if (bytes < (1024 * 1024)) {
Serial.printf("%.2f kb\n", bytes / 1024.0);
} else {
Serial.printf("%.2f mb\n", bytes / (1024.0 * 1024));
}
}
String formatBytes(size_t bytes) {
if (bytes < 1024) return String(bytes) + " b";
else if (bytes < (1024 * 1024)) return String(bytes / 1024.0, 2) + " kb";
else return String(bytes / (1024.0 * 1024), 2) + " mb";
}
String getESPInfoHTML() {
String html = "<div class='esp-info'><h3>ESP32 Information</h3>";
html += "<h4>Internal RAM</h4>";
html += "<p>Heap Size: " + formatBytes(ESP.getHeapSize()) + "</p>";
html += "<p>Free Heap: " + formatBytes(ESP.getFreeHeap()) + "</p>";
html += "<h4>PSRAM</h4>";
html += "<p>PSRAM Size: " + formatBytes(ESP.getPsramSize()) + "</p>";
html += "<p>Free PSRAM: " + formatBytes(ESP.getFreePsram()) + "</p>";
html += "<h4>Flash</h4>";
size_t usedBytes = ESP.getSketchSize();
size_t totalBytes = ESP.getFlashChipSize();
float usagePercent = (usedBytes * 100.0) / totalBytes;
html += "<p>Flash Size: " + formatBytes(totalBytes) + "</p>";
html += "<p>Used: " + formatBytes(usedBytes) + " (" + String(usagePercent, 1) + "%)</p>";
html += "<p>Flash Speed: " + String(ESP.getFlashChipSpeed() / 1000000) + " MHz</p>";
html += "<h4>CPU</h4>";
html += "<p>Model: " + String(ESP.getChipModel()) + "</p>";
html += "<p>Cores: " + String(ESP.getChipCores()) + "</p>";
html += "<p>Frequency: " + String(ESP.getCpuFreqMHz()) + " MHz</p>";
float temperature = readInternalTemperature();
if (!isnan(temperature)) {
html += "<h4>Temperature Sensor</h4>";
html += "<p>Internal Temperature: " + String(temperature, 2) + " °C</p>";
}
html += "</div>";
return html;
}
String getRAMInfoHTML() {
String html = "<div class='ram-info'><h3>RAM Information</h3>";
html += "<p>Heap Size: " + formatBytes(ESP.getHeapSize()) + "</p>";
html += "<p>Free Heap: " + formatBytes(ESP.getFreeHeap()) + "</p>";
html += "<p>Min Free Heap: " + formatBytes(ESP.getMinFreeHeap()) + "</p>";
html += "<p>Max Alloc Heap: " + formatBytes(ESP.getMaxAllocHeap()) + "</p>";
html += "<h4>PSRAM</h4>";
html += "<p>PSRAM Size: " + formatBytes(ESP.getPsramSize()) + "</p>";
html += "<p>Free PSRAM: " + formatBytes(ESP.getFreePsram()) + "</p>";
html += "<p>Min Free PSRAM: " + formatBytes(ESP.getMinFreePsram()) + "</p>";
html += "<p>Max Alloc PSRAM: " + formatBytes(ESP.getMaxAllocPsram()) + "</p>";
html += "</div>";
return html;
}
void printESPInfo() {
Serial.println("ESP32-S3 info");
Serial.println("Internal RAM");
Serial.print(" getHeapSize: "); prettyPrintBytes(ESP.getHeapSize());
Serial.print(" getFreeHeap: "); prettyPrintBytes(ESP.getFreeHeap());
Serial.print(" getMinFreeHeap: "); prettyPrintBytes(ESP.getMinFreeHeap());
Serial.print(" getMaxAllocHeap: "); prettyPrintBytes(ESP.getMaxAllocHeap());
Serial.println("PSRAM");
Serial.print(" getPsramSize: "); prettyPrintBytes(ESP.getPsramSize());
Serial.print(" getFreePsram: "); prettyPrintBytes(ESP.getFreePsram());
Serial.print(" getMinFreePsram: "); prettyPrintBytes(ESP.getMinFreePsram());
Serial.print(" getMaxAllocPsram: "); prettyPrintBytes(ESP.getMaxAllocPsram());
Serial.println("Flash");
Serial.print(" getFlashChipSize: "); prettyPrintBytes(ESP.getFlashChipSize());
Serial.printf(" getFlashChipSpeed: %d MHz\n", ESP.getFlashChipSpeed() / 1000 / 1000);
Serial.print(" getFlashChipMode: "); Serial.println("SKIPPED");
Serial.println("CPU");
Serial.printf(" getChipRevision: %d\n", ESP.getChipRevision());
Serial.printf(" getChipModel: %s\n", ESP.getChipModel());
Serial.printf(" getChipCores: %d\n", ESP.getChipCores());
Serial.printf(" getCpuFreqMHz: %d\n", ESP.getCpuFreqMHz());
Serial.printf(" getEfuseMac: %llX\n", ESP.getEfuseMac());
float temperature = readInternalTemperature();
if (!isnan(temperature)) {
Serial.printf(" Internal Temperature: %.2f °C\n", temperature);
} else {
Serial.println(" Internal Temperature: Read failed");
}
Serial.println("Software");
Serial.printf(" getSdkVersion: %s\n", ESP.getSdkVersion());
Serial.print(" getSketchSize: "); prettyPrintBytes(ESP.getSketchSize());
Serial.printf(" getFreeSketchSpace: %d kb\n", ESP.getFreeSketchSpace() / 1024);
Serial.printf(" getSketchMD5: %s\n", ESP.getSketchMD5().c_str());
Serial.print("Internal Temperature: ");
float temp = readInternalTemperature();
if (isnan(temp)) {
Serial.println("Error reading temperature");
} else {
Serial.print(temp);
Serial.println("°C");
}
}