File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,27 +3,46 @@ package main
33import ("os" ; "encoding/json" )
44
55type Config struct {
6- MaxTemp int `json:"maxTemp"`
6+ MaxTemp int `json:"maxTemp"`
77 MaxFanOffTemp int `json:"maxFanOffTemp"`
88}
99
1010var config = Config {
11- MaxTemp : 60 ,
11+ MaxTemp : 60 ,
1212 MaxFanOffTemp : 40 ,
1313}
1414
1515const configFile = "config.json"
16+ var configModTime int64
1617
1718func loadConfig () {
1819 data , err := os .ReadFile (configFile )
1920 if err != nil {
2021 saveConfig ()
21- } else {
22- json .Unmarshal (data , & config )
22+ return
2323 }
24+ json .Unmarshal (data , & config )
25+
26+ info , err := os .Stat (configFile )
27+ if err != nil { return }
28+ configModTime = info .ModTime ().Unix ()
2429}
2530
2631func saveConfig () {
2732 data , _ := json .MarshalIndent (config , "" , " " )
2833 os .WriteFile (configFile , data , 0644 )
34+
35+ info , err := os .Stat (configFile )
36+ if err == nil {
37+ configModTime = info .ModTime ().Unix ()
38+ }
39+ }
40+
41+ func reloadConfigIfChanged () {
42+ info , err := os .Stat (configFile )
43+ if err != nil { return }
44+
45+ if info .ModTime ().Unix () != configModTime {
46+ loadConfig ()
47+ }
2948}
Original file line number Diff line number Diff line change @@ -56,12 +56,15 @@ func destroyADL() {
5656
5757func start () {
5858 for {
59+ reloadConfigIfChanged ()
60+
5961 temp , rpm := readGPU ()
6062 if int (temp ) > config .MaxFanOffTemp && rpm == 0 {
6163 alert ("GPU temperature > " + fmt .Sprintf ("%v" , config .MaxFanOffTemp ) + "°C and fan is not spinning" )
6264 } else if int (temp ) > config .MaxTemp {
6365 alert ("GPU temperature > " + fmt .Sprintf ("%v" , config .MaxTemp ) + "°C" )
6466 }
67+
6568 time .Sleep (10 * time .Second )
6669 }
6770}
You can’t perform that action at this time.
0 commit comments