🐶 Sync 2025-11-02 14:26:26

This commit is contained in:
actions-user
2025-11-02 14:26:26 +08:00
parent 64bcc56c2a
commit ac011db799
1557 changed files with 746465 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
--[[
LuCI - Lua Configuration Interface
Copyright 2023 jjm2473
]]--
module("luci.controller.admin.luci-fan", package.seeall)
function index()
require "luci.sys"
local appname = "luci-fan"
local defaultpage = nil
if luci.sys.call("/usr/libexec/fan-control get >/dev/null 2>&1") == 0 then
entry({"admin", "system", appname}, cbi("luci-fan"), _("Fan Control"), 60)
else
entry({"admin", "system", appname}).dependent = true
end
entry({"admin", "system", appname, "get_fan_info"}, call("get_fan_info"), nil).leaf = true
end
function get_fan_info(zone, trip)
require "luci.util"
local words
if zone and trip and string.match(zone, "^thermal_zone%d+$") and string.match(trip, "^%d+$") then
local fs = require "nixio.fs"
words = {
luci.util.trim(fs.readfile("/sys/class/thermal/"..zone.."/temp")),
luci.util.trim(fs.readfile("/sys/class/thermal/"..zone.."/trip_point_"..trip.."_temp"))
}
else
local sys = require "luci.sys"
words = luci.util.split(luci.util.trim(sys.exec("/usr/libexec/fan-control temp 2>/dev/null")), " ")
end
local zone_temp = tonumber(words[1]) / 1000; -- ˚C
local fan_on_temp = tonumber(words[2]) / 1000; -- ˚C
luci.http.status(200, "ok")
luci.http.prepare_content("application/json")
luci.http.write_json({zone_temp=zone_temp, fan_on_temp=fan_on_temp})
end

View File

@@ -0,0 +1,93 @@
--[[
LuCI - Lua Configuration Interface
Copyright 2023 jjm2473
]]--
local m, s, o
require "luci.util"
local fs = require "nixio.fs"
local sys = require "luci.sys"
local words = luci.util.split(luci.util.trim(sys.exec("/usr/libexec/fan-control get 2>/dev/null")), " ")
if #words < 3 then
return
end
m = Map("luci-fan", translate("Fan Control"), translate("Control fan start and stop temperature. This plugin can only configure the lowest gear, not necessarily applicable to all devices."))
s = m:section(SimpleSection)
s.template = "luci-fan"
s.thermal_zone = words[1]
s.trip_point = words[2]
s.thermal_type = luci.util.trim(fs.readfile("/sys/class/thermal/"..words[1].."/type"))
s = m:section(TypedSection, "luci-fan", translate("Fan Settings"))
s.addremove = false
s.anonymous = true
o = s:option(Flag, "enabled", translate("Enabled"), translate("Whether to apply the settings"))
o.default = 0
local on_temp = s:option(Value, "on_temp", translate("Fan start temperature") .. " (&#8451;)")
on_temp.datatype = "and(uinteger,min(5))"
on_temp.rmempty = false
on_temp.default = math.floor(tonumber(words[3])/1000)
if #words > 3 then
on_temp.datatype = string.format("and(uinteger,range(5,%u))", math.floor(tonumber(words[4])/1000 - 1))
end
o = s:option(Value, "off_temp", translate("Fan stop temperature") .. " (&#8451;)", translate("Optional, MUST be lower than the fan start temperature. Default fan start temperature minus 5 &#8451;"))
o.datatype = "uinteger"
o.rmempty = true
function o.parse(self, section, novld)
local fvalue = self:formvalue(section)
local fexist = ( fvalue and (#fvalue > 0) ) -- not "nil" and "not empty"
local vvalue, errtxt = self:validate(fvalue)
if not vvalue then
if novld then -- and "novld" set
return -- then exit without raising an error
end
if fexist then -- and there is a formvalue
self:add_error(section, "invalid", errtxt or self.title .. ": invalid")
return -- so data are invalid
end
end
local rm_opt = ( self.rmempty or self.optional )
local vexist = ( vvalue and (#vvalue > 0) ) and true or false -- not "nil" and "not empty"
local eq_def = ( vvalue == self.default ) -- equal_default flag
-- (rmempty or optional) and (no data or equal_default)
if rm_opt and (not vexist or eq_def) then
if self:remove(section) then -- remove data from UCI
self.section.changed = true -- and push events
end
return
end
local cvalue = self:cfgvalue(section)
local eq_cfg = ( vvalue == cvalue ) -- update equal_config flag
-- not forcewrite and no changes, so nothing to write
if not self.forcewrite and eq_cfg then
return
end
local onvalue = on_temp:validate(on_temp:formvalue(section))
if onvalue and #onvalue > 0 then
if tonumber(vvalue) >= tonumber(onvalue) then
self:add_error(section, "invalid", translate("Fan stop temperature MUST be lower than fan start temperature"))
return
end
else
return
end
-- write data to UCI; raise event only on changes
if self:write(section, vvalue) and not eq_cfg then
self.section.changed = true
end
end
return m

View File

@@ -0,0 +1,30 @@
<div class="cbi-section">
<div class="cbi-section-node">
<h3><%:Status%></h3>
<table class="table">
<tbody>
<tr class="tr"><td class="td"><%:Thermal zone%></td><td class="td"><%=self.thermal_zone%> (<%:type:%> <%=self.thermal_type%>)</td></tr>
<tr class="tr"><td class="td"><%:Trip point%></td><td class="td">trip_point_<%=self.trip_point%></td></tr>
<tr class="tr"><td class="td"><%:Fan start temperature%></td><td class="td" id="fan_on_temp"></td></tr>
<tr class="tr"><td class="td"><%:Current temperature%></td><td class="td" id="zone_temp"></td></tr>
</tbody>
</table>
</div>
</div>
<script type="text/javascript">//<![CDATA[
(function(){
var fan_on_temp = document.getElementById('fan_on_temp');
var zone_temp = document.getElementById('zone_temp');
XHR.poll(3, '<%=url("admin/system/luci-fan/get_fan_info/"..self.thermal_zone.."/"..self.trip_point)%>', null,
function(x, st) {
if (st) {
if (fan_on_temp)
fan_on_temp.innerHTML = st.fan_on_temp + ' &#8451;';
if (zone_temp)
zone_temp.innerHTML = st.zone_temp + ' &#8451;';
}
}
);
})()
//]]></script>