Skip to content

Commit f82ed61

Browse files
committed
upd
1 parent 2d9f3b5 commit f82ed61

File tree

7 files changed

+575
-452
lines changed

7 files changed

+575
-452
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// простой пример настройки подключения к WiFi на базе DBConnector
2+
// если ssid pass не задан - откроется AP
3+
// если задан - попытаемся подключиться, по выходе таймаута запустим AP
4+
5+
#include <Arduino.h>
6+
#include <GyverDBFile.h>
7+
#include <LittleFS.h>
8+
GyverDBFile db(&LittleFS, "/data.db");
9+
10+
#include <SettingsESP.h>
11+
SettingsESP sett("WiFi config", &db);
12+
13+
DB_KEYS(
14+
kk,
15+
DB_KEY(wifi_ssid),
16+
DB_KEY(wifi_pass),
17+
DB_KEY(apply));
18+
19+
#include <DBConnector.h>
20+
DBConnector wifi(&db, kk::wifi_ssid, kk::wifi_pass);
21+
22+
void build(sets::Builder& b) {
23+
{
24+
sets::Group g(b, "WiFi");
25+
b.Input(kk::wifi_ssid, "SSID");
26+
b.Pass(kk::wifi_pass, "Password", "***");
27+
28+
if (b.Button(kk::apply, "Connect")) {
29+
db.update();
30+
wifi.connect();
31+
}
32+
}
33+
}
34+
35+
void setup() {
36+
Serial.begin(115200);
37+
Serial.println();
38+
39+
// базу данных запускаем до подключения к точке
40+
#ifdef ESP32
41+
LittleFS.begin(true);
42+
#else
43+
LittleFS.begin();
44+
#endif
45+
db.begin();
46+
47+
// подключение и реакция на подключение или ошибку
48+
wifi.onConnect([]() {
49+
Serial.print("Connected! ");
50+
Serial.println(WiFi.localIP());
51+
});
52+
wifi.onError([]() {
53+
Serial.print("Error! start AP ");
54+
Serial.println(WiFi.softAPIP());
55+
});
56+
wifi.connect();
57+
58+
// запускаем сервер после connect, иначе DNS не подхватится
59+
sett.begin();
60+
sett.onBuild(build);
61+
}
62+
63+
void loop() {
64+
sett.tick();
65+
wifi.tick();
66+
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Settings
2-
version=1.0.5
2+
version=1.0.7
33
author=AlexGyver <[email protected]>
44
maintainer=AlexGyver <[email protected]>
55
sentence=Simple UI webface builder for esp8266/esp32

src/web/settings.h

Lines changed: 422 additions & 414 deletions
Large diffs are not rendered by default.

web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "settings",
3-
"version": "1.0.6",
3+
"version": "1.0.7",
44
"main": "index.js",
55
"scripts": {
66
"build": "webpack --config ./webpack.single.js & webpack --config ./webpack.index.js",

web/src/index.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@import 'style/main.css';
22
@import 'style/widget.css';
33
@import 'style/icons.css';
4-
@import 'style/fs.css';
4+
@import 'style/menu.css';
55
@import 'style/theme.css';
66
@import 'style/animations.css';

web/src/script/settings.js

Lines changed: 72 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -95,32 +95,41 @@ export default class Settings {
9595
children: [
9696
{
9797
tag: 'div',
98-
class: 'fs_icons',
98+
class: 'menu_icons',
9999
children: [
100100
{
101101
tag: 'div',
102-
class: 'icon moon',
103-
title: 'Dark mode',
104-
events: {
105-
click: () => {
106-
document.body.classList.toggle('theme_dark');
107-
localStorage.setItem('dark', document.body.classList.contains('theme_dark') | 0);
108-
},
102+
class: 'menu_icon',
103+
child: {
104+
tag: 'div',
105+
class: 'icon moon',
106+
title: 'Dark mode',
107+
events: {
108+
click: () => {
109+
document.body.classList.toggle('theme_dark');
110+
localStorage.setItem('dark', document.body.classList.contains('theme_dark') | 0);
111+
},
112+
}
109113
}
110114
},
111115
{
116+
112117
tag: 'div',
113-
class: 'icon key',
114-
title: 'Auth',
115-
var: 'auth',
116-
events: {
117-
click: async () => {
118-
let res = await AsyncPrompt('Password', '');
119-
if (res !== null) {
120-
localStorage.setItem('auth', hash(res));
121-
window.location.reload();
122-
}
123-
},
118+
class: 'menu_icon',
119+
child: {
120+
tag: 'div',
121+
class: 'icon key',
122+
title: 'Auth',
123+
var: 'auth',
124+
events: {
125+
click: async () => {
126+
let res = await AsyncPrompt('Password', '');
127+
if (res !== null) {
128+
localStorage.setItem('auth', hash(res));
129+
window.location.reload();
130+
}
131+
},
132+
}
124133
}
125134
},
126135
{
@@ -130,16 +139,23 @@ export default class Settings {
130139
style: 'display: none',
131140
accept: '.bin',
132141
events: {
133-
change: () => this.uploadOta(),
142+
change: () => this.uploadOta(this.$upload_ota.files[0]),
134143
}
135144
},
136145
{
137146
tag: 'div',
138-
class: 'icon cloud',
139-
title: 'OTA',
140-
var: 'ota',
147+
class: 'menu_icon drop_area',
141148
events: {
142-
click: () => this.$upload_ota.click(),
149+
drop: (e) => this.uploadOta(e.dataTransfer.files[0]),
150+
},
151+
child: {
152+
tag: 'div',
153+
class: 'icon cloud',
154+
title: 'OTA',
155+
var: 'ota',
156+
events: {
157+
click: () => this.$upload_ota.click(),
158+
}
143159
}
144160
},
145161
{
@@ -148,16 +164,23 @@ export default class Settings {
148164
var: 'upload_file',
149165
style: 'display: none',
150166
events: {
151-
change: () => this.uploadFile(),
167+
change: () => this.uploadFile(this.$upload_file.files[0]),
152168
}
153169
},
154170
{
155171
tag: 'div',
156-
class: 'icon upload',
157-
title: 'Upload',
158-
var: 'upload',
172+
class: 'menu_icon drop_area',
159173
events: {
160-
click: () => this.$upload_file.click(),
174+
drop: (e) => this.uploadFile(e.dataTransfer.files[0]),
175+
},
176+
child: {
177+
tag: 'div',
178+
class: 'icon upload',
179+
title: 'Upload',
180+
var: 'upload',
181+
events: {
182+
click: () => this.$upload_file.click(),
183+
}
161184
}
162185
},
163186
]
@@ -214,6 +237,23 @@ export default class Settings {
214237
this.back();
215238
}
216239

240+
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(ev => {
241+
document.body.addEventListener(ev, (e) => {
242+
e.preventDefault();
243+
e.stopPropagation();
244+
}, false);
245+
});
246+
['dragenter', 'dragover'].forEach(e => {
247+
document.body.addEventListener(e, function () {
248+
document.querySelectorAll('.drop_area').forEach((el) => el.classList.add('active'));
249+
}, false);
250+
});
251+
['dragleave', 'drop'].forEach(e => {
252+
document.body.addEventListener(e, function () {
253+
document.querySelectorAll('.drop_area').forEach((el) => el.classList.remove('active'));
254+
}, false);
255+
});
256+
217257
if (localStorage.hasOwnProperty('dark')) {
218258
if (Number(localStorage.getItem('dark'))) {
219259
document.body.classList.add('theme_dark');
@@ -433,8 +473,7 @@ export default class Settings {
433473
popup(e);
434474
}
435475
}
436-
async uploadFile() {
437-
let file = this.$upload_file.files[0];
476+
async uploadFile(file) {
438477
this.$upload_file.value = "";
439478
let path = await AsyncPrompt("Upload", '/' + file.name);
440479
if (!path) return;
@@ -452,12 +491,12 @@ export default class Settings {
452491
if (ok) this.parse(await this.send('fs'));
453492
this.restartPing();
454493
}
455-
async uploadOta() {
494+
async uploadOta(file) {
495+
if (!file.name.endsWith(this.$upload_ota.accept)) return;
456496
if (!await AsyncConfirm("Update firmware?")) return;
457497
this.stopPing();
458498
this.offline = true;
459499

460-
let file = this.$upload_ota.files[0];
461500
this.$upload_ota.value = "";
462501

463502
let data = new FormData();

web/src/style/fs.css renamed to web/src/style/menu.css

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1-
.fs_icons {
1+
.menu_icons {
22
display: flex;
33
justify-content: space-evenly;
4-
padding: 15px 10px;
4+
padding: 10px;
5+
}
6+
7+
.menu_icon {
8+
padding: 8px;
9+
border: 2px dashed #0000;
10+
border-radius: 5px;
11+
}
12+
13+
.drop_area.active {
14+
border-color: var(--accent);
515
}
616

717
.fs_error {

0 commit comments

Comments
 (0)