shirou_gopsutil/host/host_darwin_cgo.go

48 lines
1.0 KiB
Go
Raw Permalink Normal View History

2021-12-23 05:54:41 +08:00
//go:build darwin && cgo
// +build darwin,cgo
2019-12-13 23:03:44 +08:00
package host
// #cgo LDFLAGS: -framework IOKit
// #include "smc_darwin.h"
2019-12-13 23:03:44 +08:00
import "C"
import "context"
func SensorsTemperaturesWithContext(ctx context.Context) ([]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
2021-11-09 21:14:54 +08:00
C.gopsutil_v3_open_smc()
defer C.gopsutil_v3_close_smc()
2019-12-13 23:03:44 +08:00
for _, key := range temperatureKeys {
temperatures = append(temperatures, TemperatureStat{
SensorKey: key,
2021-11-09 21:14:54 +08:00
Temperature: float64(C.gopsutil_v3_get_temperature(C.CString(key))),
2019-12-13 23:03:44 +08:00
})
}
return temperatures, nil
}