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