mirror of
https://codeberg.org/gigirassy/hotrod.git
synced 2026-08-30 15:27:39 +00:00
Add main.go
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"time"
|
||||
)
|
||||
|
||||
func getTemp() (float64, error) {
|
||||
out, err := exec.Command("cat", "/sys/class/thermal/thermal_zone0/temp").Output()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
var tempMilli float64
|
||||
fmt.Sscanf(string(out), "%f", &tempMilli)
|
||||
return tempMilli / 1000, nil
|
||||
}
|
||||
|
||||
func eatCPU(stop <-chan bool) {
|
||||
for {
|
||||
select {
|
||||
case <-stop:
|
||||
return
|
||||
default:
|
||||
_ = 1.0001 * 1.0001 // keep CPU busy
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
targetTemp := flag.Float64("t", 70, "Target temperature in Celsius")
|
||||
flag.Parse()
|
||||
|
||||
fmt.Printf("Heating CPU to %.1f°C...\n", *targetTemp)
|
||||
|
||||
stop := make(chan bool)
|
||||
go eatCPU(stop)
|
||||
|
||||
for {
|
||||
temp, err := getTemp()
|
||||
if err != nil {
|
||||
fmt.Println("Error reading temperature:", err)
|
||||
break
|
||||
}
|
||||
|
||||
fmt.Printf("Current temperature: %.1f°C\r", temp)
|
||||
if temp >= *targetTemp {
|
||||
fmt.Println("\nTarget reached. Cooling down...")
|
||||
stop <- true
|
||||
break
|
||||
}
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
|
||||
runtime.GC()
|
||||
}
|
||||
Reference in New Issue
Block a user