github.com/isyscore/isc-gobase@v1.5.3-0.20231218061332-cbc7451899e9/system/host/host_darwin_cgo.go (about) 1 //go:build darwin && cgo 2 3 package host 4 5 // #cgo LDFLAGS: -framework IOKit 6 // #include "smc_darwin.h" 7 import "C" 8 import "context" 9 10 func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, error) { 11 temperatureKeys := []string{ 12 C.AMBIENT_AIR_0, 13 C.AMBIENT_AIR_1, 14 C.CPU_0_DIODE, 15 C.CPU_0_HEATSINK, 16 C.CPU_0_PROXIMITY, 17 C.ENCLOSURE_BASE_0, 18 C.ENCLOSURE_BASE_1, 19 C.ENCLOSURE_BASE_2, 20 C.ENCLOSURE_BASE_3, 21 C.GPU_0_DIODE, 22 C.GPU_0_HEATSINK, 23 C.GPU_0_PROXIMITY, 24 C.HARD_DRIVE_BAY, 25 C.MEMORY_SLOT_0, 26 C.MEMORY_SLOTS_PROXIMITY, 27 C.NORTHBRIDGE, 28 C.NORTHBRIDGE_DIODE, 29 C.NORTHBRIDGE_PROXIMITY, 30 C.THUNDERBOLT_0, 31 C.THUNDERBOLT_1, 32 C.WIRELESS_MODULE, 33 } 34 var temperatures []TemperatureStat 35 36 C.open_smc() 37 defer C.close_smc() 38 39 for _, key := range temperatureKeys { 40 temperatures = append(temperatures, TemperatureStat{ 41 SensorKey: key, 42 Temperature: float64(C.get_temperature(C.CString(key))), 43 }) 44 } 45 return temperatures, nil 46 }