1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

tests/drivers_ds18: display negative numbers

When `ds18_read` returns -2506, DS18 test print `Temperature [ºC]: -25.-6`
whereas it should print `Temperature [ºC]: -25.06. This commit fixes this
issue.
This commit is contained in:
Guillaume Gonnet 2019-05-16 20:22:02 +02:00
parent 1783b3da55
commit c9fa1d7503

View File

@ -48,9 +48,16 @@ int main(void)
/* Get temperature in centidegrees celsius */
if (ds18_get_temperature(&dev, &temperature) == DS18_OK) {
printf("Temperature [ºC]: %d.%d"
bool negative = (temperature < 0);
if (negative) {
temperature = -temperature;
}
printf("Temperature [ºC]: %c%d.%02d"
"\n+-------------------------------------+\n",
(temperature / 100), (int)(temperature % 100));
negative ? '-': ' ',
temperature / 100,
temperature % 100);
}
else {
puts("[Error] Could not read temperature");