xmtop/src/widgets/temp_other.go

32 lines
801 B
Go
Raw Normal View History

2018-12-14 11:13:28 +08:00
// +build linux freebsd
2018-05-16 04:48:26 +08:00
package widgets
import (
"log"
2018-05-16 04:48:26 +08:00
"strings"
"github.com/cjbassi/gotop/src/utils"
2018-05-16 04:48:26 +08:00
psHost "github.com/shirou/gopsutil/host"
)
func (self *Temp) update() {
sensors, err := psHost.SensorsTemperatures()
if err != nil {
log.Printf("failed to get sensors from gopsutil: %v", err)
2018-12-14 13:59:45 +08:00
return
}
2018-05-16 04:48:26 +08:00
for _, sensor := range sensors {
// only sensors with input in their name are giving us live temp info
2018-11-30 09:37:41 +08:00
if strings.Contains(sensor.SensorKey, "input") && sensor.Temperature != 0 {
2018-05-16 04:48:26 +08:00
// removes '_input' from the end of the sensor name
label := sensor.SensorKey[:strings.Index(sensor.SensorKey, "_input")]
if self.Fahrenheit {
self.Data[label] = utils.CelsiusToFahrenheit(int(sensor.Temperature))
} else {
self.Data[label] = int(sensor.Temperature)
}
2018-05-16 04:48:26 +08:00
}
}
}