sensor_ds18b20: minor, add spacing around operator

This commit is contained in:
King Kévin 2020-12-07 19:07:21 +01:00
parent a4b5f95b07
commit 58ef5f3d1b
2 changed files with 16 additions and 16 deletions

View File

@ -2,7 +2,7 @@
* @file
* @author King Kévin <kingkevin@cuvoodoo.info>
* @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
}

View File

@ -2,7 +2,7 @@
* @file
* @author King Kévin <kingkevin@cuvoodoo.info>
* @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
*/