Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
GyverLibs committed Nov 9, 2024
1 parent 2e5dbf9 commit 7dd0e7a
Show file tree
Hide file tree
Showing 7 changed files with 578 additions and 502 deletions.
34 changes: 31 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,14 @@ void setup() {
- Вебморда отслеживает статус устройства, при потере связи появится текст offline в заголовке страницы. После потери связи вебморда будет запрашивать информацию о виджетах, это очень удобно при разработке - например добавляем виджет, загружаем прошивку. За это время вебморда уже понимает что устройство оффлайн и при первом успешном подключении выводит актуальные виджеты.
- При изменении значений виджетов вебморда следит за доставкой пакета, при ошибке связи появится надпись **error*** у соответствующего виджета
### Настройки вебморды
Некоторые параметры вебморды можно менять из скетча. Настройки обновляются при перезагрузке или первой загрузке страницы
```cpp
sett.config.sliderTout = 100;
sett.config.requestTout = 2000;
sett.config.updateTout = 2500;
```

### Контейнеры
Виджеты можно объединять в контейнеры. Контейнер нужно начать и закончить, так как пакет данных собирается линейно в целях оптимизации скорости и памяти. Метод `beginКонтейнер` всегда вернёт true для красоты организации кода в блоке условия:
```cpp
Expand Down Expand Up @@ -573,9 +581,6 @@ void reload();
// установить заголовок страницы
void setTitle(const String& title);
// установить период обновлений (умолч. 2500мс), 0 чтобы отключить
void setUpdatePeriod(uint16_t prd);
// подключить базу данных
void attachDB(GyverDB* db);
Expand All @@ -590,6 +595,19 @@ void onUpdate(UpdateCallback cb);
// тикер, вызывать в родительском классе
void tick();
// настройки вебморды
Config config;
{
// таймаут отправки слайдера, мс. 0 чтобы отключить
uint16_t sliderTout = 100;
// таймаут ожидания ответа сервера, мс
uint16_t requestTout = 2000;
// период обновлений, мс. 0 чтобы отключить
uint16_t updateTout = 2500;
}
```

### Builder
Expand Down Expand Up @@ -640,6 +658,12 @@ void Label(size_t id, Text label, Text text, sets::Colors color);
void Label(Text label = "", Text text = Text(), uint32_t color = SETS_DEFAULT_COLOR);
void Label(Text label, Text text, sets::Colors color);

// лейбл с численным значением (выполняется быстрее, весит меньше)
void LabelNum(size_t id, Text label, T text, uint32_t color = SETS_DEFAULT_COLOR);
void LabelNum(size_t id, Text label, T text, sets::Colors color);
void LabelNum(Text label, T text, uint32_t color = SETS_DEFAULT_COLOR);
void LabelNum(Text label, T text, sets::Colors color);

// ================= LED =================
// светодиод (value 1 включен - зелёный, value 0 выключен - красный)
void LED(size_t id, Text label, bool value);
Expand Down Expand Up @@ -819,6 +843,10 @@ void update(size_t id, <любой численный тип> value);
- Виджету Confirm добавлена возможность подключить bool переменную для результата
- Добавлена возможность отправить всплывающее окно в Update
- v1.1.6
- Добавлен виджет LabelNum для чисел
- Добавлены настройки вебморды (таймаут соединения, слайдеров, апдейтов)
<a id="install"></a>
## Установка
- Библиотеку можно найти по названию **Settings** и установить через менеджер библиотек в:
Expand Down
5 changes: 5 additions & 0 deletions examples/test/test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ void setup() {
sett.onBuild(build);
sett.onUpdate(update);

// настройки вебморды
// sett.config.requestTout = 3000;
// sett.config.sliderTout = 500;
// sett.config.updateTout = 1000;

// ======== DATABASE ========
#ifdef ESP32
LittleFS.begin(true);
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Settings
version=1.1.5
version=1.1.6
author=AlexGyver <alex@alexgyver.ru>
maintainer=AlexGyver <alex@alexgyver.ru>
sentence=Simple UI webface builder for esp8266/esp32
Expand Down
31 changes: 23 additions & 8 deletions src/SettingsBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ class SettingsBase {
typedef std::function<void(Builder& b)> BuildCallback;
typedef std::function<void(Updater& upd)> UpdateCallback;

struct Config {
// таймаут отправки слайдера, мс. 0 чтобы отключить
uint16_t sliderTout = 100;

// таймаут ожидания ответа сервера, мс
uint16_t requestTout = 2000;

// период обновлений, мс. 0 чтобы отключить
uint16_t updateTout = 2500;
};

public:
#ifndef SETT_NO_DB
SettingsBase(const String& title = "", GyverDB* db = nullptr) : _title(title), _db(db) {
Expand All @@ -50,7 +61,7 @@ class SettingsBase {

// установить период обновлений (умолч. 2500мс), 0 чтобы отключить
void setUpdatePeriod(uint16_t prd) {
_updPeriod = prd;
config.updateTout = prd;
}

// подключить базу данных
Expand All @@ -62,7 +73,7 @@ class SettingsBase {

// использовать автоматические обновления из БД (при изменении записи новое значение отправится в браузер) (умолч. true)
void useAutoUpdates(bool use) {
_dbupdates = use;
_db_update = use;
#ifndef SETT_NO_DB
if (_db) _db->useUpdates(use);
#endif
Expand Down Expand Up @@ -94,6 +105,9 @@ class SettingsBase {
_reload = true;
}

// настройки вебморды
Config config;

protected:
// отправка для родительского класса
virtual void send(uint8_t* data, size_t len) {}
Expand Down Expand Up @@ -129,9 +143,9 @@ class SettingsBase {
case SH("set"):
#ifndef SETT_NO_DB
if (_db) {
if (_dbupdates) _db->useUpdates(false);
if (_db_update) _db->useUpdates(false);
_db->update(id, value);
if (_dbupdates) _db->useUpdates(true);
if (_db_update) _db->useUpdates(true);
}
#endif
if (_build_cb) {
Expand Down Expand Up @@ -170,7 +184,7 @@ class SettingsBase {
p.addUint(Code::rssi, constrain(2 * (WiFi.RSSI() + 100), 0, 100));
p.beginArr(Code::content);
#ifndef SETT_NO_DB
if (_db && _dbupdates) {
if (_db && _db_update) {
while (_db->updatesAvailable()) {
size_t id = _db->updateNext();
p.beginObj();
Expand Down Expand Up @@ -217,8 +231,7 @@ class SettingsBase {
#ifndef SETT_NO_DB
GyverDB* _db = nullptr;
#endif
uint16_t _updPeriod = 2500;
bool _dbupdates = true;
bool _db_update = true;
bool _rst = false;
bool _reload = false;

Expand Down Expand Up @@ -248,7 +261,9 @@ class SettingsBase {
p.reserve(SETS_RESERVE);
p.beginObj();
p.addCode(Code::type, Code::build);
p.addUint(Code::ping, _updPeriod);
p.addUint(Code::update_tout, config.updateTout);
p.addUint(Code::request_tout, config.requestTout);
p.addUint(Code::slider_tout, config.sliderTout);
p.addUint(Code::rssi, constrain(2 * (WiFi.RSSI() + 100), 0, 100));
if (_title.length()) p.addText(Code::title, _title);
if (_passh) p.addBool(Code::granted, granted);
Expand Down
18 changes: 18 additions & 0 deletions src/core/builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,24 @@ class Builder {
Label(_NO_ID, label, text, (uint32_t)color);
}

// лейбл с численным значением (выполняется быстрее, весит меньше)
template <typename T>
void LabelNum(size_t id, Text label, T text, uint32_t color = SETS_DEFAULT_COLOR) {
_widget(Code::label, id, label, &text, color);
}
template <typename T>
void LabelNum(size_t id, Text label, T text, sets::Colors color) {
LabelNum(id, label, text, (uint32_t)color);
}
template <typename T>
void LabelNum(Text label, T text, uint32_t color = SETS_DEFAULT_COLOR) {
LabelNum(_NO_ID, label, text, color);
}
template <typename T>
void LabelNum(Text label, T text, sets::Colors color) {
LabelNum(_NO_ID, label, text, (uint32_t)color);
}

// ================= LED =================
// светодиод с цветом на выбор
void LED(size_t id, Text label, bool value, uint32_t colorOff, uint32_t colorOn) {
Expand Down
4 changes: 3 additions & 1 deletion src/core/codes.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ enum class Code : uint8_t {
build,
reload,
update,
ping,
update_tout,
slider_tout,
request_tout,
granted,
fs,
error,
Expand Down
Loading

0 comments on commit 7dd0e7a

Please sign in to comment.