2020-02-18 03:00:52 +08:00
|
|
|
// +build darwin
|
|
|
|
|
2020-02-28 08:51:28 +08:00
|
|
|
package devices
|
2018-05-16 04:48:26 +08:00
|
|
|
|
2020-05-25 02:56:25 +08:00
|
|
|
// TODO gopsutil team reports this is not needed; try getting rid of this dep
|
2020-04-23 02:33:51 +08:00
|
|
|
import smc "github.com/xxxserxxx/iSMC"
|
2018-12-05 13:44:25 +08:00
|
|
|
|
2020-02-28 08:51:28 +08:00
|
|
|
func init() {
|
|
|
|
RegisterTemp(update)
|
2020-04-24 02:01:13 +08:00
|
|
|
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
|
|
|
|
|
2020-02-28 08:51:28 +08:00
|
|
|
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 {
|
2020-04-23 23:41:20 +08:00
|
|
|
if _, ok := temps[k]; ok {
|
|
|
|
temps[k] = int(v + 0.5)
|
|
|
|
}
|
2018-05-16 04:48:26 +08:00
|
|
|
}
|
2020-02-28 08:51:28 +08:00
|
|
|
return nil
|
2018-05-16 04:48:26 +08:00
|
|
|
}
|
2020-04-23 23:41:20 +08:00
|
|
|
|
|
|
|
func devs() []string {
|
|
|
|
rv := make([]string, len(smc.AppleTemp))
|
|
|
|
for i, v := range smc.AppleTemp {
|
|
|
|
rv[i] = v.Desc
|
|
|
|
}
|
|
|
|
return rv
|
|
|
|
}
|
2020-04-24 02:01:13 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|