mirror of https://github.com/arendst/Tasmota.git
Merge pull request #8527 from device111/development
update veml7700 libary
This commit is contained in:
commit
9e0637cc60
|
@ -76,30 +76,6 @@ boolean Adafruit_VEML7700::begin(TwoWire *theWire) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Adafruit_VEML7700::alternate_pow(float a, float b)
|
|
||||||
{
|
|
||||||
// https://martin.ankerl.com/2012/01/25/optimized-approximative-pow-in-c-and-cpp/
|
|
||||||
// calculate approximation with fraction of the exponent
|
|
||||||
int e = abs((int)b);
|
|
||||||
union {
|
|
||||||
double d;
|
|
||||||
int x[2];
|
|
||||||
} u = { a };
|
|
||||||
u.x[1] = (int)((b - e) * (u.x[1] - 1072632447) + 1072632447);
|
|
||||||
u.x[0] = 0;
|
|
||||||
// exponentiation by squaring with the exponent's integer part
|
|
||||||
// double r = u.d makes everything much slower, not sure why
|
|
||||||
double r = 1.0;
|
|
||||||
while (e) {
|
|
||||||
if (e & 1) {
|
|
||||||
r *= a;
|
|
||||||
}
|
|
||||||
a *= a;
|
|
||||||
e >>= 1;
|
|
||||||
}
|
|
||||||
return r * u.d;
|
|
||||||
}
|
|
||||||
|
|
||||||
float Adafruit_VEML7700::normalize_resolution(float value) {
|
float Adafruit_VEML7700::normalize_resolution(float value) {
|
||||||
// adjust for gain (1x is normalized)
|
// adjust for gain (1x is normalized)
|
||||||
switch (getGain()) {
|
switch (getGain()) {
|
||||||
|
|
|
@ -62,6 +62,7 @@
|
||||||
#define VEML7700_POWERSAVE_MODE3 0x02 ///< Power saving mode 3
|
#define VEML7700_POWERSAVE_MODE3 0x02 ///< Power saving mode 3
|
||||||
#define VEML7700_POWERSAVE_MODE4 0x03 ///< Power saving mode 4
|
#define VEML7700_POWERSAVE_MODE4 0x03 ///< Power saving mode 4
|
||||||
|
|
||||||
|
extern float FastPrecisePowf(const float x, const float y);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Class that stores state and functions for interacting with
|
* @brief Class that stores state and functions for interacting with
|
||||||
|
@ -110,7 +111,7 @@ private:
|
||||||
*PowerSave_Enable, *PowerSave_Mode;
|
*PowerSave_Enable, *PowerSave_Mode;
|
||||||
|
|
||||||
float normalize_resolution(float value);
|
float normalize_resolution(float value);
|
||||||
float alternate_pow(float a, float b);
|
static inline float alternate_pow(float a, float b) { return FastPrecisePowf(a, b); }
|
||||||
|
|
||||||
Adafruit_I2CDevice *i2c_dev;
|
Adafruit_I2CDevice *i2c_dev;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue