Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions LEX/LEX.ino
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,18 @@ void debugDisplay(){
display.clearDisplay();
}

/**
Base-2 logarithm, rounded to the nearest integer
*/
int roundedLog2(float x)
{
int ex;
// The exponent returned by frexp() is the base-2 logarithm rounded up.
// Scaling by 1/sqrt(2) ensures round-to-nearest.
frexp(x * M_SQRT1_2, &ex);
return ex;
}

void updateDisplay(float T)
{
if (mode == DEBUG) {
Expand All @@ -388,7 +400,7 @@ void updateDisplay(float T)

int timeDisplayMode; // State of shutter speed value display (fractional, seconds, minutes)
int tFractionalDivisor; // Fractional time e.g. 1/1000, where tFractionalDivisor = 1000
float Ev; // Calculated Exposure Value
int Ev; // Calculated Exposure Value
float Tmin; // Time in minutes

if (T >= 60) {
Expand Down Expand Up @@ -478,8 +490,8 @@ void updateDisplay(float T)
display.println(FILM_SENSITIVITY_TABLE[sensitivityIndex], 0);
display.setCursor(76, 11);
display.print("EV=");
Ev = log(pow(APERTURE_TABLE[apertureIndex], 2)) / log(2) + log(1 / T) / log(2);
display.println(floor(Ev + 0.5), 1);
Ev = roundedLog2(pow(APERTURE_TABLE[apertureIndex], 2) / T);
display.println(Ev);
display.setCursor(76, 22);
display.print(lux, 1);
display.println("Lx");
Expand Down