matmunk / DS18B20

Arduino library for the Maxim Integrated DS18B20 1-Wire temperature sensor.
MIT License
90 stars 32 forks source link

Error in compilation of DS18B20.cpp in new IDE Arduino #12

Open EdilbertoMC opened 1 year ago

EdilbertoMC commented 1 year ago

The error display: c:\Users...\Arduino\libraries\DS18B20\src\DS18B20.cpp: In member function 'uint8_t DS18B20::getResolution()': c:\Users...\Arduino\libraries\DS18B20\src\DS18B20.cpp:103:1: error: control reaches end of non-void function [-Werror=return-type] 103 | } | ^ cc1plus.exe: some warnings being treated as errors exit status 1

Compilation error: exit status 1

The problem is simple to resolv. Change in the file DS18B20.cpp (line 103) this:

uint8_t DS18B20::getResolution() { switch (selectedScratchpad[CONFIGURATION]) { case RES_9_BIT: return 9; case RES_10_BIT: return 10; case RES_11_BIT: return 11; case RES_12_BIT: return 12; } }

For this, add the default case:

uint8_t DS18B20::getResolution() { switch (selectedScratchpad[CONFIGURATION]) { case RES_9_BIT: return 9; case RES_10_BIT: return 10; case RES_11_BIT: return 11; case RES_12_BIT: return 12; default: return 12; } }

Please, colud you correct the lib code.

Thank you very much. Gread work. You library is more precise with tenperature reading and easy to use that the Dallas library.

ianburton20 commented 1 year ago

I get exactly the same compile error with ESP8266 Boards Manager above Version 3.0.2 (compiles OK with Version 3.0.2). Also value a correction. Thanks

dquadros commented 1 year ago

This error will be flagged for all compilers that treat this warning as an error. In my case, I was using a Raspberry Pi Pico. Hope you incorporate the fix soon.

Alas, it look like the OneWire library is not compatible with the Pi Pico. When using it, the USB serial port is no longer available.

LRDPRDX commented 5 months ago

See also https://github.com/matmunk/DS18B20/pull/8