Skip to content

Commit

Permalink
increase max dallas sensors from 10 to 20 - #157
Browse files Browse the repository at this point in the history
  • Loading branch information
proddy committed Oct 14, 2021
1 parent c029cf7 commit 235f789
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ void Console::load_system_commands(unsigned int context) {
[](Shell & shell, const std::vector<std::string> & arguments) {
if (arguments.size() == 0) {
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()) {
shell.print(settings.sensor[i].id);
shell.print(" : ");
Expand Down
10 changes: 5 additions & 5 deletions src/dallassensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ std::string DallasSensor::Sensor::to_string(const bool name) const {
std::string str = id_string();
EMSESP::webSettingsService.read([&](WebSettings & settings) {
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) {
str = settings.sensor[i].name.c_str();
}
Expand All @@ -328,7 +328,7 @@ int16_t DallasSensor::Sensor::offset() const {
std::string str = id_string();
int16_t offset = 0; // default value
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) {
offset = settings.sensor[i].offset;
}
Expand Down Expand Up @@ -376,7 +376,7 @@ bool DallasSensor::update(const char * idstr, const char * name, int16_t offset)
EMSESP::webSettingsService.update(
[&](WebSettings & settings) {
// 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 (strlen(name) == 0 && offset == 0) { // delete entry if name and offset is empty
LOG_INFO(F("Deleting entry for sensor %s"), id);
Expand All @@ -397,7 +397,7 @@ bool DallasSensor::update(const char * idstr, const char * name, int16_t offset)
}

// 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()) {
settings.sensor[i].id = id;
settings.sensor[i].name = (strlen(name) == 0) ? id : name;
Expand All @@ -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
for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) {
for (uint8_t i = 0; i < MAX_NUM_SENSOR_NAMES; i++) {
bool found = false;
for (const auto & sensor : sensors_) {
if (strcmp(sensor.id_string().c_str(), settings.sensor[i].id.c_str()) == 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/web/WebSettingsService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void WebSettings::read(WebSettings & settings, JsonObject & root) {
root["weblog_buffer"] = settings.weblog_buffer;
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];
snprintf(buf, sizeof(buf), "sensor_id%d", i);
root[buf] = settings.sensor[i].id;
Expand Down Expand Up @@ -205,7 +205,7 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings)
settings.weblog_buffer = root["weblog_buffer"] | EMSESP_DEFAULT_WEBLOG_BUFFER;
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];
snprintf(buf, sizeof(buf), "sensor_id%d", i);
settings.sensor[i].id = root[buf] | EMSESP_DEFAULT_SENSOR_NAME;
Expand Down
4 changes: 2 additions & 2 deletions src/web/WebSettingsService.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#define EMSESP_SETTINGS_SERVICE_PATH "/rest/emsespSettings"
#define EMSESP_BOARD_PROFILE_SERVICE_PATH "/rest/boardProfile"

#define NUM_SENSOR_NAMES 10
#define MAX_NUM_SENSOR_NAMES 20

namespace emsesp {

Expand Down Expand Up @@ -71,7 +71,7 @@ class WebSettings {
String id;
String name;
int16_t offset;
} sensor[NUM_SENSOR_NAMES];
} sensor[MAX_NUM_SENSOR_NAMES];

static void read(WebSettings & settings, JsonObject & root);
static StateUpdateResult update(JsonObject & root, WebSettings & settings);
Expand Down

0 comments on commit 235f789

Please sign in to comment.