summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaleb Bassi <calebjbassi@gmail.com>2018-12-01 20:51:51 -0800
committerCaleb Bassi <calebjbassi@gmail.com>2018-12-01 20:51:51 -0800
commit357050207e10bc4cddf20f12bd7072186e7a1d82 (patch)
tree5f66e52c9bd6b32ae0c099c73a0a960a9fc133a9
parentf66833c2cc7d03eb993c85476de564ed9160b101 (diff)
Refactor inline celsius conversion into a function
-rw-r--r--src/utils/utils.go4
-rw-r--r--src/widgets/temp_darwin.go8
-rw-r--r--src/widgets/temp_linux.go3
-rw-r--r--src/widgets/temp_windows.go3
4 files changed, 14 insertions, 4 deletions
diff --git a/src/utils/utils.go b/src/utils/utils.go
index 6c9ae36..f3e11ef 100644
--- a/src/utils/utils.go
+++ b/src/utils/utils.go
@@ -14,6 +14,10 @@ var (
TB = uint64(math.Pow(2, 40))
)
+func CelsiusToFahrenheit(c int) int {
+ return c*9/5 + 32
+}
+
func BytesToKB(b uint64) float64 {
return float64(b) / float64(KB)
}
diff --git a/src/widgets/temp_darwin.go b/src/widgets/temp_darwin.go
index f4a7d09..b71a5c5 100644
--- a/src/widgets/temp_darwin.go
+++ b/src/widgets/temp_darwin.go
@@ -4,7 +4,11 @@ package widgets
// #cgo LDFLAGS: -framework IOKit
// #include "include/smc.c"
-import "C"
+import (
+ "C"
+
+ "github.com/cjbassi/gotop/src/utils"
+}
type TemperatureStat struct {
SensorKey string `json:"sensorKey"`
@@ -54,7 +58,7 @@ func (self *Temp) update() {
for _, sensor := range sensors {
if sensor.Temperature != 0 {
if self.Fahrenheit {
- self.Data[sensor.SensorKey] = int(sensor.Temperature*9/5 + 32)
+ self.Data[sensor.SensorKey] = utils.CelsiusToFahrenheit(int(sensor.Temperature))
} else {
self.Data[sensor.SensorKey] = int(sensor.Temperature)
}
diff --git a/src/widgets/temp_linux.go b/src/widgets/temp_linux.go
index 38e3cce..40c1978 100644
--- a/src/widgets/temp_linux.go
+++ b/src/widgets/temp_linux.go
@@ -3,6 +3,7 @@ package widgets
import (
"strings"
+ "github.com/cjbassi/gotop/src/utils"
psHost "github.com/shirou/gopsutil/host"
)
@@ -14,7 +15,7 @@ func (self *Temp) update() {
// removes '_input' from the end of the sensor name
label := sensor.SensorKey[:strings.Index(sensor.SensorKey, "_input")]
if self.Fahrenheit {
- self.Data[label] = int(sensor.Temperature*9/5 + 32)
+ self.Data[label] = utils.CelsiusToFahrenheit(int(sensor.Temperature))
} else {
self.Data[label] = int(sensor.Temperature)
}
diff --git a/src/widgets/temp_windows.go b/src/widgets/temp_windows.go
index 0d3f6c3..7ac35d5 100644
--- a/src/widgets/temp_windows.go
+++ b/src/widgets/temp_windows.go
@@ -1,6 +1,7 @@
package widgets
import (
+ "github.com/cjbassi/gotop/src/utils"
psHost "github.com/shirou/gopsutil/host"
)
@@ -9,7 +10,7 @@ func (self *Temp) update() {
for _, sensor := range sensors {
if sensor.Temperature != 0 {
if self.Fahrenheit {
- self.Data[sensor.SensorKey] = int(sensor.Temperature*9/5 + 32)
+ self.Data[sensor.SensorKey] = utils.CelsiusToFahrenheit(int(sensor.Temperature))
} else {
self.Data[sensor.SensorKey] = int(sensor.Temperature)
}