xmtop/devices/temp_darwin.go

47 lines
928 B
Go
Raw Normal View History

// +build darwin
package devices
2018-05-16 04:48:26 +08:00
2020-04-23 02:33:51 +08:00
import smc "github.com/xxxserxxx/iSMC"
func init() {
RegisterTemp(update)
RegisterDeviceList(Temperatures, devs, defs)
2020-04-23 02:33:51 +08:00
ts = make(map[string]float32)
2018-05-16 04:48:26 +08:00
}
2020-04-23 02:33:51 +08:00
var ts map[string]float32
func update(temps map[string]int) map[string]error {
2020-04-23 02:33:51 +08:00
err := smc.GetTemp(ts)
if err != nil {
return map[string]error{"temps": err}
2018-05-16 04:48:26 +08:00
}
2020-04-23 02:33:51 +08:00
for k, v := range ts {
if _, ok := temps[k]; ok {
temps[k] = int(v + 0.5)
}
2018-05-16 04:48:26 +08:00
}
return nil
2018-05-16 04:48:26 +08:00
}
func devs() []string {
rv := make([]string, len(smc.AppleTemp))
for i, v := range smc.AppleTemp {
rv[i] = v.Desc
}
return rv
}
func defs() []string {
// CPU 0 CPU 1 GPU Memory Disk
ids := map[string]bool{"TC0P": true, "TC1P": true, "TG0P": true, "Ts0S": true, "TH0P": true}
rv := make([]string, 0, len(ids))
for _, v := range smc.AppleTemp {
if ids[v.Key] {
rv = append(rv, v.Desc)
}
}
return rv
}