Initial commit
This commit is contained in:
68
model/Fan.js
Normal file
68
model/Fan.js
Normal file
@@ -0,0 +1,68 @@
|
||||
const fs = require('fs')
|
||||
|
||||
module.exports = class Fan {
|
||||
|
||||
path = ''
|
||||
|
||||
constructor() {
|
||||
if (!this.getPath().length)
|
||||
throw 'PWM PATH NOT FOUND!'
|
||||
this.enableFans()
|
||||
}
|
||||
|
||||
getFans() {
|
||||
return [
|
||||
{ id: 2, name: 'CPU_FAN'},
|
||||
{ id: 3, name: 'EXT_FAN'},
|
||||
{ id: 7, name: 'AIO_PUMP'}
|
||||
]
|
||||
}
|
||||
|
||||
getPath() {
|
||||
if (this.path.length)
|
||||
return this.path
|
||||
const baseDir = `/sys/class/hwmon`
|
||||
const subDirs = fs.readdirSync(baseDir)
|
||||
for (const subDir of subDirs) {
|
||||
if (fs.existsSync(`${baseDir}/${subDir}/pwm1`)) {
|
||||
this.path = `${baseDir}/${subDir}`
|
||||
return this.path
|
||||
}
|
||||
}
|
||||
return this.path
|
||||
}
|
||||
|
||||
enableFans() {
|
||||
for (const fan of this.getFans()) {
|
||||
fs.writeFileSync(`${this.path}/pwm${fan.id}_enable`, 1)
|
||||
}
|
||||
}
|
||||
|
||||
getRpm(id) {
|
||||
const file = `${this.path}/fan${id}_input`
|
||||
if (!fs.existsSync(file))
|
||||
return false
|
||||
return fs.readFileSync(file, { encoding: 'utf8' }).trim() || false
|
||||
}
|
||||
|
||||
getPwm(id) {
|
||||
const file = `${this.path}/pwm${id}`
|
||||
if (!fs.existsSync(file))
|
||||
return false
|
||||
return fs.readFileSync(file, { encoding: 'utf8' }).trim() || false
|
||||
}
|
||||
|
||||
setPwm(id, pwm) {
|
||||
const file = `${this.path}/pwm${id}`
|
||||
if (!fs.existsSync(file) || pwm < 0 || pwm > 255)
|
||||
return false
|
||||
try {
|
||||
fs.writeFileSync(file, pwm)
|
||||
return true
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
23
model/Temp.js
Normal file
23
model/Temp.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const fs = require('fs')
|
||||
|
||||
module.exports = new class {
|
||||
|
||||
path = '/sys/class/hwmon/hwmon1'
|
||||
|
||||
getCores() {
|
||||
const labels = fs.readdirSync(this.path).filter(file => file.startsWith('temp') && file.endsWith('_label'))
|
||||
const temps = fs.readdirSync(this.path).filter(file => file.startsWith('temp') && file.endsWith('_input'))
|
||||
const cores = [];
|
||||
for (const labelFile of labels) {
|
||||
const id = labelFile.replace('temp', '').replace('_label', '')
|
||||
const label = fs.readFileSync(`${this.path}/${labelFile}`, { encoding: 'utf8' }).trim()
|
||||
const temp = fs.readFileSync(`${this.path}/temp${id}_input`, { encoding: 'utf8' })
|
||||
cores.push({
|
||||
label,
|
||||
temp: parseFloat(temp / 1000)
|
||||
})
|
||||
}
|
||||
return cores
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user