Flipper/Applications/Official/DEV_FW/source/grnch/lightmeter/lightmeter_helper.c

44 lines
850 B
C
Raw Normal View History

2022-12-29 06:30:12 +00:00
#include "lightmeter_helper.h"
#include "lightmeter_config.h"
extern const float aperture_numbers[];
extern const float speed_numbers[];
float lux2ev(float lux) {
return log2(lux / 2.5);
}
float getMinDistance(float x, float v1, float v2) {
if(x - v1 > v2 - x) {
return v2;
}
return v1;
}
float normalizeAperture(float a) {
for(int i = 0; i < AP_NUM; i++) {
float a1 = aperture_numbers[i];
float a2 = aperture_numbers[i + 1];
if(a1 < a && a2 >= a) {
return getMinDistance(a, a1, a2);
}
}
return 0;
}
float normalizeTime(float a) {
for(int i = 0; i < SPEED_NUM; i++) {
float a1 = speed_numbers[i];
float a2 = speed_numbers[i + 1];
if(a1 < a && a2 >= a) {
return getMinDistance(a, a1, a2);
}
}
return 0;
}