host_darwin_cgo.go 974 B

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