Skip to content

Commit

Permalink
Correctly generate component ids
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed Dec 11, 2023
1 parent 4547fd2 commit ee42a8c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 15 deletions.
6 changes: 1 addition & 5 deletions src/Card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
*/
Card::Card(ESPDash *dashboard, const int type, const char* name, const char* symbol, const int min, const int max){
_dashboard = dashboard;
#if defined(ESP8266)
_id = RANDOM_REG32;
#elif defined(ESP32)
_id = esp_random();
#endif
_id = dashboard->nextId();
_type = type;
_name = name;
_symbol = symbol;
Expand Down
6 changes: 1 addition & 5 deletions src/Chart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
*/
Chart::Chart(ESPDash *dashboard, const int type, const char* name){
_dashboard = dashboard;
#if defined(ESP8266)
_id = RANDOM_REG32;
#elif defined(ESP32)
_id = esp_random();
#endif
_id = dashboard->nextId();
_type = type;
_name = name;
_dashboard->add(this);
Expand Down
3 changes: 3 additions & 0 deletions src/ESPDash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,9 @@ void ESPDash::refreshStatistics() {
generateLayoutJSON(nullptr, true);
}

uint32_t ESPDash::nextId() {
return _idCounter++;
}

/*
Destructor
Expand Down
3 changes: 3 additions & 0 deletions src/ESPDash.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class ESPDash{
bool basic_auth = false;
char username[64];
char password[64];
uint32_t _idCounter = 0;

// Generate layout json
size_t generateLayoutJSON(AsyncWebSocketClient *client, bool changes_only = false);
Expand Down Expand Up @@ -118,6 +119,8 @@ class ESPDash{

void refreshStatistics();

uint32_t nextId();

~ESPDash();
};

Expand Down
6 changes: 1 addition & 5 deletions src/Statistic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

Statistic::Statistic(ESPDash *dashboard, const char *key, const char *value) {
_dashboard = dashboard;
#if defined(ESP8266)
_id = RANDOM_REG32;
#elif defined(ESP32)
_id = esp_random();
#endif
_id = dashboard->nextId();
// Safe copy
strncpy(_key, key, sizeof(_key));
strncpy(_value, value, sizeof(_value));
Expand Down

0 comments on commit ee42a8c

Please sign in to comment.