From 58ef5f3d1b9699b5cf6ab297c914601823a10fd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Mon, 7 Dec 2020 19:07:21 +0100 Subject: [PATCH] sensor_ds18b20: minor, add spacing around operator --- lib/sensor_ds18b20.c | 30 +++++++++++++++--------------- lib/sensor_ds18b20.h | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/sensor_ds18b20.c b/lib/sensor_ds18b20.c index 4ba90ef..0ae2476 100644 --- a/lib/sensor_ds18b20.c +++ b/lib/sensor_ds18b20.c @@ -2,7 +2,7 @@ * @file * @author King Kévin * @copyright SPDX-License-Identifier: GPL-3.0-or-later - * @date 2017 + * @date 2017-2020 * @note peripherals used: 1-Wire (timer @ref onewire_master_timer, GPIO @ref onewire_master_gpio) * @warning this library does not support parasite power mode and alarms */ @@ -42,10 +42,10 @@ uint64_t sensor_ds18b20_number(void) return 0; // no slave presence detected } more = onewire_master_rom_search(&code, false); // get next slave ROM code (without alarm) - if (0==code) { // error occurred + if (0 == code) { // error occurred return 0; } - if (0x28==(code&0xff)) { // family code (8-LSb) for DS18B20 sensors is 0x28 + if (0x28 == (code & 0xff)) { // family code (8-LSb) for DS18B20 sensors is 0x28 last = code; // save last found code sensors++; // we found an additional sensor } else { @@ -68,12 +68,12 @@ bool sensor_ds18b20_list(uint64_t* code) return false; // no slave presence detected } onewire_master_rom_search(code, false); // get next code - return (last!=*code); // verify if the last has been found + return (last != *code); // verify if the last has been found } bool sensor_ds18b20_convert(uint64_t code) { - if (0==code && !only) { // asked for broadcast but there are different slaves on bus + if (0 == code && !only) { // asked for broadcast but there are different slaves on bus return false; // broadcast not possible when there are also different slaves on bus } @@ -83,7 +83,7 @@ bool sensor_ds18b20_convert(uint64_t code) } // send ROM command to select slave(s) - if (0==code) { // broadcast convert + if (0 == code) { // broadcast convert if (!onewire_master_rom_skip()) { // select all slaves return false; // ROM command failed } @@ -99,7 +99,7 @@ bool sensor_ds18b20_convert(uint64_t code) float sensor_ds18b20_temperature(uint64_t code) { - if (0==code && (sensors>1 || !only)) { // broadcast read requested + if (0 == code && (sensors > 1 || !only)) { // broadcast read requested return NAN; // this function is not possible when several sensors or other devices are present } @@ -115,7 +115,7 @@ float sensor_ds18b20_temperature(uint64_t code) // read scratchpad to get temperature (on byte 0 and 1) uint8_t scratchpad[9] = {0}; // to store read scratchpad - if (!onewire_master_function_read(0xbe, scratchpad, sizeof(scratchpad)*8)) { // read complete scratchpad + if (!onewire_master_function_read(0xbe, scratchpad, sizeof(scratchpad) * 8)) { // read complete scratchpad return NAN; // error occurred during read } @@ -125,16 +125,16 @@ float sensor_ds18b20_temperature(uint64_t code) } // calculate temperature (stored as int16_t but on 0.125 C steps) - return ((int16_t)(scratchpad[1]<<8)+scratchpad[0])/16.0; // get temperature (on < 16 precision the last bits are undefined, but that doesn't matter for the end result since the lower precision is still provided) + return ((int16_t)(scratchpad[1] << 8) + scratchpad[0]) / 16.0; // get temperature (on < 16 precision the last bits are undefined, but that doesn't matter for the end result since the lower precision is still provided) } bool sensor_ds18b20_precision(uint64_t code, uint8_t precision) { - if (precision<9 || precision>12) { // check input + if (precision < 9 || precision > 12) { // check input return false; // wrong precision value } - if (0==code && !only) { // asked for broadcast but there are different slaves on bus + if (0 == code && !only) { // asked for broadcast but there are different slaves on bus return false; // broadcast not possible when there are also different slaves on bus } @@ -144,7 +144,7 @@ bool sensor_ds18b20_precision(uint64_t code, uint8_t precision) } // send ROM command to select slave(s) - if (0==code) { // broadcast convert + if (0 == code) { // broadcast convert if (!onewire_master_rom_skip()) { // select all slaves return false; // ROM command failed } @@ -156,7 +156,7 @@ bool sensor_ds18b20_precision(uint64_t code, uint8_t precision) // read scratchpad to get alarm values (on byte 2 and 3) uint8_t scratchpad[9] = {0}; // to store read scratchpad - if (!onewire_master_function_read(0xbe, scratchpad, sizeof(scratchpad)*8)) { // read complete scratchpad + if (!onewire_master_function_read(0xbe, scratchpad, sizeof(scratchpad) * 8)) { // read complete scratchpad return false; // error occurred during read } @@ -169,8 +169,8 @@ bool sensor_ds18b20_precision(uint64_t code, uint8_t precision) uint8_t configuration[3] = {0}; // to store T_HIGH, T_LOW, and configuration configuration[0] = scratchpad[2]; // keep T_HIGH configuration[1] = scratchpad[3]; // keep T_LOW - configuration[2] = 0x1f+((precision-9)<<5); // set precision bit (R1-R0 on bit 6-5) - if (!onewire_master_function_write(0x4e, configuration, sizeof(configuration)*8)) { // write scratchpad with new configuration (all three bytes must be written) + configuration[2] = 0x1f + ((precision - 9) << 5); // set precision bit (R1-R0 on bit 6-5) + if (!onewire_master_function_write(0x4e, configuration, sizeof(configuration) * 8)) { // write scratchpad with new configuration (all three bytes must be written) return false; // error occurred during write } diff --git a/lib/sensor_ds18b20.h b/lib/sensor_ds18b20.h index b2a5abe..28f2b66 100644 --- a/lib/sensor_ds18b20.h +++ b/lib/sensor_ds18b20.h @@ -2,7 +2,7 @@ * @file * @author King Kévin * @copyright SPDX-License-Identifier: GPL-3.0-or-later - * @date 2017 + * @date 2017-2020 * @note peripherals used: 1-Wire (timer @ref onewire_master_timer, GPIO @ref onewire_master_gpio) * @warning this library does not support parasite power mode and alarms */