mirror of
https://github.com/DigitalDevices/octonet.git
synced 2023-10-10 13:36:52 +02:00
add fancontrol for MaxSX8 and other temp devices
This commit is contained in:
parent
dbb3354015
commit
ca2e8601c9
87
octoserve/var/monitor/fancontrol.lua
Executable file → Normal file
87
octoserve/var/monitor/fancontrol.lua
Executable file → Normal file
@ -9,12 +9,34 @@ local LogFile = "/tmp/Temperatur.log"
|
|||||||
local HighTemp = 50
|
local HighTemp = 50
|
||||||
local LowTemp = 45
|
local LowTemp = 45
|
||||||
|
|
||||||
|
function ReadAttribute(attribute)
|
||||||
|
local value = 0
|
||||||
|
local ddbridge = io.open(devicepath.."/"..attribute,"r");
|
||||||
|
if ddbridge then
|
||||||
|
value = ddbridge:read("*l")
|
||||||
|
ddbridge:close()
|
||||||
|
end
|
||||||
|
return value
|
||||||
|
end
|
||||||
|
|
||||||
function ReadTemp(sensor)
|
function ReadTemp(sensor)
|
||||||
local temp = 0
|
local temp = 0
|
||||||
local file = io.open(devicepath.."/temp"..sensor)
|
local file;
|
||||||
|
|
||||||
|
if sensor > 3 then
|
||||||
|
sensor = sensor - 4
|
||||||
|
if sensor == 0 then
|
||||||
|
file = io.open(devicepath.."/temp")
|
||||||
|
else
|
||||||
|
file = io.open(devicepath.."/templ"..sensor)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
file = io.open(devicepath.."/temp"..sensor)
|
||||||
|
end
|
||||||
|
|
||||||
if file then
|
if file then
|
||||||
temp = file:read()
|
temp = file:read()
|
||||||
if temp == "no sensor" then
|
if temp == "no sensor" then
|
||||||
temp = 0
|
temp = 0
|
||||||
else
|
else
|
||||||
temp = math.floor(tonumber(temp)/1000)
|
temp = math.floor(tonumber(temp)/1000)
|
||||||
@ -55,26 +77,23 @@ local fanstate = -1
|
|||||||
|
|
||||||
sleep(30)
|
sleep(30)
|
||||||
|
|
||||||
local ddbridge = io.open("/sys/class/ddbridge/ddbridge0/devid0","r");
|
local devid = ReadAttribute("devid0")
|
||||||
if ddbridge then
|
if devid == "0307dd01" then
|
||||||
local devid = ddbridge:read("*l")
|
fanstate = 1
|
||||||
ddbridge:close()
|
local devid1 = ReadAttribute("devid1")
|
||||||
if devid == "0307dd01" then
|
if devid1 == "0009dd01" or devid1 == "000add01" then
|
||||||
fanstate = 1
|
fanstate = -2
|
||||||
ddbridge = io.open("/sys/class/ddbridge/ddbridge0/fanspeed1","r");
|
else
|
||||||
if ddbridge then
|
local fs = tonumber(ReadAttribute("fanspeed1"))
|
||||||
local fs = tonumber(ddbridge:read("*l"))
|
if fs > 0 and fs < 17000 then
|
||||||
ddbridge:close()
|
fanstate = -2
|
||||||
if fs > 0 and fs < 17000 then
|
|
||||||
fanstate = -2
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for i = 0,4,1 do
|
for i = 0,8,1 do
|
||||||
temp = ReadTemp(i)
|
temp = ReadTemp(i)
|
||||||
if temp > 0 then
|
if temp > 0 then
|
||||||
Sensor[NumSensors] = i
|
Sensor[NumSensors] = i
|
||||||
NumSensors = NumSensors + 1
|
NumSensors = NumSensors + 1
|
||||||
end
|
end
|
||||||
@ -95,18 +114,18 @@ while true do
|
|||||||
temps = ""
|
temps = ""
|
||||||
for i = 0, NumSensors - 1, 1 do
|
for i = 0, NumSensors - 1, 1 do
|
||||||
temp = ReadTemp(Sensor[i])
|
temp = ReadTemp(Sensor[i])
|
||||||
|
|
||||||
if temp == 0 then
|
if temp == 0 then
|
||||||
print(" fanControl Error ")
|
print(" fanControl Error ")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if i == 0 then
|
if i == 0 then
|
||||||
temps = temp
|
temps = temp
|
||||||
else
|
else
|
||||||
temps = temps .. "," .. temp
|
temps = temps .. "," .. temp
|
||||||
end
|
end
|
||||||
|
|
||||||
if fanstate == 0 and temp >= HighTemp then
|
if fanstate == 0 and temp >= HighTemp then
|
||||||
SetFan(1)
|
SetFan(1)
|
||||||
fanstate = 1
|
fanstate = 1
|
||||||
@ -114,35 +133,35 @@ while true do
|
|||||||
SetFan(0)
|
SetFan(0)
|
||||||
fanstate = 0
|
fanstate = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
count = count - 1
|
count = count - 1
|
||||||
if count == 0 then
|
if count == 0 then
|
||||||
count = interval
|
count = interval
|
||||||
|
|
||||||
if #TempList < nValues then
|
if #TempList < nValues then
|
||||||
TempList[#TempList+1] = temps
|
TempList[#TempList+1] = temps
|
||||||
else
|
else
|
||||||
TempList[StartIndex] = temps
|
TempList[StartIndex] = temps
|
||||||
StartIndex = StartIndex + 1
|
StartIndex = StartIndex + 1
|
||||||
if StartIndex > nValues then StartIndex = 1 end
|
if StartIndex > nValues then StartIndex = 1 end
|
||||||
end
|
end
|
||||||
|
|
||||||
TmpLogFile = os.tmpname()
|
TmpLogFile = os.tmpname()
|
||||||
|
|
||||||
fh = io.open(TmpLogFile,"w")
|
fh = io.open(TmpLogFile,"w")
|
||||||
if fh then
|
if fh then
|
||||||
fh:write(NumSensors..","..interval..","..fanstate.."\n")
|
fh:write(NumSensors..","..interval..","..fanstate.."\n")
|
||||||
|
|
||||||
for i = StartIndex-1, 1, -1 do
|
for i = StartIndex-1, 1, -1 do
|
||||||
fh:write(TempList[i].."\n")
|
fh:write(TempList[i].."\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
for i = #TempList, StartIndex, -1 do
|
for i = #TempList, StartIndex, -1 do
|
||||||
fh:write(TempList[i].."\n")
|
fh:write(TempList[i].."\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
fh:close()
|
fh:close()
|
||||||
os.remove(LogFile)
|
os.remove(LogFile)
|
||||||
os.rename(TmpLogFile,LogFile)
|
os.rename(TmpLogFile,LogFile)
|
||||||
|
Loading…
Reference in New Issue
Block a user