From 4f79f519175f584f1fb9cc59d4aa925ba6ca141e Mon Sep 17 00:00:00 2001 From: Daniele Verducci Date: Wed, 1 May 2024 10:34:27 +0200 Subject: [PATCH] Implemented AP and TP calculations --- src/ev_calculator.py | 11 +++++---- src/widgets/aperture_priority_page.py | 24 +++++++++++++++++++ src/widgets/aperture_priority_page.ui | 4 ++-- src/widgets/time_priority_page.py | 34 ++++++++++++++++++++++++++- src/widgets/time_priority_page.ui | 4 ++-- 5 files changed, 68 insertions(+), 9 deletions(-) diff --git a/src/ev_calculator.py b/src/ev_calculator.py index 6b41c3d..ebd126a 100644 --- a/src/ev_calculator.py +++ b/src/ev_calculator.py @@ -11,10 +11,12 @@ where: S is the ISO arithmetic speed K is the reflected-light meter calibration constant ''' + +# K is the reflected-light meter calibration constant (unit: cd s/m2 ISO) +# (https://en.wikipedia.org/wiki/Light_meter#Calibration_constants) +K = 12.5 + class EVCalculator: - # K is the reflected-light meter calibration constant (unit: cd s/m2 ISO) - # (https://en.wikipedia.org/wiki/Light_meter#Calibration_constants) - K = 12.5 # TODO: Add to settings? def luxToEV(lux: float) -> float: # Wikipedia (https://en.wikipedia.org/wiki/Light_meter#Exposure_equations) @@ -22,8 +24,9 @@ class EVCalculator: return log(2*lux/5, 2) def calcShutterSpeed(isoSpeed: int, lux: float, aperture: float): - return ((aperture^2)*K)/(lux*isoSpeed) + return (aperture*aperture*K)/(lux*isoSpeed) def calcAperture(isoSpeed: int, lux: float, shutterSpeed: float): + # shutterSpeed is in seconds return sqrt(lux*isoSpeed*shutterSpeed/K) diff --git a/src/widgets/aperture_priority_page.py b/src/widgets/aperture_priority_page.py index 843ed1b..7ad3e2a 100644 --- a/src/widgets/aperture_priority_page.py +++ b/src/widgets/aperture_priority_page.py @@ -19,13 +19,37 @@ from gi.repository import Adw from gi.repository import Gtk +from .ev_calculator import EVCalculator @Gtk.Template(resource_path='/eu/ichibi/Lumos/widgets/aperture_priority_page.ui') class AperturePriorityPage(Gtk.Box): __gtype_name__ = 'AperturePriorityPage' + # Values of aperture dropdown entries defined in the .ui file + aperture_priority_speed_dropdown_values = [ + 1/32, + 1/22, + 1/16, + 1/11, + 1/8, + 1/5.6, + 1/4, + 1/2.8, + 1/2, + 1/1.4 + ] + + # Widgets + aperture_priority_aperture_dropdown = Gtk.Template.Child() + aperture_priority_time_label = Gtk.Template.Child() + def onValuesChanged(self, isoSpeed: int, sensorValue: float, sensorUnit: str): # Check the unit is absolute ("lux") if sensorUnit != "lux": return + apertureValue = self.aperture_priority_speed_dropdown_values[self.aperture_priority_aperture_dropdown.get_selected()] + shutterSpeed = EVCalculator.calcShutterSpeed(isoSpeed, sensorValue, apertureValue) + # TODO: Round shutter speed value to nearest existing value and set label color to red if outside 1 stop range + self.aperture_priority_time_label.set_label("f/ {:.2f}".format(shutterSpeed)) + diff --git a/src/widgets/aperture_priority_page.ui b/src/widgets/aperture_priority_page.ui index aa2335f..0c4e959 100644 --- a/src/widgets/aperture_priority_page.ui +++ b/src/widgets/aperture_priority_page.ui @@ -28,7 +28,7 @@ - + --s