Глобальная переделка. тест сделан по длине импульса и заданной частоте шим, а не меандру
This commit is contained in:
@@ -26,6 +26,7 @@ Display::Display() : oled_(128, 32, &Wire, -1) {}
|
||||
bool Display::begin() {
|
||||
Wire.begin(GPIO_SDA, GPIO_SCL);
|
||||
Wire.setClock(400000); // keeps a full 128x32 framebuffer update near 15 ms
|
||||
Wire.setTimeOut(30); // a faulty/stretched I2C bus must not stall button polling for seconds
|
||||
// An absent optional OLED produces a large burst of ESP-IDF NACK messages.
|
||||
// Probe it once and keep the I2C driver quiet when no display is connected.
|
||||
esp_log_level_set("i2c.master", ESP_LOG_NONE);
|
||||
@@ -103,7 +104,7 @@ void Display::show(const char *a, const char *b, uint32_t progress,
|
||||
void Display::formatFrequency(float hz, char *out, size_t n) {
|
||||
float value = hz; const char *suffix = "Hz";
|
||||
if (hz >= 999950.0f) { value = hz / 1000000.0f; suffix = "M"; }
|
||||
else if (hz >= 1000.0f) { value = hz / 1000.0f; suffix = "k"; }
|
||||
else if (hz >= 999.5f) { value = hz / 1000.0f; suffix = "k"; }
|
||||
if (suffix[0] == 'M' && fabsf(value - roundf(value)) < 0.0005f)
|
||||
snprintf(out, n, "%.0f%s", value, suffix);
|
||||
else if (value >= 100.0f) snprintf(out, n, "%.1f%s", value, suffix);
|
||||
@@ -125,6 +126,30 @@ void Display::formatTestFrequency(uint32_t hz, char *out, size_t n) {
|
||||
snprintf(out, n, "%lu", hz);
|
||||
}
|
||||
|
||||
void Display::formatPwmFrequency(uint32_t hz, char *out, size_t n) {
|
||||
if (hz >= 1000000U && hz % 1000000U == 0U)
|
||||
snprintf(out, n, "%luMHz", hz / 1000000U);
|
||||
else if (hz >= 1000U && hz % 1000U == 0U)
|
||||
snprintf(out, n, "%lukHz", hz / 1000U);
|
||||
else if (hz >= 1000U)
|
||||
snprintf(out, n, "%.3gkHz", hz / 1000.0f);
|
||||
else
|
||||
snprintf(out, n, "%luHz", hz);
|
||||
}
|
||||
|
||||
void Display::formatPulse(uint32_t pulseNs, char *out, size_t n, bool measured) {
|
||||
if (pulseNs >= 1000U) {
|
||||
const float us = pulseNs / 1000.0f;
|
||||
if (measured) snprintf(out, n, "%.2fu", us);
|
||||
else if (pulseNs % 1000U == 0U) snprintf(out, n, "%luus", pulseNs / 1000U);
|
||||
else snprintf(out, n, "%.2fus", us);
|
||||
} else if (measured) {
|
||||
snprintf(out, n, "%.3fu", pulseNs / 1000.0f);
|
||||
} else {
|
||||
snprintf(out, n, "%luns", pulseNs);
|
||||
}
|
||||
}
|
||||
|
||||
void Display::formatDuration(uint64_t us, char *out, size_t n) {
|
||||
const uint64_t totalSeconds = (us + 999999ULL) / 1000000ULL;
|
||||
const uint64_t minutes = totalSeconds / 60ULL;
|
||||
|
||||
Reference in New Issue
Block a user