From e596d524e5d90215c71840ecf6b02dabf3f17e28 Mon Sep 17 00:00:00 2001 From: Caleb Bassi Date: Mon, 3 Dec 2018 14:22:10 -0800 Subject: [PATCH] Improve OSX temp names (#71) --- src/widgets/temp_darwin.go | 55 +++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/src/widgets/temp_darwin.go b/src/widgets/temp_darwin.go index b71a5c5c..cc14b212 100644 --- a/src/widgets/temp_darwin.go +++ b/src/widgets/temp_darwin.go @@ -5,10 +5,10 @@ package widgets // #cgo LDFLAGS: -framework IOKit // #include "include/smc.c" import ( - "C" + "C" - "github.com/cjbassi/gotop/src/utils" -} + "github.com/cjbassi/gotop/src/utils" +) type TemperatureStat struct { SensorKey string `json:"sensorKey"` @@ -16,37 +16,38 @@ type TemperatureStat struct { } func SensorsTemperatures() ([]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, + temperatureKeys := map[string]string{ + C.AMBIENT_AIR_0: "ambient_air_0", + C.AMBIENT_AIR_1: "ambient_air_1", + C.CPU_0_DIODE: "cpu_0_diode", + C.CPU_0_HEATSINK: "cpu_0_heatsink", + C.CPU_0_PROXIMITY: "cpu_0_proximity", + C.ENCLOSURE_BASE_0: "enclosure_base_0", + C.ENCLOSURE_BASE_1: "enclosure_base_1", + C.ENCLOSURE_BASE_2: "enclosure_base_2", + C.ENCLOSURE_BASE_3: "enclosure_base_3", + C.GPU_0_DIODE: "gpu_0_diode", + C.GPU_0_HEATSINK: "gpu_0_heatsink", + C.GPU_0_PROXIMITY: "gpu_0_proximity", + C.HARD_DRIVE_BAY: "hard_drive_bay", + C.MEMORY_SLOT_0: "memory_slot_0", + C.MEMORY_SLOTS_PROXIMITY: "memory_slots_proximity", + C.NORTHBRIDGE: "northbridge", + C.NORTHBRIDGE_DIODE: "northbridge_diode", + C.NORTHBRIDGE_PROXIMITY: "northbridge_proximity", + C.THUNDERBOLT_0: "thunderbolt_0", + C.THUNDERBOLT_1: "thunderbolt_1", + C.WIRELESS_MODULE: "wireless_module", } + var temperatures []TemperatureStat C.open_smc() defer C.close_smc() - for _, key := range temperatureKeys { + for key, val := range temperatureKeys { temperatures = append(temperatures, TemperatureStat{ - SensorKey: key, + SensorKey: val, Temperature: float64(C.get_tmp(C.CString(key), C.CELSIUS)), }) }