Conky: hwmon rounds to integer, no way to specify resolution

Created on 28 Mar 2018  路  10Comments  路  Source: brndnmtthws/conky

Using ${hwmon 0 temp 1 1.0 0.0} I can get conky to display the temperature, but it displays an integer value "41", while running cat /sys/class/hwmon/hwmon0/temp1_input returns 40750. So clearly more accuracy is available.
Changing the conky config to ${hwmon 0 temp 1 1000.0 0.0}, conky displays the full value, but I would like it to round to 1 or 2 decimal places (preferably to be able to specify how many digits I want).

As a side note - how does conky even "know" the raw value is given in milli-Celsius anyway?

enhancement

Most helpful comment

@su8 yeah I think having decimals for temp by default is fine.

All 10 comments

As a side note - how does conky even "know" the raw value is given in milli-Celsius anyway?

Author reads documentations. https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface

@lasers can you test my latest commit and verify it ?

conky.text = [[${hwmon 0 temp 1 1.0 0.0} // ${hwmon 0 temp 1 1000.0 0.0 0.0}]]
56 // 56000

How should I round it to 1 or 2 decimal places?

You can't round it lower than 2 decimal places, e.g: 56 can't become 5.

Going off on his word, but I think he really want precision. 40750 --> 40.7 or 40.75

EDIT: Also, there is a 1000 variable * factor + offset. I got lost trying to set up two things.

With the current code we can't print float

https://github.com/brndnmtthws/conky/blob/7bca0ca8819f03883affa5fba9e8506d8c2c5f29/src/linux.cc#L1230

https://github.com/brndnmtthws/conky/blob/4b92556fca9cbede3cbac4112f0a24b554390099/src/temphelper.cc#L63

I'll poke around to create second wrapper around the "temp", instead using hwmon 0 temp 1 1.0 0.0 to become hwmon 0 temp2 1 1.0 0.0

Dont know will it work or not, have to try.

@brndnmtthws Will you accept by default to print the numbers in float instead pure integer ?

So
https://github.com/brndnmtthws/conky/blob/4b92556fca9cbede3cbac4112f0a24b554390099/src/temphelper.cc#L58

to become:

int temp_print(char *p, size_t p_max_size, double n,
               enum TEMP_UNIT input_unit) {
  float out;
  size_t plen;

  out = convert_temp_output(n, input_unit);
  plen = spaced_print(p, p_max_size, "%.2f", 3, out);

  return static_cast<int>(!(plen >= p_max_size));
}

@lasers Can you test my latest commit with the following in conky.conf:

${hwmon 0 temp2 1 1.0 0.0}
${hwmon 1 temp 1 1.0 1.0 1.0}

where temp2 should print the temperature in floating mode.

@su8 yeah I think having decimals for temp by default is fine.

Was this page helpful?
0 / 5 - 0 ratings