Merge branch 'cpu-time-offset' into 'v3'

Re-calculate time offset from CPU time to real time on each frame

Closes #830

See merge request openflexure/openflexure-microscope-server!660
This commit is contained in:
Joe Knapper 2026-07-20 14:10:08 +00:00
commit be233e6b95
2 changed files with 4 additions and 3 deletions

Binary file not shown.

View file

@ -86,8 +86,6 @@ class PicameraStreamOutput(Output):
Output.__init__(self)
self.stream = stream
self.encoder = encoder
# The difference between unix time and the CPU time
self.cpu_dt = time.time() - time.monotonic()
def outputframe(
self,
@ -101,10 +99,13 @@ class PicameraStreamOutput(Output):
if timestamp is None or self.encoder.firsttimestamp is None:
frame_timestamp = None
else:
# The difference between unix time and the CPU time. Do not cache this
# number as it can change with clock slew or other time adjustments.
cpu_dt = time.time() - time.monotonic()
# Reconstruct full CPU time of the frame in us
timestamp += self.encoder.firsttimestamp
# Convert to datetime
frame_timestamp = datetime.fromtimestamp(self.cpu_dt + timestamp / 1e6)
frame_timestamp = datetime.fromtimestamp(cpu_dt + timestamp / 1e6)
self.stream.add_frame(frame, frame_timestamp)