-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhub.h
76 lines (60 loc) · 1.94 KB
/
hub.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#pragma once
#include <Arduino.h>
#define GH_NO_MQTT
#include <GyverHub.h>
#include "data.h"
#include "palettes.h"
#include "tacho.h"
GyverHub hub("MyDevices", "TachoLED", "32");
static int _analog_f = VBAT_MAX;
static int getBat() {
int vbat = map(_analog_f, VBAT_MIN, VBAT_MAX, 0, 100);
return constrain(vbat, 0, 100);
}
void build() {
bool flag = 0;
hub.Title(F("Status"));
hub.BeginWidgets();
hub.WidgetSize(50);
hub.Gauge_(F("spd"), data.max_spd / (35 - data.max_spd), F("kmh"), F("Speed"), 0, 35);
hub.Gauge(getBat(), F("%"), F("Battery"));
hub.Title(F("Mode"));
hub.WidgetSize(100);
flag |= hub.Tabs(&data.mode, F("Palette,Radial"), F("Mode"));
if (data.mode == 0) {
hub.WidgetSize(50);
flag |= hub.Input(&data.pal_len, GH_UINT16, F("Length [leds]"));
flag |= hub.Select(&data.pal, FPSTR(paletteNames));
}
if (data.mode == 2) {
hub.WidgetSize(50);
flag |= hub.Input(&data.pal_len, GH_UINT16, F("Length [leds]"));
flag |= hub.Select(&data.pal, FPSTR(paletteNames));
}
hub.Title(F("Settings"));
hub.WidgetSize(50);
flag |= hub.Input(&data.led_amount, GH_UINT16, F("LED amount"));
flag |= hub.Input(&data.diam, GH_UINT16, F("Diameter [mm]"));
flag |= hub.Input(&data.ledm, GH_UINT8, F("leds/m"));
//flag |= hub.Input(&data.max_spd, GH_UINT8, F("Max speed [kmh]"));
hub.WidgetSize(100);
if (data.mode != 3) {
flag |= hub.Slider(&data.led_bri, GH_UINT8, F("Brightness"), 0, 255);
}
flag |= hub.Slider(&data.max_spd, GH_UINT8, F("Speed"), 0, 250);
if (flag) memory.update();
}
void hub_init() {
hub.onBuild(build);
hub.begin();
}
void hub_tick() {
hub.tick();
// filter analog read
static GHtimer vbat(500);
if (vbat) _analog_f += (analogRead(0) - _analog_f) / 4;
static GHtimer upd(1000);
if (upd) {
// hub.sendUpdate(F("spd"), String(tacho_kmh()));
}
}