mirror of
https://github.com/esphome/esphome.git
synced 2026-11-18 02:55:59 +00:00
Compare commits
3
Commits
dev
...
log-str-tables-2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2c2d366526 | ||
|
|
2bc7cdcc46 | ||
|
|
a7727df233 |
No files matched your search
@@ -1,20 +1,16 @@
|
||||
#include "adc_sensor.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/progmem.h"
|
||||
|
||||
namespace esphome::adc {
|
||||
|
||||
ESPHOME_LOG_TAG(TAG, "adc");
|
||||
|
||||
// Indexed by SamplingMode
|
||||
PROGMEM_STRING_TABLE(SamplingModeStrings, "average", "minimum", "maximum", "unknown");
|
||||
|
||||
const LogString *sampling_mode_to_str(SamplingMode mode) {
|
||||
switch (mode) {
|
||||
case SamplingMode::AVG:
|
||||
return LOG_STR("average");
|
||||
case SamplingMode::MIN:
|
||||
return LOG_STR("minimum");
|
||||
case SamplingMode::MAX:
|
||||
return LOG_STR("maximum");
|
||||
}
|
||||
return LOG_STR("unknown");
|
||||
return SamplingModeStrings::get_log_str(static_cast<uint8_t>(mode), SamplingModeStrings::LAST_INDEX);
|
||||
}
|
||||
|
||||
template<typename T> Aggregator<T>::Aggregator(SamplingMode mode) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "adc_sensor.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/progmem.h"
|
||||
#include <cinttypes>
|
||||
|
||||
namespace esphome::adc {
|
||||
@@ -10,20 +11,8 @@ ESPHOME_LOG_TAG(TAG, "adc");
|
||||
|
||||
adc_oneshot_unit_handle_t ADCSensor::shared_adc_handles[2] = {nullptr, nullptr};
|
||||
|
||||
const LogString *attenuation_to_str(adc_atten_t attenuation) {
|
||||
switch (attenuation) {
|
||||
case ADC_ATTEN_DB_0:
|
||||
return LOG_STR("0 dB");
|
||||
case ADC_ATTEN_DB_2_5:
|
||||
return LOG_STR("2.5 dB");
|
||||
case ADC_ATTEN_DB_6:
|
||||
return LOG_STR("6 dB");
|
||||
case ADC_ATTEN_DB_12_COMPAT:
|
||||
return LOG_STR("12 dB");
|
||||
default:
|
||||
return LOG_STR("Unknown Attenuation");
|
||||
}
|
||||
}
|
||||
// Indexed by adc_atten_t
|
||||
PROGMEM_STRING_TABLE(AttenuationStrings, "0 dB", "2.5 dB", "6 dB", "12 dB", "Unknown Attenuation");
|
||||
|
||||
const LogString *adc_unit_to_str(adc_unit_t unit) {
|
||||
switch (unit) {
|
||||
@@ -140,8 +129,10 @@ void ADCSensor::dump_config() {
|
||||
" Calibration: %s\n"
|
||||
" Overall Init: %s",
|
||||
this->channel_, LOG_STR_ARG(adc_unit_to_str(this->adc_unit_)),
|
||||
this->autorange_ ? "Auto" : LOG_STR_ARG(attenuation_to_str(this->attenuation_)), this->sample_count_,
|
||||
LOG_STR_ARG(sampling_mode_to_str(this->sampling_mode_)),
|
||||
this->autorange_ ? "Auto"
|
||||
: LOG_STR_ARG(AttenuationStrings::get_log_str(static_cast<uint8_t>(this->attenuation_),
|
||||
AttenuationStrings::LAST_INDEX)),
|
||||
this->sample_count_, LOG_STR_ARG(sampling_mode_to_str(this->sampling_mode_)),
|
||||
this->setup_flags_.handle_init_complete ? "OK" : "FAILED",
|
||||
this->setup_flags_.config_complete ? "OK" : "FAILED", calibration_status,
|
||||
this->setup_flags_.init_complete ? "OK" : "FAILED");
|
||||
|
||||
@@ -94,25 +94,12 @@ static bool answer_means_done(Operation operation, const char *line) {
|
||||
}
|
||||
}
|
||||
|
||||
// Indexed by Operation
|
||||
PROGMEM_STRING_TABLE(OperationStrings, "none", "stop", "start", "restart", "factory reset", "write", "save", "read");
|
||||
|
||||
static const LogString *operation_to_str(Operation operation) {
|
||||
switch (operation) {
|
||||
case Operation::OPERATION_STOP:
|
||||
return LOG_STR("stop");
|
||||
case Operation::OPERATION_START:
|
||||
return LOG_STR("start");
|
||||
case Operation::OPERATION_RESTART:
|
||||
return LOG_STR("restart");
|
||||
case Operation::OPERATION_FACTORY_RESET:
|
||||
return LOG_STR("factory reset");
|
||||
case Operation::OPERATION_WRITE:
|
||||
return LOG_STR("write");
|
||||
case Operation::OPERATION_SAVE:
|
||||
return LOG_STR("save");
|
||||
case Operation::OPERATION_READ:
|
||||
return LOG_STR("read");
|
||||
default:
|
||||
return LOG_STR("none");
|
||||
}
|
||||
return OperationStrings::get_log_str(static_cast<uint8_t>(operation),
|
||||
static_cast<uint8_t>(Operation::OPERATION_NONE));
|
||||
}
|
||||
|
||||
DFRobotSEN0609Component::DFRobotSEN0609Component(RunMode mode) : mode_(mode) {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "ens210.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/progmem.h"
|
||||
#include "esphome/core/hal.h"
|
||||
|
||||
namespace esphome::ens210 {
|
||||
@@ -45,20 +46,13 @@ static const uint8_t DATA7_WIDTH = 17;
|
||||
static const uint32_t DATA7_MASK = ((1UL << DATA7_WIDTH) - 1); // 0b 0 1111 1111 1111 1111
|
||||
static const uint32_t DATA7_MSB = (1UL << (DATA7_WIDTH - 1)); // 0b 1 0000 0000 0000 0000
|
||||
|
||||
// Indexed by ENS210Component::ErrorCode
|
||||
PROGMEM_STRING_TABLE(StatusStrings, "Status OK", "Invalid data", "CRC error",
|
||||
"I2C error - communication with ENS210 failed!", "Unknown");
|
||||
|
||||
// Converts a status to a human readable string
|
||||
static const LogString *ens210_status_to_human(int status) {
|
||||
switch (status) {
|
||||
case ENS210Component::ENS210_STATUS_I2C_ERROR:
|
||||
return LOG_STR("I2C error - communication with ENS210 failed!");
|
||||
case ENS210Component::ENS210_STATUS_CRC_ERROR:
|
||||
return LOG_STR("CRC error");
|
||||
case ENS210Component::ENS210_STATUS_INVALID:
|
||||
return LOG_STR("Invalid data");
|
||||
case ENS210Component::ENS210_STATUS_OK:
|
||||
return LOG_STR("Status OK");
|
||||
default:
|
||||
return LOG_STR("Unknown");
|
||||
}
|
||||
static __attribute__((noinline)) const LogString *ens210_status_to_human(int status) {
|
||||
return StatusStrings::get_log_str(static_cast<uint8_t>(status), StatusStrings::LAST_INDEX);
|
||||
}
|
||||
|
||||
// Compute the CRC-7 of 'value' (should only have 17 bits)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "mhz19.h"
|
||||
#include "esphome/core/application.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/progmem.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
|
||||
#include <cinttypes>
|
||||
@@ -19,17 +20,11 @@ static const uint8_t MHZ19_COMMAND_DETECTION_RANGE_0_5000PPM[] = {0xFF, 0x01, 0x
|
||||
static const uint8_t MHZ19_COMMAND_DETECTION_RANGE_0_10000PPM[] = {0xFF, 0x01, 0x99, 0x00, 0x00, 0x00, 0x27, 0x10};
|
||||
|
||||
#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_DEBUG
|
||||
// Indexed by MHZ19DetectionRange
|
||||
PROGMEM_STRING_TABLE(DetectionRangeStrings, "default", "0-2000 ppm", "0-5000 ppm", "0-10000 ppm");
|
||||
|
||||
static const LogString *detection_range_to_log_string(MHZ19DetectionRange range) {
|
||||
switch (range) {
|
||||
case MHZ19_DETECTION_RANGE_0_2000PPM:
|
||||
return LOG_STR("0-2000 ppm");
|
||||
case MHZ19_DETECTION_RANGE_0_5000PPM:
|
||||
return LOG_STR("0-5000 ppm");
|
||||
case MHZ19_DETECTION_RANGE_0_10000PPM:
|
||||
return LOG_STR("0-10000 ppm");
|
||||
default:
|
||||
return LOG_STR("default");
|
||||
}
|
||||
return DetectionRangeStrings::get_log_str(range, MHZ19_DETECTION_RANGE_DEFAULT);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "sensor_mlx90393.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/progmem.h"
|
||||
|
||||
namespace esphome::mlx90393 {
|
||||
|
||||
@@ -9,27 +10,12 @@ ESPHOME_LOG_TAG(TAG, "mlx90393");
|
||||
|
||||
static constexpr uint32_t VERIFY_SETTINGS_TIMEOUT_ID = 0;
|
||||
|
||||
// Indexed by MLX90393Setting
|
||||
PROGMEM_STRING_TABLE(SettingStrings, "gain", "resolution", "oversampling", "digital filtering",
|
||||
"temperature oversampling", "temperature compensation", "hallconf", "error", "unknown");
|
||||
|
||||
const LogString *settings_to_string(MLX90393Setting setting) {
|
||||
switch (setting) {
|
||||
case MLX90393_GAIN_SEL:
|
||||
return LOG_STR("gain");
|
||||
case MLX90393_RESOLUTION:
|
||||
return LOG_STR("resolution");
|
||||
case MLX90393_OVER_SAMPLING:
|
||||
return LOG_STR("oversampling");
|
||||
case MLX90393_DIGITAL_FILTERING:
|
||||
return LOG_STR("digital filtering");
|
||||
case MLX90393_TEMPERATURE_OVER_SAMPLING:
|
||||
return LOG_STR("temperature oversampling");
|
||||
case MLX90393_TEMPERATURE_COMPENSATION:
|
||||
return LOG_STR("temperature compensation");
|
||||
case MLX90393_HALLCONF:
|
||||
return LOG_STR("hallconf");
|
||||
case MLX90393_LAST:
|
||||
return LOG_STR("error");
|
||||
default:
|
||||
return LOG_STR("unknown");
|
||||
}
|
||||
return SettingStrings::get_log_str(static_cast<uint8_t>(setting), SettingStrings::LAST_INDEX);
|
||||
};
|
||||
|
||||
bool MLX90393Cls::transceive(const uint8_t *request, size_t request_size, uint8_t *response, size_t response_size) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "selec_meter_registers.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/progmem.h"
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cmath>
|
||||
@@ -18,18 +19,11 @@ static constexpr uint8_t EM2M_REGISTER_COUNT = 34; // 34 x 16-bit registers
|
||||
// Durable refusals an optional read tolerates before it is given up on
|
||||
static constexpr uint8_t MAX_OPTIONAL_READ_FAILURES = 5;
|
||||
|
||||
// Indexed by ReadState
|
||||
PROGMEM_STRING_TABLE(ReadStateStrings, "main block", "serial number", "DG sensing", "idle");
|
||||
|
||||
static const LogString *read_state_name(ReadState state) {
|
||||
switch (state) {
|
||||
case ReadState::READ_STATE_MAIN_BLOCK:
|
||||
return LOG_STR("main block");
|
||||
case ReadState::READ_STATE_SERIAL_NUMBER:
|
||||
return LOG_STR("serial number");
|
||||
case ReadState::READ_STATE_DG_SENSING:
|
||||
return LOG_STR("DG sensing");
|
||||
case ReadState::READ_STATE_IDLE:
|
||||
default:
|
||||
return LOG_STR("idle");
|
||||
}
|
||||
return ReadStateStrings::get_log_str(static_cast<uint8_t>(state), ReadStateStrings::LAST_INDEX);
|
||||
}
|
||||
|
||||
// FP32 at `reg` in the configured word order (MSRF high word first, LSRF low word first); NaN when
|
||||
|
||||
Reference in new issue
Block a user