Separate temp widget by platform
This commit is contained in:
parent
3387d4c792
commit
6f4984e5e7
@ -6,11 +6,9 @@ package widgets
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
ui "github.com/cjbassi/termui"
|
||||
psHost "github.com/shirou/gopsutil/host"
|
||||
)
|
||||
|
||||
type Temp struct {
|
||||
@ -43,18 +41,6 @@ func NewTemp() *Temp {
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *Temp) update() {
|
||||
sensors, _ := psHost.SensorsTemperatures()
|
||||
for _, sensor := range sensors {
|
||||
// only sensors with input in their name are giving us live temp info
|
||||
if strings.Contains(sensor.SensorKey, "input") {
|
||||
// removes '_input' from the end of the sensor name
|
||||
label := sensor.SensorKey[:strings.Index(sensor.SensorKey, "_input")]
|
||||
self.Data[label] = int(sensor.Temperature)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Buffer implements ui.Bufferer interface and renders the widget.
|
||||
func (self *Temp) Buffer() *ui.Buffer {
|
||||
buf := self.Block.Buffer()
|
||||
@ -78,7 +64,6 @@ func (self *Temp) Buffer() *ui.Buffer {
|
||||
s := ui.MaxString(key, (self.X - 4))
|
||||
buf.SetString(1, y+1, s, self.Fg, self.Bg)
|
||||
buf.SetString(self.X-2, y+1, fmt.Sprintf("%2dC", self.Data[key]), fg, self.Bg)
|
||||
|
||||
}
|
||||
|
||||
return buf
|
||||
|
57
src/widgets/temp_darwin.go
Normal file
57
src/widgets/temp_darwin.go
Normal file
@ -0,0 +1,57 @@
|
||||
// TODO do we need to add '+build cgo'?
|
||||
|
||||
package widgets
|
||||
|
||||
// #cgo LDFLAGS: -framework IOKit
|
||||
// #include "include/smc.c"
|
||||
import "C"
|
||||
|
||||
type TemperatureStat struct {
|
||||
SensorKey string `json:"sensorKey"`
|
||||
Temperature float64 `json:"sensorTemperature"`
|
||||
}
|
||||
|
||||
func SensorsTempatures() ([]TemperatureStat, error) {
|
||||
temperatureKeys := []string{
|
||||
C.AMBIENT_AIR_0,
|
||||
C.AMBIENT_AIR_1,
|
||||
C.CPU_0_DIODE,
|
||||
C.CPU_0_HEATSINK,
|
||||
C.CPU_0_PROXIMITY,
|
||||
C.ENCLOSURE_BASE_0,
|
||||
C.ENCLOSURE_BASE_1,
|
||||
C.ENCLOSURE_BASE_2,
|
||||
C.ENCLOSURE_BASE_3,
|
||||
C.GPU_0_DIODE,
|
||||
C.GPU_0_HEATSINK,
|
||||
C.GPU_0_PROXIMITY,
|
||||
C.HARD_DRIVE_BAY,
|
||||
C.MEMORY_SLOT_0,
|
||||
C.MEMORY_SLOTS_PROXIMITY,
|
||||
C.NORTHBRIDGE,
|
||||
C.NORTHBRIDGE_DIODE,
|
||||
C.NORTHBRIDGE_PROXIMITY,
|
||||
C.THUNDERBOLT_0,
|
||||
C.THUNDERBOLT_1,
|
||||
C.WIRELESS_MODULE,
|
||||
}
|
||||
var temperatures []TemperatureStat
|
||||
|
||||
C.open_smc()
|
||||
defer C.close_smc()
|
||||
|
||||
for _, key := range temperatureKeys {
|
||||
temperatures = append(temperatures, TemperatureStat{
|
||||
SensorKey: key,
|
||||
Temperature: float64(C.get_tmp(C.CString(key), C.CELSIUS)),
|
||||
})
|
||||
}
|
||||
return temperatures, nil
|
||||
}
|
||||
|
||||
func (self *Temp) update() {
|
||||
sensors, _ := SensorsTemperatures()
|
||||
for _, sensor := range sensors {
|
||||
self.Data[sensor.SensorKey] = int(sensor.Temperature)
|
||||
}
|
||||
}
|
19
src/widgets/temp_linux.go
Normal file
19
src/widgets/temp_linux.go
Normal file
@ -0,0 +1,19 @@
|
||||
package widgets
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
psHost "github.com/shirou/gopsutil/host"
|
||||
)
|
||||
|
||||
func (self *Temp) update() {
|
||||
sensors, _ := psHost.SensorsTemperatures()
|
||||
for _, sensor := range sensors {
|
||||
// only sensors with input in their name are giving us live temp info
|
||||
if strings.Contains(sensor.SensorKey, "input") {
|
||||
// removes '_input' from the end of the sensor name
|
||||
label := sensor.SensorKey[:strings.Index(sensor.SensorKey, "_input")]
|
||||
self.Data[label] = int(sensor.Temperature)
|
||||
}
|
||||
}
|
||||
}
|
12
src/widgets/temp_windows.go
Normal file
12
src/widgets/temp_windows.go
Normal file
@ -0,0 +1,12 @@
|
||||
package widgets
|
||||
|
||||
import (
|
||||
psHost "github.com/shirou/gopsutil/host"
|
||||
)
|
||||
|
||||
func (self *Temp) update() {
|
||||
sensors, _ := psHost.SensorsTemperatures()
|
||||
for _, sensor := range sensors {
|
||||
self.Data[sensor.SensorKey] = int(sensor.Temperature)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user