Calculating EV from lux

This commit is contained in:
Daniele Verducci 2024-04-21 09:10:56 +02:00
parent 5666182e66
commit 47731ad887
4 changed files with 28 additions and 4 deletions

9
src/ev_calculator.py Normal file
View File

@ -0,0 +1,9 @@
from math import log
class EVCalculator:
def luxToEV(lux: float) -> float:
# Wikipedia (https://en.wikipedia.org/wiki/Exposure_value#EV_as_a_measure_of_luminance_and_illuminance)
# says E = 2.5 * (2^EV), so the inverse is EV = ln(2*E/5)/ln(2)
return log(2*lux/5, 2)

View File

@ -31,6 +31,7 @@ lumos_sources = [
'main.py',
'window.py',
'sensors_polling_timer.py',
'ev_calculator.py',
'widgets/widgets_loader.py',
'widgets/time_priority_page.py',
'widgets/aperture_priority_page.py',

View File

@ -20,12 +20,14 @@
from gi.repository import Adw
from gi.repository import Gtk
from .sensors_polling_timer import SensorsPollingTimer
from .ev_calculator import EVCalculator
@Gtk.Template(resource_path='/eu/ichibi/Lumos/window.ui')
class LumosWindow(Adw.ApplicationWindow):
__gtype_name__ = 'LumosWindow'
lux_label = Gtk.Template.Child()
ev_label = Gtk.Template.Child()
def __init__(self, **kwargs):
super().__init__(**kwargs)
@ -34,11 +36,15 @@ class LumosWindow(Adw.ApplicationWindow):
self.sensorsPollingTimer = SensorsPollingTimer(0.1, self.onSensorRead)
self.sensorsPollingTimer.start()
def onSensorRead(self, value, unit):
def onSensorRead(self, value: float, unit: str):
# Called when the light value changed
print("Read {} {}".format(value, unit))
print("Read {} {}".format(value, unit))
if self.lux_label:
self.lux_label.set_label("{:.0f} {}".format(value, unit))
if self.lux_label:
self.lux_label.set_label("{:.0f} {}".format(value, unit))
# Convert lux to EV
ev = EVCalculator.luxToEV(value)
if self.ev_label:
self.ev_label.set_label("{:.1f} EV".format(ev))

View File

@ -96,6 +96,14 @@
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="ev_label">
<property name="label" translatable="no">XXX EV</property>
<style>
<class name="title-1"/>
</style>
</object>"
</child>
</object>