Skip to content

Commit

Permalink
minor optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
parMaster committed Mar 30, 2023
1 parent 981c1b2 commit e907a5b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,28 +345,30 @@ func (w *Worker) getFullData() interface{} {

func (w *Worker) logEverySecond(ctx context.Context) {
ticker := time.NewTicker(1 * time.Second)
var temp int
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
}

var temp int
temp = 0
// Current temperature as reported by thermal zone (sensor), millidegree Celsius
// https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-thermal
sysTemp, err := os.ReadFile("/sys/class/thermal/thermal_zone0/temp")
if err != nil {
log.Printf("[ERROR] Can't read temperature file: %e", err)
temp = 0
} else {
temp, err = strconv.Atoi(string(sysTemp[0 : len(sysTemp)-1]))
if err != nil {
log.Printf("[ERROR] Converting temp data: %e", err)
}
}

log.Printf("[DEBUG] Temp: %d m˚C | Fan RPS/RPM: %d/%d\r\n", temp, w.revs, w.revs*60)
if w.config.Server.Dbg {
log.Printf("[DEBUG] Temp: %d m˚C | Fan RPS/RPM: %d/%d\r\n", temp, w.revs, w.revs*60)
}

w.mx.Lock()
w.data["revs"] = append(w.data["revs"], w.revs*60)
Expand Down
2 changes: 1 addition & 1 deletion web/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
name: 'Pressure, hPa'
};
var PressLayout = {
title: "Atmospheric pressure, mPa",
title: "Atmospheric pressure, hPa",
margin: {"t": 64, "b": 0, "l": 32, "r": 16},
template: template
};
Expand Down

0 comments on commit e907a5b

Please sign in to comment.