%- local sys = require "luci.sys" local utl = require "luci.util" local bms_path = "/sys/class/power_supply/pm8916-bms-vm" local charger_path = "/sys/class/power_supply/pm8916-lbc-chgr" local function read_file(path) local f = io.open(path, "r") if f then local val = f:read("*all") f:close() return utl.trim(val) end return nil end local voltage = read_file(bms_path .. "/voltage_now") local status = read_file(bms_path .. "/status") local health = read_file(bms_path .. "/health") local vmax = read_file(bms_path .. "/voltage_max_design") local vmin = read_file(bms_path .. "/voltage_min_design") local online = read_file(charger_path .. "/online") -- Calcular porcentaje aproximado basado en voltaje local percentage = "N/A" if voltage and vmax and vmin then local v = tonumber(voltage) local vmax_n = tonumber(vmax) local vmin_n = tonumber(vmin) if v and vmax_n and vmin_n then local pct = ((v - vmin_n) / (vmax_n - vmin_n)) * 100 pct = math.max(0, math.min(100, pct)) percentage = string.format("%.0f%%", pct) end end -%> <% if voltage then %>