Skip to content
Closed
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions hrl/hrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ def __init__(
elif photometer == "minolta":
from .photometer.minolta import Minolta
self.photometer = Minolta("/dev/ttyUSB0")

elif photometer == "i1pro":
from .photometer.i1pro import i1Pro
self.photometer = i1Pro("/dev/ttyUSB0")

else:
self.photometer = None
Expand Down
84 changes: 84 additions & 0 deletions hrl/photometer/i1pro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
""" Class to read luminance values with X-Rite i1Pro.

It relies on the pypixxlib library from VPixx

"""

from .photometer import Photometer
from pypixxlib.i1 import I1Pro
import pygame
import numpy as np

def wait_any_button(timeout=0):
t0 = pygame.time.get_ticks()
btn = None
while (timeout == 0) or (pygame.time.get_ticks() - t0 < timeout):
event = pygame.event.wait(1) # waits for only 1 ms
if event.type == pygame.KEYDOWN:
break


class i1Pro(Photometer):
def __init__(self, timeout=5):
super(i1Pro, self).__init__()
self.phtm = I1Pro()

print("i1Pro device connected")
print(f"revision: {self.phtm.revision} - serial number: {self.phtm.serial_number}")
self.phtm.setColorSpace("CIEXYZ")

# check if calibration is necessary
self.calibrate()


def calibrate(self):
print('****************************************************')
print("Calibrating device, put the device on its nest and push the side button")
self.phtm.calibrate("Emission")

print(f"Current color space is {self.phtm.getColorSpace()}")
print(f"Current measurement mode is {self.phtm.getMeasurementMode()}")
print(f"Current illumination mode is {self.phtm.getIlluminationMode()}")
print("... Calibration done.")
print('****************************************************')
print('')
print('Put the device on the screen to be measured and press any key to start / continue the measurements')
wait_any_button(timeout=0)


def readTristimulus(self, n=3, slp=1, verbose=False):

# check if calibration is needed
if self.phtm.isCalibrationExpired():
self.calibrate()

# do measurements
for i in range(n):
try:
pygame.time.delay(slp)

# measure the XYZ tristimulus values
self.phtm.runMeasurement()
X, Y, Z = self.phtm.getLatestTriStimulusMeasurements()
if verbose:
print('Tristimulus values:')
print(f"X: {X}, Y: {Y}, Z:{Z}")


return X, Y, Z
except:
print("Error in reading from instrument")
# if no try was successful
return np.nan


def readLuminance(self, n=3, slp=1, verbose=False):

# reads tristimulus values X, Y, Z.
_, lum, _ = self.readTristimulus(n=n, slp=slp, verbose=verbose)

# returns Y, which is luminance by definition.
return lum



16 changes: 16 additions & 0 deletions tests/test_i1pro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pytest

pytestmark = [pytest.mark.photometer]


def test_initialization(photometer_dev):
from hrl.photometer.i1pro import i1Pro

i1Pro()


def test_read_luminance(photometer_dev):
from hrl.photometer.i1pro import i1Pro

device = i1Pro()
device.readLuminance(n=1, slp=5)
Loading