Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several improvements: Support move semantic + remove vector in favour of std one + add support for std::string with -D DASH_USE_STL_STRING=1 #245

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 10 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ jobs:
core: esp32:esp32
board: esp32:esp32:esp32
index_url: https://espressif.github.io/arduino-esp32/package_esp32_index.json
- name: package_esp32_dev_index.json
core: esp32:esp32
board: esp32:esp32:esp32
index_url: https://espressif.github.io/arduino-esp32/package_esp32_dev_index.json
# Disabled due to an error coming from the package file:
# Error during install: Cannot install tool esp32:esp32-arduino-libs@idf-release_v5.3-a0f798cf: testing local archive integrity: testing archive checksum: archive hash differs from hash in index
# - name: package_esp32_dev_index.json
# core: esp32:esp32
# board: esp32:esp32:esp32
# index_url: https://espressif.github.io/arduino-esp32/package_esp32_dev_index.json
- name: package_esp8266com_index.json
core: esp8266:esp8266
board: esp8266:esp8266:huzzah
Expand All @@ -56,16 +58,16 @@ jobs:
run: arduino-cli core install --additional-urls "${{ matrix.index_url }}" ${{ matrix.core }}

- name: Install AsyncTCP
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/mathieucarbou/AsyncTCP#v3.2.10
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/ESP32Async/AsyncTCP#v3.3.2

- name: Install ESPAsyncTCP
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/mathieucarbou/esphome-ESPAsyncTCP#v2.0.0
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/ESP32Async/ESPAsyncTCP#v2.0.0

- name: Install ESPAsyncWebServer
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/mathieucarbou/ESPAsyncWebServer#v3.3.14
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/ESP32Async/ESPAsyncWebServer#v3.6.0

- name: Install ArduinoJson
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/bblanchon/ArduinoJson#v7.1.0
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/bblanchon/ArduinoJson#v7.3.0

- name: Build AccessPoint
run: arduino-cli compile --library . --warnings none -b ${{ matrix.board }} "examples/AccessPoint/AccessPoint.ino"
Expand Down Expand Up @@ -112,17 +114,6 @@ jobs:
- env: ci-arduino-3
board: esp32-c6-devkitc-1

- env: ci-arduino-310rc1
board: esp32dev
- env: ci-arduino-310rc1
board: esp32-s2-saola-1
- env: ci-arduino-310rc1
board: esp32-s3-devkitc-1
- env: ci-arduino-310rc1
board: esp32-c3-devkitc-02
- env: ci-arduino-310rc1
board: esp32-c6-devkitc-1

- env: ci-esp8266
board: huzzah
- env: ci-esp8266
Expand Down
10 changes: 5 additions & 5 deletions examples/Benchmark/Benchmark.ino
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Card slider(&dashboard, SLIDER_CARD, "Test Slider", "", 0, 255);
Chart bar(&dashboard, BAR_CHART, "Power Usage (kWh)");

// Bar Chart Data
String XAxis[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
dash::string XAxis[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
int YAxis[] = {0, 0, 0, 0, 0, 0, 0};


Expand Down Expand Up @@ -107,10 +107,10 @@ void loop() {
generic.update((int)random(0, 100));
temp.update((int)random(0, 100));
hum.update((int)random(0, 100));
status1.update("success");
status2.update("warning");
status3.update("danger");
status4.update("idle");
status1.update(DASH_STATUS_SUCCESS);
status2.update(DASH_STATUS_WARNING);
status3.update(DASH_STATUS_DANGER);
status4.update(DASH_STATUS_IDLE);
progress.update((int)random(0, 100));

dashboard.sendUpdates();
Expand Down
6 changes: 3 additions & 3 deletions library.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
{
"owner": "bblanchon",
"name": "ArduinoJson",
"version": "^7.1.0",
"version": "^7.3.0",
"platforms": ["espressif8266", "espressif32"]
},
{
"owner": "mathieucarbou",
"owner": "ESP32Async",
"name": "ESPAsyncWebServer",
"version": "^3.3.14",
"version": "^3.6.0",
"platforms": ["espressif8266", "espressif32"]
}
]
Expand Down
24 changes: 16 additions & 8 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ build_flags =
-Wall -Wextra
-D CONFIG_ARDUHAL_LOG_COLORS
-D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
; -D DASH_USE_LEGACY_CHART_STORAGE=1
; -D DASH_USE_STL_STRING=1
lib_deps =
bblanchon/ArduinoJson@^7.1.0
mathieucarbou/ESPAsyncWebServer@^3.3.14
bblanchon/ArduinoJson@^7.3.0
ESP32Async/AsyncTCP@^3.3.2
ESP32Async/ESPAsyncWebServer@^3.3.23
upload_protocol = esptool
monitor_speed = 115200
monitor_filters = esp32_exception_decoder, log2file
Expand All @@ -25,12 +28,17 @@ platform = [email protected]
board = esp32-s3-devkitc-1

[env:arduino-3]
platform = https://github.com/pioarduino/platform-espressif32/releases/download/53.03.10-rc1/platform-espressif32.zip
platform = https://github.com/pioarduino/platform-espressif32/releases/download/53.03.11/platform-espressif32.zip
board = esp32-s3-devkitc-1
; board = esp32dev

[env:esp8266]
platform = espressif8266
board = huzzah
lib_deps =
bblanchon/ArduinoJson@^7.3.0
ESP32Async/ESPAsyncTCP@^2.0.0
ESP32Async/ESPAsyncWebServer@^3.3.23

; CI

Expand All @@ -39,13 +47,13 @@ platform = [email protected]
board = ${sysenv.PIO_BOARD}

[env:ci-arduino-3]
platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.05/platform-espressif32.zip
board = ${sysenv.PIO_BOARD}

[env:ci-arduino-310rc1]
platform = https://github.com/pioarduino/platform-espressif32/releases/download/53.03.10-rc1/platform-espressif32.zip
platform = https://github.com/pioarduino/platform-espressif32/releases/download/53.03.11/platform-espressif32.zip
board = ${sysenv.PIO_BOARD}

[env:ci-esp8266]
platform = espressif8266
board = ${sysenv.PIO_BOARD}
lib_deps =
bblanchon/ArduinoJson@^7.3.0
ESP32Async/ESPAsyncTCP@^2.0.0
ESP32Async/ESPAsyncWebServer@^3.3.23
28 changes: 26 additions & 2 deletions src/Card.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "Card.h"

#include <utility>

/*
Constructor
*/
Expand Down Expand Up @@ -97,11 +99,11 @@ void Card::update(float value){
_value_f = value;
}

void Card::update(const String &value, const char* symbol){
void Card::update(const dash::string &value, const char* symbol){
update(value.c_str(), symbol);
}

void Card::update(const String &value){
void Card::update(const dash::string &value){
update(value.c_str());
}

Expand All @@ -128,6 +130,28 @@ void Card::update(const char* value){
_value_s = value;
}

void Card::update(dash::string&& value, const char* symbol){
if(_value_type == Card::STRING){
if(_value_s != value)
_changed = true;
}
if (strcmp(_symbol.c_str(), symbol) != 0) {
_changed = true;
}
_value_type = Card::STRING;
_symbol = symbol;
_value_s = std::move(value);
}

void Card::update(dash::string&& value){
if(_value_type == Card::STRING){
if(_value_s != value)
_changed = true;
}
_value_type = Card::STRING;
_value_s = std::move(value);
}

void Card::update(bool value, const char* symbol){
/* Clear String if it was used before */
if(_value_type == Card::STRING){
Expand Down
21 changes: 17 additions & 4 deletions src/Card.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@
#include "ESPDash.h"
#include "ArduinoJson.h"

#ifdef DASH_USE_STL_STRING
#include <string>
namespace dash {
using string = std::string;
}
#else
namespace dash {
using string = String;
}
#endif

struct CardNames {
int value;
const char* type;
Expand Down Expand Up @@ -41,7 +52,7 @@ class Card {
float _value_f;
int _value_i;
};
String _value_s;
dash::string _value_s;
union alignas(4) {
float _value_min_f;
int _value_min;
Expand All @@ -54,7 +65,7 @@ class Card {
float _value_step_f;
int _value_step;
};
String _symbol;
dash::string _symbol;
std::function<void(int value)> _callback = nullptr;
std::function<void(float value)> _callback_f = nullptr;

Expand All @@ -71,8 +82,10 @@ class Card {
void update(float value, const char* symbol);
void update(const char* value);
void update(const char* value, const char* symbol);
void update(const String &value);
void update(const String &value, const char* symbol);
void update(const dash::string &value);
void update(const dash::string &value, const char* symbol);
void update(dash::string &&value);
void update(dash::string &&value, const char* symbol);
~Card();

friend class ESPDash;
Expand Down
34 changes: 17 additions & 17 deletions src/Chart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ Chart::Chart(ESPDash *dashboard, const int type, const char* name){

#if DASH_USE_LEGACY_CHART_STORAGE == 1
void Chart::emptyXAxisVectors() {
if(!_x_axis_i.Empty())
_x_axis_i.Clear();
if(!_x_axis_f.Empty())
_x_axis_f.Clear();
if(!_x_axis_s.Empty())
_x_axis_s.Clear();
if(!_x_axis_i.empty())
_x_axis_i.clear();
if(!_x_axis_f.empty())
_x_axis_f.clear();
if(!_x_axis_s.empty())
_x_axis_s.clear();
}

void Chart::emptyYAxisVectors() {
if(!_y_axis_i.Empty())
_y_axis_i.Clear();
if(!_y_axis_f.Empty())
_y_axis_f.Clear();
if(!_y_axis_i.empty())
_y_axis_i.clear();
if(!_y_axis_f.empty())
_y_axis_f.clear();
}
#else
void Chart::clearXAxisPointers() {
Expand All @@ -51,7 +51,7 @@ void Chart::updateX(int arr_x[], size_t x_size){
#if DASH_USE_LEGACY_CHART_STORAGE == 1
emptyXAxisVectors();
for(int i=0; i < x_size; i++){
_x_axis_i.PushBack(arr_x[i]);
_x_axis_i.push_back(arr_x[i]);
}
#else
clearXAxisPointers();
Expand All @@ -66,7 +66,7 @@ void Chart::updateX(float arr_x[], size_t x_size){
#if DASH_USE_LEGACY_CHART_STORAGE == 1
emptyXAxisVectors();
for(int i=0; i < x_size; i++){
_x_axis_f.PushBack(arr_x[i]);
_x_axis_f.push_back(arr_x[i]);
}
#else
clearXAxisPointers();
Expand All @@ -76,12 +76,12 @@ void Chart::updateX(float arr_x[], size_t x_size){
_x_changed = true;
}

void Chart::updateX(String arr_x[], size_t x_size){
void Chart::updateX(dash::string arr_x[], size_t x_size){
_x_axis_type = GraphAxisType::STRING;
#if DASH_USE_LEGACY_CHART_STORAGE == 1
emptyXAxisVectors();
for(int i=0; i < x_size; i++){
_x_axis_s.PushBack(arr_x[i].c_str());
_x_axis_s.push_back(arr_x[i].c_str());
}
#else
clearXAxisPointers();
Expand All @@ -96,7 +96,7 @@ void Chart::updateX(const char* arr_x[], size_t x_size){
#if DASH_USE_LEGACY_CHART_STORAGE == 1
emptyXAxisVectors();
for(int i=0; i < x_size; i++){
_x_axis_s.PushBack(String(arr_x[i]));
_x_axis_s.push_back(arr_x[i]);
}
#else
clearXAxisPointers();
Expand All @@ -111,7 +111,7 @@ void Chart::updateY(int arr_y[], size_t y_size){
#if DASH_USE_LEGACY_CHART_STORAGE == 1
emptyYAxisVectors();
for(int i=0; i < y_size; i++){
_y_axis_i.PushBack(arr_y[i]);
_y_axis_i.push_back(arr_y[i]);
}
#else
clearYAxisPointers();
Expand All @@ -126,7 +126,7 @@ void Chart::updateY(float arr_y[], size_t y_size){
#if DASH_USE_LEGACY_CHART_STORAGE == 1
emptyYAxisVectors();
for(int i=0; i < y_size; i++){
_y_axis_f.PushBack(arr_y[i]);
_y_axis_f.push_back(arr_y[i]);
}
#else
clearYAxisPointers();
Expand Down
Loading
Loading