mirror of
https://github.com/cjbassi/gotop.git
synced 2025-05-03 22:17:15 +08:00
Refactor inline celsius conversion into a function
This commit is contained in:
parent
f66833c2cc
commit
357050207e
@ -14,6 +14,10 @@ var (
|
|||||||
TB = uint64(math.Pow(2, 40))
|
TB = uint64(math.Pow(2, 40))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func CelsiusToFahrenheit(c int) int {
|
||||||
|
return c*9/5 + 32
|
||||||
|
}
|
||||||
|
|
||||||
func BytesToKB(b uint64) float64 {
|
func BytesToKB(b uint64) float64 {
|
||||||
return float64(b) / float64(KB)
|
return float64(b) / float64(KB)
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,11 @@ package widgets
|
|||||||
|
|
||||||
// #cgo LDFLAGS: -framework IOKit
|
// #cgo LDFLAGS: -framework IOKit
|
||||||
// #include "include/smc.c"
|
// #include "include/smc.c"
|
||||||
import "C"
|
import (
|
||||||
|
"C"
|
||||||
|
|
||||||
|
"github.com/cjbassi/gotop/src/utils"
|
||||||
|
}
|
||||||
|
|
||||||
type TemperatureStat struct {
|
type TemperatureStat struct {
|
||||||
SensorKey string `json:"sensorKey"`
|
SensorKey string `json:"sensorKey"`
|
||||||
@ -54,7 +58,7 @@ func (self *Temp) update() {
|
|||||||
for _, sensor := range sensors {
|
for _, sensor := range sensors {
|
||||||
if sensor.Temperature != 0 {
|
if sensor.Temperature != 0 {
|
||||||
if self.Fahrenheit {
|
if self.Fahrenheit {
|
||||||
self.Data[sensor.SensorKey] = int(sensor.Temperature*9/5 + 32)
|
self.Data[sensor.SensorKey] = utils.CelsiusToFahrenheit(int(sensor.Temperature))
|
||||||
} else {
|
} else {
|
||||||
self.Data[sensor.SensorKey] = int(sensor.Temperature)
|
self.Data[sensor.SensorKey] = int(sensor.Temperature)
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package widgets
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/cjbassi/gotop/src/utils"
|
||||||
psHost "github.com/shirou/gopsutil/host"
|
psHost "github.com/shirou/gopsutil/host"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -14,7 +15,7 @@ func (self *Temp) update() {
|
|||||||
// removes '_input' from the end of the sensor name
|
// removes '_input' from the end of the sensor name
|
||||||
label := sensor.SensorKey[:strings.Index(sensor.SensorKey, "_input")]
|
label := sensor.SensorKey[:strings.Index(sensor.SensorKey, "_input")]
|
||||||
if self.Fahrenheit {
|
if self.Fahrenheit {
|
||||||
self.Data[label] = int(sensor.Temperature*9/5 + 32)
|
self.Data[label] = utils.CelsiusToFahrenheit(int(sensor.Temperature))
|
||||||
} else {
|
} else {
|
||||||
self.Data[label] = int(sensor.Temperature)
|
self.Data[label] = int(sensor.Temperature)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package widgets
|
package widgets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/cjbassi/gotop/src/utils"
|
||||||
psHost "github.com/shirou/gopsutil/host"
|
psHost "github.com/shirou/gopsutil/host"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -9,7 +10,7 @@ func (self *Temp) update() {
|
|||||||
for _, sensor := range sensors {
|
for _, sensor := range sensors {
|
||||||
if sensor.Temperature != 0 {
|
if sensor.Temperature != 0 {
|
||||||
if self.Fahrenheit {
|
if self.Fahrenheit {
|
||||||
self.Data[sensor.SensorKey] = int(sensor.Temperature*9/5 + 32)
|
self.Data[sensor.SensorKey] = utils.CelsiusToFahrenheit(int(sensor.Temperature))
|
||||||
} else {
|
} else {
|
||||||
self.Data[sensor.SensorKey] = int(sensor.Temperature)
|
self.Data[sensor.SensorKey] = int(sensor.Temperature)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user