Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

ISSUE: powf function error when using 2 adafruit libraries
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

ISSUE: powf function error when using 2 adafruit libraries

by shashiprab on Fri Aug 07, 2020 5:05 pm

I wrote some code to include and use 2 libraries, Adafruit_TCS34725 and Adafruit_APDS9960. I found that it results in an error in the powf function and crashes. I found that in the 9960 library an internal powf call gets confused with the TCS34725 powf call and fails. If the "bare" powf is namespaced by prefixing and changing to
Code: Select all | TOGGLE FULL SIZE
Adafruit_APDS9960::powf
(and changing the internal call), then everything works (see the code below).

I have fixed it by modifying the file to namespace the function. The reason I bring it up here is that this is an issue across multiple libraries that powf function is not namespaced. I think its easier to say here, that submit an issue or PR to multiple libraries. Please undertake a fix so it will help with using multiple adafruit libraries simultaneously.

Thanks!
Shashi

Code: Select all | TOGGLE FULL SIZE
/*!
 *  @brief  Implements missing powf function
 *  @param  x
 *          Base number
 *  @param  y
 *          Exponent
 *  @return x raised to the power of y
 */
float powf(const float x, const float y) {
  return (float)(pow((double)x, (double)y));
}

/*!
 *  @brief  Enables the device
 *          Disables the device (putting it in lower power sleep mode)
 *  @param  en
 *          Enable (True/False)
 */
void Adafruit_APDS9960::enable(boolean en) {
  _enable.PON = en;
  this->write8(APDS9960_ENABLE, _enable.get());
}



Internal powf call


Code: Select all | TOGGLE FULL SIZE
  cct =
      (449.0F * powf(n, 3)) + (3525.0F * powf(n, 2)) + (6823.3F * n) + 5520.33F;

  /* Return the results in degrees Kelvin */

shashiprab
 
Posts: 1
Joined: Sat Jun 06, 2020 6:09 pm

Please be positive and constructive with your questions and comments.