sensor_ds18b20: minor, add spacing around operator
This commit is contained in:
parent
4ade159586
commit
b5a37148d4
|
@ -2,7 +2,7 @@
|
||||||
* @file
|
* @file
|
||||||
* @author King Kévin <kingkevin@cuvoodoo.info>
|
* @author King Kévin <kingkevin@cuvoodoo.info>
|
||||||
* @copyright SPDX-License-Identifier: GPL-3.0-or-later
|
* @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)
|
* @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
|
* @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
|
return 0; // no slave presence detected
|
||||||
}
|
}
|
||||||
more = onewire_master_rom_search(&code, false); // get next slave ROM code (without alarm)
|
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;
|
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
|
last = code; // save last found code
|
||||||
sensors++; // we found an additional sensor
|
sensors++; // we found an additional sensor
|
||||||
} else {
|
} else {
|
||||||
|
@ -68,12 +68,12 @@ bool sensor_ds18b20_list(uint64_t* code)
|
||||||
return false; // no slave presence detected
|
return false; // no slave presence detected
|
||||||
}
|
}
|
||||||
onewire_master_rom_search(code, false); // get next code
|
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)
|
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
|
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)
|
// 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
|
if (!onewire_master_rom_skip()) { // select all slaves
|
||||||
return false; // ROM command failed
|
return false; // ROM command failed
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ bool sensor_ds18b20_convert(uint64_t code)
|
||||||
|
|
||||||
float sensor_ds18b20_temperature(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
|
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)
|
// read scratchpad to get temperature (on byte 0 and 1)
|
||||||
uint8_t scratchpad[9] = {0}; // to store read scratchpad
|
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
|
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)
|
// 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)
|
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
|
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
|
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)
|
// 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
|
if (!onewire_master_rom_skip()) { // select all slaves
|
||||||
return false; // ROM command failed
|
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)
|
// read scratchpad to get alarm values (on byte 2 and 3)
|
||||||
uint8_t scratchpad[9] = {0}; // to store read scratchpad
|
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
|
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
|
uint8_t configuration[3] = {0}; // to store T_HIGH, T_LOW, and configuration
|
||||||
configuration[0] = scratchpad[2]; // keep T_HIGH
|
configuration[0] = scratchpad[2]; // keep T_HIGH
|
||||||
configuration[1] = scratchpad[3]; // keep T_LOW
|
configuration[1] = scratchpad[3]; // keep T_LOW
|
||||||
configuration[2] = 0x1f+((precision-9)<<5); // set precision bit (R1-R0 on bit 6-5)
|
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)
|
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
|
return false; // error occurred during write
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* @file
|
* @file
|
||||||
* @author King Kévin <kingkevin@cuvoodoo.info>
|
* @author King Kévin <kingkevin@cuvoodoo.info>
|
||||||
* @copyright SPDX-License-Identifier: GPL-3.0-or-later
|
* @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)
|
* @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
|
* @warning this library does not support parasite power mode and alarms
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue