qwiic AS6216 temp sensor compiler error on SAMD21 board

This is a gray area for me , I am using this sensor with a adafruit QT PY SAMD21 board and get a compiler error on one of my PC’s. Doing some searches I found a topic for a different board with the same error and it talks about missing a ‘return value’ in the code. https://github.com/chrisjoyce911/esp32FOTA/issues/3

this is the compiler error I get using a board type of adafruit QT PY SAMD21:

C:\Users\Jim\Documents\Arduino\libraries\SparkFun_AS6212_Qwiic_Arduino_Library\src\SparkFun_AS6212_Qwiic.cpp: In member function ‘uint16_t AS6212::getConversionCycleTime()’:

C:\Users\Jim\Documents\Arduino\libraries\SparkFun_AS6212_Qwiic_Arduino_Library\src\SparkFun_AS6212_Qwiic.cpp:361:1: error: control reaches end of non-void function [-Werror=return-type]

361 | }

| ^

I am in way over my head on this but for the fun of it I edited SparkFun_AS6212_Qwiic.cpp and on the line the compiler said it was an error I added return 0; as the last line, and it compiled ok.

uint16_t AS6212::getConversionCycleTime()

{

int cycleTime;

uint16_t configReg = readRegister(CONFIG,2);

bool conversionRateBit_0 = bitRead(configReg, AS6212_CONFIG_BIT_CONVERSION_RATE_0);

bool conversionRateBit_1 = bitRead(configReg, AS6212_CONFIG_BIT_CONVERSION_RATE_1);

bitWrite(cycleTime, 0, conversionRateBit_0);

bitWrite(cycleTime, 1, conversionRateBit_1);

// conversion rate value is stored in just 2 bits in the config reg,

// so we must convert from stored values (0-3) to “human readable” values (125/250/1000/4000).

if(cycleTime == AS6212_CONVERSION_CYCLE_TIME_125MS) return 125;

if(cycleTime == AS6212_CONVERSION_CYCLE_TIME_250MS) return 250;

if(cycleTime == AS6212_CONVERSION_CYCLE_TIME_1000MS) return 1000;

if(cycleTime == AS6212_CONVERSION_CYCLE_TIME_4000MS) return 4000;

return 0; // I ADDED THIS LINE TO FIX THE COMPILER ERROR

}

thoughts ?

Looks like a reasonable fix to me.

/mike

Since this was a adafruit SAMD21 board involved I had opened a ticket with them: https://forums.adafruit.com/viewtopic.php?f=62&t=192338

you can go to that link for all the details but it looks like due to an update on the SAMD21 libraries they explained:

As of the 1.7.6 release of the Adafruit SAMD Board Support Package, a compiler check for return type has been enabled:

https://github.com/adafruit/ArduinoCore … /tag/1.7.6

https://github.com/adafruit/ArduinoCore … 633eda02f1

The getConversionCycleTime() function is suppose to return a uint16_t:

https://github.com/sparkfun/SparkFun_AS … c.cpp#L343

However, if none of the conditionals are satisfied, it will reach the end the code block and return nothing. The compiler is seeing that and raising the error.

It appears like a simple fix to your AS6216 library, and earlier in this post I added a simple return statement to get it to compile.

Let me know when you update the library and I would be happy to test it.

thanks

Thanks for your work on this everyone. We have added the suggested return line of code to the library.

As a side note, sorry the issues feature was turned off on this library’s repo. We normally have this turned on for all of our repos, and so have corrected that. If anything else comes up, please feel free to file an issue to the repo here:

https://github.com/sparkfun/SparkFun_AS … ary/issues

Thanks again and have a great day!

-Pete