Advertisement
Tritonio

Autoboost

May 16th, 2023
729
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.84 KB | None | 0 0
  1. #!/usr/bin/lua5.3
  2. posix = require "socket"
  3. local low=75
  4. local high=92
  5. local sleep=0.5
  6. local tempfile="/sys/class/thermal/thermal_zone0/temp"
  7. local divisor=1000
  8. local boostfile="/sys/devices/system/cpu/cpufreq/boost"
  9.  
  10. local last=-1
  11.  
  12. function setboost(n)
  13.     if last~=n then
  14.         last=n
  15.         bh=io.open(boostfile,"w")
  16.         if bh then
  17.             bh:write(n.."\n")
  18.             bh:close()
  19.         end
  20.     end
  21. end
  22.  
  23. while true do
  24.     posix.sleep(sleep)
  25.     h=io.open(tempfile,"rb")
  26.     if h then
  27.         local sensor=h:read("*n")
  28.         h:close()
  29.         if sensor then
  30.             sensor=tonumber(sensor)/1000
  31.             io.write(math.floor(sensor+0.5).." C")
  32.             local float=1-math.min(1,math.max(0,((sensor-low)/(high-low))))
  33.             io.write("\tBoost: "..math.floor(float*100+0.5) .."%")
  34.             local boost=math.random()<float and 1 or 0
  35.             setboost(boost)
  36.             print("\t"..(boost==1 and "BOOST" or ""))
  37.         end
  38.     end
  39. end
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement