diff --git a/app/proc/drivers/hwmon.go b/app/proc/drivers/hwmon.go index 90466d7..6b23432 100644 --- a/app/proc/drivers/hwmon.go +++ b/app/proc/drivers/hwmon.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path/filepath" + "sort" "strconv" "strings" ) @@ -51,10 +52,7 @@ func (r *HwmonDriver) Render(term common.Terminal) error { term.Subheader("Temperature") for _, sensor := range temps { - tempC := sensor.TempC - tempF := (tempC * 9 / 5) + 32 - // \033[K clears from cursor to end of line (prevents lingering chars) - term.Print(fmt.Sprintf("%-16s | %.2f °C (%.3f °F)", sensor.Name, tempC, tempF)) + term.Print(fmt.Sprintf("%-16s | %.2f °C", sensor.Name, sensor.TempC)) } return nil @@ -66,6 +64,11 @@ func (r *HwmonDriver) Read() (any, error) { return nil, fmt.Errorf("no temperature inputs found in %s", r.hwmonDir) } + // Sort input paths by numerical index (temp1_input, temp2_input, ... temp10_input) + sort.Slice(inputs, func(i, j int) bool { + return extractSensorIndex(inputs[i]) < extractSensorIndex(inputs[j]) + }) + temps := make([]TemperatureSensor, 0, len(inputs)) for _, inputPath := range inputs { @@ -96,3 +99,15 @@ func (r *HwmonDriver) Read() (any, error) { return temps, nil } + +// Helper to extract the integer index from "temp_input" +func extractSensorIndex(path string) int { + base := filepath.Base(path) + trimmed := strings.TrimPrefix(base, "temp") + trimmed = strings.TrimSuffix(trimmed, "_input") + idx, err := strconv.Atoi(trimmed) + if err != nil { + return 0 + } + return idx +}