mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 08:19:52 +03:00
analogsensor default name fix
This commit is contained in:
@@ -339,7 +339,7 @@ void AnalogSensor::loop() {
|
|||||||
|
|
||||||
// update analog information name and offset
|
// update analog information name and offset
|
||||||
// a type value of -1 is used to delete the sensor
|
// a type value of -1 is used to delete the sensor
|
||||||
bool AnalogSensor::update(uint8_t gpio, const std::string & name, double offset, double factor, uint8_t uom, int8_t type, bool deleted) {
|
bool AnalogSensor::update(uint8_t gpio, std::string & name, double offset, double factor, uint8_t uom, int8_t type, bool deleted) {
|
||||||
// first see if we can find the sensor in our customization list
|
// first see if we can find the sensor in our customization list
|
||||||
bool found_sensor = false;
|
bool found_sensor = false;
|
||||||
EMSESP::webCustomizationService.update([&](WebCustomization & settings) {
|
EMSESP::webCustomizationService.update([&](WebCustomization & settings) {
|
||||||
@@ -347,6 +347,11 @@ bool AnalogSensor::update(uint8_t gpio, const std::string & name, double offset,
|
|||||||
if (AnalogCustomization.type == AnalogType::COUNTER || AnalogCustomization.type >= AnalogType::DIGITAL_OUT) {
|
if (AnalogCustomization.type == AnalogType::COUNTER || AnalogCustomization.type >= AnalogType::DIGITAL_OUT) {
|
||||||
Command::erase_command(EMSdevice::DeviceType::ANALOGSENSOR, AnalogCustomization.name.c_str());
|
Command::erase_command(EMSdevice::DeviceType::ANALOGSENSOR, AnalogCustomization.name.c_str());
|
||||||
}
|
}
|
||||||
|
if (name.empty()) {
|
||||||
|
char n[20];
|
||||||
|
snprintf(n, sizeof(n), "%s_%02d", FL_(AnalogTypeName)[type], gpio);
|
||||||
|
name = n;
|
||||||
|
}
|
||||||
if (AnalogCustomization.gpio == gpio) {
|
if (AnalogCustomization.gpio == gpio) {
|
||||||
found_sensor = true; // found the record
|
found_sensor = true; // found the record
|
||||||
// see if it's marked for deletion
|
// see if it's marked for deletion
|
||||||
@@ -756,16 +761,6 @@ AnalogSensor::Sensor::Sensor(const uint8_t gpio, const std::string & name, const
|
|||||||
value_ = 0; // init value to 0 always
|
value_ = 0; // init value to 0 always
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns name of the analog sensor or creates one if its empty
|
|
||||||
std::string AnalogSensor::Sensor::name() const {
|
|
||||||
if (name_.empty()) {
|
|
||||||
char name[20];
|
|
||||||
snprintf(name, sizeof(name), "%s_%02d", FL_(AnalogTypeName)[type_], gpio_);
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
return name_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// set the dig_out/counter/DAC/PWM value, id is gpio-no
|
// set the dig_out/counter/DAC/PWM value, id is gpio-no
|
||||||
bool AnalogSensor::command_setvalue(const char * value, const int8_t gpio) {
|
bool AnalogSensor::command_setvalue(const char * value, const int8_t gpio) {
|
||||||
float val;
|
float val;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
namespace emsesp {
|
namespace emsesp {
|
||||||
|
|
||||||
// names, same order as AnalogType
|
// names, same order as AnalogType
|
||||||
MAKE_ENUM_FIXED(AnalogTypeName, "disabled", "dig_in", "counter", "adc", "timer", "rate", "pwm0", "pwm1", "pwm2")
|
MAKE_ENUM_FIXED(AnalogTypeName, "disabled", "dig_in", "counter", "adc", "timer", "rate", "dig_out", "pwm0", "pwm1", "pwm2")
|
||||||
|
|
||||||
class AnalogSensor {
|
class AnalogSensor {
|
||||||
public:
|
public:
|
||||||
@@ -41,7 +41,9 @@ class AnalogSensor {
|
|||||||
offset_ = offset;
|
offset_ = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string name() const;
|
std::string name() const {
|
||||||
|
return name_;
|
||||||
|
}
|
||||||
|
|
||||||
void set_name(const std::string & name) {
|
void set_name(const std::string & name) {
|
||||||
name_ = name;
|
name_ = name;
|
||||||
@@ -155,7 +157,7 @@ class AnalogSensor {
|
|||||||
return sensors_.size();
|
return sensors_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool update(uint8_t gpio, const std::string & name, double offset, double factor, uint8_t uom, int8_t type, bool deleted = false);
|
bool update(uint8_t gpio, std::string & name, double offset, double factor, uint8_t uom, int8_t type, bool deleted = false);
|
||||||
bool get_value_info(JsonObject output, const char * cmd, const int8_t id = -1);
|
bool get_value_info(JsonObject output, const char * cmd, const int8_t id = -1);
|
||||||
void store_counters();
|
void store_counters();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user