Initial commit
This commit is contained in:
26
public/css/app.css
Normal file
26
public/css/app.css
Normal file
@@ -0,0 +1,26 @@
|
||||
*, *::before, *::after {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html, body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: "Roboto", sans-serif;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
input[type=range] {
|
||||
width: 100%;
|
||||
}
|
||||
15
public/index.html
Normal file
15
public/index.html
Normal file
@@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>Fan Control</title>
|
||||
<link rel="stylesheet" href="./css/app.css">
|
||||
<script defer src="./js/lib/axios.min.js"></script>
|
||||
<script defer src="./js/app.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
</body>
|
||||
</html>
|
||||
63
public/js/app.js
Normal file
63
public/js/app.js
Normal file
@@ -0,0 +1,63 @@
|
||||
document.addEventListener('DOMContentLoaded', async e => {
|
||||
const app = document.getElementById('app')
|
||||
|
||||
const headline = document.createElement('H1')
|
||||
headline.innerText = "Fan Control"
|
||||
|
||||
// const tempsElm = document.createElement('DIV')
|
||||
// tempsElm.className = 'temps'
|
||||
|
||||
const fansElm = document.createElement('DIV')
|
||||
fansElm.className = 'fans'
|
||||
|
||||
app.innerHTML = "";
|
||||
|
||||
// const tempRes = await axios.get('/api/v1/temp')
|
||||
// const temps = tempRes.data
|
||||
|
||||
// for (const temp of temps) {
|
||||
// const tempDiv = document.createElement('DIV')
|
||||
// tempDiv.innerHTML = `
|
||||
// <div><b>${temp.label}:</b> ${temp.temp} °C</div>
|
||||
// `
|
||||
// tempsElm.appendChild(tempDiv)
|
||||
// }
|
||||
|
||||
const fansRes = await axios.get('/api/v1/fan')
|
||||
const fans = fansRes.data
|
||||
|
||||
for (const fan of fans) {
|
||||
const fanPwmRes = await axios.get(`/api/v1/fan/${fan.id}/pwm`)
|
||||
const fanPwm = fanPwmRes.data.pwm
|
||||
const fanRpmRes = await axios.get(`/api/v1/fan/${fan.id}/rpm`)
|
||||
const fanRpm = fanRpmRes.data.rpm
|
||||
const fanDiv = document.createElement('DIV')
|
||||
fanDiv.className = 'fan'
|
||||
fanDiv.innerHTML = `
|
||||
<label for="fan_${fan.id}">${fan.name}</label>
|
||||
<div class="fan-values">
|
||||
<div class="fan-value">${Math.round(fanPwm / 255 * 100)}% (PWM: ${fanPwm})</div>
|
||||
<div class="fan-rpm">${fanRpm} rpm</div>
|
||||
</div>
|
||||
<input type="range" id="fan_${fan.id}" data-id="${fan.id}" min="0" max="255" value="${fanPwm}">
|
||||
`
|
||||
fanDiv.querySelector('input[type=range]').addEventListener('input', e => {
|
||||
const fanId = e.target.dataset.id
|
||||
const pwm = e.target.value
|
||||
axios.post(`/api/v1/fan/${fanId}/${pwm}`)
|
||||
.then(() => {
|
||||
e.target.closest('.fan').querySelector('.fan-value').innerText = `${Math.round(pwm / 255 * 100)}% (${pwm})`
|
||||
})
|
||||
.catch(e => console.error(e))
|
||||
})
|
||||
fansElm.appendChild(fanDiv)
|
||||
setInterval(async () => {
|
||||
const fanRpmRes = await axios.get(`/api/v1/fan/${fan.id}/rpm`)
|
||||
const fanRpm = fanRpmRes.data.rpm
|
||||
fanDiv.querySelector('.fan-rpm').innerText = `${fanRpm} rpm`
|
||||
}, 1000)
|
||||
}
|
||||
app.appendChild(headline)
|
||||
// app.appendChild(tempsElm)
|
||||
app.appendChild(fansElm)
|
||||
})
|
||||
9
public/js/lib/axios.min.js
vendored
Normal file
9
public/js/lib/axios.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user