Skip to content

Commit b781a3f

Browse files
committed
feat(config): support custom temperature limits from config.json
Implement loading and saving of `maxTemp` and `maxFanOffTemp` values from `config.json` for flexible alert configuration.
1 parent 4f8b1a6 commit b781a3f

3 files changed

Lines changed: 35 additions & 5 deletions

File tree

config.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package main
2+
3+
import ("os"; "encoding/json")
4+
5+
type Config struct {
6+
MaxTemp int `json:"maxTemp"`
7+
MaxFanOffTemp int `json:"maxFanOffTemp"`
8+
}
9+
10+
var config = Config{
11+
MaxTemp: 60,
12+
MaxFanOffTemp: 40,
13+
}
14+
15+
const configFile = "config.json"
16+
17+
func loadConfig() {
18+
data, err := os.ReadFile(configFile)
19+
if err != nil {
20+
saveConfig()
21+
} else {
22+
json.Unmarshal(data, &config)
23+
}
24+
}
25+
26+
func saveConfig() {
27+
data, _ := json.MarshalIndent(config, "", " ")
28+
os.WriteFile(configFile, data, 0644)
29+
}

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var eventPtr = utf16("Global\\HotAMD")
66

77
func main() {
88
initADL()
9+
loadConfig()
910
if len(os.Args) > 1 && os.Args[1] == "--daemon" { runDaemon() } else { runCLI() }
1011
destroyADL()
1112
}

monitor.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package main
22

3-
import ("unsafe"; "time"; w "golang.org/x/sys/windows")
3+
import ("fmt"; "unsafe"; "time"; w "golang.org/x/sys/windows")
44

55
type ADLTemperature struct {
66
Size int32
@@ -57,10 +57,10 @@ func destroyADL() {
5757
func start() {
5858
for {
5959
temp, rpm := readGPU()
60-
if temp > 40 && rpm == 0 {
61-
alert("GPU temperature > 40°C and fan is not spinning")
62-
} else if temp > 60 {
63-
alert("GPU temperature > 60°C")
60+
if int(temp) > config.MaxFanOffTemp && rpm == 0 {
61+
alert("GPU temperature > " + fmt.Sprintf("%v", config.MaxFanOffTemp) + "°C and fan is not spinning")
62+
} else if int(temp) > config.MaxTemp {
63+
alert("GPU temperature > " + fmt.Sprintf("%v", config.MaxTemp) + "°C")
6464
}
6565
time.Sleep(10 * time.Second)
6666
}

0 commit comments

Comments
 (0)