This commit is contained in:
William Clark 2022-12-08 10:53:25 +00:00
parent 8b0db47e29
commit 145e259853
3 changed files with 71 additions and 0 deletions

34
static/data-updater.js Normal file
View File

@ -0,0 +1,34 @@
const vdd = document.getElementById('vdd');
const vref = document.getElementById('vref');
const vadj = document.getElementById('vadj');
const ts = document.getElementById('timestamp');
const table = document.getElementById('data');
let old_channel_count=0;
async function update () {
data = await fetch("/data").then((data)=>{return data.json()});
vdd.innerHTML = "V<sub>DD</sub>: " + parseFloat(data["ratio"]["pivdd"]);
vref.innerHTML = "V<sub>REF</sub>: " + parseFloat(data["ratio"]["vref"]);
vadj.innerHTML = "V<sub>ADJ</sub>: " + parseFloat(data["ratio"]["vadj"]);
ts.innerHTML = "Last updated: " + data["time"];
for (let i=0; i<old_channel_count; i++) {
table.deleteRow(-1);
}
old_channel_count =0;
data["channels"].forEach(e => {
let unit = e["unit"];
let value = e["value"];
let channel = e["id"];
let row = table.insertRow(-1);
row.insertCell(0).innerText = channel;
row.insertCell(1).innerText = value;
row.insertCell(2).innerText = unit;
old_channel_count++;
});
}
update();
setInterval(update, 1000);

27
templates/index.tmpl Normal file
View File

@ -0,0 +1,27 @@
{{ define "page_index" }}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ .title }}</title>
</head>
<body>
<h1>TH7</h1>
<table id="data">
<tr>
<th>Channel</th>
<th>Value</th>
<th>Unit</th>
</tr>
</table>
<p id="vdd">V<sub>DD</sub>:</p>
<p id="vref">V<sub>REF</sub>:</p>
<p id="vadj">V<sub>ADJ</sub>:</p>
<p id="timestamp">Last updated:</p>
<script src="/assets/data-updater.js"></script>
</body>
</html>
{{ end }}

View File

@ -83,6 +83,12 @@ func (g *GinAdapter) DataHandler(c *gin.Context) {
}) })
} }
func (g *GinAdapter) IndexHandler(c *gin.Context) {
c.HTML(http.StatusOK, "page_index", gin.H{
"title": "TH7",
})
}
func NewGinAdapter(corePort ports.CorePort, port int) *GinAdapter { func NewGinAdapter(corePort ports.CorePort, port int) *GinAdapter {
var adapter GinAdapter var adapter GinAdapter
@ -97,6 +103,10 @@ func NewGinAdapter(corePort ports.CorePort, port int) *GinAdapter {
adapter.router.GET("/time", adapter.TimestampHandler) adapter.router.GET("/time", adapter.TimestampHandler)
adapter.router.GET("/data", adapter.DataHandler) adapter.router.GET("/data", adapter.DataHandler)
adapter.router.LoadHTMLGlob("./templates/*.tmpl")
adapter.router.Static("/assets", "./static")
adapter.router.GET("/", adapter.IndexHandler)
return &adapter return &adapter
} }