Initial commit

This commit is contained in:
2019-11-19 18:54:40 +01:00
commit 6477f7a30c
1536 changed files with 170775 additions and 0 deletions

26
public/css/app.css Normal file
View 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
View 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
View 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} &deg;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

File diff suppressed because one or more lines are too long