-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
148 lines (81 loc) · 3.23 KB
/
index.html
File metadata and controls
148 lines (81 loc) · 3.23 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Raspberry Pi hc05 Interface</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<script type="text/javascript" src="rpi_uart_comm.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css" />
</head>
<body>
<main class="m-3">
<section class="text-center">
<button id="btn_connect_uart" class="btn btn-primary">Start Connection</button>
<button id="btn_on_off" hidden data-state="0" class="btn btn-primary">Turn ON the LED</button>
</section>
<section class="font-monospace" style="font-size:0.8rem">
<ul class="list-group list-group-flush" id="data"></ul>
</section>
</main>
<script type="text/javascript">
const ol_data = document.getElementById("data");
const btn_connect_uart = document.getElementById("btn_connect_uart");
const btn_on_off = document.getElementById("btn_on_off");
let prev_li;
let rpi_uart_comm = new RPIUARTComm();
function set_ui(state) {
switch (state) {
case RPIUARTComm.state.stopped: {
btn_connect_uart.hidden = false;
btn_on_off.hidden = true;
}
break;
case RPIUARTComm.state.unavailable_or_error:
case RPIUARTComm.state.starting: {
btn_connect_uart.hidden = true;
btn_on_off.hidden = true;
}
break;
case RPIUARTComm.state.running: {
btn_connect_uart.hidden = true;
btn_on_off.hidden = false;
rpi_uart_comm.write_to_UART(/*query state*/50);
}
break;
default: break;
}
}
function render_log(msg) {
if (!msg) return;
if (msg == "1") {
btn_on_off.innerHTML = "Turn OFF the LED";
btn_on_off.dataset.state = "1";
msg = "LED is ON";
} else if (msg == "0") {
btn_on_off.innerHTML = "Turn ON the LED";
btn_on_off.dataset.state = "0";
msg = "LED is OFF";
}
const new_li = document.createElement("li");
new_li.classList.add("list-group-item", "text-wrap", "text-info", "fw-bold", "blink");
new_li.textContent = msg;
ol_data.prepend(new_li);
if (prev_li) {
prev_li.classList.remove("text-info", "fw-bold", "blink");
prev_li.classList.add("text-muted");
}
if (ol_data.childElementCount > 10) {
ol_data.removeChild(ol_data.lastChild);
}
prev_li = new_li;
}
document.addEventListener("DOMContentLoaded", (event) => {
document.addEventListener('hovendatareceived', (e) => render_log(e.detail.text));
document.addEventListener('hovenstate', (e) => set_ui(e.detail));
btn_connect_uart.addEventListener("click", () => rpi_uart_comm.connect_uart());
btn_on_off.addEventListener("click", (e) => { rpi_uart_comm.write_to_UART(e.currentTarget.dataset.state == '0' ? /*1*/49 : /*0*/48); });
});
</script>
</body>
</html>