mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
increase max dallas sensors from 10 to 20 - #157
This commit is contained in:
@@ -718,7 +718,7 @@ void Console::load_system_commands(unsigned int context) {
|
|||||||
[](Shell & shell, const std::vector<std::string> & arguments) {
|
[](Shell & shell, const std::vector<std::string> & arguments) {
|
||||||
if (arguments.size() == 0) {
|
if (arguments.size() == 0) {
|
||||||
EMSESP::webSettingsService.read([&](WebSettings & settings) {
|
EMSESP::webSettingsService.read([&](WebSettings & settings) {
|
||||||
for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) {
|
for (uint8_t i = 0; i < MAX_NUM_SENSOR_NAMES; i++) {
|
||||||
if (!settings.sensor[i].id.isEmpty()) {
|
if (!settings.sensor[i].id.isEmpty()) {
|
||||||
shell.print(settings.sensor[i].id);
|
shell.print(settings.sensor[i].id);
|
||||||
shell.print(" : ");
|
shell.print(" : ");
|
||||||
|
|||||||
@@ -313,7 +313,7 @@ std::string DallasSensor::Sensor::to_string(const bool name) const {
|
|||||||
std::string str = id_string();
|
std::string str = id_string();
|
||||||
EMSESP::webSettingsService.read([&](WebSettings & settings) {
|
EMSESP::webSettingsService.read([&](WebSettings & settings) {
|
||||||
if (settings.dallas_format == Dallas_Format::NAME || name) {
|
if (settings.dallas_format == Dallas_Format::NAME || name) {
|
||||||
for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) {
|
for (uint8_t i = 0; i < MAX_NUM_SENSOR_NAMES; i++) {
|
||||||
if (strcmp(settings.sensor[i].id.c_str(), str.c_str()) == 0) {
|
if (strcmp(settings.sensor[i].id.c_str(), str.c_str()) == 0) {
|
||||||
str = settings.sensor[i].name.c_str();
|
str = settings.sensor[i].name.c_str();
|
||||||
}
|
}
|
||||||
@@ -328,7 +328,7 @@ int16_t DallasSensor::Sensor::offset() const {
|
|||||||
std::string str = id_string();
|
std::string str = id_string();
|
||||||
int16_t offset = 0; // default value
|
int16_t offset = 0; // default value
|
||||||
EMSESP::webSettingsService.read([&](WebSettings & settings) {
|
EMSESP::webSettingsService.read([&](WebSettings & settings) {
|
||||||
for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) {
|
for (uint8_t i = 0; i < MAX_NUM_SENSOR_NAMES; i++) {
|
||||||
if (strcmp(settings.sensor[i].id.c_str(), str.c_str()) == 0) {
|
if (strcmp(settings.sensor[i].id.c_str(), str.c_str()) == 0) {
|
||||||
offset = settings.sensor[i].offset;
|
offset = settings.sensor[i].offset;
|
||||||
}
|
}
|
||||||
@@ -376,7 +376,7 @@ bool DallasSensor::update(const char * idstr, const char * name, int16_t offset)
|
|||||||
EMSESP::webSettingsService.update(
|
EMSESP::webSettingsService.update(
|
||||||
[&](WebSettings & settings) {
|
[&](WebSettings & settings) {
|
||||||
// check for new name of stored id
|
// check for new name of stored id
|
||||||
for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) {
|
for (uint8_t i = 0; i < MAX_NUM_SENSOR_NAMES; i++) {
|
||||||
if (strcmp(id, settings.sensor[i].id.c_str()) == 0) {
|
if (strcmp(id, settings.sensor[i].id.c_str()) == 0) {
|
||||||
if (strlen(name) == 0 && offset == 0) { // delete entry if name and offset is empty
|
if (strlen(name) == 0 && offset == 0) { // delete entry if name and offset is empty
|
||||||
LOG_INFO(F("Deleting entry for sensor %s"), id);
|
LOG_INFO(F("Deleting entry for sensor %s"), id);
|
||||||
@@ -397,7 +397,7 @@ bool DallasSensor::update(const char * idstr, const char * name, int16_t offset)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check for free place
|
// check for free place
|
||||||
for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) {
|
for (uint8_t i = 0; i < MAX_NUM_SENSOR_NAMES; i++) {
|
||||||
if (settings.sensor[i].id.isEmpty()) {
|
if (settings.sensor[i].id.isEmpty()) {
|
||||||
settings.sensor[i].id = id;
|
settings.sensor[i].id = id;
|
||||||
settings.sensor[i].name = (strlen(name) == 0) ? id : name;
|
settings.sensor[i].name = (strlen(name) == 0) ? id : name;
|
||||||
@@ -410,7 +410,7 @@ bool DallasSensor::update(const char * idstr, const char * name, int16_t offset)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check if there is a unused id and overwrite it
|
// check if there is a unused id and overwrite it
|
||||||
for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) {
|
for (uint8_t i = 0; i < MAX_NUM_SENSOR_NAMES; i++) {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (const auto & sensor : sensors_) {
|
for (const auto & sensor : sensors_) {
|
||||||
if (strcmp(sensor.id_string().c_str(), settings.sensor[i].id.c_str()) == 0) {
|
if (strcmp(sensor.id_string().c_str(), settings.sensor[i].id.c_str()) == 0) {
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ void WebSettings::read(WebSettings & settings, JsonObject & root) {
|
|||||||
root["weblog_buffer"] = settings.weblog_buffer;
|
root["weblog_buffer"] = settings.weblog_buffer;
|
||||||
root["weblog_compact"] = settings.weblog_compact;
|
root["weblog_compact"] = settings.weblog_compact;
|
||||||
|
|
||||||
for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) {
|
for (uint8_t i = 0; i < MAX_NUM_SENSOR_NAMES; i++) {
|
||||||
char buf[20];
|
char buf[20];
|
||||||
snprintf(buf, sizeof(buf), "sensor_id%d", i);
|
snprintf(buf, sizeof(buf), "sensor_id%d", i);
|
||||||
root[buf] = settings.sensor[i].id;
|
root[buf] = settings.sensor[i].id;
|
||||||
@@ -205,7 +205,7 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings)
|
|||||||
settings.weblog_buffer = root["weblog_buffer"] | EMSESP_DEFAULT_WEBLOG_BUFFER;
|
settings.weblog_buffer = root["weblog_buffer"] | EMSESP_DEFAULT_WEBLOG_BUFFER;
|
||||||
settings.weblog_compact = root["weblog_compact"] | EMSESP_DEFAULT_WEBLOG_COMPACT;
|
settings.weblog_compact = root["weblog_compact"] | EMSESP_DEFAULT_WEBLOG_COMPACT;
|
||||||
|
|
||||||
for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) {
|
for (uint8_t i = 0; i < MAX_NUM_SENSOR_NAMES; i++) {
|
||||||
char buf[20];
|
char buf[20];
|
||||||
snprintf(buf, sizeof(buf), "sensor_id%d", i);
|
snprintf(buf, sizeof(buf), "sensor_id%d", i);
|
||||||
settings.sensor[i].id = root[buf] | EMSESP_DEFAULT_SENSOR_NAME;
|
settings.sensor[i].id = root[buf] | EMSESP_DEFAULT_SENSOR_NAME;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
#define EMSESP_SETTINGS_SERVICE_PATH "/rest/emsespSettings"
|
#define EMSESP_SETTINGS_SERVICE_PATH "/rest/emsespSettings"
|
||||||
#define EMSESP_BOARD_PROFILE_SERVICE_PATH "/rest/boardProfile"
|
#define EMSESP_BOARD_PROFILE_SERVICE_PATH "/rest/boardProfile"
|
||||||
|
|
||||||
#define NUM_SENSOR_NAMES 10
|
#define MAX_NUM_SENSOR_NAMES 20
|
||||||
|
|
||||||
namespace emsesp {
|
namespace emsesp {
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ class WebSettings {
|
|||||||
String id;
|
String id;
|
||||||
String name;
|
String name;
|
||||||
int16_t offset;
|
int16_t offset;
|
||||||
} sensor[NUM_SENSOR_NAMES];
|
} sensor[MAX_NUM_SENSOR_NAMES];
|
||||||
|
|
||||||
static void read(WebSettings & settings, JsonObject & root);
|
static void read(WebSettings & settings, JsonObject & root);
|
||||||
static StateUpdateResult update(JsonObject & root, WebSettings & settings);
|
static StateUpdateResult update(JsonObject & root, WebSettings & settings);
|
||||||
|
|||||||
Reference in New Issue
Block a user