On Tue Jan 14, 2025 at 7:43 AM CET, Matti Vaittinen wrote:
...
I will give you a simple example, so you can tell me where my reasoning
fails:
raw = 100 counts
scale = 2.1504 lux/count (when IT=25ms and GAIN=1/8)
processed = 215.04 lux (raw * scale, ABI compliant for IIO_LIGHT)
Your reasoning does not fail. But, the scale = 1 / (N * total_gain),
right? (N here depends on how we choose the scale/gain values) Here,
the total_gain means the effect of both the hardware_gain and the
integration time.
Hence,
processed = X * (raw * scale)
=> processed = X * (raw * (1 / (N * total_gain))
=> processed = X * raw / (N * total_gain);
Hence I thought you might be able to get rid of this 64bit division by
using the total_gain from the iio_gts_get_total_gain() instead of
using the scale. Or, am I missing something?
I am not sure by X you mean the maximum resolution, but if that is the
case, the following would work (pseudo-code):
/* Maximum resolution (2.1504 lux/count) * 10000 */
#define VEML6030_MAX_RES 21504
total_gain = iio_gts_get_total_gain();
processed_int = raw * VEML6030_MAX_RES / total_gain / 10000;
processed_micro = ((raw * VEML6030_MAX_RES / total_gain) % 10000) * 100;