-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfangd
executable file
·43 lines (32 loc) · 995 Bytes
/
fangd
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
#!/usr/bin/env node
const {
interval,
interval_max,
curve,
targets
} = require(`${process.env.XDG_LOCAL_HOME}/etc/fangd.json`);
const { execSync } = require('child_process');
const { globSync } = require('glob');
const mean = arr => arr.reduce((memo, num) => memo + num, 0) / arr.length;
targets.forEach(target => {
const pwmPaths = globSync(target.pwm);
let temps = [];
let prev = null;
const update = () => {
let temp = Number(execSync(target.command));
temps.push(temp > 1000 ? temp / 1000 : temp);
temps = temps.slice(Math.max(0, temps.length - interval_max));
let avg = Math.round(mean(temps));
let item = curve.find(item => item.temp <= avg) || curve[curve.length - 1];
if (item !== prev) {
console.debug(`${target.name}: ${item.pwm}`);
prev = item;
}
// 40-fan-pwm-rw
pwmPaths.forEach(input => {
execSync(`echo ${item.pwm} > ${input}`);
});
setTimeout(update, interval * 1000);
};
update();
});