Skip to content

Commit 3394d0b

Browse files
committed
upd
1 parent d33f226 commit 3394d0b

File tree

8 files changed

+512
-450
lines changed

8 files changed

+512
-450
lines changed

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.8
2+
version=1.0.9
33
author=AlexGyver <[email protected]>
44
maintainer=AlexGyver <[email protected]>
55
sentence=Simple UI webface builder for esp8266/esp32

src/SettingsBase.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ class SettingsBase {
137137
Updater upd(p);
138138
p.beginObj();
139139
p.addCode(Code::type, Code::update);
140+
p.addUint(Code::rssi, constrain(2 * (WiFi.RSSI() + 100), 0, 100));
140141
p.beginArr(Code::content);
141142
if (_db && _dbupdates) {
142143
while (_db->updatesAvailable()) {
@@ -214,6 +215,7 @@ class SettingsBase {
214215
p.beginObj();
215216
p.addCode(Code::type, Code::build);
216217
p.addUint(Code::ping, _updPeriod);
218+
p.addUint(Code::rssi, constrain(2 * (WiFi.RSSI() + 100), 0, 100));
217219
if (_title.length()) p.addText(Code::title, _title);
218220
if (_passh) p.addBool(Code::granted, granted);
219221
#ifdef ATOMIC_FS_UPDATE

src/core/codes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ enum class Code : uint8_t {
2121
gzip,
2222
used,
2323
total,
24+
rssi,
2425

2526
label,
2627
title,

src/web/settings.h

Lines changed: 458 additions & 434 deletions
Large diffs are not rendered by default.

web/src/script/codes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const codes = [
1616
'gzip',
1717
'used',
1818
'total',
19+
'rssi',
1920

2021
'label',
2122
'title',

web/src/script/settings.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import decodeBson from './bson';
66
import { codes } from './codes';
77
import unMap from './unmap';
88
import { AsyncConfirm, AsyncPrompt } from './ui/dialog';
9+
import { changeRSSI, makeRSSI } from './ui/rssi';
910

1011
const timeout = 2000;
1112
const anim_s = '.11s';
@@ -29,6 +30,7 @@ export default class Settings {
2930
transOut = null;
3031
authF = false;
3132
granted = false;
33+
firstBuild = true;
3234
auth = 0;
3335
ping_prd = 2000;
3436

@@ -62,10 +64,10 @@ export default class Settings {
6264
]
6365
},
6466
{
65-
tag: 'sup',
66-
class: 'error_sup',
67-
text: 'Offline!',
68-
var: 'offline',
67+
tag: 'div',
68+
class: 'rssi',
69+
var: 'rssi',
70+
html: makeRSSI(),
6971
}
7072
]
7173
},
@@ -275,8 +277,7 @@ export default class Settings {
275277
const res = await this.send('load');
276278
this.parse(res);
277279
if (!res) {
278-
this.$offline.style.display = 'inline';
279-
this.offline = true;
280+
this.setOffline(true);
280281
this.restartPing();
281282
}
282283
}
@@ -334,19 +335,18 @@ export default class Settings {
334335
this.ping_int = setInterval(async () => {
335336
const res = await this.send(this.offline ? 'load' : 'ping');
336337
this.parse(res);
337-
if (res) {
338-
this.offline = false;
339-
} else {
340-
this.offline = true;
341-
this.authF = false;
342-
}
343-
this.$offline.style.display = this.offline ? 'inline' : 'none';
338+
if (!res) this.authF = false;
339+
this.setOffline(!res);
344340
}, this.ping_prd);
345341
}
346342
stopPing() {
347343
if (this.ping_int) clearInterval(this.ping_int);
348344
this.ping_int = null;
349345
}
346+
setOffline(offline) {
347+
this.offline = offline;
348+
if (offline) changeRSSI(this.$rssi, 0);
349+
}
350350

351351
parse(packet) {
352352
if (!packet) return;
@@ -365,13 +365,14 @@ export default class Settings {
365365
this.$auth.style.backgroundColor = this.granted ? 'var(--accent)' : 'var(--error)';
366366
this.$ota.style.display = this.granted ? 'inline-block' : 'none';
367367
this.$upload.style.display = this.granted ? 'inline-block' : 'none';
368-
if (!this.granted) popup('Unauthorized');
368+
if (!this.granted && this.firstBuild) popup('Unauthorized');
369369
} else {
370370
this.$auth.style.backgroundColor = 'var(--font_tint)';
371371
this.granted = true;
372372
}
373373
}
374374
if (packet.gzip) this.$upload_ota.accept = '.gz';
375+
this.firstBuild = false;
375376
break;
376377

377378
case 'update':
@@ -384,6 +385,7 @@ export default class Settings {
384385
this.renderFS(packet);
385386
break;
386387
}
388+
if (packet.rssi) changeRSSI(this.$rssi, packet.rssi);
387389
}
388390

389391
renderUI(json) {
@@ -514,7 +516,7 @@ export default class Settings {
514516
this.restartPing();
515517
}
516518
makeUrl(cmd, params = {}) {
517-
// const base_url = 'http://192.168.1.54';
519+
// const base_url = 'http://192.168.1.95';
518520
const base_url = window.location.origin;
519521

520522
if (this.auth) params.auth = this.auth.toString(16);

web/src/script/ui/rssi.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.rssi {
2+
display: inline-block;
3+
width: 21px;
4+
/* transform: rotate(45deg); */
5+
transform: translateY(-5px);
6+
}

web/src/script/ui/rssi.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import './rssi.css';
2+
3+
export function makeRSSI() {
4+
return `<svg viewBox="0 0 365.9 365.9" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
5+
<path name="3" d="M361 112a247 247 0 0 0-356 0 18 18 0 0 0 27 26 211 211 0 0 1 302 0 18 18 0 0 0 27-26z" style="fill:var(--font);fill-opacity:1"/>
6+
<path name="2" d="M183 107c-51 0-100 22-134 60a18 18 0 0 0 28 24 143 143 0 0 1 212 0 18 18 0 0 0 28-24c-34-38-83-60-134-60z" style="fill:var(--font);fill-opacity:1"/>
7+
<path name="1" d="M183 176c-36 0-69 17-90 46a18 18 0 0 0 30 22 74 74 0 0 1 120 0 18 18 0 0 0 30-22c-21-29-54-46-90-46z" style="fill:var(--font);fill-opacity:1"/>
8+
<circle name="0" cx="182.9" cy="286.7" r="41.5" style="fill:var(--font);fill-opacity:1"/>
9+
<path name="x" d="M273 127a19 19 0 0 0-27-27l-63 63-63-63a19 19 0 0 0-28 27l64 64-64 63a19 19 0 0 0 28 27l63-63 63 63a19 19 0 0 0 27-27l-63-63z" style="fill:var(--error);fill-opacity:0"/>
10+
</svg>`;
11+
}
12+
13+
export function changeRSSI(cont, rssi) {
14+
cont.title = rssi + '%';
15+
let svg = cont.firstElementChild;
16+
const min = 0.2, max = 0.7;
17+
for (let p of svg.children) {
18+
switch (p.getAttribute('name')) {
19+
case '3': p.style.fillOpacity = rssi > 75 ? max : min; break;
20+
case '2': p.style.fillOpacity = rssi > 50 ? max : min; break;
21+
case '1': p.style.fillOpacity = rssi > 25 ? max : min; break;
22+
case '0': p.style.fillOpacity = rssi > 0 ? max : min; break;
23+
case 'x': p.style.fillOpacity = rssi == 0 ? 1 : 0; break;
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)